author | korovkin <korovkin> | 2006-07-02 12:08:22 (UTC) |
---|---|---|
committer | korovkin <korovkin> | 2006-07-02 12:08:22 (UTC) |
commit | adcfc6f4afe184a9eb6fbf458616494dfe0dadda (patch) (unidiff) | |
tree | 5111ace883270f8e2f6da6e6578ad07ea7c650c1 | |
parent | b06b849f271079b0dd5d3419ad1162232ff4a9f5 (diff) | |
download | opie-adcfc6f4afe184a9eb6fbf458616494dfe0dadda.zip opie-adcfc6f4afe184a9eb6fbf458616494dfe0dadda.tar.gz opie-adcfc6f4afe184a9eb6fbf458616494dfe0dadda.tar.bz2 |
Added OBEX receive functionality.
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 54 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 4 |
2 files changed, 42 insertions, 16 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index a1d64a4..32560a1 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -1,364 +1,386 @@ | |||
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> |
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 | bluezReceiveOnPixmap = Resource::loadPixmap( "bluetoothapplet/receive.png" ); | ||
67 | #else | 68 | #else |
68 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); | 69 | bluezOnPixmap = OResource::loadImage( "bluetoothapplet/bluezon", OResource::SmallIcon ); |
69 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); | 70 | bluezOffPixmap = OResource::loadImage( "bluetoothapplet/bluezoff", Opie::Core::OResource::SmallIcon ); |
70 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); | 71 | bluezDiscoveryOnPixmap = OResource::loadImage( "bluetoothapplet/bluezondiscovery", Opie::Core::OResource::SmallIcon ); |
72 | bluezReceiveOnPixmap = )Resource::loadImage( "bluetoothapplet/bluezonreceive", Opie::Core::OResource::SmallIcon ); | ||
71 | #endif | 73 | #endif |
72 | startTimer(2000); | 74 | startTimer(2000); |
73 | btDevice = 0; | 75 | btDevice = 0; |
74 | btManager = 0; | 76 | btManager = 0; |
75 | bluezactive = false; | 77 | bluezactive = false; |
76 | bluezDiscoveryActive = false; | 78 | bluezDiscoveryActive = false; |
79 | bluezReceiveActive = false; | ||
80 | bluezReceiveChanged = false; | ||
77 | doListDevice = false; | 81 | doListDevice = false; |
78 | isScanning = false; | 82 | isScanning = false; |
79 | m_wasOn = false; | 83 | m_wasOn = false; |
80 | m_sync = false; | 84 | m_sync = false; |
81 | 85 | ||
82 | // TODO: determine whether this channel has to be closed at destruction time. | 86 | // TODO: determine whether this channel has to be closed at destruction time. |
83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); | 87 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); |
84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 88 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); | 89 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); |
86 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 90 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
87 | } | 91 | } |
88 | 92 | ||
89 | BluezApplet::~BluezApplet() { | 93 | BluezApplet::~BluezApplet() { |
90 | if ( btDevice ) { | 94 | if ( btDevice ) { |
91 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 95 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
92 | delete btDevice; | 96 | delete btDevice; |
93 | } | 97 | } |
94 | if ( btManager ) { | 98 | if ( btManager ) { |
95 | delete btManager; | 99 | delete btManager; |
96 | } | 100 | } |
97 | } | 101 | } |
98 | 102 | ||
99 | int BluezApplet::position() | 103 | int BluezApplet::position() |
100 | { | 104 | { |
101 | return 6; | 105 | return 6; |
102 | } | 106 | } |
103 | 107 | ||
104 | 108 | ||
105 | bool BluezApplet::checkBluezStatus() { | 109 | bool BluezApplet::checkBluezStatus() { |
106 | if (btDevice) { | 110 | if (btDevice) { |
107 | if (btDevice->isLoaded() ) { | 111 | if (btDevice->isLoaded() ) { |
108 | odebug << "btDevice isLoaded" << oendl; | 112 | odebug << "btDevice isLoaded" << oendl; |
109 | return true; | 113 | return true; |
110 | } else { | 114 | } else { |
111 | odebug << "btDevice is NOT loaded" << oendl; | 115 | odebug << "btDevice is NOT loaded" << oendl; |
112 | return false; | 116 | return false; |
113 | } | 117 | } |
114 | } else { | 118 | } else { |
115 | odebug << "btDevice is ZERO" << oendl; | 119 | odebug << "btDevice is ZERO" << oendl; |
116 | return false; | 120 | return false; |
117 | } | 121 | } |
118 | } | 122 | } |
119 | 123 | ||
120 | int BluezApplet::setBluezStatus(int c, bool sync) { | 124 | int BluezApplet::setBluezStatus(int c, bool sync) { |
121 | 125 | ||
122 | if ( c == 1 ) { | 126 | if ( c == 1 ) { |
123 | switch ( ODevice::inst()->model() ) { | 127 | switch ( ODevice::inst()->model() ) { |
124 | case Model_iPAQ_H39xx: | 128 | case Model_iPAQ_H39xx: |
125 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); | 129 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); |
126 | break; | 130 | break; |
127 | 131 | ||
128 | case Model_iPAQ_H5xxx: | 132 | case Model_iPAQ_H5xxx: |
129 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); | 133 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); |
130 | break; | 134 | break; |
131 | 135 | ||
132 | #if OPIE_VERSION >= 102010 | 136 | #if OPIE_VERSION >= 102010 |
133 | case Model_MyPal_716: | 137 | case Model_MyPal_716: |
134 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); | 138 | btDevice = new Device( "/dev/ttyS1", "bcsp", "921600" ); |
135 | break; | 139 | break; |
136 | #endif | 140 | #endif |
137 | 141 | case Model_iPAQ_H22xx: | |
138 | case Model_iPAQ_H22xx: | 142 | btDevice = new Device( "/dev/tts/3", "any", "921600" ); |
139 | btDevice = new Device( "/dev/tts/3", "any", "921600" ); | 143 | break; |
140 | break; | ||
141 | 144 | ||
142 | default: | 145 | default: |
143 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); | 146 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); |
144 | break; | 147 | break; |
145 | } | 148 | } |
146 | m_sync = sync; | 149 | m_sync = sync; |
147 | connect(btDevice, SIGNAL(device(const QString&, bool)), | 150 | connect(btDevice, SIGNAL(device(const QString&, bool)), |
148 | this, SLOT(slotDevice(const QString&, bool))); | 151 | this, SLOT(slotDevice(const QString&, bool))); |
149 | 152 | ||
150 | } else { | 153 | } else { |
154 | setObexRecieveStatus(0); | ||
151 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | 155 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
152 | if ( btManager ) { | 156 | if ( btManager ) { |
153 | delete btManager; | 157 | delete btManager; |
154 | btManager = 0; | 158 | btManager = 0; |
155 | } | 159 | } |
156 | if ( btDevice ) { | 160 | if ( btDevice ) { |
157 | delete btDevice; | 161 | delete btDevice; |
158 | btDevice = 0; | 162 | btDevice = 0; |
159 | } | 163 | } |
160 | } | 164 | } |
161 | return 0; | 165 | return 0; |
162 | } | 166 | } |
163 | 167 | ||
164 | int BluezApplet::checkBluezDiscoveryStatus() { | 168 | int BluezApplet::checkBluezDiscoveryStatus() { |
165 | return isScanning; | 169 | return isScanning; |
166 | } | 170 | } |
167 | 171 | ||
168 | int BluezApplet::setBluezDiscoveryStatus(int d) { | 172 | int BluezApplet::setBluezDiscoveryStatus(int d) { |
169 | return bluezDiscoveryActive = d; | 173 | return bluezDiscoveryActive = d; |
170 | } | 174 | } |
171 | 175 | ||
172 | // FIXME mbhaynie | 176 | int BluezApplet::setObexRecieveStatus(int d) { |
177 | { | ||
178 | QCopEnvelope e ( "QPE/Obex", "btreceive(int)" ); | ||
179 | e << ( d ? 1 : 0 ); | ||
180 | } | ||
181 | bluezReceiveActive = (bool)(d != 0); | ||
182 | bluezReceiveChanged = true; | ||
183 | return d; | ||
184 | } | ||
185 | |||
186 | // FIXME mbhaynie | ||
173 | // receiver for QCopChannel("QPE/Bluetooth") messages. | 187 | // receiver for QCopChannel("QPE/Bluetooth") messages. |
174 | void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) | 188 | void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) |
175 | { | 189 | { |
176 | if ( str == "enableBluetooth()") { | 190 | if ( str == "enableBluetooth()") { |
177 | m_wasOn = checkBluezStatus(); | 191 | m_wasOn = checkBluezStatus(); |
178 | if (!m_wasOn) { | 192 | if (!m_wasOn) { |
179 | setBluezStatus(1, true); | 193 | setBluezStatus(1, true); |
180 | sleep(2); | 194 | sleep(2); |
181 | } | 195 | } |
182 | } | 196 | } |
183 | else if ( str == "disableBluetooth()") { | 197 | else if ( str == "disableBluetooth()") { |
184 | /* | 198 | /* |
185 | * We can down BT only if it was started by qcop. We don't want | 199 | * We can down BT only if it was started by qcop. We don't want |
186 | * to down BT started from menu an break our networking connection | 200 | * to down BT started from menu an break our networking connection |
187 | */ | 201 | */ |
188 | if (checkBluezStatus() && !m_wasOn) | 202 | if (checkBluezStatus() && !m_wasOn) |
189 | setBluezStatus(0); | 203 | setBluezStatus(0); |
190 | doListDevice = false; | 204 | doListDevice = false; |
191 | } | 205 | } |
192 | else if ( str == "listDevices()") { | 206 | else if ( str == "listDevices()") { |
193 | if (checkBluezStatus()) { | 207 | if (checkBluezStatus()) { |
194 | doListDevice = false; | 208 | doListDevice = false; |
195 | timerEvent(0); | 209 | timerEvent(0); |
196 | if (!btManager) { | 210 | if (!btManager) { |
197 | btManager = new Manager("hci0"); | 211 | btManager = new Manager("hci0"); |
198 | connect( btManager, | 212 | connect( btManager, |
199 | SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), | 213 | SIGNAL( foundDevices(const QString&, RemoteDevice::ValueList) ), |
200 | this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; | 214 | this, SLOT( fillList(const QString&, RemoteDevice::ValueList) ) ) ; |
201 | } | 215 | } |
202 | btManager->searchDevices(); | 216 | btManager->searchDevices(); |
203 | isScanning = true; | 217 | isScanning = true; |
204 | } else | 218 | } else |
205 | doListDevice = true; | 219 | doListDevice = true; |
206 | } | 220 | } |
207 | } | 221 | } |
208 | 222 | ||
209 | // Once the hcitool scan is complete, report back. | 223 | // Once the hcitool scan is complete, report back. |
210 | void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) | 224 | void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) |
211 | { | 225 | { |
212 | QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); | 226 | QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); |
213 | 227 | ||
214 | QMap<QString, QString> btmap; | 228 | QMap<QString, QString> btmap; |
215 | 229 | ||
216 | RemoteDevice::ValueList::Iterator it; | 230 | RemoteDevice::ValueList::Iterator it; |
217 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) | 231 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) |
218 | btmap[(*it).name()] = (*it).mac(); | 232 | btmap[(*it).name()] = (*it).mac(); |
219 | 233 | ||
220 | e << btmap; | 234 | e << btmap; |
221 | isScanning = false; | 235 | isScanning = false; |
222 | timerEvent( 0 ); | 236 | timerEvent( 0 ); |
223 | } | 237 | } |
224 | 238 | ||
225 | void BluezApplet::mousePressEvent( QMouseEvent *) { | 239 | void BluezApplet::mousePressEvent( QMouseEvent *) { |
226 | 240 | ||
227 | QPopupMenu *menu = new QPopupMenu(); | 241 | QPopupMenu *menu = new QPopupMenu(); |
228 | QPopupMenu *signal = new QPopupMenu(); | 242 | QPopupMenu *signal = new QPopupMenu(); |
229 | int ret=0; | 243 | int ret=0; |
230 | 244 | ||
231 | /* Refresh active state */ | 245 | /* Refresh active state */ |
232 | timerEvent( 0 ); | 246 | timerEvent( 0 ); |
233 | 247 | ||
234 | 248 | ||
235 | if (bluezactive) { | 249 | if (bluezactive) { |
236 | menu->insertItem( tr("Disable Bluetooth"), 0 ); | 250 | menu->insertItem( tr("Disable Bluetooth"), 0 ); |
237 | } else { | 251 | } else { |
238 | menu->insertItem( tr("Enable Bluetooth"), 1 ); | 252 | menu->insertItem( tr("Enable Bluetooth"), 1 ); |
239 | } | 253 | } |
240 | 254 | ||
241 | menu->insertItem( tr("Launch manager"), 2 ); | 255 | menu->insertItem( tr("Launch manager"), 2 ); |
242 | 256 | ||
243 | menu->insertSeparator(6); | 257 | menu->insertSeparator(6); |
244 | //menu->insertItem( tr("Signal strength"), signal, 5); | 258 | //menu->insertItem( tr("Signal strength"), signal, 5); |
245 | //menu->insertSeparator(8); | 259 | //menu->insertSeparator(8); |
246 | 260 | ||
247 | if (bluezDiscoveryActive) { | 261 | if (bluezactive) { |
248 | menu->insertItem( tr("Disable discovery"), 3 ); | 262 | if (bluezReceiveActive) { |
249 | } else { | 263 | menu->insertItem( tr("Disable receive"), 3 ); |
250 | menu->insertItem( tr("Enable discovery"), 4 ); | 264 | } else { |
251 | } | 265 | menu->insertItem( tr("Enable receive"), 4 ); |
252 | 266 | } | |
267 | } | ||
253 | 268 | ||
254 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | 269 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); |
255 | ret = menu->exec(p, 0); | 270 | ret = menu->exec(p, 0); |
256 | menu->hide(); | 271 | menu->hide(); |
257 | 272 | ||
258 | switch(ret) { | 273 | switch(ret) { |
259 | case 0: | 274 | case 0: |
260 | setBluezStatus(0); | 275 | setBluezStatus(0); |
261 | timerEvent( 0 ); | 276 | timerEvent( 0 ); |
262 | break; | 277 | break; |
263 | case 1: | 278 | case 1: |
264 | setBluezStatus(1); | 279 | setBluezStatus(1); |
265 | timerEvent( 0 ); | 280 | timerEvent( 0 ); |
266 | break; | 281 | break; |
267 | case 2: | 282 | case 2: |
268 | // start bluetoothmanager | 283 | // start bluetoothmanager |
269 | launchManager(); | 284 | launchManager(); |
270 | timerEvent( 0 ); | 285 | timerEvent( 0 ); |
271 | break; | 286 | break; |
272 | case 3: | 287 | case 3: |
273 | setBluezDiscoveryStatus(0); | 288 | setObexRecieveStatus(0); |
274 | timerEvent( 0 ); | 289 | timerEvent( 0 ); |
275 | break; | 290 | break; |
276 | case 4: | 291 | case 4: |
277 | setBluezDiscoveryStatus(1); | 292 | setObexRecieveStatus(1); |
278 | timerEvent(0 ); | 293 | timerEvent( 0 ); |
279 | break; | 294 | break; |
280 | //case 7: | 295 | //case 7: |
281 | // With table of currently-detected devices. | 296 | // With table of currently-detected devices. |
282 | } | 297 | } |
283 | 298 | ||
284 | delete signal; | 299 | delete signal; |
285 | delete menu; | 300 | delete menu; |
286 | } | 301 | } |
287 | 302 | ||
288 | 303 | ||
289 | /** | 304 | /** |
290 | * Launches the bluetooth manager | 305 | * Launches the bluetooth manager |
291 | */ | 306 | */ |
292 | void BluezApplet::launchManager() { | 307 | void BluezApplet::launchManager() { |
293 | QCopEnvelope e("QPE/System", "execute(QString)"); | 308 | QCopEnvelope e("QPE/System", "execute(QString)"); |
294 | e << QString("bluetooth-manager"); | 309 | e << QString("bluetooth-manager"); |
295 | } | 310 | } |
296 | 311 | ||
297 | /** | 312 | /** |
298 | * Refresh timer | 313 | * Refresh timer |
299 | * @param the timer event | 314 | * @param the timer event |
300 | */ | 315 | */ |
301 | void BluezApplet::timerEvent( QTimerEvent * ) { | 316 | void BluezApplet::timerEvent( QTimerEvent * ) { |
302 | bool oldactive = bluezactive; | 317 | bool oldactive = bluezactive; |
303 | int olddiscovery = bluezDiscoveryActive; | 318 | int olddiscovery = bluezDiscoveryActive; |
304 | 319 | ||
305 | bluezactive = checkBluezStatus(); | 320 | bluezactive = checkBluezStatus(); |
306 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); | 321 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); |
307 | 322 | ||
308 | if ((bluezactive != oldactive) || | 323 | if ((bluezactive != oldactive) || |
309 | (bluezDiscoveryActive != olddiscovery)) | 324 | (bluezDiscoveryActive != olddiscovery) || |
325 | bluezReceiveChanged) | ||
310 | update(); | 326 | update(); |
311 | if (bluezactive && doListDevice) { | 327 | if (bluezactive && doListDevice) { |
312 | const QByteArray arr; | 328 | const QByteArray arr; |
313 | slotMessage("listDevices()", arr); | 329 | slotMessage("listDevices()", arr); |
314 | } | 330 | } |
331 | if (bluezReceiveChanged) | ||
332 | bluezReceiveChanged = false; | ||
315 | } | 333 | } |
316 | 334 | ||
317 | /** | 335 | /** |
318 | * Implementation of the paint event | 336 | * Implementation of the paint event |
319 | * @param the QPaintEvent | 337 | * @param the QPaintEvent |
320 | */ | 338 | */ |
321 | void BluezApplet::paintEvent( QPaintEvent* ) { | 339 | void BluezApplet::paintEvent( QPaintEvent* ) { |
322 | QPainter p(this); | 340 | QPainter p(this); |
323 | odebug << "paint bluetooth pixmap" << oendl; | 341 | odebug << "paint bluetooth pixmap" << oendl; |
324 | 342 | ||
325 | if (bluezactive) { | 343 | if (bluezactive) { |
326 | #if OPIE_VERSION < 102010 | 344 | #if OPIE_VERSION < 102010 |
327 | p.drawPixmap( 0, -1, bluezOnPixmap ); | 345 | p.drawPixmap( 0, -1, bluezOnPixmap ); |
328 | #else | 346 | #else |
329 | p.drawPixmap( 0, 0, bluezOnPixmap ); | 347 | p.drawPixmap( 0, 0, bluezOnPixmap ); |
330 | #endif | 348 | #endif |
331 | } else { | 349 | } else { |
332 | #if OPIE_VERSION < 102010 | 350 | #if OPIE_VERSION < 102010 |
333 | p.drawPixmap( 0, -1, bluezOffPixmap ); | 351 | p.drawPixmap( 0, -1, bluezOffPixmap ); |
334 | #else | 352 | #else |
335 | p.drawPixmap( 0, 0, bluezOffPixmap ); | 353 | p.drawPixmap( 0, 0, bluezOffPixmap ); |
336 | #endif | 354 | #endif |
337 | } | 355 | } |
338 | 356 | ||
339 | if (bluezDiscoveryActive) { | 357 | if (bluezDiscoveryActive) { |
340 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); | 358 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); |
341 | } | 359 | } |
360 | if (bluezReceiveActive) { | ||
361 | p.drawPixmap( 0, 0, bluezReceiveOnPixmap ); | ||
362 | } | ||
342 | } | 363 | } |
364 | |||
343 | /** | 365 | /** |
344 | * Reacts on device up | 366 | * Reacts on device up |
345 | * @param name device name | 367 | * @param name device name |
346 | * @param up if device was brought up | 368 | * @param up if device was brought up |
347 | */ | 369 | */ |
348 | void BluezApplet::slotDevice(const QString& name, bool up) | 370 | void BluezApplet::slotDevice(const QString& name, bool up) |
349 | { | 371 | { |
350 | if (!up) | 372 | if (!up) |
351 | return; | 373 | return; |
352 | odebug << name << " is up" << oendl; | 374 | odebug << name << " is up" << oendl; |
353 | if (m_sync) { | 375 | if (m_sync) { |
354 | ::system("/etc/init.d/bluetooth start >/dev/null 2>/dev/null"); | 376 | ::system("/etc/init.d/bluetooth start >/dev/null 2>/dev/null"); |
355 | } else { | 377 | } else { |
356 | QCopEnvelope e("QPE/System", "execute(QString)"); | 378 | QCopEnvelope e("QPE/System", "execute(QString)"); |
357 | e << QString("/etc/init.d/bluetooth start"); | 379 | e << QString("/etc/init.d/bluetooth start"); |
358 | } | 380 | } |
359 | } | 381 | } |
360 | }; | 382 | }; |
361 | 383 | ||
362 | 384 | ||
363 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) | 385 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) |
364 | 386 | ||
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index b79ed5b..9809d20 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h | |||
@@ -1,89 +1,93 @@ | |||
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, 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 | int setObexRecieveStatus(int); | ||
61 | 62 | ||
62 | private: | 63 | private: |
63 | Device* btDevice; | 64 | Device* btDevice; |
64 | Manager *btManager; | 65 | Manager *btManager; |
65 | QPixmap bluezOnPixmap; | 66 | QPixmap bluezOnPixmap; |
66 | QPixmap bluezOffPixmap; | 67 | QPixmap bluezOffPixmap; |
67 | QPixmap bluezDiscoveryOnPixmap; | 68 | QPixmap bluezDiscoveryOnPixmap; |
69 | QPixmap bluezReceiveOnPixmap; | ||
68 | bool bluezactive; | 70 | bool bluezactive; |
69 | bool bluezDiscoveryActive; | 71 | bool bluezDiscoveryActive; |
72 | bool bluezReceiveActive; | ||
73 | bool bluezReceiveChanged; | ||
70 | bool doListDevice; //If I have to list devices after bringing BT up? | 74 | bool doListDevice; //If I have to list devices after bringing BT up? |
71 | bool isScanning; //If I'm scanning devices | 75 | bool isScanning; //If I'm scanning devices |
72 | bool m_wasOn; //If BT was started by menu? | 76 | bool m_wasOn; //If BT was started by menu? |
73 | protected: | 77 | protected: |
74 | bool m_sync; //If we have to bring BT synchronously | 78 | bool m_sync; //If we have to bring BT synchronously |
75 | 79 | ||
76 | private slots: | 80 | private slots: |
77 | void slotMessage( const QCString& , const QByteArray& ); | 81 | void slotMessage( const QCString& , const QByteArray& ); |
78 | /** | 82 | /** |
79 | * Reacts on device up | 83 | * Reacts on device up |
80 | * @param name device name | 84 | * @param name device name |
81 | * @param up if device was brought up | 85 | * @param up if device was brought up |
82 | */ | 86 | */ |
83 | void slotDevice(const QString&, bool); | 87 | void slotDevice(const QString&, bool); |
84 | }; | 88 | }; |
85 | }; | 89 | }; |
86 | 90 | ||
87 | 91 | ||
88 | #endif | 92 | #endif |
89 | 93 | ||