File indexing completed on 2024-05-05 17:34:12
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-only 0003 SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org> 0004 */ 0005 0006 #include "action_data_base.h" 0007 0008 #include "action_data/action_data_group.h" 0009 #include "action_data/action_data_visitor.h" 0010 0011 #include "conditions/conditions_list.h" 0012 0013 #include <QDebug> 0014 #include <kconfiggroup.h> 0015 0016 namespace KHotKeys 0017 { 0018 ActionDataBase::ActionDataBase(ActionDataGroup *parent_P, const QString &name_P, const QString &comment_P, Condition_list *conditions_P) 0019 : _parent(parent_P) 0020 , _conditions(conditions_P) 0021 , _name(name_P) 0022 , _comment(comment_P) 0023 , _enabled(false) 0024 , _importId() 0025 , _allowMerging(false) 0026 { 0027 if (parent()) 0028 parent()->add_child(this); 0029 0030 if (!_conditions) { 0031 _conditions = new Condition_list(QString(), this); 0032 } else { 0033 _conditions->set_data(this); 0034 } 0035 } 0036 0037 ActionDataBase::~ActionDataBase() 0038 { 0039 if (parent()) 0040 parent()->remove_child(this); 0041 delete _conditions; 0042 } 0043 0044 void ActionDataBase::accept(ActionDataVisitor *visitor) 0045 { 0046 visitor->visitActionDataBase(this); 0047 } 0048 0049 void ActionDataBase::accept(ActionDataConstVisitor *visitor) const 0050 { 0051 visitor->visitActionDataBase(this); 0052 } 0053 0054 bool ActionDataBase::cfg_is_enabled(const KConfigGroup &cfg_P) 0055 { 0056 return cfg_P.readEntry("Enabled", false); 0057 } 0058 0059 bool ActionDataBase::allowMerging() const 0060 { 0061 return _allowMerging; 0062 } 0063 0064 QString ActionDataBase::comment() const 0065 { 0066 return _comment; 0067 } 0068 0069 const Condition_list *ActionDataBase::conditions() const 0070 { 0071 return _conditions; 0072 } 0073 0074 Condition_list *ActionDataBase::conditions() 0075 { 0076 return _conditions; 0077 } 0078 0079 bool ActionDataBase::conditions_match() const 0080 { 0081 return (conditions() ? conditions()->match() : true) && (parent() ? parent()->conditions_match() : true); 0082 } 0083 0084 bool ActionDataBase::isEnabled(IgnoreParent ip) const 0085 { 0086 if (ip == Ignore) 0087 return _enabled; 0088 else 0089 return _enabled && (parent() == 0 || parent()->isEnabled()); 0090 } 0091 0092 QString ActionDataBase::name() const 0093 { 0094 return _name; 0095 } 0096 0097 ActionDataGroup *ActionDataBase::parent() const 0098 { 0099 return _parent; 0100 } 0101 0102 void ActionDataBase::setAllowMerging(bool allowMerging) 0103 { 0104 _allowMerging = allowMerging; 0105 } 0106 0107 void ActionDataBase::set_comment(const QString &comment) 0108 { 0109 _comment = comment; 0110 } 0111 0112 void ActionDataBase::disable() 0113 { 0114 if (!_enabled) 0115 return; 0116 0117 _enabled = false; 0118 doDisable(); 0119 } 0120 0121 void ActionDataBase::enable() 0122 { 0123 if (_enabled) 0124 return; 0125 0126 _enabled = true; 0127 0128 // Enable only if the parent is enabled too 0129 if (isEnabled()) 0130 // FIXME: let doEnable decide if it makes sense to enable (No trigger 0131 // .... ) 0132 doEnable(); 0133 } 0134 0135 QString ActionDataBase::importId() const 0136 { 0137 return _importId; 0138 } 0139 0140 void ActionDataBase::set_name(const QString &name_P) 0141 { 0142 _name = name_P; 0143 } 0144 0145 void ActionDataBase::set_conditions(Condition_list *conditions) 0146 { 0147 if (_conditions) { 0148 delete _conditions; 0149 } 0150 0151 _conditions = conditions; 0152 } 0153 0154 void ActionDataBase::setImportId(const QString &id) 0155 { 0156 _importId = id; 0157 } 0158 0159 } // namespace KHotKeys 0160 0161 #include "moc_action_data_base.cpp"