KNewStuff

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

KDE's Doxygen guidelines are available online.