File indexing completed on 2024-12-01 13:34:29

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_list.h"
0009 #include "conditions/conditions_visitor.h"
0010 
0011 #include "action_data/action_data.h"
0012 #include "khotkeysglobal.h"
0013 
0014 #include <KConfigGroup>
0015 #include <QDebug>
0016 
0017 namespace KHotKeys
0018 {
0019 Condition_list::Condition_list(KConfigGroup &cfg_P, ActionDataBase *data_P)
0020     : Condition_list_base(cfg_P, nullptr)
0021     , data(data_P)
0022 {
0023     _comment = cfg_P.readEntry("Comment");
0024 }
0025 
0026 Condition_list::Condition_list(const QString &comment_P, ActionDataBase *data_P)
0027     : Condition_list_base(nullptr)
0028     , _comment(comment_P)
0029     , data(data_P)
0030 {
0031 }
0032 
0033 void Condition_list::cfg_write(KConfigGroup &cfg_P) const
0034 {
0035     base::cfg_write(cfg_P);
0036     cfg_P.writeEntry("Comment", comment());
0037 }
0038 
0039 const QString &Condition_list::comment() const
0040 {
0041     return _comment;
0042 }
0043 
0044 Condition_list *Condition_list::copy() const
0045 {
0046     qDebug() << count();
0047 
0048     Condition_list *ret = new Condition_list(comment());
0049     for (ConstIterator it = begin(); it != end(); ++it) {
0050         ret->append((*it)->copy());
0051     }
0052     return ret;
0053 }
0054 
0055 const QString Condition_list::description() const
0056 {
0057     return QString();
0058 }
0059 
0060 bool Condition_list::match() const
0061 {
0062     if (count() == 0) // no conditions to match => ok
0063         return true;
0064     for (ConstIterator it(begin()); it != end(); ++it)
0065         if ((*it)->match()) // OR
0066             return true;
0067     return false;
0068 }
0069 
0070 void Condition_list::set_data(ActionDataBase *data_P)
0071 {
0072     Q_ASSERT(data == nullptr || data == data_P);
0073     data = data_P;
0074 }
0075 
0076 void Condition_list::updated() const
0077 {
0078     if (!khotkeys_active())
0079         return;
0080     data->update_triggers();
0081     //    base::updated(); no need to, doesn't have parent
0082 }
0083 
0084 void Condition_list::visit(ConditionsVisitor *visitor)
0085 {
0086     visitor->visitConditionsList(this);
0087 }
0088 
0089 } // namespace KHotKeys