From e7568c8478f663474f8896afe693c9b52c43c0ac Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 5 May 2019 20:47:20 +0300 Subject: [PATCH] NO/ASSIGN active Shares to active Centrals --- app/layout/centrallayout.cpp | 38 +++++++++++---- app/layout/centrallayout.h | 7 ++- app/layout/sharedlayout.cpp | 1 + app/settings/settingsdialog.cpp | 83 +++++++++++++++++++++++++++++++++ app/settings/settingsdialog.h | 2 + 5 files changed, 119 insertions(+), 12 deletions(-) diff --git a/app/layout/centrallayout.cpp b/app/layout/centrallayout.cpp index 351b36853..01a53fa62 100644 --- a/app/layout/centrallayout.cpp +++ b/app/layout/centrallayout.cpp @@ -60,7 +60,7 @@ void CentralLayout::unloadContainments() Layout::GenericLayout::unloadContainments(); if (m_sharedLayout) { - disconnect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged); + disconnectSharedConnections(); m_sharedLayout->removeCentralLayout(this); } } @@ -207,28 +207,46 @@ void CentralLayout::setSharedLayoutName(QString name) emit sharedLayoutNameChanged(); } +SharedLayout *CentralLayout::sharedLayout() const +{ + return m_sharedLayout; +} + void CentralLayout::setSharedLayout(SharedLayout *layout) { if (m_sharedLayout == layout) { return; } - //! drop old signals - for (const auto &sc : m_sharedConnections) { - QObject::disconnect(sc); - } - m_sharedConnections.clear(); + + disconnectSharedConnections(); m_sharedLayout = layout; - //! attach new signals - m_sharedConnections << connect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged); - m_sharedConnections << connect(m_sharedLayout, &Layout::AbstractLayout::nameChanged, this, [this]() { + if (layout) { setSharedLayoutName(m_sharedLayout->name()); - }); + + //! attach new signals + m_sharedConnections << connect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged); + m_sharedConnections << connect(m_sharedLayout, &Layout::AbstractLayout::nameChanged, this, [this]() { + setSharedLayoutName(m_sharedLayout->name()); + }); + } else { + setSharedLayoutName(QString()); + } emit viewsCountChanged(); } +void CentralLayout::disconnectSharedConnections() +{ + //! drop old signals + for (const auto &sc : m_sharedConnections) { + QObject::disconnect(sc); + } + + m_sharedConnections.clear(); +} + void CentralLayout::loadConfig() { m_disableBordersForMaximizedWindows = m_layoutGroup.readEntry("disableBordersForMaximizedWindows", false); diff --git a/app/layout/centrallayout.h b/app/layout/centrallayout.h index 7a8778517..00be99276 100644 --- a/app/layout/centrallayout.h +++ b/app/layout/centrallayout.h @@ -67,6 +67,9 @@ public: QStringList activities() const; void setActivities(QStringList activities); + SharedLayout *sharedLayout() const; + void setSharedLayout(SharedLayout *layout); + //! OVERRIDE GeneralLayout implementations void addView(Plasma::Containment *containment, bool forceOnPrimary = false, int explicitScreen = -1, Layout::ViewsMap *occupied = nullptr); void syncLatteViewsToScreens(Layout::ViewsMap *occupiedMap = nullptr) override; @@ -96,11 +99,11 @@ signals: void sharedLayoutNameChanged(); private slots: + void disconnectSharedConnections(); + void loadConfig(); void saveConfig(); - void setSharedLayout(SharedLayout *layout); - private: void init(); void importLocalLayout(QString file); diff --git a/app/layout/sharedlayout.cpp b/app/layout/sharedlayout.cpp index d274ede9c..92db17e3c 100644 --- a/app/layout/sharedlayout.cpp +++ b/app/layout/sharedlayout.cpp @@ -111,6 +111,7 @@ void SharedLayout::addCentralLayout(CentralLayout *layout) if (layout != nullptr && !m_centralLayouts.contains(layout)) { m_centralLayouts.append(layout); + qDebug() << " ADDING Central : " << layout->name() << " at Shared: " << name(); connect(layout, &GenericLayout::activitiesChanged, this, &GenericLayout::activitiesChanged); emit activitiesChanged(); emit viewsCountChanged(); diff --git a/app/settings/settingsdialog.cpp b/app/settings/settingsdialog.cpp index 60b2781db..a4ab33463 100644 --- a/app/settings/settingsdialog.cpp +++ b/app/settings/settingsdialog.cpp @@ -29,6 +29,7 @@ #include "../lattecorona.h" #include "../layout/genericlayout.h" #include "../layout/centrallayout.h" +#include "../layout/sharedlayout.h" #include "../liblatte2/types.h" #include "../plasma/extended/theme.h" #include "delegates/activitiesdelegate.h" @@ -1632,8 +1633,15 @@ bool SettingsDialog::saveAllChanges() } } + //! update SharedLayouts that are Active + if (m_corona->layoutManager()->memoryUsage() == Types::MultipleLayouts) { + updateActiveShares(); + } + + //! reload layouts in layoutmanager m_corona->layoutManager()->loadLayouts(); + //! send to layout manager in which layout to switch Latte::Types::LayoutsMemoryUsage inMemoryOption = static_cast(m_inMemoryButtons->checkedId()); if (m_corona->layoutManager()->memoryUsage() != inMemoryOption) { @@ -1655,6 +1663,70 @@ bool SettingsDialog::saveAllChanges() return true; } +void SettingsDialog::updateActiveShares() +{ + QHash currentSharesMap; + + for (int i = 0; i < m_model->rowCount(); ++i) { + if (isShared(i)) { + QString id = m_model->data(m_model->index(i, IDCOLUMN), Qt::DisplayRole).toString(); + QStringList shares = m_model->data(m_model->index(i, SHAREDCOLUMN), Qt::UserRole).toStringList(); + currentSharesMap[id] = shares; + } + } + + qDebug() << " CURRENT SHARES MAP :: " << currentSharesMap; + + QHash unassign; + + for (QHash::iterator i=currentSharesMap.begin(); i!=currentSharesMap.end(); ++i) { + SharedLayout *shared = m_corona->layoutManager()->sharedLayout(nameForId(i.key())); + if (shared) { + qDebug() << " SHARED :: " << shared->name(); + for (const auto ¢ralId : i.value()) { + CentralLayout *central = m_corona->layoutManager()->centralLayout(nameForId(centralId)); + qDebug() << " CENTRAL NAME :: " << nameForId(centralId); + if (central) { + //! Assign this Central Layout at a different Shared Layout + SharedLayout *oldShared = central->sharedLayout(); + if (shared != oldShared) { + shared->addCentralLayout(central); + central->setSharedLayout(shared); + if (oldShared) { + //! CENTRAL layout that changed from one ACTIVESHARED layout to another + unassign[central] = shared; + } + } + } + } + } + } + + //! CENTRAL Layouts that wont have any SHARED Layout any more + for (QHash::iterator i=m_sharesMap.begin(); i!=m_sharesMap.end(); ++i) { + for (const auto ¢ralId : i.value()) { + if (!mapHasRecord(centralId, currentSharesMap)) { + CentralLayout *central = m_corona->layoutManager()->centralLayout(nameForId(centralId)); + if (central && central->sharedLayout()) { + central->sharedLayout()->removeCentralLayout(central); + central->setSharedLayout(nullptr); + } + } + } + } + + //! Unassing from Shared Layouts Central ones that are not assigned any more + //! IMPORTANT: This must be done after all the ASSIGNMENTS in order to avoid + //! to unload a SharedLayout that it should not + for (QHash::iterator i=unassign.begin(); i!=unassign.end(); ++i) { + i.value()->removeCentralLayout(i.key()); + } + + //! TODO : (active) SharedLayouts that become Active should be unloaded first + m_sharesMap.clear(); + m_sharesMap = currentSharesMap; +} + bool SettingsDialog::idExistsInModel(QString id) { for (int i = 0; i < m_model->rowCount(); ++i) { @@ -1668,6 +1740,17 @@ bool SettingsDialog::idExistsInModel(QString id) return false; } +bool SettingsDialog::mapHasRecord(const QString &record, QHash &map) +{ + for (QHash::iterator i=map.begin(); i!=map.end(); ++i) { + if (i.value().contains(record)) { + return true; + } + } + + return false; +} + bool SettingsDialog::nameExistsInModel(QString name) { for (int i = 0; i < m_model->rowCount(); ++i) { diff --git a/app/settings/settingsdialog.h b/app/settings/settingsdialog.h index a5d7b5bc8..ca445228a 100644 --- a/app/settings/settingsdialog.h +++ b/app/settings/settingsdialog.h @@ -103,10 +103,12 @@ private: QStringList activities, bool locked = false); void updateApplyButtonsState(); void updateSharedLayoutsStates(); + void updateActiveShares(); bool dataAreAccepted(); bool idExistsInModel(QString id); bool importLayoutsFromV1ConfigFile(QString file); + bool mapHasRecord(const QString &record, QHash &map); bool nameExistsInModel(QString name); bool saveAllChanges();