File indexing completed on 2024-04-21 05:31:01

0001 /*
0002     SPDX-FileCopyrightText: 2021 Michail Vourlakos <mvourlakos@gmail.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 #ifndef VIEWSDIALOGHANDLER_H
0007 #define VIEWSDIALOGHANDLER_H
0008 
0009 // local
0010 #include "../generic/generichandler.h"
0011 #include "../../data/layoutdata.h"
0012 #include "../../layout/abstractlayout.h"
0013 
0014 // Qt
0015 #include <QAction>
0016 #include <QButtonGroup>
0017 #include <QMenu>
0018 #include <QSortFilterProxyModel>
0019 
0020 // KDE
0021 #include <KMessageBox>
0022 
0023 namespace Ui {
0024 class ViewsDialog;
0025 }
0026 
0027 namespace Latte{
0028 class CentralLayout;
0029 class Corona;
0030 namespace Settings{
0031 namespace Controller{
0032 class Layouts;
0033 class Views;
0034 }
0035 namespace Dialog{
0036 class ViewsDialog;
0037 }
0038 }
0039 }
0040 
0041 
0042 namespace Latte {
0043 namespace Settings {
0044 namespace Handler {
0045 
0046 //! Handlers are objects to handle the UI elements that semantically associate with specific
0047 //! ui::tabs or different windows. They are responsible also to handle the user interaction
0048 //! between controllers and views
0049 
0050 class ViewsHandler : public Generic
0051 {
0052     Q_OBJECT
0053 public:
0054     ViewsHandler(Dialog::ViewsDialog *dialog);
0055     ~ViewsHandler();
0056 
0057     bool hasChangedData() const override;
0058     bool inDefaultValues() const override;
0059 
0060     bool isSelectedLayoutOriginal() const;
0061 
0062     Latte::Data::Layout currentData() const;
0063     Latte::Data::Layout originalData() const;
0064 
0065     Ui::ViewsDialog *ui() const;
0066     Latte::Corona *corona() const;
0067     Settings::Controller::Layouts *layoutsController() const;
0068 
0069 public slots:
0070     void reset() override;
0071     void resetDefaults() override;
0072     void save() override;
0073 
0074 signals:
0075     void currentLayoutChanged();
0076 
0077 private slots:
0078     void initViewTemplatesSubMenu();
0079     void initViewExportSubMenu();
0080     void removeSelectedViews();
0081     void updateWindowTitle();
0082 
0083     void exportViewForBackup();
0084     void exportViewAsTemplate();
0085     void importView();
0086 
0087     void onCurrentLayoutIndexChanged(int row);
0088     void onSelectionChanged();
0089 
0090     void newView(const Data::Generic &templateData);
0091 
0092 private:
0093     void init();
0094 
0095     void reload();
0096 
0097     void loadLayout(const Latte::Data::Layout &data);
0098 
0099     QString storedView(const QString &viewId);
0100 
0101     KMessageBox::ButtonCode saveChangesConfirmation();
0102     KMessageBox::ButtonCode removalConfirmation(const int &count);
0103 
0104 private:
0105     Dialog::ViewsDialog *m_dialog{nullptr};
0106     Ui::ViewsDialog *m_ui{nullptr};
0107     Settings::Controller::Views *m_viewsController{nullptr};
0108 
0109     QSortFilterProxyModel *m_layoutsProxyModel{nullptr};
0110 
0111     Latte::Data::Layout o_data;
0112 
0113     int m_lastConfirmedLayoutIndex{-1};
0114 
0115     //! Actions
0116     QAction *m_newViewAction{nullptr};
0117     QAction *m_duplicateViewAction{nullptr};
0118     QAction *m_removeViewAction{nullptr};
0119     QAction *m_exportViewAction{nullptr};
0120     QAction *m_importViewAction{nullptr};
0121 
0122     //! Menus
0123     QMenu *m_viewTemplatesSubMenu{nullptr};
0124     QMenu *m_viewExportSubMenu{nullptr};
0125 };
0126 
0127 }
0128 }
0129 }
0130 
0131 #endif