File indexing completed on 2022-11-29 15:04:02

0001 /*
0002     SPDX-FileCopyrightText: 2017 Smith AR <audoban@openmailbox.org>
0003     SPDX-FileCopyrightText: 2017 Michail Vourlakos <mvourlakos@gmail.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef IMPORTER_H
0009 #define IMPORTER_H
0010 
0011 // local
0012 #include "../apptypes.h"
0013 
0014 // Qt
0015 #include <QObject>
0016 #include <QTemporaryDir>
0017 
0018 namespace Latte {
0019 namespace Layouts {
0020 class Manager;
0021 }
0022 }
0023 
0024 namespace Latte {
0025 namespace Layouts {
0026 
0027 //! This class is responsible to import/export configurations
0028 //! and of course to import old configuration to new architecture
0029 class Importer : public QObject
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     enum LatteFileVersion
0035     {
0036         UnknownFileType = -1,
0037         LayoutVersion1 = 0,
0038         ConfigVersion1 = 1,
0039         LayoutVersion2 = 2,
0040         ConfigVersion2 = 3
0041     };
0042     Q_ENUM(LatteFileVersion);
0043 
0044     Importer(QObject *parent = nullptr);
0045     ~Importer() override;
0046 
0047     //! updates the old configuration to version: 2
0048     bool updateOldConfiguration();
0049 
0050     //! imports an old layout file,
0051     //! newName: the layout new name, if it is empty the original is used
0052     //! alternative: old files can contain both a Default and an Alternative layout
0053     //!    false: imports only Default layout
0054     //!    true: imports only Alternative layout
0055     bool importOldLayout(QString oldAppletsPath, QString newName, bool alternative = false, QString exportDirectory = QString());
0056 
0057     //! imports and old configuration file (tar archive) that contains
0058     //! both an applets file and a latterc file with the screens
0059     //!     newName: if it is empty the name is extracted from the old config file name
0060     bool importOldConfiguration(QString oldConfigPath, QString newName = QString());
0061 
0062     bool exportFullConfiguration(QString file);
0063 
0064     QString storageTmpDir() const;
0065     //! imports the specific layout and return the new layout name.
0066     //! if the function didn't succeed returns an empty string
0067     QString importLayout(const QString &fileName, const QString &suggestedName = QString());
0068 
0069     static void enableAutostart();
0070     static void disableAutostart();
0071     static bool isAutostartEnabled();
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 returns an empty string
0089     static QString importLayoutHelper(const QString &fileName, const QString &suggestedName = QString());
0090 
0091     //! returns the file path of a layout either existing or not
0092     static QString layoutUserFilePath(QString layoutName);
0093     //! returns the layouts user directory
0094     static QString layoutUserDir();
0095     //! returns the system path for latte shell data
0096     static QString systemShellDataPath();
0097 
0098     static QString nameOfConfigFile(const QString &fileName);
0099     static QString uniqueLayoutName(QString name);
0100 
0101     static bool hasViewTemplate(const QString &name);
0102     static QString layoutTemplateSystemFilePath(const QString &name);
0103 
0104     static QStringList availableLayouts();
0105     static QStringList availableLayoutTemplates();
0106     static QStringList availableViewTemplates();
0107     //! it checks the linked file if there are Containments in it that belong
0108     //! to Original Layouts and moves them accordingly. This is used mainly on
0109     //! startup and if such state occurs, it basically means that the app didn't
0110     //! close correctly, e.g. there was a crash.
0111     static QStringList checkRepairMultipleLayoutsLinkedFile();
0112 
0113     static Latte::MultipleLayouts::Status multipleLayoutsStatus();
0114     static void setMultipleLayoutsStatus(const Latte::MultipleLayouts::Status &status);
0115 
0116 signals:
0117     void newLayoutAdded(const QString &path);
0118 
0119 private:
0120     //! checks if this old layout can be imported. If it can it returns
0121     //! the new layout path and an empty string if it cant
0122     QString layoutCanBeImported(QString oldAppletsPath, QString newName, QString exportDirectory = QString());
0123 
0124     QTemporaryDir m_storageTmpDir;
0125 
0126     Layouts::Manager *m_manager;
0127 };
0128 
0129 }
0130 }
0131 
0132 #endif // IMPORTER_H