Diffstat (limited to 'noncore/net/opietooth/applet/bluezapplet.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 143 |
1 files changed, 109 insertions, 34 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 | |||
@@ -36,2 +36,3 @@ | |||
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> |
@@ -51,2 +52,3 @@ using namespace Opie::Core; | |||
51 | #include <qpopupmenu.h> | 52 | #include <qpopupmenu.h> |
53 | #include <qmessagebox.h> | ||
52 | 54 | ||
@@ -55,4 +57,5 @@ using namespace Opie::Core; | |||
55 | 57 | ||
56 | namespace OpieTooth { | 58 | // #define OPIE120 // undefine it fo the latest OPIE |
57 | 59 | ||
60 | namespace OpieTooth { | ||
58 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | 61 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { |
@@ -60,2 +63,7 @@ namespace OpieTooth { | |||
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 ); |
@@ -63,3 +71,4 @@ namespace OpieTooth { | |||
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; |
@@ -68,2 +77,5 @@ namespace OpieTooth { | |||
68 | bluezDiscoveryActive = false; | 77 | bluezDiscoveryActive = false; |
78 | doListDevice = false; | ||
79 | isScanning = false; | ||
80 | m_wasOn = false; | ||
69 | 81 | ||
@@ -73,2 +85,12 @@ namespace OpieTooth { | |||
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 | } |
@@ -104,2 +126,3 @@ int BluezApplet::position() | |||
104 | 126 | ||
127 | OProcess* btstart = new OProcess(); | ||
105 | if ( c == 1 ) { | 128 | if ( c == 1 ) { |
@@ -110,6 +133,7 @@ int BluezApplet::position() | |||
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: |
@@ -117,2 +141,3 @@ int BluezApplet::position() | |||
117 | break; | 141 | break; |
142 | #endif | ||
118 | 143 | ||
@@ -122,3 +147,19 @@ int BluezApplet::position() | |||
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 ) { |
@@ -132,3 +173,3 @@ int BluezApplet::position() | |||
132 | int BluezApplet::checkBluezDiscoveryStatus() { | 173 | int BluezApplet::checkBluezDiscoveryStatus() { |
133 | return bluezDiscoveryActive; | 174 | return isScanning; |
134 | } | 175 | } |
@@ -136,3 +177,3 @@ int BluezApplet::position() | |||
136 | int BluezApplet::setBluezDiscoveryStatus(int d) { | 177 | int BluezApplet::setBluezDiscoveryStatus(int d) { |
137 | return bluezDiscoveryActive=d; | 178 | return bluezDiscoveryActive = d; |
138 | } | 179 | } |
@@ -143,20 +184,33 @@ int BluezApplet::position() | |||
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 | } |
@@ -166,6 +220,5 @@ int BluezApplet::position() | |||
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 | ||
@@ -173,7 +226,7 @@ int BluezApplet::position() | |||
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 | } |
@@ -262,4 +315,8 @@ int BluezApplet::position() | |||
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 | } |
@@ -275,9 +332,17 @@ int BluezApplet::position() | |||
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 ); |
@@ -285,4 +350,14 @@ int BluezApplet::position() | |||
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 | |||
288 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) | 363 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) |