diff --git a/app/lattecorona.cpp b/app/lattecorona.cpp index f045d255d..a33e6dae9 100644 --- a/app/lattecorona.cpp +++ b/app/lattecorona.cpp @@ -1164,8 +1164,8 @@ QStringList Corona::viewTemplatesData() void Corona::addView(const uint &containmentId, const QString &templateId) { auto view = m_layoutsManager->synchronizer()->viewForContainment((int)containmentId); - if (view && view->layout() && !templateId.isEmpty()) { - view->layout()->newView(templateId); + if (view) { + view->newView(templateId); } } diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index fc435a8ac..8c6391916 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -1550,21 +1550,14 @@ void GenericLayout::duplicateView(Plasma::Containment *containment) emit viewEdgeChanged(); } -void GenericLayout::newView(const QString &templateFile) +void GenericLayout::newView(const QString &templateFile, const Latte::Data::View &nextViewData) { - //! 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()->newView(this, templateFile); - if (result.containment) { - addView(result.containment, result.forceOnPrimary, result.explicitScreen); - - if (result.reactToScreenChange) { - result.containment->reactToScreenChange(); - } + if (nextViewData.state() == Data::View::IsInvalid) { + return; } - setBlockAutomaticLatteViewCreation(false); + Data::View result = Layouts::Storage::self()->newView(this, templateFile, nextViewData); + emit viewEdgeChanged(); } diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index 33bd3c531..8ee460bac 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -125,8 +125,9 @@ public: void recreateView(Plasma::Containment *containment, bool delayed = true); bool latteViewExists(Plasma::Containment *containment); - void updateView(const Latte::Data::View &viewData); + void newView(const QString &templateFile, const Latte::Data::View &nextViewData); void removeView(const Latte::Data::View &viewData); + void updateView(const Latte::Data::View &viewData); //! Available edges for specific view in that screen virtual QList availableEdgesForView(QScreen *scr, Latte::View *forView) const; @@ -147,7 +148,6 @@ public: Latte::Data::ViewsTable viewsTable() const; public slots: - Q_INVOKABLE void newView(const QString &templateFile); Q_INVOKABLE int viewsWithTasks() const; virtual Q_INVOKABLE QList qmlFreeEdges(int screen) const; //change to types diff --git a/app/layouts/storage.cpp b/app/layouts/storage.cpp index ffe358894..67cbfd20b 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -573,27 +573,50 @@ QList Storage::importLayoutFile(const Layout::GenericLayo qDebug() << " imported containments ::: " << newContainments.length(); - QList importedDocks; + QList importedViews; for (const auto containment : newContainments) { if (isLatteContainment(containment)) { qDebug() << "new latte containment id: " << containment->id(); - importedDocks << containment; + importedViews << containment; } } - return importedDocks; + return importedViews; } -ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destination, const QString &templateFile) +void Storage::importContainments(const QString &originFile, const QString &destinationFile) { - if (!destination || !destination->corona()) { - return ViewDelayedCreationData(); + if (originFile.isEmpty() || destinationFile.isEmpty()) { + return; + } + + KSharedConfigPtr originPtr = KSharedConfig::openConfig(originFile); + KSharedConfigPtr destinationPtr = KSharedConfig::openConfig(destinationFile); + + KConfigGroup originContainments = KConfigGroup(originPtr, "Containments"); + KConfigGroup destinationContainments = KConfigGroup(destinationPtr, "Containments"); + + for (const auto originContId : originContainments.groupList()) { + KConfigGroup destinationContainment(&destinationContainments, originContId); + originContainments.group(originContId).copyTo(&destinationContainment); + } + + destinationContainments.sync(); +} + +Data::View Storage::newView(const Layout::GenericLayout *destinationLayout, const QString &templateFile, const Data::View &nextViewData) +{ + if (!destinationLayout) { + return Data::View(); } qDebug() << "new view for layout"; - //! Setting mutable for create a containment - destination->corona()->setImmutability(Plasma::Types::Mutable); + + if (destinationLayout->isActive()) { + //! Setting mutable for create a containment + destinationLayout->corona()->setImmutability(Plasma::Types::Mutable); + } //! copy view template path in temp file QString templateTmpAbsolutePath = m_storageTmpDir.path() + "/" + QFileInfo(templateFile).fileName() + ".newids"; @@ -605,18 +628,46 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio QFile(templateFile).copy(templateTmpAbsolutePath); //! update ids to unique ones - QString temp2File = newUniqueIdsFile(templateTmpAbsolutePath, destination); + QString temp2File = newUniqueIdsFile(templateTmpAbsolutePath, destinationLayout); - //! Finally import the configuration - QList importedViews = importLayoutFile(destination, temp2File); + //! update view containment data in case next data are provided + if (nextViewData.state() != Data::View::IsInvalid) { - Plasma::Containment *newContainment = (importedViews.size() == 1 ? importedViews[0] : nullptr); + KSharedConfigPtr lFile = KSharedConfig::openConfig(temp2File); + KConfigGroup containments = KConfigGroup(lFile, "Containments"); - if (!newContainment || !newContainment->kPackage().isValid()) { - qWarning() << "the requested containment plugin can not be located or loaded from:" << templateFile; - return ViewDelayedCreationData(); + for (const auto cId : containments.groupList()) { + if (Layouts::Storage::self()->isLatteContainment(containments.group(cId))) { + //! first view we will find, we update its value + updateView(containments.group(cId), nextViewData); + break; + } + } + } + + Data::ViewsTable updatedNextViews = views(temp2File); + + if (updatedNextViews.rowCount() <= 0) { + return Data::View(); } + if (destinationLayout->isActive()) { + //! import views for active layout + QList importedViews = importLayoutFile(destinationLayout, temp2File); + + Plasma::Containment *newContainment = (importedViews.size() == 1 ? importedViews[0] : nullptr); + + if (!newContainment || !newContainment->kPackage().isValid()) { + qWarning() << "the requested containment plugin can not be located or loaded from:" << templateFile; + return Data::View(); + } + } else { + //! import views for inactive layout + importContainments(temp2File, destinationLayout->file()); + } + + return updatedNextViews[0]; + /* auto config = newContainment->config(); int primaryScrId = destination->corona()->screenPool()->primaryScreenId(); @@ -644,7 +695,7 @@ ViewDelayedCreationData Storage::newView(const Layout::GenericLayout *destinatio result.explicitScreen = primaryScrId; result.reactToScreenChange = false; - return result; + return result;*/ } void Storage::clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup) diff --git a/app/layouts/storage.h b/app/layouts/storage.h index a11918f3c..72534d62c 100644 --- a/app/layouts/storage.h +++ b/app/layouts/storage.h @@ -86,7 +86,7 @@ public: void importToCorona(const Layout::GenericLayout *layout); void syncToLayoutFile(const Layout::GenericLayout *layout, bool removeLayoutId); ViewDelayedCreationData copyView(const Layout::GenericLayout *layout, Plasma::Containment *containment); - ViewDelayedCreationData newView(const Layout::GenericLayout *destination, const QString &templateFile); + Data::View newView(const Layout::GenericLayout *destination, const QString &templateFile, const Data::View &nextViewData); void updateView(const Layout::GenericLayout *layout, const Data::View &viewData); void updateView(KConfigGroup viewGroup, const Data::View &viewData); @@ -120,6 +120,7 @@ private: Storage(); void clearExportedLayoutSettings(KConfigGroup &layoutSettingsGroup); + void importContainments(const QString &originFile, const QString &destinationFile); bool isSubContainment(const KConfigGroup &appletGroup) const; int subIdentityIndex(const KConfigGroup &appletGroup) const; diff --git a/app/view/view.cpp b/app/view/view.cpp index c801ee69d..ab1224461 100644 --- a/app/view/view.cpp +++ b/app/view/view.cpp @@ -32,10 +32,12 @@ #include "../apptypes.h" #include "../lattecorona.h" #include "../data/layoutdata.h" +#include "../data/viewstable.h" #include "../declarativeimports/interfaces.h" #include "../indicator/factory.h" #include "../layout/genericlayout.h" #include "../layouts/manager.h" +#include "../layouts/storage.h" #include "../plasma/extended/theme.h" #include "../screenpool.h" #include "../settings/universalsettings.h" @@ -322,7 +324,7 @@ void View::init(Plasma::Containment *plasma_containment) connect(m_effects, &ViewPart::Effects::innerShadowChanged, this, [&]() { emit availableScreenRectChangedFrom(this); - }); + }); connect(m_positioner, &ViewPart::Positioner::onHideWindowsForSlidingOut, this, &View::hideWindowsForSlidingOut); connect(m_positioner, &ViewPart::Positioner::screenGeometryChanged, this, &View::screenGeometryChanged); connect(m_positioner, &ViewPart::Positioner::windowSizeChanged, this, [&]() { @@ -472,6 +474,32 @@ void View::exportTemplate() exportDlg->show(); } +void View::newView(const QString &templateFile) +{ + if (templateFile.isEmpty() || !m_layout) { + return; + } + + Data::ViewsTable templateviews = Layouts::Storage::self()->views(templateFile); + + if (templateviews.rowCount() <= 0) { + return; + } + + Data::View nextdata = templateviews[0]; + int scrId = onPrimary() ? m_corona->screenPool()->primaryScreenId() : m_positioner->currentScreenId(); + + QList freeedges = m_layout->freeEdges(scrId); + + if (!freeedges.contains(nextdata.edge)) { + nextdata.edge = (freeedges.count() > 0 ? freeedges[0] : Plasma::Types::BottomEdge); + } + + nextdata.setState(Data::View::OriginFromViewTemplate, templateFile); + + m_layout->newView(templateFile, nextdata); +} + void View::removeView() { if (m_layout) { diff --git a/app/view/view.h b/app/view/view.h index b04ceee7a..c2e14e4b9 100644 --- a/app/view/view.h +++ b/app/view/view.h @@ -276,9 +276,11 @@ public: void releaseConfigView(); public slots: + Q_INVOKABLE void newView(const QString &templateFile); + Q_INVOKABLE void removeView(); Q_INVOKABLE void duplicateView(); Q_INVOKABLE void exportTemplate(); - Q_INVOKABLE void removeView(); + Q_INVOKABLE void moveToLayout(QString layoutName); diff --git a/shell/package/contents/configuration/LatteDockConfiguration.qml b/shell/package/contents/configuration/LatteDockConfiguration.qml index d36cb29c6..388a2b678 100644 --- a/shell/package/contents/configuration/LatteDockConfiguration.qml +++ b/shell/package/contents/configuration/LatteDockConfiguration.qml @@ -541,7 +541,7 @@ Loader { var item = actionsModel.get(index); if (item && item.actionId === "add:") { - latteView.layout.newView(item.templateId); + latteView.newView(item.templateId); } else if (item && item.actionId === "duplicate:") { latteView.duplicateView(); }