-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index 6351d4e..f7774f0 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -1,112 +1,111 @@ | |||
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/applnk.h> | 39 | #include <qpe/applnk.h> |
39 | #include <qpe/qcopenvelope_qws.h> | 40 | #include <qpe/qcopenvelope_qws.h> |
40 | #include <qpe/config.h> | 41 | #include <qpe/config.h> |
41 | using namespace Opie::Core; | 42 | using namespace Opie::Core; |
42 | 43 | ||
43 | /* QT */ | 44 | /* QT */ |
44 | #include <qapplication.h> | 45 | #include <qapplication.h> |
45 | #include <qpoint.h> | 46 | #include <qpoint.h> |
46 | #include <qpainter.h> | 47 | #include <qpainter.h> |
47 | #include <qlayout.h> | 48 | #include <qlayout.h> |
48 | #include <qframe.h> | 49 | #include <qframe.h> |
49 | #include <qpixmap.h> | 50 | #include <qpixmap.h> |
50 | #include <qstring.h> | 51 | #include <qstring.h> |
51 | #include <qtimer.h> | 52 | #include <qtimer.h> |
52 | #include <qpopupmenu.h> | 53 | #include <qpopupmenu.h> |
53 | #include <qmessagebox.h> | 54 | #include <qmessagebox.h> |
54 | 55 | ||
55 | /* STD */ | 56 | /* STD */ |
56 | #include <device.h> | 57 | #include <device.h> |
57 | 58 | ||
58 | #define OPIE120 // undefine it fo the latest OPIE | ||
59 | |||
60 | namespace OpieTooth { | 59 | namespace OpieTooth { |
61 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | 60 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { |
62 | setFixedHeight( AppLnk::smallIconSize() ); | 61 | setFixedHeight( AppLnk::smallIconSize() ); |
63 | setFixedWidth( AppLnk::smallIconSize() ); | 62 | setFixedWidth( AppLnk::smallIconSize() ); |
64 | #ifdef OPIE120 | 63 | #if OPIE_VERSION < 102010 |
65 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); | 64 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); |
66 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); | 65 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); |
67 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); | 66 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); |
68 | #else | 67 | #else |
69 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); | 68 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); |
70 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); | 69 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); |
71 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); | 70 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); |
72 | #endif | 71 | #endif |
73 | startTimer(2000); | 72 | startTimer(2000); |
74 | btDevice = 0; | 73 | btDevice = 0; |
75 | btManager = 0; | 74 | btManager = 0; |
76 | bluezactive = false; | 75 | bluezactive = false; |
77 | bluezDiscoveryActive = false; | 76 | bluezDiscoveryActive = false; |
78 | doListDevice = false; | 77 | doListDevice = false; |
79 | isScanning = false; | 78 | isScanning = false; |
80 | m_wasOn = false; | 79 | m_wasOn = false; |
81 | 80 | ||
82 | // TODO: determine whether this channel has to be closed at destruction time. | 81 | // TODO: determine whether this channel has to be closed at destruction time. |
83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); | 82 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); |
84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 83 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); | 84 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); |
86 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 85 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
87 | } | 86 | } |
88 | 87 | ||
89 | BluezApplet::~BluezApplet() { | 88 | BluezApplet::~BluezApplet() { |
90 | if ( btDevice ) { | 89 | if ( btDevice ) { |
91 | delete btDevice; | 90 | delete btDevice; |
92 | } | 91 | } |
93 | if ( btManager ) { | 92 | if ( btManager ) { |
94 | delete btManager; | 93 | delete btManager; |
95 | } | 94 | } |
96 | } | 95 | } |
97 | 96 | ||
98 | int BluezApplet::position() | 97 | int BluezApplet::position() |
99 | { | 98 | { |
100 | return 6; | 99 | return 6; |
101 | } | 100 | } |
102 | 101 | ||
103 | 102 | ||
104 | bool BluezApplet::checkBluezStatus() { | 103 | bool BluezApplet::checkBluezStatus() { |
105 | if (btDevice) { | 104 | if (btDevice) { |
106 | if (btDevice->isLoaded() ) { | 105 | if (btDevice->isLoaded() ) { |
107 | odebug << "btDevice isLoaded" << oendl; | 106 | odebug << "btDevice isLoaded" << oendl; |
108 | return true; | 107 | return true; |
109 | } else { | 108 | } else { |
110 | odebug << "btDevice is NOT loaded" << oendl; | 109 | odebug << "btDevice is NOT loaded" << oendl; |
111 | return false; | 110 | return false; |
112 | } | 111 | } |
@@ -275,70 +274,70 @@ namespace OpieTooth { | |||
275 | timerEvent(0 ); | 274 | timerEvent(0 ); |
276 | break; | 275 | break; |
277 | //case 7: | 276 | //case 7: |
278 | // With table of currently-detected devices. | 277 | // With table of currently-detected devices. |
279 | } | 278 | } |
280 | 279 | ||
281 | delete signal; | 280 | delete signal; |
282 | delete menu; | 281 | delete menu; |
283 | } | 282 | } |
284 | 283 | ||
285 | 284 | ||
286 | /** | 285 | /** |
287 | * Launches the bluetooth manager | 286 | * Launches the bluetooth manager |
288 | */ | 287 | */ |
289 | void BluezApplet::launchManager() { | 288 | void BluezApplet::launchManager() { |
290 | QCopEnvelope e("QPE/System", "execute(QString)"); | 289 | QCopEnvelope e("QPE/System", "execute(QString)"); |
291 | e << QString("bluetooth-manager"); | 290 | e << QString("bluetooth-manager"); |
292 | } | 291 | } |
293 | 292 | ||
294 | /** | 293 | /** |
295 | * Refresh timer | 294 | * Refresh timer |
296 | * @param the timer event | 295 | * @param the timer event |
297 | */ | 296 | */ |
298 | void BluezApplet::timerEvent( QTimerEvent * ) { | 297 | void BluezApplet::timerEvent( QTimerEvent * ) { |
299 | bool oldactive = bluezactive; | 298 | bool oldactive = bluezactive; |
300 | int olddiscovery = bluezDiscoveryActive; | 299 | int olddiscovery = bluezDiscoveryActive; |
301 | 300 | ||
302 | bluezactive = checkBluezStatus(); | 301 | bluezactive = checkBluezStatus(); |
303 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); | 302 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); |
304 | 303 | ||
305 | if ((bluezactive != oldactive) || | 304 | if ((bluezactive != oldactive) || |
306 | (bluezDiscoveryActive != olddiscovery)) | 305 | (bluezDiscoveryActive != olddiscovery)) |
307 | update(); | 306 | update(); |
308 | if (bluezactive && doListDevice) { | 307 | if (bluezactive && doListDevice) { |
309 | const QByteArray arr; | 308 | const QByteArray arr; |
310 | slotMessage("listDevices()", arr); | 309 | slotMessage("listDevices()", arr); |
311 | } | 310 | } |
312 | } | 311 | } |
313 | 312 | ||
314 | /** | 313 | /** |
315 | * Implementation of the paint event | 314 | * Implementation of the paint event |
316 | * @param the QPaintEvent | 315 | * @param the QPaintEvent |
317 | */ | 316 | */ |
318 | void BluezApplet::paintEvent( QPaintEvent* ) { | 317 | void BluezApplet::paintEvent( QPaintEvent* ) { |
319 | QPainter p(this); | 318 | QPainter p(this); |
320 | odebug << "paint bluetooth pixmap" << oendl; | 319 | odebug << "paint bluetooth pixmap" << oendl; |
321 | 320 | ||
322 | if (bluezactive) { | 321 | if (bluezactive) { |
323 | #ifdef OPIE120 | 322 | #if OPIE_VERSION < 102010 |
324 | p.drawPixmap( 0, -1, bluezOnPixmap ); | 323 | p.drawPixmap( 0, -1, bluezOnPixmap ); |
325 | #else | 324 | #else |
326 | p.drawPixmap( 0, 0, bluezOnPixmap ); | 325 | p.drawPixmap( 0, 0, bluezOnPixmap ); |
327 | #endif | 326 | #endif |
328 | } else { | 327 | } else { |
329 | #ifdef OPIE120 | 328 | #if OPIE_VERSION < 102010 |
330 | p.drawPixmap( 0, -1, bluezOffPixmap ); | 329 | p.drawPixmap( 0, -1, bluezOffPixmap ); |
331 | #else | 330 | #else |
332 | p.drawPixmap( 0, 0, bluezOffPixmap ); | 331 | p.drawPixmap( 0, 0, bluezOffPixmap ); |
333 | #endif | 332 | #endif |
334 | } | 333 | } |
335 | 334 | ||
336 | if (bluezDiscoveryActive) { | 335 | if (bluezDiscoveryActive) { |
337 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); | 336 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); |
338 | } | 337 | } |
339 | } | 338 | } |
340 | }; | 339 | }; |
341 | 340 | ||
342 | 341 | ||
343 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) | 342 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) |
344 | 343 | ||