~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to khotkeys/kcm_hotkeys/helper_widgets/window_definition_widget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2008 Michael Jansen <kde@michael-jansen.biz>
 
2
 
 
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.
 
7
 
 
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.
 
12
 
 
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.
 
17
*/
 
18
 
 
19
#include "window_definition_widget.h"
 
20
#include "ui_window_definition_widget.h"
 
21
 
 
22
#include "windows_handler.h"
 
23
#include "helper_widgets/window_selector.h"
 
24
#include "windows_helper/window_selection_rules.h"
 
25
 
 
26
#include <KDebug>
 
27
 
 
28
 
 
29
WindowDefinitionWidget::WindowDefinitionWidget(KHotKeys::Windowdef_simple *windowdef, QWidget *parent)
 
30
    :   HotkeysWidgetIFace(parent)
 
31
        ,ui(new Ui::WindowDefinitionWidget)
 
32
        ,_windowdef(windowdef)
 
33
    {
 
34
    ui->setupUi(this);
 
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()));
 
43
 
 
44
    // user changes -> isChanged for all others
 
45
    connect(
 
46
            ui->comment, SIGNAL(textChanged(QString)),
 
47
            _changedSignals, SLOT(map()) );
 
48
    _changedSignals->setMapping(ui->comment, "text" );
 
49
 
 
50
    connect(
 
51
            ui->window_class, SIGNAL(textChanged(QString)),
 
52
            _changedSignals, SLOT(map()) );
 
53
    _changedSignals->setMapping(ui->window_class, "window_class" );
 
54
 
 
55
    connect(
 
56
            ui->window_role, SIGNAL(textChanged(QString)),
 
57
            _changedSignals, SLOT(map()) );
 
58
    _changedSignals->setMapping(ui->window_role, "window_role" );
 
59
 
 
60
    connect(
 
61
            ui->window_title, SIGNAL(textChanged(QString)),
 
62
            _changedSignals, SLOT(map()) );
 
63
    _changedSignals->setMapping(ui->window_title, "window_title" );
 
64
 
 
65
    connect(
 
66
            ui->type_dialog, SIGNAL(toggled(bool)),
 
67
            _changedSignals, SLOT(map()) );
 
68
    _changedSignals->setMapping(ui->type_dialog, "window_type_dialog" );
 
69
 
 
70
    connect(
 
71
            ui->type_dock, SIGNAL(toggled(bool)),
 
72
            _changedSignals, SLOT(map()) );
 
73
    _changedSignals->setMapping(ui->type_dock, "window_type_dock" );
 
74
 
 
75
    connect(
 
76
            ui->type_desktop, SIGNAL(toggled(bool)),
 
77
            _changedSignals, SLOT(map()) );
 
78
    _changedSignals->setMapping(ui->type_desktop, "window_type_desktop" );
 
79
 
 
80
    connect(
 
81
            ui->type_normal, SIGNAL(toggled(bool)),
 
82
            _changedSignals, SLOT(map()) );
 
83
    _changedSignals->setMapping(ui->type_normal, "window_type_normal" );
 
84
    }
 
85
 
 
86
 
 
87
WindowDefinitionWidget::~WindowDefinitionWidget()
 
88
    { delete ui; }
 
89
 
 
90
 
 
91
void WindowDefinitionWidget::doCopyFromObject()
 
92
    {
 
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));
 
108
    }
 
109
 
 
110
 
 
111
void WindowDefinitionWidget::doCopyToObject()
 
112
    {
 
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()));
 
120
    int types = 0;
 
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);
 
130
    }
 
131
 
 
132
 
 
133
bool WindowDefinitionWidget::isChanged() const
 
134
    {
 
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())
 
142
        {
 
143
        return true;
 
144
        }
 
145
 
 
146
    int types = 0;
 
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;
 
157
    }
 
158
 
 
159
 
 
160
void WindowDefinitionWidget::slotAutoDetect()
 
161
    {
 
162
    KHotKeys::WindowSelector* sel = new KHotKeys::WindowSelector( this, SLOT( slotWindowSelected( WId )));
 
163
    sel->select();
 
164
    }
 
165
 
 
166
 
 
167
void WindowDefinitionWidget::slotWindowClassChanged(int index)
 
168
    {
 
169
    ui->window_class->setEnabled(index!=0);
 
170
    slotChanged("window_class");
 
171
    }
 
172
 
 
173
 
 
174
void WindowDefinitionWidget::slotWindowRoleChanged(int index)
 
175
    {
 
176
    ui->window_role->setEnabled(index!=0);
 
177
    slotChanged("window_role");
 
178
    }
 
179
 
 
180
 
 
181
void WindowDefinitionWidget::slotWindowSelected(WId window)
 
182
    {
 
183
    if (window)
 
184
        {
 
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 );
 
193
        }
 
194
    }
 
195
 
 
196
 
 
197
void WindowDefinitionWidget::slotWindowTitleChanged(int index)
 
198
    {
 
199
    ui->window_title->setEnabled(index!=0);
 
200
    slotChanged("window_title");
 
201
    }
 
202
 
 
203
 
 
204
#include "moc_window_definition_widget.cpp"