File indexing completed on 2024-11-03 11:09:06

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-only
0003     SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org>
0004  */
0005 
0006 #ifndef ACTION_DATA_BASE_H
0007 #define ACTION_DATA_BASE_H
0008 
0009 #include <QObject>
0010 #include <QString>
0011 
0012 class KConfigGroup;
0013 
0014 namespace KHotKeys
0015 {
0016 class ActionDataGroup;
0017 class ActionDataVisitor;
0018 class ActionDataConstVisitor;
0019 class Condition_list;
0020 
0021 /**
0022  * Base class for all actions.
0023  */
0024 class Q_DECL_EXPORT ActionDataBase : public QObject
0025 {
0026     Q_OBJECT
0027 
0028     Q_DISABLE_COPY(ActionDataBase)
0029 
0030 public:
0031     /**
0032      * Create a action data base object.
0033      *
0034      * \param parent  A ActionDataGroup or 0. If provided this action is
0035      *        registered with the group.
0036      * \param name    Name for the object.
0037      * \param comment Comment for the object.
0038      * \param condition Conditions for the object or 0
0039      */
0040     ActionDataBase(ActionDataGroup *parent, const QString &name, const QString &comment, Condition_list *condition);
0041 
0042     /**
0043      * Destructor
0044      */
0045     ~ActionDataBase() override;
0046 
0047     /**
0048      * Visitor pattern
0049      */
0050     virtual void accept(ActionDataVisitor *visitor);
0051     virtual void accept(ActionDataConstVisitor *visitor) const;
0052 
0053     /**
0054      * Get the conditions for this action or 0 if the action has no
0055      * conditions.
0056      */
0057     const Condition_list *conditions() const;
0058     Condition_list *conditions();
0059 
0060     /**
0061      * Prepare this action for complete removal.
0062      */
0063     virtual void aboutToBeErased() = 0;
0064 
0065     /**
0066      * Get the \c ActionDataGroup this object belongs to or 0 if it
0067      * does not belong to a group.
0068      */
0069     ActionDataGroup *parent() const;
0070 
0071     /**
0072      * \todo document this method
0073      */
0074     virtual void update_triggers() = 0;
0075 
0076     /**
0077      * Check if the conditions match.
0078      */
0079     bool conditions_match() const;
0080 
0081     //@{
0082     /**
0083      * Name for the action
0084      */
0085     QString name() const;
0086     void set_name(const QString &name);
0087     //@}
0088 
0089     //@{
0090     /**
0091      * A comment for this action.
0092      */
0093     QString comment() const;
0094     void set_comment(const QString &comment);
0095     //@}
0096 
0097     /**
0098      */
0099     void setImportId(const QString &);
0100     QString importId() const;
0101 
0102     /**
0103      */
0104     void setAllowMerging(bool);
0105     bool allowMerging() const;
0106 
0107     /**
0108      * Is the action enabled?
0109      *
0110      * The action has different states.
0111      *
0112      * Absolute State:  Has the action an enabled/disabled state?
0113      * Effective State: Even if the action is enabled it's effective state
0114      *                  is disabled if it's parent is disabled.
0115      */
0116     enum IgnoreParent {
0117         Ignore,
0118         DontIgnore,
0119     };
0120     bool isEnabled(IgnoreParent ip = DontIgnore) const;
0121 
0122     /**
0123      * Enable the action.
0124      */
0125     void enable();
0126     void disable();
0127     //@}
0128 
0129     /**
0130      * See if it the config group is enabled.
0131      */
0132     static bool cfg_is_enabled(const KConfigGroup &cfg);
0133 
0134     //! Set the list of condition for this element
0135     void set_conditions(Condition_list *conditions);
0136 
0137 protected:
0138     virtual void doEnable() = 0;
0139 
0140     virtual void doDisable() = 0;
0141 
0142 private:
0143     friend class ActionDataGroup;
0144 
0145     //! The parent or nullptr
0146     ActionDataGroup *_parent;
0147 
0148     //! List of conditions for this element
0149     Condition_list *_conditions;
0150 
0151     //! Name for element
0152     QString _name;
0153 
0154     //! The comment for this element
0155     QString _comment;
0156 
0157     //! If this element is enabled
0158     bool _enabled; // is not really important, only used in conf. module and when reading cfg. file
0159 
0160     //! The importId from the file we were imported
0161     QString _importId;
0162 
0163     //! Is it allowed to merge this directory with others. Used when
0164     // exporting and importing the directory
0165     bool _allowMerging;
0166 };
0167 
0168 } // namespace KHotKeys
0169 
0170 #endif // ACTION_DATA_BASE_H