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/active_window_condition.h"
0009 
0010 #include "khotkeysglobal.h"
0011 #include "windows_handler.h"
0012 #include "windows_helper/window_selection_list.h"
0013 
0014 #include <KConfig>
0015 #include <KConfigGroup>
0016 #include <QDebug>
0017 
0018 namespace KHotKeys
0019 {
0020 Active_window_condition::Active_window_condition(KConfigGroup &cfg_P, Condition_list_base *parent_P)
0021     : Condition(cfg_P, parent_P)
0022 {
0023     KConfigGroup windowConfig(cfg_P.config(), cfg_P.name() + "Window");
0024     _window = new Windowdef_list(windowConfig);
0025     init();
0026     set_match();
0027 }
0028 
0029 Active_window_condition::Active_window_condition(Windowdef_list *window_P, Condition_list_base *parent_P)
0030     : Condition(parent_P)
0031     , _window(window_P)
0032 {
0033     init();
0034     set_match();
0035 }
0036 
0037 Active_window_condition::~Active_window_condition()
0038 {
0039     disconnect(windows_handler, nullptr, this, nullptr);
0040     delete _window;
0041 }
0042 
0043 void Active_window_condition::active_window_changed(WId)
0044 {
0045     set_match();
0046 }
0047 
0048 void Active_window_condition::cfg_write(KConfigGroup &cfg_P) const
0049 {
0050     base::cfg_write(cfg_P);
0051     KConfigGroup windowConfig(cfg_P.config(), cfg_P.name() + "Window");
0052     window()->cfg_write(windowConfig);
0053     cfg_P.writeEntry("Type", "ACTIVE_WINDOW"); // overwrites value set in base::cfg_write()
0054 }
0055 
0056 Active_window_condition *Active_window_condition::copy() const
0057 {
0058     qDebug();
0059     return new Active_window_condition(window()->copy());
0060 }
0061 
0062 const QString Active_window_condition::description() const
0063 {
0064     return i18n("Active window: ") + window()->comment();
0065 }
0066 
0067 void Active_window_condition::init()
0068 {
0069     connect(windows_handler, SIGNAL(active_window_changed(WId)), this, SLOT(active_window_changed(WId)));
0070 }
0071 
0072 bool Active_window_condition::match() const
0073 {
0074     return is_match;
0075 }
0076 
0077 void Active_window_condition::set_match()
0078 {
0079     is_match = window()->match(Window_data(windows_handler->active_window()));
0080     updated();
0081 }
0082 
0083 const Windowdef_list *Active_window_condition::window() const
0084 {
0085     return _window;
0086 }
0087 
0088 Windowdef_list *Active_window_condition::window()
0089 {
0090     return _window;
0091 }
0092 
0093 } // namespace KHotKeys