layouts::storage, move syncToLayoutFile() code

pull/19/head
Michail Vourlakos 5 years ago
parent d97be6744d
commit 53a0cb6574

@ -1053,7 +1053,7 @@ void GenericLayout::assignToLayout(Latte::View *latteView, QList<Plasma::Contain
//! 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);
}
}
@ -1091,7 +1091,7 @@ QList<Plasma::Containment *> 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)

@ -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())

@ -41,7 +41,6 @@ public:
~Storage() override;
void copyView(Plasma::Containment *containment);
void syncToLayoutFile(bool removeLayoutId);
void setStorageTmpDir(const QString &tmpDir);

@ -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<Plasma::Containment *> Storage::importLayoutFile(const Layout::GenericLayout *layout, QString file)
{
KSharedConfigPtr filePtr = KSharedConfig::openConfig(file);

@ -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

Loading…
Cancel
Save