From aa608f1bf5a8229610f6aebc039471f9ba817b9d Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 18 Apr 2021 11:20:05 +0300 Subject: [PATCH] use ::storedView approach for Duplicate View --- app/layout/genericlayout.cpp | 18 ---- app/layout/genericlayout.h | 1 - app/layouts/storage.cpp | 157 ++--------------------------------- app/layouts/storage.h | 13 +-- app/view/view.cpp | 3 +- 5 files changed, 10 insertions(+), 182 deletions(-) diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 9dac85ddc..88a6afe4b 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1559,24 +1559,6 @@ void GenericLayout::syncToLayoutFile(bool removeLayoutId) Layouts::Storage::self()->syncToLayoutFile(this, removeLayoutId); } -void GenericLayout::duplicateView(Plasma::Containment *containment) -{ - //! Don't create LatteView when the containment is created because we must update its screen settings first - setBlockAutomaticLatteViewCreation(true); - - Layouts::ViewDelayedCreationData result = Layouts::Storage::self()->copyView(this, containment); - if (result.containment) { - addView(result.containment, result.forceOnPrimary, result.explicitScreen); - - if (result.reactToScreenChange) { - result.containment->reactToScreenChange(); - } - } - - setBlockAutomaticLatteViewCreation(false); - emit viewEdgeChanged(); -} - Data::View GenericLayout::newView(const Latte::Data::View &nextViewData) { if (nextViewData.state() == Data::View::IsInvalid) { diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 327e1d21d..430529c71 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -122,7 +122,6 @@ public: //! this function needs the layout to have first set the corona through initToCorona() function virtual void addView(Plasma::Containment *containment, bool forceOnPrimary = false, int explicitScreen = -1, Layout::ViewsMap *occupied = nullptr); - void duplicateView(Plasma::Containment *containment); void recreateView(Plasma::Containment *containment, bool delayed = true); bool latteViewExists(Plasma::Containment *containment); diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index 91389ef59..a5e72d73d 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -830,156 +830,6 @@ bool Storage::exportTemplate(const Layout::GenericLayout *layout, Plasma::Contai return true; } -ViewDelayedCreationData Storage::copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment) -{ - if (!containment || !layout->corona()) { - return ViewDelayedCreationData(); - } - - qDebug() << "copying containment layout"; - //! Setting mutable for create a containment - layout->corona()->setImmutability(Plasma::Types::Mutable); - - QString temp1File = m_storageTmpDir.path() + "/" + layout->name() + ".copy.view"; - - //! WE NEED A WAY TO COPY A CONTAINMENT!!!! - QFile copyFile(temp1File); - - if (copyFile.exists()) { - copyFile.remove(); - } - - KSharedConfigPtr newFile = KSharedConfig::openConfig(temp1File); - KConfigGroup copied_conts = KConfigGroup(newFile, "Containments"); - KConfigGroup copied_c1 = KConfigGroup(&copied_conts, QString::number(containment->id())); - - containment->config().copyTo(&copied_c1); - - //!investigate if there are subcontainments in the containment to copy also - - //! subId, subAppletId - QHash subInfo; - auto applets = containment->config().group("Applets"); - - for (const auto &applet : applets.groupList()) { - int tSubId = subContainmentId(applets.group(applet)); - - //! It is a subcontainment !!! - if (isValid(tSubId)) { - subInfo[tSubId] = applet; - qDebug() << "subcontainment with id "<< tSubId << " was found in the containment... ::: " << containment->id(); - } - } - - if (subInfo.count() > 0) { - for(const auto subId : subInfo.keys()) { - Plasma::Containment *subcontainment{nullptr}; - - for (const auto containment : layout->corona()->containments()) { - if (containment->id() == subId) { - subcontainment = containment; - break; - } - } - - if (subcontainment) { - KConfigGroup copied_sub = KConfigGroup(&copied_conts, QString::number(subcontainment->id())); - subcontainment->config().copyTo(&copied_sub); - } - } - } - //! end of subcontainments specific code - - //! update ids to unique ones - QString temp2File = newUniqueIdsFile(temp1File, layout); - - //! Finally import the configuration - QList importedDocks = importLayoutFile(layout, temp2File); - - Plasma::Containment *newContainment{nullptr}; - - if (importedDocks.size() == 1) { - newContainment = importedDocks[0]; - } - - if (!newContainment || !newContainment->kPackage().isValid()) { - qWarning() << "the requested containment plugin can not be located or loaded"; - return ViewDelayedCreationData(); - } - - auto config = newContainment->config(); - - //in multi-screen environment the copied dock is moved to alternative screens first - const auto screens = qGuiApp->screens(); - auto dock = layout->viewForContainment(containment); - - bool setOnExplicitScreen = false; - - int dockScrId = IDNULL; - int copyScrId = IDNULL; - - if (dock) { - dockScrId = dock->positioner()->currentScreenId(); - qDebug() << "COPY DOCK SCREEN ::: " << dockScrId; - - 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 (isValid(copyScrId) && copyScrId != dockScrId) { - QList fEdges = layout->freeEdges(copyScrId); - - if (fEdges.contains((Plasma::Types::Location)containment->location())) { - ///set this containment to an explicit screen - config.writeEntry("onPrimary", false); - config.writeEntry("lastScreen", copyScrId); - newContainment->setLocation(containment->location()); - - qDebug() << "COPY DOCK SCREEN NEW SCREEN ::: " << copyScrId; - - setOnExplicitScreen = true; - break; - } - } - } - } - } - - if (!setOnExplicitScreen) { - QList edges = layout->freeEdges(newContainment->screen()); - - if (edges.count() > 0) { - newContainment->setLocation(edges.at(0)); - } else { - newContainment->setLocation(Plasma::Types::BottomEdge); - } - - config.writeEntry("onPrimary", true); - config.writeEntry("lastScreen", dockScrId); - } - - newContainment->config().sync(); - - ViewDelayedCreationData result; - - if (setOnExplicitScreen && isValid(copyScrId)) { - qDebug() << "Copy Dock in explicit screen ::: " << copyScrId; - result.containment = newContainment; - result.forceOnPrimary = false; - result.explicitScreen = copyScrId; - result.reactToScreenChange = true; - } else { - qDebug() << "Copy Dock in current screen..."; - result.containment = newContainment; - result.forceOnPrimary = false; - result.explicitScreen = dockScrId; - result.reactToScreenChange = false; - } - - return result; -} - bool Storage::isBroken(const Layout::GenericLayout *layout, QStringList &errors) const { if (layout->file().isEmpty() || !QFile(layout->file()).exists()) { @@ -1450,10 +1300,15 @@ QString Storage::storedView(const Layout::GenericLayout *layout, const int &cont //! 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"; + QFile tempStoredViewFile(nextTmpStoredViewAbsolutePath); + + if (tempStoredViewFile.exists()) { + tempStoredViewFile.remove(); + } + KSharedConfigPtr destinationPtr = KSharedConfig::openConfig(nextTmpStoredViewAbsolutePath); KConfigGroup destinationContainments = KConfigGroup(destinationPtr, "Containments"); - if (layout->isActive()) { //! update and copy containments auto containment = layout->containmentForId((uint)containmentId); diff --git a/app/layouts/storage.h b/app/layouts/storage.h index 4aa5419ab..931171f62 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -50,14 +50,6 @@ struct SubContaimentIdentityData QString cfgProperty; }; -struct ViewDelayedCreationData -{ - Plasma::Containment *containment{nullptr}; - bool forceOnPrimary{false}; - int explicitScreen{-1}; - bool reactToScreenChange{false}; -}; - class Storage { @@ -85,12 +77,11 @@ public: void importToCorona(const Layout::GenericLayout *layout); void syncToLayoutFile(const Layout::GenericLayout *layout, bool removeLayoutId); - ViewDelayedCreationData copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment); - Data::View newView(const Layout::GenericLayout *destination, const Data::View &nextViewData); + Data::View newView(const Layout::GenericLayout *destination, const Data::View &nextViewData); + void removeView(const QString &filepath, const Data::View &viewData); void updateView(const Layout::GenericLayout *layout, const Data::View &viewData); void updateView(KConfigGroup viewGroup, const Data::View &viewData); - void removeView(const QString &filepath, const Data::View &viewData); QString storedView(const Layout::GenericLayout *layout, const int &containmentId); //returns temp filepath containing all view data bool exportTemplate(const QString &originFile, const QString &destinationFile, const Data::AppletsTable &approvedApplets); diff --git a/app/view/view.cpp b/app/view/view.cpp index 8d5cd2db2..3451354a6 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -465,7 +465,8 @@ void View::reconsiderScreen() void View::duplicateView() { - m_layout->duplicateView(containment()); + QString storedTmpViewFilepath = m_layout->storedView(containment()->id()); + newView(storedTmpViewFilepath); } void View::exportTemplate()