Changeset View
Changeset View
Standalone View
Standalone View
libtaskmanager/tasktools.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2016 Eike Hein <hein.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | | ||||
21 | #ifndef TASKTOOLS_H | ||||
22 | #define TASKTOOLS_H | ||||
23 | | ||||
24 | #include "taskmanager_export.h" | ||||
25 | | ||||
26 | #include <QIcon> | ||||
27 | #include <QModelIndex> | ||||
28 | #include <QUrl> | ||||
29 | | ||||
30 | namespace TaskManager | ||||
31 | { | ||||
32 | | ||||
33 | struct AppData | ||||
34 | { | ||||
35 | QString id; // Application id (*.desktop sans extension). | ||||
36 | QString name; // Application name. | ||||
37 | QString genericName; // Generic application name. | ||||
38 | QIcon icon; | ||||
39 | QUrl url; | ||||
40 | }; | ||||
41 | | ||||
42 | enum UrlComparisonMode { | ||||
43 | Strict = 0, | ||||
44 | IgnoreQueryItems | ||||
45 | }; | ||||
46 | | ||||
47 | /** | ||||
48 | * Fills in and returns an AppData struct based on the given URL. | ||||
49 | * | ||||
50 | * If the URL contains iconData in its query string, it is decoded and | ||||
51 | * set as AppData.icon, taking precedence over normal icon discovery. | ||||
52 | * | ||||
53 | * If the URL is using the preferred:// scheme, the URL it resolves to | ||||
54 | * is set as AppData.url. | ||||
55 | * | ||||
56 | * The supplied fallback icon is set as AppData.icon if no other icon | ||||
57 | * could be found. | ||||
58 | * | ||||
59 | * @see defaultApplication | ||||
60 | * @param url A URL to a .desktop file or executable, or a preferred:// URL. | ||||
61 | * @param fallbackIcon An icon to use when none could be read from the URL or | ||||
62 | * otherwise found. | ||||
63 | * @returns @c AppData filled in based on the given URL. | ||||
64 | */ | ||||
65 | TASKMANAGER_EXPORT AppData appDataFromUrl(const QUrl &url, const QIcon &fallbackIcon = QIcon()); | ||||
66 | | ||||
67 | /** | ||||
68 | * Returns an application id for an URL using the preferred:// scheme. | ||||
69 | * | ||||
70 | * Recognized values for the host component of the URL are: | ||||
71 | * - "browser" | ||||
72 | * - "mailer" | ||||
73 | * - "terminal" | ||||
74 | * - "windowmanager" | ||||
75 | * | ||||
76 | * If the host component matches none of the above, an attempt is made | ||||
77 | * to match to application links stored in kcm_componentchooser/. | ||||
78 | * | ||||
79 | * @param url A URL using the preferred:// scheme. | ||||
80 | * @returns an application id for the given URL. | ||||
81 | **/ | ||||
82 | TASKMANAGER_EXPORT QString defaultApplication(const QUrl &url); | ||||
83 | | ||||
84 | /** | ||||
85 | * Compares two launcher URLs either strictly or ignoring the query string. | ||||
86 | * | ||||
87 | * In launcher URLs, the query string is used to hold metadata such as an | ||||
88 | * icon. When comparing tasks by launcher URL, this metadata should usually | ||||
89 | * be ignored. This function serves this need. | ||||
90 | * | ||||
91 | * @see LauncherTasksModel | ||||
92 | * @param a The first launcher URL. | ||||
93 | * @param b The second launcher URL. | ||||
94 | * @param c The comparison mode. Either Strict or IgnoreQueryItems. | ||||
95 | * @returns @c true if the URLs match. | ||||
96 | **/ | ||||
97 | TASKMANAGER_EXPORT bool launcherUrlsMatch(const QUrl &a, const QUrl &b, UrlComparisonMode mode = Strict); | ||||
98 | | ||||
99 | TASKMANAGER_EXPORT bool appsMatch(const QModelIndex &a, const QModelIndex &b); | ||||
100 | } | ||||
101 | | ||||
102 | #endif |