File indexing completed on 2024-12-01 13:34:28
0001 /* 0002 SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org> 0003 SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz> 0004 0005 SPDX-License-Identifier: LGPL-2.0-only 0006 */ 0007 0008 #include "conditions/conditions.h" 0009 0010 #include "conditions/active_window_condition.h" 0011 #include "conditions/conditions_visitor.h" 0012 #include "conditions/existing_window_condition.h" 0013 0014 #include <KConfigGroup> 0015 #include <QDebug> 0016 0017 namespace KHotKeys 0018 { 0019 Condition::Condition(Condition_list_base *parent) 0020 : _parent(nullptr) 0021 { 0022 if (parent) { 0023 parent->append(this); 0024 Q_ASSERT(_parent); 0025 } 0026 } 0027 0028 Condition::Condition(KConfigGroup &, Condition_list_base *parent) 0029 : _parent(nullptr) 0030 { 0031 if (parent) { 0032 parent->append(this); 0033 Q_ASSERT(_parent); 0034 } 0035 } 0036 0037 Condition::~Condition() 0038 { 0039 if (_parent) 0040 _parent->removeAll(this); 0041 } 0042 0043 void Condition::cfg_write(KConfigGroup &cfg_P) const 0044 { 0045 cfg_P.writeEntry("Type", "ERROR"); 0046 } 0047 0048 Condition *Condition::create_cfg_read(KConfigGroup &cfg_P, Condition_list_base *parent_P) 0049 { 0050 QString type = cfg_P.readEntry("Type"); 0051 if (type == "ACTIVE_WINDOW") 0052 return new Active_window_condition(cfg_P, parent_P); 0053 if (type == "EXISTING_WINDOW") 0054 return new Existing_window_condition(cfg_P, parent_P); 0055 if (type == "NOT") 0056 return new Not_condition(cfg_P, parent_P); 0057 if (type == "AND") 0058 return new And_condition(cfg_P, parent_P); 0059 if (type == "OR") 0060 return new Or_condition(cfg_P, parent_P); 0061 qWarning() << "Unknown Condition type read from cfg file\n"; 0062 return nullptr; 0063 } 0064 0065 const Condition_list_base *Condition::parent() const 0066 { 0067 return _parent; 0068 } 0069 0070 Condition_list_base *Condition::parent() 0071 { 0072 return _parent; 0073 } 0074 0075 void Condition::reparent(Condition_list_base *parent) 0076 { 0077 if (_parent == parent) 0078 return; 0079 0080 if (_parent) 0081 _parent->removeAll(this); 0082 _parent = parent; 0083 if (_parent) 0084 _parent->append(this); 0085 } 0086 0087 void Condition::updated() const 0088 { 0089 if (!khotkeys_active() || !_parent) { 0090 return; 0091 } 0092 0093 _parent->updated(); 0094 } 0095 0096 void Condition::visit(ConditionsVisitor *visitor) 0097 { 0098 visitor->visitCondition(this); 0099 } 0100 0101 } // namespace KHotKeys