diff --git a/app/settings/data/layoutstable.cpp b/app/settings/data/layoutstable.cpp index 7720630ec..525ea6fde 100644 --- a/app/settings/data/layoutstable.cpp +++ b/app/settings/data/layoutstable.cpp @@ -127,6 +127,38 @@ const Layout LayoutsTable::operator[](const uint &index) const return m_layouts[index]; } +QStringList LayoutsTable::allSharesIds() const +{ + QStringList sharesIds; + + for(int i=0; i namespace Latte { @@ -50,6 +53,10 @@ public: LayoutsTable subtracted(const LayoutsTable &rhs) const; + QStringList allSharesIds() const; + QStringList allSharesNames() const; + Latte::Layouts::SharesMap sharesMap() const; + bool contains(const QString &id) const; bool rowExists(const int &row) const; diff --git a/app/settings/settingsdialog.cpp b/app/settings/settingsdialog.cpp index 139bf61ef..5a84fbf43 100644 --- a/app/settings/settingsdialog.cpp +++ b/app/settings/settingsdialog.cpp @@ -40,6 +40,7 @@ #include "delegates/checkboxdelegate.h" #include "delegates/layoutnamedelegate.h" #include "delegates/shareddelegate.h" +#include "tools/settingstools.h" // Qt #include @@ -944,7 +945,11 @@ void SettingsDialog::addLayoutForFile(QString file, QString layoutName, bool new void SettingsDialog::loadSettings() { m_model->clear(); - m_sharesMap.clear(); + + //! The shares map needs to be constructed for start/scratch. + //! We start feeding information with layout_names and during the process + //! we update them to valid layout_ids + Layouts::SharesMap sharesMap; int i = 0; QStringList brokenLayouts; @@ -981,7 +986,7 @@ void SettingsDialog::loadSettings() //! create initial SHARES maps QString shared = central->sharedLayoutName(); if (!shared.isEmpty()) { - m_sharesMap[shared].append(original.id); + sharesMap[shared].append(original.id); } layoutsBuffer << original; @@ -1001,26 +1006,26 @@ void SettingsDialog::loadSettings() QStringList tempSharedNames; //! remove these records after updating - for (QHash::iterator i=m_sharesMap.begin(); i!=m_sharesMap.end(); ++i) { + for (QHash::iterator i=sharesMap.begin(); i!=sharesMap.end(); ++i) { tempSharedNames << i.key(); } //! update keys - for (QHash::iterator i=m_sharesMap.begin(); i!=m_sharesMap.end(); ++i) { + for (QHash::iterator i=sharesMap.begin(); i!=sharesMap.end(); ++i) { QString shareid = layoutsBuffer.idForOriginalName(i.key()); if (!shareid.isEmpty()) { - m_sharesMap[shareid] = i.value(); + sharesMap[shareid] = i.value(); } } //! remove deprecated keys for (const auto &key : tempSharedNames) { - m_sharesMap.remove(key); + sharesMap.remove(key); } - qDebug() << "SHARES MAP ::: " << m_sharesMap; + qDebug() << "SHARES MAP ::: " << sharesMap; - for (QHash::iterator i=m_sharesMap.begin(); i!=m_sharesMap.end(); ++i) { + for (QHash::iterator i=sharesMap.begin(); i!=sharesMap.end(); ++i) { layoutsBuffer[i.key()].shares = i.value(); } @@ -1626,42 +1631,29 @@ void SettingsDialog::syncActiveShares() return; } - QHash currentSharesIdMap; - Layouts::SharesMap currentSharesNamesMap; + Settings::Data::LayoutsTable currentLayoutsData = m_model->currentData(); - 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(); - QString name = m_model->data(m_model->index(i, NAMECOLUMN), Qt::DisplayRole).toString(); - QStringList shareIds = m_model->data(m_model->index(i, SHAREDCOLUMN), Qt::UserRole).toStringList(); - QStringList shareNames; + Layouts::SharesMap currentSharesNamesMap = currentLayoutsData.sharesMap(); + QStringList originalSharesIds = o_layoutsOriginalData.allSharesIds(); + QStringList currentSharesIds = currentLayoutsData.allSharesIds(); - for (const auto &shareid : shareIds) { - QString shareName = nameForId(shareid); - shareNames << shareName; - } + QStringList deprecatedSharesIds = Latte::subtracted(originalSharesIds, currentSharesIds); + QStringList deprecatedSharesNames; - currentSharesIdMap[id] = shareIds; - currentSharesNamesMap[name] = shareNames; + for(int i=0; ilayoutsManager()->synchronizer()->mapHasRecord(oldShareName, currentSharesNamesMap)) { - deprecatedShares << oldShareName; - } - } - } - - qDebug() << " CURRENT SHARES ID MAP :: " << currentSharesIdMap; - m_corona->layoutsManager()->synchronizer()->syncActiveShares(currentSharesNamesMap, deprecatedShares); - - m_sharesMap.clear(); - m_sharesMap = currentSharesIdMap; + m_corona->layoutsManager()->synchronizer()->syncActiveShares(currentSharesNamesMap, deprecatedSharesNames); } bool SettingsDialog::idExistsInModel(QString id) diff --git a/app/settings/settingsdialog.h b/app/settings/settingsdialog.h index bc5c0cf4e..702254ad9 100644 --- a/app/settings/settingsdialog.h +++ b/app/settings/settingsdialog.h @@ -157,8 +157,6 @@ private: Settings::Controller::Layouts *m_layoutsController{nullptr}; Ui::SettingsDialog *ui; - //! SharedLayout #settingsid, Shares #settingsid - QHash m_sharesMap; QHash m_layouts; QList o_settingsOriginalData; diff --git a/app/settings/tools/settingstools.cpp b/app/settings/tools/settingstools.cpp index 3bae08d4b..af237f427 100644 --- a/app/settings/tools/settingstools.cpp +++ b/app/settings/tools/settingstools.cpp @@ -43,4 +43,17 @@ QPalette::ColorGroup colorGroup(const QStyleOptionViewItem &option) } } +QStringList subtracted(const QStringList &original, const QStringList ¤t) +{ + QStringList subtract; + + for(int i=0; i