| 1 | // SPDX-FileCopyrightText: 2023 Alexander Lohnau <alexander.lohnau@gmx.de> |
| 2 | // SPDX-License-Identifier: LGPL-2.0-or-later |
| 3 | #ifndef KRUNNER_ACTION_H |
| 4 | #define KRUNNER_ACTION_H |
| 5 | |
| 6 | #include "krunner_export.h" |
| 7 | |
| 8 | #include <QMetaType> |
| 9 | #include <QString> |
| 10 | #include <memory> |
| 11 | |
| 12 | namespace KRunner |
| 13 | { |
| 14 | class ActionPrivate; |
| 15 | /*! |
| 16 | * \class KRunner::Action |
| 17 | * \inheaderfile KRunner/Action |
| 18 | * \inmodule KRunner |
| 19 | * |
| 20 | * \brief This class represents an action that will be shown next to a match. |
| 21 | * |
| 22 | * The goal is to make it more reliable, because QIcon::fromTheme which is often needed in a QAction constructor is not thread safe. |
| 23 | * Also, it makes the API more consistent with the org.kde.krunner1 DBus interface and forces consumers to set an icon. |
| 24 | * |
| 25 | * \since 6.0 |
| 26 | */ |
| 27 | class KRUNNER_EXPORT Action final |
| 28 | { |
| 29 | Q_GADGET |
| 30 | /*! |
| 31 | * \property KRunner::Action::text |
| 32 | * User-visible text |
| 33 | */ |
| 34 | Q_PROPERTY(QString text READ text CONSTANT) |
| 35 | /*! |
| 36 | * \property KRunner::Action::iconSource |
| 37 | * Source for the icon: Name of the icon from a theme, file path or file URL |
| 38 | */ |
| 39 | Q_PROPERTY(QString iconSource READ iconSource CONSTANT) |
| 40 | public: |
| 41 | /*! |
| 42 | * Constructs a new action |
| 43 | * |
| 44 | * \a id ID which identifies the action uniquely within the context of the respective runner plugin |
| 45 | * |
| 46 | * \a iconSource name for the icon, that can be passed in to QIcon::fromTheme or file path/URL |
| 47 | */ |
| 48 | explicit Action(const QString &id, const QString &iconSource, const QString &text); |
| 49 | |
| 50 | /*! |
| 51 | * Empty constructor creating invalid action |
| 52 | */ |
| 53 | Action(); |
| 54 | |
| 55 | ~Action(); |
| 56 | |
| 57 | Action(const KRunner::Action &other); |
| 58 | |
| 59 | Action &operator=(const Action &other); |
| 60 | |
| 61 | /*! |
| 62 | * Check if the action is valid |
| 63 | */ |
| 64 | explicit operator bool() const |
| 65 | { |
| 66 | return !id().isEmpty(); |
| 67 | } |
| 68 | |
| 69 | bool operator==(const KRunner::Action &other) const |
| 70 | { |
| 71 | return id() == other.id(); |
| 72 | } |
| 73 | |
| 74 | QString id() const; |
| 75 | QString text() const; |
| 76 | QString iconSource() const; |
| 77 | |
| 78 | private: |
| 79 | std::unique_ptr<ActionPrivate> d; |
| 80 | }; |
| 81 | |
| 82 | using Actions = QList<KRunner::Action>; |
| 83 | } |
| 84 | |
| 85 | Q_DECLARE_METATYPE(KRunner::Action) |
| 86 | #endif |
| 87 | |