mirror of
https://github.com/KDE/latte-dock.git
synced 2024-12-26 23:21:37 +03:00
Importer importes the containments correctly
This commit is contained in:
parent
1a9ea88bc8
commit
db08a09bbf
@ -82,6 +82,7 @@ DockCorona::DockCorona(QObject *parent)
|
||||
setKPackage(package);
|
||||
//! global settings must be loaded after the package has been set
|
||||
m_globalSettings->load();
|
||||
m_layoutManager->load();
|
||||
|
||||
qmlRegisterTypes();
|
||||
QFontDatabase::addApplicationFont(kPackage().filePath("tangerineFont"));
|
||||
@ -636,7 +637,7 @@ void DockCorona::syncDockViews()
|
||||
foreach (auto view, m_dockViews) {
|
||||
bool found{false};
|
||||
|
||||
foreach (auto scr, qGuiApp->screens()) {
|
||||
foreach (auto scr, qGuiApp->screens()) {
|
||||
if (scr->name() == view->currentScreen()
|
||||
|| (view->onPrimary() && scr == qGuiApp->primaryScreen() ) ) {
|
||||
found = true;
|
||||
|
131
app/importer.cpp
131
app/importer.cpp
@ -19,6 +19,12 @@
|
||||
*/
|
||||
|
||||
#include "importer.h"
|
||||
#include "layoutsettings.h"
|
||||
#include "../liblattedock/dock.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
#include <KLocalizedString>
|
||||
|
||||
namespace Latte {
|
||||
|
||||
@ -31,4 +37,129 @@ Importer::~Importer()
|
||||
{
|
||||
}
|
||||
|
||||
bool Importer::updateOldConfiguration()
|
||||
{
|
||||
importOldLayout(QDir::homePath() + "/.config/lattedock-appletsrc", i18n("My Layout"));
|
||||
importOldLayout(QDir::homePath() + "/.config/lattedock-appletsrc", i18n("Alternative"), true);
|
||||
}
|
||||
|
||||
bool Importer::importOldLayout(QString oldAppletsPath, QString newName, bool alternative)
|
||||
{
|
||||
QString newLayoutPath = layoutCanBeImported(oldAppletsPath, newName);
|
||||
qDebug() << "New Layout Should be created: " << newLayoutPath;
|
||||
|
||||
KSharedConfigPtr oldFile = KSharedConfig::openConfig(oldAppletsPath);
|
||||
KSharedConfigPtr newFile = KSharedConfig::openConfig(newLayoutPath);
|
||||
|
||||
KConfigGroup containments = KConfigGroup(oldFile, "Containments");
|
||||
KConfigGroup copiedContainments = KConfigGroup(newFile, "Containments");
|
||||
|
||||
QList<int> systrays;
|
||||
|
||||
//! first copy the latte containments that correspond to the correct session
|
||||
//! and find also the systrays that should be copied also
|
||||
foreach (auto containmentId, containments.groupList()) {
|
||||
KConfigGroup containmentGroup = containments.group(containmentId);
|
||||
|
||||
QString plugin = containmentGroup.readEntry("plugin", QString());
|
||||
Dock::SessionType session = (Dock::SessionType)containmentGroup.readEntry("session", (int)Dock::DefaultSession);
|
||||
|
||||
bool shouldImport = false;
|
||||
|
||||
if (plugin == "org.kde.latte.containment" && session == Dock::DefaultSession && !alternative) {
|
||||
qDebug() << containmentId << " - " << plugin << " - " << session;
|
||||
shouldImport = true;
|
||||
} else if (plugin == "org.kde.latte.containment" && session == Dock::AlternativeSession && alternative) {
|
||||
qDebug() << containmentId << " - " << plugin << " - " << session;
|
||||
shouldImport = true;
|
||||
}
|
||||
|
||||
// this latte containment should be imported
|
||||
if (shouldImport) {
|
||||
auto applets = containments.group(containmentId).group("Applets");
|
||||
|
||||
foreach (auto applet, applets.groupList()) {
|
||||
KConfigGroup appletSettings = applets.group(applet).group("Configuration");
|
||||
|
||||
int systrayId = appletSettings.readEntry("SystrayContainmentId", "-1").toInt();
|
||||
|
||||
if (systrayId != -1) {
|
||||
systrays.append(systrayId);
|
||||
qDebug() << "systray was found in the containment...";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
KConfigGroup newContainment = copiedContainments.group(containmentId);
|
||||
containmentGroup.copyTo(&newContainment);
|
||||
}
|
||||
}
|
||||
|
||||
//! copy also the systrays that were discovered
|
||||
foreach (auto containmentId, containments.groupList()) {
|
||||
int cId = containmentId.toInt();
|
||||
|
||||
if (systrays.contains(cId)) {
|
||||
KConfigGroup containmentGroup = containments.group(containmentId);
|
||||
KConfigGroup newContainment = copiedContainments.group(containmentId);
|
||||
containmentGroup.copyTo(&newContainment);
|
||||
}
|
||||
}
|
||||
|
||||
copiedContainments.sync();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
QString Importer::layoutCanBeImported(QString oldAppletsPath, QString newName)
|
||||
{
|
||||
QFile oldAppletsrc(oldAppletsPath);
|
||||
|
||||
//! old file doesnt exist
|
||||
if (!oldAppletsrc.exists()) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
LayoutSettings oldLSettings(this, oldAppletsPath);
|
||||
|
||||
//! old file layout appears to not be old as its version is >=2
|
||||
if (oldLSettings.version() >= 2) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
QDir layoutDir(QDir::homePath() + "/.config/latte");
|
||||
|
||||
if (!layoutDir.exists()) {
|
||||
QDir(QDir::homePath() + "/.config").mkdir("latte");
|
||||
}
|
||||
|
||||
//! set up the new layout name
|
||||
if (newName.isEmpty()) {
|
||||
int extension = oldAppletsrc.fileName().lastIndexOf(".latterc");
|
||||
|
||||
if (extension > 0) {
|
||||
//! remove the last 8 characters that contain the extension
|
||||
newName = oldAppletsrc.fileName().remove(extension, 8);
|
||||
} else {
|
||||
newName = oldAppletsrc.fileName();
|
||||
}
|
||||
}
|
||||
|
||||
QFile newLayoutFile(layoutDir.absolutePath() + "/" + newName + ".layout.latte");
|
||||
QString newLayoutPath = newLayoutFile.fileName();
|
||||
|
||||
QStringList filter;
|
||||
filter.append(QString(newName + "*.layout.latte"));
|
||||
QStringList files = layoutDir.entryList(filter, QDir::Files | QDir::NoSymLinks);
|
||||
|
||||
//! if the newLayout already exists provide a newName that doesnt
|
||||
if (files.count() >= 1) {
|
||||
int newCounter = files.count() + 1;
|
||||
|
||||
newLayoutPath = layoutDir.absolutePath() + "/" + newName + "-" + QString::number(newCounter) + ".layout.latte";
|
||||
}
|
||||
|
||||
return newLayoutPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,20 @@ public:
|
||||
Importer(QObject *parent = nullptr);
|
||||
~Importer() override;
|
||||
|
||||
//! 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
|
||||
bool importOldLayout(QString oldAppletsPath, QString newName, bool alternative = false);
|
||||
|
||||
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
|
||||
QString layoutCanBeImported(QString oldAppletsPath, QString newName);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ LayoutManager::LayoutManager(QObject *parent)
|
||||
: QObject(parent),
|
||||
m_importer(new Importer(this))
|
||||
{
|
||||
m_corona = qobject_cast<DockCorona *>(parent);
|
||||
}
|
||||
|
||||
LayoutManager::~LayoutManager()
|
||||
@ -33,4 +34,18 @@ LayoutManager::~LayoutManager()
|
||||
m_importer->deleteLater();
|
||||
}
|
||||
|
||||
void LayoutManager::load()
|
||||
{
|
||||
int configVer = m_corona->universalSettings()->version();
|
||||
qDebug() << "Universal Settings version : " << configVer;
|
||||
|
||||
if (configVer < 2) {
|
||||
qDebug() << "Latte must update its configuration...";
|
||||
m_importer->updateOldConfiguration();
|
||||
} else {
|
||||
qDebug() << "Latte is loading its layouts...";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -37,6 +37,8 @@ public:
|
||||
LayoutManager(QObject *parent = nullptr);
|
||||
~LayoutManager() override;
|
||||
|
||||
void load();
|
||||
|
||||
private:
|
||||
DockCorona *m_corona{nullptr};
|
||||
Importer *m_importer{nullptr};
|
||||
|
@ -29,22 +29,57 @@ LayoutSettings::LayoutSettings(QObject *parent, KSharedConfig::Ptr config)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_layoutGroup = KConfigGroup(config, "LayoutSettings");
|
||||
init();
|
||||
}
|
||||
|
||||
LayoutSettings::LayoutSettings(QObject *parent, QString layoutFile )
|
||||
LayoutSettings::LayoutSettings(QObject *parent, QString layoutFile)
|
||||
: QObject(parent)
|
||||
{
|
||||
if (QFile(layoutFile).exists()){
|
||||
if (QFile(layoutFile).exists()) {
|
||||
KSharedConfigPtr lConfig = KSharedConfig::openConfig(layoutFile);
|
||||
m_layoutGroup = KConfigGroup(lConfig, "LayoutSettings");
|
||||
|
||||
m_layoutFile = layoutFile;
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
LayoutSettings::~LayoutSettings()
|
||||
{
|
||||
saveConfig();
|
||||
m_layoutGroup.sync();
|
||||
}
|
||||
|
||||
void LayoutSettings::init()
|
||||
{
|
||||
connect(this, &LayoutSettings::versionChanged, this, &LayoutSettings::saveConfig);
|
||||
}
|
||||
|
||||
int LayoutSettings::version() const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
void LayoutSettings::setVersion(int ver)
|
||||
{
|
||||
if (m_version == ver) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_version = ver;
|
||||
|
||||
emit versionChanged();
|
||||
}
|
||||
|
||||
void LayoutSettings::loadConfig()
|
||||
{
|
||||
m_version = m_layoutGroup.readEntry("version", 1);
|
||||
}
|
||||
|
||||
void LayoutSettings::saveConfig()
|
||||
{
|
||||
m_layoutGroup.writeEntry("version", m_version);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,22 @@ public:
|
||||
LayoutSettings(QObject *parent, KSharedConfig::Ptr config);
|
||||
~LayoutSettings() override;
|
||||
|
||||
int version() const;
|
||||
void setVersion(int ver);
|
||||
|
||||
signals:
|
||||
void versionChanged();
|
||||
|
||||
private slots:
|
||||
void loadConfig();
|
||||
void saveConfig();
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
private:
|
||||
//if version doesnt exist it is and old layout file
|
||||
int m_version{1};
|
||||
QString m_layoutFile;
|
||||
|
||||
DockCorona *m_corona{nullptr};
|
||||
|
@ -26,11 +26,45 @@ UniversalSettings::UniversalSettings(KSharedConfig::Ptr config, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_universalGroup(KConfigGroup(config, QStringLiteral("UniversalSettings")))
|
||||
{
|
||||
connect(this, &UniversalSettings::versionChanged, this, &UniversalSettings::saveConfig);
|
||||
}
|
||||
|
||||
UniversalSettings::~UniversalSettings()
|
||||
{
|
||||
m_universalGroup.sync();
|
||||
saveConfig();
|
||||
m_universalGroup.sync();
|
||||
}
|
||||
|
||||
void UniversalSettings::load()
|
||||
{
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
int UniversalSettings::version() const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
void UniversalSettings::setVersion(int ver)
|
||||
{
|
||||
if (m_version == ver) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_version = ver;
|
||||
|
||||
emit versionChanged();
|
||||
}
|
||||
|
||||
void UniversalSettings::loadConfig()
|
||||
{
|
||||
m_version = m_universalGroup.readEntry("version", 1);
|
||||
}
|
||||
|
||||
void UniversalSettings::saveConfig()
|
||||
{
|
||||
m_universalGroup.writeEntry("version", m_version);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -44,9 +44,23 @@ public:
|
||||
UniversalSettings(KSharedConfig::Ptr config, QObject *parent = nullptr);
|
||||
~UniversalSettings() override;
|
||||
|
||||
private:
|
||||
KConfigGroup m_universalGroup;
|
||||
void load();
|
||||
|
||||
int version() const;
|
||||
void setVersion(int ver);
|
||||
|
||||
signals:
|
||||
void versionChanged();
|
||||
|
||||
private slots:
|
||||
void loadConfig();
|
||||
void saveConfig();
|
||||
|
||||
private:
|
||||
//when there isnt a version it is an old universal file
|
||||
int m_version{1};
|
||||
|
||||
KConfigGroup m_universalGroup;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user