From 78d212ce8e2eff93449b8a9d9a55a1e0c2fde501 Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Sun, 5 May 2019 17:46:14 +0300 Subject: [PATCH] SharedLayouts saving their settings from Layouts --- app/layout/centrallayout.cpp | 13 ++++- app/layout/centrallayout.h | 2 + app/layout/genericlayout.cpp | 16 +++--- app/settings/settingsdialog.cpp | 89 ++++++++++++++++++--------------- 4 files changed, 70 insertions(+), 50 deletions(-) diff --git a/app/layout/centrallayout.cpp b/app/layout/centrallayout.cpp index 1715bd9de..351b36853 100644 --- a/app/layout/centrallayout.cpp +++ b/app/layout/centrallayout.cpp @@ -212,11 +212,20 @@ void CentralLayout::setSharedLayout(SharedLayout *layout) if (m_sharedLayout == layout) { return; } - disconnect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged); + //! drop old signals + for (const auto &sc : m_sharedConnections) { + QObject::disconnect(sc); + } + m_sharedConnections.clear(); m_sharedLayout = layout; - connect(m_sharedLayout, &Layout::GenericLayout::viewsCountChanged, this, &Layout::GenericLayout::viewsCountChanged); + //! 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()); + }); + emit viewsCountChanged(); } diff --git a/app/layout/centrallayout.h b/app/layout/centrallayout.h index e30fc0445..7a8778517 100644 --- a/app/layout/centrallayout.h +++ b/app/layout/centrallayout.h @@ -115,6 +115,8 @@ private: QStringList m_activities; QPointer m_sharedLayout; + + QList m_sharedConnections; }; } diff --git a/app/layout/genericlayout.cpp b/app/layout/genericlayout.cpp index 1a93c543a..ac0885df8 100644 --- a/app/layout/genericlayout.cpp +++ b/app/layout/genericlayout.cpp @@ -593,19 +593,19 @@ void GenericLayout::destroyedChanged(bool destroyed) void GenericLayout::renameLayout(QString newName) { + if (!m_corona || m_corona->layoutManager()->memoryUsage() != Types::MultipleLayouts) { + return; + } + if (m_layoutFile != Importer::layoutFilePath(newName)) { setFile(Importer::layoutFilePath(newName)); } - if (m_layoutName != newName) { - setName(newName); - } + setName(newName); - //! thus this is a linked file - if (m_corona) { - for (const auto containment : m_containments) { - containment->config().writeEntry("layoutId", m_layoutName); - } + for (const auto containment : m_containments) { + qDebug() << "Cont ID :: " << containment->id(); + containment->config().writeEntry("layoutId", m_layoutName); } } diff --git a/app/settings/settingsdialog.cpp b/app/settings/settingsdialog.cpp index 070beadc9..9aeb62374 100644 --- a/app/settings/settingsdialog.cpp +++ b/app/settings/settingsdialog.cpp @@ -1448,7 +1448,7 @@ bool SettingsDialog::saveAllChanges() QString switchToLayout; - QHash centralLayoutsToRename; + QHash activeLayoutsToRename; //! remove layouts that have been removed from the user for (const auto &initLayout : m_initLayoutPaths) { @@ -1482,61 +1482,65 @@ bool SettingsDialog::saveAllChanges() } //qDebug() << i << ". " << id << " - " << color << " - " << name << " - " << menu << " - " << lActivities; - CentralLayout *centralLayout = m_corona->layoutManager()->centralLayout(m_layouts[id]->name()); - - CentralLayout *layout = centralLayout ? centralLayout : m_layouts[id]; + //! update the generic parts of the layouts + Layout::GenericLayout *genericActive= m_corona->layoutManager()->layout(m_layouts[id]->name()); + Layout::GenericLayout *generic = genericActive ? genericActive : m_layouts[id]; //! unlock read-only layout - if (!layout->isWritable()) { - layout->unlock(); + if (!generic->isWritable()) { + generic->unlock(); } if (color.startsWith("/")) { //it is image file in such case - if (color != layout->background()) { - layout->setBackground(color); + if (color != generic->background()) { + generic->setBackground(color); } - if (layout->textColor() != textColor) { - layout->setTextColor(textColor); + if (generic->textColor() != textColor) { + generic->setTextColor(textColor); } } else { - if (color != layout->color()) { - layout->setColor(color); - layout->setBackground(QString()); - layout->setTextColor(QString()); + if (color != generic->color()) { + generic->setColor(color); + generic->setBackground(QString()); + generic->setTextColor(QString()); } } - if (layout->showInMenu() != menu) { - layout->setShowInMenu(menu); + //! update only the Central-specific layout parts + CentralLayout *centralActive= m_corona->layoutManager()->centralLayout(m_layouts[id]->name()); + CentralLayout *central = centralActive ? centralActive : m_layouts[id]; + + if (central->showInMenu() != menu) { + central->setShowInMenu(menu); } - if (layout->disableBordersForMaximizedWindows() != disabledBorders) { - layout->setDisableBordersForMaximizedWindows(disabledBorders); + if (central->disableBordersForMaximizedWindows() != disabledBorders) { + central->setDisableBordersForMaximizedWindows(disabledBorders); } - if (layout->activities() != cleanedActivities) { - layout->setActivities(cleanedActivities); + if (central->activities() != cleanedActivities) { + central->setActivities(cleanedActivities); } //! If the layout name changed OR the layout path is a temporary one - if (layout->name() != name || (id.startsWith("/tmp/"))) { + if (generic->name() != name || (id.startsWith("/tmp/"))) { //! If the layout is Active in MultipleLayouts - if (m_corona->layoutManager()->memoryUsage() == Types::MultipleLayouts && centralLayout) { - qDebug() << " Active Layout Should Be Renamed From : " << layout->name() << " TO :: " << name; - centralLayoutsToRename[name] = layout; + if (m_corona->layoutManager()->memoryUsage() == Types::MultipleLayouts && generic->isActive()) { + qDebug() << " Active Layout Should Be Renamed From : " << generic->name() << " TO :: " << name; + activeLayoutsToRename[name] = generic; } - QString tempFile = layoutTempDir.path() + "/" + QString(layout->name() + ".layout.latte"); + QString tempFile = layoutTempDir.path() + "/" + QString(generic->name() + ".layout.latte"); qDebug() << "new temp file ::: " << tempFile; - if ((m_corona->layoutManager()->memoryUsage() == Types::SingleLayout) && (layout->name() == m_corona->layoutManager()->currentLayoutName())) { + if ((m_corona->layoutManager()->memoryUsage() == Types::SingleLayout) && (generic->name() == m_corona->layoutManager()->currentLayoutName())) { switchToLayout = name; } - layout = m_layouts.take(id); - delete layout; + generic = m_layouts.take(id); + delete generic; QFile(id).rename(tempFile); @@ -1556,6 +1560,7 @@ bool SettingsDialog::saveAllChanges() CentralLayout *nLayout = new CentralLayout(this, newFile); m_layouts[newFile] = nLayout; + //! updating the #SETTINGSID in the model for the layout that was renamed for (int j = 0; j < m_model->rowCount(); ++j) { QString tId = m_model->data(m_model->index(j, IDCOLUMN), Qt::DisplayRole).toString(); @@ -1574,14 +1579,18 @@ bool SettingsDialog::saveAllChanges() QString orphanedLayout; if (m_corona->layoutManager()->memoryUsage() == Types::MultipleLayouts) { - for (const auto &newLayoutName : centralLayoutsToRename.keys()) { - qDebug() << " Active Layout Is Renamed From : " << centralLayoutsToRename[newLayoutName]->name() << " TO :: " << newLayoutName; - CentralLayout *layout = centralLayoutsToRename[newLayoutName]; - layout->renameLayout(newLayoutName); - - //! that means it is an active layout for orphaned Activities - if (layout->activities().isEmpty()) { - orphanedLayout = newLayoutName; + for (const auto &newLayoutName : activeLayoutsToRename.keys()) { + Layout::GenericLayout *layout = activeLayoutsToRename[newLayoutName]; + qDebug() << " Active Layout of Type: " << layout->type() << " Is Renamed From : " << activeLayoutsToRename[newLayoutName]->name() << " TO :: " << newLayoutName; + layout->renameLayout(newLayoutName); + + if (layout->type() == Layout::Type::Central) { + CentralLayout *central = qobject_cast(layout); + + if (central->activities().isEmpty()) { + //! that means it is an active layout for orphaned Activities + orphanedLayout = newLayoutName; + } } } } @@ -1592,11 +1601,11 @@ bool SettingsDialog::saveAllChanges() QString name = m_model->data(m_model->index(i, NAMECOLUMN), Qt::DisplayRole).toString(); bool locked = m_model->data(m_model->index(i, NAMECOLUMN), Qt::UserRole).toBool(); - CentralLayout *centralLayout = m_corona->layoutManager()->centralLayout(m_layouts[id]->name()); - CentralLayout *layout = centralLayout ? centralLayout : m_layouts[id]; + Layout::GenericLayout *generic = m_corona->layoutManager()->layout(m_layouts[id]->name()); + Layout::GenericLayout *layout = generic ? generic : m_layouts[id]; - if (layout && locked && layout->isWritable()) { - layout->lock(); + if (generic && locked && generic->isWritable()) { + generic->lock(); } }