From ac2a4cffc6c92b134bf3db1824e3d987d93a587d Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Wed, 19 Aug 2020 16:26:08 +0300 Subject: [PATCH] support different subcontainments types --create an abstract implementation for subcontainments such as systrays and group applet in order to use the same infrastructure for all storage operations such as Multiple Layouts loading, copying views, providing important information etc. BUG:418642 --- app/layout/genericlayout.cpp | 97 +++++++++--------- app/layout/genericlayout.h | 6 +- app/layouts/storage.cpp | 185 +++++++++++++++++++++-------------- app/layouts/storage.h | 14 ++- 4 files changed, 171 insertions(+), 131 deletions(-) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 6bf44eeca..ee80fb2bd 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -82,21 +82,21 @@ void GenericLayout::unloadContainments() m_unloadedContainmentsIds.clear(); - QList systrays; + QList subcontainments; - //!identify systrays and unload them first + //!identify subcontainments and unload them first for (const auto containment : m_containments) { if (Plasma::Applet *parentApplet = qobject_cast(containment->parent())) { - systrays.append(containment); + subcontainments.append(containment); } } - while (!systrays.isEmpty()) { - Plasma::Containment *systray = systrays.at(0); - m_unloadedContainmentsIds << QString::number(systray->id()); - systrays.removeFirst(); - m_containments.removeAll(systray); - delete systray; + while (!subcontainments.isEmpty()) { + Plasma::Containment *sub = subcontainments.at(0); + m_unloadedContainmentsIds << QString::number(sub->id()); + subcontainments.removeFirst(); + m_containments.removeAll(sub); + delete sub; } while (!m_containments.isEmpty()) { @@ -682,14 +682,14 @@ void GenericLayout::addContainment(Plasma::Containment *containment) void GenericLayout::appletCreated(Plasma::Applet *applet) { - //! In Multiple Layout the orphaned systrays must be assigned to layouts + //! In Multiple Layout the orphaned subcontainments must be assigned to layouts //! when the user adds them - KConfigGroup appletSettings = applet->containment()->config().group("Applets").group(QString::number(applet->id())).group("Configuration"); + KConfigGroup appletSettings = applet->containment()->config().group("Applets").group(QString::number(applet->id())); - int systrayId = appletSettings.readEntry("SystrayContainmentId", -1); + int subId = Layouts::Storage::self()->subContainmentId(appletSettings); - if (systrayId != -1) { - uint sId = (uint)systrayId; + if (subId >= 0) { + uint sId = (uint)subId; for (const auto containment : m_corona->containments()) { if (containment->id() == sId) { @@ -1035,7 +1035,7 @@ void GenericLayout::assignToLayout(Latte::View *latteView, QListconfig().writeEntry("layoutId", name()); if (latteView->containment() != containment) { - //! assign signals only to systrays + //! assign signals only to subcontainments //! the View::setLayout() is responsible for the View::Containment signals connect(containment, &QObject::destroyed, this, &GenericLayout::containmentDestroyed); connect(containment, &Plasma::Applet::destroyedChanged, this, &GenericLayout::destroyedChanged); @@ -1067,10 +1067,10 @@ QList GenericLayout::unassignFromLayout(Latte::View *latt for (const auto containment : m_containments) { Plasma::Applet *parentApplet = qobject_cast(containment->parent()); - //! add systrays from that latteView + //! add subcontainments from that latteView if (parentApplet && parentApplet->containment() && parentApplet->containment() == latteView->containment()) { containments << containment; - //! unassign signals only to systrays + //! unassign signals only to subcontainments //! the View::setLayout() is responsible for the View::Containment signals disconnect(containment, &QObject::destroyed, this, &GenericLayout::containmentDestroyed); disconnect(containment, &Plasma::Applet::destroyedChanged, this, &GenericLayout::destroyedChanged); @@ -1387,24 +1387,23 @@ void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap) qDebug() << "end of, syncLatteViewsToScreens ...."; } -QList GenericLayout::containmentSystrays(Plasma::Containment *containment) const +QList GenericLayout::subContainmentsOf(Plasma::Containment *containment) const { - QList trays; + QList subs; if (Layouts::Storage::self()->isLatteContainment(containment)) { auto applets = containment->config().group("Applets"); for (const auto &applet : applets.groupList()) { - KConfigGroup appletSettings = applets.group(applet).group("Configuration"); - int tSysId = appletSettings.readEntry("SystrayContainmentId", -1); + int tSubId = Layouts::Storage::self()->subContainmentId(applets.group(applet)); - if (tSysId != -1) { - trays << tSysId; + if (tSubId >= 0) { + subs << tSubId; } } } - return trays; + return subs; } @@ -1451,37 +1450,37 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool) } report += ""; - //! latte containment ids, systrays - QHash> systrays; - QList assignedSystrays; - QList orphanSystrays; + //! latte containment ids, subcontainments + QHash> subContainments; + QList assignedSubContainments; + QList orphanSubContainments; if (isActive()) { - //! organize systrays + //! organize subcontainments for (const auto containment : m_containments) { - QList trays = containmentSystrays(containment); - if (trays.count() > 0) { - systrays[containment->id()] = trays; - assignedSystrays << trays; + QList subs = subContainmentsOf(containment); + if (subs.count() > 0) { + subContainments[containment->id()] = subs; + assignedSubContainments << subs; } } - //! orphan systrays + //! orphan subcontainments for (const auto containment : m_containments) { - if (!Layouts::Storage::self()->isLatteContainment(containment) && !assignedSystrays.contains(containment->id())) { - orphanSystrays << containment->id(); + if (!Layouts::Storage::self()->isLatteContainment(containment) && !assignedSubContainments.contains(containment->id())) { + orphanSubContainments << containment->id(); } } } else { - Layouts::Storage::self()->systraysInformation(file(), systrays, assignedSystrays, orphanSystrays); + Layouts::Storage::self()->subContainmentsInfo(file(), subContainments, assignedSubContainments, orphanSubContainments); } report += ""; - report += "" + i18n("Orphan Systrays:") +""; - if (orphanSystrays.count() == 0) { + report += "" + i18n("Orphan SubContainments:") +""; + if (orphanSubContainments.count() == 0) { report += " -- "; } else { - report += "" + idsLineStr(orphanSystrays) +""; + report += "" + idsLineStr(orphanSubContainments) +""; } report += ""; report += ""; @@ -1491,7 +1490,7 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool) "" + i18n("Screen") + "" + "" + i18nc("screen edge","Edge") + "" + "" + i18nc("active dock/panel","Active") + "" + - "" + i18n("Systrays") + ""; + "" + i18n("SubContainments") + ""; report += "
"; @@ -1524,13 +1523,13 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool) vData.onPrimary = onPrimary; vData.screenId = screenId; - vData.systrays = containmentSystrays(containment); + vData.subContainments = subContainmentsOf(containment); viewsData << vData; } } } else { - viewsData = Layouts::Storage::self()->viewsData(file(), systrays); + viewsData = Layouts::Storage::self()->viewsData(file(), subContainments); } //! sort views data @@ -1582,15 +1581,15 @@ QString GenericLayout::reportHtml(const ScreenPool *screenPool) } report += "" + activeStr + "" ; - //! systrays - QString systraysStr = " -- "; - if (viewsData[i].systrays.count() > 0) { - systraysStr = idsLineStr(viewsData[i].systrays); + //! subcontainments + QString subContainmentsStr = " -- "; + if (viewsData[i].subContainments.count() > 0) { + subContainmentsStr = idsLineStr(viewsData[i].subContainments); } if(viewsData[i].active) { - systraysStr = "" + systraysStr + ""; + subContainmentsStr = "" + subContainmentsStr + ""; } - report += "" + systraysStr + ""; + report += "" + subContainmentsStr + ""; report += ""; } diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 5e1e9b02f..b57786f7e 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -55,7 +55,7 @@ struct ViewData bool onPrimary; //on primary int screenId; //explicit screen id int location; //edge location - QList systrays; + QList subContainments; }; //! This is views map in the following structure: @@ -131,7 +131,7 @@ public: virtual QList freeEdges(QScreen *scr) const; virtual QList freeEdges(int screen) const; - //! Bind this latteView and its relevant containments(including systrays) + //! Bind this latteView and its relevant containments(including subcontainments) //! to this layout. It is used for moving a Latte::View from layout to layout) void assignToLayout(Latte::View *latteView, QList containments); //! Unassign that latteView from this layout (this is used for moving a latteView @@ -196,7 +196,7 @@ private: bool mapContainsId(const ViewsMap *map, uint viewId) const; - QList containmentSystrays(Plasma::Containment *containment) const; + QList subContainmentsOf(Plasma::Containment *containment) const; QList sortedViewsData(const QList &viewsData); diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index 2e4a22ef1..95acee63b 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -52,12 +52,9 @@ Storage::Storage() SubContaimentIdentityData data; //! Systray - data.cfgGroup = "Configuration"; data.cfgGroup = "SystrayContainmentId"; - m_subIdentities << data; - + m_subIdentities << SubContaimentIdentityData{.cfgGroup="Configuration", .cfgProperty="SystrayContainmentId"}; //! Group applet - data.cfgGroup = "Configuration"; data.cfgGroup = "ContainmentId"; - m_subIdentities << data; + m_subIdentities << SubContaimentIdentityData{.cfgGroup="Configuration", .cfgProperty="ContainmentId"}; } Storage::~Storage() @@ -118,20 +115,23 @@ bool Storage::isSubContainment(const Layout::GenericLayout *layout, const Plasma bool Storage::isSubContainment(const KConfigGroup &appletGroup) const { - return subContainmentId(appletGroup) > 0; + return isValid(subContainmentId(appletGroup)); +} + +bool Storage::isValid(const int &id) +{ + return id >= IDBASE; } int Storage::subContainmentId(const KConfigGroup &appletGroup) const { - int subId{-1}; - //! cycle through subcontainments identities for (auto subidentity : m_subIdentities) { KConfigGroup appletConfigGroup = appletGroup; if (!subidentity.cfgGroup.isEmpty()) { //! if identity provides specific configuration group - if (appletGroup.hasGroup(subidentity.cfgGroup)) { + if (appletConfigGroup.hasGroup(subidentity.cfgGroup)) { appletConfigGroup = appletGroup.group(subidentity.cfgGroup); } } @@ -139,13 +139,41 @@ int Storage::subContainmentId(const KConfigGroup &appletGroup) const if (!subidentity.cfgProperty.isEmpty()) { //! if identity provides specific property for configuration group if (appletConfigGroup.hasKey(subidentity.cfgProperty)) { - subId = appletConfigGroup.readEntry(subidentity.cfgProperty, -1); - return subId; + return appletConfigGroup.readEntry(subidentity.cfgProperty, IDNULL); } } } - return subId; + return IDNULL; +} + +int Storage::subIdentityIndex(const KConfigGroup &appletGroup) const +{ + if (!isSubContainment(appletGroup)) { + return IDNULL; + } + + //! cycle through subcontainments identities + for (int i=0; i systrayParentContainmentIds; - QHash systrayAppletIds; + //! first is the subcontainment id + QHash subParentContainmentIds; + QHash subAppletIds; //qDebug() << "Ids:" << allIds; @@ -304,19 +332,17 @@ QString Storage::newUniqueIdsLayoutFromFile(const Layout::GenericLayout *layout, auto appletsEntries = investigate_conts.group(cId).group("Applets"); toInvestigateAppletIds << appletsEntries.groupList(); - //! investigate for systrays + //! investigate for subcontainments for (const auto &appletId : appletsEntries.groupList()) { - KConfigGroup appletSettings = appletsEntries.group(appletId).group("Configuration"); + int subId = subContainmentId(appletsEntries.group(appletId)); - int tSysId = appletSettings.readEntry("SystrayContainmentId", -1); - - //! It is a systray !!! - if (tSysId != -1) { - QString tSysIdStr = QString::number(tSysId); - toInvestigateSystrayContIds << tSysIdStr; - systrayParentContainmentIds[tSysIdStr] = cId; - systrayAppletIds[tSysIdStr] = appletId; - qDebug() << "systray was found in the containment..."; + //! It is a subcontainment !!! + if (isValid(subId)) { + QString tSubIdStr = QString::number(subId); + toInvestigateSubContIds << tSubIdStr; + subParentContainmentIds[tSubIdStr] = cId; + subAppletIds[tSubIdStr] = appletId; + qDebug() << "subcontainment was found in the containment..."; } } } @@ -397,11 +423,23 @@ QString Storage::newUniqueIdsLayoutFromFile(const Layout::GenericLayout *layout, } } - //! must update also the systray id in its applet - for (const auto &systrayId : toInvestigateSystrayContIds) { - KConfigGroup systrayParentContainment = investigate_conts.group(systrayParentContainmentIds[systrayId]); - systrayParentContainment.group("Applets").group(systrayAppletIds[systrayId]).group("Configuration").writeEntry("SystrayContainmentId", assigned[systrayId]); - systrayParentContainment.sync(); + //! must update also the sub id in its applet + for (const auto &subId : toInvestigateSubContIds) { + KConfigGroup subParentContainment = investigate_conts.group(subParentContainmentIds[subId]); + KConfigGroup subAppletConfig = subParentContainment.group("Applets").group(subAppletIds[subId]); + + int entityIndex = subIdentityIndex(subAppletConfig); + + if (entityIndex >= 0) { + if (!m_subIdentities[entityIndex].cfgGroup.isEmpty()) { + subAppletConfig = subAppletConfig.group(m_subIdentities[entityIndex].cfgGroup); + } + + if (!m_subIdentities[entityIndex].cfgProperty.isEmpty()) { + subAppletConfig.writeEntry(m_subIdentities[entityIndex].cfgProperty, assigned[subId]); + subParentContainment.sync(); + } + } } investigate_conts.sync(); @@ -467,11 +505,9 @@ QList Storage::importLayoutFile(const Layout::GenericLayo KSharedConfigPtr filePtr = KSharedConfig::openConfig(file); auto newContainments = layout->corona()->importLayout(KConfigGroup(filePtr, "")); - ///Find latte and systray containments qDebug() << " imported containments ::: " << newContainments.length(); QList importedDocks; - //QList systrays; for (const auto containment : newContainments) { if (isLatteContainment(containment)) { @@ -507,41 +543,40 @@ ViewDelayedCreationData Storage::copyView(const Layout::GenericLayout *layout, P containment->config().copyTo(&copied_c1); - //!investigate if there multiple systray(s) in the containment to copy also + //!investigate if there are subcontainments in the containment to copy also - //! systrayId, systrayAppletId - QHash systraysInfo; + //! subId, subAppletId + QHash subInfo; auto applets = containment->config().group("Applets"); for (const auto &applet : applets.groupList()) { - KConfigGroup appletSettings = applets.group(applet).group("Configuration"); + int tSubId = subContainmentId(applets.group(applet)); - int tSysId = appletSettings.readEntry("SystrayContainmentId", -1); - - if (tSysId != -1) { - systraysInfo[tSysId] = applet; - qDebug() << "systray with id "<< tSysId << " was found in the containment... ::: " << tSysId; + //! It is a subcontainment !!! + if (isValid(tSubId)) { + subInfo[tSubId] = applet; + qDebug() << "subcontainment with id "<< tSubId << " was found in the containment... ::: " << containment->id(); } } - if (systraysInfo.count() > 0) { - for(const auto systrayId : systraysInfo.keys()) { - Plasma::Containment *systray{nullptr}; + if (subInfo.count() > 0) { + for(const auto subId : subInfo.keys()) { + Plasma::Containment *subcontainment{nullptr}; for (const auto containment : layout->corona()->containments()) { - if (containment->id() == systrayId) { - systray = containment; + if (containment->id() == subId) { + subcontainment = containment; break; } } - if (systray) { - KConfigGroup copied_systray = KConfigGroup(&copied_conts, QString::number(systray->id())); - systray->config().copyTo(&copied_systray); + if (subcontainment) { + KConfigGroup copied_sub = KConfigGroup(&copied_conts, QString::number(subcontainment->id())); + subcontainment->config().copyTo(&copied_sub); } } } - //! end of systray specific code + //! end of subcontainments specific code //! update ids to unique ones QString temp2File = newUniqueIdsLayoutFromFile(layout, temp1File); @@ -568,19 +603,19 @@ ViewDelayedCreationData Storage::copyView(const Layout::GenericLayout *layout, P bool setOnExplicitScreen = false; - int dockScrId = -1; - int copyScrId = -1; + int dockScrId = IDNULL; + int copyScrId = IDNULL; if (dock) { dockScrId = dock->positioner()->currentScreenId(); qDebug() << "COPY DOCK SCREEN ::: " << dockScrId; - if (dockScrId != -1 && screens.count() > 1) { + if (isValid(dockScrId) && screens.count() > 1) { for (const auto scr : screens) { copyScrId = layout->corona()->screenPool()->id(scr->name()); //the screen must exist and not be the same with the original dock - if (copyScrId > -1 && copyScrId != dockScrId) { + if (isValid(copyScrId) && copyScrId != dockScrId) { QList fEdges = layout->freeEdges(copyScrId); if (fEdges.contains((Plasma::Types::Location)containment->location())) { @@ -616,7 +651,7 @@ ViewDelayedCreationData Storage::copyView(const Layout::GenericLayout *layout, P ViewDelayedCreationData result; - if (setOnExplicitScreen && copyScrId > -1) { + if (setOnExplicitScreen && isValid(copyScrId)) { qDebug() << "Copy Dock in explicit screen ::: " << copyScrId; result.containment = newContainment; result.forceOnPrimary = false; @@ -763,41 +798,41 @@ bool Storage::isBroken(const Layout::GenericLayout *layout, QStringList &errors) } //! Data For Reports -void Storage::systraysInformation(const QString &file, QHash> &systrays, QList &assignedSystrays, QList &orphanSystrays) +void Storage::subContainmentsInfo(const QString &file, QHash> &subContainments, QList &assignedSubContainments, QList &orphanSubContainments) { - systrays.clear(); - assignedSystrays.clear(); - orphanSystrays.clear(); + subContainments.clear(); + assignedSubContainments.clear(); + orphanSubContainments.clear(); KSharedConfigPtr lFile = KSharedConfig::openConfig(file); KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); - //! assigned systrays + //! 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 &applet : applets.groupList()) { KConfigGroup appletSettings = applets.group(applet).group("Configuration"); - int tSysId = appletSettings.readEntry("SystrayContainmentId", -1); + int tSubId = appletSettings.readEntry("SystrayContainmentId", IDNULL); - if (tSysId != -1) { - assignedSystrays << tSysId; - systrays[cId.toInt()].append(tSysId); + if (isValid(tSubId)) { + assignedSubContainments << tSubId; + subContainments[cId.toInt()].append(tSubId); } } } } - //! orphan systrays + //! orphan subcontainments for (const auto &cId : containmentGroups.groupList()) { - if (!Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId)) && !assignedSystrays.contains(cId.toInt())) { - orphanSystrays << cId.toInt(); + if (!Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId)) && !assignedSubContainments.contains(cId.toInt())) { + orphanSubContainments << cId.toInt(); } } } -QList Storage::viewsData(const QString &file, const QHash> &systrays) +QList Storage::viewsData(const QString &file, const QHash> &subContainments) { QList viewsData; @@ -819,13 +854,13 @@ QList Storage::viewsData(const QString &file, const QHash Storage::viewsScreens(const QString &file) for (const auto &cId : containmentGroups.groupList()) { if (Layouts::Storage::self()->isLatteContainment(containmentGroups.group(cId))) { - int screenId = containmentGroups.group(cId).readEntry("lastScreen", -1); + int screenId = containmentGroups.group(cId).readEntry("lastScreen", IDNULL); - if (screenId != -1 && !screens.contains(screenId)) { + if (isValid(screenId) && !screens.contains(screenId)) { screens << screenId; } } diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 77c2bae77..c001c48e8 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -40,6 +40,9 @@ struct ViewData; namespace Latte { namespace Layouts { +#define IDBASE 0 +#define IDNULL -1 + struct SubContaimentIdentityData { QString cfgGroup; @@ -67,6 +70,8 @@ public: bool isBroken(const Layout::GenericLayout *layout, QStringList &errors) const; bool isSubContainment(const Layout::GenericLayout *layout, const Plasma::Applet *applet) const; + int subContainmentId(const KConfigGroup &appletGroup) const; + Plasma::Containment *subContainmentOf(const Layout::GenericLayout *layout, const Plasma::Applet *applet); void lock(const Layout::GenericLayout *layout); //! make it only read-only @@ -80,20 +85,21 @@ public: /// STATIC //! Check if an applet config group is valid or belongs to removed applet static bool appletGroupIsValid(const KConfigGroup &appletGroup); + static bool isValid(const int &id); //! Functions used from Layout Reports - //! [containment id, list], list, list[systrays ids] - void systraysInformation(const QString &file, QHash> &systrays, QList &assignedSystrays, QList &orphanSystrays); + //! [containment id, list], list, list[subcontainment ids] + void subContainmentsInfo(const QString &file, QHash> &subContainments, QList &assignedSubContainments, QList &orphanSubContainments); //! list QList viewsScreens(const QString &file); //! list - QList viewsData(const QString &file, const QHash> &systrays); + QList viewsData(const QString &file, const QHash> &subContainments); private: Storage(); bool isSubContainment(const KConfigGroup &appletGroup) const; - int subContainmentId(const KConfigGroup &appletGroup) const; + int subIdentityIndex(const KConfigGroup &appletGroup) const; //! STORAGE !//// QString availableId(QStringList all, QStringList assigned, int base);