KService

kserviceaction.h
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 2007 David Faure <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KSERVICEACTION_H
9 #define KSERVICEACTION_H
10 
11 #include <QSharedDataPointer>
12 #include <QVariant>
13 #include <kservice_export.h>
14 class QVariant;
15 class KServiceActionPrivate;
16 class KService;
17 
18 // we can't include kservice.h, it includes this header...
20 
21 /**
22  * @class KServiceAction kserviceaction.h <KServiceAction>
23  *
24  * Represents an action in a .desktop file
25  * Actions are defined with the config key Actions in the [Desktop Entry]
26  * group, followed by one group per action, as per the desktop entry standard.
27  * @see KService::actions
28  */
29 class KSERVICE_EXPORT KServiceAction
30 {
31 public:
32 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 69)
33  /**
34  * Creates a KServiceAction.
35  * Normally you don't have to do this, KService creates the actions
36  * when parsing the .desktop file.
37  * @deprecated Since 5.69, use the 6-args constructor
38  */
39  KSERVICE_DEPRECATED_VERSION_BELATED(5, 71, 5, 69, "Use the 6-args constructor")
40  KServiceAction(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay = false);
41 #endif
42  /**
43  * Creates a KServiceAction.
44  * Normally you don't have to do this, KService creates the actions
45  * when parsing the .desktop file.
46  * @since 5.69
47  */
48  KServiceAction(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay, const KServicePtr &service);
49  /**
50  * @internal
51  * Needed for operator>>
52  */
54  /**
55  * Destroys a KServiceAction.
56  */
57  ~KServiceAction();
58 
59  /**
60  * Copy constructor
61  */
62  KServiceAction(const KServiceAction &other);
63  /**
64  * Assignment operator
65  */
66  KServiceAction &operator=(const KServiceAction &other);
67 
68  /**
69  * Sets the action's internal data to the given @p userData.
70  */
71  void setData(const QVariant &userData);
72  /**
73  * @return the action's internal data.
74  */
75  QVariant data() const;
76 
77  /**
78  * @return the action's internal name
79  * For instance Actions=Setup;... and the group [Desktop Action Setup]
80  * define an action with the name "Setup".
81  */
82  QString name() const;
83 
84  /**
85  * @return the action's text, as defined by the Name key in the desktop action group
86  */
87  QString text() const;
88 
89  /**
90  * @return the action's icon, as defined by the Icon key in the desktop action group
91  */
92  QString icon() const;
93 
94  /**
95  * @return the action's exec command, as defined by the Exec key in the desktop action group
96  */
97  QString exec() const;
98 
99  /**
100  * Returns whether the action should be suppressed in menus.
101  * This is useful for having actions with a known name that the code
102  * looks for explicitly, like Setup and Root for kscreensaver actions,
103  * and which should not appear in popup menus.
104  * @return true to suppress this service
105  */
106  bool noDisplay() const;
107 
108  /**
109  * Returns whether the action is a separator.
110  * This is true when the Actions key contains "_SEPARATOR_".
111  */
112  bool isSeparator() const;
113 
114  /**
115  * Returns the service that this action comes from
116  * @since 5.69
117  */
118  KServicePtr service() const;
119 
120  /**
121  * Returns the requested property.
122  *
123  * @param name the name of the property
124  * @param type the assumed type of the property
125  * @return the property, or an invalid QVariant if not found
126  * @since 5.102
127  */
128  QVariant property(const QString &name, QMetaType::Type type) const;
129 
130 private:
132  friend KSERVICE_EXPORT QDataStream &operator>>(QDataStream &str, KServiceAction &act);
133  friend KSERVICE_EXPORT QDataStream &operator<<(QDataStream &str, const KServiceAction &act);
134  friend class KService;
135  void setService(const KServicePtr &service);
136 };
137 
138 KSERVICE_EXPORT QDataStream &operator>>(QDataStream &str, KServiceAction &act);
139 KSERVICE_EXPORT QDataStream &operator<<(QDataStream &str, const KServiceAction &act);
140 
141 #endif /* KSERVICEACTION_H */
KCALENDARCORE_EXPORT QDataStream & operator<<(QDataStream &out, const KCalendarCore::Alarm::Ptr &)
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sat Apr 1 2023 03:57:41 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.