mirror of
https://github.com/KDE/latte-dock.git
synced 2025-01-15 15:24:24 +03:00
update universal settings correctly
--update exposeLayoutsMenu correctly from the Importer --cleanup universal settings file on exit
This commit is contained in:
parent
db08a09bbf
commit
35a8f607b8
@ -19,6 +19,8 @@
|
||||
*/
|
||||
|
||||
#include "importer.h"
|
||||
|
||||
#include "layoutmanager.h"
|
||||
#include "layoutsettings.h"
|
||||
#include "../liblattedock/dock.h"
|
||||
|
||||
@ -31,6 +33,7 @@ namespace Latte {
|
||||
Importer::Importer(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
m_manager = qobject_cast<LayoutManager *>(parent);
|
||||
}
|
||||
|
||||
Importer::~Importer()
|
||||
@ -39,8 +42,18 @@ Importer::~Importer()
|
||||
|
||||
bool Importer::updateOldConfiguration()
|
||||
{
|
||||
//! import standard old configuration and create the relevant layouts
|
||||
importOldLayout(QDir::homePath() + "/.config/lattedock-appletsrc", i18n("My Layout"));
|
||||
importOldLayout(QDir::homePath() + "/.config/lattedock-appletsrc", i18n("Alternative"), true);
|
||||
|
||||
//! global settings that must be imported to universal
|
||||
KSharedConfigPtr oldFile = KSharedConfig::openConfig(QDir::homePath() + "/.config/lattedock-appletsrc");
|
||||
KConfigGroup oldGeneralSettings = KConfigGroup(oldFile, "General");
|
||||
bool exposeLayoutsMenu = oldGeneralSettings.readEntry("exposeAltSession", false);
|
||||
|
||||
if (m_manager) {
|
||||
m_manager->corona()->universalSettings()->setExposeLayoutsMenu(exposeLayoutsMenu);
|
||||
}
|
||||
}
|
||||
|
||||
bool Importer::importOldLayout(QString oldAppletsPath, QString newName, bool alternative)
|
||||
@ -56,6 +69,8 @@ bool Importer::importOldLayout(QString oldAppletsPath, QString newName, bool alt
|
||||
|
||||
QList<int> systrays;
|
||||
|
||||
bool atLeastOneContainmentWasFound{false};
|
||||
|
||||
//! 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()) {
|
||||
@ -92,9 +107,16 @@ bool Importer::importOldLayout(QString oldAppletsPath, QString newName, bool alt
|
||||
|
||||
KConfigGroup newContainment = copiedContainments.group(containmentId);
|
||||
containmentGroup.copyTo(&newContainment);
|
||||
atLeastOneContainmentWasFound = true;
|
||||
}
|
||||
}
|
||||
|
||||
//! not even one latte containment was found for that layout so we must break
|
||||
//! the code here
|
||||
if (!atLeastOneContainmentWasFound) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//! copy also the systrays that were discovered
|
||||
foreach (auto containmentId, containments.groupList()) {
|
||||
int cId = containmentId.toInt();
|
||||
@ -108,6 +130,25 @@ bool Importer::importOldLayout(QString oldAppletsPath, QString newName, bool alt
|
||||
|
||||
copiedContainments.sync();
|
||||
|
||||
KConfigGroup oldGeneralSettings = KConfigGroup(oldFile, "General");
|
||||
|
||||
bool syncLaunchers{false};
|
||||
QStringList globalLaunchers;
|
||||
|
||||
if (!alternative) {
|
||||
syncLaunchers = oldGeneralSettings.readEntry("syncLaunchers_default", false);
|
||||
globalLaunchers = oldGeneralSettings.readEntry("globalLaunchers_default", QStringList());
|
||||
} else {
|
||||
syncLaunchers = oldGeneralSettings.readEntry("syncLaunchers_alternative", false);
|
||||
globalLaunchers = oldGeneralSettings.readEntry("globalLaunchers_alternative", QStringList());
|
||||
}
|
||||
|
||||
//! update also the layout settings correctly
|
||||
LayoutSettings newLayout(this, newLayoutPath);
|
||||
newLayout.setVersion(2);
|
||||
newLayout.setSyncLaunchers(syncLaunchers);
|
||||
newLayout.setGlobalLaunchers(globalLaunchers);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,12 @@
|
||||
#ifndef IMPORTER_H
|
||||
#define IMPORTER_H
|
||||
|
||||
#include "layoutmanager.h"
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class LayoutManager;
|
||||
|
||||
namespace Latte {
|
||||
|
||||
//! This class is responsible to import/export configurations
|
||||
@ -48,6 +52,8 @@ 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);
|
||||
|
||||
LayoutManager *m_manager;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -48,4 +48,9 @@ void LayoutManager::load()
|
||||
|
||||
}
|
||||
|
||||
DockCorona *LayoutManager::corona()
|
||||
{
|
||||
return m_corona;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,6 +26,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class Importer;
|
||||
|
||||
namespace Latte {
|
||||
|
||||
//! This class is responsible to manipulate all layouts.
|
||||
@ -39,6 +41,8 @@ public:
|
||||
|
||||
void load();
|
||||
|
||||
DockCorona *corona();
|
||||
|
||||
private:
|
||||
DockCorona *m_corona{nullptr};
|
||||
Importer *m_importer{nullptr};
|
||||
|
@ -53,6 +53,8 @@ LayoutSettings::~LayoutSettings()
|
||||
void LayoutSettings::init()
|
||||
{
|
||||
connect(this, &LayoutSettings::versionChanged, this, &LayoutSettings::saveConfig);
|
||||
connect(this, &LayoutSettings::syncLaunchersChanged, this, &LayoutSettings::saveConfig);
|
||||
connect(this, &LayoutSettings::globalLaunchersChanged, this, &LayoutSettings::saveConfig);
|
||||
}
|
||||
|
||||
int LayoutSettings::version() const
|
||||
@ -71,14 +73,48 @@ void LayoutSettings::setVersion(int ver)
|
||||
emit versionChanged();
|
||||
}
|
||||
|
||||
bool LayoutSettings::syncLaunchers() const
|
||||
{
|
||||
return m_syncLaunchers;
|
||||
}
|
||||
void LayoutSettings::setSyncLaunchers(bool sync)
|
||||
{
|
||||
if (m_syncLaunchers == sync)
|
||||
return;
|
||||
|
||||
m_syncLaunchers = sync;
|
||||
|
||||
emit syncLaunchersChanged();
|
||||
}
|
||||
|
||||
QStringList LayoutSettings::globalLaunchers() const
|
||||
{
|
||||
return m_globalLaunchers;
|
||||
}
|
||||
|
||||
void LayoutSettings::setGlobalLaunchers(QStringList launchers)
|
||||
{
|
||||
if (m_globalLaunchers == launchers)
|
||||
return;
|
||||
|
||||
m_globalLaunchers = launchers;
|
||||
|
||||
emit globalLaunchersChanged();
|
||||
}
|
||||
|
||||
|
||||
void LayoutSettings::loadConfig()
|
||||
{
|
||||
m_version = m_layoutGroup.readEntry("version", 1);
|
||||
m_syncLaunchers = m_layoutGroup.readEntry("syncLaunchers", false);
|
||||
m_globalLaunchers = m_layoutGroup.readEntry("globalLaunchers", QStringList());
|
||||
}
|
||||
|
||||
void LayoutSettings::saveConfig()
|
||||
{
|
||||
m_layoutGroup.writeEntry("version", m_version);
|
||||
m_layoutGroup.writeEntry("syncLaunchers", m_syncLaunchers);
|
||||
m_layoutGroup.writeEntry("globalLaunchers", m_globalLaunchers);
|
||||
}
|
||||
|
||||
|
||||
|
@ -37,17 +37,27 @@ namespace Latte {
|
||||
//! its general settings (no the containments)
|
||||
class LayoutSettings : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool syncLaunchers READ syncLaunchers WRITE setSyncLaunchers NOTIFY syncLaunchersChanged)
|
||||
Q_PROPERTY(QStringList globalLaunchers READ globalLaunchers WRITE setGlobalLaunchers NOTIFY globalLaunchersChanged)
|
||||
|
||||
public:
|
||||
LayoutSettings(QObject *parent, QString layoutFile);
|
||||
LayoutSettings(QObject *parent, KSharedConfig::Ptr config);
|
||||
~LayoutSettings() override;
|
||||
|
||||
QStringList globalLaunchers() const;
|
||||
void setGlobalLaunchers(QStringList launchers);
|
||||
|
||||
int version() const;
|
||||
void setVersion(int ver);
|
||||
|
||||
bool syncLaunchers() const;
|
||||
void setSyncLaunchers(bool sync);
|
||||
|
||||
signals:
|
||||
void globalLaunchersChanged();
|
||||
void versionChanged();
|
||||
void syncLaunchersChanged();
|
||||
|
||||
private slots:
|
||||
void loadConfig();
|
||||
@ -57,9 +67,12 @@ private:
|
||||
void init();
|
||||
|
||||
private:
|
||||
bool m_syncLaunchers{false};
|
||||
//if version doesnt exist it is and old layout file
|
||||
int m_version{1};
|
||||
|
||||
QString m_layoutFile;
|
||||
QStringList m_globalLaunchers;
|
||||
|
||||
DockCorona *m_corona{nullptr};
|
||||
KConfigGroup m_layoutGroup;
|
||||
|
@ -24,15 +24,17 @@ namespace Latte {
|
||||
|
||||
UniversalSettings::UniversalSettings(KSharedConfig::Ptr config, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_config(config),
|
||||
m_universalGroup(KConfigGroup(config, QStringLiteral("UniversalSettings")))
|
||||
{
|
||||
connect(this, &UniversalSettings::versionChanged, this, &UniversalSettings::saveConfig);
|
||||
connect(this, &UniversalSettings::exposeLayoutsMenuChanged, this, &UniversalSettings::saveConfig);
|
||||
}
|
||||
|
||||
UniversalSettings::~UniversalSettings()
|
||||
{
|
||||
saveConfig();
|
||||
m_universalGroup.sync();
|
||||
cleanupSettings();
|
||||
}
|
||||
|
||||
void UniversalSettings::load()
|
||||
@ -40,6 +42,22 @@ void UniversalSettings::load()
|
||||
loadConfig();
|
||||
}
|
||||
|
||||
bool UniversalSettings::exposeLayoutsMenu() const
|
||||
{
|
||||
return m_exposeLayoutsMenu;
|
||||
}
|
||||
|
||||
void UniversalSettings::setExposeLayoutsMenu(bool state)
|
||||
{
|
||||
if (m_exposeLayoutsMenu == state) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_exposeLayoutsMenu = state;
|
||||
emit exposeLayoutsMenuChanged();
|
||||
}
|
||||
|
||||
|
||||
int UniversalSettings::version() const
|
||||
{
|
||||
return m_version;
|
||||
@ -59,12 +77,23 @@ void UniversalSettings::setVersion(int ver)
|
||||
void UniversalSettings::loadConfig()
|
||||
{
|
||||
m_version = m_universalGroup.readEntry("version", 1);
|
||||
m_exposeLayoutsMenu = m_universalGroup.readEntry("exposeLayoutsMenu", false);
|
||||
}
|
||||
|
||||
void UniversalSettings::saveConfig()
|
||||
{
|
||||
m_universalGroup.writeEntry("version", m_version);
|
||||
m_universalGroup.writeEntry("exposeLayoutsMenu", m_exposeLayoutsMenu);
|
||||
|
||||
m_universalGroup.sync();
|
||||
}
|
||||
|
||||
void UniversalSettings::cleanupSettings()
|
||||
{
|
||||
KConfigGroup containments = KConfigGroup(m_config, QStringLiteral("Containments"));
|
||||
containments.deleteGroup();
|
||||
|
||||
containments.sync();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ namespace Latte {
|
||||
class UniversalSettings : public QObject {
|
||||
Q_OBJECT
|
||||
//Q_PROPERTY(bool autostart READ autostart WRITE setAutostart NOTIFY autostartChanged)
|
||||
//Q_PROPERTY(bool exposeAltSession READ exposeAltSession WRITE setExposeAltSession NOTIFY exposeAltSessionChanged)
|
||||
Q_PROPERTY(bool exposeLayoutsMenu READ exposeLayoutsMenu WRITE setExposeLayoutsMenu NOTIFY exposeLayoutsMenuChanged)
|
||||
|
||||
//Q_PROPERTY(Latte::Dock::SessionType currentSession READ currentSession WRITE setCurrentSession NOTIFY currentSessionChanged)
|
||||
|
||||
@ -46,10 +46,14 @@ public:
|
||||
|
||||
void load();
|
||||
|
||||
bool exposeLayoutsMenu() const;
|
||||
void setExposeLayoutsMenu(bool state);
|
||||
|
||||
int version() const;
|
||||
void setVersion(int ver);
|
||||
|
||||
signals:
|
||||
void exposeLayoutsMenuChanged();
|
||||
void versionChanged();
|
||||
|
||||
private slots:
|
||||
@ -57,10 +61,15 @@ private slots:
|
||||
void saveConfig();
|
||||
|
||||
private:
|
||||
void cleanupSettings();
|
||||
|
||||
private:
|
||||
bool m_exposeLayoutsMenu{false};
|
||||
//when there isnt a version it is an old universal file
|
||||
int m_version{1};
|
||||
|
||||
KConfigGroup m_universalGroup;
|
||||
KSharedConfig::Ptr m_config;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user