mirror of
https://github.com/KDE/latte-dock.git
synced 2025-08-15 21:49:28 +03:00
support import configuration from command line
This commit is contained in:
@ -32,6 +32,7 @@
|
||||
#include <KArchive/KArchiveEntry>
|
||||
#include <KArchive/KArchiveDirectory>
|
||||
#include <KLocalizedString>
|
||||
#include <KNotification>
|
||||
|
||||
|
||||
namespace Latte {
|
||||
@ -426,6 +427,34 @@ Importer::LatteFileVersion Importer::fileVersion(QString file)
|
||||
return Importer::UnknownFileType;
|
||||
}
|
||||
|
||||
bool Importer::importHelper(QString fileName)
|
||||
{
|
||||
LatteFileVersion version = fileVersion(fileName);
|
||||
|
||||
if ((version != ConfigVersion1) && (version != ConfigVersion2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
KTar archive(fileName, QStringLiteral("application/x-tar"));
|
||||
archive.open(QIODevice::ReadOnly);
|
||||
|
||||
if (!archive.isOpen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QString latteDirPath(QDir::homePath() + "/.config/latte");
|
||||
QDir latteDir(latteDirPath);
|
||||
|
||||
if (latteDir.exists()) {
|
||||
latteDir.removeRecursively();
|
||||
}
|
||||
|
||||
archive.directory()->copyTo(QString(QDir::homePath() + "/.config"));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
QString Importer::nameOfConfigFile(const QString &fileName)
|
||||
{
|
||||
int lastSlash = fileName.lastIndexOf("/");
|
||||
|
@ -66,6 +66,7 @@ public:
|
||||
|
||||
static Importer::LatteFileVersion fileVersion(QString file);
|
||||
static QString nameOfConfigFile(const QString &fileName);
|
||||
static bool importHelper(QString fileName);
|
||||
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
|
||||
|
@ -30,9 +30,8 @@
|
||||
#include <QDir>
|
||||
#include <QFileDialog>
|
||||
#include <QHeaderView>
|
||||
#include <KLocalizedString>
|
||||
|
||||
#include <QMessageBox>
|
||||
#include <QProcess>
|
||||
#include <QStandardItem>
|
||||
#include <QStandardItemModel>
|
||||
#include <QTemporaryDir>
|
||||
@ -240,6 +239,13 @@ void LayoutConfigDialog::on_importButton_clicked()
|
||||
, this, [ &, file](bool check) {
|
||||
importLayoutsFromV1ConfigFile(file);
|
||||
});
|
||||
|
||||
connect(fullBtn, &QPushButton::clicked
|
||||
, this, [ &, file](bool check) {
|
||||
//!NOTE: Restart latte for import the new configuration
|
||||
QProcess::startDetached(qGuiApp->applicationFilePath() + " --import \"" + file + "\"");
|
||||
qGuiApp->exit();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#include "dockcorona.h"
|
||||
#include "config-latte.h"
|
||||
#include "globalsettings.h"
|
||||
#include "importer.h"
|
||||
|
||||
#include <memory>
|
||||
#include <csignal>
|
||||
@ -107,7 +107,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (parser.isSet(QStringLiteral("import"))) {
|
||||
bool imported = Latte::GlobalSettings::importHelper(parser.value(QStringLiteral("import")));
|
||||
bool imported = Latte::Importer::importHelper(parser.value(QStringLiteral("import")));
|
||||
|
||||
if (!imported) {
|
||||
qInfo() << i18n("The configuration cannot be imported");
|
||||
|
Reference in New Issue
Block a user