File indexing completed on 2024-12-01 12:37:48
0001 /* 0002 SPDX-FileCopyrightText: 2015 Gregor Mi <codestruct@posteo.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #include "kmoretoolspresets.h" 0008 #include "kmoretoolspresets_p.h" 0009 #include "knewstuff_debug.h" 0010 #include <QHash> 0011 0012 #include "kmoretools.h" 0013 0014 #define _ QStringLiteral 0015 0016 class KmtServiceInfo 0017 { 0018 public: 0019 KmtServiceInfo(const QString &desktopEntryName, const QString &homepageUrl, int maxUrlArgCount, const QString &appstreamId) 0020 : desktopEntryName(desktopEntryName) 0021 , homepageUrl(homepageUrl) 0022 , maxUrlArgCount(maxUrlArgCount) 0023 , appstreamId(appstreamId) 0024 { 0025 } 0026 0027 public: 0028 QString desktopEntryName; 0029 QString homepageUrl; 0030 int maxUrlArgCount; 0031 QString appstreamId; 0032 }; 0033 0034 // 0035 // todo later: add a property "maturity" with values "stable" > "new" > "incubating" or similar 0036 // 0037 KMoreToolsService *KMoreToolsPresets::registerServiceByDesktopEntryName(KMoreTools *kmt, const QString &desktopEntryName) 0038 { 0039 static QHash<QString, KmtServiceInfo> dict; 0040 // clang-format off 0041 #define ADD_ENTRY(desktopEntryName, maxUrlArgCount, homepageUrl, appstreamUrl) dict.insert(desktopEntryName, KmtServiceInfo(desktopEntryName, homepageUrl, maxUrlArgCount, appstreamUrl)); 0042 0043 // 0044 // definitions begin (sorted alphabetically): 0045 // .------ If one gives more URL arguments as 0046 // | specified here the program will not work. 0047 // | Note, that there are some desktop files where _too few_ 0048 // | arguments also lead to errors. Watch the console 0049 // v output for messages from the program. 0050 // 0051 ADD_ENTRY(QStringLiteral("angrysearch"), 0, QStringLiteral("https://github.com/DoTheEvo/ANGRYsearch"), QString()); 0052 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 0053 ADD_ENTRY(QStringLiteral("catfish"), 1, QStringLiteral("http://www.twotoasts.de/index.php/catfish/"), QStringLiteral("catfish")); 0054 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 0055 ADD_ENTRY(QStringLiteral("disk"), 0, QStringLiteral("https://en.opensuse.org/YaST_Disk_Controller"), QString()); 0056 ADD_ENTRY(QStringLiteral("fontinst"), 0, QStringLiteral("https://docs.kde.org/?application=kcontrol/fontinst&branch=trunk5"), QString()); // good for previewing many fonts at once 0057 ADD_ENTRY(QStringLiteral("fontmatrix"), 0, QStringLiteral("https://github.com/fontmatrix/fontmatrix"), QString()); 0058 ADD_ENTRY(QStringLiteral("fsearch"), 0, QStringLiteral("https://github.com/cboxdoerfer/fsearch"), QString()); 0059 ADD_ENTRY(QStringLiteral("giggle"), 1, QStringLiteral("https://wiki.gnome.org/Apps/giggle/"), QStringLiteral("giggle.desktop")); // good for searching in history 0060 ADD_ENTRY(QStringLiteral("git-cola-folder-handler"), 1, QStringLiteral("https://git-cola.github.io"), QStringLiteral("git-cola.desktop")); 0061 ADD_ENTRY(QStringLiteral("git-cola-view-history.kmt-edition"), 1, QStringLiteral("https://git-cola.github.io"), QStringLiteral("git-cola.desktop")); 0062 ADD_ENTRY(QStringLiteral("gitk.kmt-edition"), 1, QStringLiteral("https://git-scm.com/docs/gitk"), QString()); 0063 ADD_ENTRY(QStringLiteral("qgit.kmt-edition"), 1, QStringLiteral("https://github.com/tibirna/qgit"), QString()); 0064 ADD_ENTRY(QStringLiteral("gitg"), 1, QStringLiteral("https://wiki.gnome.org/action/show/Apps/Gitg?action=show&redirect=Gitg"), QStringLiteral("gitg.desktop")); 0065 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 0066 ADD_ENTRY(QStringLiteral("gucharmap"), 0, QStringLiteral("https://wiki.gnome.org/action/show/Apps/Gucharmap"), QStringLiteral("gucharmap.desktop")); 0067 ADD_ENTRY(QStringLiteral("gparted"), 0, QStringLiteral("https://gparted.org"), QStringLiteral("gparted.desktop")); 0068 ADD_ENTRY(QStringLiteral("htop"), 0, QStringLiteral("https://hisham.hm/htop/"), QStringLiteral("htop.desktop")); 0069 ADD_ENTRY(QStringLiteral("hotshots"), 1, QStringLiteral("https://sourceforge.net/projects/hotshots/"), QString()); 0070 ADD_ENTRY(QStringLiteral("kaption"), 0, QStringLiteral("https://www.linux-apps.com/content/show.php/?content=139302"), QString()); 0071 ADD_ENTRY(QStringLiteral("kding"), 0, QString(), QString()); // Offline dict; unmaintained? 0072 ADD_ENTRY(QStringLiteral("org.kde.kmousetool"), 0, QStringLiteral("https://kde.org/applications/utilities/org.kde.kmousetool/"), QStringLiteral("org.kde.kmousetool")); 0073 ADD_ENTRY(QStringLiteral("org.gnome.clocks"), 0, QStringLiteral("https://wiki.gnome.org/Apps/Clocks"), QStringLiteral("org.gnome.clocks.desktop")); 0074 ADD_ENTRY(QStringLiteral("org.kde.filelight"), 1, QStringLiteral("https://kde.org/applications/utilities/org.kde.filelight/"), QStringLiteral("org.kde.filelight.desktop")); 0075 ADD_ENTRY(QStringLiteral("org.kde.kcharselect"), 0, QStringLiteral("https://kde.org/applications/utilities/org.kde.kcharselect/"), QStringLiteral("org.kde.kcharselect")); 0076 ADD_ENTRY(QStringLiteral("org.kde.kdf"), 0, QStringLiteral("https://kde.org/applications/system/org.kde.kdf/"), QStringLiteral("org.kde.kdf")); 0077 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 0078 ADD_ENTRY(QStringLiteral("org.kde.partitionmanager"), 0, QStringLiteral("https://kde.org/applications/system/org.kde.partitionmanager"), QStringLiteral("org.kde.partitionmanager.desktop")); 0079 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")); 0080 ADD_ENTRY(QStringLiteral("org.kde.ksysguard"), 0, QStringLiteral("https://userbase.kde.org/KSysGuard"), QStringLiteral("org.kde.ksysguard")); 0081 ADD_ENTRY(QStringLiteral("org.kde.ksystemlog"), 0, QStringLiteral("https://kde.org/applications/system/org.kde.ksystemlog/"), QStringLiteral("org.kde.ksystemlog")); 0082 ADD_ENTRY(QStringLiteral("org.kde.ktimer"), 0, QStringLiteral("https://kde.org/applications/utilities/org.kde.ktimer/"), QStringLiteral("org.kde.ktimer")); 0083 ADD_ENTRY(QStringLiteral("org.kde.spectacle"), 0, QStringLiteral("https://kde.org/applications/utilities/org.kde.spectacle"), QStringLiteral("org.kde.spectacle.desktop")); 0084 ADD_ENTRY(QStringLiteral("simplescreenrecorder"), 0, QStringLiteral("https://www.maartenbaert.be/simplescreenrecorder/"), QStringLiteral("simplescreenrecorder.desktop")); 0085 ADD_ENTRY(QStringLiteral("com.obsproject.Studio"), 0, QStringLiteral("https://obsproject.com/"), QStringLiteral("com.obsproject.Studio")); 0086 ADD_ENTRY(QStringLiteral("vokoscreenNG"), 0, QStringLiteral("https://github.com/vkohaupt/vokoscreenNG"), QStringLiteral("com.github.vkohaupt.vokoscreenNG")); // feature-rich screen recorder 0087 ADD_ENTRY(QStringLiteral("xfce4-taskmanager"), 0, QStringLiteral("https://goodies.xfce.org/projects/applications/xfce4-taskmanager"), QStringLiteral("xfce4-taskmanager.desktop")); 0088 // 0089 // ...definitions end 0090 // 0091 0092 #undef ADD_ENTRY 0093 // clang-format on 0094 0095 auto iter = dict.constFind(desktopEntryName); 0096 if (iter != dict.constEnd()) { 0097 auto kmtServiceInfo = *iter; 0098 const QString subdir = QStringLiteral("presets-kmoretools"); 0099 auto serviceLocatingMode = desktopEntryName.endsWith(QLatin1String(".kmt-edition")) ? KMoreTools::ServiceLocatingMode_ByProvidedExecLine 0100 : KMoreTools::ServiceLocatingMode_Default; 0101 auto service = kmt->registerServiceByDesktopEntryName(desktopEntryName, subdir, serviceLocatingMode); 0102 if (service) { // We might get nullptr in case of missing or broken .desktop files 0103 service->setHomepageUrl(QUrl(kmtServiceInfo.homepageUrl)); 0104 service->setMaxUrlArgCount(kmtServiceInfo.maxUrlArgCount); 0105 service->setAppstreamId(kmtServiceInfo.appstreamId); 0106 } 0107 return service; 0108 } else { 0109 qCDebug(KNEWSTUFF) << "KMoreToolsPresets::registerServiceByDesktopEntryName: " << desktopEntryName << "was not found. Return nullptr."; 0110 return nullptr; 0111 } 0112 } 0113 0114 QList<KMoreToolsService *> KMoreToolsPresets::registerServicesByGroupingNames(KMoreTools *kmt, const QStringList &groupingNames) 0115 { 0116 QString firstMoreSectionDesktopEntryName; 0117 return KMoreToolsPresetsPrivate::registerServicesByGroupingNames(&firstMoreSectionDesktopEntryName, kmt, groupingNames); 0118 } 0119 0120 QList<KMoreToolsService *> 0121 KMoreToolsPresetsPrivate::registerServicesByGroupingNames(QString *firstMoreSectionDesktopEntryName, KMoreTools *kmt, const QStringList &groupingNames) 0122 { 0123 static QHash<QString, QList<QString>> dict; 0124 0125 // The corresponding desktop files are located here: 0126 // 'knewstuff/data/kmoretools-desktopfiles/' 0127 0128 // Use KMoreToolsTest2::testDialogForGroupingNames to see if the settings 0129 // here are correct. 0130 0131 // NOTE that the desktopentry names must be registered in 0132 // registerServiceByDesktopEntryName above. 0133 0134 // For special handlings about naming in the menu etc. see kmoretoolsmenufactory.cpp/addItemsForGroupingNameWithSpecialHandling 0135 0136 // 0137 // grouping definitions begin (sorted alphabetically): 0138 // 0139 // clang-format off 0140 dict.insert(_("disk-usage"), { _("org.kde.kdf"), _("org.kde.filelight") }); 0141 dict.insert(_("disk-partitions"), { _("gparted"), _("org.kde.partitionmanager"), _("disk") }); 0142 dict.insert(_("files-find"), { _("org.kde.kfind"), _("fsearch"), _("more:"), _("gnome-search-tool"), _("catfish"), _("angrysearch") }); 0143 dict.insert(_("font-tools"), { _("fontinst"), _("gucharmap"), _("more:"), _("org.kde.kcharselect"), _("fontmatrix") }); 0144 dict.insert(_("git-clients-for-folder"), { _("git-cola-folder-handler"), _("gitk.kmt-edition"), 0145 _("giggle"), _("qgit.kmt-edition"), _("gitg") }); 0146 dict.insert(_("git-clients-and-actions"), { _("git-cola-folder-handler"), _("git-cola-view-history.kmt-edition"), 0147 _("giggle"), _("gitk.kmt-edition"), _("qgit.kmt-edition"), _("gitg") }); 0148 dict.insert(_("icon-browser"), { _("org.kde.plasma.cuttlefish.kmt-edition") }); 0149 dict.insert(_("language-dictionary"), { _("ding"), _("kding") }); 0150 dict.insert(_("mouse-tools"), { _("org.kde.kmousetool") }); // todo: add program "xbanish" to remove mouse cursor while typing 0151 dict.insert(_("screenrecorder"), { _("com.uploadedlobster.peek"), _("simplescreenrecorder"), _("vokoscreenNG"), _("com.obsproject.Studio") }); 0152 dict.insert(_("screenshot-take"), { _("org.kde.spectacle"), _("shutter"), _("kaption"), _("hotshots") }); 0153 dict.insert(_("system-monitor-processes"), { _("org.kde.ksysguard"), _("more:"), _("htop"), _("xfce4-taskmanager") }); 0154 dict.insert(_("system-monitor-logs"), { _("org.kde.ksystemlog") }); 0155 dict.insert(_("time-countdown"), { _("org.gnome.clocks"), _("org.kde.ktimer") }); 0156 // 0157 // ...grouping definitions end 0158 // 0159 // clang-format on 0160 0161 QList<KMoreToolsService *> resultList; 0162 QSet<QString> alreadyUsedDesktopEntryNames; // including the "more:" keyword 0163 bool nextIsMore = false; 0164 0165 for (const QString &groupingName : groupingNames) { 0166 auto iter = dict.constFind(groupingName); 0167 if (iter != dict.constEnd()) { 0168 for (const QString &desktopEntryName : std::as_const(*iter)) { 0169 if (!alreadyUsedDesktopEntryNames.contains(desktopEntryName)) { 0170 if (desktopEntryName == _("more:")) { 0171 nextIsMore = true; 0172 } else { 0173 if (nextIsMore) { // this will be only set once 0174 *firstMoreSectionDesktopEntryName = desktopEntryName; 0175 nextIsMore = false; 0176 } 0177 KMoreToolsService *kmtService = KMoreToolsPresets::registerServiceByDesktopEntryName(kmt, desktopEntryName); 0178 if (kmtService) { // Do not add null pointers caused by missing or broken .desktop files 0179 resultList << kmtService; 0180 } 0181 } 0182 } else { 0183 alreadyUsedDesktopEntryNames.insert(desktopEntryName); 0184 } 0185 } 0186 } else { 0187 qCWarning(KNEWSTUFF) << "KMoreToolsPresets::registerServicesByGroupingName: groupingName not found: " << groupingName; 0188 } 0189 } 0190 0191 if (resultList.isEmpty()) { 0192 qCWarning(KNEWSTUFF) << "KMoreToolsPresets::registerServicesByGroupingName: " << groupingNames 0193 << ". Nothing found in this groupings. HINT: check for invalid grouping names."; 0194 } 0195 0196 return resultList; 0197 }