2017-07-02 15:02:07 +03:00
/*
2021-05-27 15:01:00 +00:00
SPDX - FileCopyrightText : 2017 Smith AR < audoban @ openmailbox . org >
SPDX - FileCopyrightText : 2017 Michail Vourlakos < mvourlakos @ gmail . com >
SPDX - License - Identifier : GPL - 2.0 - or - later
2017-07-02 15:02:07 +03:00
*/
# ifndef IMPORTER_H
# define IMPORTER_H
2018-12-02 02:05:52 +02:00
// Qt
2017-07-02 15:02:07 +03:00
# include <QObject>
2020-07-26 13:11:44 +03:00
# include <QTemporaryDir>
2017-07-02 15:02:07 +03:00
2018-02-03 11:34:13 +02:00
namespace Latte {
2019-05-09 17:12:57 +03:00
namespace Layouts {
class Manager ;
}
2018-02-03 11:34:13 +02:00
}
2017-07-02 21:02:27 +03:00
2017-07-02 15:02:07 +03:00
namespace Latte {
2019-05-09 17:57:12 +03:00
namespace Layouts {
2017-07-02 15:02:07 +03:00
2017-07-02 15:06:35 +03:00
//! This class is responsible to import/export configurations
//! and of course to import old configuration to new architecture
2018-07-03 22:15:45 +03:00
class Importer : public QObject
{
2017-07-02 15:02:07 +03:00
Q_OBJECT
public :
2018-07-03 22:15:45 +03:00
enum LatteFileVersion
{
2017-07-22 17:59:23 +03:00
UnknownFileType = - 1 ,
LayoutVersion1 = 0 ,
ConfigVersion1 = 1 ,
LayoutVersion2 = 2 ,
ConfigVersion2 = 3
} ;
Q_ENUM ( LatteFileVersion ) ;
2017-07-02 15:02:07 +03:00
Importer ( QObject * parent = nullptr ) ;
~ Importer ( ) override ;
2017-07-02 20:19:18 +03:00
//! updates the old configuration to version: 2
bool updateOldConfiguration ( ) ;
//! imports an old layout file,
//! newName: the layout new name, if it is empty the original is used
//! alternative: old files can contain both a Default and an Alternative layout
//! false: imports only Default layout
//! true: imports only Alternative layout
2017-07-22 19:49:28 +03:00
bool importOldLayout ( QString oldAppletsPath , QString newName , bool alternative = false , QString exportDirectory = QString ( ) ) ;
2017-07-02 20:19:18 +03:00
2017-07-03 00:34:59 +03:00
//! imports and old configuration file (tar archive) that contains
//! both an applets file and a latterc file with the screens
//! newName: if it is empty the name is extracted from the old config file name
bool importOldConfiguration ( QString oldConfigPath , QString newName = QString ( ) ) ;
2017-07-22 22:52:31 +03:00
bool exportFullConfiguration ( QString file ) ;
2020-07-26 13:11:44 +03:00
QString storageTmpDir ( ) const ;
2020-08-29 20:42:15 +03:00
//! imports the specific layout and return the new layout name.
//! if the function didn't succeed returns an empty string
QString importLayout ( QString fileName ) ;
2020-07-26 13:11:44 +03:00
2017-07-22 17:59:23 +03:00
static Importer : : LatteFileVersion fileVersion ( QString file ) ;
2017-12-17 17:42:49 +02:00
2017-07-22 23:15:54 +03:00
static bool importHelper ( QString fileName ) ;
2019-03-16 13:44:00 +02:00
//! returns the standard path found that contains the subPath
//! local paths have higher priority by default
static QString standardPath ( QString subPath , bool localFirst = true ) ;
2019-03-23 17:49:09 +02:00
//! returns all application data standard paths
//! local paths have higher priority by default
static QStringList standardPaths ( bool localfirst = true ) ;
2020-07-26 13:11:44 +03:00
static QStringList standardPathsFor ( QString subPath , bool localfirst = true ) ;
2019-03-16 13:44:00 +02:00
2017-12-17 18:34:50 +02:00
//! check if this layout exists already in the latte directory
static bool layoutExists ( QString layoutName ) ;
2017-12-17 19:08:35 +02:00
//! imports the specific layout and return the new layout name.
2020-08-29 20:42:15 +03:00
//! if the function didn't succeed returns an empty string
2017-12-17 19:08:35 +02:00
static QString importLayoutHelper ( QString fileName ) ;
2017-12-17 18:34:50 +02:00
2020-08-14 09:33:39 +03:00
//! returns the file path of a layout either existing or not
static QString layoutUserFilePath ( QString layoutName ) ;
//! returns the layouts user directory
static QString layoutUserDir ( ) ;
2017-12-17 17:42:49 +02:00
static QString nameOfConfigFile ( const QString & fileName ) ;
static QString uniqueLayoutName ( QString name ) ;
2018-01-15 14:09:41 +02:00
2017-12-17 18:13:26 +02:00
static QStringList availableLayouts ( ) ;
2018-01-15 14:09:41 +02:00
//! it checks the linked file if there are Containments in it that belong
//! to Original Layouts and moves them accordingly. This is used mainly on
2018-08-30 08:47:53 +03:00
//! startup and if such state occurs, it basically means that the app didn't
2018-01-15 14:09:41 +02:00
//! close correctly, e.g. there was a crash.
static QStringList checkRepairMultipleLayoutsLinkedFile ( ) ;
2017-12-17 17:42:49 +02:00
2020-08-29 20:42:15 +03:00
signals :
void newLayoutAdded ( const QString & path ) ;
2017-07-02 20:19:18 +03:00
private :
//! checks if this old layout can be imported. If it can it returns
//! the new layout path and an empty string if it cant
2017-07-22 19:49:28 +03:00
QString layoutCanBeImported ( QString oldAppletsPath , QString newName , QString exportDirectory = QString ( ) ) ;
2017-07-02 21:02:27 +03:00
2020-07-26 13:11:44 +03:00
QTemporaryDir m_storageTmpDir ;
2019-05-09 17:12:57 +03:00
Layouts : : Manager * m_manager ;
2017-07-02 15:02:07 +03:00
} ;
2019-05-09 17:57:12 +03:00
}
2017-07-02 15:02:07 +03:00
}
# endif // IMPORTER_H