File indexing completed on 2024-12-08 08:00:09
0001 /* 0002 SPDX-FileCopyrightText: 2020 Michail Vourlakos <mvourlakos@gmail.com> 0003 SPDX-License-Identifier: GPL-2.0-or-later 0004 */ 0005 0006 #ifndef TEMPLATESMANAGER_H 0007 #define TEMPLATESMANAGER_H 0008 0009 // local 0010 #include "../lattecorona.h" 0011 #include "../data/appletdata.h" 0012 #include "../data/layoutdata.h" 0013 #include "../data/layoutstable.h" 0014 #include "../data/genericbasictable.h" 0015 0016 // Qt 0017 #include <QObject> 0018 0019 // KDE 0020 #include <KLocalizedString> 0021 0022 namespace Latte { 0023 class Corona; 0024 class View; 0025 } 0026 0027 namespace Latte { 0028 namespace Templates { 0029 0030 const char DEFAULTLAYOUTTEMPLATENAME[] = "Default"; 0031 const char EMPTYLAYOUTTEMPLATENAME[] = "Empty"; 0032 0033 class Manager : public QObject 0034 { 0035 Q_OBJECT 0036 0037 public: 0038 Manager(Latte::Corona *corona = nullptr); 0039 ~Manager() override; 0040 0041 Latte::Corona *corona(); 0042 void init(); 0043 0044 bool hasCustomLayoutTemplate(const QString &templateName) const; 0045 bool hasLayoutTemplate(const QString &templateName) const; 0046 bool hasViewTemplate(const QString &templateName) const; 0047 0048 bool exportTemplate(const QString &originFile, const QString &destinationFile, const Data::AppletsTable &approvedApplets); 0049 bool exportTemplate(const Latte::View *view, const QString &destinationFile, const Data::AppletsTable &approvedApplets); 0050 0051 Data::Layout layoutTemplateForName(const QString &layoutName); 0052 0053 Data::LayoutsTable layoutTemplates(); 0054 Data::GenericBasicTable viewTemplates(); 0055 0056 //! creates a new layout with layoutName based on specific layout template and returns the new layout path 0057 QString newLayout(QString layoutName, QString layoutTemplate = i18n(DEFAULTLAYOUTTEMPLATENAME)); 0058 0059 QString proposedTemplateAbsolutePath(QString templateFilename); 0060 0061 QString viewTemplateFilePath(const QString templateName) const; 0062 0063 static QString templateName(const QString &filePath); 0064 0065 void importSystemLayouts(); 0066 void installCustomLayoutTemplate(const QString &templateFilePath); 0067 0068 signals: 0069 void newLayoutAdded(const QString &path); 0070 void layoutTemplatesChanged(); 0071 void viewTemplatesChanged(); 0072 0073 private slots: 0074 void onCustomTemplatesCountChanged(const QString &file); 0075 0076 private: 0077 void initLayoutTemplates(); 0078 void initViewTemplates(); 0079 0080 void initLayoutTemplates(const QString &path); 0081 void initViewTemplates(const QString &path); 0082 0083 void exposeTranslatedTemplateNames(); 0084 0085 QString uniqueLayoutTemplateName(QString name) const; 0086 QString uniqueViewTemplateName(QString name) const; 0087 0088 private: 0089 Latte::Corona *m_corona; 0090 0091 Data::LayoutsTable m_layoutTemplates; 0092 Data::GenericBasicTable m_viewTemplates; 0093 0094 }; 0095 0096 } 0097 } 0098 0099 #endif //TEMPLATESMANAGER_H