From e36c8557d00f40777f17b17cf7f9cb98d340f9e6 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Fri, 5 Mar 2021 12:54:53 +0200 Subject: [PATCH] fixes for applets order during startup --when an applet is not loaded properly is removed from its registered order --when an applet is loaded properly but is not found in the registered order is at in the end of the stack --- containment/package/contents/ui/main.qml | 3 +- containment/plugin/layoutmanager.cpp | 59 ++++++++++++++++++++++-- containment/plugin/layoutmanager.h | 1 + 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/containment/package/contents/ui/main.qml b/containment/package/contents/ui/main.qml index b79715eda..0bb9e91b2 100644 --- a/containment/package/contents/ui/main.qml +++ b/containment/package/contents/ui/main.qml @@ -583,7 +583,6 @@ Item { addAppletItemInLayout(appletItem, x, y); console.log(applet.pluginName); fastLayoutManager.save(); - plasmoid.configuration.appletOrder = fastLayoutManager.appletOrder; console.log("org.kde.latte configuration from qml appletOrder :: " + plasmoid.configuration.appletOrder + " :: " + fastLayoutManager.appletOrder); updateIndexes(); } @@ -867,7 +866,7 @@ Item { onAppletOrderChanged: plasmoid.configuration.appletOrder = fastLayoutManager.appletOrder; onSplitterPositionChanged: plasmoid.configuration.splitterPosition = fastLayoutManager.splitterPosition; - onSplitterPosition2Changed: plasmoid.configuration.splitterPosition = fastLayoutManager.splitterPosition2; + onSplitterPosition2Changed: plasmoid.configuration.splitterPosition2 = fastLayoutManager.splitterPosition2; } ///////////////BEGIN UI elements diff --git a/containment/plugin/layoutmanager.cpp b/containment/plugin/layoutmanager.cpp index 80303d613..bb382b379 100644 --- a/containment/plugin/layoutmanager.cpp +++ b/containment/plugin/layoutmanager.cpp @@ -213,6 +213,25 @@ void LayoutManager::onRootItemChanged() qDebug() << "org.kde.latte :::: root item set methods...."; } +bool LayoutManager::isValidApplet(const int &id) +{ + //! should be loaded after m_plasmoid has been set properly + if (!m_plasmoid) { + return false; + } + + QList applets = m_plasmoid->property("applets").value>(); + + for(int i=0; iproperty("id").toUInt(); + if (appletid == id) { + return true; + } + } + + return false; +} + //! Actions void LayoutManager::restore() { @@ -228,11 +247,33 @@ void LayoutManager::restore() appletIdsOrder << appletStringIdsOrder[i].toInt(); } - if (alignment==Latte::Types::Justify && splitterPosition!=-1 && splitterPosition2!=-1) { - appletIdsOrder.insert(splitterPosition-1, -1); - appletIdsOrder.insert(splitterPosition2-1, -1); + if (alignment==Latte::Types::Justify) { + if (splitterPosition!=-1 && splitterPosition2!=-1) { + appletIdsOrder.insert(splitterPosition-1, -1); + appletIdsOrder.insert(splitterPosition2-1, -1); + } else { + appletIdsOrder.insert(0, -1); + appletIdsOrder << -1; + } + } + + QList invalidApplets; + + //! track invalid applets, meaning applets that have not be loaded properly + for (int i=0; i0 && !isValidApplet(aid)) { + invalidApplets << aid; + } + } + + //! remove invalid applets from the ids order + for (int i=0; i orderedApplets; for (int i=0; iproperty("id").toUInt(); + if (!appletIdsOrder.contains(id)) { orphanedIds << QString::number(id); } @@ -268,8 +310,15 @@ void LayoutManager::restore() validateAppletsOrder << orderedApplets[i]->property("id").toUInt(); } + for(int i=0; i