diff --git a/libtaskmanager/launchertasksmodel.h b/libtaskmanager/launchertasksmodel.h --- a/libtaskmanager/launchertasksmodel.h +++ b/libtaskmanager/launchertasksmodel.h @@ -118,7 +118,7 @@ * @param url A launcher URL. * @returns @c true if a launcher was added. */ - bool requestAddLauncherToActivity(const QUrl &url); + bool requestAddLauncherToActivity(const QUrl &url, const QString &activity); /** * Request removing the launcher with the given URL from the current activity. @@ -131,7 +131,7 @@ * @param url A launcher URL. * @returns @c true if the launcher was removed. */ - bool requestRemoveLauncherFromActivity(const QUrl &url); + bool requestRemoveLauncherFromActivity(const QUrl &url, const QString &activity); /** * Return the list of activities the launcher belongs to. diff --git a/libtaskmanager/launchertasksmodel.cpp b/libtaskmanager/launchertasksmodel.cpp --- a/libtaskmanager/launchertasksmodel.cpp +++ b/libtaskmanager/launchertasksmodel.cpp @@ -46,16 +46,30 @@ typedef QSet ActivitiesSet; +template +inline bool isOnAllActivities(const ActivitiesCollection &activities) +{ + return activities.isEmpty() || activities.contains(NULL_UUID); +} + + class LauncherTasksModel::Private { public: Private(LauncherTasksModel *q); - KActivities::Consumer activities; + KActivities::Consumer activitiesConsumer; QList launchersOrder; QHash activitiesForLauncher; + inline void setActivitiesForLauncher(const QUrl &url, const ActivitiesSet &activities) { + if (activities.size() == activitiesConsumer.activities().size()) { + activitiesForLauncher[url] = { NULL_UUID }; + } else { + activitiesForLauncher[url] = activities; + } + } QHash appDataCache; QTimer sycocaChangeTimer; @@ -145,12 +159,12 @@ newActivities = activities; } else { - if (activities.isEmpty() || activities.contains(NULL_UUID)) { + if (isOnAllActivities(activities)) { // If the new list is empty, or has a null uuid, this // launcher should be on all activities newActivities = ActivitiesSet { NULL_UUID }; - } else if (activitiesForLauncher[url].isEmpty() || activitiesForLauncher[url].contains(NULL_UUID)) { + } else if (isOnAllActivities(activitiesForLauncher[url])) { // If we have been on all activities before, and we have // been asked to be on a specific one, lets make an // exception - we will set the activities to exactly @@ -166,7 +180,7 @@ } if (newActivities != activitiesForLauncher[url]) { - activitiesForLauncher[url] = newActivities; + setActivitiesForLauncher(url, newActivities); emit q->dataChanged( q->index(row, 0), @@ -184,7 +198,7 @@ // This is a new one const auto count = launchersOrder.count(); q->beginInsertRows(QModelIndex(), count, count); - activitiesForLauncher[url] = activities; + setActivitiesForLauncher(url, activities); launchersOrder.append(url); q->endInsertRows(); @@ -203,17 +217,19 @@ const auto currentActivities = activitiesForLauncher[url]; ActivitiesSet newActivities; + bool remove = false; bool update = false; - if (currentActivities.isEmpty()) { + if (isOnAllActivities(currentActivities)) { // We are currently on all activities. // Should we go away, or just remove from the current one? - if (activities.isEmpty()) { + + if (isOnAllActivities(activities)) { remove = true; } else { - for (const auto& activity: currentActivities) { + for (const auto& activity: activitiesConsumer.activities()) { if (!activities.contains(activity)) { newActivities << activity; } else { @@ -247,7 +263,7 @@ q->endRemoveRows(); } else if (update) { - activitiesForLauncher[url] = newActivities; + setActivitiesForLauncher(url, newActivities); emit q->dataChanged( q->index(row, 0), @@ -332,7 +348,7 @@ const auto &activities = d->activitiesForLauncher[launcher]; QString serializedLauncher; - if (activities.isEmpty() || activities.contains(NULL_UUID)) { + if (isOnAllActivities(activities)) { serializedLauncher = launcher.toString(); } else { @@ -369,12 +385,12 @@ // If we have a null uuid, it means we are on all activities // and we should contain only the null uuid - if (activities.isEmpty() || activities.contains(NULL_UUID)) { + if (isOnAllActivities(activities)) { activities = { NULL_UUID }; } else { // Filter out invalid activities - const auto allActivities = d->activities.activities(); + const auto allActivities = d->activitiesConsumer.activities(); ActivitiesSet validActivities; for (const auto& activity: activities) { if (allActivities.contains(activity)) { @@ -460,12 +476,12 @@ bool LauncherTasksModel::requestAddLauncher(const QUrl &url) { - return d->requestAddLauncherToActivities(url, QStringList()); + return d->requestAddLauncherToActivities(url, { NULL_UUID }); } bool LauncherTasksModel::requestRemoveLauncher(const QUrl &url) { - return d->requestRemoveLauncherFromActivities(url, QStringList()); + return d->requestRemoveLauncherFromActivities(url, { NULL_UUID }); } bool LauncherTasksModel::requestAddLauncherToActivity(const QUrl &url, const QString &activity) diff --git a/libtaskmanager/tasksmodel.h b/libtaskmanager/tasksmodel.h --- a/libtaskmanager/tasksmodel.h +++ b/libtaskmanager/tasksmodel.h @@ -558,7 +558,7 @@ * @param url A launcher URL. * @returns @c true if a launcher was added. */ - Q_INVOKABLE bool requestAddLauncherToActivity(const QUrl &url); + Q_INVOKABLE bool requestAddLauncherToActivity(const QUrl &url, const QString &activity); /** * Request removing the launcher with the given URL from the current activity. @@ -571,7 +571,7 @@ * @param url A launcher URL. * @returns @c true if the launcher was removed. */ - Q_INVOKABLE bool requestRemoveLauncherFromActivity(const QUrl &url); + Q_INVOKABLE bool requestRemoveLauncherFromActivity(const QUrl &url, const QString &activity); /** * Return the list of activities the launcher belongs to. diff --git a/libtaskmanager/tasksmodel.cpp b/libtaskmanager/tasksmodel.cpp --- a/libtaskmanager/tasksmodel.cpp +++ b/libtaskmanager/tasksmodel.cpp @@ -1154,11 +1154,11 @@ return false; } -bool TasksModel::requestAddLauncherToActivity(const QUrl &url) +bool TasksModel::requestAddLauncherToActivity(const QUrl &url, const QString &activity) { d->initLauncherTasksModel(); - bool added = d->launcherTasksModel->requestAddLauncherToActivity(url); + bool added = d->launcherTasksModel->requestAddLauncherToActivity(url, activity); // If using manual and launch-in-place sorting with separate launchers, // we need to trigger a sort map update to move any window tasks to @@ -1171,10 +1171,10 @@ return added; } -bool TasksModel::requestRemoveLauncherFromActivity(const QUrl &url) +bool TasksModel::requestRemoveLauncherFromActivity(const QUrl &url, const QString &activity) { if (d->launcherTasksModel) { - bool removed = d->launcherTasksModel->requestRemoveLauncherFromActivity(url); + bool removed = d->launcherTasksModel->requestRemoveLauncherFromActivity(url, activity); // If using manual and launch-in-place sorting with separate launchers, // we need to trigger a sort map update to move any window tasks no