KMoreTools

kmoretoolspresets.cpp
1/*
2 SPDX-FileCopyrightText: 2015 Gregor Mi <codestruct@posteo.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include "kmoretoolspresets.h"
8#include "kmoretools_debug.h"
9#include "kmoretoolspresets_p.h"
10#include <QFile>
11#include <QHash>
12
13#include "kmoretools.h"
14
15#define _ QStringLiteral
16
17class KmtServiceInfo
18{
19public:
20 KmtServiceInfo(const QString &desktopEntryName, const QString &homepageUrl, int maxUrlArgCount, const QString &appstreamId)
21 : desktopEntryName(desktopEntryName)
22 , homepageUrl(homepageUrl)
23 , maxUrlArgCount(maxUrlArgCount)
24 , appstreamId(appstreamId)
25 {
26 }
27
28public:
29 QString desktopEntryName;
30 QString homepageUrl;
31 int maxUrlArgCount;
32 QString appstreamId;
33};
34
35namespace KMoreToolsNamespace
36{
37class OSDetection
38{
39public:
40 static bool is_LinuxOSFamily_Debian()
41 {
42 return QFile::exists(QLatin1String("/etc/debian_version"));
43 }
44};
45}
46
47//
48// todo later: add a property "maturity" with values "stable" > "new" > "incubating" or similar
49//
51{
53 // clang-format off
54#define ADD_ENTRY(desktopEntryName, maxUrlArgCount, homepageUrl, appstreamUrl) dict.insert(desktopEntryName, KmtServiceInfo(desktopEntryName, homepageUrl, maxUrlArgCount, appstreamUrl));
55
56 //
57 // definitions begin (sorted alphabetically):
58 // .------ If one gives more URL arguments as
59 // | specified here the program will not work.
60 // | Note, that there are some desktop files where _too few_
61 // | arguments also lead to errors. Watch the console
62 // v output for messages from the program.
63 //
64 ADD_ENTRY(QStringLiteral("angrysearch"), 0, QStringLiteral("https://github.com/DoTheEvo/ANGRYsearch"), QString());
65 ADD_ENTRY(QStringLiteral("com.uploadedlobster.peek"), 0, QStringLiteral("https://github.com/phw/peek"), QStringLiteral("com.uploadedlobster.peek.desktop")); // easy to use screen recorder, creates gif
66 ADD_ENTRY(QStringLiteral("catfish"), 1, QStringLiteral("http://www.twotoasts.de/index.php/catfish/"), QStringLiteral("catfish"));
67 ADD_ENTRY(QStringLiteral("ding"), 0, QStringLiteral("https://www-user.tu-chemnitz.de/~fri/ding/"), QString()); // Offline dict, Online: https://dict.tu-chemnitz.de/dings.cgi
68 ADD_ENTRY(QStringLiteral("disk"), 0, QStringLiteral("https://en.opensuse.org/YaST_Disk_Controller"), QString());
69 ADD_ENTRY(QStringLiteral("fontinst"), 0, QStringLiteral("https://docs.kde.org/?application=kcontrol/fontinst"), QString()); // good for previewing many fonts at once
70 ADD_ENTRY(QStringLiteral("fontmatrix"), 0, QStringLiteral("https://github.com/fontmatrix/fontmatrix"), QString());
71 ADD_ENTRY(QStringLiteral("fsearch"), 0, QStringLiteral("https://github.com/cboxdoerfer/fsearch"), QString());
72 ADD_ENTRY(QStringLiteral("giggle"), 1, QStringLiteral("https://wiki.gnome.org/Apps/giggle/"), QStringLiteral("giggle.desktop")); // good for searching in history
73 ADD_ENTRY(QStringLiteral("git-cola-folder-handler"), 1, QStringLiteral("https://git-cola.github.io"), QStringLiteral("git-cola.desktop"));
74 ADD_ENTRY(QStringLiteral("git-cola-view-history.kmt-edition"), 1, QStringLiteral("https://git-cola.github.io"), QStringLiteral("git-cola.desktop"));
75 ADD_ENTRY(QStringLiteral("gitk.kmt-edition"), 1, QStringLiteral("https://git-scm.com/docs/gitk"), QString());
76 ADD_ENTRY(QStringLiteral("qgit.kmt-edition"), 1, QStringLiteral("https://github.com/tibirna/qgit"), QString());
77 ADD_ENTRY(QStringLiteral("gitg"), 1, QStringLiteral("https://wiki.gnome.org/action/show/Apps/Gitg?action=show&redirect=Gitg"), QStringLiteral("gitg.desktop"));
78 ADD_ENTRY(QStringLiteral("gnome-search-tool"), 0, QStringLiteral("https://help.gnome.org/users/gnome-search-tool/"), QStringLiteral("gnome-search-tool.desktop")); // has good filtering options
79 ADD_ENTRY(QStringLiteral("gucharmap"), 0, QStringLiteral("https://wiki.gnome.org/action/show/Apps/Gucharmap"), QStringLiteral("gucharmap.desktop"));
80 ADD_ENTRY(QStringLiteral("gparted"), 0, QStringLiteral("https://gparted.org"), QStringLiteral("gparted.desktop"));
81 ADD_ENTRY(QStringLiteral("htop"), 0, QStringLiteral("https://hisham.hm/htop/"), QStringLiteral("htop.desktop"));
82 ADD_ENTRY(QStringLiteral("hotshots"), 1, QStringLiteral("https://sourceforge.net/projects/hotshots/"), QString());
83 ADD_ENTRY(QStringLiteral("kaption"), 0, QStringLiteral("https://www.linux-apps.com/content/show.php/?content=139302"), QString());
84 ADD_ENTRY(QStringLiteral("kding"), 0, QString(), QString()); // Offline dict; unmaintained?
85 ADD_ENTRY(QStringLiteral("org.kde.kmousetool"), 0, QStringLiteral("https://apps.kde.org/kmousetool"), QStringLiteral("org.kde.kmousetool"));
86 ADD_ENTRY(QStringLiteral("org.gnome.clocks"), 0, QStringLiteral("https://wiki.gnome.org/Apps/Clocks"), QStringLiteral("org.gnome.clocks.desktop"));
87 ADD_ENTRY(QStringLiteral("org.kde.filelight"), 1, QStringLiteral("https://apps.kde.org/filelight"), QStringLiteral("org.kde.filelight.desktop"));
88 ADD_ENTRY(QStringLiteral("org.kde.kcharselect"), 0, QStringLiteral("https://apps.kde.org/kcharselect"), QStringLiteral("org.kde.kcharselect"));
89 ADD_ENTRY(QStringLiteral("org.kde.kdf"), 0, QStringLiteral("https://apps.kde.org/kdf"), QStringLiteral("org.kde.kdf"));
90 ADD_ENTRY(QStringLiteral("org.kde.kfind"), 1, QStringLiteral("https://apps.kde.org/kfind"), QStringLiteral("org.kde.kfind.desktop")); // has good filtering options
91 ADD_ENTRY(QStringLiteral("org.kde.partitionmanager"), 0, QStringLiteral("https://apps.kde.org/partitionmanager"), QStringLiteral("org.kde.partitionmanager.desktop"));
92 ADD_ENTRY(QStringLiteral("org.kde.plasma.cuttlefish.kmt-edition"), 0, QStringLiteral("https://vizzzion.org/blog/2015/02/say-hi-to-cuttlefish/"), QStringLiteral("org.kde.plasma.cuttlefish"));
93 ADD_ENTRY(QStringLiteral("org.kde.ksysguard"), 0, QStringLiteral("https://apps.kde.org/ksysguard"), QStringLiteral("org.kde.ksysguard"));
94 ADD_ENTRY(QStringLiteral("org.kde.ksystemlog"), 0, QStringLiteral("https://apps.kde.org/ksystemlog"), QStringLiteral("org.kde.ksystemlog"));
95 ADD_ENTRY(QStringLiteral("org.kde.ktimer"), 0, QStringLiteral("https://apps.kde.org/ktimer"), QStringLiteral("org.kde.ktimer"));
96 ADD_ENTRY(QStringLiteral("org.kde.spectacle"), 0, QStringLiteral("https://apps.kde.org/spectacle"), QStringLiteral("org.kde.spectacle.desktop"));
97 ADD_ENTRY(QStringLiteral("simplescreenrecorder"), 0, QStringLiteral("https://www.maartenbaert.be/simplescreenrecorder"), QStringLiteral("simplescreenrecorder.desktop"));
98 ADD_ENTRY(QStringLiteral("com.obsproject.Studio"), 0, QStringLiteral("https://obsproject.com"), QStringLiteral("com.obsproject.Studio"));
99 ADD_ENTRY(QStringLiteral("vokoscreenNG"), 0, QStringLiteral("https://github.com/vkohaupt/vokoscreenNG"), KMoreToolsNamespace::OSDetection::is_LinuxOSFamily_Debian() ? QLatin1String("de.volkoh.linuxecke.vokoscreen_ng") : QStringLiteral("com.github.vkohaupt.vokoscreenNG")); // feature-rich screen recorder
100 ADD_ENTRY(QStringLiteral("xfce4-taskmanager"), 0, QStringLiteral("https://goodies.xfce.org/projects/applications/xfce4-taskmanager"), QStringLiteral("xfce4-taskmanager.desktop"));
101 //
102 // ...definitions end
103 //
104
105#undef ADD_ENTRY
106 // clang-format on
107
108 auto iter = dict.constFind(desktopEntryName);
109 if (iter != dict.constEnd()) {
110 auto kmtServiceInfo = *iter;
111 const QString subdir = QStringLiteral("presets-kmoretools");
112 auto serviceLocatingMode = desktopEntryName.endsWith(QLatin1String(".kmt-edition")) ? KMoreTools::ServiceLocatingMode_ByProvidedExecLine
114 auto service = kmt->registerServiceByDesktopEntryName(desktopEntryName, subdir, serviceLocatingMode);
115 if (service) { // We might get nullptr in case of missing or broken .desktop files
116 service->setHomepageUrl(QUrl(kmtServiceInfo.homepageUrl));
117 service->setMaxUrlArgCount(kmtServiceInfo.maxUrlArgCount);
118 service->setAppstreamId(kmtServiceInfo.appstreamId);
119 }
120 return service;
121 } else {
122 qCDebug(KMORETOOLS) << "KMoreToolsPresets::registerServiceByDesktopEntryName: " << desktopEntryName << "was not found. Return nullptr.";
123 return nullptr;
124 }
125}
126
128{
129 QString firstMoreSectionDesktopEntryName;
130 return KMoreToolsPresetsPrivate::registerServicesByGroupingNames(&firstMoreSectionDesktopEntryName, kmt, groupingNames);
131}
132
134KMoreToolsPresetsPrivate::registerServicesByGroupingNames(QString *firstMoreSectionDesktopEntryName, KMoreTools *kmt, const QStringList &groupingNames)
135{
137
138 // The corresponding desktop files are located here:
139 // 'knewstuff/data/kmoretools-desktopfiles/'
140
141 // Use KMoreToolsTest2::testDialogForGroupingNames to see if the settings
142 // here are correct.
143
144 // NOTE that the desktopentry names must be registered in
145 // registerServiceByDesktopEntryName above.
146
147 // For special handlings about naming in the menu etc. see kmoretoolsmenufactory.cpp/addItemsForGroupingNameWithSpecialHandling
148
149 //
150 // grouping definitions begin (sorted alphabetically):
151 //
152 // clang-format off
153 dict.insert(_("disk-usage"), { _("org.kde.kdf"), _("org.kde.filelight") });
154 dict.insert(_("disk-partitions"), { _("gparted"), _("org.kde.partitionmanager"), _("disk") });
155 dict.insert(_("files-find"), { _("org.kde.kfind"), _("fsearch"), _("more:"), _("gnome-search-tool"), _("catfish"), _("angrysearch") });
156 dict.insert(_("font-tools"), { _("fontinst"), _("gucharmap"), _("more:"), _("org.kde.kcharselect"), _("fontmatrix") });
157 dict.insert(_("git-clients-for-folder"), { _("git-cola-folder-handler"), _("gitk.kmt-edition"),
158 _("giggle"), _("qgit.kmt-edition"), _("gitg") });
159 dict.insert(_("git-clients-and-actions"), { _("git-cola-folder-handler"), _("git-cola-view-history.kmt-edition"),
160 _("giggle"), _("gitk.kmt-edition"), _("qgit.kmt-edition"), _("gitg") });
161 dict.insert(_("icon-browser"), { _("org.kde.plasma.cuttlefish.kmt-edition") });
162 dict.insert(_("language-dictionary"), { _("ding"), _("kding") });
163 dict.insert(_("mouse-tools"), { _("org.kde.kmousetool") }); // todo: add program "xbanish" to remove mouse cursor while typing
164 dict.insert(_("screenrecorder"), { _("com.uploadedlobster.peek"), _("simplescreenrecorder"), _("vokoscreenNG"), _("com.obsproject.Studio") });
165 dict.insert(_("screenshot-take"), { _("org.kde.spectacle"), _("shutter"), _("kaption"), _("hotshots") });
166 dict.insert(_("system-monitor-processes"), { _("org.kde.ksysguard"), _("more:"), _("htop"), _("xfce4-taskmanager") });
167 dict.insert(_("system-monitor-logs"), { _("org.kde.ksystemlog") });
168 dict.insert(_("time-countdown"), { _("org.gnome.clocks"), _("org.kde.ktimer") });
169 //
170 // ...grouping definitions end
171 //
172 // clang-format on
173
175 QSet<QString> alreadyUsedDesktopEntryNames; // including the "more:" keyword
176 bool nextIsMore = false;
177
178 for (const QString &groupingName : groupingNames) {
179 auto iter = dict.constFind(groupingName);
180 if (iter != dict.constEnd()) {
181 for (const QString &desktopEntryName : std::as_const(*iter)) {
182 if (!alreadyUsedDesktopEntryNames.contains(desktopEntryName)) {
183 if (desktopEntryName == _("more:")) {
184 nextIsMore = true;
185 } else {
186 if (nextIsMore) { // this will be only set once
187 *firstMoreSectionDesktopEntryName = desktopEntryName;
188 nextIsMore = false;
189 }
191 if (kmtService) { // Do not add null pointers caused by missing or broken .desktop files
192 resultList << kmtService;
193 }
194 }
195 } else {
196 alreadyUsedDesktopEntryNames.insert(desktopEntryName);
197 }
198 }
199 } else {
200 qCWarning(KMORETOOLS) << "KMoreToolsPresets::registerServicesByGroupingName: groupingName not found: " << groupingName;
201 }
202 }
203
204 if (resultList.isEmpty()) {
205 qCWarning(KMORETOOLS) << "KMoreToolsPresets::registerServicesByGroupingName: " << groupingNames
206 << ". Nothing found in this groupings. HINT: check for invalid grouping names.";
207 }
208
209 return resultList;
210}
static KMoreToolsService * registerServiceByDesktopEntryName(KMoreTools *kmt, const QString &desktopEntryName)
Registers a service who's kmt-desktopfile is provided by the KMoreTools library itself (see directory...
static QList< KMoreToolsService * > registerServicesByGroupingNames(KMoreTools *kmt, const QStringList &groupingNames)
A service described in a .desktop file (kmt-desktopfile) which will be called "registered service".
Definition kmoretools.h:357
Helps to create user-configurable menus with tools which are potentially not yet installed.
Definition kmoretools.h:163
KMoreToolsService * registerServiceByDesktopEntryName(const QString &desktopEntryName, const QString &kmtDesktopfileSubdir=QString(), ServiceLocatingMode serviceLocatingMode=ServiceLocatingMode_Default)
Registers a service with KMoreTools.
@ ServiceLocatingMode_Default
by existence of desktop file (discoverable by KService)
Definition kmoretools.h:175
@ ServiceLocatingMode_ByProvidedExecLine
by existence of executable defined in the TryExec or Exec line of the provided kmt-desktopfile
Definition kmoretools.h:181
bool exists() const const
const_iterator constEnd() const const
const_iterator constFind(const Key &key) const const
iterator insert(const Key &key, const T &value)
bool isEmpty() const const
bool contains(const QSet< T > &other) const const
iterator insert(const T &value)
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.