summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.cpp111
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.h6
2 files changed, 98 insertions, 19 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp
index 5676e4f..9c6c71d 100644
--- a/noncore/net/opietooth/applet/bluezapplet.cpp
+++ b/noncore/net/opietooth/applet/bluezapplet.cpp
@@ -36,2 +36,3 @@
36#include <opie2/oresource.h> 36#include <opie2/oresource.h>
37#include <opie2/oprocess.h>
37#include <qpe/applnk.h> 38#include <qpe/applnk.h>
@@ -51,2 +52,3 @@ using namespace Opie::Core;
51#include <qpopupmenu.h> 52#include <qpopupmenu.h>
53#include <qmessagebox.h>
52 54
@@ -55,4 +57,5 @@ using namespace Opie::Core;
55 57
56namespace OpieTooth { 58// #define OPIE120 // undefine it fo the latest OPIE
57 59
60namespace OpieTooth {
58 BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { 61 BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) {
@@ -60,2 +63,7 @@ namespace OpieTooth {
60 setFixedWidth( AppLnk::smallIconSize() ); 63 setFixedWidth( AppLnk::smallIconSize() );
64#ifdef OPIE120
65 bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" );
66 bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" );
67 bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" );
68#else
61 bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); 69 bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon );
@@ -63,3 +71,4 @@ namespace OpieTooth {
63 bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); 71 bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon );
64 startTimer(4000); 72#endif
73 startTimer(2000);
65 btDevice = 0; 74 btDevice = 0;
@@ -68,2 +77,5 @@ namespace OpieTooth {
68 bluezDiscoveryActive = false; 77 bluezDiscoveryActive = false;
78 doListDevice = false;
79 isScanning = false;
80 m_wasOn = false;
69 81
@@ -73,2 +85,12 @@ namespace OpieTooth {
73 this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); 85 this, SLOT(slotMessage(const QCString&,const QByteArray&) ) );
86
87 OProcess* btstart = new OProcess();
88 *btstart << "/etc/init.d/bluetooth" << "stop";
89 btstart->setUseShell(true);
90 if (!btstart->start(OProcess::DontCare, OProcess::AllOutput))
91 delete btstart;
92 else {
93 connect(btstart, SIGNAL(processExited(Opie::Core::OProcess*)),
94 this, SLOT(slotProcessExited(Opie::Core::OProcess*)));
95 }
74 } 96 }
@@ -104,2 +126,3 @@ int BluezApplet::position()
104 126
127 OProcess* btstart = new OProcess();
105 if ( c == 1 ) { 128 if ( c == 1 ) {
@@ -114,2 +137,3 @@ int BluezApplet::position()
114 137
138#ifndef OPIE120
115 case Model_MyPal_716: 139 case Model_MyPal_716:
@@ -117,2 +141,3 @@ int BluezApplet::position()
117 break; 141 break;
142#endif
118 143
@@ -122,3 +147,19 @@ int BluezApplet::position()
122 } 147 }
148 *btstart << "/etc/init.d/bluetooth" << "start";
149 btstart->setUseShell(true);
150 if (!btstart->start(OProcess::DontCare, OProcess::AllOutput))
151 delete btstart;
152 else {
153 connect(btstart, SIGNAL(processExited(Opie::Core::OProcess*)),
154 this, SLOT(slotProcessExited(Opie::Core::OProcess*)));
155 }
123 } else { 156 } else {
157 *btstart << "/etc/init.d/bluetooth" << "stop";
158 btstart->setUseShell(true);
159 if (!btstart->start(OProcess::DontCare, OProcess::AllOutput))
160 delete btstart;
161 else {
162 connect(btstart, SIGNAL(processExited(Opie::Core::OProcess*)),
163 this, SLOT(slotProcessExited(Opie::Core::OProcess*)));
164 }
124 if ( btDevice ) { 165 if ( btDevice ) {
@@ -132,3 +173,3 @@ int BluezApplet::position()
132 int BluezApplet::checkBluezDiscoveryStatus() { 173 int BluezApplet::checkBluezDiscoveryStatus() {
133 return bluezDiscoveryActive; 174 return isScanning;
134 } 175 }
@@ -144,18 +185,31 @@ int BluezApplet::position()
144 if ( str == "enableBluetooth()") { 185 if ( str == "enableBluetooth()") {
145 if (!checkBluezStatus()) { 186 m_wasOn = checkBluezStatus();
187 if (!m_wasOn) {
146 setBluezStatus(1); 188 setBluezStatus(1);
189 sleep(2);
147 } 190 }
148 } else if ( str == "disableBluetooth()") {
149 if (checkBluezStatus()) {
150 // setBluezStatus(0);
151 } 191 }
152 } else if ( str == "listDevices()") { 192 else if ( str == "disableBluetooth()") {
153 if (!btManager) 193 /*
154 { 194 * We can down BT only if it was started by qcop. We don't want
195 * to down BT started from menu an break our networking connection
196 */
197 if (checkBluezStatus() && !m_wasOn)
198 setBluezStatus(0);
199 doListDevice = false;
200 }
201 else if ( str == "listDevices()") {
202 if (checkBluezStatus()) {
203 doListDevice = false;
204 timerEvent(0);
205 if (!btManager) {
155 btManager = new Manager("hci0"); 206 btManager = new Manager("hci0");
156 connect( btManager, SIGNAL( foundDevices(const QString&,RemoteDevice::ValueList) ), 207 connect( btManager,
208 SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ),
157 this, SLOT( fillList(const QString&,RemoteDevice::ValueList) ) ) ; 209 this, SLOT( fillList(const QString&,RemoteDevice::ValueList) ) ) ;
158 } 210 }
159
160 btManager->searchDevices(); 211 btManager->searchDevices();
212 isScanning = true;
213 } else
214 doListDevice = true;
161 } 215 }
@@ -168,3 +222,2 @@ int BluezApplet::position()
168 222
169 QStringList list;
170 QMap<QString, QString> btmap; 223 QMap<QString, QString> btmap;
@@ -173,7 +226,7 @@ int BluezApplet::position()
173 for( it = deviceList.begin(); it != deviceList.end(); ++it ) 226 for( it = deviceList.begin(); it != deviceList.end(); ++it )
174 {
175 btmap[(*it).name()] = (*it).mac(); 227 btmap[(*it).name()] = (*it).mac();
176 }
177 228
178 e << btmap; 229 e << btmap;
230 isScanning = false;
231 timerEvent( 0 );
179 } 232 }
@@ -262,4 +315,8 @@ int BluezApplet::position()
262 315
263 if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) { 316 if ((bluezactive != oldactive) ||
317 (bluezDiscoveryActive != olddiscovery))
264 update(); 318 update();
319 if (bluezactive && doListDevice) {
320 const QByteArray arr;
321 slotMessage("listDevices()", arr);
265 } 322 }
@@ -275,9 +332,17 @@ int BluezApplet::position()
275 332
276 if (bluezactive > 0) { 333 if (bluezactive) {
334#ifdef OPIE120
335 p.drawPixmap( 0, -1, bluezOnPixmap );
336#else
277 p.drawPixmap( 0, 0, bluezOnPixmap ); 337 p.drawPixmap( 0, 0, bluezOnPixmap );
338#endif
278 } else { 339 } else {
340#ifdef OPIE120
341 p.drawPixmap( 0, -1, bluezOffPixmap );
342#else
279 p.drawPixmap( 0, 0, bluezOffPixmap ); 343 p.drawPixmap( 0, 0, bluezOffPixmap );
344#endif
280 } 345 }
281 346
282 if (bluezDiscoveryActive > 0) { 347 if (bluezDiscoveryActive) {
283 p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); 348 p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap );
@@ -285,4 +350,14 @@ int BluezApplet::position()
285 } 350 }
351
352/**
353 * Implementation of the process finish
354 * @param the finished process
355 */
356 void BluezApplet::slotProcessExited(OProcess* proc)
357 {
358 delete proc;
359 }
286}; 360};
287 361
362
288EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) 363EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet )
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h
index c096e29..85022bb 100644
--- a/noncore/net/opietooth/applet/bluezapplet.h
+++ b/noncore/net/opietooth/applet/bluezapplet.h
@@ -35,2 +35,3 @@
35#include <manager.h> 35#include <manager.h>
36#include <opie2/oprocess.h>
36 37
@@ -68,2 +69,5 @@ public slots:
68 bool bluezDiscoveryActive; 69 bool bluezDiscoveryActive;
70 bool doListDevice; //If I have to list devices after bringing BT up?
71 bool isScanning; //If I'm scanning devices
72 bool m_wasOn; //If BT was started by menu?
69 73
@@ -71,3 +75,3 @@ private slots:
71 void slotMessage( const QCString& , const QByteArray& ); 75 void slotMessage( const QCString& , const QByteArray& );
72 76 void slotProcessExited(Opie::Core::OProcess* proc);
73 77