KService

kserviceaction.cpp
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#include "kserviceaction.h"
9#include "kservice.h"
10#include "ksycoca.h"
11#include "ksycoca_p.h"
12
13#include <QDataStream>
14#include <QVariant>
15
16#include <KConfigGroup>
17
18class KServiceActionPrivate : public QSharedData
19{
20public:
21 KServiceActionPrivate(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay)
22 : m_name(name)
23 , m_text(text)
24 , m_icon(icon)
25 , m_exec(exec)
26 , m_noDisplay(noDisplay)
27 {
28 }
29 QString m_name;
30 QString m_text;
31 QString m_icon;
32 QString m_exec;
33 QVariant m_data;
34 bool m_noDisplay;
35 KServicePtr m_service;
36 // warning keep QDataStream operators in sync if adding data here
37};
38
40 : d(new KServiceActionPrivate(QString(), QString(), QString(), QString(), false))
41{
42}
43
44KServiceAction::KServiceAction(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay, const KServicePtr &service)
45 : d(new KServiceActionPrivate(name, text, icon, exec, noDisplay))
46{
47 d->m_service = service;
48}
49
53
55 : d(other.d)
56{
57}
58
60{
61 d = other.d;
62 return *this;
63}
64
66{
67 return d->m_data;
68}
69
71{
72 d->m_data = data;
73}
74
76{
77 return d->m_name;
78}
79
81{
82 return d->m_text;
83}
84
86{
87 return d->m_icon;
88}
89
91{
92 return d->m_exec;
93}
94
96{
97 return d->m_noDisplay;
98}
99
101{
102 return d->m_name == QLatin1String("_SEPARATOR_");
103}
104
106{
107 return d->m_service;
108}
109
110void KServiceAction::setService(const KServicePtr &service)
111{
112 d->m_service = service;
113}
114
116{
117 KServiceActionPrivate *d = act.d;
118 str >> d->m_name;
119 str >> d->m_text;
120 str >> d->m_icon;
121 str >> d->m_exec;
122 str >> d->m_data;
123 str >> d->m_noDisplay;
124 return str;
125}
126
128{
129 const KServiceActionPrivate *d = act.d;
130 str << d->m_name;
131 str << d->m_text;
132 str << d->m_icon;
133 str << d->m_exec;
134 str << d->m_data;
135 str << d->m_noDisplay;
136 return str;
137}
138
140{
141 const auto dataMap = d->m_data.toMap();
142 auto it = dataMap.constFind(_name);
143 if (it == dataMap.cend() || !it.value().isValid()) {
144 return QVariant(); // No property set.
145 }
146
147 if (type == QMetaType::QString) {
148 return it.value(); // no conversion necessary
149 } else {
150 // All others
151 // For instance properties defined as StringList, like MimeTypes.
152 // XXX This API is accessible only through a friend declaration.
153 return KConfigGroup::convertToQVariant(_name.toUtf8().constData(), it.value().toString().toUtf8(), QVariant(QMetaType(type)));
154 }
155}
Represents an action in a .desktop file Actions are defined with the config key Actions in the [Deskt...
QString text() const
QString name() const
KServiceAction & operator=(const KServiceAction &other)
Assignment operator.
bool isSeparator() const
Returns whether the action is a separator.
QString exec() const
~KServiceAction()
Destroys a KServiceAction.
KServicePtr service() const
Returns the service that this action comes from.
T property(const QString &name) const
Returns the requested property.
QString icon() const
QVariant data() const
void setData(const QVariant &userData)
Sets the action's internal data to the given userData.
bool noDisplay() const
Returns whether the action should be suppressed in menus.
KCALENDARCORE_EXPORT QDataStream & operator>>(QDataStream &in, const KCalendarCore::Alarm::Ptr &)
QString name(StandardShortcut id)
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.