1 /*
2     SPDX-FileCopyrightText: 2017 Smith AR <audoban@openmailbox.org>
3     SPDX-FileCopyrightText: 2017 Michail Vourlakos <mvourlakos@gmail.com>
4 
5     SPDX-License-Identifier: GPL-2.0-or-later
6 */
7 
8 #ifndef LAYOUTSMANAGER_H
9 #define LAYOUTSMANAGER_H
10 
11 // local
12 #include "syncedlaunchers.h"
13 #include "synchronizer.h"
14 #include "../apptypes.h"
15 #include "../data/layoutdata.h"
16 #include "../data/layouticondata.h"
17 #include "../settings/settingsdialog/settingsdialog.h"
18 
19 // Qt
20 #include <QAction>
21 #include <QObject>
22 #include <QPointer>
23 
24 // KDE
25 #include <KLocalizedString>
26 
27 namespace Plasma {
28 class Containment;
29 class Types;
30 }
31 
32 namespace Latte {
33 class Corona;
34 class CentralLayout;
35 namespace Layouts {
36 class Importer;
37 class SyncedLaunchers;
38 class Synchronizer;
39 }
40 }
41 
42 namespace Latte {
43 namespace Layouts {
44 
45 //! Layouts::Manager is a very IMPORTANT class which is responsible to
46 //! to provide the qml accessible Layouts manipulation API and at the
47 //! same time to interact with Latte::Corona in order
48 //! to update correctly the underlying Layouts files by using also
49 //! its Importer object
50 //!
51 //! This class is responsible both for ACTIVE/PASSIVE Layouts.
52 //!
53 //! ACTIVE Layout is consider one layout that is loaded and active in memory
54 //! PASSIVE Layouts is consider one layout that is not loaded/active in memory
55 //! and its properties are just stored in the filesystem
56 //!
57 
58 class Manager : public QObject
59 {
60     Q_OBJECT
61     Q_PROPERTY(SyncedLaunchers *syncedLaunchers READ syncedLaunchers NOTIFY syncedLaunchersChanged)
62 
63 public:
64     Manager(QObject *parent = nullptr);
65     ~Manager() override;
66 
67     Latte::Corona *corona();
68     Importer *importer();
69 
70     void init();
71     void loadLayoutOnStartup(QString layoutName);
72     void setOnAllActivities(QString layoutName);
73     void setOnActivities(QString layoutName, QStringList activities);
74     void showInfoWindow(QString info, int duration, QStringList activities = {"0"});
75     void unload();
76 
77     QStringList currentLayoutsNames() const;
78 
79     Latte::Data::LayoutIcon iconForLayout(const QString &storedLayoutName) const;
80     Latte::Data::LayoutIcon iconForLayout(const Data::Layout &layout) const;
81 
82     MemoryUsage::LayoutsMemory memoryUsage() const;
83     void setMemoryUsage(MemoryUsage::LayoutsMemory memoryUsage);
84 
85     //! switch to specified layout, default previousMemoryUsage means that it didn't change
86     bool switchToLayout(QString layoutName,  MemoryUsage::LayoutsMemory newMemoryUsage = MemoryUsage::Current);
87 
88     //! returns the current and central layout based on activities and user preferences
89     QList<CentralLayout *>currentLayouts() const;
90     SyncedLaunchers *syncedLaunchers() const;
91     Synchronizer *synchronizer() const;
92 
93     void moveView(QString originLayoutName, uint originViewId, QString destinationLayoutName);
94 
95 public slots:
96     void showAboutDialog();
97 
98     void hideLatteSettingsDialog();
99     Q_INVOKABLE void showLatteSettingsDialog(int firstPage = Settings::Dialog::LayoutPage, bool toggleCurrentPage = false);
100     Q_INVOKABLE QStringList centralLayoutsNames();
101     Q_INVOKABLE QStringList viewTemplateNames() const;
102     Q_INVOKABLE QStringList viewTemplateIds() const;
103 
104 signals:
105     void centralLayoutsChanged();
106     void syncedLaunchersChanged();
107     void viewTemplatesChanged();
108 
109     void currentLayoutIsSwitching(QString layoutName);
110 
111     //! used from ConfigView(s) in order to be informed which is one should be shown
112     void lastConfigViewChangedFrom(Latte::View *view);
113 
114 private:
115     void cleanupOnStartup(QString path); //!remove deprecated or oldstyle config options
116     void clearUnloadedContainmentsFromLinkedFile(QStringList containmentsIds, bool bypassChecks = false);
117 
118     void loadLatteLayout(QString layoutPath);
119 
120     void setMenuLayouts(QStringList layouts);
121 
122 private:
123     QPointer<Latte::Settings::Dialog::SettingsDialog> m_latteSettingsDialog;
124 
125     Latte::Corona *m_corona{nullptr};
126     Importer *m_importer{nullptr};
127     SyncedLaunchers *m_syncedLaunchers{nullptr};
128     Synchronizer *m_synchronizer{nullptr};
129 
130     friend class Latte::Settings::Dialog::SettingsDialog;
131     friend class Synchronizer;
132 };
133 
134 }
135 }
136 
137 #endif // LAYOUTSMANAGER_H
138