diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index a2baf16b8..9dac85ddc 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1457,6 +1457,33 @@ void GenericLayout::syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap) qDebug() << "end of, syncLatteViewsToScreens ...."; } +QList GenericLayout::subContainmentsOf(uint id) const +{ + QList subs; + + auto containment = containmentForId(id); + + if (!containment || !Layouts::Storage::self()->isLatteContainment(containment)) { + return subs; + } + + auto applets = containment->config().group("Applets"); + + for (const auto &applet : applets.groupList()) { + int tSubId = Layouts::Storage::self()->subContainmentId(applets.group(applet)); + + if (Layouts::Storage::isValid(tSubId)) { + auto subcontainment = containmentForId(tSubId); + + if (subcontainment) { + subs << subcontainment; + } + } + } + + return subs; +} + QList GenericLayout::subContainmentsOf(Plasma::Containment *containment) const { QList subs; @@ -1670,6 +1697,11 @@ void GenericLayout::removeView(const Latte::Data::View &viewData) } } +QString GenericLayout::storedView(const int &containmentId) +{ + return Layouts::Storage::self()->storedView(this, containmentId); +} + void GenericLayout::importToCorona() { Layouts::Storage::self()->importToCorona(this); diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 3f38170a1..327e1d21d 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -97,6 +97,7 @@ public: Latte::View *viewForContainment(uint id) const; Latte::View *viewForContainment(Plasma::Containment *containment) const; Plasma::Containment *containmentForId(uint id) const; + QList subContainmentsOf(uint id) const; static bool viewAtLowerScreenPriority(Latte::View *test, Latte::View *base); static bool viewAtLowerEdgePriority(Latte::View *test, Latte::View *base); @@ -128,6 +129,7 @@ public: Data::View newView(const Latte::Data::View &nextViewData); void removeView(const Latte::Data::View &viewData); void updateView(const Latte::Data::View &viewData); + QString storedView(const int &containmentId); //returns temp filepath containing all view data //! Available edges for specific view in that screen virtual QList availableEdgesForView(QScreen *scr, Latte::View *forView) const; diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index c5fb0d15f..91389ef59 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -668,35 +668,6 @@ Data::View Storage::newView(const Layout::GenericLayout *destinationLayout, cons } return updatedNextViews[0]; - /* - auto config = newContainment->config(); - int primaryScrId = destination->corona()->screenPool()->primaryScreenId(); - - QList edges = destination->freeEdges(primaryScrId); - qDebug() << "org.kde.latte current template edge : " << newContainment->location() << " free edges :: " << edges; - - //! if selected template screen edge is not free - if (!edges.contains(newContainment->location())) { - if (edges.count() > 0) { - newContainment->setLocation(edges.at(0)); - } else { - newContainment->setLocation(Plasma::Types::BottomEdge); - } - } - - config.writeEntry("onPrimary", true); - config.writeEntry("lastScreen", primaryScrId); - - newContainment->config().sync(); - - ViewDelayedCreationData result; - - result.containment = newContainment; - result.forceOnPrimary = false; - result.explicitScreen = primaryScrId; - result.reactToScreenChange = false; - - return result;*/ } void Storage::clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup) @@ -1458,6 +1429,76 @@ void Storage::removeView(const QString &filepath, const Data::View &viewData) containmentGroups.sync(); } +QString Storage::storedView(const Layout::GenericLayout *layout, const int &containmentId) +{ + //! make sure that layout and containmentId are valid + if (!layout) { + return QString(); + } + + if (layout->isActive()) { + auto containment = layout->containmentForId((uint)containmentId); + if (!containment || !isLatteContainment(containment)) { + return QString(); + } + } else { + if (!containsView(layout->file(), containmentId)) { + return QString(); + } + } + + //! at this point we are sure that both layout and containmentId are acceptable + QString nextTmpStoredViewAbsolutePath = m_storageTmpDir.path() + "/" + QFileInfo(layout->name()).fileName() + "." + QString::number(containmentId) + ".stored.tmp"; + + KSharedConfigPtr destinationPtr = KSharedConfig::openConfig(nextTmpStoredViewAbsolutePath); + KConfigGroup destinationContainments = KConfigGroup(destinationPtr, "Containments"); + + + if (layout->isActive()) { + //! update and copy containments + auto containment = layout->containmentForId((uint)containmentId); + containment->config().sync(); + + KConfigGroup destinationViewContainment(&destinationContainments, QString::number(containment->id())); + containment->config().copyTo(&destinationViewContainment); + + QList subconts = layout->subContainmentsOf(containment->id()); + + for(const auto subcont : subconts) { + subcont->config().sync(); + KConfigGroup destinationsubcontainment(&destinationContainments, QString::number(subcont->id())); + subcont->config().copyTo(&destinationsubcontainment); + } + + //! update with latest view data if active view is present + auto view = layout->viewForContainment(containment); + + if (view) { + Data::View currentviewdata = view->data(); + updateView(destinationViewContainment, currentviewdata); + } + } else { + QString containmentid = QString::number(containmentId); + KConfigGroup destinationViewContainment(&destinationContainments, containmentid); + + KSharedConfigPtr originPtr = KSharedConfig::openConfig(layout->file()); + KConfigGroup originContainments = KConfigGroup(originPtr, "Containments"); + + originContainments.group(containmentid).copyTo(&destinationViewContainment); + + Data::GenericTable subconts = subcontainments(originContainments.group(containmentid)); + + for(int i=0; i