1
0
mirror of https://github.com/KDE/latte-dock.git synced 2024-12-28 19:21:50 +03:00

import screens from old configuration files

This commit is contained in:
Michail Vourlakos 2017-07-03 00:34:59 +03:00
parent 942d3b04db
commit 2d22b2c243
2 changed files with 108 additions and 0 deletions

View File

@ -22,11 +22,14 @@
#include "layoutmanager.h"
#include "layoutsettings.h"
#include "screenpool.h"
#include "../liblattedock/dock.h"
#include <QFile>
#include <QTemporaryDir>
#include <KLocalizedString>
#include <KArchive/KTar>
namespace Latte {
@ -61,6 +64,21 @@ bool Importer::updateOldConfiguration()
m_manager->corona()->universalSettings()->setExposeLayoutsMenu(exposeLayoutsMenu);
}
QFile extFile(QDir::homePath() + "/.config/lattedockextrc");
//! import also the old user layouts into the new architecture
if (extFile.exists()) {
KSharedConfigPtr extFileConfig = KSharedConfig::openConfig(extFile.fileName());
KConfigGroup externalSettings = KConfigGroup(extFileConfig, "External");
QStringList userLayouts = externalSettings.readEntry("userLayouts", QStringList());
foreach (auto userConfig, userLayouts) {
qDebug() << "user layout : " << userConfig;
importOldConfiguration(userConfig);
}
}
return true;
}
@ -211,4 +229,89 @@ QString Importer::layoutCanBeImported(QString oldAppletsPath, QString newName)
return newLayoutPath;
}
bool Importer::importOldConfiguration(QString oldConfigPath, QString newName)
{
QFile oldConfigFile(oldConfigPath);
if (!oldConfigFile.exists()) {
return false;
}
KTar archive(oldConfigPath, QStringLiteral("application/x-tar"));
archive.open(QIODevice::ReadOnly);
if (!archive.isOpen()) {
return false;
}
auto rootDir = archive.directory();
QTemporaryDir uniqueTempDir;
QDir tempDir{uniqueTempDir.path()};
qDebug() << "temp layout directory : " << tempDir.absolutePath();
if (rootDir) {
if (!tempDir.exists())
tempDir.mkpath(tempDir.absolutePath());
foreach (auto &name, rootDir->entries()) {
auto fileEntry = rootDir->file(name);
if (fileEntry && (fileEntry->name() == "lattedockrc"
|| fileEntry->name() == "lattedock-appletsrc")) {
if (!fileEntry->copyTo(tempDir.absolutePath())) {
qInfo() << i18nc("import/export config", "The extracted file coulnd be copied!!!");
archive.close();
return false;
}
} else {
qInfo() << i18nc("import/export config", "The file has a wrong format!!!");
archive.close();
return false;
}
}
} else {
qInfo() << i18nc("import/export config", "The temp directory couldnt be created!!!");
archive.close();
return false;
}
//! only if the above has passed we must process the files
QString appletsPath(tempDir.absolutePath() + "/lattedock-appletsrc");
QString screensPath(tempDir.absolutePath() + "/lattedockrc");
if (!QFile(appletsPath).exists() || !QFile(screensPath).exists()) {
return false;
}
if (newName.isEmpty()) {
int lastSlash = oldConfigPath.lastIndexOf("/");
newName = oldConfigPath.remove(0, lastSlash + 1);
int ext = newName.lastIndexOf(".latterc");
newName = newName.remove(ext, 8);
}
if (!importOldLayout(appletsPath, newName)) {
return false;
}
//! the old configuration contains also screen values, these must be updated also
KSharedConfigPtr oldScreensConfig = KSharedConfig::openConfig(screensPath);
KConfigGroup m_screensGroup = KConfigGroup(oldScreensConfig, "ScreenConnectors");
//restore the known ids to connector mappings
foreach (const QString &key, m_screensGroup.keyList()) {
QString connector = m_screensGroup.readEntry(key, QString());
int id = key.toInt();
if (id >= 10 && !m_manager->corona()->screenPool()->knownIds().contains(id)) {
m_manager->corona()->screenPool()->insertScreenMapping(id, connector);
}
}
return true;
}
}

View File

@ -48,6 +48,11 @@ public:
//! true: imports only Alternative layout
bool importOldLayout(QString oldAppletsPath, QString newName, bool alternative = false);
//! 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());
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