From 53a0cb65742ef605afde90b78207da5b6f3b09a9 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 18 Aug 2020 02:23:34 +0300 Subject: [PATCH] layouts::storage, move syncToLayoutFile() code --- app/layout/genericlayout.cpp | 6 +++--- app/layout/storage.cpp | 30 ------------------------------ app/layout/storage.h | 1 - app/layouts/storage.cpp | 30 ++++++++++++++++++++++++++++++ app/layouts/storage.h | 1 + 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 67bb2e672..f30d3d241 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1053,7 +1053,7 @@ void GenericLayout::assignToLayout(Latte::View *latteView, QListlayoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { - m_storage->syncToLayoutFile(false); + Layouts::Storage::self()->syncToLayoutFile(this, false); } } @@ -1091,7 +1091,7 @@ QList GenericLayout::unassignFromLayout(Latte::View *latt //! sync the original layout file for integrity if (m_corona && m_corona->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { - m_storage->syncToLayoutFile(false); + Layouts::Storage::self()->syncToLayoutFile(this, false); } return containments; @@ -1677,7 +1677,7 @@ void GenericLayout::unlock() void GenericLayout::syncToLayoutFile(bool removeLayoutId) { syncSettings(); - m_storage->syncToLayoutFile(removeLayoutId); + Layouts::Storage::self()->syncToLayoutFile(this, removeLayoutId); } void GenericLayout::copyView(Plasma::Containment *containment) diff --git a/app/layout/storage.cpp b/app/layout/storage.cpp index edf655d34..bd49aaf89 100644 --- a/app/layout/storage.cpp +++ b/app/layout/storage.cpp @@ -60,36 +60,6 @@ void Storage::setStorageTmpDir(const QString &tmpDir) m_storageTmpDir = tmpDir; } -void Storage::syncToLayoutFile(bool removeLayoutId) -{ - if (!m_layout->corona() || !Layouts::Storage::self()->isWritable(m_layout)) { - return; - } - - KSharedConfigPtr filePtr = KSharedConfig::openConfig(m_layout->file()); - - KConfigGroup oldContainments = KConfigGroup(filePtr, "Containments"); - oldContainments.deleteGroup(); - - qDebug() << " LAYOUT :: " << m_layout->name() << " is syncing its original file."; - - for (const auto containment : *m_layout->containments()) { - if (removeLayoutId) { - containment->config().writeEntry("layoutId", ""); - } - - KConfigGroup newGroup = oldContainments.group(QString::number(containment->id())); - containment->config().copyTo(&newGroup); - - if (!removeLayoutId) { - newGroup.writeEntry("layoutId", ""); - newGroup.sync(); - } - } - - oldContainments.sync(); -} - void Storage::copyView(Plasma::Containment *containment) { if (!containment || !m_layout->corona()) diff --git a/app/layout/storage.h b/app/layout/storage.h index a2341b8c0..0ea45cfe8 100644 --- a/app/layout/storage.h +++ b/app/layout/storage.h @@ -41,7 +41,6 @@ public: ~Storage() override; void copyView(Plasma::Containment *containment); - void syncToLayoutFile(bool removeLayoutId); void setStorageTmpDir(const QString &tmpDir); diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index 0a0586d28..ce00e1fcf 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -356,6 +356,36 @@ QString Storage::newUniqueIdsLayoutFromFile(const Layout::GenericLayout *layout, return tempFile; } +void Storage::syncToLayoutFile(const Layout::GenericLayout *layout, bool removeLayoutId) +{ + if (!layout->corona() || !isWritable(layout)) { + return; + } + + KSharedConfigPtr filePtr = KSharedConfig::openConfig(layout->file()); + + KConfigGroup oldContainments = KConfigGroup(filePtr, "Containments"); + oldContainments.deleteGroup(); + + qDebug() << " LAYOUT :: " << layout->name() << " is syncing its original file."; + + for (const auto containment : *layout->containments()) { + if (removeLayoutId) { + containment->config().writeEntry("layoutId", ""); + } + + KConfigGroup newGroup = oldContainments.group(QString::number(containment->id())); + containment->config().copyTo(&newGroup); + + if (!removeLayoutId) { + newGroup.writeEntry("layoutId", ""); + newGroup.sync(); + } + } + + oldContainments.sync(); +} + QList Storage::importLayoutFile(const Layout::GenericLayout *layout, QString file) { KSharedConfigPtr filePtr = KSharedConfig::openConfig(file); diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 01f80121c..f0ce3385d 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -54,6 +54,7 @@ public: void unlock(const Layout::GenericLayout *layout); //! make it writable which it should be the default void importToCorona(const Layout::GenericLayout *layout); + void syncToLayoutFile(const Layout::GenericLayout *layout, bool removeLayoutId); /// STATIC //! Check if an applet config group is valid or belongs to removed applet