diff --git a/app/data/layoutdata.cpp b/app/data/layoutdata.cpp index b9ff51c8f..c41c2b9b8 100644 --- a/app/data/layoutdata.cpp +++ b/app/data/layoutdata.cpp @@ -40,7 +40,6 @@ Layout::Layout(Layout &&o) lastUsedActivity(o.lastUsedActivity), isActive(o.isActive), isConsideredActive(o.isConsideredActive), - isBroken(o.isBroken), isLocked(o.isLocked), isShownInMenu(o.isShownInMenu), isTemplate(o.isTemplate), @@ -62,7 +61,6 @@ Layout::Layout(const Layout &o) lastUsedActivity(o.lastUsedActivity), isActive(o.isActive), isConsideredActive(o.isConsideredActive), - isBroken(o.isBroken), isLocked(o.isLocked), isShownInMenu(o.isShownInMenu), isTemplate(o.isTemplate), @@ -86,7 +84,6 @@ Layout &Layout::operator=(Layout &&rhs) lastUsedActivity = rhs.lastUsedActivity; isActive = rhs.isActive; isConsideredActive = rhs.isConsideredActive; - isBroken = rhs.isBroken; isLocked = rhs.isLocked; isShownInMenu = rhs.isShownInMenu; isTemplate = rhs.isTemplate; @@ -111,7 +108,6 @@ Layout &Layout::operator=(const Layout &rhs) lastUsedActivity = rhs.lastUsedActivity; isActive = rhs.isActive; isConsideredActive = rhs.isConsideredActive; - isBroken = rhs.isBroken; isLocked = rhs.isLocked; isShownInMenu = rhs.isShownInMenu; isTemplate = rhs.isTemplate; @@ -133,7 +129,6 @@ bool Layout::operator==(const Layout &rhs) const && (color == rhs.color) && (background == rhs.background) && (textColor == rhs.textColor) - && (isBroken == rhs.isBroken) //&& (lastUsedActivity == rhs.lastUsedActivity) /*Disabled because it can change too often*/ //&& (isActive == rhs.isActive) /*Disabled because this is not a data but a layout state*/ //&& (isConsideredActive == rhs.isConsideredActive) /*Disabled because this is not a data but a layout state*/ @@ -183,6 +178,16 @@ bool Layout::isSystemTemplate() const return isTemplate && !id.startsWith(QDir::tempPath()) && !id.startsWith(QDir::homePath()); } +bool Layout::hasErrors() const +{ + return errors > 0; +} + +bool Layout::hasWarnings() const +{ + return warnings > 0; +} + } } diff --git a/app/data/layoutdata.h b/app/data/layoutdata.h index 899d54be5..a5eea0bbf 100644 --- a/app/data/layoutdata.h +++ b/app/data/layoutdata.h @@ -53,7 +53,6 @@ public: QString lastUsedActivity; bool isActive{false}; bool isConsideredActive{false}; //used from settings window to indicate activeness based on selected layouts mode - bool isBroken{false}; bool isLocked{false}; bool isShownInMenu{false}; bool isTemplate{false}; @@ -74,6 +73,9 @@ public: bool isEmpty() const; bool isSystemTemplate() const; + bool hasErrors() const; + bool hasWarnings() const; + //! Operators Layout &operator=(const Layout &rhs); Layout &operator=(Layout &&rhs); diff --git a/app/layout/centrallayout.cpp b/app/layout/centrallayout.cpp index 64349ccf3..1405adc1c 100644 --- a/app/layout/centrallayout.cpp +++ b/app/layout/centrallayout.cpp @@ -148,7 +148,6 @@ Data::Layout CentralLayout::data() const cdata.background = customBackground(); cdata.textColor = customTextColor(); cdata.isActive = (m_corona != nullptr); - cdata.isBroken = isBroken(); cdata.isLocked = !isWritable(); cdata.isShownInMenu = showInMenu(); cdata.hasDisabledBorders = disableBordersForMaximizedWindows(); diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 39c0c6df4..da56ee939 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1669,12 +1669,6 @@ void GenericLayout::importToCorona() Layouts::Storage::self()->importToCorona(this); } -bool GenericLayout::isBroken() const -{ - QStringList errors; - return Layouts::Storage::self()->isBroken(this, errors); -} - Data::ErrorsList GenericLayout::errors() const { return Layouts::Storage::self()->errors(this); diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index d6844d65c..507b73072 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -75,7 +75,6 @@ public: bool isActive() const; //! is loaded and running virtual bool isCurrent(); bool isWritable() const; - bool isBroken() const; virtual int viewsCount(int screen) const; virtual int viewsCount(QScreen *screen) const; diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index d1e696b24..ec8489bc7 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -1133,136 +1133,6 @@ Data::WarningsList Storage::warnings(const Layout::GenericLayout *layout) return warns; } - -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; -} - //! AppletsData Information Data::Applet Storage::metadata(const QString &pluginId) { diff --git a/app/layouts/storage.h b/app/layouts/storage.h index d612e6598..3ab615e16 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -65,7 +65,6 @@ public: bool isWritable(const Layout::GenericLayout *layout) const; bool isLatteContainment(const Plasma::Containment *containment) const; bool isLatteContainment(const KConfigGroup &group) const; - bool isBroken(const Layout::GenericLayout *layout, QStringList &errors) const; bool isSubContainment(const Layout::GenericLayout *layout, const Plasma::Applet *applet) const; bool containsView(const QString &filepath, const int &viewId); diff --git a/app/layouts/synchronizer.cpp b/app/layouts/synchronizer.cpp index bf4ba15fb..cdd7d7c95 100644 --- a/app/layouts/synchronizer.cpp +++ b/app/layouts/synchronizer.cpp @@ -274,9 +274,10 @@ void Synchronizer::updateLayoutsTable() } for (int i = 0; i < m_layouts.rowCount(); ++i) { - if (m_layouts[i].isBroken && !m_layouts[i].isActive) { + if ((m_layouts[i].errors>0 || m_layouts[i].warnings>0) && !m_layouts[i].isActive) { CentralLayout central(this, m_layouts[i].id); - m_layouts[i].isBroken = central.isBroken(); + m_layouts[i].errors = central.errors().count(); + m_layouts[i].warnings = central.warnings().count(); } } } diff --git a/app/settings/settingsdialog/layoutscontroller.cpp b/app/settings/settingsdialog/layoutscontroller.cpp index 8fe104157..93c9b160c 100644 --- a/app/settings/settingsdialog/layoutscontroller.cpp +++ b/app/settings/settingsdialog/layoutscontroller.cpp @@ -512,12 +512,11 @@ void Layouts::initLayouts() m_handler->corona()->layoutsManager()->synchronizer()->updateLayoutsTable(); Latte::Data::LayoutsTable layouts = m_handler->corona()->layoutsManager()->synchronizer()->layoutsTable(); - - QStringList brokenLayouts; + Latte::Data::LayoutsTable erroredlayouts; for (int i=0; i 0) { - if (brokenLayouts.count() == 1) { - m_handler->showInlineMessage(i18nc("settings:broken layout", "Layout %0 is broken! Please remove it to improve stability...").arg(brokenLayouts.join(", ")), + if (erroredlayouts.rowCount() > 0) { + messagesForErroredLayouts(erroredlayouts); + } +} + +void Layouts::messagesForErroredLayouts(const Data::LayoutsTable &layouts) +{ + //! add only warnings first + for (int i=0; ishowInlineMessage(i18nc("settings:layout with warnings", + "Warning: Be careful, Layout %0 reports %1 warning(s) that might need your attention.").arg(layouts[i].name).arg(layouts[i].warnings), + KMessageWidget::Warning, + true); + } + } + + //! add errors in the end in order to be read by the user + for (int i=0; ishowInlineMessage(i18nc("settings:layout with errors", + "Error: Be careful, Layout %0 reports %1 error(s) that you need to repair.").arg(layouts[i].name).arg(layouts[i].errors), KMessageWidget::Error, true); - } else { - m_handler->showInlineMessage(i18nc("settings:broken layouts", "Layouts %0 are broken! Please remove them to improve stability...").arg(brokenLayouts.join(", ")), + } + } + + //! add most important errors in the end in order to be read by the user + for (int i=0; ishowInlineMessage(i18nc("settings:layout with errors and warnings", + "Error: Be careful, Layout %0 reports %1 error(s) and %2 warning(s) that you need to repair.").arg(layouts[i].name).arg(layouts[i].errors).arg(layouts[i].warnings), KMessageWidget::Error, true); } diff --git a/app/settings/settingsdialog/layoutscontroller.h b/app/settings/settingsdialog/layoutscontroller.h index b3d02c282..3584bc9c3 100644 --- a/app/settings/settingsdialog/layoutscontroller.h +++ b/app/settings/settingsdialog/layoutscontroller.h @@ -135,6 +135,8 @@ private: QString uniqueTempDirectory(); QString uniqueLayoutName(QString name); + void messagesForErroredLayouts(const Data::LayoutsTable &layouts); + private: Settings::Handler::TabLayouts *m_handler{nullptr}; Settings::Part::TemplatesKeeper *m_templatesKeeper{nullptr};