[libtaskmanager] Add role to determine whether a new instance of a task can be launched

This moves a bit of logic that is currently in the task manager context menu down to the model.

This makes it easier to extend in the future
wilder-5.24
Nicolas Fella 4 years ago committed by Nate Graham
parent 456879f91d
commit d79b4734dc
  1. 1
      libtaskmanager/abstracttasksmodel.h
  2. 2
      libtaskmanager/launchertasksmodel.cpp
  3. 8
      libtaskmanager/tasktools.cpp
  4. 2
      libtaskmanager/tasktools.h
  5. 2
      libtaskmanager/waylandstartuptasksmodel.cpp
  6. 5
      libtaskmanager/waylandtasksmodel.cpp
  7. 2
      libtaskmanager/xstartuptasksmodel.cpp
  8. 5
      libtaskmanager/xwindowtasksmodel.cpp

@ -84,6 +84,7 @@ public:
May be empty. @since 5.19 */
IsHidden, /**< Task (i.e window) is hidden on screen. A minimzed
window is not necessarily hidden. */
CanLaunchNewInstance, /**< A new instance of the task can be launched. @since 5.24 */
};
Q_ENUM(AdditionalRoles)

@ -329,6 +329,8 @@ QVariant LauncherTasksModel::data(const QModelIndex &index, int role) const
return true;
} else if (role == Activities) {
return QStringList(d->activitiesForLauncher[url].values());
} else if (role == CanLaunchNewInstance) {
return false;
}
return QVariant();

@ -764,4 +764,12 @@ void runApp(const AppData &appData, const QList<QUrl> &urls)
}
}
bool canLauchNewInstance(const AppData &appData)
{
if (appData.url.isEmpty()) {
return false;
}
return true;
}
}

@ -172,4 +172,6 @@ TASKMANAGER_EXPORT QRect screenGeometry(const QPoint &pos);
* @param urls A list of URLs for the application to open.
*/
TASKMANAGER_EXPORT void runApp(const AppData &appData, const QList<QUrl> &urls = QList<QUrl>());
bool canLauchNewInstance(const AppData &appData);
}

@ -194,6 +194,8 @@ QVariant WaylandStartupTasksModel::data(const QModelIndex &index, int role) cons
return data.launcherUrl;
} else if (role == IsStartup) {
return true;
} else if (role == CanLaunchNewInstance) {
return false;
}
return QVariant();

@ -83,6 +83,7 @@ void WaylandTasksModel::Private::init()
AbstractTasksModel::GenericName,
AbstractTasksModel::LauncherUrl,
AbstractTasksModel::LauncherUrlWithoutIcon,
AbstractTasksModel::CanLaunchNewInstance,
AbstractTasksModel::SkipTaskbar});
};
@ -200,7 +201,7 @@ void WaylandTasksModel::Private::addWindow(KWayland::Client::PlasmaWindow *windo
appDataCache.remove(window);
// Refresh roles satisfied from the app data cache.
this->dataChanged(window, QVector<int>{AppId, AppName, GenericName, LauncherUrl, LauncherUrlWithoutIcon, SkipTaskbar});
this->dataChanged(window, QVector<int>{AppId, AppName, GenericName, LauncherUrl, LauncherUrlWithoutIcon, SkipTaskbar, CanLaunchNewInstance});
});
QObject::connect(window, &KWayland::Client::PlasmaWindow::activeChanged, q, [window, this] {
@ -464,6 +465,8 @@ QVariant WaylandTasksModel::data(const QModelIndex &index, int role) const
return window->applicationMenuObjectPath();
} else if (role == ApplicationMenuServiceName) {
return window->applicationMenuServiceName();
} else if (role == CanLaunchNewInstance) {
return canLauchNewInstance(d->appData(window));
}
return QVariant();

@ -249,6 +249,8 @@ QVariant XStartupTasksModel::data(const QModelIndex &index, int role) const
return QVariantList() << QVariant(data.desktop());
} else if (role == IsOnAllVirtualDesktops) {
return (data.desktop() == 0);
} else if (role == CanLaunchNewInstance) {
return false;
}
return QVariant();

@ -111,6 +111,7 @@ void XWindowTasksModel::Private::init()
AbstractTasksModel::GenericName,
AbstractTasksModel::LauncherUrl,
AbstractTasksModel::LauncherUrlWithoutIcon,
AbstractTasksModel::CanLaunchNewInstance,
AbstractTasksModel::SkipTaskbar});
};
@ -316,7 +317,7 @@ void XWindowTasksModel::Private::windowChanged(WId window, NET::Properties prope
if (properties & (NET::WMPid) || properties2 & (NET::WM2DesktopFileName | NET::WM2WindowClass)) {
wipeInfoCache = true;
wipeAppDataCache = true;
changedRoles << Qt::DecorationRole << AppId << AppName << GenericName << LauncherUrl << AppPid << SkipTaskbar;
changedRoles << Qt::DecorationRole << AppId << AppName << GenericName << LauncherUrl << AppPid << SkipTaskbar << CanLaunchNewInstance;
}
if (properties & (NET::WMName | NET::WMVisibleName)) {
@ -681,6 +682,8 @@ QVariant XWindowTasksModel::data(const QModelIndex &index, int role) const
return d->appMenuObjectPath(window);
} else if (role == ApplicationMenuServiceName) {
return d->appMenuServiceName(window);
} else if (role == CanLaunchNewInstance) {
return canLauchNewInstance(d->appData(window));
}
return QVariant();

Loading…
Cancel
Save