1
/* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
3
This library is free software; you can redistribute it and/or
4
modify it under the terms of the GNU Library General Public
5
License as published by the Free Software Foundation; either
6
version 2 of the License, or (at your option) any later version.
8
This library is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
Library General Public License for more details.
13
You should have received a copy of the GNU Library General Public License
14
along with this library; see the file COPYING.LIB. If not, write to
15
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
Boston, MA 02110-1301, USA.
19
#include "window_definition_widget.h"
20
#include "ui_window_definition_widget.h"
22
#include "windows_handler.h"
23
#include "helper_widgets/window_selector.h"
24
#include "windows_helper/window_selection_rules.h"
29
WindowDefinitionWidget::WindowDefinitionWidget(KHotKeys::Windowdef_simple *windowdef, QWidget *parent)
30
: HotkeysWidgetIFace(parent)
31
,ui(new Ui::WindowDefinitionWidget)
32
,_windowdef(windowdef)
35
connect(ui->window_class_combo, SIGNAL(currentIndexChanged(int)),
36
SLOT(slotWindowClassChanged(int)));
37
connect(ui->window_title_combo, SIGNAL(currentIndexChanged(int)),
38
SLOT(slotWindowTitleChanged(int)));
39
connect(ui->window_role_combo, SIGNAL(currentIndexChanged(int)),
40
SLOT(slotWindowRoleChanged(int)));
41
connect(ui->autodetect, SIGNAL(clicked()),
42
SLOT(slotAutoDetect()));
44
// user changes -> isChanged for all others
46
ui->comment, SIGNAL(textChanged(QString)),
47
_changedSignals, SLOT(map()) );
48
_changedSignals->setMapping(ui->comment, "text" );
51
ui->window_class, SIGNAL(textChanged(QString)),
52
_changedSignals, SLOT(map()) );
53
_changedSignals->setMapping(ui->window_class, "window_class" );
56
ui->window_role, SIGNAL(textChanged(QString)),
57
_changedSignals, SLOT(map()) );
58
_changedSignals->setMapping(ui->window_role, "window_role" );
61
ui->window_title, SIGNAL(textChanged(QString)),
62
_changedSignals, SLOT(map()) );
63
_changedSignals->setMapping(ui->window_title, "window_title" );
66
ui->type_dialog, SIGNAL(toggled(bool)),
67
_changedSignals, SLOT(map()) );
68
_changedSignals->setMapping(ui->type_dialog, "window_type_dialog" );
71
ui->type_dock, SIGNAL(toggled(bool)),
72
_changedSignals, SLOT(map()) );
73
_changedSignals->setMapping(ui->type_dock, "window_type_dock" );
76
ui->type_desktop, SIGNAL(toggled(bool)),
77
_changedSignals, SLOT(map()) );
78
_changedSignals->setMapping(ui->type_desktop, "window_type_desktop" );
81
ui->type_normal, SIGNAL(toggled(bool)),
82
_changedSignals, SLOT(map()) );
83
_changedSignals->setMapping(ui->type_normal, "window_type_normal" );
87
WindowDefinitionWidget::~WindowDefinitionWidget()
91
void WindowDefinitionWidget::doCopyFromObject()
93
ui->comment->setText(_windowdef->comment());
94
ui->window_class->setText(_windowdef->wclass());
95
ui->window_class_combo->setCurrentIndex(_windowdef->wclass_match_type());
96
ui->window_role->setText(_windowdef->role());
97
ui->window_role_combo->setCurrentIndex(_windowdef->role_match_type());
98
ui->window_title->setText(_windowdef->title());
99
ui->window_title_combo->setCurrentIndex(_windowdef->title_match_type());
100
ui->type_desktop->setChecked(
101
_windowdef->type_match(KHotKeys::Windowdef_simple::WINDOW_TYPE_DESKTOP));
102
ui->type_dialog->setChecked(
103
_windowdef->type_match(KHotKeys::Windowdef_simple::WINDOW_TYPE_DIALOG));
104
ui->type_dock->setChecked(
105
_windowdef->type_match(KHotKeys::Windowdef_simple::WINDOW_TYPE_DOCK));
106
ui->type_normal->setChecked(
107
_windowdef->type_match(KHotKeys::Windowdef_simple::WINDOW_TYPE_NORMAL));
111
void WindowDefinitionWidget::doCopyToObject()
113
_windowdef->set_comment(ui->comment->text());
114
_windowdef->set_wclass(ui->window_class->text());
115
_windowdef->set_wclass_match_type(static_cast<KHotKeys::Windowdef_simple::substr_type_t>(ui->window_class_combo->currentIndex()));
116
_windowdef->set_role(ui->window_role->text());
117
_windowdef->set_role_match_type(static_cast<KHotKeys::Windowdef_simple::substr_type_t>(ui->window_role_combo->currentIndex()));
118
_windowdef->set_title(ui->window_title->text());
119
_windowdef->set_title_match_type(static_cast<KHotKeys::Windowdef_simple::substr_type_t>(ui->window_title_combo->currentIndex()));
121
if (ui->type_desktop->isChecked())
122
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_DESKTOP;
123
if (ui->type_dialog->isChecked())
124
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_DIALOG;
125
if (ui->type_dock->isChecked())
126
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_DOCK;
127
if (ui->type_normal->isChecked())
128
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_NORMAL;
129
_windowdef->set_window_types(types);
133
bool WindowDefinitionWidget::isChanged() const
135
if ( _windowdef->comment() != ui->comment->text()
136
|| _windowdef->wclass() != ui->window_class->text()
137
|| _windowdef->wclass_match_type() != ui->window_class_combo->currentIndex()
138
|| _windowdef->role() != ui->window_role->text()
139
|| _windowdef->role_match_type() != ui->window_role_combo->currentIndex()
140
|| _windowdef->title() != ui->window_title->text()
141
|| _windowdef->title_match_type() != ui->window_title_combo->currentIndex())
147
if (ui->type_desktop->isChecked())
148
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_DESKTOP;
149
if (ui->type_dialog->isChecked())
150
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_DIALOG;
151
if (ui->type_dock->isChecked())
152
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_DOCK;
153
if (ui->type_normal->isChecked())
154
types |= KHotKeys::Windowdef_simple::WINDOW_TYPE_NORMAL;
155
kDebug() << _windowdef->window_types() << types;
156
return _windowdef->window_types() != types;
160
void WindowDefinitionWidget::slotAutoDetect()
162
KHotKeys::WindowSelector* sel = new KHotKeys::WindowSelector( this, SLOT( slotWindowSelected( WId )));
167
void WindowDefinitionWidget::slotWindowClassChanged(int index)
169
ui->window_class->setEnabled(index!=0);
170
slotChanged("window_class");
174
void WindowDefinitionWidget::slotWindowRoleChanged(int index)
176
ui->window_role->setEnabled(index!=0);
177
slotChanged("window_role");
181
void WindowDefinitionWidget::slotWindowSelected(WId window)
185
KHotKeys::Window_data data( window );
186
ui->window_title->setText( data.title );
187
ui->window_role->setText( data.role );
188
ui->window_class->setText( data.wclass );
189
ui->type_normal->setChecked( data.type == NET::Normal );
190
ui->type_dialog->setChecked( data.type == NET::Dialog );
191
ui->type_dock->setChecked( data.type == NET::Dock );
192
ui->type_desktop->setChecked( data.type == NET::Desktop );
197
void WindowDefinitionWidget::slotWindowTitleChanged(int index)
199
ui->window_title->setEnabled(index!=0);
200
slotChanged("window_title");
204
#include "moc_window_definition_widget.cpp"