File indexing completed on 2024-04-21 16:17:09
0001 /* 0002 * Copyright 2017 Smith AR <audoban@openmailbox.org> 0003 * Michail Vourlakos <mvourlakos@gmail.com> 0004 * 0005 * This file is part of Latte-Dock 0006 * 0007 * Latte-Dock is free software; you can redistribute it and/or 0008 * modify it under the terms of the GNU General Public License as 0009 * published by the Free Software Foundation; either version 2 of 0010 * the License, or (at your option) any later version. 0011 * 0012 * Latte-Dock is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0015 * GNU General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU General Public License 0018 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 0021 #ifndef LAYOUTSMANAGER_H 0022 #define LAYOUTSMANAGER_H 0023 0024 // local 0025 #include "launcherssignals.h" 0026 #include "synchronizer.h" 0027 #include "settings/settingsdialog.h" 0028 0029 // Qt 0030 #include <QAction> 0031 #include <QObject> 0032 #include <QPointer> 0033 0034 // KDE 0035 #include <KLocalizedString> 0036 0037 namespace Plasma { 0038 class Containment; 0039 class Types; 0040 } 0041 0042 namespace Latte { 0043 class Corona; 0044 class CentralLayout; 0045 namespace Layouts { 0046 class Importer; 0047 class LaunchersSignals; 0048 class Synchronizer; 0049 } 0050 } 0051 0052 namespace Latte { 0053 namespace Layouts { 0054 0055 //! Layouts::Manager is a very IMPORTANT class which is responsible to 0056 //! to provide the qml accessible Layouts manipulation API and at the 0057 //! same time to interact with Latte::Corona in order 0058 //! to update correctly the underlying Layouts files by using also 0059 //! its Importer object 0060 //! 0061 //! This class is responsible both for ACTIVE/PASSIVE Layouts. 0062 //! 0063 //! ACTIVE Layout is consider one layout that is loaded and active in memory 0064 //! PASSIVE Layouts is consider one layout that is not loaded/active in memory 0065 //! and its properties are just stored in the filesystem 0066 //! 0067 0068 class Manager : public QObject 0069 { 0070 Q_OBJECT 0071 0072 Q_PROPERTY(QString currentLayoutName READ currentLayoutName NOTIFY currentLayoutNameChanged) 0073 0074 Q_PROPERTY(QStringList layouts READ layouts NOTIFY layoutsChanged) 0075 Q_PROPERTY(QStringList menuLayouts READ menuLayouts NOTIFY menuLayoutsChanged) 0076 0077 Q_PROPERTY(LaunchersSignals *launchersSignals READ launchersSignals NOTIFY launchersSignalsChanged) 0078 0079 public: 0080 Manager(QObject *parent = nullptr); 0081 ~Manager() override; 0082 0083 Latte::Corona *corona(); 0084 Importer *importer(); 0085 0086 void load(); 0087 void loadLayoutOnStartup(QString layoutName); 0088 void showInfoWindow(QString info, int duration, QStringList activities = {"0"}); 0089 void unload(); 0090 0091 QString currentLayoutName() const; 0092 QString defaultLayoutName() const; 0093 0094 QStringList layouts() const; 0095 QStringList menuLayouts() const; 0096 QStringList presetsPaths() const; 0097 QStringList storedSharedLayouts() const; 0098 0099 Types::LayoutsMemoryUsage memoryUsage() const; 0100 void setMemoryUsage(Types::LayoutsMemoryUsage memoryUsage); 0101 0102 //! returns the current and central layout based on activities and user preferences 0103 CentralLayout *currentLayout() const; 0104 LaunchersSignals *launchersSignals() const; 0105 Synchronizer *synchronizer() const; 0106 0107 void importDefaultLayout(bool newInstanceIfPresent = false); 0108 void importPresets(bool includeDefault = false); 0109 0110 public slots: 0111 void showAboutDialog(); 0112 0113 void hideLatteSettingsDialog(); 0114 Q_INVOKABLE void showLatteSettingsDialog(int page = Latte::Types::LayoutPage); 0115 0116 //! switch to specified layout, default previousMemoryUsage means that it didn't change 0117 Q_INVOKABLE bool switchToLayout(QString layoutName, int previousMemoryUsage = -1); 0118 0119 Q_INVOKABLE int layoutsMemoryUsage(); 0120 0121 //! creates a new layout with layoutName based on the preset 0122 Q_INVOKABLE QString newLayout(QString layoutName, QString preset = i18n("Default")); 0123 0124 Q_INVOKABLE QStringList centralLayoutsNames(); 0125 Q_INVOKABLE QStringList sharedLayoutsNames(); 0126 0127 signals: 0128 void centralLayoutsChanged(); 0129 void currentLayoutChanged(); 0130 void currentLayoutNameChanged(); 0131 void launchersSignalsChanged(); 0132 void layoutsChanged(); 0133 void menuLayoutsChanged(); 0134 0135 void currentLayoutIsSwitching(QString layoutName); 0136 0137 private: 0138 void cleanupOnStartup(QString path); //!remove deprecated or oldstyle config options 0139 void clearUnloadedContainmentsFromLinkedFile(QStringList containmentsIds, bool bypassChecks = false); 0140 0141 //! it is used just in order to provide translations for the presets 0142 void ghostForTranslatedPresets(); 0143 0144 void importPreset(int presetNo, bool newInstanceIfPresent = false); 0145 void loadLatteLayout(QString layoutPath); 0146 0147 void setMenuLayouts(QStringList layouts); 0148 0149 private: 0150 QStringList m_presetsPaths; 0151 0152 QPointer<Latte::SettingsDialog> m_latteSettingsDialog; 0153 0154 Latte::Corona *m_corona{nullptr}; 0155 Importer *m_importer{nullptr}; 0156 LaunchersSignals *m_launchersSignals{nullptr}; 0157 Synchronizer *m_synchronizer{nullptr}; 0158 0159 friend class Latte::SettingsDialog; 0160 friend class Synchronizer; 0161 }; 0162 0163 } 0164 } 0165 0166 #endif // LAYOUTSMANAGER_H