From 2327965c2435a271cca56e84af5c1e1df2b2898a Mon Sep 17 00:00:00 2001 From: Michail Vourlakos Date: Mon, 29 Jan 2018 22:50:55 +0200 Subject: [PATCH] support pausing activities from main config window --- app/latteconfigdialog.cpp | 10 ++++++++++ app/latteconfigdialog.h | 1 + app/layoutmanager.cpp | 31 ++++++++++++++++++++++++++++++- app/layoutmanager.h | 1 + 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/app/latteconfigdialog.cpp b/app/latteconfigdialog.cpp index a5afb5147..5a805ba4e 100644 --- a/app/latteconfigdialog.cpp +++ b/app/latteconfigdialog.cpp @@ -841,6 +841,16 @@ void LatteConfigDialog::on_switchButton_clicked() updatePauseButtonState(); } +void LatteConfigDialog::on_pauseButton_clicked() +{ + QString id = m_model->data(m_model->index(ui->layoutsView->currentIndex().row(), IDCOLUMN), Qt::DisplayRole).toString(); + Layout *layout = m_layouts[id]; + + if (layout) { + m_corona->layoutManager()->pauseLayout(layout->name()); + } +} + void LatteConfigDialog::layoutsChanged() { for (int i = 0; i < m_model->rowCount(); ++i) { diff --git a/app/latteconfigdialog.h b/app/latteconfigdialog.h index 4ac0f34b8..e2230645b 100644 --- a/app/latteconfigdialog.h +++ b/app/latteconfigdialog.h @@ -62,6 +62,7 @@ private slots: void on_newButton_clicked(); void on_copyButton_clicked(); void on_downloadButton_clicked(); + void on_pauseButton_clicked(); void on_removeButton_clicked(); void on_switchButton_clicked(); void on_importButton_clicked(); diff --git a/app/layoutmanager.cpp b/app/layoutmanager.cpp index c5fa60f0a..9cf369a34 100644 --- a/app/layoutmanager.cpp +++ b/app/layoutmanager.cpp @@ -718,8 +718,16 @@ bool LayoutManager::switchToLayout(QString layoutName, int previousMemoryUsage) //! is such case we just activate these Activities Layout layout(this, Importer::layoutFilePath(layoutName)); + int i = 0; + foreach (auto assignedActivity, layout.activities()) { - m_activitiesController->startActivity(assignedActivity); + //! Starting the activities must be done asynchronous because otherwise + //! the activity manager cant close multiple activities + QTimer::singleShot(i * 1000, [this, assignedActivity]() { + m_activitiesController->startActivity(assignedActivity); + }); + + i = i + 1; } m_activitiesController->setCurrentActivity(layout.activities()[0]); @@ -838,6 +846,27 @@ void LayoutManager::syncMultipleLayoutsToActivities(QString layoutForOrphans) emit activeLayoutsChanged(); } +void LayoutManager::pauseLayout(QString layoutName) +{ + if (memoryUsage() == Dock::MultipleLayouts) { + Layout *layout = activeLayout(layoutName); + + if (layout && !layout->activities().isEmpty()) { + int i = 0; + + foreach (auto activityId, layout->activities()) { + //! Stopping the activities must be done asynchronous because otherwise + //! the activity manager cant close multiple activities + QTimer::singleShot(i * 1000, [this, activityId]() { + m_activitiesController->stopActivity(activityId); + }); + + i = i + 1; + } + } + } +} + void LayoutManager::syncActiveLayoutsToOriginalFiles() { if (memoryUsage() == Dock::MultipleLayouts) { diff --git a/app/layoutmanager.h b/app/layoutmanager.h index 3abfa0639..1e65d347a 100644 --- a/app/layoutmanager.h +++ b/app/layoutmanager.h @@ -68,6 +68,7 @@ public: void loadLayoutOnStartup(QString layoutName); void unload(); void addDock(Plasma::Containment *containment, bool forceLoading = false, int expDockScreen = -1); + void pauseLayout(QString layoutName); void recreateDock(Plasma::Containment *containment); void syncDockViewsToScreens(); void syncActiveLayoutsToOriginalFiles();