-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 31 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 8 | ||||
-rw-r--r-- | noncore/net/opietooth/lib/device.cc | 5 |
3 files changed, 36 insertions, 8 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index f7774f0..127b0af 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -16,194 +16,194 @@ | |||
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> |
42 | using namespace Opie::Core; | 42 | using 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 | 55 | ||
56 | /* STD */ | 56 | /* STD */ |
57 | #include <device.h> | 57 | #include <device.h> |
58 | 58 | ||
59 | namespace OpieTooth { | 59 | namespace OpieTooth { |
60 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | 60 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { |
61 | setFixedHeight( AppLnk::smallIconSize() ); | 61 | setFixedHeight( AppLnk::smallIconSize() ); |
62 | setFixedWidth( AppLnk::smallIconSize() ); | 62 | setFixedWidth( AppLnk::smallIconSize() ); |
63 | #if OPIE_VERSION < 102010 | 63 | #if OPIE_VERSION < 102010 |
64 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); | 64 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); |
65 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); | 65 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); |
66 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); | 66 | bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass.png" ); |
67 | #else | 67 | #else |
68 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); | 68 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); |
69 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); | 69 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); |
70 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); | 70 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); |
71 | #endif | 71 | #endif |
72 | startTimer(2000); | 72 | startTimer(2000); |
73 | btDevice = 0; | 73 | btDevice = 0; |
74 | btManager = 0; | 74 | btManager = 0; |
75 | bluezactive = false; | 75 | bluezactive = false; |
76 | bluezDiscoveryActive = false; | 76 | bluezDiscoveryActive = false; |
77 | doListDevice = false; | 77 | doListDevice = false; |
78 | isScanning = false; | 78 | isScanning = false; |
79 | m_wasOn = false; | 79 | m_wasOn = false; |
80 | m_sync = false; | ||
80 | 81 | ||
81 | // 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. |
82 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); | 83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); |
83 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
84 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); | 85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); |
85 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 86 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
86 | } | 87 | } |
87 | 88 | ||
88 | BluezApplet::~BluezApplet() { | 89 | BluezApplet::~BluezApplet() { |
89 | if ( btDevice ) { | 90 | if ( btDevice ) { |
91 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | ||
90 | delete btDevice; | 92 | delete btDevice; |
91 | } | 93 | } |
92 | if ( btManager ) { | 94 | if ( btManager ) { |
93 | delete btManager; | 95 | delete btManager; |
94 | } | 96 | } |
95 | } | 97 | } |
96 | 98 | ||
97 | int BluezApplet::position() | 99 | int BluezApplet::position() |
98 | { | 100 | { |
99 | return 6; | 101 | return 6; |
100 | } | 102 | } |
101 | 103 | ||
102 | 104 | ||
103 | bool BluezApplet::checkBluezStatus() { | 105 | bool BluezApplet::checkBluezStatus() { |
104 | if (btDevice) { | 106 | if (btDevice) { |
105 | if (btDevice->isLoaded() ) { | 107 | if (btDevice->isLoaded() ) { |
106 | odebug << "btDevice isLoaded" << oendl; | 108 | odebug << "btDevice isLoaded" << oendl; |
107 | return true; | 109 | return true; |
108 | } else { | 110 | } else { |
109 | odebug << "btDevice is NOT loaded" << oendl; | 111 | odebug << "btDevice is NOT loaded" << oendl; |
110 | return false; | 112 | return false; |
111 | } | 113 | } |
112 | } else { | 114 | } else { |
113 | odebug << "btDevice is ZERO" << oendl; | 115 | odebug << "btDevice is ZERO" << oendl; |
114 | return false; | 116 | return false; |
115 | } | 117 | } |
116 | } | 118 | } |
117 | 119 | ||
118 | int BluezApplet::setBluezStatus(int c, bool sync) { | 120 | int BluezApplet::setBluezStatus(int c, bool sync) { |
119 | 121 | ||
120 | if ( c == 1 ) { | 122 | if ( c == 1 ) { |
121 | switch ( ODevice::inst()->model() ) { | 123 | switch ( ODevice::inst()->model() ) { |
122 | case Model_iPAQ_H39xx: | 124 | case Model_iPAQ_H39xx: |
123 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); | 125 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); |
124 | break; | 126 | break; |
125 | 127 | ||
126 | case Model_iPAQ_H5xxx: | 128 | case Model_iPAQ_H5xxx: |
127 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); | 129 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); |
128 | break; | 130 | break; |
129 | 131 | ||
130 | #ifndef OPIE120 | 132 | #if OPIE_VERSION >= 102010 |
131 | case Model_MyPal_716: | 133 | case Model_MyPal_716: |
132 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); | 134 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); |
133 | break; | 135 | break; |
134 | #endif | 136 | #endif |
135 | 137 | ||
136 | default: | 138 | default: |
137 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); | 139 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); |
138 | break; | 140 | break; |
139 | } | 141 | } |
140 | if (sync) { | 142 | m_sync = sync; |
141 | ::system("/etc/init.d/bluetooth start >/dev/null 2>/dev/null"); | 143 | connect(btDevice, SIGNAL(device(const QString&, bool)), |
142 | } else { | 144 | this, SLOT(slotDevice(const QString&, bool))); |
143 | QCopEnvelope e("QPE/System", "execute(QString)"); | 145 | |
144 | e << QString("/etc/init.d/bluetooth start"); | ||
145 | } | ||
146 | } else { | 146 | } else { |
147 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 147 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
148 | if ( btManager ) { | 148 | if ( btManager ) { |
149 | delete btManager; | 149 | delete btManager; |
150 | btManager = 0; | 150 | btManager = 0; |
151 | } | 151 | } |
152 | if ( btDevice ) { | 152 | if ( btDevice ) { |
153 | delete btDevice; | 153 | delete btDevice; |
154 | btDevice = 0; | 154 | btDevice = 0; |
155 | } | 155 | } |
156 | } | 156 | } |
157 | return 0; | 157 | return 0; |
158 | } | 158 | } |
159 | 159 | ||
160 | int BluezApplet::checkBluezDiscoveryStatus() { | 160 | int BluezApplet::checkBluezDiscoveryStatus() { |
161 | return isScanning; | 161 | return isScanning; |
162 | } | 162 | } |
163 | 163 | ||
164 | int BluezApplet::setBluezDiscoveryStatus(int d) { | 164 | int BluezApplet::setBluezDiscoveryStatus(int d) { |
165 | return bluezDiscoveryActive = d; | 165 | return bluezDiscoveryActive = d; |
166 | } | 166 | } |
167 | 167 | ||
168 | // FIXME mbhaynie | 168 | // FIXME mbhaynie |
169 | // receiver for QCopChannel("QPE/Bluetooth") messages. | 169 | // receiver for QCopChannel("QPE/Bluetooth") messages. |
170 | void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) | 170 | void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) |
171 | { | 171 | { |
172 | if ( str == "enableBluetooth()") { | 172 | if ( str == "enableBluetooth()") { |
173 | m_wasOn = checkBluezStatus(); | 173 | m_wasOn = checkBluezStatus(); |
174 | if (!m_wasOn) { | 174 | if (!m_wasOn) { |
175 | setBluezStatus(1, true); | 175 | setBluezStatus(1, true); |
176 | sleep(2); | 176 | sleep(2); |
177 | } | 177 | } |
178 | } | 178 | } |
179 | else if ( str == "disableBluetooth()") { | 179 | else if ( str == "disableBluetooth()") { |
180 | /* | 180 | /* |
181 | * We can down BT only if it was started by qcop. We don't want | 181 | * We can down BT only if it was started by qcop. We don't want |
182 | * to down BT started from menu an break our networking connection | 182 | * to down BT started from menu an break our networking connection |
183 | */ | 183 | */ |
184 | if (checkBluezStatus() && !m_wasOn) | 184 | if (checkBluezStatus() && !m_wasOn) |
185 | setBluezStatus(0); | 185 | setBluezStatus(0); |
186 | doListDevice = false; | 186 | doListDevice = false; |
187 | } | 187 | } |
188 | else if ( str == "listDevices()") { | 188 | else if ( str == "listDevices()") { |
189 | if (checkBluezStatus()) { | 189 | if (checkBluezStatus()) { |
190 | doListDevice = false; | 190 | doListDevice = false; |
191 | timerEvent(0); | 191 | timerEvent(0); |
192 | if (!btManager) { | 192 | if (!btManager) { |
193 | btManager = new Manager("hci0"); | 193 | btManager = new Manager("hci0"); |
194 | connect( btManager, | 194 | connect( btManager, |
195 | SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), | 195 | SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), |
196 | this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; | 196 | this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; |
197 | } | 197 | } |
198 | btManager->searchDevices(); | 198 | btManager->searchDevices(); |
199 | isScanning = true; | 199 | isScanning = true; |
200 | } else | 200 | } else |
201 | doListDevice = true; | 201 | doListDevice = true; |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | // Once the hcitool scan is complete, report back. | 205 | // Once the hcitool scan is complete, report back. |
206 | void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) | 206 | void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) |
207 | { | 207 | { |
208 | QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); | 208 | QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); |
209 | 209 | ||
@@ -275,69 +275,86 @@ namespace OpieTooth { | |||
275 | break; | 275 | break; |
276 | //case 7: | 276 | //case 7: |
277 | // With table of currently-detected devices. | 277 | // With table of currently-detected devices. |
278 | } | 278 | } |
279 | 279 | ||
280 | delete signal; | 280 | delete signal; |
281 | delete menu; | 281 | delete menu; |
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | /** | 285 | /** |
286 | * Launches the bluetooth manager | 286 | * Launches the bluetooth manager |
287 | */ | 287 | */ |
288 | void BluezApplet::launchManager() { | 288 | void BluezApplet::launchManager() { |
289 | QCopEnvelope e("QPE/System", "execute(QString)"); | 289 | QCopEnvelope e("QPE/System", "execute(QString)"); |
290 | e << QString("bluetooth-manager"); | 290 | e << QString("bluetooth-manager"); |
291 | } | 291 | } |
292 | 292 | ||
293 | /** | 293 | /** |
294 | * Refresh timer | 294 | * Refresh timer |
295 | * @param the timer event | 295 | * @param the timer event |
296 | */ | 296 | */ |
297 | void BluezApplet::timerEvent( QTimerEvent * ) { | 297 | void BluezApplet::timerEvent( QTimerEvent * ) { |
298 | bool oldactive = bluezactive; | 298 | bool oldactive = bluezactive; |
299 | int olddiscovery = bluezDiscoveryActive; | 299 | int olddiscovery = bluezDiscoveryActive; |
300 | 300 | ||
301 | bluezactive = checkBluezStatus(); | 301 | bluezactive = checkBluezStatus(); |
302 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); | 302 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); |
303 | 303 | ||
304 | if ((bluezactive != oldactive) || | 304 | if ((bluezactive != oldactive) || |
305 | (bluezDiscoveryActive != olddiscovery)) | 305 | (bluezDiscoveryActive != olddiscovery)) |
306 | update(); | 306 | update(); |
307 | if (bluezactive && doListDevice) { | 307 | if (bluezactive && doListDevice) { |
308 | const QByteArray arr; | 308 | const QByteArray arr; |
309 | slotMessage("listDevices()", arr); | 309 | slotMessage("listDevices()", arr); |
310 | } | 310 | } |
311 | } | 311 | } |
312 | 312 | ||
313 | /** | 313 | /** |
314 | * Implementation of the paint event | 314 | * Implementation of the paint event |
315 | * @param the QPaintEvent | 315 | * @param the QPaintEvent |
316 | */ | 316 | */ |
317 | void BluezApplet::paintEvent( QPaintEvent* ) { | 317 | void BluezApplet::paintEvent( QPaintEvent* ) { |
318 | QPainter p(this); | 318 | QPainter p(this); |
319 | odebug << "paint bluetooth pixmap" << oendl; | 319 | odebug << "paint bluetooth pixmap" << oendl; |
320 | 320 | ||
321 | if (bluezactive) { | 321 | if (bluezactive) { |
322 | #if OPIE_VERSION < 102010 | 322 | #if OPIE_VERSION < 102010 |
323 | p.drawPixmap( 0, -1, bluezOnPixmap ); | 323 | p.drawPixmap( 0, -1, bluezOnPixmap ); |
324 | #else | 324 | #else |
325 | p.drawPixmap( 0, 0, bluezOnPixmap ); | 325 | p.drawPixmap( 0, 0, bluezOnPixmap ); |
326 | #endif | 326 | #endif |
327 | } else { | 327 | } else { |
328 | #if OPIE_VERSION < 102010 | 328 | #if OPIE_VERSION < 102010 |
329 | p.drawPixmap( 0, -1, bluezOffPixmap ); | 329 | p.drawPixmap( 0, -1, bluezOffPixmap ); |
330 | #else | 330 | #else |
331 | p.drawPixmap( 0, 0, bluezOffPixmap ); | 331 | p.drawPixmap( 0, 0, bluezOffPixmap ); |
332 | #endif | 332 | #endif |
333 | } | 333 | } |
334 | 334 | ||
335 | if (bluezDiscoveryActive) { | 335 | if (bluezDiscoveryActive) { |
336 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); | 336 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); |
337 | } | 337 | } |
338 | } | 338 | } |
339 | /** | ||
340 | * Reacts on device up | ||
341 | * @param name device name | ||
342 | * @param up if device was brought up | ||
343 | */ | ||
344 | void BluezApplet::slotDevice(const QString& name, bool up) | ||
345 | { | ||
346 | if (!up) | ||
347 | return; | ||
348 | odebug << name << " is up" << oendl; | ||
349 | if (m_sync) { | ||
350 | ::system("/etc/init.d/bluetooth start >/dev/null 2>/dev/null"); | ||
351 | } else { | ||
352 | QCopEnvelope e("QPE/System", "execute(QString)"); | ||
353 | e << QString("/etc/init.d/bluetooth start"); | ||
354 | } | ||
355 | } | ||
339 | }; | 356 | }; |
340 | 357 | ||
341 | 358 | ||
342 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) | 359 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) |
343 | 360 | ||
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index 1937934..b79ed5b 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h | |||
@@ -9,73 +9,81 @@ | |||
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, bool sync = false); | 58 | int setBluezStatus(int, bool sync = false); |
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 | protected: | ||
74 | bool m_sync; //If we have to bring BT synchronously | ||
73 | 75 | ||
74 | private slots: | 76 | private slots: |
75 | void slotMessage( const QCString& , const QByteArray& ); | 77 | void slotMessage( const QCString& , const QByteArray& ); |
78 | /** | ||
79 | * Reacts on device up | ||
80 | * @param name device name | ||
81 | * @param up if device was brought up | ||
82 | */ | ||
83 | void slotDevice(const QString&, bool); | ||
76 | }; | 84 | }; |
77 | }; | 85 | }; |
78 | 86 | ||
79 | 87 | ||
80 | #endif | 88 | #endif |
81 | 89 | ||
diff --git a/noncore/net/opietooth/lib/device.cc b/noncore/net/opietooth/lib/device.cc index 2f04d46..88d4cf9 100644 --- a/noncore/net/opietooth/lib/device.cc +++ b/noncore/net/opietooth/lib/device.cc | |||
@@ -65,118 +65,121 @@ Device::~Device(){ | |||
65 | void Device::attach(){ | 65 | void Device::attach(){ |
66 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; | 66 | owarn << "attaching " << m_device.latin1() << " " << m_mode.latin1() << " " << m_speed.latin1() << oendl; |
67 | if(m_process == 0 ){ | 67 | if(m_process == 0 ){ |
68 | m_output.resize(0); | 68 | m_output.resize(0); |
69 | owarn << "new process to create" << oendl; | 69 | owarn << "new process to create" << oendl; |
70 | m_process = new OProcess(); | 70 | m_process = new OProcess(); |
71 | *m_process << "hciattach"; | 71 | *m_process << "hciattach"; |
72 | *m_process << "-p"; | 72 | *m_process << "-p"; |
73 | 73 | ||
74 | // FIXME -- this is a hack for an odd hciattach interface. | 74 | // FIXME -- this is a hack for an odd hciattach interface. |
75 | if ( ODevice::inst()->modelString() == "HX4700" ) | 75 | if ( ODevice::inst()->modelString() == "HX4700" ) |
76 | *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; | 76 | *m_process << "-S" << "/etc/bluetooth/TIInit_3.2.26.bts" << "/dev/ttyS1" << "texas"; |
77 | else | 77 | else |
78 | *m_process << m_device << m_mode << m_speed; | 78 | *m_process << m_device << m_mode << m_speed; |
79 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | 79 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), |
80 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 80 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
81 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), | 81 | connect(m_process, SIGNAL( receivedStdout(Opie::Core::OProcess*, char*, int) ), |
82 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); | 82 | this, SLOT(slotStdOut(Opie::Core::OProcess*,char*,int ) ) ); |
83 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), | 83 | connect(m_process, SIGNAL(receivedStderr(Opie::Core::OProcess*, char*, int ) ), |
84 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); | 84 | this, SLOT(slotStdErr(Opie::Core::OProcess*,char*,int) ) ); |
85 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ | 85 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ){ |
86 | owarn << "Could not start" << oendl; | 86 | owarn << "Could not start" << oendl; |
87 | delete m_process; | 87 | delete m_process; |
88 | m_process = 0; | 88 | m_process = 0; |
89 | } | 89 | } |
90 | } | 90 | } |
91 | } | 91 | } |
92 | void Device::detach(){ | 92 | void Device::detach(){ |
93 | delete m_hci; | 93 | delete m_hci; |
94 | m_hci = 0; | 94 | m_hci = 0; |
95 | delete m_process; | 95 | delete m_process; |
96 | m_process = 0; | 96 | m_process = 0; |
97 | // kill the pid we got | 97 | // kill the pid we got |
98 | if(m_attached ){ | 98 | if(m_attached ){ |
99 | //kill the pid | 99 | //kill the pid |
100 | owarn << "killing" << oendl; | 100 | owarn << "killing" << oendl; |
101 | ::kill(pid, 9); | 101 | ::kill(pid, 9); |
102 | } | 102 | } |
103 | owarn << "detached" << oendl; | 103 | owarn << "detached" << oendl; |
104 | } | 104 | } |
105 | bool Device::isLoaded()const{ | 105 | bool Device::isLoaded()const{ |
106 | return m_attached; | 106 | return m_attached; |
107 | } | 107 | } |
108 | QString Device::devName()const { | 108 | QString Device::devName()const { |
109 | return QString::fromLatin1("hci0"); | 109 | return QString::fromLatin1("hci0"); |
110 | }; | 110 | }; |
111 | void Device::slotExited( OProcess* proc) | 111 | void Device::slotExited( OProcess* proc) |
112 | { | 112 | { |
113 | owarn << "prcess exited" << oendl; | 113 | owarn << "prcess exited" << oendl; |
114 | if(proc== m_process ){ | 114 | if(proc== m_process ){ |
115 | owarn << "proc == m_process" << oendl; | 115 | owarn << "proc == m_process" << oendl; |
116 | if( m_process->normalExit() ){ // normal exit | 116 | if( m_process->normalExit() ){ // normal exit |
117 | owarn << "normalExit" << oendl; | 117 | owarn << "normalExit" << oendl; |
118 | int ret = m_process->exitStatus(); | 118 | int ret = m_process->exitStatus(); |
119 | if( ret == 0 ){ // attached | 119 | if( ret == 0 ){ // attached |
120 | owarn << "attached" << oendl; | 120 | owarn << "attached" << oendl; |
121 | owarn << "Output: " << m_output.data() << oendl; | 121 | owarn << "Output: " << m_output.data() << oendl; |
122 | pid = parsePid( m_output ); | 122 | pid = parsePid( m_output ); |
123 | owarn << "Pid = " << pid << oendl; | 123 | owarn << "Pid = " << pid << oendl; |
124 | // now hciconfig hci0 up ( determine hciX FIXME) | 124 | // now hciconfig hci0 up ( determine hciX FIXME) |
125 | // and call hciconfig hci0 up | 125 | // and call hciconfig hci0 up |
126 | // FIXME hardcoded to hci0 now :( | 126 | // FIXME hardcoded to hci0 now :( |
127 | m_hci = new OProcess( ); | 127 | m_hci = new OProcess( ); |
128 | *m_hci << "hciconfig"; | 128 | *m_hci << "hciconfig"; |
129 | *m_hci << "hci0 up"; | 129 | *m_hci << "hci0"; |
130 | *m_hci << "up"; | ||
130 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), | 131 | connect(m_hci, SIGNAL( processExited(Opie::Core::OProcess*) ), |
131 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | 132 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); |
132 | if(!m_hci->start() ){ | 133 | if(!m_hci->start() ){ |
133 | owarn << "could not start" << oendl; | 134 | owarn << "could not start" << oendl; |
134 | m_attached = false; | 135 | m_attached = false; |
135 | emit device("hci0", false ); | 136 | emit device("hci0", false ); |
136 | } | 137 | } |
137 | }else{ | 138 | }else{ |
138 | owarn << "crass" << oendl; | 139 | owarn << "crass" << oendl; |
139 | m_attached = false; | 140 | m_attached = false; |
140 | emit device("hci0", false ); | 141 | emit device("hci0", false ); |
141 | 142 | ||
142 | } | 143 | } |
143 | } | 144 | } |
144 | delete m_process; | 145 | delete m_process; |
145 | m_process = 0; | 146 | m_process = 0; |
146 | }else if(proc== m_hci ){ | 147 | }else if(proc== m_hci ){ |
147 | owarn << "M HCI exited" << oendl; | 148 | owarn << "M HCI exited" << oendl; |
148 | if( m_hci->normalExit() ){ | 149 | if( m_hci->normalExit() ){ |
149 | owarn << "normal exit" << oendl; | 150 | owarn << "normal exit" << oendl; |
150 | int ret = m_hci->exitStatus(); | 151 | int ret = m_hci->exitStatus(); |
151 | if( ret == 0 ){ | 152 | if( ret == 0 ){ |
152 | owarn << "attached really really attached" << oendl; | 153 | owarn << "attached really really attached" << oendl; |
153 | m_attached = true; | 154 | m_attached = true; |
155 | //Wait for a device to be brought up | ||
156 | ::sleep(1); | ||
154 | emit device("hci0", true ); | 157 | emit device("hci0", true ); |
155 | }else{ | 158 | }else{ |
156 | owarn << "failed" << oendl; | 159 | owarn << "failed" << oendl; |
157 | emit device("hci0", false ); | 160 | emit device("hci0", false ); |
158 | m_attached = false; | 161 | m_attached = false; |
159 | } | 162 | } |
160 | }// normal exit | 163 | }// normal exit |
161 | delete m_hci; | 164 | delete m_hci; |
162 | m_hci = 0; | 165 | m_hci = 0; |
163 | } | 166 | } |
164 | } | 167 | } |
165 | void Device::slotStdOut(OProcess* proc, char* chars, int len) | 168 | void Device::slotStdOut(OProcess* proc, char* chars, int len) |
166 | { | 169 | { |
167 | owarn << "std out" << oendl; | 170 | owarn << "std out" << oendl; |
168 | if( len <1 ){ | 171 | if( len <1 ){ |
169 | owarn << "len < 1 " << oendl; | 172 | owarn << "len < 1 " << oendl; |
170 | return; | 173 | return; |
171 | } | 174 | } |
172 | if(proc == m_process ){ | 175 | if(proc == m_process ){ |
173 | QCString string( chars, len+1 ); // \0 == +1 | 176 | QCString string( chars, len+1 ); // \0 == +1 |
174 | owarn << "output: " << string.data() << oendl; | 177 | owarn << "output: " << string.data() << oendl; |
175 | m_output.append( string.data() ); | 178 | m_output.append( string.data() ); |
176 | } | 179 | } |
177 | } | 180 | } |
178 | void Device::slotStdErr(OProcess* proc, char* chars, int len) | 181 | void Device::slotStdErr(OProcess* proc, char* chars, int len) |
179 | { | 182 | { |
180 | owarn << "std err" << oendl; | 183 | owarn << "std err" << oendl; |
181 | slotStdOut( proc, chars, len ); | 184 | slotStdOut( proc, chars, len ); |
182 | } | 185 | } |