From a45b97a2b13ff01d64117c594090d30461edb03a Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 7 Feb 2021 12:53:10 +0200 Subject: [PATCH] provide basic implementation of ExportTemplateDlg --- app/data/appletdata.cpp | 5 + app/data/appletdata.h | 1 + app/settings/dialogs/exporttemplatedialog.cpp | 14 ++- app/settings/dialogs/exporttemplatedialog.h | 18 +++- app/settings/dialogs/exporttemplatedialog.ui | 37 +------ app/settings/handlers/CMakeLists.txt | 1 + .../handlers/exporttemplatehandler.cpp | 100 ++++++++++++++++++ app/settings/handlers/exporttemplatehandler.h | 97 +++++++++++++++++ app/settings/handlers/tablayoutshandler.cpp | 8 ++ app/settings/models/appletsmodel.cpp | 22 ++++ app/settings/models/appletsmodel.h | 15 ++- 11 files changed, 278 insertions(+), 40 deletions(-) create mode 100644 app/settings/handlers/exporttemplatehandler.cpp create mode 100644 app/settings/handlers/exporttemplatehandler.h diff --git a/app/data/appletdata.cpp b/app/data/appletdata.cpp index c51a83aa7..c3dcd8656 100644 --- a/app/data/appletdata.cpp +++ b/app/data/appletdata.cpp @@ -66,6 +66,11 @@ Applet &Applet::operator=(Applet &&rhs) return (*this); } +bool Applet::isInstalled() const +{ + return isValid() && id != name; +} + bool Applet::isValid() const { return !id.isEmpty() && !name.isEmpty(); diff --git a/app/data/appletdata.h b/app/data/appletdata.h index 57ca198d5..b7ba12b8c 100644 --- a/app/data/appletdata.h +++ b/app/data/appletdata.h @@ -48,6 +48,7 @@ public: Applet &operator=(const Applet &rhs); Applet &operator=(Applet &&rhs); + bool isInstalled() const; bool isValid() const; }; diff --git a/app/settings/dialogs/exporttemplatedialog.cpp b/app/settings/dialogs/exporttemplatedialog.cpp index 09e97acc2..bca4eeacb 100644 --- a/app/settings/dialogs/exporttemplatedialog.cpp +++ b/app/settings/dialogs/exporttemplatedialog.cpp @@ -22,18 +22,23 @@ // local #include "ui_exporttemplatedialog.h" +#include "../controllers/layoutscontroller.h" +#include "../handlers/exporttemplatehandler.h" namespace Latte { namespace Settings { namespace Dialog { -ExportTemplateDialog::ExportTemplateDialog(SettingsDialog *parent) +ExportTemplateDialog::ExportTemplateDialog(SettingsDialog *parent, Controller::Layouts *controller) : GenericDialog(parent), m_parentDlg(parent), - m_ui(new Ui::ExportTemplateDialog) + m_ui(new Ui::ExportTemplateDialog), + m_layoutsController(controller) { //! first we need to setup the ui m_ui->setupUi(this); + //! we must create handlers after creating/adjusting the ui + m_handler = new Handler::ExportTemplateHandler(this); } ExportTemplateDialog::~ExportTemplateDialog() @@ -50,6 +55,11 @@ Latte::Corona *ExportTemplateDialog::corona() const return m_parentDlg->corona(); } +Controller::Layouts *ExportTemplateDialog::layoutsController() const +{ + return m_layoutsController; +} + void ExportTemplateDialog::accept() { qDebug() << Q_FUNC_INFO; diff --git a/app/settings/dialogs/exporttemplatedialog.h b/app/settings/dialogs/exporttemplatedialog.h index 573f63d6b..e58b3f1ea 100644 --- a/app/settings/dialogs/exporttemplatedialog.h +++ b/app/settings/dialogs/exporttemplatedialog.h @@ -33,6 +33,18 @@ namespace Ui { class ExportTemplateDialog; } +namespace Latte { +namespace Settings { +namespace Controller { +class Layouts; +} +namespace Handler { +class ExportTemplateHandler; +} +} +} + + namespace Latte { namespace Settings { namespace Dialog { @@ -42,12 +54,13 @@ class ExportTemplateDialog : public GenericDialog Q_OBJECT public: - ExportTemplateDialog(SettingsDialog *parent); + ExportTemplateDialog(SettingsDialog *parent, Controller::Layouts *controller); ~ExportTemplateDialog(); Latte::Corona *corona() const; Ui::ExportTemplateDialog *ui() const; + Controller::Layouts *layoutsController() const; protected: void accept() override; @@ -58,6 +71,9 @@ private slots: private: SettingsDialog *m_parentDlg{nullptr}; Ui::ExportTemplateDialog *m_ui; + Controller::Layouts *m_layoutsController{nullptr}; + + Handler::ExportTemplateHandler *m_handler; }; } diff --git a/app/settings/dialogs/exporttemplatedialog.ui b/app/settings/dialogs/exporttemplatedialog.ui index ce6a66580..d9156c91f 100644 --- a/app/settings/dialogs/exporttemplatedialog.ui +++ b/app/settings/dialogs/exporttemplatedialog.ui @@ -45,7 +45,7 @@ - + @@ -80,38 +80,5 @@ - - - buttonBox - accepted() - DetailsDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - DetailsDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/app/settings/handlers/CMakeLists.txt b/app/settings/handlers/CMakeLists.txt index c7a248f7f..459757ef5 100644 --- a/app/settings/handlers/CMakeLists.txt +++ b/app/settings/handlers/CMakeLists.txt @@ -1,6 +1,7 @@ set(lattedock-app_SRCS ${lattedock-app_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/detailshandler.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/exporttemplatehandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/generichandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tabpreferenceshandler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/tablayoutshandler.cpp diff --git a/app/settings/handlers/exporttemplatehandler.cpp b/app/settings/handlers/exporttemplatehandler.cpp new file mode 100644 index 000000000..e41bacdbc --- /dev/null +++ b/app/settings/handlers/exporttemplatehandler.cpp @@ -0,0 +1,100 @@ +/* + * Copyright 2021 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#include "exporttemplatehandler.h" + +// local +#include "ui_exporttemplatedialog.h" +#include "../controllers/layoutscontroller.h" +#include "../dialogs/exporttemplatedialog.h" +#include "../models/appletsmodel.h" +#include "../../data/appletdata.h" +#include "../../layouts/storage.h" + +namespace Latte { +namespace Settings { +namespace Handler { + +ExportTemplateHandler::ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog) + : Generic(parentDialog), + m_parentDialog(parentDialog), + m_ui(m_parentDialog->ui()), + m_appletsModel(new Model::Applets(this, parentDialog->corona())) +{ + init(); +} + +ExportTemplateHandler::~ExportTemplateHandler() +{ +} + +void ExportTemplateHandler::init() +{ + //! Layouts + m_appletsProxyModel = new QSortFilterProxyModel(this); + m_appletsProxyModel->setSourceModel(m_appletsModel); + m_appletsProxyModel->setSortRole(Model::Applets::SORTINGROLE); + m_appletsProxyModel->setSortCaseSensitivity(Qt::CaseInsensitive); + m_appletsProxyModel->sort(Model::Applets::NAMECOLUMN, Qt::AscendingOrder); + + m_ui->appletsTable->setModel(m_appletsProxyModel); + + loadCurrentLayoutApplets(); +} + +void ExportTemplateHandler::loadCurrentLayoutApplets() +{ + Data::Layout o_layout = m_parentDialog->layoutsController()->selectedLayoutOriginalData(); + c_data = Latte::Layouts::Storage::self()->plugins(o_layout.id); + o_data = c_data; + + m_appletsModel->setData(c_data); +} + +bool ExportTemplateHandler::dataAreChanged() const +{ + return o_data != c_data; +} + +bool ExportTemplateHandler::inDefaultValues() const +{ + //nothing special + return true; +} + + +void ExportTemplateHandler::reset() +{ + c_data = o_data; +} + +void ExportTemplateHandler::resetDefaults() +{ + //do nothing +} + +void ExportTemplateHandler::save() +{ + //do nothing +} + +} +} +} diff --git a/app/settings/handlers/exporttemplatehandler.h b/app/settings/handlers/exporttemplatehandler.h new file mode 100644 index 000000000..aeff5720a --- /dev/null +++ b/app/settings/handlers/exporttemplatehandler.h @@ -0,0 +1,97 @@ +/* + * Copyright 2021 Michail Vourlakos + * + * This file is part of Latte-Dock + * + * Latte-Dock is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * Latte-Dock is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef EXPORTTEMPLATEHANDLER_H +#define EXPORTTEMPLATEHANDLER_H + +// local +#include "generichandler.h" +#include "../../data/appletdata.h" + +// Qt +#include +#include + +namespace Ui { +class ExportTemplateDialog; +} + +namespace Latte{ +namespace Settings{ +namespace Dialog{ +class ExportTemplateDialog; +} +} +} + +namespace Latte{ +namespace Settings{ +namespace Model { +class Applets; +} +} +} + + +namespace Latte { +namespace Settings { +namespace Handler { + +//! Handlers are objects to handle the UI elements that semantically associate with specific +//! ui::tabs or different windows. They are responsible also to handle the user interaction +//! between controllers and views + +class ExportTemplateHandler : public Generic +{ + Q_OBJECT +public: + ExportTemplateHandler(Dialog::ExportTemplateDialog *parentDialog); + ~ExportTemplateHandler(); + + bool dataAreChanged() const override; + bool inDefaultValues() const override; + + void reset() override; + void resetDefaults() override; + void save() override; + + Latte::Data::AppletsTable currentData() const; + +private: + void init(); + void loadCurrentLayoutApplets(); + +private: + Dialog::ExportTemplateDialog *m_parentDialog{nullptr}; + Ui::ExportTemplateDialog *m_ui{nullptr}; + + //! current data + Model::Applets *m_appletsModel{nullptr}; + QSortFilterProxyModel *m_appletsProxyModel{nullptr}; + + Latte::Data::AppletsTable o_data; + Latte::Data::AppletsTable c_data; +}; + +} +} +} + +#endif diff --git a/app/settings/handlers/tablayoutshandler.cpp b/app/settings/handlers/tablayoutshandler.cpp index b6e63f447..c2c6ae1ec 100644 --- a/app/settings/handlers/tablayoutshandler.cpp +++ b/app/settings/handlers/tablayoutshandler.cpp @@ -26,6 +26,7 @@ #include "../universalsettings.h" #include "../dialogs/detailsdialog.h" #include "../dialogs/settingsdialog.h" +#include "../dialogs/exporttemplatedialog.h" #include "../controllers/layoutscontroller.h" #include "../models/layoutsmodel.h" #include "../views/layoutstableview.h" @@ -555,6 +556,13 @@ void TabLayouts::exportLayoutAsTemplate() if (!m_layoutsController->hasSelectedLayout()) { return; } + + //! Update ALL active original layouts before exporting, + m_corona->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles(); + m_corona->universalSettings()->syncSettings(); + + Dialog::ExportTemplateDialog *exportDlg = new Dialog::ExportTemplateDialog(m_parentDialog, m_layoutsController); + exportDlg->exec(); } void TabLayouts::exportLayoutForBackup() diff --git a/app/settings/models/appletsmodel.cpp b/app/settings/models/appletsmodel.cpp index 3f33d8522..718ab2828 100644 --- a/app/settings/models/appletsmodel.cpp +++ b/app/settings/models/appletsmodel.cpp @@ -70,6 +70,26 @@ int Applets::row(const QString &id) return -1; } +void Applets::clear() +{ + if (m_appletsTable.rowCount() > 0) { + beginRemoveRows(QModelIndex(), 0, m_appletsTable.rowCount() - 1); + m_appletsTable.clear(); + endRemoveRows(); + } +} + +void Applets::setData(const Latte::Data::AppletsTable &applets) +{ + clear(); + + if (applets.rowCount() > 0) { + beginInsertRows(QModelIndex(), 0, applets.rowCount()-1); + m_appletsTable = applets; + endInsertRows(); + } +} + QVariant Applets::data(const QModelIndex &index, int role) const { const int row = index.row(); @@ -89,6 +109,8 @@ QVariant Applets::data(const QModelIndex &index, int role) const return m_appletsTable[row].icon; } else if (role == DESCRIPTIONROLE) { return m_appletsTable[row].description; + } else if (role == SORTINGROLE) { + return m_appletsTable[row].isInstalled() ? QString(1000 + m_appletsTable[row].name) : m_appletsTable[row].name; } return QVariant{}; diff --git a/app/settings/models/appletsmodel.h b/app/settings/models/appletsmodel.h index 6b1395a97..d4bb78403 100644 --- a/app/settings/models/appletsmodel.h +++ b/app/settings/models/appletsmodel.h @@ -41,12 +41,18 @@ public: enum AppletsRoles { IDROLE = Qt::UserRole + 1, - SELECTEDROLE, - ICONROLE, NAMEROLE, + ICONROLE, + SELECTEDROLE, + SORTINGROLE, DESCRIPTIONROLE }; + enum Columns + { + NAMECOLUMN = 0 + }; + explicit Applets(QObject *parent, Latte::Corona *corona); ~Applets(); @@ -58,6 +64,11 @@ public: QVariant data(const QModelIndex &index, int role) const override; + void setData(const Latte::Data::AppletsTable &applets); + +private: + void clear(); + private: Latte::Data::AppletsTable m_appletsTable;