diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 0a202b377..67bb2e672 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -612,7 +612,7 @@ QList GenericLayout::sortedViewsData(const QList &viewsData) } -const QList *GenericLayout::containments() +const QList *GenericLayout::containments() const { return &m_containments; } @@ -1603,7 +1603,7 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool) report += "

"; QStringList errorsList; - bool broken = m_storage->layoutIsBroken(errorsList); + bool broken = Layouts::Storage::self()->isBroken(this, errorsList); if (!broken && unknownScreens.count() == 0) { report += "" + i18n("No errors were identified for this layout...") + "
"; @@ -1691,10 +1691,10 @@ void GenericLayout::importToCorona() Layouts::Storage::self()->importToCorona(this); } -bool GenericLayout::layoutIsBroken() const +bool GenericLayout::isBroken() const { QStringList errors; - return m_storage->layoutIsBroken(errors); + return Layouts::Storage::self()->isBroken(this, errors); } } diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 8915f5e0e..d1025a873 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -88,7 +88,7 @@ public: bool isActive() const; //! is loaded and running virtual bool isCurrent() const; bool isWritable() const; - bool layoutIsBroken() const; + bool isBroken() const; bool isSubContainment(Plasma::Applet *applet) const; Plasma::Containment *subContainmentOf(Plasma::Applet *applet) const; @@ -104,7 +104,7 @@ public: QStringList unloadedContainmentsIds(); virtual Types::ViewType latteViewType(uint containmentId) const; - const QList *containments(); + const QList *containments() const; Latte::View *highestPriorityView(); Latte::View *viewForContainment(Plasma::Containment *containment); diff --git a/app/layout/storage.cpp b/app/layout/storage.cpp index 6cfccc51b..edf655d34 100644 --- a/app/layout/storage.cpp +++ b/app/layout/storage.cpp @@ -540,135 +540,5 @@ QString Storage::newUniqueIdsLayoutFromFile(QString file) return tempFile; } -bool Storage::layoutIsBroken(QStringList &errors) const -{ - if (m_layout->file().isEmpty() || !QFile(m_layout->file()).exists()) { - return false; - } - - QStringList ids; - QStringList conts; - QStringList applets; - - KSharedConfigPtr lFile = KSharedConfig::openConfig(m_layout->file()); - - if (!m_layout->corona()) { - KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments"); - ids << containmentsEntries.groupList(); - conts << ids; - - for (const auto &cId : containmentsEntries.groupList()) { - auto appletsEntries = containmentsEntries.group(cId).group("Applets"); - - QStringList validAppletIds; - bool updated{false}; - - for (const auto &appletId : appletsEntries.groupList()) { - KConfigGroup appletGroup = appletsEntries.group(appletId); - - if (Layouts::Storage::appletGroupIsValid(appletGroup)) { - validAppletIds << appletId; - } else { - updated = true; - //! heal layout file by removing applet config records that are not used any more - qDebug() << "Layout: " << m_layout->name() << " removing deprecated applet : " << appletId; - appletsEntries.deleteGroup(appletId); - } - } - - if (updated) { - appletsEntries.sync(); - } - - ids << validAppletIds; - applets << validAppletIds; - } - } else { - for (const auto containment : *m_layout->containments()) { - ids << QString::number(containment->id()); - conts << QString::number(containment->id()); - - for (const auto applet : containment->applets()) { - ids << QString::number(applet->id()); - applets << QString::number(applet->id()); - } - } - } - -#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) - QSet idsSet = QSet::fromList(ids); -#else - QSet idsSet(ids.begin(), ids.end()); -#endif - /* a different way to count duplicates - QMap countOfStrings; - - for (int i = 0; i < ids.count(); i++) { - countOfStrings[ids[i]]++; - }*/ - - if (idsSet.count() != ids.count()) { - qDebug() << " ---- ERROR - BROKEN LAYOUT :: " << m_layout->name() << " ----"; - - if (!m_layout->corona()) { - qDebug() << " --- storaged file : " << m_layout->file(); - } else { - if (m_layout->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { - qDebug() << " --- in multiple layouts hidden file : " << Layouts::Importer::layoutUserFilePath(MULTIPLELAYOUTSHIDDENNAME); - } else { - qDebug() << " --- in active layout file : " << m_layout->file(); - } - } - - qDebug() << "Containments :: " << conts; - qDebug() << "Applets :: " << applets; - - for (const QString &c : conts) { - if (applets.contains(c)) { - QString errorStr = i18n("Same applet and containment id found ::: ") + c; - qDebug() << "Error: " << errorStr; - errors << errorStr; - } - } - - for (int i = 0; i < ids.count(); ++i) { - for (int j = i + 1; j < ids.count(); ++j) { - if (ids[i] == ids[j]) { - QString errorStr = i18n("Different applets with same id ::: ") + ids[i]; - qDebug() << "Error: " << errorStr; - errors << errorStr; - } - } - } - - qDebug() << " -- - -- - -- - -- - - -- - - - - -- - - - - "; - - if (!m_layout->corona()) { - KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments"); - - for (const auto &cId : containmentsEntries.groupList()) { - auto appletsEntries = containmentsEntries.group(cId).group("Applets"); - - qDebug() << " CONTAINMENT : " << cId << " APPLETS : " << appletsEntries.groupList(); - } - } else { - for (const auto containment : *m_layout->containments()) { - QStringList appletsIds; - - for (const auto applet : containment->applets()) { - appletsIds << QString::number(applet->id()); - } - - qDebug() << " CONTAINMENT : " << containment->id() << " APPLETS : " << appletsIds.join(","); - } - } - - return true; - } - - return false; -} - - } } diff --git a/app/layout/storage.h b/app/layout/storage.h index bae50a38e..a2341b8c0 100644 --- a/app/layout/storage.h +++ b/app/layout/storage.h @@ -40,8 +40,6 @@ public: Storage(GenericLayout *parent); ~Storage() override; - bool layoutIsBroken(QStringList &errors) const; - void copyView(Plasma::Containment *containment); void syncToLayoutFile(bool removeLayoutId); diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index 4112650e6..0a0586d28 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -20,8 +20,10 @@ #include "storage.h" // local +#include "importer.h" #include "manager.h" #include "../lattecorona.h" +#include "../layout/abstractlayout.h" #include "../layout/storage.h" // Qt @@ -375,5 +377,133 @@ QList Storage::importLayoutFile(const Layout::GenericLayo return importedDocks; } +bool Storage::isBroken(const Layout::GenericLayout *layout, QStringList &errors) const +{ + if (layout->file().isEmpty() || !QFile(layout->file()).exists()) { + return false; + } + + QStringList ids; + QStringList conts; + QStringList applets; + + KSharedConfigPtr lFile = KSharedConfig::openConfig(layout->file()); + + if (!layout->corona()) { + KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments"); + ids << containmentsEntries.groupList(); + conts << ids; + + for (const auto &cId : containmentsEntries.groupList()) { + auto appletsEntries = containmentsEntries.group(cId).group("Applets"); + + QStringList validAppletIds; + bool updated{false}; + + for (const auto &appletId : appletsEntries.groupList()) { + KConfigGroup appletGroup = appletsEntries.group(appletId); + + if (Layouts::Storage::appletGroupIsValid(appletGroup)) { + validAppletIds << appletId; + } else { + updated = true; + //! heal layout file by removing applet config records that are not used any more + qDebug() << "Layout: " << layout->name() << " removing deprecated applet : " << appletId; + appletsEntries.deleteGroup(appletId); + } + } + + if (updated) { + appletsEntries.sync(); + } + + ids << validAppletIds; + applets << validAppletIds; + } + } else { + for (const auto containment : *layout->containments()) { + ids << QString::number(containment->id()); + conts << QString::number(containment->id()); + + for (const auto applet : containment->applets()) { + ids << QString::number(applet->id()); + applets << QString::number(applet->id()); + } + } + } + +#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0) + QSet idsSet = QSet::fromList(ids); +#else + QSet idsSet(ids.begin(), ids.end()); +#endif + /* a different way to count duplicates + QMap countOfStrings; + + for (int i = 0; i < ids.count(); i++) { + countOfStrings[ids[i]]++; + }*/ + + if (idsSet.count() != ids.count()) { + qDebug() << " ---- ERROR - BROKEN LAYOUT :: " << layout->name() << " ----"; + + if (!layout->corona()) { + qDebug() << " --- storaged file : " << layout->file(); + } else { + if (layout->corona()->layoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { + qDebug() << " --- in multiple layouts hidden file : " << Layouts::Importer::layoutUserFilePath(Layout::MULTIPLELAYOUTSHIDDENNAME); + } else { + qDebug() << " --- in active layout file : " << layout->file(); + } + } + + qDebug() << "Containments :: " << conts; + qDebug() << "Applets :: " << applets; + + for (const QString &c : conts) { + if (applets.contains(c)) { + QString errorStr = i18n("Same applet and containment id found ::: ") + c; + qDebug() << "Error: " << errorStr; + errors << errorStr; + } + } + + for (int i = 0; i < ids.count(); ++i) { + for (int j = i + 1; j < ids.count(); ++j) { + if (ids[i] == ids[j]) { + QString errorStr = i18n("Different applets with same id ::: ") + ids[i]; + qDebug() << "Error: " << errorStr; + errors << errorStr; + } + } + } + + qDebug() << " -- - -- - -- - -- - - -- - - - - -- - - - - "; + + if (!layout->corona()) { + KConfigGroup containmentsEntries = KConfigGroup(lFile, "Containments"); + + for (const auto &cId : containmentsEntries.groupList()) { + auto appletsEntries = containmentsEntries.group(cId).group("Applets"); + + qDebug() << " CONTAINMENT : " << cId << " APPLETS : " << appletsEntries.groupList(); + } + } else { + for (const auto containment : *layout->containments()) { + QStringList appletsIds; + + for (const auto applet : containment->applets()) { + appletsIds << QString::number(applet->id()); + } + + qDebug() << " CONTAINMENT : " << containment->id() << " APPLETS : " << appletsIds.join(","); + } + } + + return true; + } + + return false; +} } } diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 32f372a95..01f80121c 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -48,6 +48,7 @@ public: bool isWritable(const Layout::GenericLayout *layout) const; bool isLatteContainment(Plasma::Containment *containment) const; bool isLatteContainment(const KConfigGroup &group) const; + bool isBroken(const Layout::GenericLayout *layout, QStringList &errors) const; 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 diff --git a/app/settings/controllers/layoutscontroller.cpp b/app/settings/controllers/layoutscontroller.cpp index 7026b7cb2..b0528fffe 100644 --- a/app/settings/controllers/layoutscontroller.cpp +++ b/app/settings/controllers/layoutscontroller.cpp @@ -434,7 +434,7 @@ void Layouts::loadLayouts() Latte::Layout::GenericLayout *generic = m_handler->corona()->layoutsManager()->synchronizer()->layout(central->name()); - if ((generic && generic->layoutIsBroken()) || (!generic && central->layoutIsBroken())) { + if ((generic && generic->isBroken()) || (!generic && central->isBroken())) { brokenLayouts.append(central->name()); } }