File indexing completed on 2024-12-08 13:18:52

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 "triggers.h"
0009 
0010 #include <KConfig>
0011 #include <KConfigGroup>
0012 
0013 namespace KHotKeys
0014 {
0015 Trigger_list::Trigger_list(const QString &comment_P)
0016     : QList<Trigger *>()
0017     , _comment(comment_P)
0018 {
0019 }
0020 
0021 Trigger_list::~Trigger_list()
0022 {
0023     while (!isEmpty()) {
0024         delete takeFirst();
0025     }
0026 }
0027 
0028 void Trigger_list::aboutToBeErased()
0029 {
0030     QListIterator<Trigger *> it(*this);
0031     while (it.hasNext()) {
0032         it.next()->aboutToBeErased();
0033     }
0034 }
0035 
0036 void Trigger_list::activate(bool activate_P)
0037 {
0038     for (Trigger_list::Iterator it = begin(); it != end(); ++it) {
0039         (*it)->activate(activate_P);
0040     }
0041 }
0042 
0043 void Trigger_list::cfg_write(KConfigGroup &cfg_P) const
0044 {
0045     cfg_P.writeEntry("Comment", comment());
0046     int i = 0;
0047     for (Trigger_list::ConstIterator it = begin(); it != end(); ++it) {
0048         KConfigGroup triggerConfig(cfg_P.config(), cfg_P.name() + QString::number(i++));
0049         (*it)->cfg_write(triggerConfig);
0050     }
0051     cfg_P.writeEntry("TriggersCount", i);
0052 }
0053 
0054 const QString Trigger_list::comment() const
0055 {
0056     return _comment;
0057 }
0058 
0059 Trigger_list *Trigger_list::copy(ActionData *data_P) const
0060 {
0061     Trigger_list *ret = new Trigger_list(comment());
0062     for (Trigger_list::ConstIterator it = begin(); it != end(); ++it) {
0063         ret->append((*it)->copy(data_P));
0064     }
0065     return ret;
0066 }
0067 
0068 void Trigger_list::set_comment(const QString &comment)
0069 {
0070     _comment = comment;
0071 }
0072 
0073 void Trigger_list::disable()
0074 {
0075     QListIterator<Trigger *> it(*this);
0076     while (it.hasNext()) {
0077         it.next()->disable();
0078     }
0079 }
0080 
0081 void Trigger_list::enable()
0082 {
0083     QListIterator<Trigger *> it(*this);
0084     while (it.hasNext()) {
0085         it.next()->enable();
0086     }
0087 }
0088 
0089 } // namespace KHotKeys