File indexing completed on 2024-10-06 13:22:23
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 IMPORTER_H 0022 #define IMPORTER_H 0023 0024 // Qt 0025 #include <QObject> 0026 0027 namespace Latte { 0028 namespace Layouts { 0029 class Manager; 0030 } 0031 } 0032 0033 namespace Latte { 0034 namespace Layouts { 0035 0036 //! This class is responsible to import/export configurations 0037 //! and of course to import old configuration to new architecture 0038 class Importer : public QObject 0039 { 0040 Q_OBJECT 0041 0042 public: 0043 enum LatteFileVersion 0044 { 0045 UnknownFileType = -1, 0046 LayoutVersion1 = 0, 0047 ConfigVersion1 = 1, 0048 LayoutVersion2 = 2, 0049 ConfigVersion2 = 3 0050 }; 0051 Q_ENUM(LatteFileVersion); 0052 0053 Importer(QObject *parent = nullptr); 0054 ~Importer() override; 0055 0056 //! updates the old configuration to version: 2 0057 bool updateOldConfiguration(); 0058 0059 //! imports an old layout file, 0060 //! newName: the layout new name, if it is empty the original is used 0061 //! alternative: old files can contain both a Default and an Alternative layout 0062 //! false: imports only Default layout 0063 //! true: imports only Alternative layout 0064 bool importOldLayout(QString oldAppletsPath, QString newName, bool alternative = false, QString exportDirectory = QString()); 0065 0066 //! imports and old configuration file (tar archive) that contains 0067 //! both an applets file and a latterc file with the screens 0068 //! newName: if it is empty the name is extracted from the old config file name 0069 bool importOldConfiguration(QString oldConfigPath, QString newName = QString()); 0070 0071 bool exportFullConfiguration(QString file); 0072 0073 static Importer::LatteFileVersion fileVersion(QString file); 0074 0075 static bool importHelper(QString fileName); 0076 0077 //! returns the standard path found that contains the subPath 0078 //! local paths have higher priority by default 0079 static QString standardPath(QString subPath, bool localFirst = true); 0080 //! returns all application data standard paths 0081 //! local paths have higher priority by default 0082 static QStringList standardPaths(bool localfirst = true); 0083 static QStringList standardPathsFor(QString subPath, bool localfirst = true); 0084 0085 //! check if this layout exists already in the latte directory 0086 static bool layoutExists(QString layoutName); 0087 //! imports the specific layout and return the new layout name. 0088 //! if the function didn't succeed return an empty string 0089 static QString importLayoutHelper(QString fileName); 0090 0091 //! return the file path of a layout either existing or not 0092 static QString layoutFilePath(QString layoutName); 0093 static QString nameOfConfigFile(const QString &fileName); 0094 static QString uniqueLayoutName(QString name); 0095 0096 static QStringList availableLayouts(); 0097 //! it checks the linked file if there are Containments in it that belong 0098 //! to Original Layouts and moves them accordingly. This is used mainly on 0099 //! startup and if such state occurs, it basically means that the app didn't 0100 //! close correctly, e.g. there was a crash. 0101 static QStringList checkRepairMultipleLayoutsLinkedFile(); 0102 0103 private: 0104 //! checks if this old layout can be imported. If it can it returns 0105 //! the new layout path and an empty string if it cant 0106 QString layoutCanBeImported(QString oldAppletsPath, QString newName, QString exportDirectory = QString()); 0107 0108 Layouts::Manager *m_manager; 0109 }; 0110 0111 } 0112 } 0113 0114 #endif // IMPORTER_H