1 /*
2     SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com>
3     SPDX-License-Identifier: GPL-2.0-or-later
4 */
5 
6 #ifndef SETTINGSTABLAYOUTSHANDLER_H
7 #define SETTINGSTABLAYOUTSHANDLER_H
8 
9 //! local
10 #include "../generic/generichandler.h"
11 #include "../../data/layoutdata.h"
12 
13 //! Qt
14 #include <QAction>
15 #include <QButtonGroup>
16 #include <QMenu>
17 
18 //!
19 #include <KConfigGroup>
20 
21 namespace Ui {
22 class SettingsDialog;
23 }
24 
25 namespace Latte {
26 class Corona;
27 
28 namespace Settings {
29 namespace Controller {
30 class Layouts;
31 }
32 
33 namespace Dialog{
34 class SettingsDialog;
35 }
36 
37 }
38 }
39 
40 namespace Latte {
41 namespace Settings {
42 namespace Handler {
43 
44 //! Handlers are objects to handle the UI elements that semantically associate with specific
45 //! ui::tabs or different windows. They are responsible also to handle the user interaction
46 //! between controllers and views
47 
48 class TabLayouts : public Generic
49 {
50     Q_OBJECT
51 public:
52     TabLayouts(Dialog::SettingsDialog *parent);
53     ~TabLayouts();
54 
55     bool hasChangedData() const override;
56     bool inDefaultValues() const override;
57     bool isCurrentTab() const;
58 
59     bool isViewsDialogVisible() const;
60 
61     Latte::Corona *corona() const;
62     Dialog::SettingsDialog *dialog() const;
63     Ui::SettingsDialog *ui() const;
64     Controller::Layouts *layoutsController() const;
65 
66 public slots:
67     void onDragEnterEvent(QDragEnterEvent *event);
68     void onDragLeaveEvent(QDragLeaveEvent *event);
69     void onDragMoveEvent(QDragMoveEvent *event);
70     void onDropEvent(QDropEvent *event);
71 
72     void showViewsDialog();
73 
74     void reset() override;
75     void resetDefaults() override;
76     void save() override;
77 
78 signals:
79     void currentPageChanged();
80 
81 private slots:
82     void initUi();
83     void initLayoutMenu();
84 
85     void loadConfig();
86     void saveConfig();
87 
88     void downloadLayout();
89     void duplicateLayout();
90     void switchLayout();
91     void importLayout();
92     void exportLayoutForBackup();
93     void exportLayoutAsTemplate();
94     void lockLayout();
95     void removeLayout();
96     void toggleActivitiesManager();
97     void toggleEnabledLayout();
98     void showDetailsDialog();
99 
100     void onCurrentPageChanged();
101     void onLayoutFilesDropped(const QStringList &paths);
102     void onRawLayoutDropped(const QString &rawLayout);
103     void updatePerLayoutButtonsState();
104 
105     void newLayout(const QString &templateName);
106 
107 private:
108     bool isHoveringLayoutsTable(const QPoint &pos);
109 
110     void initLayoutTemplatesSubMenu();
111     void initImportLayoutSubMenu();
112     void initExportLayoutSubMenu();
113 
114 private:
115     Settings::Dialog::SettingsDialog *m_parentDialog{nullptr};
116     Ui::SettingsDialog *m_ui{nullptr};
117     Latte::Corona *m_corona{nullptr};
118 
119     Settings::Controller::Layouts *m_layoutsController{nullptr};
120 
121     KConfigGroup m_storage;
122 
123     bool m_isViewsDialogVisible{false};
124 
125     QButtonGroup *m_inMemoryButtons;
126 
127     //! Layout menu actions
128     QMenu *m_layoutMenu{nullptr};
129     QMenu *m_layoutTemplatesSubMenu{nullptr};
130     QMenu *m_layoutImportSubMenu{nullptr};
131     QMenu *m_layoutExportSubMenu{nullptr};
132 
133     QAction *m_switchLayoutAction{nullptr};
134     QAction *m_activitiesManagerAction{nullptr};
135     QAction *m_newLayoutAction{nullptr};
136     QAction *m_duplicateLayoutAction{nullptr};
137     QAction *m_enabledLayoutAction{nullptr};
138     QAction *m_readOnlyLayoutAction{nullptr};
139     QAction *m_removeLayoutAction{nullptr};
140     QAction *m_importLayoutAction{nullptr};
141     QAction *m_exportLayoutAction{nullptr};
142     QAction *m_detailsAction{nullptr};
143     QAction *m_viewsAction{nullptr};
144 };
145 
146 }
147 }
148 }
149 
150 #endif
151