diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index e2af5ba3a..fc435a8ac 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -431,6 +431,20 @@ int GenericLayout::screenForContainment(Plasma::Containment *containment) return containment->lastScreen(); } +bool GenericLayout::containsView(const int &containmentId) const +{ + if (!isActive()) { + return Layouts::Storage::self()->containsView(file(), containmentId); + } + + for(auto containment : m_containments) { + if ((int)containment->id() == containmentId && Layouts::Storage::self()->isLatteContainment(containment)) { + return true; + } + } + + return false; +} Latte::View *GenericLayout::viewForContainment(Plasma::Containment *containment) const { @@ -1615,6 +1629,53 @@ void GenericLayout::updateView(const Latte::Data::View &viewData) syncLatteViewsToScreens(); } +void GenericLayout::removeView(const Latte::Data::View &viewData) +{ + if (!containsView(viewData.id.toInt())) { + return; + } + + if (!isActive()) { + Layouts::Storage::self()->removeView(file(), viewData); + return; + } + + Latte::View *view = viewForContainment(viewData.id.toUInt()); + + if (view) { + //! viewMustBeDeleted + m_latteViews.remove(view->containment()); + view->disconnectSensitiveSignals(); + view->positioner()->hideOnExit(); + delete view; + } + + //! delete also the relevant containments + Plasma::Containment *viewcontainment = containmentForId(viewData.id.toUInt()); + + if (viewcontainment) { + m_containments.removeAll(viewcontainment); + delete viewcontainment; + } + + for (int i=0; ilayoutsManager()->memoryUsage() == MemoryUsage::MultipleLayouts) { + QString multiplelayoutfile = Layouts::Importer::layoutUserFilePath(Layout::MULTIPLELAYOUTSHIDDENNAME); + Layouts::Storage::self()->removeView(multiplelayoutfile, viewData); + } else { + //! remove from storage + Layouts::Storage::self()->removeView(file(), viewData); + } +} + void GenericLayout::importToCorona() { Layouts::Storage::self()->importToCorona(this); diff --git a/app/layout/genericlayout.h b/app/layout/genericlayout.h index dcc680aea..33bd3c531 100644 --- a/app/layout/genericlayout.h +++ b/app/layout/genericlayout.h @@ -90,6 +90,7 @@ public: const QList *containments() const; bool contains(Plasma::Containment *containment) const; + bool containsView(const int &containmentId) const; int screenForContainment(Plasma::Containment *containment); Latte::View *highestPriorityView(); @@ -125,6 +126,7 @@ public: bool latteViewExists(Plasma::Containment *containment); void updateView(const Latte::Data::View &viewData); + void removeView(const Latte::Data::View &viewData); //! 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 661c49219..65a440cd6 100644 --- a/app/layouts/storage.cpp +++ b/app/layouts/storage.cpp @@ -1188,6 +1188,14 @@ Data::AppletsTable Storage::plugins(const QString &layoutfile, const int contain //! Views Data +bool Storage::containsView(const QString &filepath, const int &viewId) +{ + KSharedConfigPtr lFile = KSharedConfig::openConfig(filepath); + KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); + KConfigGroup viewGroup = containmentGroups.group(QString::number(viewId)); + return viewGroup.exists() && isLatteContainment(viewGroup); +} + Data::GenericTable Storage::subcontainments(const Layout::GenericLayout *layout, const Plasma::Containment *lattecontainment) const { Data::GenericTable subs; @@ -1333,6 +1341,24 @@ void Storage::updateView(const Layout::GenericLayout *layout, const Data::View & } } +void Storage::removeView(const QString &filepath, const Data::View &viewData) +{ + if (!viewData.isValid()) { + return; + } + + KSharedConfigPtr lFile = KSharedConfig::openConfig(filepath); + KConfigGroup containmentGroups = KConfigGroup(lFile, "Containments"); + + containmentGroups.group(viewData.id).deleteGroup(); + + for (int i=0; iisSelectedLayoutOriginal() ? m_handler->corona()->layoutsManager()->synchronizer()->centralLayout(originallayout.name) : nullptr; Latte::CentralLayout *central = centralActive ? centralActive : new Latte::CentralLayout(this, currentlayout.id); + //! update altered views Latte::Data::ViewsTable alteredViews = m_model->alteredViews(); for (int i=0; ioriginalViewsData(); Latte::Data::ViewsTable currentViews = m_model->currentViewsData(); + Latte::Data::ViewsTable removedViews = originalViews.subtracted(currentViews); + + for (int i=0; iremoveView(removedViews[i]); + } + + if (removedViews.rowCount() > 0) { + m_handler->corona()->layoutsManager()->synchronizer()->syncActiveLayoutsToOriginalFiles(); + } + + //! update model original data m_model->setOriginalData(currentViews); }