KRunner

action.h
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
12namespace KRunner
13{
14class ActionPrivate;
15/**
16 * This class represents an action that will be shown next to a match.
17 * The goal is to make it more reliable, because QIcon::fromTheme which is often needed in a QAction constructor is not thread safe.
18 * Also, it makes the API more consistent with the org.kde.krunner1 DBus interface and forces consumers to set an icon.
19 *
20 * @since 6.0
21 */
22class KRUNNER_EXPORT Action final
23{
24 Q_GADGET
25 /// User-visible text
26 Q_PROPERTY(QString text READ text CONSTANT)
27 /// Source for the icon: Name of the icon from a theme, file path or file URL
28 Q_PROPERTY(QString iconSource READ iconSource CONSTANT)
29public:
30 /**
31 * Constructs a new action
32 * @param id ID which identifies the action uniquely within the context of the respective runner plugin
33 * @param iconSource name for the icon, that can be passed in to QIcon::fromTheme or file path/URL
34 */
35 explicit Action(const QString &id, const QString &iconSource, const QString &text);
36
37 /// Empty constructor creating invalid action
38 Action();
39
40 ~Action();
41
42 /**
43 * Copy constructor
44 * @internal
45 */
46 Action(const KRunner::Action &other);
47
48 Action &operator=(const Action &other);
49
50 /// Check if the action is valid
51 explicit operator bool() const
52 {
53 return !id().isEmpty();
54 }
55
56 bool operator==(const KRunner::Action &other) const
57 {
58 return id() == other.id();
59 }
60
61 QString id() const;
62 QString text() const;
63 QString iconSource() const;
64
65private:
66 std::unique_ptr<ActionPrivate> d;
67};
68
69using Actions = QList<KRunner::Action>;
70}
71
72Q_DECLARE_METATYPE(KRunner::Action)
73#endif
This class represents an action that will be shown next to a match.
Definition action.h:23
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 12:01:02 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.