KService

kserviceaction.h
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
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#include <kserviceconversioncheck_p.h>
15class QVariant;
16class KServiceActionPrivate;
17class KService;
18
19// we can't include kservice.h, it includes this header...
21
22/**
23 * @class KServiceAction kserviceaction.h <KServiceAction>
24 *
25 * Represents an action in a .desktop file
26 * Actions are defined with the config key Actions in the [Desktop Entry]
27 * group, followed by one group per action, as per the desktop entry standard.
28 * @see KService::actions
29 */
30class KSERVICE_EXPORT KServiceAction
31{
32public:
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 * @since 5.69
38 */
39 KServiceAction(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay, const KServicePtr &service);
40 /**
41 * @internal
42 * Needed for operator>>
43 */
45 /**
46 * Destroys a KServiceAction.
47 */
49
50 /**
51 * Copy constructor
52 */
53 KServiceAction(const KServiceAction &other);
54 /**
55 * Assignment operator
56 */
57 KServiceAction &operator=(const KServiceAction &other);
58
59 /**
60 * Sets the action's internal data to the given @p userData.
61 */
62 void setData(const QVariant &userData);
63 /**
64 * @return the action's internal data.
65 */
66 QVariant data() const;
67
68 /**
69 * @return the action's internal name
70 * For instance Actions=Setup;... and the group [Desktop Action Setup]
71 * define an action with the name "Setup".
72 */
73 QString name() const;
74
75 /**
76 * @return the action's text, as defined by the Name key in the desktop action group
77 */
78 QString text() const;
79
80 /**
81 * @return the action's icon, as defined by the Icon key in the desktop action group
82 */
83 QString icon() const;
84
85 /**
86 * @return the action's exec command, as defined by the Exec key in the desktop action group
87 */
88 QString exec() const;
89
90 /**
91 * Returns whether the action should be suppressed in menus.
92 * This is useful for having actions with a known name that the code
93 * looks for explicitly, like Setup and Root for kscreensaver actions,
94 * and which should not appear in popup menus.
95 * @return true to suppress this service
96 */
97 bool noDisplay() const;
98
99 /**
100 * Returns whether the action is a separator.
101 * This is true when the Actions key contains "_SEPARATOR_".
102 */
103 bool isSeparator() const;
104
105 /**
106 * Returns the service that this action comes from
107 * @since 5.69
108 */
109 KServicePtr service() const;
110
111 /**
112 * Returns the requested property.
113 *
114 * @tparam T the type of the requested property
115 * @param name the name of the requested property
116 * @return the property
117 * @since 6.0
118 */
119 template<typename T>
120 T property(const QString &name) const
121 {
122 KServiceConversionCheck::to_QVariant<T>();
123 return property(name, static_cast<QMetaType::Type>(qMetaTypeId<T>())).value<T>();
124 }
125
126private:
128 friend KSERVICE_EXPORT QDataStream &operator>>(QDataStream &str, KServiceAction &act);
129 friend KSERVICE_EXPORT QDataStream &operator<<(QDataStream &str, const KServiceAction &act);
130 friend class KService;
131 KSERVICE_NO_EXPORT void setService(const KServicePtr &service);
132
133 QVariant property(const QString &_name, QMetaType::Type type) const;
134};
135
138
139#endif /* KSERVICEACTION_H */
Represents an action in a .desktop file Actions are defined with the config key Actions in the [Deskt...
T property(const QString &name) const
Returns the requested property.
Represents an installed application.
Definition kservice.h:44
T property(const QString &name) const
Returns the requested property.
Definition kservice.h:321
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:40 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.