KMoreTools
kmoretools.cpp
59 * '/usr/share' = "~/.local/share", "/usr/local/share", "/usr/share" (see QStandardPaths::GenericDataLocation)
70 static QString findFileInKmtDesktopfilesDir(const QString &kmtDesktopfileSubdir, const QString &filename)
72 const QString kmtDesktopfilesFilename = QLatin1String("kf6/kmoretools/") + kmtDesktopfileSubdir + QLatin1Char('/') + filename;
73 const QString foundKmtFile = QStandardPaths::locate(QStandardPaths::GenericDataLocation, kmtDesktopfilesFilename);
91 d->findFileInKmtDesktopfilesDir(d->kmtDesktopfileSubdirOrUniqueId(kmtDesktopfileSubdir), desktopEntryName + QLatin1String(".desktop"));
99 qCCritical(KMORETOOLS) << "KMoreTools::registerServiceByDesktopEntryName: the kmt-desktopfile " << desktopEntryName
100 << " is provided but no Exec line is specified. The desktop file is probably faulty. Please fix. Return nullptr.";
104 qCWarning(KMORETOOLS) << "KMoreTools::registerServiceByDesktopEntryName: desktopEntryName " << desktopEntryName
106 << ") not provided (or at the wrong place) in the installed kmt-desktopfiles directory. If the service is also not installed on "
108 qCDebug(KMORETOOLS) << "`-- More info at findFileInKmtDesktopfilesDir, QStandardPaths::standardLocations = "
114 if (serviceLocatingMode == KMoreTools::ServiceLocatingMode_Default) { // == default behaviour: search for installed services
117 } else if (serviceLocatingMode == KMoreTools::ServiceLocatingMode_ByProvidedExecLine) { // only use provided kmt-desktopfile:
121 << ": If detectServiceExistenceViaProvidedExecLine is true then a kmt-desktopfile must be provided. Please fix. Return nullptr.";
127 (!tryExec.isEmpty() && !QStandardPaths::findExecutable(tryExec).isEmpty()) || !QStandardPaths::findExecutable(kmtDesktopfile->exec()).isEmpty();
133 new KMoreToolsService(d->kmtDesktopfileSubdirOrUniqueId(kmtDesktopfileSubdir), desktopEntryName, isInstalled, installedService, kmtDesktopfile);
136 auto foundService = std::find_if(d->serviceList.begin(), d->serviceList.end(), [&desktopEntryName](KMoreToolsService *service) {
154 d->menuBuilderMap.insert(userConfigPostfix, new KMoreToolsMenuBuilder(d->uniqueId, userConfigPostfix));
159// ------------------------------------------------------------------------------------------------
160// ------------------------------------------------------------------------------------------------
202 * @return the provided icon or an empty icon if not kmtDesktopfile is available or the icon was not found
210 QString iconPath = KMoreToolsPrivate::findFileInKmtDesktopfilesDir(kmtDesktopfileSubdir, kmtDesktopfile->icon() + QLatin1String(".svg"));
216 iconPath = KMoreToolsPrivate::findFileInKmtDesktopfilesDir(kmtDesktopfileSubdir, kmtDesktopfile->icon() + QLatin1String(".png"));
340// ------------------------------------------------------------------------------------------------
341// ------------------------------------------------------------------------------------------------
419 * This is done by KMoreToolsMenuBuilderPrivate::createMenuStructure(mergeWithUserConfig = true).
428 * If createMenuStructureOption == CreateMenuStructure_Default then the default menu structure is returned.
432 KmtMenuStructureDto configuredStructure; // if this stays empty then the default structure will not be changed
445 auto foundItem = std::find_if(menuItemsSource.begin(), menuItemsSource.end(), [&item](const KMoreToolsMenuItem *kMenuItem) {
463 if ((registeredService && registeredService->isInstalled()) || !registeredService) { // if a QAction was registered directly
474 "invalid enum"); // todo/later: apart from static programming error, if the config garbage this might happen
489 void showConfigDialog(KmtMenuStructureDto defaultStructureDto, const QString &title = QString()) const
495 KMoreToolsConfigDialog *dlg = new KMoreToolsConfigDialog(defaultStructureDto, currentStructureDto, title);
520 QMenu *submenuForNotInstalled = KmtNotInstalledUtil::createSubmenuForNotInstalledApp(registeredService->formatString(QStringLiteral("$Name")),
536KMoreToolsMenuBuilder::KMoreToolsMenuBuilder(const QString &uniqueId, const QString &userConfigPostfix)
553KMoreToolsMenuItem *KMoreToolsMenuBuilder::addMenuItem(KMoreToolsService *registeredService, KMoreTools::MenuSection defaultLocation)
555 auto kmtMenuItem = new KMoreToolsMenuItem(registeredService, defaultLocation, d->initialItemTextTemplate);
561KMoreToolsMenuItem *KMoreToolsMenuBuilder::addMenuItem(QAction *action, const QString &itemId, KMoreTools::MenuSection defaultLocation)
563 auto kmtMenuItem = new KMoreToolsMenuItem(action, d->menuItemIdGen.getId(itemId), defaultLocation);
576 KmtMenuStructure mstruct = d->createMenuStructure(mergeWithUserConfig ? KMoreToolsMenuBuilderPrivate::CreateMenuStructure_MergeWithUserConfig
597 d->showConfigDialog(d->createMenuStructure(KMoreToolsMenuBuilderPrivate::CreateMenuStructure_Default).toDto(), title);
604 KmtMenuStructure mstruct = d->createMenuStructure(KMoreToolsMenuBuilderPrivate::CreateMenuStructure_MergeWithUserConfig);
638 if (configureDialogAccessibleSetting == KMoreTools::ConfigureDialogAccessible_Always || QApplication::keyboardModifiers() & Qt::ControlModifier
639 || (configureDialogAccessibleSetting == KMoreTools::ConfigureDialogAccessible_Defensive && !mstruct.notInstalledServices.empty())) {
650 auto configureAction = baseMenu->addAction(QIcon::fromTheme(QStringLiteral("configure")), i18nc("@action:inmenu", "Configure..."));
651 configureAction->setData(QStringLiteral("configureItem")); // tag the action (currently only used in unit-test)
652 KmtMenuStructure mstructDefault = d->createMenuStructure(KMoreToolsMenuBuilderPrivate::CreateMenuStructure_Default);
653 KmtMenuStructureDto mstructDefaultDto = mstructDefault.toDto(); // makes sure the "Reset" button works as expected
654 QObject::connect(configureAction, &QAction::triggered, configureAction, [this, mstructDefaultDto](bool) {
672KMoreToolsMenuItem::KMoreToolsMenuItem(KMoreToolsService *registeredService, KMoreTools::MenuSection defaultLocation, const QString &initialItemTextTemplate)
679 QString defaultName = registeredService->formatString(initialItemTextTemplate); // e.g. "$GenericName", "$Name"
683KMoreToolsMenuItem::KMoreToolsMenuItem(QAction *action, const QString &itemId, KMoreTools::MenuSection defaultLocation)
693 if (d->actionAutoCreated && d->action) { // Only do this if KMoreTools created the action. Other actions must be deleted by client.
740 // this happens in unit-tests where menu.clear() is called before another buildByAppendingToMenu call
NoGlobals
Define how the default structure of the menu should look like.
Definition kmoretools.h:525
void buildByAppendingToMenu(QMenu *menu, KMoreTools::ConfigureDialogAccessibleSetting configureDialogAccessibleSetting=KMoreTools::ConfigureDialogAccessible_Always, QMenu **outMoreMenu=nullptr)
Builds the actual menu and appends all items (main items, more submenu with a potential "not installe...
Definition kmoretools.cpp:600
KMoreToolsMenuItem * addMenuItem(KMoreToolsService *registeredService, KMoreTools::MenuSection defaultLocation=KMoreTools::MenuSection_Main)
Adds a registered service (which can installed or not) to the menu.
Definition kmoretools.cpp:553
void setInitialItemTextTemplate(const QString &templateText)
Affects addMenuItem() if called before it.
Definition kmoretools.cpp:548
Represents a menu item of a service (application, tool or variant of the same service with different ...
Definition kmoretools.h:656
void setId(const QString &id)
(Optional) to help with stable ids (see id())
Definition kmoretools.cpp:706
KMoreToolsService * registeredService() const
Definition kmoretools.cpp:711
void setInitialItemText(const QString &itemText)
Sets the initial text of a menu item.
Definition kmoretools.cpp:726
QString id() const
Auto-generated unique id that tries to be as stable as possible even if the menu gets restructured af...
Definition kmoretools.cpp:701
KMoreTools::MenuSection defaultLocation() const
see KMoreToolsMenuBuilder::addMenuItem
Definition kmoretools.cpp:716
A service described in a .desktop file (kmt-desktopfile) which will be called "registered service".
Definition kmoretools.h:357
QString appstreamId() const
Returns the associated appstream id that was previously set with setAppstreamId().
Definition kmoretools.cpp:330
void setHomepageUrl(const QUrl &url)
Sets the homepage url the user is shown when a service is not installed.
Definition kmoretools.cpp:272
KService::Ptr kmtProvidedService() const
Definition kmoretools.cpp:257
void setMaxUrlArgCount(int maxUrlArgCount)
In KMoreToolsMenuFactory some minor magic is done.
Definition kmoretools.cpp:282
KService::Ptr installedService() const
Definition kmoretools.cpp:252
QString formatString(const QString &formatString) const
Definition kmoretools.cpp:287
void setExec(const QString &exec)
Will override the "Exec=" line of the service.
Definition kmoretools.cpp:322
void setAppstreamId(const QString &)
Sets the appstream id of the service.
Definition kmoretools.cpp:335
KMoreToolsService * registerServiceByDesktopEntryName(const QString &desktopEntryName, const QString &kmtDesktopfileSubdir=QString(), ServiceLocatingMode serviceLocatingMode=ServiceLocatingMode_Default)
Registers a service with KMoreTools.
Definition kmoretools.cpp:86
KMoreToolsMenuBuilder * menuBuilder(const QString &userConfigPostfix=QString()) const
Definition kmoretools.cpp:151
ConfigureDialogAccessibleSetting
Specify if the Configure dialog be accessible from the menu (via a "Configure..." menu item)
Definition kmoretools.h:220
@ ConfigureDialogAccessible_Always
Always show the "Configure..." menu item (default)
Definition kmoretools.h:225
@ ConfigureDialogAccessible_Defensive
Defensively show the "Configure..." menu item.
Definition kmoretools.h:239
ServiceLocatingMode
Specify how should be determined if a service is installed or not.
Definition kmoretools.h:171
@ 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
static Ptr serviceByDesktopName(const QString &_name)
QExplicitlySharedDataPointer< KService > Ptr
QString i18nc(const char *context, const char *text, const TYPE &arg...)
void setData(const QVariant &data)
void triggered(bool checked)
Accepted
Qt::KeyboardModifiers keyboardModifiers()
QIcon fromTheme(const QString &name)
void append(QList< T > &&value)
iterator begin()
void clear()
iterator end()
bool removeOne(const AT &t)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void destroyed(QObject *obj)
GenericDataLocation
QString findExecutable(const QString &executableName, const QStringList &paths)
QString locate(StandardLocation type, const QString &fileName, LocateOptions options)
QStringList standardLocations(StandardLocation type)
bool isEmpty() const const
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
ControlModifier
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:15:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.