File indexing completed on 2024-09-15 09:26:36
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 1998, 1999 Torben Weis <weis@kde.org> 0004 SPDX-FileCopyrightText: 1999-2006 David Faure <faure@kde.org> 0005 SPDX-FileCopyrightText: 2022 Harald Sitter <sitter@kde.org> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef KSERVICE_H 0011 #define KSERVICE_H 0012 0013 #include "kserviceaction.h" 0014 #include <QCoreApplication> 0015 #include <QStringList> 0016 #include <QVariant> 0017 #include <ksycocaentry.h> 0018 0019 // Exclude includes that are not needed when deprecations are disabled 0020 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 94) 0021 #include <KPluginFactory> 0022 #include <KPluginLoader> 0023 #endif 0024 0025 class KServiceType; 0026 class QDataStream; 0027 class KDesktopFile; 0028 class QWidget; 0029 0030 class KServicePrivate; 0031 0032 /** 0033 * @class KService kservice.h <KService> 0034 * 0035 * Represent a service, like an application or plugin 0036 * bound to one or several MIME types (or servicetypes) as written 0037 * in its desktop entry file. 0038 * 0039 * The starting point you need is often the static methods, like createInstance(). 0040 * The types of service a plugin provides is taken from the accompanying desktop file 0041 * where the 'X-KDE-ServiceTypes=' field is used. 0042 * 0043 * For a tutorial on how to build a plugin-loading mechanism and how to write plugins 0044 * in general, see http://techbase.kde.org/Development/Tutorials#Services:_Applications_and_Plugins 0045 * 0046 * @see KServiceType 0047 * @see KServiceGroup 0048 * @author Torben Weis 0049 */ 0050 class KSERVICE_EXPORT KService : public KSycocaEntry 0051 { 0052 public: 0053 /** 0054 * A shared data pointer for KService. 0055 */ 0056 typedef QExplicitlySharedDataPointer<KService> Ptr; 0057 /** 0058 * A list of shared data pointers for KService. 0059 */ 0060 typedef QList<Ptr> List; 0061 0062 /** 0063 * Construct a temporary service with a given name, exec-line and icon. 0064 * @param name the name of the service 0065 * @param exec the executable 0066 * @param icon the name of the icon 0067 */ 0068 KService(const QString &name, const QString &exec, const QString &icon); 0069 0070 /** 0071 * Construct a service and take all information from a config file. 0072 * 0073 * @param fullpath Full path to the config file. 0074 */ 0075 explicit KService(const QString &fullpath); 0076 0077 /** 0078 * Construct a service and take all information from a desktop file. 0079 * @param config the desktop file to read 0080 * @param optional relative path to store for findByName 0081 */ 0082 explicit KService(const KDesktopFile *config, const QString &entryPath = QString()); 0083 0084 KService(const KService &other); 0085 0086 ~KService() override; 0087 0088 /** 0089 * Services are either applications (executables) or dlopened libraries (plugins). 0090 * @return true if this service is an application, i.e. it has Type=Application in its 0091 * .desktop file and exec() will not be empty. 0092 */ 0093 bool isApplication() const; 0094 0095 /** 0096 * Returns the executable. 0097 * @return the command that the service executes, 0098 * or QString() if not set 0099 */ 0100 QString exec() const; 0101 /** 0102 * Returns the name of the service's library. 0103 * @return the name of the library that contains the service's 0104 * implementation, or QString() if not set 0105 */ 0106 QString library() const; 0107 0108 /** 0109 * Returns the name of the icon. 0110 * @return the icon associated with the service, 0111 * or QString() if not set 0112 */ 0113 QString icon() const; 0114 /** 0115 * Checks whether the service should be run in a terminal. 0116 * @return true if the service is to be run in a terminal. 0117 */ 0118 bool terminal() const; 0119 0120 /** 0121 * Returns any options associated with the terminal the service 0122 * runs in, if it requires a terminal. 0123 * 0124 * The service must be a tty-oriented program. 0125 * @return the terminal options, 0126 * or QString() if not set 0127 */ 0128 QString terminalOptions() const; 0129 0130 /** 0131 * Returns @c true if the service inidicates that it's preferred to run 0132 * the application on a discrete graphics card, otherwise return @c false. 0133 * 0134 * In releases older than 5.86 this methoed checked for the @c X-KDE-RunOnDiscreteGpu 0135 * key in the .desktop file represented by this service; starting from 5.86 this method 0136 * now also checks for @c PrefersNonDefaultGPU key (added to the Freedesktop.org desktop 0137 * entry spec in version 1.4 of the spec). 0138 * 0139 * @since 5.30 0140 */ 0141 bool runOnDiscreteGpu() const; 0142 0143 /** 0144 * Checks whether the service runs with a different user id. 0145 * @return true if the service has to be run under a different uid. 0146 * @see username() 0147 */ 0148 bool substituteUid() const; 0149 /** 0150 * Returns the user name, if the service runs with a 0151 * different user id. 0152 * @return the username under which the service has to be run, 0153 * or QString() if not set 0154 * @see substituteUid() 0155 */ 0156 QString username() const; 0157 0158 /** 0159 * Returns the filename of the service desktop entry without any 0160 * extension. E.g. "kppp" 0161 * @return the name of the desktop entry without path or extension, 0162 * or QString() if not set 0163 */ 0164 QString desktopEntryName() const; 0165 0166 /** 0167 * Returns the menu ID of the service desktop entry. 0168 * The menu ID is used to add or remove the entry to a menu. 0169 * @return the menu ID 0170 */ 0171 QString menuId() const; 0172 0173 /** 0174 * Returns a normalized ID suitable for storing in configuration files. 0175 * It will be based on the menu-id when available and otherwise falls 0176 * back to entryPath() 0177 * @return the storage ID 0178 */ 0179 QString storageId() const; 0180 0181 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 102) 0182 /** 0183 * Describes the D-Bus Startup type of the service. 0184 * @li None - This service has no D-Bus support 0185 * @li Unique - This service provides a unique D-Bus service. 0186 * The service name is equal to the desktopEntryName. 0187 * @li Multi - This service provides a D-Bus service which can be run 0188 * with multiple instances in parallel. The service name of 0189 * an instance is equal to the desktopEntryName + "-" + 0190 * the PID of the process. 0191 */ 0192 enum DBusStartupType { DBusNone = 0, DBusUnique, DBusMulti }; 0193 #endif 0194 0195 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 102) 0196 /** 0197 * Returns the DBUSStartupType supported by this service. 0198 * @return the DBUSStartupType supported by this service 0199 * 0200 * @deprecated since 5.102, no known users. 0201 */ 0202 KSERVICE_DEPRECATED_VERSION(5, 102, "No known users") 0203 DBusStartupType dbusStartupType() const; 0204 #endif 0205 0206 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 63) 0207 /** 0208 * @return the working directory to run the program in, 0209 * or QString() if not set 0210 * @deprecated since 5.63, use workingDirectory() instead 0211 */ 0212 KSERVICE_DEPRECATED_VERSION(5, 63, "Use KService::workingDirectory()") 0213 QString path() const; 0214 #endif 0215 0216 /** 0217 * @return the working directory to run the program in, 0218 * or QString() if not set 0219 * @since 5.63 0220 */ 0221 QString workingDirectory() const; 0222 0223 /** 0224 * Returns the descriptive comment for the service, if there is one. 0225 * @return the descriptive comment for the service, or QString() 0226 * if not set 0227 */ 0228 QString comment() const; 0229 0230 /** 0231 * Returns the generic name for the service, if there is one 0232 * (e.g. "Mail Client"). 0233 * @return the generic name, 0234 * or QString() if not set 0235 */ 0236 QString genericName() const; 0237 0238 /** 0239 * Returns the untranslated (US English) generic name 0240 * for the service, if there is one 0241 * (e.g. "Mail Client"). 0242 * @return the generic name, 0243 * or QString() if not set 0244 */ 0245 QString untranslatedGenericName() const; 0246 0247 /** 0248 * Returns a list of descriptive keywords the service, if there are any. 0249 * @return the list of keywords 0250 */ 0251 QStringList keywords() const; 0252 0253 /** 0254 * Returns a list of VFolder categories. 0255 * @return the list of VFolder categories 0256 */ 0257 QStringList categories() const; 0258 0259 /** 0260 * Returns the list of MIME types that this service supports. 0261 * Note that this doesn't include inherited MIME types, 0262 * only the MIME types listed in the .desktop file. 0263 * @since 4.8.3 0264 */ 0265 QStringList mimeTypes() const; 0266 0267 /** 0268 * Returns the list of protocols this service supports. 0269 * 0270 * This is taken from the x-scheme-handler MIME types 0271 * listed in the .destkop file as well as the 'X-KDE-Protocols' 0272 * entry 0273 * 0274 * For example a web browser could return {"http", "https"}. 0275 * @since 5.104 0276 */ 0277 QStringList supportedProtocols() const; 0278 0279 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 104) 0280 /** 0281 * Returns the service types that this service supports. 0282 * @return the list of service types that are supported 0283 * Note that this doesn't include inherited servicetypes or MIME types, 0284 * only the service types listed in the .desktop file. 0285 * 0286 * @deprecated since 5.104, service types are deprecated. Read the 0287 * X-KDE-ServiceType[s] key manually if really needed. 0288 * 0289 */ 0290 KSERVICE_DEPRECATED_VERSION(5, 104, "Service Types are deprecated") 0291 QStringList serviceTypes() const; 0292 #endif 0293 0294 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 104) 0295 /** 0296 * Checks whether the service supports this service type 0297 * @param serviceTypePtr The name of the service type you are 0298 * interested in determining whether this service supports. 0299 * 0300 * @return true if the service type you specified is supported, otherwise false. 0301 * 0302 * @deprecated since 5.104, service types are deprecated. Read the 0303 * X-KDE-ServiceType[s] key manually if really needed. 0304 */ 0305 KSERVICE_DEPRECATED_VERSION(5, 104, "Service Types are deprecated") 0306 bool hasServiceType(const QString &serviceTypePtr) const; 0307 #endif 0308 0309 /** 0310 * Checks whether the service supports this MIME type 0311 * @param mimeType The name of the MIME type you are 0312 * interested in determining whether this service supports. 0313 * @since 4.6 0314 */ 0315 bool hasMimeType(const QString &mimeType) const; 0316 0317 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 67) 0318 /** 0319 * Set to true if it is allowed to use this service as the default (main) 0320 * action for the files it supports (e.g. Left Click in a file manager, or KRun in general). 0321 * 0322 * If not, then this service is only available in RMB popups, so it must 0323 * be selected explicitly by the user in order to be used. 0324 * Note that servicemenus supersede this functionality though, at least in konqueror. 0325 * 0326 * @return true if the service may be used as the default (main) handler 0327 * @deprecated since 5.67 due to no known use case 0328 */ 0329 KSERVICE_DEPRECATED_VERSION(5, 67, "No known use case") 0330 bool allowAsDefault() const; 0331 #endif 0332 0333 /** 0334 * Returns the actions defined in this desktop file 0335 */ 0336 QList<KServiceAction> actions() const; 0337 0338 /** 0339 * Checks whether this service can handle several files as 0340 * startup arguments. 0341 * @return true if multiple files may be passed to this service at 0342 * startup. False if only one file at a time may be passed. 0343 */ 0344 bool allowMultipleFiles() const; 0345 0346 /** 0347 * What preference to associate with this service initially (before 0348 * the user has had any chance to define a profile for it). 0349 * The bigger the value, the most preferred the service is. 0350 * @return the service preference level of the service 0351 */ 0352 int initialPreference() const; 0353 0354 /** 0355 * Whether the entry should be suppressed in the K menu. 0356 * @return true to suppress this service 0357 * 0358 * Such services still appear in trader queries, i.e. in 0359 * "Open With" popup menus for instance. 0360 */ 0361 bool noDisplay() const; 0362 0363 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 0) 0364 /** 0365 * Whether the service should be shown in KDE at all 0366 * (including in context menus). 0367 * @return true if the service should be shown. 0368 * 0369 * KMimeTypeTrader honors this and removes such services 0370 * from its results. 0371 * 0372 * @since 4.5 0373 * @deprecated since 5.0, use showInCurrentDesktop() 0374 */ 0375 KSERVICE_DEPRECATED_VERSION(5, 0, "Use KService::showInCurrentDesktop()") 0376 bool showInKDE() const 0377 { 0378 return showInCurrentDesktop(); 0379 } 0380 #endif 0381 0382 /** 0383 * Whether the service should be shown in the current desktop 0384 * (including in context menus). 0385 * @return true if the service should be shown. 0386 * 0387 * KApplicationTrader honors this and removes such services 0388 * from its results. 0389 * 0390 * @since 5.0 0391 */ 0392 bool showInCurrentDesktop() const; 0393 0394 /** 0395 * Whether the service should be shown on the current 0396 * platform (e.g. on xcb or on wayland). 0397 * @return true if the service should be shown 0398 * 0399 * @since 5.0 0400 */ 0401 bool showOnCurrentPlatform() const; 0402 0403 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 87) 0404 /** 0405 * Name of the application this service belongs to. 0406 * (Useful for e.g. plugins) 0407 * @return the parent application, or QString() if not set 0408 * @deprecated Since 5.87, the concept of parent apps is deprecated. Plugins should use KPluginMetaData instead of 0409 * KService and a dedicated namespace if the plugins are only for one app relevant. 0410 */ 0411 KSERVICE_DEPRECATED_VERSION(5, 87, "See API docs") 0412 QString parentApp() const; 0413 #endif 0414 0415 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 87) 0416 /** 0417 * The keyword to be used when constructing the plugin using KPluginFactory. The keyword is 0418 * defined with X-KDE-PluginKeyword in the .desktop file and with registerPlugin<T>(keyword) 0419 * in the K_PLUGIN_FACTORY macro when implementing the plugin. 0420 * @deprecated Since 5.87, the metadata should be embedded in the actual plugin. Consequently 0421 * this property is obsolete. In case there is only one plugin in the library the usage is not needed. 0422 * In case there are different base classes registered the keyword is not needed too. 0423 * If there are multiple classes of a common base class registered they should be split up 0424 * in separate libs. 0425 */ 0426 KSERVICE_DEPRECATED_VERSION(5, 87, "See API docs") 0427 QString pluginKeyword() const; 0428 #endif 0429 0430 /** 0431 * The path to the documentation for this service. 0432 * @since 4.2 0433 * @return the documentation path, or QString() if not set 0434 */ 0435 QString docPath() const; 0436 0437 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 102) 0438 /** 0439 * Returns the requested property. 0440 * 0441 * @param _name the name of the property 0442 * @param t the assumed type of the property 0443 * @return the property, or invalid if not found 0444 * @see KServiceType 0445 * 0446 * @deprecated since 5.102, use property(QString, QMetaType::Type) instead. 0447 */ 0448 KSERVICE_DEPRECATED_VERSION(5, 102, "Use property(QString, QMetaType::Type) instead") 0449 QVariant property(const QString &_name, QVariant::Type t) const; 0450 #endif 0451 0452 /** 0453 * Returns the requested property. 0454 * 0455 * @param _name the name of the property 0456 * @param t the assumed type of the property 0457 * @return the property, or invalid if not found 0458 * @see KServiceType 0459 * 0460 * @since 5.102 0461 */ 0462 QVariant property(const QString &_name, QMetaType::Type t) const; 0463 0464 using KSycocaEntry::property; 0465 0466 /** 0467 * Returns a path that can be used for saving changes to this 0468 * service 0469 * @return path that can be used for saving changes to this service 0470 */ 0471 QString locateLocal() const; 0472 0473 /** 0474 * @internal 0475 * Set the menu id 0476 */ 0477 void setMenuId(const QString &menuId); 0478 /** 0479 * @internal 0480 * Sets whether to use a terminal or not 0481 */ 0482 void setTerminal(bool b); 0483 /** 0484 * @internal 0485 * Sets the terminal options to use 0486 */ 0487 void setTerminalOptions(const QString &options); 0488 0489 /** 0490 * Overrides the "Exec=" line of the service. 0491 * 0492 * If @ref exec is not empty, its value will override the one 0493 * the one set when this service was created. 0494 * 0495 * Please note that @ref entryPath is also cleared so the service 0496 * will no longer be associated with a specific config file. 0497 * 0498 * @internal 0499 * @since 4.11 0500 */ 0501 void setExec(const QString &exec); 0502 0503 /** 0504 * Overrides the "Path=" line of the service. 0505 * 0506 * If @ref workingDir is not empty, its value will override the one 0507 * the one set when this service was created. 0508 * 0509 * Please note that @ref entryPath is also cleared so the service 0510 * will no longer be associated with a specific config file. 0511 * 0512 * @internal 0513 * @param workingDir 0514 * @since 5.79 0515 */ 0516 void setWorkingDirectory(const QString &workingDir); 0517 0518 /** 0519 * Find a service based on its path as returned by entryPath(). 0520 * It's usually better to use serviceByStorageId() instead. 0521 * 0522 * @param _path the path of the configuration file 0523 * @return a pointer to the requested service or @c nullptr if the service is 0524 * unknown. 0525 * @em Very @em important: Don't store the result in a KService* ! 0526 */ 0527 static Ptr serviceByDesktopPath(const QString &_path); 0528 0529 /** 0530 * Find a service by the name of its desktop file, not depending on 0531 * its actual location (as long as it's under the applications or service 0532 * directories). For instance "konqbrowser" or "kcookiejar". Note that 0533 * the ".desktop" extension is implicit. 0534 * 0535 * This is the recommended method (safe even if the user moves stuff) 0536 * but note that it assumes that no two entries have the same filename. 0537 * 0538 * @param _name the name of the configuration file 0539 * @return a pointer to the requested service or @c nullptr if the service is 0540 * unknown. 0541 * @em Very @em important: Don't store the result in a KService* ! 0542 */ 0543 static Ptr serviceByDesktopName(const QString &_name); 0544 0545 /** 0546 * Find a service by its menu-id 0547 * 0548 * @param _menuId the menu id of the service 0549 * @return a pointer to the requested service or @c nullptr if the service is 0550 * unknown. 0551 * @em Very @em important: Don't store the result in a KService* ! 0552 */ 0553 static Ptr serviceByMenuId(const QString &_menuId); 0554 0555 /** 0556 * Find a service by its storage-id or desktop-file path. This 0557 * function will try very hard to find a matching service. 0558 * 0559 * @param _storageId the storage id or desktop-file path of the service 0560 * @return a pointer to the requested service or @c nullptr if the service is 0561 * unknown. 0562 * @em Very @em important: Don't store the result in a KService* ! 0563 */ 0564 static Ptr serviceByStorageId(const QString &_storageId); 0565 0566 /** 0567 * Returns the whole list of services. 0568 * 0569 * Useful for being able to 0570 * to display them in a list box, for example. 0571 * More memory consuming than the ones above, don't use unless 0572 * really necessary. 0573 * @return the list of all services 0574 */ 0575 static List allServices(); 0576 0577 /** 0578 * Returns a path that can be used to create a new KService based 0579 * on @p suggestedName. 0580 * @param showInMenu true, if the service should be shown in the KDE menu 0581 * false, if the service should be hidden from the menu 0582 * This argument isn't used anymore, use NoDisplay=true to hide the service. 0583 * @param suggestedName name to base the file on, if a service with such a 0584 * name already exists, a suffix will be added to make it unique 0585 * (e.g. foo.desktop, foo-1.desktop, foo-2.desktop). 0586 * @param menuId If provided, menuId will be set to the menu id to use for 0587 * the KService 0588 * @param reservedMenuIds If provided, the path and menu id will be chosen 0589 * in such a way that the new menu id does not conflict with any 0590 * of the reservedMenuIds 0591 * @return The path to use for the new KService. 0592 */ 0593 static QString newServicePath(bool showInMenu, const QString &suggestedName, QString *menuId = nullptr, const QStringList *reservedMenuIds = nullptr); 0594 0595 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 86) 0596 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 86) 0597 /** 0598 * This template allows to load the library for the specified service and ask the 0599 * factory to create an instance of the given template type. 0600 * 0601 * @param parent The parent object (see QObject constructor) 0602 * @param args A list of arguments, passed to the factory and possibly 0603 * to the component (see KPluginFactory) 0604 * @param error A pointer to QString which should receive the error description or @c nullptr 0605 * 0606 * @return A pointer to the newly created object or a null pointer if the 0607 * factory was unable to create an object of the given type. 0608 * 0609 * @see KPluginFactory::instantiatePlugin 0610 * @deprecated Since 5.86, Use KPluginMetaData/KPluginFactory or QPluginloader instead 0611 */ 0612 template<class T> 0613 KSERVICE_DEPRECATED_VERSION(5, 86, "Use KPluginMetaData/KPluginFactory or QPluginloader instead") 0614 T *createInstance(QObject *parent = nullptr, const QVariantList &args = QVariantList(), QString *error = nullptr) const 0615 { 0616 return createInstance<T>(nullptr, parent, args, error); 0617 } 0618 #endif 0619 #endif 0620 0621 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 86) 0622 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 86) 0623 /** 0624 * This template allows to load the library for the specified service and ask the 0625 * factory to create an instance of the given template type. 0626 * 0627 * @param parentWidget A parent widget for the service. This is used e. g. for parts 0628 * @param parent The parent object (see QObject constructor) 0629 * @param args A list of arguments, passed to the factory and possibly 0630 * to the component (see KPluginFactory) 0631 * @param error A pointer to QString which should receive the error description or @c nullptr 0632 * 0633 * @return A pointer to the newly created object or a null pointer if the 0634 * factory was unable to create an object of the given type. 0635 * 0636 * @see KPluginFactory::instantiatePlugin 0637 * @deprecated Since 5.86, Use KPluginMetaData/KPluginFactory or QPluginloader instead 0638 */ 0639 template<class T> 0640 KSERVICE_DEPRECATED_VERSION(5, 86, "Use KPluginMetaData/KPluginFactory or QPluginloader instead") 0641 T *createInstance(QWidget *parentWidget, QObject *parent, const QVariantList &args = QVariantList(), QString *error = nullptr) const 0642 { 0643 QT_WARNING_PUSH 0644 QT_WARNING_DISABLE_DEPRECATED 0645 KPluginLoader pluginLoader(*this); 0646 KPluginFactory *factory = pluginLoader.factory(); 0647 if (factory) { 0648 QVariantList argsWithMetaData = args; 0649 argsWithMetaData << pluginLoader.metaData().toVariantMap(); 0650 T *o = factory->template create<T>(parentWidget, parent, pluginKeyword(), argsWithMetaData); 0651 if (!o && error) 0652 *error = QCoreApplication::translate("", "The service '%1' does not provide an interface '%2' with keyword '%3'") 0653 .arg(name(), QString::fromLatin1(T::staticMetaObject.className()), pluginKeyword()); 0654 return o; 0655 } else if (error) { 0656 *error = pluginLoader.errorString(); 0657 pluginLoader.unload(); 0658 } 0659 QT_WARNING_POP 0660 return nullptr; 0661 } 0662 #endif 0663 #endif 0664 0665 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 86) 0666 #if KCOREADDONS_ENABLE_DEPRECATED_SINCE(5, 86) 0667 /** 0668 * Convert this KService to a KPluginName. 0669 * 0670 * This allows expressions like 0671 * @code 0672 * KPluginLoader(service); 0673 * @endcode 0674 * which will use library() as the name of the plugin. If the service 0675 * is not valid or does not have a library, KPluginLoader::errorString() 0676 * will be set appropriately. 0677 */ 0678 operator KPluginName() const; 0679 #endif 0680 #endif 0681 0682 /** 0683 * @brief A desktop file name that this service is an alias for. 0684 * 0685 * This is used when a NoDisplay service is used to enforce specific handling 0686 * for an application. In that case the NoDisplay service is an AliasFor another 0687 * service and be considered roughly equal to the AliasFor service (which should 0688 * not be NoDisplay=true) 0689 * For example okular supplies a desktop file for each supported format (e.g. PDF), all 0690 * of which NoDisplay and merely there to selectively support specific file formats. 0691 * A UI may choose to display the aliased entry org.kde.okular instead of the NoDisplay entries. 0692 * 0693 * @since 5.96 0694 * 0695 * @return QString desktopName of the aliased service (excluding .desktop suffix) 0696 */ 0697 QString aliasFor() const; 0698 0699 private: 0700 friend class KBuildServiceFactory; 0701 0702 /// @internal for KBuildSycoca only 0703 struct KSERVICE_NO_EXPORT ServiceTypeAndPreference { 0704 ServiceTypeAndPreference() 0705 : preference(-1) 0706 , serviceType() 0707 { 0708 } 0709 ServiceTypeAndPreference(int pref, const QString &servType) 0710 : preference(pref) 0711 , serviceType(servType) 0712 { 0713 } 0714 int preference; 0715 QString serviceType; // or MIME type 0716 }; 0717 /// @internal for KBuildSycoca only 0718 QVector<ServiceTypeAndPreference> &_k_accessServiceTypes(); 0719 0720 void setActions(const QList<KServiceAction> &actions); 0721 0722 friend QDataStream &operator>>(QDataStream &, ServiceTypeAndPreference &); 0723 friend QDataStream &operator<<(QDataStream &, const ServiceTypeAndPreference &); 0724 0725 Q_DECLARE_PRIVATE(KService) 0726 0727 friend class KServiceFactory; 0728 0729 /** 0730 * @internal 0731 * Construct a service from a stream. 0732 * The stream must already be positioned at the correct offset. 0733 */ 0734 KSERVICE_NO_EXPORT KService(QDataStream &str, int offset); 0735 }; 0736 #endif