KNewStuff

kmoretools.h
1 /*
2  SPDX-FileCopyrightText: 2015 Gregor Mi <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.1-or-later
5 */
6 
7 #ifndef KMORETOOLS_H
8 #define KMORETOOLS_H
9 
10 #include <QString>
11 #include <QUrl>
12 #include <QMenu>
13 
14 #include <KService>
15 
16 #include "knewstuff_export.h"
17 
18 class KMoreToolsService;
20 class KMoreToolsPrivate;
21 
161 class KNEWSTUFF_EXPORT KMoreTools
162 {
163  friend class KMoreToolsService;
164  friend class KMoreToolsServicePrivate;
165 
166 public:
171  {
176 
181  ServiceLocatingMode_ByProvidedExecLine
182  };
183 
188  {
193 
197  MenuSection_More
198  };
199 
200 // /* *
201 // * todo/later: introduce when needed
202 // */
203 // enum NotInstalledSectionOption
204 // {
205 // /* *
206 // * default
207 // */
208 // NotInstalledSection_Show,
209 //
210 // /* *
211 // * Even if there are non-installed apps the Not-Installed section will
212 // * not be shown
213 // */
214 // NotInstalledSection_Hide
215 // };
216 
222  {
228 
241  ConfigureDialogAccessible_Defensive
242  };
243 
244 public:
280  explicit KMoreTools(const QString& uniqueId);
281 
282  ~KMoreTools();
283 
284  KMoreTools(const KMoreTools &) = delete;
285  KMoreTools& operator=(const KMoreTools &) = delete;
286 
322  KMoreToolsService* registerServiceByDesktopEntryName(
323  const QString& desktopEntryName,
324  const QString& kmtDesktopfileSubdir = QString(),
325  ServiceLocatingMode serviceLocatingMode = ServiceLocatingMode_Default);
326 
341  KMoreToolsMenuBuilder* menuBuilder(const QString& userConfigPostfix = QString()) const;
342 
343 private:
344  KMoreToolsPrivate* d;
345 };
346 
347 // --------------------------------------------------------------------------------------
348 // --------------------------------------------------------------------------------------
349 
350 class KMoreToolsServicePrivate;
351 
361 class KNEWSTUFF_EXPORT KMoreToolsService
362 {
363  friend class KMoreTools;
364  friend class KMoreToolsPrivate;
365 
366 public:
368 
369  KMoreToolsService(const KMoreToolsService &) = delete;
370  KMoreToolsService& operator=(const KMoreToolsService &) = delete;
371 
380  QString desktopEntryName() const;
381 
387  bool isInstalled() const;
388 
397  KService::Ptr installedService() const;
398 
403  KService::Ptr kmtProvidedService() const;
404 
409  QIcon kmtProvidedIcon() const;
410 
414  QUrl homepageUrl() const;
415 
421  void setHomepageUrl(const QUrl& url);
422 
426  int maxUrlArgCount() const;
427 
436  void setMaxUrlArgCount(int maxUrlArgCount);
437 
457  QString formatString(const QString& formatString) const;
458 
467  QIcon icon() const;
468 
475  void setExec(const QString& exec);
476 
485  QString appstreamId() const;
486 
497  void setAppstreamId(const QString&);
498 
499 private:
507  KMoreToolsService(const QString& kmtDesktopfileSubdir,
508  const QString& desktopEntryName,
509  bool isInstalled, KService::Ptr installedService,
510  KService::Ptr kmtDesktopfile);
511 
516 
517  KMoreToolsServicePrivate* d;
518 };
519 
520 // --------------------------------------------------------------------------------------
521 // --------------------------------------------------------------------------------------
522 
523 class KMoreToolsMenuItem;
524 class KMoreToolsMenuBuilderPrivate;
525 
534 class KNEWSTUFF_EXPORT KMoreToolsMenuBuilder
535 {
536  friend class KMoreToolsPrivate;
537  friend class KMoreTools;
538  friend class KMoreToolsTest;
539  friend class KMoreToolsTest2;
540  friend class KMoreToolsTestInteractive;
541 
542 public:
544 
546  KMoreToolsMenuBuilder& operator=(const KMoreToolsMenuBuilder &) = delete;
547 
555  void setInitialItemTextTemplate(const QString& templateText);
556 
576  KMoreToolsMenuItem* addMenuItem(KMoreToolsService* registeredService,
578 
595  KMoreToolsMenuItem* addMenuItem(QAction* action, const QString& itemId,
597 
603  void clear();
604 
619  void buildByAppendingToMenu(
620  QMenu* menu,
621  KMoreTools::ConfigureDialogAccessibleSetting configureDialogAccessibleSetting
623  QMenu** outMoreMenu = nullptr);
624 
625 private:
629  QString menuStructureAsString(bool mergeWithUserConfig) const;
630 
634  void showConfigDialog(const QString& title);
635 
640 
644  KMoreToolsMenuBuilder(const QString& uniqueId, const QString& userConfigPostfix);
645 
650 
651  KMoreToolsMenuBuilderPrivate* d;
652 };
653 
654 // --------------------------------------------------------------------------------------
655 // --------------------------------------------------------------------------------------
656 
657 class KMoreToolsMenuItemPrivate;
658 
671 class KNEWSTUFF_EXPORT KMoreToolsMenuItem
672 {
673  friend class KMoreToolsMenuBuilderPrivate;
674  friend class KMoreToolsMenuBuilder;
675 
676 public:
677  KMoreToolsMenuItem(const KMoreToolsMenuItem &) = delete;
678  KMoreToolsMenuItem& operator=(const KMoreToolsMenuItem &) = delete;
679 
691  QString id() const;
692 
700  void setId(const QString& id);
701 
708  KMoreToolsService* registeredService() const;
709 
713  KMoreTools::MenuSection defaultLocation() const;
714 
718  QString initialItemText() const;
719 
733  void setInitialItemText(const QString& itemText);
734 
760  QAction* action() const;
761 
762 private: // internal usage
766  KMoreToolsMenuItem(KMoreToolsService* registeredService, KMoreTools::MenuSection defaultLocation, const QString& initialItemTextTemplate);
767 
768  KMoreToolsMenuItem(QAction* action, const QString& itemId, KMoreTools::MenuSection defaultLocation);
769 
771 
772 private:
773  KMoreToolsMenuItemPrivate* d;
774 };
775 
776 #endif // KMORETOOLS_H
ConfigureDialogAccessibleSetting
Specify if the Configure dialog be accessible from the menu (via a "Configure..." menu item) ...
Definition: kmoretools.h:221
A service described in a .desktop file (kmt-desktopfile) which will be called "registered service"...
Definition: kmoretools.h:361
Define how the default structure of the menu should look like.
Definition: kmoretools.h:534
Represents a menu item of a service (application, tool or variant of the same service with different ...
Definition: kmoretools.h:671
by existence of desktop file (discoverable by KService)
Definition: kmoretools.h:175
Always show the "Configure..." menu item (default)
Definition: kmoretools.h:227
ServiceLocatingMode
Specify how should be determined if a service is installed or not.
Definition: kmoretools.h:170
MenuSection
Specify where a menu item be placed by default.
Definition: kmoretools.h:187
Helps to create user-configurable menus with tools which are potentially not yet installed.
Definition: kmoretools.h:161
The item is placed in the main section (default)
Definition: kmoretools.h:192
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue Aug 11 2020 22:43:23 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.