summaryrefslogtreecommitdiff
path: root/noncore
Unidiff
Diffstat (limited to 'noncore') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp
index 787abc6..60fa4f8 100644
--- a/noncore/net/opietooth/applet/bluezapplet.cpp
+++ b/noncore/net/opietooth/applet/bluezapplet.cpp
@@ -1,318 +1,339 @@
1/* 1/*
2               =. This file is part of the OPIE Project 2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de> 3             .=l. Copyright (c) 2002 Maximilian Reiss <max.reiss@gmx.de>
4           .>+-= 4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can 5 _;:,     .>    :=|. This library is free software; you can
6.> <,   >  .   <= redistribute it and/or modify it under 6.> <,   >  .   <= redistribute it and/or modify it under
7:=1 )Y*s>-.--   : the terms of the GNU Library General Public 7:=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software 8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; version 2 of the License. 9 - .   .-<_>     .<> Foundation; version 2 of the License.
10     ._= =}       : 10     ._= =}       :
11    .%+i>       _;_. 11    .%+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that 12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of 14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A 15    =_        +     =;=| MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU 16  _.=:.       :    :=>: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more 17..}^=.=       =       ; Library General Public License for more
18++=   -.     .     .: details. 18++=   -.     .     .: details.
19 :     =  ...= . :.=- 19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU 20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with 21  -_. . .   )=.  = Library General Public License along with
22   --        :-= this library; see the file COPYING.LIB. 22   --        :-= this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation, 23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330, 24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29 29
30#include "bluezapplet.h" 30#include "bluezapplet.h"
31 31
32/* OPIE */ 32/* OPIE */
33#include <opie2/otaskbarapplet.h> 33#include <opie2/otaskbarapplet.h>
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 <opie2/oprocess.h>
38#include <qpe/version.h> 38#include <qpe/version.h>
39#include <qpe/applnk.h> 39#include <qpe/applnk.h>
40#include <qpe/qcopenvelope_qws.h> 40#include <qpe/qcopenvelope_qws.h>
41#include <qpe/config.h> 41#include <qpe/config.h>
42using namespace Opie::Core; 42using namespace Opie::Core;
43 43
44/* QT */ 44/* QT */
45#include <qapplication.h> 45#include <qapplication.h>
46#include <qpoint.h> 46#include <qpoint.h>
47#include <qpainter.h> 47#include <qpainter.h>
48#include <qlayout.h> 48#include <qlayout.h>
49#include <qframe.h> 49#include <qframe.h>
50#include <qpixmap.h> 50#include <qpixmap.h>
51#include <qstring.h> 51#include <qstring.h>
52#include <qtimer.h> 52#include <qtimer.h>
53#include <qpopupmenu.h> 53#include <qpopupmenu.h>
54#include <qmessagebox.h> 54#include <qmessagebox.h>
55#include <qfile.h>
56#include <qtextstream.h>
55 57
56/* STD */ 58/* STD */
57#include <device.h> 59#include <device.h>
58 60
59namespace OpieTooth { 61namespace OpieTooth {
60 BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { 62 BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) {
61 setFixedHeight( AppLnk::smallIconSize() ); 63 setFixedHeight( AppLnk::smallIconSize() );
62 setFixedWidth( AppLnk::smallIconSize() ); 64 setFixedWidth( AppLnk::smallIconSize() );
63#if OPIE_VERSION < 102010 65#if OPIE_VERSION < 102010
64 bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); 66 bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" );
65 bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); 67 bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" );
66 bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); 68 bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" );
67 bluezReceiveOnPixmap = Resource::loadPixmap( "bluetoothapplet/receive.png" ); 69 bluezReceiveOnPixmap = Resource::loadPixmap( "bluetoothapplet/receive.png" );
68#else 70#else
69 bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); 71 bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon );
70 bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); 72 bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon );
71 bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); 73 bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon );
72 bluezReceiveOnPixmap = OResource::loadImage( "bluetoothapplet/bluezonreceive", Opie::Core::OResource::SmallIcon ); 74 bluezReceiveOnPixmap = OResource::loadImage( "bluetoothapplet/bluezonreceive", Opie::Core::OResource::SmallIcon );
73#endif 75#endif
74 startTimer(2000); 76 startTimer(2000);
75 btDevice = 0; 77 btDevice = 0;
76 btManager = 0; 78 btManager = 0;
77 bluezactive = false; 79 bluezactive = false;
78 bluezDiscoveryActive = false; 80 bluezDiscoveryActive = false;
79 bluezReceiveActive = false; 81 bluezReceiveActive = false;
80 bluezReceiveChanged = false; 82 bluezReceiveChanged = false;
81 doListDevice = false; 83 doListDevice = false;
82 isScanning = false; 84 isScanning = false;
83 m_wasOn = false; 85 m_wasOn = false;
84 m_sync = false; 86 m_sync = false;
85 87
86 // TODO: determine whether this channel has to be closed at destruction time. 88 // TODO: determine whether this channel has to be closed at destruction time.
87 QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); 89 QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this );
88 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), 90 connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ),
89 this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); 91 this, SLOT(slotMessage(const QCString&,const QByteArray&) ) );
90 ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); 92 ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null");
91 } 93 }
92 94
93 BluezApplet::~BluezApplet() { 95 BluezApplet::~BluezApplet() {
94 if ( btDevice ) { 96 if ( btDevice ) {
95 ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); 97 ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null");
96 delete btDevice; 98 delete btDevice;
97 } 99 }
98 if ( btManager ) { 100 if ( btManager ) {
99 delete btManager; 101 delete btManager;
100 } 102 }
101 } 103 }
102 104
103 int BluezApplet::position() 105 int BluezApplet::position()
104 { 106 {
105 return 6; 107 return 6;
106 } 108 }
107 109
108 110
109 bool BluezApplet::checkBluezStatus() { 111 bool BluezApplet::checkBluezStatus() {
110 if (btDevice) { 112 if (btDevice) {
111 if (btDevice->isLoaded() ) { 113 if (btDevice->isLoaded() ) {
112 odebug << "btDevice isLoaded" << oendl; 114 odebug << "btDevice isLoaded" << oendl;
113 return true; 115 return true;
114 } else { 116 } else {
115 odebug << "btDevice is NOT loaded" << oendl; 117 odebug << "btDevice is NOT loaded" << oendl;
116 return false; 118 return false;
117 } 119 }
118 } else { 120 } else {
119 odebug << "btDevice is ZERO" << oendl; 121 odebug << "btDevice is ZERO" << oendl;
120 return false; 122 return false;
121 } 123 }
122 } 124 }
123 125
124 int BluezApplet::setBluezStatus(int c, bool sync) { 126 int BluezApplet::setBluezStatus(int c, bool sync) {
125 127
126 if ( c == 1 ) { 128 if ( c == 1 ) {
129 QFile cfg("/etc/sysconfig/bluetooth");
130 if ( cfg.open( IO_ReadOnly ) ) {
131 QTextStream stream( &cfg );
132 QString streamIn = stream.read();
133 QStringList list = QStringList::split( "\n", streamIn );
134 cfg.close();
135 if ( list.grep( "BLUETOOTH_PORT=" ).count() > 0 &&
136 list.grep( "BLUETOOTH_PROTOCOL=" ).count() > 0 &&
137 list.grep( "BLUETOOTH_SPEED=" ).count() > 0)
138 {
139 btDevice =
140 new Device( list.grep( "BLUETOOTH_PORT=" )[0].replace( QString( "BLUETOOTH_PORT=" ), ""),
141 list.grep( "BLUETOOTH_PROTOCOL=" )[0].replace( QString( "BLUETOOTH_PROTOCOL=" ), ""),
142 list.grep( "BLUETOOTH_SPEED=" )[0].replace( QString( "BLUETOOTH_SPEED=" ), "" ) );
143 return 0;
144 }
145 }
146
147 // Device-specific stuff - should be removed
127 switch ( ODevice::inst()->model() ) { 148 switch ( ODevice::inst()->model() ) {
128 case Model_iPAQ_H39xx: 149 case Model_iPAQ_H39xx:
129 btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); 150 btDevice = new Device( "/dev/tts/1", "bcsp", "921600" );
130 break; 151 break;
131 152
132 case Model_iPAQ_H5xxx: 153 case Model_iPAQ_H5xxx:
133 btDevice = new Device( "/dev/tts/1", "any", "921600" ); 154 btDevice = new Device( "/dev/tts/1", "any", "921600" );
134 break; 155 break;
135 156
136#if OPIE_VERSION >= 102010 157#if OPIE_VERSION >= 102010
137 case Model_MyPal_716: 158 case Model_MyPal_716:
138 btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); 159 btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" );
139 break; 160 break;
140#endif 161#endif
141 case Model_HTC_Universal: 162 case Model_HTC_Universal:
142 btDevice = new Device( "/dev/ttyS1", "texas", "115200" ); 163 btDevice = new Device( "/dev/ttyS1", "texas", "115200" );
143 break; 164 break;
144 165
145 case Model_iPAQ_H22xx: 166 case Model_iPAQ_H22xx:
146 btDevice = new Device( "/dev/tts/3", "any", "921600" ); 167 btDevice = new Device( "/dev/tts/3", "any", "921600" );
147 break; 168 break;
148 169
149 default: 170 default:
150 btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); 171 btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" );
151 break; 172 break;
152 } 173 }
153 m_sync = sync; 174 m_sync = sync;
154 connect(btDevice, SIGNAL(device(const QString&, bool)), 175 connect(btDevice, SIGNAL(device(const QString&, bool)),
155 this, SLOT(slotDevice(const QString&, bool))); 176 this, SLOT(slotDevice(const QString&, bool)));
156 177
157 } else { 178 } else {
158 setObexRecieveStatus(0); 179 setObexRecieveStatus(0);
159 ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); 180 ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null");
160 if ( btManager ) { 181 if ( btManager ) {
161 delete btManager; 182 delete btManager;
162 btManager = 0; 183 btManager = 0;
163 } 184 }
164 if ( btDevice ) { 185 if ( btDevice ) {
165 delete btDevice; 186 delete btDevice;
166 btDevice = 0; 187 btDevice = 0;
167 } 188 }
168 } 189 }
169 return 0; 190 return 0;
170 } 191 }
171 192
172 int BluezApplet::checkBluezDiscoveryStatus() { 193 int BluezApplet::checkBluezDiscoveryStatus() {
173 return isScanning; 194 return isScanning;
174 } 195 }
175 196
176 int BluezApplet::setBluezDiscoveryStatus(int d) { 197 int BluezApplet::setBluezDiscoveryStatus(int d) {
177 return bluezDiscoveryActive = d; 198 return bluezDiscoveryActive = d;
178 } 199 }
179 200
180 int BluezApplet::setObexRecieveStatus(int d) { 201 int BluezApplet::setObexRecieveStatus(int d) {
181 { 202 {
182 QCopEnvelope e ( "QPE/Obex", "btreceive(int)" ); 203 QCopEnvelope e ( "QPE/Obex", "btreceive(int)" );
183 e << ( d ? 1 : 0 ); 204 e << ( d ? 1 : 0 );
184 } 205 }
185 bluezReceiveActive = (bool)(d != 0); 206 bluezReceiveActive = (bool)(d != 0);
186 bluezReceiveChanged = true; 207 bluezReceiveChanged = true;
187 return d; 208 return d;
188 } 209 }
189 210
190 // FIXME mbhaynie 211 // FIXME mbhaynie
191 // receiver for QCopChannel("QPE/Bluetooth") messages. 212 // receiver for QCopChannel("QPE/Bluetooth") messages.
192 void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) 213 void BluezApplet::slotMessage( const QCString& str, const QByteArray& )
193 { 214 {
194 if ( str == "enableBluetooth()") { 215 if ( str == "enableBluetooth()") {
195 m_wasOn = checkBluezStatus(); 216 m_wasOn = checkBluezStatus();
196 if (!m_wasOn) { 217 if (!m_wasOn) {
197 setBluezStatus(1, true); 218 setBluezStatus(1, true);
198 sleep(2); 219 sleep(2);
199 } 220 }
200 } 221 }
201 else if ( str == "disableBluetooth()") { 222 else if ( str == "disableBluetooth()") {
202 /* 223 /*
203 * We can down BT only if it was started by qcop. We don't want 224 * We can down BT only if it was started by qcop. We don't want
204 * to down BT started from menu an break our networking connection 225 * to down BT started from menu an break our networking connection
205 */ 226 */
206 if (checkBluezStatus() && !m_wasOn) 227 if (checkBluezStatus() && !m_wasOn)
207 setBluezStatus(0); 228 setBluezStatus(0);
208 doListDevice = false; 229 doListDevice = false;
209 } 230 }
210 else if ( str == "listDevices()") { 231 else if ( str == "listDevices()") {
211 if (checkBluezStatus()) { 232 if (checkBluezStatus()) {
212 doListDevice = false; 233 doListDevice = false;
213 timerEvent(0); 234 timerEvent(0);
214 if (!btManager) { 235 if (!btManager) {
215 btManager = new Manager("hci0"); 236 btManager = new Manager("hci0");
216 connect( btManager, 237 connect( btManager,
217 SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), 238 SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ),
218 this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; 239 this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ;
219 } 240 }
220 btManager->searchDevices(); 241 btManager->searchDevices();
221 isScanning = true; 242 isScanning = true;
222 } else 243 } else
223 doListDevice = true; 244 doListDevice = true;
224 } 245 }
225 } 246 }
226 247
227 // Once the hcitool scan is complete, report back. 248 // Once the hcitool scan is complete, report back.
228 void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) 249 void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList)
229 { 250 {
230 QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); 251 QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)");
231 252
232 QMap<QString, QString> btmap; 253 QMap<QString, QString> btmap;
233 254
234 RemoteDevice::ValueList::Iterator it; 255 RemoteDevice::ValueList::Iterator it;
235 for( it = deviceList.begin(); it != deviceList.end(); ++it ) 256 for( it = deviceList.begin(); it != deviceList.end(); ++it )
236 btmap[(*it).name()] = (*it).mac(); 257 btmap[(*it).name()] = (*it).mac();
237 258
238 e << btmap; 259 e << btmap;
239 isScanning = false; 260 isScanning = false;
240 timerEvent( 0 ); 261 timerEvent( 0 );
241 } 262 }
242 263
243 void BluezApplet::mousePressEvent( QMouseEvent *) { 264 void BluezApplet::mousePressEvent( QMouseEvent *) {
244 265
245 QPopupMenu *menu = new QPopupMenu(); 266 QPopupMenu *menu = new QPopupMenu();
246 QPopupMenu *signal = new QPopupMenu(); 267 QPopupMenu *signal = new QPopupMenu();
247 int ret=0; 268 int ret=0;
248 269
249 /* Refresh active state */ 270 /* Refresh active state */
250 timerEvent( 0 ); 271 timerEvent( 0 );
251 272
252 273
253 if (bluezactive) { 274 if (bluezactive) {
254 menu->insertItem( tr("Disable Bluetooth"), 0 ); 275 menu->insertItem( tr("Disable Bluetooth"), 0 );
255 } else { 276 } else {
256 menu->insertItem( tr("Enable Bluetooth"), 1 ); 277 menu->insertItem( tr("Enable Bluetooth"), 1 );
257 } 278 }
258 279
259 menu->insertItem( tr("Launch manager"), 2 ); 280 menu->insertItem( tr("Launch manager"), 2 );
260 281
261 menu->insertSeparator(6); 282 menu->insertSeparator(6);
262 //menu->insertItem( tr("Signal strength"), signal, 5); 283 //menu->insertItem( tr("Signal strength"), signal, 5);
263 //menu->insertSeparator(8); 284 //menu->insertSeparator(8);
264 285
265 if (bluezactive) { 286 if (bluezactive) {
266 if (bluezReceiveActive) { 287 if (bluezReceiveActive) {
267 menu->insertItem( tr("Disable receive"), 3 ); 288 menu->insertItem( tr("Disable receive"), 3 );
268 } else { 289 } else {
269 menu->insertItem( tr("Enable receive"), 4 ); 290 menu->insertItem( tr("Enable receive"), 4 );
270 } 291 }
271 } 292 }
272 293
273 QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); 294 QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) );
274 ret = menu->exec(p, 0); 295 ret = menu->exec(p, 0);
275 menu->hide(); 296 menu->hide();
276 297
277 switch(ret) { 298 switch(ret) {
278 case 0: 299 case 0:
279 setBluezStatus(0); 300 setBluezStatus(0);
280 timerEvent( 0 ); 301 timerEvent( 0 );
281 break; 302 break;
282 case 1: 303 case 1:
283 setBluezStatus(1); 304 setBluezStatus(1);
284 timerEvent( 0 ); 305 timerEvent( 0 );
285 break; 306 break;
286 case 2: 307 case 2:
287 // start bluetoothmanager 308 // start bluetoothmanager
288 launchManager(); 309 launchManager();
289 timerEvent( 0 ); 310 timerEvent( 0 );
290 break; 311 break;
291 case 3: 312 case 3:
292 setObexRecieveStatus(0); 313 setObexRecieveStatus(0);
293 timerEvent( 0 ); 314 timerEvent( 0 );
294 break; 315 break;
295 case 4: 316 case 4:
296 setObexRecieveStatus(1); 317 setObexRecieveStatus(1);
297 timerEvent( 0 ); 318 timerEvent( 0 );
298 break; 319 break;
299 //case 7: 320 //case 7:
300 // With table of currently-detected devices. 321 // With table of currently-detected devices.
301 } 322 }
302 323
303 delete signal; 324 delete signal;
304 delete menu; 325 delete menu;
305 } 326 }
306 327
307 328
308/** 329/**
309 * Launches the bluetooth manager 330 * Launches the bluetooth manager
310 */ 331 */
311 void BluezApplet::launchManager() { 332 void BluezApplet::launchManager() {
312 QCopEnvelope e("QPE/System", "execute(QString)"); 333 QCopEnvelope e("QPE/System", "execute(QString)");
313 e << QString("bluetooth-manager"); 334 e << QString("bluetooth-manager");
314 } 335 }
315 336
316/** 337/**
317 * Refresh timer 338 * Refresh timer
318 * @param the timer event 339 * @param the timer event