update code to TabLayoutsHandler

--all ui code from settings dialog for Layouts Tab
in now moved to its handler.
pull/12/head
Michail Vourlakos 5 years ago
parent f7b8bd6619
commit 0d79c2ed15

@ -54,7 +54,7 @@ public:
virtual void resetDefaults() = 0; virtual void resetDefaults() = 0;
virtual void save() = 0; virtual void save() = 0;
virtual void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0) = 0; virtual void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0, QList<QAction *> actions = QList<QAction *>()) = 0;
signals: signals:
void dataChanged(); void dataChanged();

@ -164,9 +164,9 @@ void Preferences::resetDefaults()
updateUi(); updateUi();
} }
void Preferences::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval) void Preferences::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval, QList<QAction *> actions)
{ {
m_parentDialog->showInlineMessage(msg, type, hideInterval); m_parentDialog->showInlineMessage(msg, type, hideInterval, actions);
} }
void Preferences::save() void Preferences::save()

@ -61,7 +61,7 @@ public:
void resetDefaults() override; void resetDefaults() override;
void save() override; void save() override;
void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0) override; void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0, QList<QAction *> actions = QList<QAction *>()) override;
signals: signals:
void borderlessMaximizedChanged(); void borderlessMaximizedChanged();

@ -26,13 +26,25 @@
#include "../universalsettings.h" #include "../universalsettings.h"
#include "../controllers/layoutscontroller.h" #include "../controllers/layoutscontroller.h"
#include "../../lattecorona.h" #include "../../lattecorona.h"
#include "../../layout/centrallayout.h"
#include "../../layouts/importer.h"
#include "../../layouts/manager.h"
#include "../../../liblatte2/types.h" #include "../../../liblatte2/types.h"
//! Qt
#include <QFileDialog>
#include <QFileInfo>
//! KDE
#include <KWindowSystem>
#include <KActivities/Controller>
#include <KIO/OpenFileManagerWindowJob>
#include <KNewStuff3/KNS3/DownloadDialog>
namespace Latte { namespace Latte {
namespace Settings { namespace Settings {
namespace Handler { namespace Handler {
TabLayouts::TabLayouts(Latte::SettingsDialog *parent) TabLayouts::TabLayouts(Latte::SettingsDialog *parent)
: Generic(parent), : Generic(parent),
m_parentDialog(parent), m_parentDialog(parent),
@ -40,24 +52,131 @@ TabLayouts::TabLayouts(Latte::SettingsDialog *parent)
m_ui(m_parentDialog->ui()), m_ui(m_parentDialog->ui()),
m_layoutsController(new Settings::Controller::Layouts(this)) m_layoutsController(new Settings::Controller::Layouts(this))
{ {
initSettings();
initUi(); initUi();
initLayoutMenu();
} }
void TabLayouts::initUi() void TabLayouts::initUi()
{ {
m_inMemoryButtons = new QButtonGroup(this);
m_inMemoryButtons->addButton(m_ui->singleToolBtn, Latte::Types::SingleLayout);
m_inMemoryButtons->addButton(m_ui->multipleToolBtn, Latte::Types::MultipleLayouts);
m_inMemoryButtons->setExclusive(true);
} if (KWindowSystem::isPlatformWayland()) {
m_inMemoryButtons->button(Latte::Types::MultipleLayouts)->setEnabled(false);
}
void TabLayouts::initSettings() bool inMultiple{m_corona->layoutsManager()->memoryUsage() == Types::MultipleLayouts};
{
if (inMultiple) {
m_ui->multipleToolBtn->setChecked(true);
} else {
m_ui->singleToolBtn->setChecked(true);
}
connect(m_ui->layoutsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &Generic::dataChanged);
connect(m_layoutsController, &Settings::Controller::Layouts::dataChanged, this, &Generic::dataChanged);
connect(this, &Settings::Handler::TabLayouts::dataChanged, this, &TabLayouts::updatePerLayoutButtonsState);
connect(m_inMemoryButtons, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
[ = ](int id, bool checked) {
if (checked) {
m_layoutsController->setInMultipleMode(id == Latte::Types::MultipleLayouts);
}
});
updateUi(); connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &TabLayouts::on_currentPageChanged);
updatePerLayoutButtonsState();
} }
void TabLayouts::updateUi() void TabLayouts::initLayoutMenu()
{ {
if (!m_layoutMenu) {
m_layoutMenu = new QMenu(i18n("Layout"), m_parentDialog->appMenuBar());
m_parentDialog->appMenuBar()->addMenu(m_layoutMenu);
}
m_switchLayoutAction = m_layoutMenu->addAction(i18nc("switch layout","Switch"));
m_switchLayoutAction->setToolTip(i18n("Switch to selected layout"));
m_switchLayoutAction->setIcon(QIcon::fromTheme("user-identity"));
m_switchLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab));
connectActionWithButton(m_ui->switchButton, m_switchLayoutAction);
connect(m_switchLayoutAction, &QAction::triggered, this, &TabLayouts::on_switch_layout);
m_pauseLayoutAction = m_layoutMenu->addAction(i18nc("pause layout", "&Pause"));
m_pauseLayoutAction->setToolTip(i18n("Switch to selected layout"));
m_pauseLayoutAction->setIcon(QIcon::fromTheme("media-playback-pause"));
m_pauseLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
connectActionWithButton(m_ui->pauseButton, m_pauseLayoutAction);
connect(m_pauseLayoutAction, &QAction::triggered, this, &TabLayouts::on_pause_layout);
m_layoutMenu->addSeparator();
m_newLayoutAction = m_layoutMenu->addAction(i18nc("new layout", "&New"));
m_newLayoutAction->setToolTip(i18n("New layout"));
m_newLayoutAction->setIcon(QIcon::fromTheme("add"));
m_newLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
connectActionWithButton(m_ui->newButton, m_newLayoutAction);
connect(m_newLayoutAction, &QAction::triggered, this, &TabLayouts::on_new_layout);
m_copyLayoutAction = m_layoutMenu->addAction(i18nc("copy layout", "&Copy"));
m_copyLayoutAction->setToolTip(i18n("Copy selected layout"));
m_copyLayoutAction->setIcon(QIcon::fromTheme("edit-copy"));
m_copyLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
connectActionWithButton(m_ui->copyButton, m_copyLayoutAction);
connect(m_copyLayoutAction, &QAction::triggered, this, &TabLayouts::on_copy_layout);
m_removeLayoutAction = m_layoutMenu->addAction(i18nc("remove layout", "Remove"));
m_removeLayoutAction->setToolTip(i18n("Remove selected layout"));
m_removeLayoutAction->setIcon(QIcon::fromTheme("delete"));
m_removeLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
connectActionWithButton(m_ui->removeButton, m_removeLayoutAction);
connect(m_removeLayoutAction, &QAction::triggered, this, &TabLayouts::on_remove_layout);
m_layoutMenu->addSeparator();
m_lockedLayoutAction = m_layoutMenu->addAction(i18nc("locked layout", "&Locked"));
m_lockedLayoutAction->setToolTip(i18n("Lock/Unlock selected layout and make it read-only"));
m_lockedLayoutAction->setIcon(QIcon::fromTheme("object-locked"));
m_lockedLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
m_lockedLayoutAction->setCheckable(true);
connectActionWithButton(m_ui->lockedButton, m_lockedLayoutAction);
connect(m_lockedLayoutAction, &QAction::triggered, this, &TabLayouts::on_locked_layout);
m_sharedLayoutAction = m_layoutMenu->addAction(i18nc("shared layout", "Sha&red"));
m_sharedLayoutAction->setToolTip(i18n("Share selected layout with other central layouts"));
m_sharedLayoutAction->setIcon(QIcon::fromTheme("document-share"));
m_sharedLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
m_sharedLayoutAction->setCheckable(true);
connectActionWithButton(m_ui->sharedButton, m_sharedLayoutAction);
connect(m_sharedLayoutAction, &QAction::triggered, this, &TabLayouts::on_shared_layout);
m_layoutMenu->addSeparator();
m_importLayoutAction = m_layoutMenu->addAction(i18nc("import layout", "&Import..."));
m_importLayoutAction->setToolTip(i18n("Import layout file from your system"));
m_importLayoutAction->setIcon(QIcon::fromTheme("document-import"));
m_importLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I));
connectActionWithButton(m_ui->importButton, m_importLayoutAction);
connect(m_importLayoutAction, &QAction::triggered, this, &TabLayouts::on_import_layout);
m_exportLayoutAction = m_layoutMenu->addAction(i18nc("export layout", "&Export..."));
m_exportLayoutAction->setToolTip(i18n("Export selected layout at your system"));
m_exportLayoutAction->setIcon(QIcon::fromTheme("document-export"));
m_exportLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_E));
connectActionWithButton(m_ui->exportButton, m_exportLayoutAction);
connect(m_exportLayoutAction, &QAction::triggered, this, &TabLayouts::on_export_layout);
m_downloadLayoutAction = m_layoutMenu->addAction(i18nc("download layout", "&Download..."));
m_downloadLayoutAction->setToolTip(i18n("Download community layouts from KDE Store"));
m_downloadLayoutAction->setIcon(QIcon::fromTheme("get-hot-new-stuff"));
m_downloadLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D));
connectActionWithButton(m_ui->downloadButton, m_downloadLayoutAction);
connect(m_downloadLayoutAction, &QAction::triggered, this, &TabLayouts::on_download_layout);
} }
Latte::Corona *TabLayouts::corona() const Latte::Corona *TabLayouts::corona() const
@ -77,7 +196,7 @@ Ui::SettingsDialog *TabLayouts::ui() const
bool TabLayouts::dataAreChanged() const bool TabLayouts::dataAreChanged() const
{ {
return false; return m_layoutsController->dataAreChanged();
} }
bool TabLayouts::inDefaultValues() const bool TabLayouts::inDefaultValues() const
@ -87,24 +206,453 @@ bool TabLayouts::inDefaultValues() const
void TabLayouts::reset() void TabLayouts::reset()
{ {
updateUi(); m_layoutsController->reset();
} }
void TabLayouts::resetDefaults() void TabLayouts::resetDefaults()
{ {
//do nothing because there are no defaults
} }
void TabLayouts::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval) void TabLayouts::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval, QList<QAction *> actions)
{ {
m_parentDialog->showInlineMessage(msg, type, hideInterval); m_parentDialog->showInlineMessage(msg, type, hideInterval, actions);
} }
void TabLayouts::save() void TabLayouts::save()
{ {
m_layoutsController->save();
}
void TabLayouts::on_switch_layout()
{
if (!isCurrentTab() || !m_switchLayoutAction->isEnabled()) {
return;
}
Settings::Data::Layout selectedLayoutCurrent = m_layoutsController->selectedLayoutCurrentData();
Settings::Data::Layout selectedLayoutOriginal = m_layoutsController->selectedLayoutOriginalData();
selectedLayoutOriginal = selectedLayoutOriginal.isEmpty() ? selectedLayoutCurrent : selectedLayoutOriginal;
if (m_layoutsController->dataAreChanged()) {
showInlineMessage(i18nc("settings:not permitted switching layout","You need to <b>apply</b> your changes first to switch layout..."),
KMessageWidget::Warning,
SettingsDialog::WARNINGINTERVAL);
return;
}
if (!m_layoutsController->selectedLayoutIsCurrentActive()) {
bool appliedShared = m_layoutsController->inMultipleMode() && selectedLayoutCurrent.isShared();
bool freeActivitiesLayoutUpdated{false};
if (!appliedShared && selectedLayoutCurrent.activities.isEmpty()) {
m_layoutsController->setOriginalLayoutForFreeActivities(selectedLayoutOriginal.id);
freeActivitiesLayoutUpdated = true;
}
if (m_layoutsController->inMultipleMode()) {
m_corona->layoutsManager()->switchToLayout(selectedLayoutOriginal.name);
} else {
if (freeActivitiesLayoutUpdated) {
m_corona->layoutsManager()->switchToLayout(selectedLayoutOriginal.name);
} else {
CentralLayout singleLayout(this, selectedLayoutCurrent.id);
QString switchToActivity = selectedLayoutCurrent.isForFreeActivities() ? singleLayout.lastUsedActivity() : selectedLayoutCurrent.activities[0];
if (!m_corona->activitiesConsumer()->runningActivities().contains(switchToActivity)) {
m_corona->layoutsManager()->synchronizer()->activitiesController()->startActivity(switchToActivity);
}
m_corona->layoutsManager()->synchronizer()->activitiesController()->setCurrentActivity(switchToActivity);
}
}
}
updatePerLayoutButtonsState();
} }
void TabLayouts::on_pause_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_pauseLayoutAction->isEnabled()) {
return;
}
setTwinProperty(m_pauseLayoutAction, TWINENABLED, false);
Settings::Data::Layout selectedLayoutCurrent = m_layoutsController->selectedLayoutCurrentData();
Settings::Data::Layout selectedLayoutOriginal = m_layoutsController->selectedLayoutOriginalData();
selectedLayoutOriginal = selectedLayoutOriginal.isEmpty() ? selectedLayoutCurrent : selectedLayoutOriginal;
m_corona->layoutsManager()->synchronizer()->pauseLayout(selectedLayoutOriginal.name);
}
void TabLayouts::updatePerLayoutButtonsState()
{
if (!m_layoutsController->hasSelectedLayout()) {
return;
}
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData();
//! Switch Button
if ((m_layoutsController->inMultipleMode() && selectedLayout.isShared())
|| m_layoutsController->selectedLayoutIsCurrentActive()) {
setTwinProperty(m_switchLayoutAction, TWINENABLED, false);
} else {
setTwinProperty(m_switchLayoutAction, TWINENABLED, true);
}
//! Pause Button
if (!m_layoutsController->inMultipleMode()) {
//! Single Layout mode
setTwinProperty(m_pauseLayoutAction, TWINVISIBLE, false);
} else {
setTwinProperty(m_pauseLayoutAction, TWINVISIBLE, true);
if (selectedLayout.isActive
&& !selectedLayout.isForFreeActivities()
&& !selectedLayout.isShared()) {
setTwinProperty(m_pauseLayoutAction, TWINENABLED, true);
} else {
setTwinProperty(m_pauseLayoutAction, TWINENABLED, false);
}
}
//! Remove Layout Button
/* if (selectedLayout.isActive || selectedLayout.isLocked) {
m_ui->removeButton->setEnabled(false);
} else {
m_ui->removeButton->setEnabled(true);
}*/
//! Layout Locked Button
if (selectedLayout.isLocked) {
setTwinProperty(m_lockedLayoutAction, TWINCHECKED, true);
} else {
setTwinProperty(m_lockedLayoutAction, TWINCHECKED, false);
}
//! UI Elements that need to be enabled/disabled
if (m_layoutsController->inMultipleMode()) {
setTwinProperty(m_sharedLayoutAction, TWINVISIBLE, true);
} else {
setTwinProperty(m_sharedLayoutAction, TWINVISIBLE, false);
}
//! Layout Shared Button
if (selectedLayout.isShared()) {
setTwinProperty(m_sharedLayoutAction, TWINCHECKED, true);
} else {
setTwinProperty(m_sharedLayoutAction, TWINCHECKED, false);
}
}
void TabLayouts::on_new_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_newLayoutAction->isEnabled()) {
return;
}
//! find Default preset path
for (const auto &preset : m_corona->layoutsManager()->presetsPaths()) {
QString presetName = CentralLayout::layoutName(preset);
if (presetName == "Default") {
Settings::Data::Layout newlayout = m_layoutsController->addLayoutForFile(preset, presetName, true);
showInlineMessage(i18nc("settings:layout added successfully","Layout <b>%0</b> added successfully...").arg(newlayout.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONINTERVAL);
break;
}
}
}
void TabLayouts::on_copy_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_copyLayoutAction->isEnabled()) {
return;
}
m_layoutsController->copySelectedLayout();
}
void TabLayouts::on_download_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_downloadLayoutAction->isEnabled()) {
return;
}
KNS3::DownloadDialog dialog(QStringLiteral("latte-layouts.knsrc"), m_parentDialog);
dialog.resize(m_corona->universalSettings()->downloadWindowSize());
dialog.exec();
if (!dialog.changedEntries().isEmpty() || !dialog.installedEntries().isEmpty()) {
for (const auto &entry : dialog.installedEntries()) {
for (const auto &entryFile : entry.installedFiles()) {
Latte::Layouts::Importer::LatteFileVersion version = Latte::Layouts::Importer::fileVersion(entryFile);
if (version == Latte::Layouts::Importer::LayoutVersion2) {
Settings::Data::Layout downloaded = m_layoutsController->addLayoutForFile(entryFile);
showInlineMessage(i18nc("settings:layout downloaded successfully","Layout <b>%0</b> downloaded successfully...").arg(downloaded.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONINTERVAL);
break;
}
}
}
}
m_corona->universalSettings()->setDownloadWindowSize(dialog.size());
}
void TabLayouts::on_remove_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_removeLayoutAction->isEnabled()) {
return;
}
if (!m_layoutsController->hasSelectedLayout()) {
return;
}
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData();
if (selectedLayout.isActive) {
showInlineMessage(i18nc("settings: active layout remove","<b>Active</b> layouts can not be removed..."),
KMessageWidget::Error,
SettingsDialog::WARNINGINTERVAL);
return;
}
if (selectedLayout.isLocked) {
showInlineMessage(i18nc("settings: locked layout remove","Locked layouts can not be removed..."),
KMessageWidget::Error,
SettingsDialog::WARNINGINTERVAL);
return;
}
qDebug() << Q_FUNC_INFO;
m_layoutsController->removeSelected();
}
void TabLayouts::on_locked_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_lockedLayoutAction->isEnabled()) {
return;
}
m_layoutsController->toggleLockedForSelected();
updatePerLayoutButtonsState();
}
void TabLayouts::on_shared_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_sharedLayoutAction->isEnabled()) {
return;
}
m_layoutsController->toggleSharedForSelected();
updatePerLayoutButtonsState();
}
void TabLayouts::on_import_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_importLayoutAction->isEnabled()) {
return;
}
QFileDialog *importFileDialog = new QFileDialog(m_parentDialog, i18nc("import layout", "Import Layout"), QDir::homePath(), QStringLiteral("layout.latte"));
importFileDialog->setWindowIcon(QIcon::fromTheme("document-import"));
importFileDialog->setLabelText(QFileDialog::Accept, i18nc("import layout","Import"));
importFileDialog->setFileMode(QFileDialog::AnyFile);
importFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
importFileDialog->setDefaultSuffix("layout.latte");
QStringList filters;
filters << QString(i18nc("import latte layout", "Latte Dock Layout file v0.2") + "(*.layout.latte)")
<< QString(i18nc("import older latte layout", "Latte Dock Layout file v0.1") + "(*.latterc)");
importFileDialog->setNameFilters(filters);
connect(importFileDialog, &QFileDialog::finished, importFileDialog, &QFileDialog::deleteLater);
connect(importFileDialog, &QFileDialog::fileSelected, this, [&](const QString & file) {
Latte::Layouts::Importer::LatteFileVersion version = Latte::Layouts::Importer::fileVersion(file);
qDebug() << "VERSION :::: " << version;
if (version == Latte::Layouts::Importer::LayoutVersion2) {
Settings::Data::Layout importedlayout = m_layoutsController->addLayoutForFile(file);
showInlineMessage(i18nc("settings:layout imported successfully","Layout <b>%0</b> imported successfully...").arg(importedlayout.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONINTERVAL);
} else if (version == Latte::Layouts::Importer::ConfigVersion1) {
if (!m_layoutsController->importLayoutsFromV1ConfigFile(file)) {
showInlineMessage(i18nc("settings:deprecated layouts import failed","Import layouts from deprecated version <b>failed</b>..."),
KMessageWidget::Error);
}
}
});
importFileDialog->open();
}
void TabLayouts::on_export_layout()
{
qDebug() << Q_FUNC_INFO;
if (!isCurrentTab() || !m_exportLayoutAction->isEnabled()) {
return;
}
if (!m_layoutsController->hasSelectedLayout()) {
return;
}
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData();
//! Update ALL active original layouts before exporting,
m_corona->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles();
QFileDialog *exportFileDialog = new QFileDialog(m_parentDialog, i18n("Export Layout"), QDir::homePath(), QStringLiteral("layout.latte"));
exportFileDialog->setLabelText(QFileDialog::Accept, i18nc("export layout","Export"));
exportFileDialog->setFileMode(QFileDialog::AnyFile);
exportFileDialog->setAcceptMode(QFileDialog::AcceptSave);
exportFileDialog->setDefaultSuffix("layout.latte");
QStringList filters;
QString filter1(i18nc("export layout", "Latte Dock Layout file v0.2") + "(*.layout.latte)");
filters << filter1;
exportFileDialog->setNameFilters(filters);
connect(exportFileDialog, &QFileDialog::finished, exportFileDialog, &QFileDialog::deleteLater);
connect(exportFileDialog, &QFileDialog::fileSelected, this, [ &, selectedLayout](const QString & file) {
auto showExportLayoutError = [this](const Settings::Data::Layout &layout) {
showInlineMessage(i18nc("settings:layout export fail","Layout <b>%0</b> export <b>failed</b>...").arg(layout.name),
KMessageWidget::Error);
};
if (QFile::exists(file) && !QFile::remove(file)) {
showExportLayoutError(selectedLayout);
return;
}
if (file.endsWith(".layout.latte")) {
if (!QFile(selectedLayout.id).copy(file)) {
showExportLayoutError(selectedLayout);
return;
}
QFileInfo newFileInfo(file);
if (newFileInfo.exists() && !newFileInfo.isWritable()) {
QFile(file).setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ReadGroup | QFileDevice::ReadOther);
}
CentralLayout layoutS(this, file);
layoutS.setActivities(QStringList());
layoutS.clearLastUsedActivity();
QAction *openUrlAction = new QAction(i18n("Open Location..."), this);
openUrlAction->setData(file);
QList<QAction *> actions;
actions << openUrlAction;
connect(openUrlAction, &QAction::triggered, this, [&, openUrlAction]() {
QString file = openUrlAction->data().toString();
if (!file.isEmpty()) {
KIO::highlightInFileManager({file});
}
});
showInlineMessage(i18nc("settings:layout export success","Layout <b>%0</b> export succeeded...").arg(selectedLayout.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONWITHACTIONINTERVAL,
actions);
} else if (file.endsWith(".latterc")) {
auto showExportConfigurationError = [this]() {
showInlineMessage(i18n("Full configuration export <b>failed</b>..."), KMessageWidget::Error);
};
if (m_corona->layoutsManager()->importer()->exportFullConfiguration(file)) {
QAction *openUrlAction = new QAction(i18n("Open Location..."), this);
openUrlAction->setData(file);
QList<QAction *> actions;
actions << openUrlAction;
connect(openUrlAction, &QAction::triggered, this, [&, openUrlAction]() {
QString file = openUrlAction->data().toString();
if (!file.isEmpty()) {
KIO::highlightInFileManager({file});
}
});
showInlineMessage(i18n("Full configuration export succeeded..."),
KMessageWidget::Information,
SettingsDialog::INFORMATIONWITHACTIONINTERVAL,
actions);
} else {
showExportConfigurationError();
}
}
});
exportFileDialog->open();
exportFileDialog->selectFile(selectedLayout.name);
}
bool TabLayouts::isCurrentTab() const
{
return (m_layoutMenu->isEnabled() && (m_parentDialog->currentPage() == Types::LayoutPage));
}
void TabLayouts::on_currentPageChanged(int page)
{
Types::LatteConfigPage cPage= static_cast<Types::LatteConfigPage>(page);
if (cPage == Types::LayoutPage) {
m_layoutMenu->setEnabled(true);
m_layoutMenu->menuAction()->setVisible(true);
} else {
m_layoutMenu->menuAction()->setVisible(false);
m_layoutMenu->setEnabled(false);
}
}
void TabLayouts::on_keyReleaseEvent(QKeyEvent *event)
{
if (event && event->key() == Qt::Key_Delete && m_parentDialog->currentPage() == Types::LayoutPage){
on_remove_layout();
}
}
} }
} }
} }

@ -24,6 +24,11 @@
//! local //! local
#include "generichandler.h" #include "generichandler.h"
//! Qt
#include <QAction>
#include <QButtonGroup>
#include <QMenu>
namespace Ui { namespace Ui {
class SettingsDialog; class SettingsDialog;
} }
@ -55,6 +60,7 @@ public:
bool dataAreChanged() const override; bool dataAreChanged() const override;
bool inDefaultValues() const override; bool inDefaultValues() const override;
bool isCurrentTab() const;
void reset() override; void reset() override;
void resetDefaults() override; void resetDefaults() override;
@ -64,12 +70,28 @@ public:
Latte::SettingsDialog *dialog() const; Latte::SettingsDialog *dialog() const;
Ui::SettingsDialog *ui() const; Ui::SettingsDialog *ui() const;
void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0) override; void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0, QList<QAction *> actions = QList<QAction *>()) override;
public slots:
void on_keyReleaseEvent(QKeyEvent *event);
private slots: private slots:
void initUi(); void initUi();
void initSettings(); void initLayoutMenu();
void updateUi();
void on_new_layout();
void on_copy_layout();
void on_download_layout();
void on_pause_layout();
void on_switch_layout();
void on_import_layout();
void on_export_layout();
void on_locked_layout();
void on_remove_layout();
void on_shared_layout();
void on_currentPageChanged(int page);
void updatePerLayoutButtonsState();
private: private:
Latte::SettingsDialog *m_parentDialog{nullptr}; Latte::SettingsDialog *m_parentDialog{nullptr};
@ -78,6 +100,20 @@ private:
Settings::Controller::Layouts *m_layoutsController{nullptr}; Settings::Controller::Layouts *m_layoutsController{nullptr};
QButtonGroup *m_inMemoryButtons;
//! Layout menu actions
QMenu *m_layoutMenu{nullptr};
QAction *m_switchLayoutAction{nullptr};
QAction *m_pauseLayoutAction{nullptr};
QAction *m_newLayoutAction{nullptr};
QAction *m_copyLayoutAction{nullptr};
QAction *m_removeLayoutAction{nullptr};
QAction *m_lockedLayoutAction{nullptr};
QAction *m_sharedLayoutAction{nullptr};
QAction *m_importLayoutAction{nullptr};
QAction *m_exportLayoutAction{nullptr};
QAction *m_downloadLayoutAction{nullptr};
}; };
} }

@ -45,11 +45,9 @@
#include <QMimeData> #include <QMimeData>
// KDE // KDE
#include <KActivities/Controller>
#include <KIO/OpenFileManagerWindowJob> #include <KIO/OpenFileManagerWindowJob>
#include <KLocalizedString> #include <KLocalizedString>
#include <KWindowSystem> #include <KWindowSystem>
#include <KNewStuff3/KNS3/DownloadDialog>
#define TWINENABLED "Enabled" #define TWINENABLED "Enabled"
@ -82,59 +80,21 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona)
connect(m_ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked connect(m_ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked
, this, &SettingsDialog::restoreDefaults); , this, &SettingsDialog::restoreDefaults);
//! Global Menu
initGlobalMenu();
m_tabLayoutsHandler = new Settings::Handler::TabLayouts(this); m_tabLayoutsHandler = new Settings::Handler::TabLayouts(this);
m_preferencesHandler = new Settings::Handler::Preferences(this); m_preferencesHandler = new Settings::Handler::Preferences(this);
m_layoutsController = new Settings::Controller::Layouts(m_tabLayoutsHandler);
m_inMemoryButtons = new QButtonGroup(this);
m_inMemoryButtons->addButton(m_ui->singleToolBtn, Latte::Types::SingleLayout);
m_inMemoryButtons->addButton(m_ui->multipleToolBtn, Latte::Types::MultipleLayouts);
m_inMemoryButtons->setExclusive(true);
if (KWindowSystem::isPlatformWayland()) {
m_inMemoryButtons->button(Latte::Types::MultipleLayouts)->setEnabled(false);
}
m_ui->messageWidget->setVisible(false); m_ui->messageWidget->setVisible(false);
//! Global Menu
initGlobalMenu();
m_ui->buttonBox->button(QDialogButtonBox::Apply)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S)); m_ui->buttonBox->button(QDialogButtonBox::Apply)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_S));
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L)); m_ui->buttonBox->button(QDialogButtonBox::Reset)->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
m_openUrlAction = new QAction(i18n("Open Location..."), this);
connect(m_openUrlAction, &QAction::triggered, this, [&]() {
QString file = m_openUrlAction->data().toString();
if (!file.isEmpty()) {
KIO::highlightInFileManager({file});
}
});
loadSettings();
//! SIGNALS //! SIGNALS
connect(m_ui->layoutsView->selectionModel(), &QItemSelectionModel::currentRowChanged, this, [&]() { connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SettingsDialog::updateApplyButtonsState);
updatePerLayoutButtonsState();
updateApplyButtonsState();
});
connect(m_layoutsController, &Settings::Controller::Layouts::dataChanged, this, [&]() { connect(m_tabLayoutsHandler, &Settings::Handler::TabLayouts::dataChanged, this, &SettingsDialog::updateApplyButtonsState);
updateApplyButtonsState();
updatePerLayoutButtonsState();
});
connect(m_inMemoryButtons, static_cast<void(QButtonGroup::*)(int, bool)>(&QButtonGroup::buttonToggled),
[ = ](int id, bool checked) {
if (checked) {
m_layoutsController->setInMultipleMode(id == Latte::Types::MultipleLayouts);
}
});
connect(m_ui->tabWidget, &QTabWidget::currentChanged, this, &SettingsDialog::on_currentPageChanged);
connect(m_preferencesHandler, &Settings::Handler::Preferences::dataChanged, this, &SettingsDialog::updateApplyButtonsState); connect(m_preferencesHandler, &Settings::Handler::Preferences::dataChanged, this, &SettingsDialog::updateApplyButtonsState);
connect(m_preferencesHandler, &Settings::Handler::Preferences::borderlessMaximizedChanged, this, [&]() { connect(m_preferencesHandler, &Settings::Handler::Preferences::borderlessMaximizedChanged, this, [&]() {
@ -157,12 +117,13 @@ SettingsDialog::SettingsDialog(QWidget *parent, Latte::Corona *corona)
m_hideInlineMessageTimer.setInterval(2000); m_hideInlineMessageTimer.setInterval(2000);
connect(&m_hideInlineMessageTimer, &QTimer::timeout, this, [&]() { connect(&m_hideInlineMessageTimer, &QTimer::timeout, this, [&]() {
m_ui->messageWidget->animatedHide(); m_ui->messageWidget->animatedHide();
m_ui->messageWidget->removeAction(m_openUrlAction);
}); });
connect(m_ui->messageWidget, &KMessageWidget::hideAnimationFinished, this, [&]() { connect(m_ui->messageWidget, &KMessageWidget::hideAnimationFinished, this, [&]() {
m_ui->messageWidget->removeAction(m_openUrlAction); clearCurrentMessageActions();
}); });
updateApplyButtonsState();
} }
SettingsDialog::~SettingsDialog() SettingsDialog::~SettingsDialog()
@ -179,96 +140,9 @@ void SettingsDialog::initGlobalMenu()
layout()->setMenuBar(m_globalMenuBar); layout()->setMenuBar(m_globalMenuBar);
initFileMenu(); initFileMenu();
initLayoutMenu();
initHelpMenu(); initHelpMenu();
} }
void SettingsDialog::initLayoutMenu()
{
if (!m_layoutMenu) {
m_layoutMenu = new QMenu(i18n("Layout"), m_globalMenuBar);
m_globalMenuBar->addMenu(m_layoutMenu);
}
m_switchLayoutAction = m_layoutMenu->addAction(i18nc("switch layout","Switch"));
m_switchLayoutAction->setToolTip(i18n("Switch to selected layout"));
m_switchLayoutAction->setIcon(QIcon::fromTheme("user-identity"));
m_switchLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Tab));
twinActionWithButton(m_ui->switchButton, m_switchLayoutAction);
connect(m_switchLayoutAction, &QAction::triggered, this, &SettingsDialog::on_switch_layout);
m_pauseLayoutAction = m_layoutMenu->addAction(i18nc("pause layout", "&Pause"));
m_pauseLayoutAction->setToolTip(i18n("Switch to selected layout"));
m_pauseLayoutAction->setIcon(QIcon::fromTheme("media-playback-pause"));
m_pauseLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_P));
twinActionWithButton(m_ui->pauseButton, m_pauseLayoutAction);
connect(m_pauseLayoutAction, &QAction::triggered, this, &SettingsDialog::on_pause_layout);
m_layoutMenu->addSeparator();
m_newLayoutAction = m_layoutMenu->addAction(i18nc("new layout", "&New"));
m_newLayoutAction->setToolTip(i18n("New layout"));
m_newLayoutAction->setIcon(QIcon::fromTheme("add"));
m_newLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_N));
twinActionWithButton(m_ui->newButton, m_newLayoutAction);
connect(m_newLayoutAction, &QAction::triggered, this, &SettingsDialog::on_new_layout);
m_copyLayoutAction = m_layoutMenu->addAction(i18nc("copy layout", "&Copy"));
m_copyLayoutAction->setToolTip(i18n("Copy selected layout"));
m_copyLayoutAction->setIcon(QIcon::fromTheme("edit-copy"));
m_copyLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C));
twinActionWithButton(m_ui->copyButton, m_copyLayoutAction);
connect(m_copyLayoutAction, &QAction::triggered, this, &SettingsDialog::on_copy_layout);
m_removeLayoutAction = m_layoutMenu->addAction(i18nc("remove layout", "Remove"));
m_removeLayoutAction->setToolTip(i18n("Remove selected layout"));
m_removeLayoutAction->setIcon(QIcon::fromTheme("delete"));
m_removeLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_D));
twinActionWithButton(m_ui->removeButton, m_removeLayoutAction);
connect(m_removeLayoutAction, &QAction::triggered, this, &SettingsDialog::on_remove_layout);
m_layoutMenu->addSeparator();
m_lockedLayoutAction = m_layoutMenu->addAction(i18nc("locked layout", "&Locked"));
m_lockedLayoutAction->setToolTip(i18n("Lock/Unlock selected layout and make it read-only"));
m_lockedLayoutAction->setIcon(QIcon::fromTheme("object-locked"));
m_lockedLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_L));
m_lockedLayoutAction->setCheckable(true);
twinActionWithButton(m_ui->lockedButton, m_lockedLayoutAction);
connect(m_lockedLayoutAction, &QAction::triggered, this, &SettingsDialog::on_locked_layout);
m_sharedLayoutAction = m_layoutMenu->addAction(i18nc("shared layout", "Sha&red"));
m_sharedLayoutAction->setToolTip(i18n("Share selected layout with other central layouts"));
m_sharedLayoutAction->setIcon(QIcon::fromTheme("document-share"));
m_sharedLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_R));
m_sharedLayoutAction->setCheckable(true);
twinActionWithButton(m_ui->sharedButton, m_sharedLayoutAction);
connect(m_sharedLayoutAction, &QAction::triggered, this, &SettingsDialog::on_shared_layout);
m_layoutMenu->addSeparator();
m_importLayoutAction = m_layoutMenu->addAction(i18nc("import layout", "&Import..."));
m_importLayoutAction->setToolTip(i18n("Import layout file from your system"));
m_importLayoutAction->setIcon(QIcon::fromTheme("document-import"));
m_importLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_I));
twinActionWithButton(m_ui->importButton, m_importLayoutAction);
connect(m_importLayoutAction, &QAction::triggered, this, &SettingsDialog::on_import_layout);
m_exportLayoutAction = m_layoutMenu->addAction(i18nc("export layout", "&Export..."));
m_exportLayoutAction->setToolTip(i18n("Export selected layout at your system"));
m_exportLayoutAction->setIcon(QIcon::fromTheme("document-export"));
m_exportLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_E));
twinActionWithButton(m_ui->exportButton, m_exportLayoutAction);
connect(m_exportLayoutAction, &QAction::triggered, this, &SettingsDialog::on_export_layout);
m_downloadLayoutAction = m_layoutMenu->addAction(i18nc("download layout", "&Download..."));
m_downloadLayoutAction->setToolTip(i18n("Download community layouts from KDE Store"));
m_downloadLayoutAction->setIcon(QIcon::fromTheme("get-hot-new-stuff"));
m_downloadLayoutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_D));
twinActionWithButton(m_ui->downloadButton, m_downloadLayoutAction);
connect(m_downloadLayoutAction, &QAction::triggered, this, &SettingsDialog::on_download_layout);
}
void SettingsDialog::initFileMenu() void SettingsDialog::initFileMenu()
{ {
if (!m_fileMenu) { if (!m_fileMenu) {
@ -329,36 +203,9 @@ Ui::SettingsDialog *SettingsDialog::ui() const
return m_ui; return m_ui;
} }
void SettingsDialog::twinActionWithButton(QPushButton *button, QAction *action) QMenuBar *SettingsDialog::appMenuBar() const
{
button->setText(action->text());
button->setToolTip(action->toolTip());
button->setWhatsThis(action->whatsThis());
button->setIcon(action->icon());
button->setCheckable(action->isCheckable());
button->setChecked(action->isChecked());
m_twinActions[action] = button;
connect(button, &QPushButton::clicked, action, &QAction::trigger);
}
void SettingsDialog::setTwinProperty(QAction *action, const QString &property, QVariant value)
{ {
if (!m_twinActions.contains(action)) { return m_globalMenuBar;
return;
}
if (property == TWINVISIBLE) {
action->setVisible(value.toBool());
m_twinActions[action]->setVisible(value.toBool());
} else if (property == TWINENABLED) {
action->setEnabled(value.toBool());
m_twinActions[action]->setEnabled(value.toBool());
} else if (property == TWINCHECKED) {
action->setChecked(value.toBool());
m_twinActions[action]->setChecked(value.toBool());
}
} }
Types::LatteConfigPage SettingsDialog::currentPage() Types::LatteConfigPage SettingsDialog::currentPage()
@ -382,194 +229,6 @@ void SettingsDialog::setCurrentPage(int page)
m_ui->tabWidget->setCurrentIndex(page); m_ui->tabWidget->setCurrentIndex(page);
} }
void SettingsDialog::on_currentPageChanged(int page)
{
Types::LatteConfigPage cPage= static_cast<Types::LatteConfigPage>(page);
if (cPage == Types::LayoutPage) {
m_layoutMenu->setEnabled(true);
m_layoutMenu->menuAction()->setVisible(true);
} else {
m_layoutMenu->menuAction()->setVisible(false);
m_layoutMenu->setEnabled(false);
}
updateApplyButtonsState();
}
void SettingsDialog::on_new_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_newLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
//! find Default preset path
for (const auto &preset : m_corona->layoutsManager()->presetsPaths()) {
QString presetName = CentralLayout::layoutName(preset);
if (presetName == "Default") {
Settings::Data::Layout newlayout = m_layoutsController->addLayoutForFile(preset, presetName, true);
showInlineMessage(i18nc("settings:layout added successfully","Layout <b>%0</b> added successfully...").arg(newlayout.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONINTERVAL);
break;
}
}
}
void SettingsDialog::on_copy_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_copyLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
m_layoutsController->copySelectedLayout();
}
void SettingsDialog::on_download_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_downloadLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
KNS3::DownloadDialog dialog(QStringLiteral("latte-layouts.knsrc"), this);
dialog.resize(m_corona->universalSettings()->downloadWindowSize());
dialog.exec();
if (!dialog.changedEntries().isEmpty() || !dialog.installedEntries().isEmpty()) {
for (const auto &entry : dialog.installedEntries()) {
for (const auto &entryFile : entry.installedFiles()) {
Layouts::Importer::LatteFileVersion version = Layouts::Importer::fileVersion(entryFile);
if (version == Layouts::Importer::LayoutVersion2) {
Settings::Data::Layout downloaded = m_layoutsController->addLayoutForFile(entryFile);
showInlineMessage(i18nc("settings:layout downloaded successfully","Layout <b>%0</b> downloaded successfully...").arg(downloaded.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONINTERVAL);
break;
}
}
}
}
m_corona->universalSettings()->setDownloadWindowSize(dialog.size());
}
void SettingsDialog::on_remove_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_removeLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
if (!m_layoutsController->hasSelectedLayout()) {
return;
}
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData();
if (selectedLayout.isActive) {
showInlineMessage(i18nc("settings: active layout remove","<b>Active</b> layouts can not be removed..."),
KMessageWidget::Error,
SettingsDialog::WARNINGINTERVAL);
return;
}
if (selectedLayout.isLocked) {
showInlineMessage(i18nc("settings: locked layout remove","Locked layouts can not be removed..."),
KMessageWidget::Error,
SettingsDialog::WARNINGINTERVAL);
return;
}
qDebug() << Q_FUNC_INFO;
m_layoutsController->removeSelected();
updateApplyButtonsState();
}
void SettingsDialog::on_locked_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_lockedLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
m_layoutsController->toggleLockedForSelected();
updatePerLayoutButtonsState();
updateApplyButtonsState();
}
void SettingsDialog::on_shared_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_sharedLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
m_layoutsController->toggleSharedForSelected();
updatePerLayoutButtonsState();
updateApplyButtonsState();
}
void SettingsDialog::on_import_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_importLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
QFileDialog *importFileDialog = new QFileDialog(this, i18nc("import layout", "Import Layout")
, QDir::homePath()
, QStringLiteral("layout.latte"));
importFileDialog->setWindowIcon(QIcon::fromTheme("document-import"));
importFileDialog->setLabelText(QFileDialog::Accept, i18nc("import layout","Import"));
importFileDialog->setFileMode(QFileDialog::AnyFile);
importFileDialog->setAcceptMode(QFileDialog::AcceptOpen);
importFileDialog->setDefaultSuffix("layout.latte");
QStringList filters;
filters << QString(i18nc("import latte layout", "Latte Dock Layout file v0.2") + "(*.layout.latte)")
<< QString(i18nc("import older latte layout", "Latte Dock Layout file v0.1") + "(*.latterc)");
importFileDialog->setNameFilters(filters);
connect(importFileDialog, &QFileDialog::finished, importFileDialog, &QFileDialog::deleteLater);
connect(importFileDialog, &QFileDialog::fileSelected, this, [&](const QString & file) {
Layouts::Importer::LatteFileVersion version = Layouts::Importer::fileVersion(file);
qDebug() << "VERSION :::: " << version;
if (version == Layouts::Importer::LayoutVersion2) {
Settings::Data::Layout importedlayout = m_layoutsController->addLayoutForFile(file);
showInlineMessage(i18nc("settings:layout imported successfully","Layout <b>%0</b> imported successfully...").arg(importedlayout.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONINTERVAL);
} else if (version == Layouts::Importer::ConfigVersion1) {
if (!m_layoutsController->importLayoutsFromV1ConfigFile(file)) {
showInlineMessage(i18nc("settings:deprecated layouts import failed","Import layouts from deprecated version <b>failed</b>..."),
KMessageWidget::Error);
}
}
});
importFileDialog->open();
}
void SettingsDialog::on_import_fullconfiguration() void SettingsDialog::on_import_fullconfiguration()
{ {
qDebug() << Q_FUNC_INFO; qDebug() << Q_FUNC_INFO;
@ -633,92 +292,6 @@ void SettingsDialog::on_import_fullconfiguration()
importFileDialog->open(); importFileDialog->open();
} }
void SettingsDialog::on_export_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_exportLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
if (!m_layoutsController->hasSelectedLayout()) {
return;
}
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData();
//! Update ALL active original layouts before exporting,
m_corona->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles();
QFileDialog *exportFileDialog = new QFileDialog(this, i18n("Export Layout"), QDir::homePath(), QStringLiteral("layout.latte"));
exportFileDialog->setLabelText(QFileDialog::Accept, i18nc("export layout","Export"));
exportFileDialog->setFileMode(QFileDialog::AnyFile);
exportFileDialog->setAcceptMode(QFileDialog::AcceptSave);
exportFileDialog->setDefaultSuffix("layout.latte");
QStringList filters;
QString filter1(i18nc("export layout", "Latte Dock Layout file v0.2") + "(*.layout.latte)");
filters << filter1;
exportFileDialog->setNameFilters(filters);
connect(exportFileDialog, &QFileDialog::finished, exportFileDialog, &QFileDialog::deleteLater);
connect(exportFileDialog, &QFileDialog::fileSelected, this, [ &, selectedLayout](const QString & file) {
auto showExportLayoutError = [this](const Settings::Data::Layout &layout) {
showInlineMessage(i18nc("settings:layout export fail","Layout <b>%0</b> export <b>failed</b>...").arg(layout.name),
KMessageWidget::Error);
};
if (QFile::exists(file) && !QFile::remove(file)) {
showExportLayoutError(selectedLayout);
return;
}
if (file.endsWith(".layout.latte")) {
if (!QFile(selectedLayout.id).copy(file)) {
showExportLayoutError(selectedLayout);
return;
}
QFileInfo newFileInfo(file);
if (newFileInfo.exists() && !newFileInfo.isWritable()) {
QFile(file).setPermissions(QFileDevice::ReadUser | QFileDevice::WriteUser | QFileDevice::ReadGroup | QFileDevice::ReadOther);
}
CentralLayout layoutS(this, file);
layoutS.setActivities(QStringList());
layoutS.clearLastUsedActivity();
m_openUrlAction->setData(file);
m_ui->messageWidget->addAction(m_openUrlAction);
showInlineMessage(i18nc("settings:layout export success","Layout <b>%0</b> export succeeded...").arg(selectedLayout.name),
KMessageWidget::Information,
SettingsDialog::INFORMATIONWITHACTIONINTERVAL);
} else if (file.endsWith(".latterc")) {
auto showExportConfigurationError = [this]() {
showInlineMessage(i18n("Full configuration export <b>failed</b>..."), KMessageWidget::Error);
};
if (m_corona->layoutsManager()->importer()->exportFullConfiguration(file)) {
m_openUrlAction->setData(file);
m_ui->messageWidget->addAction(m_openUrlAction);
showInlineMessage(i18n("Full configuration export succeeded..."),
KMessageWidget::Information,
SettingsDialog::INFORMATIONWITHACTIONINTERVAL);
} else {
showExportConfigurationError();
}
}
});
exportFileDialog->open();
exportFileDialog->selectFile(selectedLayout.name);
}
void SettingsDialog::on_export_fullconfiguration() void SettingsDialog::on_export_fullconfiguration()
{ {
//! Update ALL active original layouts before exporting, //! Update ALL active original layouts before exporting,
@ -748,11 +321,23 @@ void SettingsDialog::on_export_fullconfiguration()
}; };
if (m_corona->layoutsManager()->importer()->exportFullConfiguration(file)) { if (m_corona->layoutsManager()->importer()->exportFullConfiguration(file)) {
m_openUrlAction->setData(file); QAction *openUrlAction = new QAction(i18n("Open Location..."), this);
m_ui->messageWidget->addAction(m_openUrlAction); openUrlAction->setData(file);
QList<QAction *> actions;
actions << openUrlAction;
connect(openUrlAction, &QAction::triggered, this, [&, openUrlAction]() {
QString file = openUrlAction->data().toString();
if (!file.isEmpty()) {
KIO::highlightInFileManager({file});
}
});
showInlineMessage(i18n("Full configuration export succeeded..."), showInlineMessage(i18n("Full configuration export succeeded..."),
KMessageWidget::Information, KMessageWidget::Information,
SettingsDialog::INFORMATIONWITHACTIONINTERVAL); SettingsDialog::INFORMATIONWITHACTIONINTERVAL,
actions);
} else { } else {
showExportConfigurationError(); showExportConfigurationError();
} }
@ -817,10 +402,7 @@ void SettingsDialog::apply()
return; return;
} }
saveAllChanges(); save();
updateApplyButtonsState();
updatePerLayoutButtonsState();
} }
void SettingsDialog::reset() void SettingsDialog::reset()
@ -832,7 +414,7 @@ void SettingsDialog::reset()
} }
if (m_ui->tabWidget->currentIndex() == Latte::Types::LayoutPage) { if (m_ui->tabWidget->currentIndex() == Latte::Types::LayoutPage) {
m_layoutsController->reset(); m_tabLayoutsHandler->reset();
} else if (m_ui->tabWidget->currentIndex() == Latte::Types::PreferencesPage) { } else if (m_ui->tabWidget->currentIndex() == Latte::Types::PreferencesPage) {
m_preferencesHandler->reset(); m_preferencesHandler->reset();
} }
@ -849,108 +431,13 @@ void SettingsDialog::restoreDefaults()
} }
} }
void SettingsDialog::loadSettings()
{
bool inMultiple{m_corona->layoutsManager()->memoryUsage() == Types::MultipleLayouts};
if (inMultiple) {
m_ui->multipleToolBtn->setChecked(true);
} else {
m_ui->singleToolBtn->setChecked(true);
}
updatePerLayoutButtonsState();
updateApplyButtonsState();
}
QList<int> SettingsDialog::currentSettings()
{
QList<int> settings;
settings << (int)m_ui->autostartChkBox->isChecked();
settings << (int)m_ui->badges3DStyleChkBox->isChecked();
settings << (int)m_ui->infoWindowChkBox->isChecked();
settings << (int)m_ui->metaPressChkBox->isChecked();
settings << (int)m_ui->metaPressHoldChkBox->isChecked();
settings << (int)m_ui->noBordersForMaximizedChkBox->isChecked();
settings << m_mouseSensitivityButtons->checkedId();
settings << m_ui->screenTrackerSpinBox->value();
settings << m_ui->outlineSpinBox->value();
return settings;
}
void SettingsDialog::on_switch_layout()
{
if (!m_layoutMenu->isEnabled() || !m_switchLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
Settings::Data::Layout selectedLayoutCurrent = m_layoutsController->selectedLayoutCurrentData();
Settings::Data::Layout selectedLayoutOriginal = m_layoutsController->selectedLayoutOriginalData();
selectedLayoutOriginal = selectedLayoutOriginal.isEmpty() ? selectedLayoutCurrent : selectedLayoutOriginal;
if (m_layoutsController->dataAreChanged()) {
showInlineMessage(i18nc("settings:not permitted switching layout","You need to <b>apply</b> your changes first to switch layout..."),
KMessageWidget::Warning,
WARNINGINTERVAL);
return;
}
if (!m_layoutsController->selectedLayoutIsCurrentActive()) {
bool appliedShared = m_layoutsController->inMultipleMode() && selectedLayoutCurrent.isShared();
bool freeActivitiesLayoutUpdated{false};
if (!appliedShared && selectedLayoutCurrent.activities.isEmpty()) {
m_layoutsController->setOriginalLayoutForFreeActivities(selectedLayoutOriginal.id);
freeActivitiesLayoutUpdated = true;
}
if (m_layoutsController->inMultipleMode()) {
m_corona->layoutsManager()->switchToLayout(selectedLayoutOriginal.name);
} else {
if (freeActivitiesLayoutUpdated) {
m_corona->layoutsManager()->switchToLayout(selectedLayoutOriginal.name);
} else {
CentralLayout singleLayout(this, selectedLayoutCurrent.id);
QString switchToActivity = selectedLayoutCurrent.isForFreeActivities() ? singleLayout.lastUsedActivity() : selectedLayoutCurrent.activities[0];
if (!m_corona->activitiesConsumer()->runningActivities().contains(switchToActivity)) {
m_corona->layoutsManager()->synchronizer()->activitiesController()->startActivity(switchToActivity);
}
m_corona->layoutsManager()->synchronizer()->activitiesController()->setCurrentActivity(switchToActivity);
}
}
}
updatePerLayoutButtonsState();
}
void SettingsDialog::on_pause_layout()
{
qDebug() << Q_FUNC_INFO;
if (!m_layoutMenu->isEnabled() || !m_pauseLayoutAction->isEnabled() || currentPage() != Types::LayoutPage) {
return;
}
setTwinProperty(m_pauseLayoutAction, TWINENABLED, false);
Settings::Data::Layout selectedLayoutCurrent = m_layoutsController->selectedLayoutCurrentData();
Settings::Data::Layout selectedLayoutOriginal = m_layoutsController->selectedLayoutOriginalData();
selectedLayoutOriginal = selectedLayoutOriginal.isEmpty() ? selectedLayoutCurrent : selectedLayoutOriginal;
m_corona->layoutsManager()->synchronizer()->pauseLayout(selectedLayoutOriginal.name);
}
void SettingsDialog::updateApplyButtonsState() void SettingsDialog::updateApplyButtonsState()
{ {
bool changed{false}; bool changed{false};
//! Ok, Apply Buttons //! Ok, Apply Buttons
if ((currentPage() == Latte::Types::LayoutPage && m_layoutsController->dataAreChanged()) if ((currentPage() == Latte::Types::LayoutPage && m_tabLayoutsHandler->dataAreChanged())
||(currentPage() == Latte::Types::PreferencesPage && m_preferencesHandler->dataAreChanged())) { ||(currentPage() == Latte::Types::PreferencesPage && m_preferencesHandler->dataAreChanged())) {
changed = true; changed = true;
} }
@ -978,67 +465,6 @@ void SettingsDialog::updateApplyButtonsState()
} }
} }
void SettingsDialog::updatePerLayoutButtonsState()
{
if (!m_layoutsController->hasSelectedLayout()) {
return;
}
Settings::Data::Layout selectedLayout = m_layoutsController->selectedLayoutCurrentData();
//! Switch Button
if ((m_layoutsController->inMultipleMode() && selectedLayout.isShared())
|| m_layoutsController->selectedLayoutIsCurrentActive()) {
setTwinProperty(m_switchLayoutAction, TWINENABLED, false);
} else {
setTwinProperty(m_switchLayoutAction, TWINENABLED, true);
}
//! Pause Button
if (!m_layoutsController->inMultipleMode()) {
//! Single Layout mode
setTwinProperty(m_pauseLayoutAction, TWINVISIBLE, false);
} else {
setTwinProperty(m_pauseLayoutAction, TWINVISIBLE, true);
if (selectedLayout.isActive
&& !selectedLayout.isForFreeActivities()
&& !selectedLayout.isShared()) {
setTwinProperty(m_pauseLayoutAction, TWINENABLED, true);
} else {
setTwinProperty(m_pauseLayoutAction, TWINENABLED, false);
}
}
//! Remove Layout Button
/* if (selectedLayout.isActive || selectedLayout.isLocked) {
m_ui->removeButton->setEnabled(false);
} else {
m_ui->removeButton->setEnabled(true);
}*/
//! Layout Locked Button
if (selectedLayout.isLocked) {
setTwinProperty(m_lockedLayoutAction, TWINCHECKED, true);
} else {
setTwinProperty(m_lockedLayoutAction, TWINCHECKED, false);
}
//! UI Elements that need to be enabled/disabled
if (m_layoutsController->inMultipleMode()) {
setTwinProperty(m_sharedLayoutAction, TWINVISIBLE, true);
} else {
setTwinProperty(m_sharedLayoutAction, TWINVISIBLE, false);
}
//! Layout Shared Button
if (selectedLayout.isShared()) {
setTwinProperty(m_sharedLayoutAction, TWINCHECKED, true);
} else {
setTwinProperty(m_sharedLayoutAction, TWINCHECKED, false);
}
}
void SettingsDialog::showLayoutInformation() void SettingsDialog::showLayoutInformation()
{ {
/* int currentRow = m_ui->layoutsView->currentIndex().row(); /* int currentRow = m_ui->layoutsView->currentIndex().row();
@ -1099,8 +525,8 @@ void SettingsDialog::dropEvent(QDropEvent *event)
QString layoutPath = urlList[i].path(); QString layoutPath = urlList[i].path();
if (layoutPath.endsWith(".layout.latte")) { if (layoutPath.endsWith(".layout.latte")) {
Settings::Data::Layout importedlayout = m_layoutsController->addLayoutForFile(layoutPath); // Settings::Data::Layout importedlayout = m_layoutsController->addLayoutForFile(layoutPath);
layoutNames << importedlayout.name; // layoutNames << importedlayout.name;
} }
} }
@ -1122,7 +548,7 @@ void SettingsDialog::keyPressEvent(QKeyEvent *event)
if (m_ui->messageWidget->isVisible()) { if (m_ui->messageWidget->isVisible()) {
m_hideInlineMessageTimer.stop(); m_hideInlineMessageTimer.stop();
m_ui->messageWidget->animatedHide(); m_ui->messageWidget->animatedHide();
m_ui->messageWidget->removeAction(m_openUrlAction); clearCurrentMessageActions();
return; return;
} }
} }
@ -1132,8 +558,8 @@ void SettingsDialog::keyPressEvent(QKeyEvent *event)
void SettingsDialog::keyReleaseEvent(QKeyEvent *event) void SettingsDialog::keyReleaseEvent(QKeyEvent *event)
{ {
if (event && event->key() == Qt::Key_Delete && currentPage() == Types::LayoutPage){ if (event && currentPage() == Types::LayoutPage){
on_remove_layout(); m_tabLayoutsHandler->on_keyReleaseEvent(event);
} }
QDialog::keyReleaseEvent(event); QDialog::keyReleaseEvent(event);
@ -1146,21 +572,40 @@ void SettingsDialog::updateWindowActivities()
} }
} }
void SettingsDialog::saveAllChanges() void SettingsDialog::save()
{ {
if (currentPage() == Latte::Types::LayoutPage) { if (currentPage() == Latte::Types::LayoutPage) {
m_layoutsController->save(); m_tabLayoutsHandler->save();
} else if (currentPage() == Latte::Types::PreferencesPage) { } else if (currentPage() == Latte::Types::PreferencesPage) {
m_preferencesHandler->save(); m_preferencesHandler->save();
} }
} }
void SettingsDialog::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval) void SettingsDialog::clearCurrentMessageActions()
{
while(m_currentMessageActions.count() > 0) {
QAction *action = m_currentMessageActions.takeAt(0);
m_ui->messageWidget->removeAction(action);
action->deleteLater();
}
}
void SettingsDialog::showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval, QList<QAction *> actions)
{ {
if (msg.isEmpty()) { if (msg.isEmpty()) {
return; return;
} }
if (!m_currentMessageActions.isEmpty()) {
clearCurrentMessageActions();
}
m_currentMessageActions = actions;
for (int i=0; i<actions.count(); ++i) {
m_ui->messageWidget->addAction(actions[i]);
}
m_hideInlineMessageTimer.stop(); m_hideInlineMessageTimer.stop();
if (m_ui->messageWidget->isVisible()) { if (m_ui->messageWidget->isVisible()) {

@ -70,16 +70,16 @@ public:
Latte::Corona *corona() const; Latte::Corona *corona() const;
Ui::SettingsDialog *ui() const; Ui::SettingsDialog *ui() const;
QMenuBar *appMenuBar() const;
Types::LatteConfigPage currentPage(); Types::LatteConfigPage currentPage();
void toggleCurrentPage();
void setCurrentPage(int page); void setCurrentPage(int page);
void toggleCurrentPage();
void requestImagesDialog(int row); void requestImagesDialog(int row);
void requestColorsDialog(int row); void requestColorsDialog(int row);
void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0); void showInlineMessage(const QString &msg, const KMessageWidget::MessageType &type, const int &hideInterval = 0, QList<QAction *> actions = QList<QAction *>());
protected: protected:
void dragEnterEvent(QDragEnterEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override;
@ -88,22 +88,9 @@ protected:
void keyReleaseEvent(QKeyEvent *event) override; void keyReleaseEvent(QKeyEvent *event) override;
private slots: private slots:
void on_currentPageChanged(int page);
void on_import_fullconfiguration(); void on_import_fullconfiguration();
void on_export_fullconfiguration(); void on_export_fullconfiguration();
void on_new_layout();
void on_copy_layout();
void on_download_layout();
void on_pause_layout();
void on_remove_layout();
void on_switch_layout();
void on_import_layout();
void on_export_layout();
void on_locked_layout();
void on_shared_layout();
void accept() override; void accept() override;
void apply(); void apply();
@ -112,38 +99,27 @@ private slots:
void showLayoutInformation(); void showLayoutInformation();
void showScreensInformation(); void showScreensInformation();
void updateApplyButtonsState(); void updateApplyButtonsState();
void updatePerLayoutButtonsState();
void updateWindowActivities(); void updateWindowActivities();
private: void clearCurrentMessageActions();
void loadSettings();
private:
void initGlobalMenu(); void initGlobalMenu();
void initLayoutMenu(); void initLayoutMenu();
void initFileMenu(); void initFileMenu();
void initHelpMenu(); void initHelpMenu();
void setTwinProperty(QAction *action, const QString &property, QVariant value); void save();
void twinActionWithButton(QPushButton *button, QAction *action);
void saveAllChanges();
void setCurrentFreeActivitiesLayout(const int &row); void setCurrentFreeActivitiesLayout(const int &row);
QList<int> currentSettings();
private: private:
Latte::Corona *m_corona{nullptr}; Latte::Corona *m_corona{nullptr};
Ui::SettingsDialog *m_ui; Ui::SettingsDialog *m_ui;
Settings::Controller::Layouts *m_layoutsController{nullptr};
//! Handlers for UI //! Handlers for UI
Settings::Handler::TabLayouts *m_tabLayoutsHandler{nullptr}; Settings::Handler::TabLayouts *m_tabLayoutsHandler{nullptr};
Settings::Handler::Preferences *m_preferencesHandler{nullptr}; Settings::Handler::Preferences *m_preferencesHandler{nullptr};
QButtonGroup *m_inMemoryButtons;
QButtonGroup *m_mouseSensitivityButtons;
QAction *m_openUrlAction{nullptr};
//! Global menu //! Global menu
QMenuBar *m_globalMenuBar{nullptr}; QMenuBar *m_globalMenuBar{nullptr};
@ -152,26 +128,12 @@ private:
QAction *m_importFullAction{nullptr}; QAction *m_importFullAction{nullptr};
QAction *m_exportFullAction{nullptr}; QAction *m_exportFullAction{nullptr};
//! Layout menu actions
QMenu *m_layoutMenu{nullptr};
QAction *m_switchLayoutAction{nullptr};
QAction *m_pauseLayoutAction{nullptr};
QAction *m_newLayoutAction{nullptr};
QAction *m_copyLayoutAction{nullptr};
QAction *m_removeLayoutAction{nullptr};
QAction *m_lockedLayoutAction{nullptr};
QAction *m_sharedLayoutAction{nullptr};
QAction *m_importLayoutAction{nullptr};
QAction *m_exportLayoutAction{nullptr};
QAction *m_downloadLayoutAction{nullptr};
QAction *m_editLayoutAction{nullptr};
//! Twin Actions bind QAction* behavior with QPushButton*
QHash<QAction *, QPushButton *> m_twinActions;
//! Help menu actions //! Help menu actions
KHelpMenu *m_helpMenu{nullptr}; KHelpMenu *m_helpMenu{nullptr};
//! Current shown KMessageActions
QList<QAction *> m_currentMessageActions;
//! workaround to assign ALLACTIVITIES during startup //! workaround to assign ALLACTIVITIES during startup
QTimer m_activitiesTimer; QTimer m_activitiesTimer;
//! Timer to hide the inline message widget //! Timer to hide the inline message widget

Loading…
Cancel
Save