From a7ac422b31966050000eb1505edab225c1b5bc48 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 21 Mar 2021 15:31:47 +0200 Subject: [PATCH] support running views data from Layouts::Storage --- app/data/viewdata.h | 1 - app/layout/genericlayout.cpp | 12 +--- app/layouts/storage.cpp | 107 +++++++++++++++++++++++------------ app/layouts/storage.h | 13 ++--- app/view/view.cpp | 21 +++++++ app/view/view.h | 3 + 6 files changed, 103 insertions(+), 54 deletions(-) diff --git a/app/data/viewdata.h b/app/data/viewdata.h index c59e23f49..d1fbefdec 100644 --- a/app/data/viewdata.h +++ b/app/data/viewdata.h @@ -58,7 +58,6 @@ public: float maxLength{1.0}; Plasma::Types::Location edge{Plasma::Types::BottomEdge}; Latte::Types::Alignment alignment{Latte::Types::Center}; - GenericTable subcontainments; bool isValid() const; diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 94ceb9d38..722a6a412 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -154,17 +154,7 @@ void GenericLayout::setBlockAutomaticLatteViewCreation(bool block) bool GenericLayout::isActive() const { - if (!m_corona) { - return false; - } - - GenericLayout *generic = m_corona->layoutsManager()->synchronizer()->layout(m_layoutName); - - if (generic) { - return true; - } else { - return false; - } + return m_corona && (m_corona->layoutsManager()->synchronizer()->layout(m_layoutName) != nullptr); } bool GenericLayout::isCurrent() diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index 4b4c612f0..d52d566d7 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -20,6 +20,7 @@ #include "storage.h" // local +#include #include "importer.h" #include "manager.h" #include "../lattecorona.h" @@ -84,7 +85,7 @@ bool Storage::isWritable(const Layout::GenericLayout *layout) const } } -bool Storage::isLatteContainment(Plasma::Containment *containment) const +bool Storage::isLatteContainment(const Plasma::Containment *containment) const { if (!containment) { return false; @@ -1173,40 +1174,32 @@ Data::AppletsTable Storage::plugins(const QString &layoutfile, const int contain return knownapplets; } +//! Views Data -//! Data For Reports -void Storage::subContainmentsInfo(const QString &file, QHash> &subContainments, QList &assignedSubContainments, QList &orphanSubContainments) +Data::GenericTable Storage::subcontainments(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment) const { - subContainments.clear(); - assignedSubContainments.clear(); - orphanSubContainments.clear(); + Data::GenericTable subs; - KSharedConfigPtr lFile = KSharedConfig::openConfig(file); - KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); + if (!layout || !Layouts::Storage::self()->isLatteContainment(lattecontainment)) { + return subs; + } - //! assigned subcontainments - for (const auto &cId : containmentGroups.groupList()) { - if (Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId))) { - auto applets = containmentGroups.group(cId).group("Applets"); + for (const auto containment : (*layout->containments())) { + if (containment == lattecontainment) { + continue; + } - for (const auto &applet : applets.groupList()) { - KConfigGroup appletSettings = applets.group(applet).group("Configuration"); - int tSubId = appletSettings.readEntry("SystrayContainmentId", IDNULL); + Plasma::Applet *parentApplet = qobject_cast(containment->parent()); - if (isValid(tSubId)) { - assignedSubContainments << tSubId; - subContainments[cId.toInt()].append(tSubId); - } - } + //! add subcontainments for that lattecontainment + if (parentApplet && parentApplet->containment() && parentApplet->containment() == lattecontainment) { + Data::Generic subdata; + subdata.id = QString::number(containment->id()); + subs << subdata; } } - //! orphan subcontainments - for (const auto &cId : containmentGroups.groupList()) { - if (!Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId)) && !assignedSubContainments.contains(cId.toInt())) { - orphanSubContainments << cId.toInt(); - } - } + return subs; } Data::GenericTable Storage::subcontainments(const KConfigGroup &containmentGroup) @@ -1230,6 +1223,26 @@ Data::GenericTable Storage::subcontainments(const KConfigGroup &c return subs; } +Data::View Storage::view(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment) +{ + Data::View vdata; + + if (!layout || !Layouts::Storage::self()->isLatteContainment(lattecontainment)) { + return vdata; + } + + vdata = view(lattecontainment->config()); + + vdata.screen = lattecontainment->screen(); + if (!isValid(vdata.screen)) { + vdata.screen = lattecontainment->lastScreen(); + } + + vdata.subcontainments = subcontainments(layout, lattecontainment); + + return vdata; +} + Data::View Storage::view(const KConfigGroup &containmentGroup) { Data::View vdata; @@ -1238,28 +1251,52 @@ Data::View Storage::view(const KConfigGroup &containmentGroup) return vdata; } - //! id vdata.id = containmentGroup.name(); - - //! active vdata.isActive = false; - - //! onPrimary vdata.onPrimary = containmentGroup.readEntry("onPrimary", true); - - //! screen vdata.screen = containmentGroup.readEntry("lastScreen", IDNULL); - //! edge int location = containmentGroup.readEntry("location", (int)Plasma::Types::BottomEdge); vdata.edge = (Plasma::Types::Location)location; - //! subcontainments + vdata.maxLength = containmentGroup.group("General").readEntry("maxLength", (float)100.0); + + int alignment = containmentGroup.group("General").readEntry("alignment", (int)Latte::Types::Center) ; + vdata.alignment = (Latte::Types::Alignment)alignment; + vdata.subcontainments = subcontainments(containmentGroup); + vdata.setState(Data::View::IsCreated); return vdata; } +Data::ViewsTable Storage::views(const Layout::GenericLayout *layout) +{ + Data::ViewsTable vtable; + + if (!layout) { + return vtable; + } else if (!layout->isActive()) { + return views(layout->file()); + } + + for (const auto containment : (*layout->containments())) { + if (!isLatteContainment(containment)) { + continue; + } + + Latte::View *vw = layout->viewForContainment(containment); + + if (vw) { + vtable << vw->data(); + } else { + vtable << view(layout, containment); + } + } + + return vtable; +} + Data::ViewsTable Storage::views(const QString &file) { Data::ViewsTable vtable; diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 0da24d91d..1fc4201d1 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -69,7 +69,7 @@ public: static const int IDBASE; bool isWritable(const Layout::GenericLayout *layout) const; - bool isLatteContainment(Plasma::Containment *containment) 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; @@ -100,13 +100,15 @@ public: Data::AppletsTable plugins(const Layout::GenericLayout *layout, const int containmentid = IDNULL); Data::AppletsTable plugins(const QString &layoutfile, const int containmentid = IDNULL); - //! Functions used from Layout Reports - //! [containment id, list], list, list[subcontainment ids] - void subContainmentsInfo(const QString &file, QHash> &subContainments, QList &assignedSubContainments, QList &orphanSubContainments); //! list QList viewsScreens(const QString &file); + Data::GenericTable subcontainments(const KConfigGroup &containmentGroup); + Data::GenericTable subcontainments(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment) const; + Data::View view(const KConfigGroup &containmentGroup); + Data::View view(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment); Data::ViewsTable views(const QString &file); + Data::ViewsTable views(const Layout::GenericLayout *layout); private: Storage(); @@ -125,9 +127,6 @@ private: //! imports a layout file and returns the containments for the docks QList importLayoutFile(const Layout::GenericLayout *layout, QString file); - Data::View view(const KConfigGroup &containmentGroup); - Data::GenericTable subcontainments(const KConfigGroup &containmentGroup); - private: QTemporaryDir m_storageTmpDir; diff --git a/app/view/view.cpp b/app/view/view.cpp index 949f656f5..b0a5e86bb 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -1273,6 +1273,27 @@ bool View::mimeContainsPlasmoid(QMimeData *mimeData, QString name) return false; } +Latte::Data::View View::data() const +{ + Latte::Data::View vdata; + vdata.id = QString::number(containment()->id()); + vdata.isActive = true; + vdata.onPrimary = onPrimary(); + + vdata.screen = containment()->screen(); + if (!Layouts::Storage::isValid(vdata.screen)) { + vdata.screen = containment()->lastScreen(); + } + + vdata.edge = location(); + vdata.maxLength = m_maxLength * 100; + vdata.alignment = m_alignment; + vdata.subcontainments = Layouts::Storage::self()->subcontainments(layout(), containment()); + + vdata.setState(Latte::Data::View::IsCreated); + return vdata; +} + QQuickItem *View::colorizer() const { return m_colorizer; diff --git a/app/view/view.h b/app/view/view.h index caf7c363e..63bbd73e0 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -32,6 +32,7 @@ #include "indicator/indicator.h" #include "settings/primaryconfigview.h" #include "windowstracker/windowstracker.h" +#include "../data/viewdata.h" #include "../shortcuts/globalshortcuts.h" #include "../layout/genericlayout.h" #include "../plasma/quick/containmentview.h" @@ -237,6 +238,8 @@ public: QQuickView *configView(); + Latte::Data::View data() const; + ViewPart::Effects *effects() const; ViewPart::ContextMenu *contextMenu() const; ViewPart::ContainmentInterface *extendedInterface() const;