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

« back to all changes in this revision

Viewing changes to kdebluetooth/kbluetooth/application.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
 
 *  kbluetooth - Another KDE Bluetooth tray icon application.
4
 
 *
5
 
 *  Copyright (C) 2003  Fred Schaettgen <kbluetoothd@schaettgen.de>
6
 
 *  Copyright (C) 2006  Daniel Gollub <dgollub@suse.de>
7
 
 *
8
 
 *
9
 
 *  This file is part of kbluetooth.
10
 
 *
11
 
 *  kbluetooth is free software; you can redistribute it and/or modify
12
 
 *  it under the terms of the GNU General Public License as published by
13
 
 *  the Free Software Foundation; either version 2 of the License, or
14
 
 *  (at your option) any later version.
15
 
 *
16
 
 *  libkbluetooth is distributed in the hope that it will be useful,
17
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 *  GNU General Public License for more details.
20
 
 *
21
 
 *  You should have received a copy of the GNU General Public License
22
 
 *  along with libkbluetooth; if not, write to the Free Software
23
 
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
24
 
 *
25
 
 */
26
 
 
27
 
 
28
 
#include "pindialog.h"
29
 
#include "authorize.h"
30
 
#include "trayicon.h"
31
 
 
32
 
#include "application.h"
33
 
 
34
 
KBluetoothApp::KBluetoothApp() :
35
 
    KUniqueApplication()
36
 
{
37
 
    m_config = new KConfig("kdebluetoothrc");
38
 
    // Enable autostart
39
 
    m_config->setGroup("General");
40
 
    m_config->writeEntry("AutoStart", true);
41
 
    m_config->sync();
42
 
    noAdapter = 0;      
43
 
        noDBus = 0;
44
 
    bFirstNewInstance = true;
45
 
 
46
 
    // blueZ DBUS API
47
 
    dbus = new DBusInit();
48
 
    conn = dbus->getDBus();
49
 
 
50
 
        if (!conn) {
51
 
                noDBus = 1;
52
 
                return;
53
 
        }
54
 
    manager = new Manager(conn);
55
 
    if (!manager->listAdapters().count() || manager->defaultAdapter() == "") { 
56
 
                noAdapter = 1;
57
 
                adapter = NULL;
58
 
    } else {
59
 
 
60
 
                 adapter = new Adapter(manager->defaultAdapter(), conn);
61
 
         rfcomm = new RfcommPortListener(m_config,adapter);
62
 
        }
63
 
                
64
 
 
65
 
   
66
 
 
67
 
//    hcid = new DBusHcid(this);
68
 
 
69
 
    // Register Default PasskeyAgent
70
 
    passkeyagent = new PasskeyAgent(conn, "/org/kde/kbluetooth_1234");
71
 
    passkeyagent->registerDefaultPasskeyAgent();
72
 
 
73
 
    authagent = new AuthAgent(conn, "/org/kde/kbluetooth_auth_1234");
74
 
    authagent->registerDefaultAuthorizationAgent();
75
 
 
76
 
 
77
 
 
78
 
 
79
 
    connect(passkeyagent, SIGNAL(request(const QString&, const QString&, bool)), SLOT(slotPinDialog(const QString&, const QString&, bool))); 
80
 
    connect(authagent, SIGNAL(authorize(const QString&, const QString&, const QString&, const QString&)), SLOT(slotAuthDialog(const QString&, const QString&, const QString&, const QString&))); 
81
 
 
82
 
    connect(manager, SIGNAL(adapterAdded(const QString&)), SLOT(slotAdapterAdded(const QString&)));
83
 
    connect(manager, SIGNAL(adapterRemoved(const QString&)), SLOT(slotAdapterRemoved(const QString&)));
84
 
        trayIcon = new TrayIcon(this);
85
 
        setMainWidget(trayIcon);
86
 
 
87
 
    connect(trayIcon, SIGNAL(setKbtobexSrv(bool)), this, SLOT(slotKbtobexSrv(bool)));
88
 
 
89
 
//    slotAuthDialog("/org/bluez/hci0", "00:00:00:ff:ff:ff", "foo", "0x213");
90
 
 
91
 
}
92
 
 
93
 
 
94
 
void KBluetoothApp::slotAdapterAdded(const QString& /*address*/) {
95
 
 
96
 
         if (!noAdapter)
97
 
                 return;
98
 
         else {
99
 
                 noAdapter = 0;
100
 
                 adapter = new Adapter(manager->defaultAdapter(), conn);
101
 
         rfcomm = new RfcommPortListener(m_config,adapter);
102
 
         }
103
 
 
104
 
}
105
 
 
106
 
void KBluetoothApp::slotAdapterRemoved(const QString& /*address*/) {
107
 
 
108
 
                 noAdapter = 1;
109
 
                 if (rfcomm)
110
 
                 delete rfcomm;
111
 
 
112
 
}
113
 
 
114
 
 
115
 
void KBluetoothApp::slotKbtobexSrv(bool status) {
116
 
        if (status)
117
 
                rfcomm = new RfcommPortListener(m_config,adapter);
118
 
        else
119
 
                delete rfcomm;
120
 
 
121
 
}
122
 
 
123
 
KBluetoothApp::~KBluetoothApp()
124
 
{
125
 
    delete m_config;
126
 
    if (!noDBus) {
127
 
        passkeyagent->unregisterDefaultPasskeyAgent();  
128
 
        delete trayIcon;
129
 
                if (adapter != NULL)
130
 
                        delete adapter;
131
 
                delete manager;
132
 
//              delete dbus;
133
 
    }
134
 
}
135
 
 
136
 
int KBluetoothApp::newInstance()
137
 
{
138
 
    // KBluetooth is started via autostart. If session management
139
 
    // is activated it will be called twice after login. This would
140
 
    // set the tray icon to visible every time, so we turn off
141
 
    // session management.
142
 
    disableSessionManagement();
143
 
 
144
 
    KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
145
 
    // If kbluetooth is started while already running we
146
 
    // make the tray icon permanently visible
147
 
    if (bFirstNewInstance == false) {
148
 
        if ((args->isSet("dontforceshow") == false) && trayIcon) {
149
 
            trayIcon->setAlwaysShowIcon(true);
150
 
        }
151
 
    }
152
 
    bFirstNewInstance = false;
153
 
    return 0;
154
 
}
155
 
 
156
 
void KBluetoothApp::slotPinDialog(const QString &path, const QString &address, bool isNumeric)
157
 
{
158
 
        kdDebug() << k_funcinfo << " (" << path << "," << address << "," << isNumeric << ")" << endl;
159
 
 
160
 
        PinDialog *dialog = new PinDialog(address, adapter->getRemoteName(address), passkeyagent); 
161
 
 
162
 
        kapp->updateUserTimestamp();
163
 
        dialog->show();
164
 
        dialog->raise();
165
 
 
166
 
}
167
 
 
168
 
void KBluetoothApp::slotAuthDialog(const QString &path, const QString &address, const QString &service, const QString &uuid)
169
 
{
170
 
        kdDebug() << k_funcinfo << " (" << path << "," << address << "," << service << "," << uuid << ")" << endl;
171
 
 
172
 
        AuthorizeDialog *dialog = new AuthorizeDialog(address, adapter->getRemoteName(address), service, uuid, authagent); 
173
 
        
174
 
        kapp->updateUserTimestamp();
175
 
        dialog->show();
176
 
        dialog->raise();
177
 
 
178
 
        
179
 
}
180
 
 
181
 
#include "application.moc"