~ubuntu-branches/ubuntu/intrepid/kdebluetooth/intrepid-proposed

« back to all changes in this revision

Viewing changes to src/adapterconfig.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Mercatante
  • Date: 2008-08-07 09:49:47 UTC
  • mto: This revision was merged to the branch mainline in revision 56.
  • Revision ID: james.westby@ubuntu.com-20080807094947-pj6q3uxwuv7l844q
Tags: upstream-0.1
ImportĀ upstreamĀ versionĀ 0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 *  KBluetooth4 - KDE Bluetooth Framework
 
4
 *
 
5
 *  Copyright (C) 2008  Tom Patzig <tpatzig@suse.de>
 
6
 *
 
7
 *  This file is part of kbluetooth4.
 
8
 *
 
9
 *  kbluetooth4 is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 2 of the License, or
 
12
 *  (at your option) any later version.
 
13
 *
 
14
 *  kbluetooth4 is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with kbluetooth4; if not, write to the Free Software
 
21
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
22
 *
 
23
*/
 
24
 
 
25
 
 
26
#include <KDebug>
 
27
#include "adapterconfig.h"
 
28
 
 
29
AdapterConfig::AdapterConfig(QObject* parent) : Ui_AdapterUi(),btmanager(Solid::Control::BluetoothManager::self())
 
30
{
 
31
        m_parent = parent;
 
32
        setupUi(this);
 
33
        setWindowIcon(KIcon("preferences-system-bluetooth"));
 
34
        adapterTabWidget->clear();
 
35
        closePushButton->setIcon(KIcon("window-close"));
 
36
        connect(closePushButton,SIGNAL(clicked()),this, SLOT(slotQuit()));      
 
37
 
 
38
        connect(&btmanager,SIGNAL(interfaceAdded(const QString&)),this,SLOT(adapterAdded(const QString&)));
 
39
        connect(&btmanager,SIGNAL(interfaceRemoved(const QString&)),this,SLOT(adapterRemoved(const QString&)));
 
40
        
 
41
        adapterMap = new QMap<QString,AdapterWidget*>();
 
42
 
 
43
        initialize();
 
44
        
 
45
}
 
46
 
 
47
AdapterConfig::~AdapterConfig()
 
48
{
 
49
        qDeleteAll (adapterMap->begin(),adapterMap->end());
 
50
        delete adapterMap;
 
51
}
 
52
 
 
53
void AdapterConfig::initialize()
 
54
{
 
55
        searchAdapters();
 
56
        show();
 
57
}
 
58
 
 
59
void AdapterConfig::searchAdapters()
 
60
{
 
61
        Solid::Control::BluetoothInterfaceList adapters = btmanager.bluetoothInterfaces();      
 
62
        foreach (Solid::Control::BluetoothInterface dev,adapters) {
 
63
 
 
64
                if(adapterMap->find(dev.ubi()) == adapterMap->end()) {
 
65
 
 
66
                        kDebug() << "New Adapter: " << dev.ubi();
 
67
                        tab = new AdapterWidget(dev.ubi(),this);
 
68
                        connect(tab,SIGNAL(nameFieldChanged(AdapterWidget*, QString)),this,SLOT(setTabName(AdapterWidget*,QString)));
 
69
                        setAdapterWidgetProperties(tab,dev);
 
70
                        adapterMap->insert(dev.ubi(),tab);
 
71
                        adapterTabWidget->addTab(tab,dev.name());
 
72
                } else {
 
73
                        kDebug() << "Adapter: " << dev.ubi();
 
74
                        AdapterWidget* tab1= *(adapterMap->find(dev.ubi()));
 
75
                        setAdapterWidgetProperties(tab1,dev);
 
76
                }
 
77
        }
 
78
}
 
79
 
 
80
void AdapterConfig::setAdapterWidgetProperties(AdapterWidget* tab,Solid::Control::BluetoothInterface dev)
 
81
{
 
82
                tab->setMac(dev.address());
 
83
                tab->setVersion(dev.version());
 
84
                tab->setDetails(dev.revision(),dev.manufacturer());
 
85
 
 
86
                tab->setName(dev.name());
 
87
                tab->setMode(dev.mode());
 
88
                tab->setDiscoverableTimeout(dev.discoverableTimeout());
 
89
                tab->setMinorClass(dev.minorClass());
 
90
}
 
91
 
 
92
void AdapterConfig::setTabName(AdapterWidget* tab, QString name)
 
93
{
 
94
        int index = adapterTabWidget->indexOf(tab);
 
95
        adapterTabWidget->setTabText(index,name);
 
96
}
 
97
 
 
98
void AdapterConfig::adapterAdded(const QString& ubi)
 
99
{
 
100
        kDebug() << "Adapter added: " << ubi;
 
101
        Solid::Control::BluetoothInterface dev(ubi);
 
102
        tab = new AdapterWidget(ubi,this);
 
103
        connect(tab,SIGNAL(nameFieldChanged(AdapterWidget*, QString)),this,SLOT(setTabName(AdapterWidget*,QString)));
 
104
        setAdapterWidgetProperties(tab,dev);
 
105
        adapterMap->insert(ubi,tab);
 
106
        adapterTabWidget->addTab(tab,dev.name());
 
107
}
 
108
 
 
109
void AdapterConfig::adapterRemoved(const QString& ubi)
 
110
{
 
111
        kDebug() << "Adapter removed: " << ubi;
 
112
        AdapterWidget* tab = adapterMap->value(ubi);
 
113
        int index = adapterTabWidget->indexOf(tab);
 
114
        adapterTabWidget->removeTab(index);
 
115
        adapterMap->take(ubi);
 
116
        delete tab;
 
117
}
 
118
 
 
119
void AdapterConfig::slotQuit()
 
120
{
 
121
        close();
 
122
}
 
123
 
 
124
#include "moc_adapterconfig.cpp"