From 51044ce630694becc9c2d1370ae1b79445081401 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 30 Apr 2021 00:26:47 +0300 Subject: [PATCH] layout:provide errors/warnings structured nicely --- app/data/CMakeLists.txt | 1 + app/data/errordata.cpp | 2 +- app/data/errordata.h | 11 ++-- app/data/errorinformationdata.h | 2 + app/data/layoutdata.cpp | 10 ++++ app/data/layoutdata.h | 2 + app/layout/centrallayout.cpp | 3 + app/layout/genericlayout.cpp | 10 ++++ app/layout/genericlayout.h | 5 ++ app/layouts/storage.cpp | 101 ++++++++++++++++++++++---------- app/layouts/storage.h | 8 ++- 11 files changed, 117 insertions(+), 38 deletions(-) diff --git a/app/data/CMakeLists.txt b/app/data/CMakeLists.txt index 657426651..f4ddc2df1 100644 --- a/app/data/CMakeLists.txt +++ b/app/data/CMakeLists.txt @@ -2,6 +2,7 @@ set(lattedock-app_SRCS ${lattedock-app_SRCS} ${CMAKE_CURRENT_SOURCE_DIR}/activitydata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/appletdata.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/errordata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/errorinformationdata.cpp ${CMAKE_CURRENT_SOURCE_DIR}/genericbasictable.cpp ${CMAKE_CURRENT_SOURCE_DIR}/genericdata.cpp diff --git a/app/data/errordata.cpp b/app/data/errordata.cpp index c5a8fdc8c..49e24c164 100644 --- a/app/data/errordata.cpp +++ b/app/data/errordata.cpp @@ -62,7 +62,7 @@ bool Error::operator==(const Error &rhs) const { return (id == rhs.id) && (name == rhs.name) - && (information == rhs.information) + && (information == rhs.information); } bool Error::operator!=(const Error &rhs) const diff --git a/app/data/errordata.h b/app/data/errordata.h index 25a9ec6a5..c9e251121 100644 --- a/app/data/errordata.h +++ b/app/data/errordata.h @@ -18,8 +18,8 @@ * */ -#ifndef ERRORDATA_H -#define ERRORDATA_H +#ifndef GENERICERRORDATA_H +#define GENERICERRORDATA_H //! local #include "genericdata.h" @@ -55,15 +55,16 @@ public: GenericTable information; -private: - }; -typedef QList ErrorList; +typedef Error Warning; +typedef QList ErrorsList; +typedef QList WarningsList; } } Q_DECLARE_METATYPE(Latte::Data::Error) +Q_DECLARE_METATYPE(Latte::Data::ErrorsList) #endif diff --git a/app/data/errorinformationdata.h b/app/data/errorinformationdata.h index 737de1a36..7413c5fda 100644 --- a/app/data/errorinformationdata.h +++ b/app/data/errorinformationdata.h @@ -52,6 +52,8 @@ public: bool operator!=(const ErrorInformation &rhs) const; }; +typedef ErrorInformation WarningInformation; + } } diff --git a/app/data/layoutdata.cpp b/app/data/layoutdata.cpp index fe32639ee..b9ff51c8f 100644 --- a/app/data/layoutdata.cpp +++ b/app/data/layoutdata.cpp @@ -47,6 +47,8 @@ Layout::Layout(Layout &&o) hasDisabledBorders(o.hasDisabledBorders), activities(o.activities), backgroundStyle(o.backgroundStyle), + errors(o.errors), + warnings(o.warnings), views(o.views) { } @@ -67,6 +69,8 @@ Layout::Layout(const Layout &o) hasDisabledBorders(o.hasDisabledBorders), activities(o.activities), backgroundStyle(o.backgroundStyle), + errors(o.errors), + warnings(o.warnings), views(o.views) { } @@ -89,6 +93,8 @@ Layout &Layout::operator=(Layout &&rhs) hasDisabledBorders = rhs.hasDisabledBorders; activities = rhs.activities; backgroundStyle = rhs.backgroundStyle; + errors = rhs.errors; + warnings = rhs.warnings; views = rhs.views; return (*this); @@ -112,6 +118,8 @@ Layout &Layout::operator=(const Layout &rhs) hasDisabledBorders = rhs.hasDisabledBorders; activities = rhs.activities; backgroundStyle = rhs.backgroundStyle; + errors = rhs.errors; + warnings = rhs.warnings; views = rhs.views; return (*this); @@ -135,6 +143,8 @@ bool Layout::operator==(const Layout &rhs) const && (hasDisabledBorders == rhs.hasDisabledBorders) && (activities == rhs.activities) && (backgroundStyle == rhs.backgroundStyle) + && (errors == rhs.errors) + && (warnings == rhs.warnings) && (views == rhs.views); } diff --git a/app/data/layoutdata.h b/app/data/layoutdata.h index fd9b80177..899d54be5 100644 --- a/app/data/layoutdata.h +++ b/app/data/layoutdata.h @@ -59,6 +59,8 @@ public: bool isTemplate{false}; bool hasDisabledBorders{false}; QStringList activities; + int errors{0}; + int warnings{0}; Latte::Layout::BackgroundStyle backgroundStyle{Latte::Layout::ColorBackgroundStyle}; diff --git a/app/layout/centrallayout.cpp b/app/layout/centrallayout.cpp index aea7d5ba9..64349ccf3 100644 --- a/app/layout/centrallayout.cpp +++ b/app/layout/centrallayout.cpp @@ -155,6 +155,9 @@ Data::Layout CentralLayout::data() const cdata.activities = activities(); cdata.lastUsedActivity = lastUsedActivity(); + cdata.errors = errors().count(); + cdata.warnings = warnings().count(); + return cdata; } diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 69e8eee07..39c0c6df4 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1675,6 +1675,16 @@ bool GenericLayout::isBroken() const return Layouts::Storage::self()->isBroken(this, errors); } +Data::ErrorsList GenericLayout::errors() const +{ + return Layouts::Storage::self()->errors(this); +} + +Data::WarningsList GenericLayout::warnings() const +{ + return Layouts::Storage::self()->warnings(this); +} + Latte::Data::ViewsTable GenericLayout::viewsTable() const { return Layouts::Storage::self()->views(this); diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index de2e1db89..d6844d65c 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -23,6 +23,7 @@ // local #include #include "abstractlayout.h" +#include "../data/errordata.h" #include "../data/viewdata.h" #include "../data/viewstable.h" @@ -148,6 +149,10 @@ public: Latte::Data::ViewsTable viewsTable() const; + //! errors/warnings + Data::ErrorsList errors() const; + Data::WarningsList warnings() const; + public slots: Q_INVOKABLE int viewsWithTasks() const; virtual Q_INVOKABLE QList qmlFreeEdges(int screen) const; //change to types diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index f32761df2..d1e696b24 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -924,7 +924,7 @@ bool Storage::hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout, return !error.information.isEmpty(); } -bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *layout, Data::Error &warning) +bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *layout, Data::Warning &warning) { if (!layout || layout->file().isEmpty() || !QFile(layout->file()).exists()) { return false; @@ -968,11 +968,11 @@ bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *l QString cid = QString::number(containment->id()); if (conflicted.contains(cid)) { - Data::ErrorInformation errorinfo; - errorinfo.containment = metadata(containment->pluginMetaData().pluginId()); - errorinfo.containment.storageId = cid; + Data::WarningInformation warninginfo; + warninginfo.containment = metadata(containment->pluginMetaData().pluginId()); + warninginfo.containment.storageId = cid; - warning.information << errorinfo; + warning.information << warninginfo; } for (const auto applet : containment->applets()) { @@ -982,13 +982,13 @@ bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *l continue; } - Data::ErrorInformation errorinfo; - errorinfo.containment = metadata(containment->pluginMetaData().pluginId()); - errorinfo.containment.storageId = cid; - errorinfo.applet = metadata(applet->pluginMetaData().pluginId()); - errorinfo.applet.storageId = aid; + Data::WarningInformation warninginfo; + warninginfo.containment = metadata(containment->pluginMetaData().pluginId()); + warninginfo.containment.storageId = cid; + warninginfo.applet = metadata(applet->pluginMetaData().pluginId()); + warninginfo.applet.storageId = aid; - warning.information << errorinfo; + warning.information << warninginfo; } } } else { // inactive layout @@ -1021,11 +1021,11 @@ bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *l //! create warning data for (const auto &cid : containmentsEntries.groupList()) { if (conflicted.contains(cid)) { - Data::ErrorInformation errorinfo; - errorinfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", "")); - errorinfo.containment.storageId = cid; + Data::WarningInformation warninginfo; + warninginfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", "")); + warninginfo.containment.storageId = cid; - warning.information << errorinfo; + warning.information << warninginfo; } for (const auto &aid : containmentsEntries.group(cid).group("Applets").groupList()) { @@ -1033,13 +1033,13 @@ bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *l continue; } - Data::ErrorInformation errorinfo; - errorinfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", "")); - errorinfo.containment.storageId = cid; - errorinfo.applet = metadata(containmentsEntries.group(cid).group("Applets").group(aid).readEntry("plugin", "")); - errorinfo.applet.storageId = aid; + Data::WarningInformation warninginfo; + warninginfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", "")); + warninginfo.containment.storageId = cid; + warninginfo.applet = metadata(containmentsEntries.group(cid).group("Applets").group(aid).readEntry("plugin", "")); + warninginfo.applet.storageId = aid; - warning.information << errorinfo; + warning.information << warninginfo; } } } @@ -1047,7 +1047,7 @@ bool Storage::hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *l return !warning.information.isEmpty(); } -bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Error &warning) +bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Warning &warning) { if (!layout || layout->file().isEmpty() || !QFile(layout->file()).exists()) { return false; @@ -1067,10 +1067,10 @@ bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Da continue; } - Data::ErrorInformation errorinfo; - errorinfo.containment = metadata(containment->pluginMetaData().pluginId()); - errorinfo.containment.storageId = cid; - warning.information << errorinfo; + Data::WarningInformation warninginfo; + warninginfo.containment = metadata(containment->pluginMetaData().pluginId()); + warninginfo.containment.storageId = cid; + warning.information << warninginfo; } } else { // inactive layout @@ -1083,16 +1083,57 @@ bool Storage::hasOrphanedSubContainments(const Layout::GenericLayout *layout, Da continue; } - Data::ErrorInformation errorinfo; - errorinfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", "")); - errorinfo.containment.storageId = cid; - warning.information << errorinfo; + Data::WarningInformation warninginfo; + warninginfo.containment = metadata(containmentsEntries.group(cid).readEntry("plugin", "")); + warninginfo.containment.storageId = cid; + warning.information << warninginfo; } } return !warning.information.isEmpty(); } +Data::ErrorsList Storage::errors(const Layout::GenericLayout *layout) +{ + Data::ErrorsList errs; + + if (!layout || layout->file().isEmpty() || !QFile(layout->file()).exists()) { + return errs; + } + + Data::Error error1; + + if (hasDifferentAppletsWithSameId(layout, error1)) { + errs << error1; + } + + return errs; +} + +Data::WarningsList Storage::warnings(const Layout::GenericLayout *layout) +{ + Data::WarningsList warns; + + if (!layout || layout->file().isEmpty() || !QFile(layout->file()).exists()) { + return warns; + } + + Data::Warning warning1; + + if (hasAppletsAndContainmentsWithSameId(layout, warning1)) { + warns << warning1; + } + + Data::Warning warning2; + + if (hasOrphanedSubContainments(layout, warning2)) { + warns << warning2; + } + + return warns; +} + + bool Storage::isBroken(const Layout::GenericLayout *layout, QStringList &errors) const { if (layout->file().isEmpty() || !QFile(layout->file()).exists()) { diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 9365f4696..d612e6598 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -110,6 +110,10 @@ public: Data::ViewsTable views(const QString &file); Data::ViewsTable views(const Layout::GenericLayout *layout); + //! errors/warning; + Data::ErrorsList errors(const Layout::GenericLayout *layout); + Data::WarningsList warnings(const Layout::GenericLayout *layout); + private: Storage(); @@ -134,8 +138,8 @@ private: //! errors/warnings checkers bool hasDifferentAppletsWithSameId(const Layout::GenericLayout *layout, Data::Error &error); - bool hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *layout, Data::Error &warning); - bool hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Error &warning); + bool hasAppletsAndContainmentsWithSameId(const Layout::GenericLayout *layout, Data::Warning &warning); + bool hasOrphanedSubContainments(const Layout::GenericLayout *layout, Data::Warning &warning); private: QTemporaryDir m_storageTmpDir;