File indexing completed on 2023-11-26 10:45:34
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef KSERVICEACTION_H 0009 #define KSERVICEACTION_H 0010 0011 #include <QSharedDataPointer> 0012 #include <QVariant> 0013 #include <kservice_export.h> 0014 class QVariant; 0015 class KServiceActionPrivate; 0016 class KService; 0017 0018 // we can't include kservice.h, it includes this header... 0019 typedef QExplicitlySharedDataPointer<KService> KServicePtr; 0020 0021 /** 0022 * @class KServiceAction kserviceaction.h <KServiceAction> 0023 * 0024 * Represents an action in a .desktop file 0025 * Actions are defined with the config key Actions in the [Desktop Entry] 0026 * group, followed by one group per action, as per the desktop entry standard. 0027 * @see KService::actions 0028 */ 0029 class KSERVICE_EXPORT KServiceAction 0030 { 0031 public: 0032 /** 0033 * Creates a KServiceAction. 0034 * Normally you don't have to do this, KService creates the actions 0035 * when parsing the .desktop file. 0036 * @since 5.69 0037 */ 0038 KServiceAction(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay, const KServicePtr &service); 0039 /** 0040 * @internal 0041 * Needed for operator>> 0042 */ 0043 KServiceAction(); 0044 /** 0045 * Destroys a KServiceAction. 0046 */ 0047 ~KServiceAction(); 0048 0049 /** 0050 * Copy constructor 0051 */ 0052 KServiceAction(const KServiceAction &other); 0053 /** 0054 * Assignment operator 0055 */ 0056 KServiceAction &operator=(const KServiceAction &other); 0057 0058 /** 0059 * Sets the action's internal data to the given @p userData. 0060 */ 0061 void setData(const QVariant &userData); 0062 /** 0063 * @return the action's internal data. 0064 */ 0065 QVariant data() const; 0066 0067 /** 0068 * @return the action's internal name 0069 * For instance Actions=Setup;... and the group [Desktop Action Setup] 0070 * define an action with the name "Setup". 0071 */ 0072 QString name() const; 0073 0074 /** 0075 * @return the action's text, as defined by the Name key in the desktop action group 0076 */ 0077 QString text() const; 0078 0079 /** 0080 * @return the action's icon, as defined by the Icon key in the desktop action group 0081 */ 0082 QString icon() const; 0083 0084 /** 0085 * @return the action's exec command, as defined by the Exec key in the desktop action group 0086 */ 0087 QString exec() const; 0088 0089 /** 0090 * Returns whether the action should be suppressed in menus. 0091 * This is useful for having actions with a known name that the code 0092 * looks for explicitly, like Setup and Root for kscreensaver actions, 0093 * and which should not appear in popup menus. 0094 * @return true to suppress this service 0095 */ 0096 bool noDisplay() const; 0097 0098 /** 0099 * Returns whether the action is a separator. 0100 * This is true when the Actions key contains "_SEPARATOR_". 0101 */ 0102 bool isSeparator() const; 0103 0104 /** 0105 * Returns the service that this action comes from 0106 * @since 5.69 0107 */ 0108 KServicePtr service() const; 0109 0110 /** 0111 * Returns the requested property. 0112 * 0113 * @param name the name of the property 0114 * @param type the assumed type of the property 0115 * @return the property, or an invalid QVariant if not found 0116 * @since 5.102 0117 */ 0118 QVariant property(const QString &name, QMetaType::Type type) const; 0119 0120 private: 0121 QSharedDataPointer<KServiceActionPrivate> d; 0122 friend KSERVICE_EXPORT QDataStream &operator>>(QDataStream &str, KServiceAction &act); 0123 friend KSERVICE_EXPORT QDataStream &operator<<(QDataStream &str, const KServiceAction &act); 0124 friend class KService; 0125 KSERVICE_NO_EXPORT void setService(const KServicePtr &service); 0126 }; 0127 0128 KSERVICE_EXPORT QDataStream &operator>>(QDataStream &str, KServiceAction &act); 0129 KSERVICE_EXPORT QDataStream &operator<<(QDataStream &str, const KServiceAction &act); 0130 0131 #endif /* KSERVICEACTION_H */