KAuth

objectdecorator.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2009-2012 Dario Freddi <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KAUTH_OBJECTDECORATOR_H
9 #define KAUTH_OBJECTDECORATOR_H
10 
11 // Qt
12 #include <QObject>
13 // KAuthCore
14 #include <KAuth/Action>
15 // lib
16 #include "kauth_export.h"
17 // Std
18 #include <memory>
19 
20 namespace KAuth
21 {
22 class ObjectDecoratorPrivate;
23 
24 /**
25  * @class ObjectDecorator objectdecorator.h <KAuth/ObjectDecorator>
26  *
27  * @brief A decorator to add auth features to a button or an action
28  *
29  * @author Dario Freddi <[email protected]>
30  */
31 class KAUTH_EXPORT ObjectDecorator : public QObject
32 {
33  Q_OBJECT
34 public:
35  /**
36  * Instantiate a new decorator attached to an object
37  *
38  * @param parent The parent object this decorator will be attached to
39  */
40  explicit ObjectDecorator(QObject *parent);
41 
42  /**
43  * Destructs the decorator
44  */
45  ~ObjectDecorator() override;
46 
47  /**
48  * Returns the action object associated with this decorator,
49  * or an invalid action if it does not have one.
50  *
51  * @returns the KAuth::Action associated with this decorator.
52  */
53  KAuth::Action authAction() const;
54 
55  /**
56  * Sets the action object associated with this decorator
57  *
58  * By setting a KAuth::Action, this decorator will become associated with it, and
59  * whenever the action or button it is attached to gets clicked, it will trigger the
60  * authorization and execution process for the action.
61  * Pass an invalid action to this function to disassociate the decorator.
62  *
63  * @param action the KAuth::Action to associate with this decorator.
64  */
65  void setAuthAction(const KAuth::Action &action);
66 
67  /**
68  * Sets the action object associated with this decorator
69  *
70  * Overloaded member to allow creating the action by name
71  *
72  * @param actionName the name of the action to associate
73  */
74  void setAuthAction(const QString &actionName);
75 
76 Q_SIGNALS:
77  /**
78  * Signal emitted when the action is authorized
79  *
80  * If the decorator needs authorization, whenever the user triggers it,
81  * the authorization process automatically begins.
82  * If it succeeds, this signal is emitted. The KAuth::Action object is provided for convenience
83  * if you have multiple Action objects, but of course it's always the same set with
84  * setAuthAction().
85  *
86  * WARNING: If your button or action needs authorization you should connect eventual slots
87  * processing stuff to this signal, and NOT clicked/triggered. Clicked/triggered will be emitted
88  * even if the user has not been authorized
89  *
90  * @param action The object set with setAuthAction()
91  */
92  void authorized(const KAuth::Action &action);
93 
94 private:
95  friend class ObjectDecoratorPrivate;
96  std::unique_ptr<ObjectDecoratorPrivate> const d;
97 
98  Q_PRIVATE_SLOT(d, void slotActivated())
99  Q_PRIVATE_SLOT(d, void authStatusChanged(KAuth::Action::AuthStatus))
100 };
101 
102 } // namespace KAuth
103 
104 #endif // KAUTH_OBJECTDECORATOR_H
A decorator to add auth features to a button or an action.
AuthStatus
The three values set by authorization methods.
Definition: action.h:82
Definition: action.cpp:18
Class to access, authorize and execute actions.
Definition: action.h:75
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Wed Sep 28 2022 04:09:06 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.