summaryrefslogtreecommitdiff
path: root/noncore/net
authorkorovkin <korovkin>2006-04-24 16:05:26 (UTC)
committer korovkin <korovkin>2006-04-24 16:05:26 (UTC)
commit71722eacaa44f3b738318d68dc6148c9e2ff643d (patch) (unidiff)
tree2c8eed7019d47db0885c1a0ba0ff6dc0fc16effb /noncore/net
parent2457dde10b8108a74f160b5d1c6bdbb877e0099a (diff)
downloadopie-71722eacaa44f3b738318d68dc6148c9e2ff643d.zip
opie-71722eacaa44f3b738318d68dc6148c9e2ff643d.tar.gz
opie-71722eacaa44f3b738318d68dc6148c9e2ff643d.tar.bz2
On start runs /etc/init.d/bluetooth stop.
On setBluezStatus runs /etc/init.d/bluetooth start or stop. If "listDevices()" is called prior to "enableBluetooth()", postpone the action. If BT was enabled befor "enableBluetooth()" was received, do not disable it on "disableBluetooth()". Timer period became twice shorter. When "listDevices()" received, show browsing icon. Added OPIE120 for compatibility.
Diffstat (limited to 'noncore/net') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.cpp143
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.h6
2 files changed, 114 insertions, 35 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
@@ -34,6 +34,7 @@
34#include <opie2/odevice.h> 34#include <opie2/odevice.h>
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
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>
38#include <qpe/qcopenvelope_qws.h> 39#include <qpe/qcopenvelope_qws.h>
39#include <qpe/config.h> 40#include <qpe/config.h>
@@ -49,28 +50,49 @@ using namespace Opie::Core;
49#include <qstring.h> 50#include <qstring.h>
50#include <qtimer.h> 51#include <qtimer.h>
51#include <qpopupmenu.h> 52#include <qpopupmenu.h>
53#include <qmessagebox.h>
52 54
53/* STD */ 55/* STD */
54#include <device.h> 56#include <device.h>
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 ) {
59 setFixedHeight( AppLnk::smallIconSize() ); 62 setFixedHeight( AppLnk::smallIconSize() );
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 );
62 bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); 70 bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon );
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;
66 btManager = 0; 75 btManager = 0;
67 bluezactive = false; 76 bluezactive = false;
68 bluezDiscoveryActive = false; 77 bluezDiscoveryActive = false;
78 doListDevice = false;
79 isScanning = false;
80 m_wasOn = false;
69 81
70 // TODO: determine whether this channel has to be closed at destruction time. 82 // TODO: determine whether this channel has to be closed at destruction time.
71 QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); 83 QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this );
72 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 84 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
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 }
75 97
76 BluezApplet::~BluezApplet() { 98 BluezApplet::~BluezApplet() {
@@ -102,25 +124,44 @@ int BluezApplet::position()
102 124
103 int BluezApplet::setBluezStatus(int c) { 125 int BluezApplet::setBluezStatus(int c) {
104 126
127 OProcess* btstart = new OProcess();
105 if ( c == 1 ) { 128 if ( c == 1 ) {
106 switch ( ODevice::inst()->model() ) { 129 switch ( ODevice::inst()->model() ) {
107 case Model_iPAQ_H39xx: 130 case Model_iPAQ_H39xx:
108 btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); 131 btDevice = new Device( "/dev/tts/1", "bcsp", "921600" );
109 break; 132 break;
110 133
111 case Model_iPAQ_H5xxx: 134 case Model_iPAQ_H5xxx:
112 btDevice = new Device( "/dev/tts/1", "any", "921600" ); 135 btDevice = new Device( "/dev/tts/1", "any", "921600" );
113 break; 136 break;
114 137
138#ifndef OPIE120
115 case Model_MyPal_716: 139 case Model_MyPal_716:
116 btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); 140 btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" );
117 break; 141 break;
142#endif
118 143
119 default: 144 default:
120 btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); 145 btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" );
121 break; 146 break;
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 ) {
125 delete btDevice; 166 delete btDevice;
126 btDevice = 0; 167 btDevice = 0;
@@ -130,52 +171,64 @@ int BluezApplet::position()
130 } 171 }
131 172
132 int BluezApplet::checkBluezDiscoveryStatus() { 173 int BluezApplet::checkBluezDiscoveryStatus() {
133 return bluezDiscoveryActive; 174 return isScanning;
134 } 175 }
135 176
136 int BluezApplet::setBluezDiscoveryStatus(int d) { 177 int BluezApplet::setBluezDiscoveryStatus(int d) {
137 return bluezDiscoveryActive=d; 178 return bluezDiscoveryActive = d;
138 } 179 }
139 180
140 // FIXME mbhaynie 181 // FIXME mbhaynie
141 // receiver for QCopChannel("QPE/Bluetooth") messages. 182 // receiver for QCopChannel("QPE/Bluetooth") messages.
142 void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) 183 void BluezApplet::slotMessage( const QCString& str, const QByteArray& )
143 { 184 {
144 if ( str == "enableBluetooth()") { 185 if ( str == "enableBluetooth()") {
145 if (!checkBluezStatus()) { 186 m_wasOn = checkBluezStatus();
146 setBluezStatus(1); 187 if (!m_wasOn) {
147 } 188 setBluezStatus(1);
148 } else if ( str == "disableBluetooth()") { 189 sleep(2);
149 if (checkBluezStatus()) { 190 }
150 // setBluezStatus(0); 191 }
151 } 192 else if ( str == "disableBluetooth()") {
152 } else if ( str == "listDevices()") { 193 /*
153 if (!btManager) 194 * We can down BT only if it was started by qcop. We don't want
154 { 195 * to down BT started from menu an break our networking connection
155 btManager = new Manager("hci0"); 196 */
156 connect( btManager, SIGNAL( foundDevices(const QString&,RemoteDevice::ValueList) ), 197 if (checkBluezStatus() && !m_wasOn)
157 this, SLOT( fillList(const QString&,RemoteDevice::ValueList) ) ) ; 198 setBluezStatus(0);
199 doListDevice = false;
158 } 200 }
159 201 else if ( str == "listDevices()") {
160 btManager->searchDevices(); 202 if (checkBluezStatus()) {
161 } 203 doListDevice = false;
204 timerEvent(0);
205 if (!btManager) {
206 btManager = new Manager("hci0");
207 connect( btManager,
208 SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ),
209 this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ;
210 }
211 btManager->searchDevices();
212 isScanning = true;
213 } else
214 doListDevice = true;
215 }
162 } 216 }
163 217
164 // Once the hcitool scan is complete, report back. 218 // Once the hcitool scan is complete, report back.
165 void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) 219 void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList)
166 { 220 {
167 QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); 221 QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)");
168 222
169 QStringList list; 223 QMap<QString, QString> btmap;
170 QMap<QString, QString> btmap;
171 224
172 RemoteDevice::ValueList::Iterator it; 225 RemoteDevice::ValueList::Iterator it;
173 for( it = deviceList.begin(); it != deviceList.end(); ++it ) 226 for( it = deviceList.begin(); it != deviceList.end(); ++it )
174 { 227 btmap[(*it).name()] = (*it).mac();
175 btmap[(*it).name()] = (*it).mac();
176 }
177 228
178 e << btmap; 229 e << btmap;
230 isScanning = false;
231 timerEvent( 0 );
179 } 232 }
180 233
181 void BluezApplet::mousePressEvent( QMouseEvent *) { 234 void BluezApplet::mousePressEvent( QMouseEvent *) {
@@ -260,8 +313,12 @@ int BluezApplet::position()
260 bluezactive = checkBluezStatus(); 313 bluezactive = checkBluezStatus();
261 bluezDiscoveryActive = checkBluezDiscoveryStatus(); 314 bluezDiscoveryActive = checkBluezDiscoveryStatus();
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 }
266 } 323 }
267 324
@@ -273,17 +330,35 @@ int BluezApplet::position()
273 QPainter p(this); 330 QPainter p(this);
274 odebug << "paint bluetooth pixmap" << oendl; 331 odebug << "paint bluetooth pixmap" << oendl;
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 );
284 } 349 }
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 )
289 364
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
@@ -33,6 +33,7 @@
33#include <qpixmap.h> 33#include <qpixmap.h>
34#include <qtimer.h> 34#include <qtimer.h>
35#include <manager.h> 35#include <manager.h>
36#include <opie2/oprocess.h>
36 37
37namespace OpieTooth { 38namespace OpieTooth {
38 class Device; 39 class Device;
@@ -66,10 +67,13 @@ public slots:
66 QPixmap bluezDiscoveryOnPixmap; 67 QPixmap bluezDiscoveryOnPixmap;
67 bool bluezactive; 68 bool bluezactive;
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
70private slots: 74private 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
74 }; 78 };
75}; 79};