File indexing completed on 2024-04-28 15:29:51

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 #if KSERVICE_ENABLE_DEPRECATED_SINCE(5, 69)
0033     /**
0034      * Creates a KServiceAction.
0035      * Normally you don't have to do this, KService creates the actions
0036      * when parsing the .desktop file.
0037      * @deprecated Since 5.69, use the 6-args constructor
0038      */
0039     KSERVICE_DEPRECATED_VERSION_BELATED(5, 71, 5, 69, "Use the 6-args constructor")
0040     KServiceAction(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay = false);
0041 #endif
0042     /**
0043      * Creates a KServiceAction.
0044      * Normally you don't have to do this, KService creates the actions
0045      * when parsing the .desktop file.
0046      * @since 5.69
0047      */
0048     KServiceAction(const QString &name, const QString &text, const QString &icon, const QString &exec, bool noDisplay, const KServicePtr &service);
0049     /**
0050      * @internal
0051      * Needed for operator>>
0052      */
0053     KServiceAction();
0054     /**
0055      * Destroys a KServiceAction.
0056      */
0057     ~KServiceAction();
0058 
0059     /**
0060      * Copy constructor
0061      */
0062     KServiceAction(const KServiceAction &other);
0063     /**
0064      * Assignment operator
0065      */
0066     KServiceAction &operator=(const KServiceAction &other);
0067 
0068     /**
0069      * Sets the action's internal data to the given @p userData.
0070      */
0071     void setData(const QVariant &userData);
0072     /**
0073      * @return the action's internal data.
0074      */
0075     QVariant data() const;
0076 
0077     /**
0078      * @return the action's internal name
0079      * For instance Actions=Setup;... and the group [Desktop Action Setup]
0080      * define an action with the name "Setup".
0081      */
0082     QString name() const;
0083 
0084     /**
0085      * @return the action's text, as defined by the Name key in the desktop action group
0086      */
0087     QString text() const;
0088 
0089     /**
0090      * @return the action's icon, as defined by the Icon key in the desktop action group
0091      */
0092     QString icon() const;
0093 
0094     /**
0095      * @return the action's exec command, as defined by the Exec key in the desktop action group
0096      */
0097     QString exec() const;
0098 
0099     /**
0100      * Returns whether the action should be suppressed in menus.
0101      * This is useful for having actions with a known name that the code
0102      * looks for explicitly, like Setup and Root for kscreensaver actions,
0103      * and which should not appear in popup menus.
0104      * @return true to suppress this service
0105      */
0106     bool noDisplay() const;
0107 
0108     /**
0109      * Returns whether the action is a separator.
0110      * This is true when the Actions key contains "_SEPARATOR_".
0111      */
0112     bool isSeparator() const;
0113 
0114     /**
0115      * Returns the service that this action comes from
0116      * @since 5.69
0117      */
0118     KServicePtr service() const;
0119 
0120     /**
0121      * Returns the requested property.
0122      *
0123      * @param name the name of the property
0124      * @param type the assumed type of the property
0125      * @return the property, or an invalid QVariant if not found
0126      * @since 5.102
0127      */
0128     QVariant property(const QString &name, QMetaType::Type type) const;
0129 
0130 private:
0131     QSharedDataPointer<KServiceActionPrivate> d;
0132     friend KSERVICE_EXPORT QDataStream &operator>>(QDataStream &str, KServiceAction &act);
0133     friend KSERVICE_EXPORT QDataStream &operator<<(QDataStream &str, const KServiceAction &act);
0134     friend class KService;
0135     KSERVICE_NO_EXPORT void setService(const KServicePtr &service);
0136 };
0137 
0138 KSERVICE_EXPORT QDataStream &operator>>(QDataStream &str, KServiceAction &act);
0139 KSERVICE_EXPORT QDataStream &operator<<(QDataStream &str, const KServiceAction &act);
0140 
0141 #endif /* KSERVICEACTION_H */