From 9a1346d04a2adf02258906a2d0c27411522db7ca Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Tue, 18 Aug 2020 01:56:11 +0300 Subject: [PATCH] layouts::storage support importToCorona() --- app/layout/genericlayout.cpp | 2 +- app/layout/storage.cpp | 47 -------------------------------- app/layout/storage.h | 2 -- app/layouts/storage.cpp | 53 ++++++++++++++++++++++++++++++++++-- app/layouts/storage.h | 6 ++-- 5 files changed, 56 insertions(+), 54 deletions(-) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 01cf80c9d..0a202b377 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1688,7 +1688,7 @@ void GenericLayout::copyView(Plasma::Containment *containment) void GenericLayout::importToCorona() { - m_storage->importToCorona(); + Layouts::Storage::self()->importToCorona(this); } bool GenericLayout::layoutIsBroken() const diff --git a/app/layout/storage.cpp b/app/layout/storage.cpp index af6486e30..6cfccc51b 100644 --- a/app/layout/storage.cpp +++ b/app/layout/storage.cpp @@ -60,53 +60,6 @@ void Storage::setStorageTmpDir(const QString &tmpDir) m_storageTmpDir = tmpDir; } -void Storage::importToCorona() -{ - if (!m_layout->corona()) { - return; - } - - //! Setting mutable for create a containment - m_layout->corona()->setImmutability(Plasma::Types::Mutable); - - QString temp1FilePath = m_storageTmpDir + "/" + m_layout->name() + ".multiple.views"; - //! we need to copy first the layout file because the kde cache - //! may not have yet been updated (KSharedConfigPtr) - //! this way we make sure at the latest changes stored in the layout file - //! will be also available when changing to Multiple Layouts - QString tempLayoutFilePath = m_storageTmpDir + "/" + m_layout->name() + ".multiple.tmplayout"; - - //! WE NEED A WAY TO COPY A CONTAINMENT!!!! - QFile tempLayoutFile(tempLayoutFilePath); - QFile copyFile(temp1FilePath); - QFile layoutOriginalFile(m_layout->file()); - - if (tempLayoutFile.exists()) { - tempLayoutFile.remove(); - } - - if (copyFile.exists()) - copyFile.remove(); - - layoutOriginalFile.copy(tempLayoutFilePath); - - KSharedConfigPtr filePtr = KSharedConfig::openConfig(tempLayoutFilePath); - KSharedConfigPtr newFile = KSharedConfig::openConfig(temp1FilePath); - KConfigGroup copyGroup = KConfigGroup(newFile, "Containments"); - KConfigGroup current_containments = KConfigGroup(filePtr, "Containments"); - - current_containments.copyTo(©Group); - - copyGroup.sync(); - - //! update ids to unique ones - QString temp2File = newUniqueIdsLayoutFromFile(temp1FilePath); - - - //! Finally import the configuration - importLayoutFile(temp2File); -} - void Storage::syncToLayoutFile(bool removeLayoutId) { if (!m_layout->corona() || !Layouts::Storage::self()->isWritable(m_layout)) { diff --git a/app/layout/storage.h b/app/layout/storage.h index 144f01653..bae50a38e 100644 --- a/app/layout/storage.h +++ b/app/layout/storage.h @@ -42,8 +42,6 @@ public: bool layoutIsBroken(QStringList &errors) const; - void importToCorona(); - void copyView(Plasma::Containment *containment); void syncToLayoutFile(bool removeLayoutId); diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index c20684e32..4112650e6 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -87,7 +87,7 @@ bool Storage::isLatteContainment(const KConfigGroup &group) const return pluginId == "org.kde.latte.containment"; } -void Storage::lock(Layout::GenericLayout *layout) const +void Storage::lock(const Layout::GenericLayout *layout) { QFileInfo layoutFileInfo(layout->file()); @@ -96,7 +96,7 @@ void Storage::lock(Layout::GenericLayout *layout) const } } -void Storage::unlock(Layout::GenericLayout *layout) const +void Storage::unlock(const Layout::GenericLayout *layout) { QFileInfo layoutFileInfo(layout->file()); @@ -105,6 +105,55 @@ void Storage::unlock(Layout::GenericLayout *layout) const } } + +void Storage::importToCorona(const Layout::GenericLayout *layout) +{ + if (!layout->corona()) { + return; + } + + //! Setting mutable for create a containment + layout->corona()->setImmutability(Plasma::Types::Mutable); + + QString temp1FilePath = m_storageTmpDir.path() + "/" + layout->name() + ".multiple.views"; + //! we need to copy first the layout file because the kde cache + //! may not have yet been updated (KSharedConfigPtr) + //! this way we make sure at the latest changes stored in the layout file + //! will be also available when changing to Multiple Layouts + QString tempLayoutFilePath = m_storageTmpDir.path() + "/" + layout->name() + ".multiple.tmplayout"; + + //! WE NEED A WAY TO COPY A CONTAINMENT!!!! + QFile tempLayoutFile(tempLayoutFilePath); + QFile copyFile(temp1FilePath); + QFile layoutOriginalFile(layout->file()); + + if (tempLayoutFile.exists()) { + tempLayoutFile.remove(); + } + + if (copyFile.exists()) + copyFile.remove(); + + layoutOriginalFile.copy(tempLayoutFilePath); + + KSharedConfigPtr filePtr = KSharedConfig::openConfig(tempLayoutFilePath); + KSharedConfigPtr newFile = KSharedConfig::openConfig(temp1FilePath); + KConfigGroup copyGroup = KConfigGroup(newFile, "Containments"); + KConfigGroup current_containments = KConfigGroup(filePtr, "Containments"); + + current_containments.copyTo(©Group); + + copyGroup.sync(); + + //! update ids to unique ones + QString temp2File = newUniqueIdsLayoutFromFile(layout, temp1FilePath); + + + //! Finally import the configuration + importLayoutFile(layout, temp2File); +} + + QString Storage::availableId(QStringList all, QStringList assigned, int base) { bool found = false; diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 272b152b0..32f372a95 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -49,8 +49,10 @@ public: bool isLatteContainment(Plasma::Containment *containment) const; bool isLatteContainment(const KConfigGroup &group) const; - void lock(Layout::GenericLayout *layout) const; //! make it only read-only - void unlock(Layout::GenericLayout *layout) const; //! make it writable which it should be the default + void lock(const Layout::GenericLayout *layout); //! make it only read-only + void unlock(const Layout::GenericLayout *layout); //! make it writable which it should be the default + + void importToCorona(const Layout::GenericLayout *layout); /// STATIC //! Check if an applet config group is valid or belongs to removed applet