KNewStuff

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

KDE's Doxygen guidelines are available online.