Plasma-workspace

tasktools.h
1/*
2 SPDX-FileCopyrightText: 2016 Eike Hein <hein@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#pragma once
8
9#include "taskmanager_export.h"
10
11#include <QIcon>
12#include <QModelIndex>
13#include <QUrl>
14
15#include <KService>
16#include <KSharedConfig>
17
18namespace TaskManager
19{
20struct AppData {
21 QString id; // Application id (*.desktop sans extension).
22 QString name; // Application name.
23 QString genericName; // Generic application name.
24 QIcon icon;
25 QUrl url;
26 bool skipTaskbar = false;
27};
28
29enum UrlComparisonMode {
30 Strict = 0,
31 IgnoreQueryItems,
32};
33
34/**
35 * Fills in and returns an AppData struct based on the given URL.
36 *
37 * If the URL contains iconData in its query string, it is decoded and
38 * set as AppData.icon, taking precedence over normal icon discovery.
39 *
40 * If the URL is using the preferred:// scheme, the URL it resolves to
41 * is set as AppData.url.
42 *
43 * The supplied fallback icon is set as AppData.icon if no other icon
44 * could be found.
45 *
46 * @see defaultApplication
47 * @param url A URL to a .desktop file or executable, or a preferred:// URL.
48 * @param fallbackIcon An icon to use when none could be read from the URL or
49 * otherwise found.
50 * @returns @c AppData filled in based on the given URL.
51 */
52TASKMANAGER_EXPORT AppData appDataFromUrl(const QUrl &url, const QIcon &fallbackIcon = QIcon());
53
54/**
55 * Takes several bits of window metadata as input and tries to find
56 * the .desktop file for the application owning this window, or,
57 * failing that, the path to its executable.
58 *
59 * The source for the metadata is generally the window's appId on
60 * Wayland, or the window class part of the WM_CLASS window property
61 * on X Windows.
62 *
63 * TODO: The supplied config object can contain various mapping and
64 * mangling rules that affect the behavior of this function, allowing
65 * to map bits of metadata to different values and other things. This
66 * config file format still needs to be documented fully; in the
67 * meantime the bundled default rules in taskmanagerrulesrc (the
68 * config file opened by various models in this library) can be used
69 * for reference.
70 *
71 * @param appId A string uniquely identifying the application owning
72 * the window, ideally matching a .desktop file name.
73 * @param pid The process id for the process owning the window.
74 * @param config A KConfig object parameterizing the matching
75 * behavior.
76 * @param xWindowsWMClassName The instance name part of X Windows'
77 * WM_CLASS window property.
78 * @returns A .desktop file or executable path for the application
79 * owning the window.
80 */
81TASKMANAGER_EXPORT QUrl windowUrlFromMetadata(const QString &appId,
82 quint32 pid = 0,
83 const KSharedConfig::Ptr &config = KSharedConfig::Ptr(),
84 const QString &xWindowsWMClassName = QString());
85
86/**
87 * Returns a list of (usually application) KService instances for the
88 * given process id, by examining the process and querying the service
89 * database for process metadata.
90 *
91 * @param pid A process id.
92 * @param rulesConfig A KConfig object parameterizing the matching
93 * behavior.
94 * @returns A list of KService instances.
95 */
96TASKMANAGER_EXPORT KService::List servicesFromPid(quint32 pid, const KSharedConfig::Ptr &rulesConfig = KSharedConfig::Ptr());
97
98/**
99 * Returns a list of (usually application) KService instances for the
100 * given process command line and process name, by mangling the command
101 * line in various ways and checking the data against the Exec keys in
102 * the service database. Mangling is done e.g. to check for executable
103 * names with and without paths leading to them and to ignore arguments.
104 * if needed.
105 *
106 * The [Settings]TryIgnoreRuntimes key in the supplied config object can
107 * hold a comma-separated list of runtime executables that this code will
108 * try to ignore in the process command line. This is useful in cases where
109 * the command line has the contents of a .desktop Exec key prefixed with
110 * a runtime executable. The code tries to strip the path to the runtime
111 * executable if needed.
112 *
113 * @param cmdLine A process command line.
114 * @param processName The process name.
115 * @param rulesConfig A KConfig object parameterizing the matching
116 * behavior.
117 * @returns A list of KService instances.
118 */
119TASKMANAGER_EXPORT KService::List
120servicesFromCmdLine(const QString &cmdLine, const QString &processName, const KSharedConfig::Ptr &rulesConfig = KSharedConfig::Ptr());
121
122/**
123 * Returns an application id for an URL using the preferred:// scheme.
124 *
125 * Recognized values for the host component of the URL are:
126 * - "browser"
127 * - "mailer"
128 * - "terminal"
129 * - "filemanager"
130 *
131 * @param url A URL using the preferred:// scheme.
132 * @returns an application id for the given URL.
133 **/
134TASKMANAGER_EXPORT QString defaultApplication(const QUrl &url);
135
136/**
137 * Convenience function to compare two launcher URLs either strictly
138 * or ignoring their query strings.
139 *
140 * @see LauncherTasksModel
141 * @param a The first launcher URL.
142 * @param b The second launcher URL.
143 * @param mode The comparison mode. Either Strict or IgnoreQueryItems.
144 * @returns @c true if the URLs match.
145 **/
146TASKMANAGER_EXPORT bool launcherUrlsMatch(const QUrl &a, const QUrl &b, UrlComparisonMode mode = Strict);
147
148/**
149 * Determines whether tasks model entries belong to the same app.
150 *
151 * @param a The first model index.
152 * @param b The second model index.
153 * @returns @c true if the model entries belong to the same app.
154 **/
155TASKMANAGER_EXPORT bool appsMatch(const QModelIndex &a, const QModelIndex &b);
156
157/**
158 * Given global coordinates, returns the geometry of the screen they are
159 * on, or the geometry of the screen they are closest to.
160 *
161 * @param pos Coordinates in global space.
162 * @return The geometry of the screen containing pos or closest to pos.
163 */
164TASKMANAGER_EXPORT QRect screenGeometry(const QPoint &pos);
165
166/**
167 * Attempts to run the application described by the AppData struct that
168 * is passed in, optionally also handing the application a list of URLs
169 * to open.
170 *
171 * @param appData An application data struct.
172 * @param urls A list of URLs for the application to open.
173 */
174TASKMANAGER_EXPORT void runApp(const AppData &appData, const QList<QUrl> &urls = QList<QUrl>());
175
176bool canLauchNewInstance(const AppData &appData);
177}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:42 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.