author | korovkin <korovkin> | 2006-05-09 12:38:24 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-05-09 12:38:24 (UTC) |
commit | 620d55ae3b94fa8d2fa696b6626893e4520c3a02 (patch) (unidiff) | |
tree | ca1296808dfac6fa6c74086f4dda6af525d7b151 | |
parent | dc719be35432469c24dd8d10136c1ea25c6861d2 (diff) | |
download | opie-620d55ae3b94fa8d2fa696b6626893e4520c3a02.zip opie-620d55ae3b94fa8d2fa696b6626893e4520c3a02.tar.gz opie-620d55ae3b94fa8d2fa696b6626893e4520c3a02.tar.bz2 |
Instead of calling a process, do ::system on stop and use QCopEnvelope on start.
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 56 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 2 |
2 files changed, 16 insertions, 42 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index 9c6c71d..90b0c6d 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -1,364 +1,340 @@ | |||
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/applnk.h> | 38 | #include <qpe/applnk.h> |
39 | #include <qpe/qcopenvelope_qws.h> | 39 | #include <qpe/qcopenvelope_qws.h> |
40 | #include <qpe/config.h> | 40 | #include <qpe/config.h> |
41 | using namespace Opie::Core; | 41 | using namespace Opie::Core; |
42 | 42 | ||
43 | /* QT */ | 43 | /* QT */ |
44 | #include <qapplication.h> | 44 | #include <qapplication.h> |
45 | #include <qpoint.h> | 45 | #include <qpoint.h> |
46 | #include <qpainter.h> | 46 | #include <qpainter.h> |
47 | #include <qlayout.h> | 47 | #include <qlayout.h> |
48 | #include <qframe.h> | 48 | #include <qframe.h> |
49 | #include <qpixmap.h> | 49 | #include <qpixmap.h> |
50 | #include <qstring.h> | 50 | #include <qstring.h> |
51 | #include <qtimer.h> | 51 | #include <qtimer.h> |
52 | #include <qpopupmenu.h> | 52 | #include <qpopupmenu.h> |
53 | #include <qmessagebox.h> | 53 | #include <qmessagebox.h> |
54 | 54 | ||
55 | /* STD */ | 55 | /* STD */ |
56 | #include <device.h> | 56 | #include <device.h> |
57 | 57 | ||
58 | // #define OPIE120 // undefine it fo the latest OPIE | 58 | #define OPIE120 // undefine it fo the latest OPIE |
59 | 59 | ||
60 | namespace OpieTooth { | 60 | namespace OpieTooth { |
61 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | 61 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { |
62 | setFixedHeight( AppLnk::smallIconSize() ); | 62 | setFixedHeight( AppLnk::smallIconSize() ); |
63 | setFixedWidth( AppLnk::smallIconSize() ); | 63 | setFixedWidth( AppLnk::smallIconSize() ); |
64 | #ifdef OPIE120 | 64 | #ifdef OPIE120 |
65 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); | 65 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); |
66 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); | 66 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); |
67 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); | 67 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); |
68 | #else | 68 | #else |
69 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); | 69 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); |
70 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); | 70 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); |
71 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); | 71 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); |
72 | #endif | 72 | #endif |
73 | startTimer(2000); | 73 | startTimer(2000); |
74 | btDevice = 0; | 74 | btDevice = 0; |
75 | btManager = 0; | 75 | btManager = 0; |
76 | bluezactive = false; | 76 | bluezactive = false; |
77 | bluezDiscoveryActive = false; | 77 | bluezDiscoveryActive = false; |
78 | doListDevice = false; | 78 | doListDevice = false; |
79 | isScanning = false; | 79 | isScanning = false; |
80 | m_wasOn = false; | 80 | m_wasOn = false; |
81 | 81 | ||
82 | // 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. |
83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); | 83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); |
84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); | 85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); |
86 | 86 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | |
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 | } | ||
96 | } | 87 | } |
97 | 88 | ||
98 | BluezApplet::~BluezApplet() { | 89 | BluezApplet::~BluezApplet() { |
99 | if ( btDevice ) { | 90 | if ( btDevice ) { |
100 | delete btDevice; | 91 | delete btDevice; |
101 | } | 92 | } |
102 | if ( btManager ) { | 93 | if ( btManager ) { |
103 | delete btManager; | 94 | delete btManager; |
104 | } | 95 | } |
105 | } | 96 | } |
106 | 97 | ||
107 | int BluezApplet::position() | 98 | int BluezApplet::position() |
108 | { | 99 | { |
109 | return 6; | 100 | return 6; |
110 | } | 101 | } |
111 | 102 | ||
112 | 103 | ||
113 | bool BluezApplet::checkBluezStatus() { | 104 | bool BluezApplet::checkBluezStatus() { |
114 | if (btDevice) { | 105 | if (btDevice) { |
115 | if (btDevice->isLoaded() ) { | 106 | if (btDevice->isLoaded() ) { |
107 | odebug << "btDevice isLoaded" << oendl; | ||
116 | return true; | 108 | return true; |
117 | } else { | 109 | } else { |
110 | odebug << "btDevice is NOT loaded" << oendl; | ||
118 | return false; | 111 | return false; |
119 | } | 112 | } |
120 | } else { | 113 | } else { |
114 | odebug << "btDevice is ZERO" << oendl; | ||
121 | return false; | 115 | return false; |
122 | } | 116 | } |
123 | } | 117 | } |
124 | 118 | ||
125 | int BluezApplet::setBluezStatus(int c) { | 119 | int BluezApplet::setBluezStatus(int c) { |
126 | 120 | ||
127 | OProcess* btstart = new OProcess(); | ||
128 | if ( c == 1 ) { | 121 | if ( c == 1 ) { |
129 | switch ( ODevice::inst()->model() ) { | 122 | switch ( ODevice::inst()->model() ) { |
130 | case Model_iPAQ_H39xx: | 123 | case Model_iPAQ_H39xx: |
131 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); | 124 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); |
132 | break; | 125 | break; |
133 | 126 | ||
134 | case Model_iPAQ_H5xxx: | 127 | case Model_iPAQ_H5xxx: |
135 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); | 128 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); |
136 | break; | 129 | break; |
137 | 130 | ||
138 | #ifndef OPIE120 | 131 | #ifndef OPIE120 |
139 | case Model_MyPal_716: | 132 | case Model_MyPal_716: |
140 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); | 133 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); |
141 | break; | 134 | break; |
142 | #endif | 135 | #endif |
143 | 136 | ||
144 | default: | 137 | default: |
145 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); | 138 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); |
146 | break; | 139 | break; |
147 | } | 140 | } |
148 | *btstart << "/etc/init.d/bluetooth" << "start"; | 141 | QCopEnvelope e("QPE/System", "execute(QString)"); |
149 | btstart->setUseShell(true); | 142 | e << QString("/etc/init.d/bluetooth start"); |
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 | } | ||
156 | } else { | 143 | } else { |
157 | *btstart << "/etc/init.d/bluetooth" << "stop"; | 144 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
158 | btstart->setUseShell(true); | 145 | if ( btManager ) { |
159 | if (!btstart->start(OProcess::DontCare, OProcess::AllOutput)) | 146 | delete btManager; |
160 | delete btstart; | 147 | btManager = 0; |
161 | else { | ||
162 | connect(btstart, SIGNAL(processExited(Opie::Core::OProcess*)), | ||
163 | this, SLOT(slotProcessExited(Opie::Core::OProcess*))); | ||
164 | } | 148 | } |
165 | if ( btDevice ) { | 149 | if ( btDevice ) { |
166 | delete btDevice; | 150 | delete btDevice; |
167 | btDevice = 0; | 151 | btDevice = 0; |
168 | } | 152 | } |
169 | } | 153 | } |
170 | return 0; | 154 | return 0; |
171 | } | 155 | } |
172 | 156 | ||
173 | int BluezApplet::checkBluezDiscoveryStatus() { | 157 | int BluezApplet::checkBluezDiscoveryStatus() { |
174 | return isScanning; | 158 | return isScanning; |
175 | } | 159 | } |
176 | 160 | ||
177 | int BluezApplet::setBluezDiscoveryStatus(int d) { | 161 | int BluezApplet::setBluezDiscoveryStatus(int d) { |
178 | return bluezDiscoveryActive = d; | 162 | return bluezDiscoveryActive = d; |
179 | } | 163 | } |
180 | 164 | ||
181 | // FIXME mbhaynie | 165 | // FIXME mbhaynie |
182 | // receiver for QCopChannel("QPE/Bluetooth") messages. | 166 | // receiver for QCopChannel("QPE/Bluetooth") messages. |
183 | void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) | 167 | void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) |
184 | { | 168 | { |
185 | if ( str == "enableBluetooth()") { | 169 | if ( str == "enableBluetooth()") { |
186 | m_wasOn = checkBluezStatus(); | 170 | m_wasOn = checkBluezStatus(); |
187 | if (!m_wasOn) { | 171 | if (!m_wasOn) { |
188 | setBluezStatus(1); | 172 | setBluezStatus(1); |
189 | sleep(2); | 173 | sleep(2); |
190 | } | 174 | } |
191 | } | 175 | } |
192 | else if ( str == "disableBluetooth()") { | 176 | else if ( str == "disableBluetooth()") { |
193 | /* | 177 | /* |
194 | * We can down BT only if it was started by qcop. We don't want | 178 | * 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 | 179 | * to down BT started from menu an break our networking connection |
196 | */ | 180 | */ |
197 | if (checkBluezStatus() && !m_wasOn) | 181 | if (checkBluezStatus() && !m_wasOn) |
198 | setBluezStatus(0); | 182 | setBluezStatus(0); |
199 | doListDevice = false; | 183 | doListDevice = false; |
200 | } | 184 | } |
201 | else if ( str == "listDevices()") { | 185 | else if ( str == "listDevices()") { |
202 | if (checkBluezStatus()) { | 186 | if (checkBluezStatus()) { |
203 | doListDevice = false; | 187 | doListDevice = false; |
204 | timerEvent(0); | 188 | timerEvent(0); |
205 | if (!btManager) { | 189 | if (!btManager) { |
206 | btManager = new Manager("hci0"); | 190 | btManager = new Manager("hci0"); |
207 | connect( btManager, | 191 | connect( btManager, |
208 | SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), | 192 | SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), |
209 | this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; | 193 | this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; |
210 | } | 194 | } |
211 | btManager->searchDevices(); | 195 | btManager->searchDevices(); |
212 | isScanning = true; | 196 | isScanning = true; |
213 | } else | 197 | } else |
214 | doListDevice = true; | 198 | doListDevice = true; |
215 | } | 199 | } |
216 | } | 200 | } |
217 | 201 | ||
218 | // Once the hcitool scan is complete, report back. | 202 | // Once the hcitool scan is complete, report back. |
219 | void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) | 203 | void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) |
220 | { | 204 | { |
221 | QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); | 205 | QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); |
222 | 206 | ||
223 | QMap<QString, QString> btmap; | 207 | QMap<QString, QString> btmap; |
224 | 208 | ||
225 | RemoteDevice::ValueList::Iterator it; | 209 | RemoteDevice::ValueList::Iterator it; |
226 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) | 210 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) |
227 | btmap[(*it).name()] = (*it).mac(); | 211 | btmap[(*it).name()] = (*it).mac(); |
228 | 212 | ||
229 | e << btmap; | 213 | e << btmap; |
230 | isScanning = false; | 214 | isScanning = false; |
231 | timerEvent( 0 ); | 215 | timerEvent( 0 ); |
232 | } | 216 | } |
233 | 217 | ||
234 | void BluezApplet::mousePressEvent( QMouseEvent *) { | 218 | void BluezApplet::mousePressEvent( QMouseEvent *) { |
235 | 219 | ||
236 | QPopupMenu *menu = new QPopupMenu(); | 220 | QPopupMenu *menu = new QPopupMenu(); |
237 | QPopupMenu *signal = new QPopupMenu(); | 221 | QPopupMenu *signal = new QPopupMenu(); |
238 | int ret=0; | 222 | int ret=0; |
239 | 223 | ||
240 | /* Refresh active state */ | 224 | /* Refresh active state */ |
241 | timerEvent( 0 ); | 225 | timerEvent( 0 ); |
242 | 226 | ||
243 | 227 | ||
244 | if (bluezactive) { | 228 | if (bluezactive) { |
245 | menu->insertItem( tr("Disable Bluetooth"), 0 ); | 229 | menu->insertItem( tr("Disable Bluetooth"), 0 ); |
246 | } else { | 230 | } else { |
247 | menu->insertItem( tr("Enable Bluetooth"), 1 ); | 231 | menu->insertItem( tr("Enable Bluetooth"), 1 ); |
248 | } | 232 | } |
249 | 233 | ||
250 | menu->insertItem( tr("Launch manager"), 2 ); | 234 | menu->insertItem( tr("Launch manager"), 2 ); |
251 | 235 | ||
252 | menu->insertSeparator(6); | 236 | menu->insertSeparator(6); |
253 | //menu->insertItem( tr("Signal strength"), signal, 5); | 237 | //menu->insertItem( tr("Signal strength"), signal, 5); |
254 | //menu->insertSeparator(8); | 238 | //menu->insertSeparator(8); |
255 | 239 | ||
256 | if (bluezDiscoveryActive) { | 240 | if (bluezDiscoveryActive) { |
257 | menu->insertItem( tr("Disable discovery"), 3 ); | 241 | menu->insertItem( tr("Disable discovery"), 3 ); |
258 | } else { | 242 | } else { |
259 | menu->insertItem( tr("Enable discovery"), 4 ); | 243 | menu->insertItem( tr("Enable discovery"), 4 ); |
260 | } | 244 | } |
261 | 245 | ||
262 | 246 | ||
263 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | 247 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); |
264 | ret = menu->exec(p, 0); | 248 | ret = menu->exec(p, 0); |
249 | menu->hide(); | ||
265 | 250 | ||
266 | switch(ret) { | 251 | switch(ret) { |
267 | case 0: | 252 | case 0: |
268 | setBluezStatus(0); | 253 | setBluezStatus(0); |
269 | timerEvent( 0 ); | 254 | timerEvent( 0 ); |
270 | break; | 255 | break; |
271 | case 1: | 256 | case 1: |
272 | setBluezStatus(1); | 257 | setBluezStatus(1); |
273 | timerEvent( 0 ); | 258 | timerEvent( 0 ); |
274 | break; | 259 | break; |
275 | case 2: | 260 | case 2: |
276 | // start bluetoothmanager | 261 | // start bluetoothmanager |
277 | launchManager(); | 262 | launchManager(); |
278 | timerEvent( 0 ); | 263 | timerEvent( 0 ); |
279 | break; | 264 | break; |
280 | case 3: | 265 | case 3: |
281 | setBluezDiscoveryStatus(0); | 266 | setBluezDiscoveryStatus(0); |
282 | timerEvent( 0 ); | 267 | timerEvent( 0 ); |
283 | break; | 268 | break; |
284 | case 4: | 269 | case 4: |
285 | setBluezDiscoveryStatus(1); | 270 | setBluezDiscoveryStatus(1); |
286 | timerEvent(0 ); | 271 | timerEvent(0 ); |
287 | break; | 272 | break; |
288 | //case 7: | 273 | //case 7: |
289 | // With table of currently-detected devices. | 274 | // With table of currently-detected devices. |
290 | } | 275 | } |
291 | 276 | ||
292 | delete signal; | 277 | delete signal; |
293 | delete menu; | 278 | delete menu; |
294 | } | 279 | } |
295 | 280 | ||
296 | 281 | ||
297 | /** | 282 | /** |
298 | * Launches the bluetooth manager | 283 | * Launches the bluetooth manager |
299 | */ | 284 | */ |
300 | void BluezApplet::launchManager() { | 285 | void BluezApplet::launchManager() { |
301 | QCopEnvelope e("QPE/System", "execute(QString)"); | 286 | QCopEnvelope e("QPE/System", "execute(QString)"); |
302 | e << QString("bluetooth-manager"); | 287 | e << QString("bluetooth-manager"); |
303 | } | 288 | } |
304 | 289 | ||
305 | /** | 290 | /** |
306 | * Refresh timer | 291 | * Refresh timer |
307 | * @param the timer event | 292 | * @param the timer event |
308 | */ | 293 | */ |
309 | void BluezApplet::timerEvent( QTimerEvent * ) { | 294 | void BluezApplet::timerEvent( QTimerEvent * ) { |
310 | bool oldactive = bluezactive; | 295 | bool oldactive = bluezactive; |
311 | int olddiscovery = bluezDiscoveryActive; | 296 | int olddiscovery = bluezDiscoveryActive; |
312 | 297 | ||
313 | bluezactive = checkBluezStatus(); | 298 | bluezactive = checkBluezStatus(); |
314 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); | 299 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); |
315 | 300 | ||
316 | if ((bluezactive != oldactive) || | 301 | if ((bluezactive != oldactive) || |
317 | (bluezDiscoveryActive != olddiscovery)) | 302 | (bluezDiscoveryActive != olddiscovery)) |
318 | update(); | 303 | update(); |
319 | if (bluezactive && doListDevice) { | 304 | if (bluezactive && doListDevice) { |
320 | const QByteArray arr; | 305 | const QByteArray arr; |
321 | slotMessage("listDevices()", arr); | 306 | slotMessage("listDevices()", arr); |
322 | } | 307 | } |
323 | } | 308 | } |
324 | 309 | ||
325 | /** | 310 | /** |
326 | * Implementation of the paint event | 311 | * Implementation of the paint event |
327 | * @param the QPaintEvent | 312 | * @param the QPaintEvent |
328 | */ | 313 | */ |
329 | void BluezApplet::paintEvent( QPaintEvent* ) { | 314 | void BluezApplet::paintEvent( QPaintEvent* ) { |
330 | QPainter p(this); | 315 | QPainter p(this); |
331 | odebug << "paint bluetooth pixmap" << oendl; | 316 | odebug << "paint bluetooth pixmap" << oendl; |
332 | 317 | ||
333 | if (bluezactive) { | 318 | if (bluezactive) { |
334 | #ifdef OPIE120 | 319 | #ifdef OPIE120 |
335 | p.drawPixmap( 0, -1, bluezOnPixmap ); | 320 | p.drawPixmap( 0, -1, bluezOnPixmap ); |
336 | #else | 321 | #else |
337 | p.drawPixmap( 0, 0, bluezOnPixmap ); | 322 | p.drawPixmap( 0, 0, bluezOnPixmap ); |
338 | #endif | 323 | #endif |
339 | } else { | 324 | } else { |
340 | #ifdef OPIE120 | 325 | #ifdef OPIE120 |
341 | p.drawPixmap( 0, -1, bluezOffPixmap ); | 326 | p.drawPixmap( 0, -1, bluezOffPixmap ); |
342 | #else | 327 | #else |
343 | p.drawPixmap( 0, 0, bluezOffPixmap ); | 328 | p.drawPixmap( 0, 0, bluezOffPixmap ); |
344 | #endif | 329 | #endif |
345 | } | 330 | } |
346 | 331 | ||
347 | if (bluezDiscoveryActive) { | 332 | if (bluezDiscoveryActive) { |
348 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); | 333 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); |
349 | } | 334 | } |
350 | } | 335 | } |
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 | } | ||
360 | }; | 336 | }; |
361 | 337 | ||
362 | 338 | ||
363 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) | 339 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) |
364 | 340 | ||
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index 85022bb..90bee3b 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h | |||
@@ -1,83 +1,81 @@ | |||
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 | #ifndef __BLUEZAPPLET_H__ | 29 | #ifndef __BLUEZAPPLET_H__ |
30 | #define __BLUEZAPPLET_H__ | 30 | #define __BLUEZAPPLET_H__ |
31 | 31 | ||
32 | #include <qwidget.h> | 32 | #include <qwidget.h> |
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 | #include <opie2/oprocess.h> |
37 | 37 | ||
38 | namespace OpieTooth { | 38 | namespace OpieTooth { |
39 | class Device; | 39 | class Device; |
40 | 40 | ||
41 | class BluezApplet : public QWidget { | 41 | class BluezApplet : public QWidget { |
42 | Q_OBJECT | 42 | Q_OBJECT |
43 | public: | 43 | public: |
44 | BluezApplet( QWidget *parent = 0, const char *name=0 ); | 44 | BluezApplet( QWidget *parent = 0, const char *name=0 ); |
45 | ~BluezApplet(); | 45 | ~BluezApplet(); |
46 | static int position(); | 46 | static int position(); |
47 | protected: | 47 | protected: |
48 | void timerEvent(QTimerEvent *te ); | 48 | void timerEvent(QTimerEvent *te ); |
49 | 49 | ||
50 | public slots: | 50 | public slots: |
51 | void fillList( const QString& device, RemoteDevice::ValueList list ); | 51 | void fillList( const QString& device, RemoteDevice::ValueList list ); |
52 | 52 | ||
53 | private: | 53 | private: |
54 | void mousePressEvent( QMouseEvent * ); | 54 | void mousePressEvent( QMouseEvent * ); |
55 | void paintEvent( QPaintEvent* ); | 55 | void paintEvent( QPaintEvent* ); |
56 | void launchManager(); | 56 | void launchManager(); |
57 | bool checkBluezStatus(); | 57 | bool checkBluezStatus(); |
58 | int setBluezStatus(int); | 58 | int setBluezStatus(int); |
59 | int checkBluezDiscoveryStatus(); | 59 | int checkBluezDiscoveryStatus(); |
60 | int setBluezDiscoveryStatus(int); | 60 | int setBluezDiscoveryStatus(int); |
61 | 61 | ||
62 | private: | 62 | private: |
63 | Device* btDevice; | 63 | Device* btDevice; |
64 | Manager *btManager; | 64 | Manager *btManager; |
65 | QPixmap bluezOnPixmap; | 65 | QPixmap bluezOnPixmap; |
66 | QPixmap bluezOffPixmap; | 66 | QPixmap bluezOffPixmap; |
67 | QPixmap bluezDiscoveryOnPixmap; | 67 | QPixmap bluezDiscoveryOnPixmap; |
68 | bool bluezactive; | 68 | bool bluezactive; |
69 | bool bluezDiscoveryActive; | 69 | bool bluezDiscoveryActive; |
70 | bool doListDevice; //If I have to list devices after bringing BT up? | 70 | bool doListDevice; //If I have to list devices after bringing BT up? |
71 | bool isScanning; //If I'm scanning devices | 71 | bool isScanning; //If I'm scanning devices |
72 | bool m_wasOn; //If BT was started by menu? | 72 | bool m_wasOn; //If BT was started by menu? |
73 | 73 | ||
74 | private slots: | 74 | private slots: |
75 | void slotMessage( const QCString& , const QByteArray& ); | 75 | void slotMessage( const QCString& , const QByteArray& ); |
76 | void slotProcessExited(Opie::Core::OProcess* proc); | ||
77 | |||
78 | }; | 76 | }; |
79 | }; | 77 | }; |
80 | 78 | ||
81 | 79 | ||
82 | #endif | 80 | #endif |
83 | 81 | ||