File indexing completed on 2024-05-05 17:34:14

0001 /* SPDX-FileCopyrightText: 1999-2001 Lubos Lunak <l.lunak@kde.org>
0002    SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz>
0003 
0004    SPDX-License-Identifier: GPL-2.0-only
0005 */
0006 
0007 #include "windows_helper/window_selection_list.h"
0008 
0009 #include <KConfig>
0010 #include <QDebug>
0011 
0012 namespace KHotKeys
0013 {
0014 Windowdef_list::Windowdef_list(const QString &comment_P)
0015     : QList<Windowdef *>()
0016     , _comment(comment_P)
0017 {
0018 }
0019 
0020 Windowdef_list::Windowdef_list(KConfigGroup &cfg_P)
0021     : QList<Windowdef *>()
0022 {
0023     _comment = cfg_P.readEntry("Comment");
0024     int cnt = cfg_P.readEntry("WindowsCount", 0);
0025     for (int i = 0; i < cnt; ++i) {
0026         KConfigGroup windowGroup(cfg_P.config(), cfg_P.name() + QString::number(i));
0027         Windowdef *window = Windowdef::create_cfg_read(windowGroup);
0028         if (window)
0029             append(window);
0030     }
0031 }
0032 
0033 Windowdef_list::~Windowdef_list()
0034 {
0035     qDeleteAll(*this);
0036 }
0037 
0038 const QString &Windowdef_list::comment() const
0039 {
0040     return _comment;
0041 }
0042 
0043 void Windowdef_list::cfg_write(KConfigGroup &cfg_P) const
0044 {
0045     int i = 0;
0046     for (ConstIterator it(begin()); it != end(); ++it, ++i) {
0047         KConfigGroup itGroup(cfg_P.config(), cfg_P.name() + QString::number(i));
0048         (*it)->cfg_write(itGroup);
0049     }
0050     cfg_P.writeEntry("WindowsCount", i);
0051     cfg_P.writeEntry("Comment", comment());
0052 }
0053 
0054 Windowdef_list *Windowdef_list::copy() const
0055 {
0056     Windowdef_list *ret = new Windowdef_list(comment());
0057     for (ConstIterator it(constBegin()); it != constEnd(); ++it) {
0058         qDebug() << "Duplicating " << (*it)->comment();
0059         ret->append((*it)->copy());
0060     }
0061     return ret;
0062 }
0063 
0064 bool Windowdef_list::match(const Window_data &window_P) const
0065 {
0066     if (count() == 0) // CHECKME no windows to match => ok
0067         return true;
0068     for (ConstIterator it(begin()); it != end(); ++it)
0069         if ((*it)->match(window_P))
0070             return true;
0071     return false;
0072 }
0073 
0074 void Windowdef_list::set_comment(const QString &comment)
0075 {
0076     _comment = comment;
0077 }
0078 
0079 } // namespace KHotKeys