-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 51 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 5 |
2 files changed, 56 insertions, 0 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index 8925803..48698b6 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -2,186 +2,237 @@ | |||
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 <qpe/applnk.h> | 36 | #include <qpe/applnk.h> |
37 | #include <qpe/qcopenvelope_qws.h> | 37 | #include <qpe/qcopenvelope_qws.h> |
38 | #include <qpe/config.h> | 38 | #include <qpe/config.h> |
39 | #include <qpe/resource.h> | 39 | #include <qpe/resource.h> |
40 | using namespace Opie::Core; | 40 | using namespace Opie::Core; |
41 | 41 | ||
42 | /* QT */ | 42 | /* QT */ |
43 | #include <qapplication.h> | 43 | #include <qapplication.h> |
44 | #include <qpoint.h> | 44 | #include <qpoint.h> |
45 | #include <qpainter.h> | 45 | #include <qpainter.h> |
46 | #include <qlayout.h> | 46 | #include <qlayout.h> |
47 | #include <qframe.h> | 47 | #include <qframe.h> |
48 | #include <qpixmap.h> | 48 | #include <qpixmap.h> |
49 | #include <qstring.h> | 49 | #include <qstring.h> |
50 | #include <qtimer.h> | 50 | #include <qtimer.h> |
51 | #include <qpopupmenu.h> | 51 | #include <qpopupmenu.h> |
52 | 52 | ||
53 | /* STD */ | 53 | /* STD */ |
54 | #include <device.h> | 54 | #include <device.h> |
55 | 55 | ||
56 | namespace OpieTooth { | 56 | namespace OpieTooth { |
57 | 57 | ||
58 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | 58 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { |
59 | setFixedHeight( AppLnk::smallIconSize() ); | 59 | setFixedHeight( AppLnk::smallIconSize() ); |
60 | setFixedWidth( AppLnk::smallIconSize() ); | 60 | setFixedWidth( AppLnk::smallIconSize() ); |
61 | bluezOnPixmap = Resource::loadImage( "bluetoothapplet/bluezon" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 61 | bluezOnPixmap = Resource::loadImage( "bluetoothapplet/bluezon" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
62 | bluezOffPixmap = Resource::loadImage( "bluetoothapplet/bluezoff" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); | 62 | bluezOffPixmap = Resource::loadImage( "bluetoothapplet/bluezoff" ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ); |
63 | //bluezDiscoveryOnPixmap = Resource::loadImage( "bluetoothapplet/magglass" )smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize()); | 63 | //bluezDiscoveryOnPixmap = Resource::loadImage( "bluetoothapplet/magglass" )smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize()); |
64 | startTimer(4000); | 64 | startTimer(4000); |
65 | btDevice = 0; | 65 | btDevice = 0; |
66 | btManager = 0; | ||
66 | bluezactive = false; | 67 | bluezactive = false; |
67 | bluezDiscoveryActive = false; | 68 | bluezDiscoveryActive = false; |
68 | 69 | ||
70 | // TODO: determine whether this channel has to be closed at destruction time. | ||
71 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); | ||
72 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | ||
73 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); | ||
69 | } | 74 | } |
70 | 75 | ||
71 | BluezApplet::~BluezApplet() { | 76 | BluezApplet::~BluezApplet() { |
72 | if ( btDevice ) { | 77 | if ( btDevice ) { |
73 | delete btDevice; | 78 | delete btDevice; |
74 | } | 79 | } |
80 | if ( btManager ) { | ||
81 | delete btManager; | ||
82 | } | ||
75 | } | 83 | } |
76 | 84 | ||
77 | int BluezApplet::position() | 85 | int BluezApplet::position() |
78 | { | 86 | { |
79 | return 6; | 87 | return 6; |
80 | } | 88 | } |
81 | 89 | ||
82 | 90 | ||
83 | bool BluezApplet::checkBluezStatus() { | 91 | bool BluezApplet::checkBluezStatus() { |
84 | if (btDevice) { | 92 | if (btDevice) { |
85 | if (btDevice->isLoaded() ) { | 93 | if (btDevice->isLoaded() ) { |
86 | return true; | 94 | return true; |
87 | } else { | 95 | } else { |
88 | return false; | 96 | return false; |
89 | } | 97 | } |
90 | } else { | 98 | } else { |
91 | return false; | 99 | return false; |
92 | } | 100 | } |
93 | } | 101 | } |
94 | 102 | ||
95 | int BluezApplet::setBluezStatus(int c) { | 103 | int BluezApplet::setBluezStatus(int c) { |
96 | 104 | ||
97 | if ( c == 1 ) { | 105 | if ( c == 1 ) { |
98 | switch ( ODevice::inst()->model() ) { | 106 | switch ( ODevice::inst()->model() ) { |
99 | case Model_iPAQ_H39xx: | 107 | case Model_iPAQ_H39xx: |
100 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); | 108 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); |
101 | break; | 109 | break; |
102 | 110 | ||
103 | case Model_iPAQ_H5xxx: | 111 | case Model_iPAQ_H5xxx: |
104 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); | 112 | btDevice = new Device( "/dev/tts/1", "any", "921600" ); |
105 | break; | 113 | break; |
106 | 114 | ||
107 | default: | 115 | default: |
108 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); | 116 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); |
109 | break; | 117 | break; |
110 | } | 118 | } |
111 | } else { | 119 | } else { |
112 | if ( btDevice ) { | 120 | if ( btDevice ) { |
113 | delete btDevice; | 121 | delete btDevice; |
114 | btDevice = 0; | 122 | btDevice = 0; |
115 | } | 123 | } |
116 | } | 124 | } |
117 | return 0; | 125 | return 0; |
118 | } | 126 | } |
119 | 127 | ||
120 | int BluezApplet::checkBluezDiscoveryStatus() { | 128 | int BluezApplet::checkBluezDiscoveryStatus() { |
129 | return bluezDiscoveryActive; | ||
121 | } | 130 | } |
122 | 131 | ||
123 | int BluezApplet::setBluezDiscoveryStatus(int d) { | 132 | int BluezApplet::setBluezDiscoveryStatus(int d) { |
133 | return bluezDiscoveryActive=d; | ||
134 | } | ||
135 | |||
136 | // FIXME mbhaynie | ||
137 | // receiver for QCopChannel("QPE/Bluetooth") messages. | ||
138 | void BluezApplet::slotMessage( const QCString& str, const QByteArray& ) | ||
139 | { | ||
140 | if ( str == "enableBluetooth()") { | ||
141 | if (!checkBluezStatus()) { | ||
142 | setBluezStatus(1); | ||
143 | } | ||
144 | } else if ( str == "disableBluetooth()") { | ||
145 | if (checkBluezStatus()) { | ||
146 | // setBluezStatus(0); | ||
147 | } | ||
148 | } else if ( str == "listDevices()") { | ||
149 | if (!btManager) | ||
150 | { | ||
151 | btManager = new Manager("hci0"); | ||
152 | connect( btManager, SIGNAL( foundDevices(const QString&,RemoteDevice::ValueList) ), | ||
153 | this, SLOT( fillList(const QString&,RemoteDevice::ValueList) ) ) ; | ||
154 | } | ||
155 | |||
156 | btManager->searchDevices(); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | // Once the hcitool scan is complete, report back. | ||
161 | void BluezApplet::fillList(const QString&, RemoteDevice::ValueList deviceList) | ||
162 | { | ||
163 | QCopEnvelope e("QPE/BluetoothBack", "devices(QStringMap)"); | ||
164 | |||
165 | QStringList list; | ||
166 | QMap<QString, QString> btmap; | ||
167 | |||
168 | RemoteDevice::ValueList::Iterator it; | ||
169 | for( it = deviceList.begin(); it != deviceList.end(); ++it ) | ||
170 | { | ||
171 | btmap[(*it).name()] = (*it).mac(); | ||
172 | } | ||
173 | |||
174 | e << btmap; | ||
124 | } | 175 | } |
125 | 176 | ||
126 | void BluezApplet::mousePressEvent( QMouseEvent *) { | 177 | void BluezApplet::mousePressEvent( QMouseEvent *) { |
127 | 178 | ||
128 | QPopupMenu *menu = new QPopupMenu(); | 179 | QPopupMenu *menu = new QPopupMenu(); |
129 | QPopupMenu *signal = new QPopupMenu(); | 180 | QPopupMenu *signal = new QPopupMenu(); |
130 | int ret=0; | 181 | int ret=0; |
131 | 182 | ||
132 | /* Refresh active state */ | 183 | /* Refresh active state */ |
133 | timerEvent( 0 ); | 184 | timerEvent( 0 ); |
134 | 185 | ||
135 | 186 | ||
136 | if (bluezactive) { | 187 | if (bluezactive) { |
137 | menu->insertItem( tr("Disable Bluetooth"), 0 ); | 188 | menu->insertItem( tr("Disable Bluetooth"), 0 ); |
138 | } else { | 189 | } else { |
139 | menu->insertItem( tr("Enable Bluetooth"), 1 ); | 190 | menu->insertItem( tr("Enable Bluetooth"), 1 ); |
140 | } | 191 | } |
141 | 192 | ||
142 | menu->insertItem( tr("Launch manager"), 2 ); | 193 | menu->insertItem( tr("Launch manager"), 2 ); |
143 | 194 | ||
144 | menu->insertSeparator(6); | 195 | menu->insertSeparator(6); |
145 | //menu->insertItem( tr("Signal strength"), signal, 5); | 196 | //menu->insertItem( tr("Signal strength"), signal, 5); |
146 | //menu->insertSeparator(8); | 197 | //menu->insertSeparator(8); |
147 | 198 | ||
148 | if (bluezDiscoveryActive) { | 199 | if (bluezDiscoveryActive) { |
149 | menu->insertItem( tr("Disable discovery"), 3 ); | 200 | menu->insertItem( tr("Disable discovery"), 3 ); |
150 | } else { | 201 | } else { |
151 | menu->insertItem( tr("Enable discovery"), 4 ); | 202 | menu->insertItem( tr("Enable discovery"), 4 ); |
152 | } | 203 | } |
153 | 204 | ||
154 | 205 | ||
155 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | 206 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); |
156 | ret = menu->exec(p, 0); | 207 | ret = menu->exec(p, 0); |
157 | 208 | ||
158 | switch(ret) { | 209 | switch(ret) { |
159 | case 0: | 210 | case 0: |
160 | setBluezStatus(0); | 211 | setBluezStatus(0); |
161 | timerEvent( 0 ); | 212 | timerEvent( 0 ); |
162 | break; | 213 | break; |
163 | case 1: | 214 | case 1: |
164 | setBluezStatus(1); | 215 | setBluezStatus(1); |
165 | timerEvent( 0 ); | 216 | timerEvent( 0 ); |
166 | break; | 217 | break; |
167 | case 2: | 218 | case 2: |
168 | // start bluetoothmanager | 219 | // start bluetoothmanager |
169 | launchManager(); | 220 | launchManager(); |
170 | timerEvent( 0 ); | 221 | timerEvent( 0 ); |
171 | break; | 222 | break; |
172 | case 3: | 223 | case 3: |
173 | setBluezDiscoveryStatus(0); | 224 | setBluezDiscoveryStatus(0); |
174 | timerEvent( 0 ); | 225 | timerEvent( 0 ); |
175 | break; | 226 | break; |
176 | case 4: | 227 | case 4: |
177 | setBluezDiscoveryStatus(1); | 228 | setBluezDiscoveryStatus(1); |
178 | timerEvent(0 ); | 229 | timerEvent(0 ); |
179 | break; | 230 | break; |
180 | //case 7: | 231 | //case 7: |
181 | // With table of currently-detected devices. | 232 | // With table of currently-detected devices. |
182 | } | 233 | } |
183 | 234 | ||
184 | delete signal; | 235 | delete signal; |
185 | delete menu; | 236 | delete menu; |
186 | } | 237 | } |
187 | 238 | ||
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index a394e38..3b99c0f 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h | |||
@@ -1,74 +1,79 @@ | |||
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 | 36 | ||
36 | namespace OpieTooth { | 37 | namespace OpieTooth { |
37 | class Device; | 38 | class Device; |
38 | 39 | ||
39 | class BluezApplet : public QWidget { | 40 | class BluezApplet : public QWidget { |
40 | Q_OBJECT | 41 | Q_OBJECT |
41 | public: | 42 | public: |
42 | BluezApplet( QWidget *parent = 0, const char *name=0 ); | 43 | BluezApplet( QWidget *parent = 0, const char *name=0 ); |
43 | ~BluezApplet(); | 44 | ~BluezApplet(); |
44 | static int position(); | 45 | static int position(); |
45 | protected: | 46 | protected: |
46 | void timerEvent(QTimerEvent *te ); | 47 | void timerEvent(QTimerEvent *te ); |
47 | 48 | ||
48 | public slots: | 49 | public slots: |
50 | void fillList( const QString& device, RemoteDevice::ValueList list ); | ||
51 | |||
49 | private: | 52 | private: |
50 | void mousePressEvent( QMouseEvent * ); | 53 | void mousePressEvent( QMouseEvent * ); |
51 | void paintEvent( QPaintEvent* ); | 54 | void paintEvent( QPaintEvent* ); |
52 | void launchManager(); | 55 | void launchManager(); |
53 | bool checkBluezStatus(); | 56 | bool checkBluezStatus(); |
54 | int setBluezStatus(int); | 57 | int setBluezStatus(int); |
55 | int checkBluezDiscoveryStatus(); | 58 | int checkBluezDiscoveryStatus(); |
56 | int setBluezDiscoveryStatus(int); | 59 | int setBluezDiscoveryStatus(int); |
57 | 60 | ||
58 | private: | 61 | private: |
59 | Device* btDevice; | 62 | Device* btDevice; |
63 | Manager *btManager; | ||
60 | QPixmap bluezOnPixmap; | 64 | QPixmap bluezOnPixmap; |
61 | QPixmap bluezOffPixmap; | 65 | QPixmap bluezOffPixmap; |
62 | QPixmap bluezDiscoveryOnPixmap; | 66 | QPixmap bluezDiscoveryOnPixmap; |
63 | bool bluezactive; | 67 | bool bluezactive; |
64 | bool bluezDiscoveryActive; | 68 | bool bluezDiscoveryActive; |
65 | 69 | ||
66 | private slots: | 70 | private slots: |
71 | void slotMessage( const QCString& , const QByteArray& ); | ||
67 | 72 | ||
68 | 73 | ||
69 | }; | 74 | }; |
70 | }; | 75 | }; |
71 | 76 | ||
72 | 77 | ||
73 | #endif | 78 | #endif |
74 | 79 | ||