PolkitQt-1

polkitqt1-gui-actionbutton.h
1/*
2 This file is part of the Polkit-qt project
3 SPDX-FileCopyrightText: 2009 Daniel Nicoletti <dantti85-pk@yahoo.com.br>
4 SPDX-FileCopyrightText: 2009 Dario Freddi <drf@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef POLKITQT1_GUI_ACTIONBUTTON_H
10#define POLKITQT1_GUI_ACTIONBUTTON_H
11
12#include "polkitqt1-gui-action.h"
13
14class QAbstractButton;
15
16namespace PolkitQt1
17{
18
19namespace Gui
20{
21
22class ActionButtonPrivate;
23/**
24 * \class ActionButton polkitqt1-gui-actionbutton.h ActionButton
25 * \author Daniel Nicoletti <dantti85-pk@yahoo.com.br>
26 * \author Dario Freddi <drf@kde.org>
27 *
28 * \brief Class used to hold and update a QAbstractButton
29 *
30 * This class allows you to associate QAbstractButtons
31 * (i.e. QPushButton) to a PolicyKit Action. It will update the
32 * button properties according to the PolicyKit Action automatically.
33 *
34 * \note You should connect the activated() signal to receive
35 * a notification when the user clicked the button and gets
36 * permission to perform the given action. If you set 'noEnabled'
37 * to \c true it will be emitted when PolKitResult is NO.
38 */
39class POLKITQT1_GUI_EXPORT ActionButton : public Action
40{
41 Q_OBJECT
42 Q_DECLARE_PRIVATE(ActionButton)
43 Q_DISABLE_COPY(ActionButton)
44
45public:
46 /**
47 * Constructs a new ActionButton. You need to pass this
48 * constructor an existing QAbstractButton, whose properties
49 * will be modified according to the underlying Action
50 * object. As ActionButton inherits from Action, you can
51 * define your button's behavior right through this wrapper.
52 *
53 * \see Action
54 *
55 * \param button the QAbstractButton to associate to this ActionButton
56 * \param actionId the action Id to create the underlying Action
57 * \param parent the parent object
58 */
59 explicit ActionButton(QAbstractButton *button, const QString &actionId = QString(), QObject *parent = nullptr);
60 ~ActionButton() override;
61
62 /**
63 * Sets the button associated to the underlying action.
64 *
65 * \note If you are calling this function, you're probably
66 * changing the button the action is referring to. If this
67 * is the case, please note that Polkit-Qt does not handle
68 * the previous button's memory, so you should take care of
69 * deleting it yourself (if needed). You can retrieve it by
70 * using button()
71 *
72 * \see button
73 *
74 * \param button the new button associated with the underlying action
75 */
76 void setButton(QAbstractButton *button);
77
78 /**
79 * Returns the current button
80 *
81 * \return the button currently associated with the underlying action
82 */
83 QAbstractButton *button() const;
84
85public Q_SLOTS:
86 /**
87 * Connect clicked() signals to this slot. This should be
88 * manually done, as in some cases we might want
89 * to manually call this. Calling this will emit authorized().
90 *
91 * \note This slot is reentrant which is likely to only be a problem
92 * if you are creating an interface to setup PolicyKit policies.
93 * \note If you have a checkbox, connect to its' clicked() signal
94 * to avoid an infinite loop as this function internally calls setChecked().
95 * You can always use the clicked(bool) signal in this class to
96 * connect to here.
97 * \warning if you use this class take care to not call Action::activate
98 * otherwise your checkable buttons won't be properly updated.
99 */
100 bool activate();
101
102Q_SIGNALS:
103 /**
104 * Emitted when the abstract button clicked(bool) signal
105 * is emitted. This allows you to use qobject_cast<ActionButton *>(sender())
106 * in a slot connected to this signal and call activate() on it.
107 *
108 * \note you will normally want to connect this signal
109 * to the activate slot.
110 *
111 * \param button the button that has been clicked
112 * \param checked the checked state, if applicable. Otherwise \c false
113 *
114 */
115 void clicked(QAbstractButton *button, bool checked = false);
116
117protected:
118 ActionButton(ActionButtonPrivate &dd, const QString &actionId, QObject *parent = nullptr);
119
120 ActionButtonPrivate * const d_ptr;
121
122private:
123 Q_PRIVATE_SLOT(d_func(), void updateButton())
124 Q_PRIVATE_SLOT(d_func(), void streamClicked(bool))
125};
126
127}
128
129}
130
131#endif
Class used to hold and update a QAbstractButton.
void clicked(QAbstractButton *button, bool checked=false)
Emitted when the abstract button clicked(bool) signal is emitted.
Class used to manage actions.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:56 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.