~ubuntu-branches/ubuntu/raring/recorditnow/raring

« back to all changes in this revision

Viewing changes to src/config/keyboardconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Felix Geyer
  • Date: 2011-01-09 14:54:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110109145401-gyckb4airz4fio50
Tags: 0.8.1-0ubuntu1
* New upstream release. (LP: #681270)
  - Update debian/copyright.
* Build-depend on recordmydesktop.
* Add a watch file.
* Drop 01_fix_ftbfs_kwarning_call.diff, fixed upstream.
* Add 01_joschy_install_to_usr_lib.diff.
* Add 02_fix_ftbfs_no-add-needed.diff.
* Add 03_dont_install_header_files.diff.
* Replace dependency on libpolkit-qt-1-0 with policykit-1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *   Copyright (C) 2010 by Kai Dombrowe <just89@gmx.de>                    *
 
3
 *                                                                         *
 
4
 *   This program is free software; you can redistribute it and/or modify  *
 
5
 *   it under the terms of the GNU General Public License as published by  *
 
6
 *   the Free Software Foundation; either version 2 of the License, or     *
 
7
 *   (at your option) any later version.                                   *
 
8
 *                                                                         *
 
9
 *   This program is distributed in the hope that it will be useful,       *
 
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 
12
 *   GNU General Public License for more details.                          *
 
13
 *                                                                         *
 
14
 *   You should have received a copy of the GNU General Public License     *
 
15
 *   along with this program; if not, write to the                         *
 
16
 *   Free Software Foundation, Inc.,                                       *
 
17
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA .        *
 
18
 ***************************************************************************/
 
19
 
 
20
 
 
21
// own
 
22
#include "keyboardconfig.h"
 
23
#include "keyboardwizard.h"
 
24
#include "devicesearchdialog.h"
 
25
 
 
26
// KDE
 
27
#include <kicon.h>
 
28
#include <kmessagebox.h>
 
29
#include <kconfiggroup.h>
 
30
 
 
31
// Qt
 
32
#include <QtGui/QListWidget>
 
33
 
 
34
 
 
35
KeyboardConfig::KeyboardConfig(KConfig *cfg, QWidget *parent)
 
36
    : RecordItNow::ConfigPage(cfg, parent)
 
37
{
 
38
 
 
39
    setupUi(this);
 
40
 
 
41
    addButton->setIcon(KIcon("list-add"));
 
42
    removeButton->setIcon(KIcon("list-remove"));
 
43
    upButton->setIcon(KIcon("go-up"));
 
44
    downButton->setIcon(KIcon("go-down"));
 
45
    searchButton->setIcon(KIcon("system-search"));
 
46
 
 
47
    connect(addButton, SIGNAL(clicked()), this, SLOT(add()));
 
48
    connect(removeButton, SIGNAL(clicked()), this, SLOT(remove()));
 
49
    connect(upButton, SIGNAL(clicked()), this, SLOT(up()));
 
50
    connect(downButton, SIGNAL(clicked()), this, SLOT(down()));
 
51
    connect(listWidget, SIGNAL(itemSelectionChanged()), this, SLOT(itemSelectionChanged()));
 
52
    connect(searchButton, SIGNAL(clicked()), this, SLOT(showSearchDialog()));
 
53
    connect(kcfg_keyboardDevice, SIGNAL(textChanged(QString)), this, SLOT(textChanged(QString)));
 
54
 
 
55
    itemSelectionChanged();
 
56
 
 
57
}
 
58
 
 
59
 
 
60
QList<KeyboardKey> KeyboardConfig::readConfig(KConfig *cfg)
 
61
{
 
62
 
 
63
    KConfigGroup group(cfg, "Keyboard");
 
64
    const int count = group.readEntry("Keys", 0);
 
65
    QList<KeyboardKey> keyMap;
 
66
 
 
67
    for (int i = 0; i < count; i++) {
 
68
        const int key = group.readEntry(QString("Key %1 Code").arg(i), -1);
 
69
        const QString icon = group.readEntry(QString("Key %1 Icon").arg(i), QString());
 
70
        const QString text = group.readEntry(QString("Key %1 Text").arg(i), QString());
 
71
 
 
72
        keyMap.append(KeyboardKey(key, icon, text));
 
73
    }
 
74
 
 
75
    return keyMap;
 
76
 
 
77
}
 
78
 
 
79
 
 
80
void KeyboardConfig::loadConfig()
 
81
{
 
82
 
 
83
    QList<KeyboardKey> list(readConfig(config()));
 
84
    foreach (const KeyboardKey &key, list) {
 
85
        QListWidgetItem *item = new QListWidgetItem();
 
86
        item->setText(key.text());
 
87
        item->setIcon(KIcon(key.icon()));
 
88
        item->setData(Qt::UserRole+1, key.code());
 
89
        item->setData(Qt::UserRole+2, key.icon());
 
90
 
 
91
        listWidget->addItem(item);
 
92
    }
 
93
 
 
94
}
 
95
 
 
96
 
 
97
void KeyboardConfig::saveConfig()
 
98
{
 
99
 
 
100
    KConfigGroup group(config(), "Keyboard");
 
101
    int count = 0;
 
102
    for (int i = 0; i < listWidget->count(); i++) {
 
103
        QListWidgetItem *item = listWidget->item(i);
 
104
        group.writeEntry(QString("Key %1 Code").arg(i), item->data(Qt::UserRole+1).toInt());
 
105
        group.writeEntry(QString("Key %1 Icon").arg(i), item->data(Qt::UserRole+2).toString());
 
106
        group.writeEntry(QString("Key %1 Text").arg(i), item->text());
 
107
        count++;
 
108
    }
 
109
    group.writeEntry("Keys", count);
 
110
 
 
111
}
 
112
 
 
113
 
 
114
void KeyboardConfig::setDefaults()
 
115
{
 
116
 
 
117
    listWidget->clear();
 
118
 
 
119
}
 
120
 
 
121
 
 
122
void KeyboardConfig::add()
 
123
{
 
124
 
 
125
    KeyboardWizard *wizard = new KeyboardWizard(kcfg_keyboardDevice->text(), this);
 
126
    connect(wizard, SIGNAL(wizardFinished(int, QString, QString)), this,
 
127
            SLOT(wizardFinished(int, QString, QString)));
 
128
 
 
129
    wizard->show();
 
130
 
 
131
}
 
132
 
 
133
 
 
134
void KeyboardConfig::remove()
 
135
{
 
136
 
 
137
    QList<QListWidgetItem*> items = listWidget->selectedItems();
 
138
    if (items.isEmpty()) {
 
139
        return;
 
140
    }
 
141
 
 
142
    QListWidgetItem *item = items.first();
 
143
 
 
144
    listWidget->takeItem(listWidget->row(item));
 
145
    delete item;
 
146
 
 
147
    emit configChanged();
 
148
 
 
149
}
 
150
 
 
151
 
 
152
void KeyboardConfig::up()
 
153
{
 
154
 
 
155
    QList<QListWidgetItem*> items = listWidget->selectedItems();
 
156
    if (items.isEmpty()) {
 
157
        return;
 
158
    }
 
159
 
 
160
    QListWidgetItem *item = items.first();
 
161
    const int index = listWidget->row(item);
 
162
 
 
163
    listWidget->takeItem(index);
 
164
    listWidget->insertItem(index-1, item);
 
165
 
 
166
    listWidget->setCurrentItem(item);
 
167
 
 
168
    emit configChanged();
 
169
 
 
170
}
 
171
 
 
172
 
 
173
void KeyboardConfig::down()
 
174
{
 
175
 
 
176
    QList<QListWidgetItem*> items = listWidget->selectedItems();
 
177
    if (items.isEmpty()) {
 
178
        return;
 
179
    }
 
180
 
 
181
    QListWidgetItem *item = items.first();
 
182
    const int index = listWidget->row(item);
 
183
 
 
184
    listWidget->takeItem(index);
 
185
    listWidget->insertItem(index+1, item);
 
186
 
 
187
    listWidget->setCurrentItem(item);
 
188
 
 
189
    emit configChanged();
 
190
 
 
191
}
 
192
 
 
193
 
 
194
void KeyboardConfig::itemSelectionChanged()
 
195
{
 
196
 
 
197
    if(listWidget->selectedItems().isEmpty()) {
 
198
        upButton->setEnabled(false);
 
199
        downButton->setEnabled(false);
 
200
        removeButton->setEnabled(false);
 
201
    } else {
 
202
        const int index = listWidget->row(listWidget->selectedItems().first());
 
203
        upButton->setEnabled(index != 0);
 
204
        downButton->setEnabled(index != listWidget->count()-1);
 
205
        removeButton->setEnabled(true);
 
206
    }
 
207
 
 
208
}
 
209
 
 
210
 
 
211
void KeyboardConfig::wizardFinished(const int &key, const QString &icon, const QString &text)
 
212
{
 
213
 
 
214
    for (int i = 0; i < listWidget->count(); i++) {
 
215
        if (listWidget->item(i)->data(Qt::UserRole+1).toInt() == key) {
 
216
            KMessageBox::error(this, i18n("There is already a key with code '%1' in your list!", key));
 
217
            return;
 
218
        }
 
219
 
 
220
    }
 
221
 
 
222
    QListWidgetItem *item = new QListWidgetItem();
 
223
    item->setText(text);
 
224
    item->setIcon(KIcon(icon));
 
225
    item->setData(Qt::UserRole+1, key);
 
226
    item->setData(Qt::UserRole+2, icon);
 
227
 
 
228
    listWidget->addItem(item);
 
229
 
 
230
    emit configChanged();
 
231
 
 
232
}
 
233
 
 
234
 
 
235
void KeyboardConfig::showSearchDialog()
 
236
{
 
237
 
 
238
    DeviceSearchDialog *dialog = new DeviceSearchDialog(KeyMon::DeviceInfo::KeyboardType, this);
 
239
    connect(dialog, SIGNAL(deviceSelected(QString)), this, SLOT(searchDialogFinished(QString)));
 
240
 
 
241
    dialog->show();
 
242
 
 
243
}
 
244
 
 
245
 
 
246
void KeyboardConfig::searchDialogFinished(const QString &uuid)
 
247
{
 
248
 
 
249
    kcfg_keyboardDevice->setText(uuid);
 
250
 
 
251
}
 
252
 
 
253
 
 
254
void KeyboardConfig::textChanged(const QString &text)
 
255
{
 
256
 
 
257
    addButton->setDisabled(text.isEmpty());
 
258
 
 
259
}
 
260
 
 
261
 
 
262
#include "keyboardconfig.moc"
 
263