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

« back to all changes in this revision

Viewing changes to src/devicesearchdialog.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
 
 
22
// own
 
23
#include "devicesearchdialog.h"
 
24
#include "keymonmanager.h"
 
25
 
 
26
// KDE
 
27
#include <klocalizedstring.h>
 
28
#include <kmessagebox.h>
 
29
 
 
30
// Qt
 
31
#include <QtGui/QTreeWidgetItem>
 
32
 
 
33
 
 
34
DeviceSearchDialog::DeviceSearchDialog(const KeyMon::DeviceInfo::DeviceType &type, QWidget *parent)
 
35
    : KDialog(parent)
 
36
{
 
37
 
 
38
    QWidget *main = new QWidget(this);
 
39
    setupUi(main);
 
40
    setMainWidget(main);
 
41
 
 
42
    setAttribute(Qt::WA_DeleteOnClose);
 
43
    resize(500, 300);
 
44
 
 
45
    switch (type) {
 
46
    case KeyMon::DeviceInfo::MouseType:
 
47
    case KeyMon::DeviceInfo::KeyboardType: {
 
48
            foreach (const KeyMon::DeviceInfo &info, KeyMonManager::self()->getInputDeviceList()) {
 
49
                if (info.type != type) {
 
50
                    continue;
 
51
                }
 
52
                QTreeWidgetItem *item = new QTreeWidgetItem;
 
53
                if (!info.icon.isEmpty()) {
 
54
                    item->setIcon(0, KIcon(info.icon));
 
55
                }
 
56
                item->setText(0, info.name);
 
57
                item->setText(1, info.file);
 
58
                item->setText(2, info.uuid);
 
59
                treeWidget->addTopLevelItem(item);
 
60
            }
 
61
        }
 
62
    default: break;
 
63
    }
 
64
 
 
65
    switch (type) {
 
66
    case KeyMon::DeviceInfo::MouseType: setWindowTitle(i18n("Mouse"));  break;
 
67
    case KeyMon::DeviceInfo::KeyboardType: setWindowTitle(i18n("Keyboard")); break;
 
68
    default: break;
 
69
    }
 
70
 
 
71
    connect(this, SIGNAL(finished(int)), this, SLOT(dialogFinished(int)));
 
72
    treeWidget->header()->setResizeMode(QHeaderView::ResizeToContents);
 
73
 
 
74
 
 
75
    if (treeWidget->topLevelItemCount() == 0) {
 
76
        KMessageBox::information(this, i18n("No devices found."));
 
77
        reject();
 
78
    }
 
79
 
 
80
}
 
81
 
 
82
 
 
83
void DeviceSearchDialog::dialogFinished(const int &ret)
 
84
{
 
85
 
 
86
    if (ret == KDialog::Accepted) {
 
87
        QList<QTreeWidgetItem*> items = treeWidget->selectedItems();
 
88
        if (items.isEmpty()) {
 
89
            return;
 
90
        }
 
91
        emit deviceSelected(items.first()->text(2));
 
92
    }
 
93
 
 
94
}
 
95
 
 
96
 
 
97
#include "devicesearchdialog.moc"