File indexing completed on 2024-04-28 15:18:47

0001 /*
0002     This file is part of the KDE libraries
0003     SPDX-FileCopyrightText: 2009-2012 Dario Freddi <drf@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KAUTH_OBJECTDECORATOR_H
0009 #define KAUTH_OBJECTDECORATOR_H
0010 
0011 // Qt
0012 #include <QObject>
0013 // KAuthCore
0014 #include <KAuth/Action>
0015 // lib
0016 #include "kauth_export.h"
0017 // Std
0018 #include <memory>
0019 
0020 namespace KAuth
0021 {
0022 class ObjectDecoratorPrivate;
0023 
0024 /**
0025  * @class ObjectDecorator objectdecorator.h <KAuth/ObjectDecorator>
0026  *
0027  * @brief A decorator to add auth features to a button or an action
0028  *
0029  * @author Dario Freddi <drf@kde.org>
0030  */
0031 class KAUTH_EXPORT ObjectDecorator : public QObject
0032 {
0033     Q_OBJECT
0034 public:
0035     /**
0036      * Instantiate a new decorator attached to an object
0037      *
0038      * @param parent The parent object this decorator will be attached to
0039      */
0040     explicit ObjectDecorator(QObject *parent);
0041 
0042     /**
0043      * Destructs the decorator
0044      */
0045     ~ObjectDecorator() override;
0046 
0047     /**
0048      * Returns the action object associated with this decorator,
0049      * or an invalid action if it does not have one.
0050      *
0051      * @returns the KAuth::Action associated with this decorator.
0052      */
0053     KAuth::Action authAction() const;
0054 
0055     /**
0056      * Sets the action object associated with this decorator
0057      *
0058      * By setting a KAuth::Action, this decorator will become associated with it, and
0059      * whenever the action or button it is attached to gets clicked, it will trigger the
0060      * authorization and execution process for the action.
0061      * Pass an invalid action to this function to disassociate the decorator.
0062      *
0063      * @param action the KAuth::Action to associate with this decorator.
0064      */
0065     void setAuthAction(const KAuth::Action &action);
0066 
0067     /**
0068      * Sets the action object associated with this decorator
0069      *
0070      * Overloaded member to allow creating the action by name
0071      *
0072      * @param actionName the name of the action to associate
0073      */
0074     void setAuthAction(const QString &actionName);
0075 
0076 Q_SIGNALS:
0077     /**
0078      * Signal emitted when the action is authorized
0079      *
0080      * If the decorator needs authorization, whenever the user triggers it,
0081      * the authorization process automatically begins.
0082      * If it succeeds, this signal is emitted. The KAuth::Action object is provided for convenience
0083      * if you have multiple Action objects, but of course it's always the same set with
0084      * setAuthAction().
0085      *
0086      * WARNING: If your button or action needs authorization you should connect eventual slots
0087      * processing stuff to this signal, and NOT clicked/triggered. Clicked/triggered will be emitted
0088      * even if the user has not been authorized
0089      *
0090      * @param action The object set with setAuthAction()
0091      */
0092     void authorized(const KAuth::Action &action);
0093 
0094 private:
0095     friend class ObjectDecoratorPrivate;
0096     std::unique_ptr<ObjectDecoratorPrivate> const d;
0097 
0098     Q_PRIVATE_SLOT(d, void slotActivated())
0099     Q_PRIVATE_SLOT(d, void authStatusChanged(KAuth::Action::AuthStatus))
0100 };
0101 
0102 } // namespace KAuth
0103 
0104 #endif // KAUTH_OBJECTDECORATOR_H