author | harlekin <harlekin> | 2002-06-16 15:24:00 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2002-06-16 15:24:00 (UTC) |
commit | df2185572894877d0b4c524227b204b9f1a2341b (patch) (unidiff) | |
tree | 1da3398299a56d8995be9ca3441abb0d666aeb3e | |
parent | 0704b913f5da703218f66ddc18a4c6b280577d97 (diff) | |
download | opie-df2185572894877d0b4c524227b204b9f1a2341b.zip opie-df2185572894877d0b4c524227b204b9f1a2341b.tar.gz opie-df2185572894877d0b4c524227b204b9f1a2341b.tar.bz2 |
update
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 15 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 4 |
2 files changed, 12 insertions, 7 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index 94e29c7..8bb7a93 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -1,199 +1,204 @@ | |||
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; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
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 | #include <qapplication.h> | 31 | #include <qapplication.h> |
32 | 32 | ||
33 | #include <qpe/resource.h> | 33 | #include <qpe/resource.h> |
34 | #include <qpe/qcopenvelope_qws.h> | 34 | #include <qpe/qcopenvelope_qws.h> |
35 | #include <qpe/resource.h> | 35 | #include <qpe/resource.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
37 | 37 | ||
38 | #include <qpoint.h> | 38 | #include <qpoint.h> |
39 | #include <qpainter.h> | 39 | #include <qpainter.h> |
40 | #include <qlayout.h> | 40 | #include <qlayout.h> |
41 | #include <qframe.h> | 41 | #include <qframe.h> |
42 | #include <qpixmap.h> | 42 | #include <qpixmap.h> |
43 | #include <qstring.h> | 43 | #include <qstring.h> |
44 | #include <qtimer.h> | 44 | #include <qtimer.h> |
45 | #include <qpopupmenu.h> | 45 | #include <qpopupmenu.h> |
46 | 46 | ||
47 | #include <device.h> | 47 | #include <device.h> |
48 | 48 | ||
49 | namespace OpieTooth { | 49 | namespace OpieTooth { |
50 | 50 | ||
51 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | 51 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { |
52 | setFixedHeight( 18 ); | 52 | setFixedHeight( 18 ); |
53 | setFixedWidth( 14 ); | 53 | setFixedWidth( 14 ); |
54 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); | 54 | bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); |
55 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); | 55 | bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); |
56 | // bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass" ); | 56 | // bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass" ); |
57 | startTimer(5000); | 57 | startTimer(5000); |
58 | btDevice = 0; | 58 | btDevice = 0; |
59 | 59 | ||
60 | } | 60 | } |
61 | 61 | ||
62 | BluezApplet::~BluezApplet() { | 62 | BluezApplet::~BluezApplet() { |
63 | } | 63 | } |
64 | 64 | ||
65 | int BluezApplet::checkBluezStatus() { | 65 | bool BluezApplet::checkBluezStatus() { |
66 | if (btDevice) { | 66 | if (btDevice) { |
67 | if (btDevice->isLoaded() ) { | 67 | if (btDevice->isLoaded() ) { |
68 | return 1; | 68 | return true; |
69 | } else { | 69 | } else { |
70 | return 0; | 70 | return false; |
71 | } | 71 | } |
72 | } else { | 72 | } else { |
73 | return 0; | 73 | return false; |
74 | } | 74 | } |
75 | } | 75 | } |
76 | 76 | ||
77 | int BluezApplet::setBluezStatus(int c) { | 77 | int BluezApplet::setBluezStatus(int c) { |
78 | 78 | ||
79 | if (c == 1) { | 79 | if (c == 1) { |
80 | btDevice = new Device("/dev/ttySB0", "csr" ); | 80 | btDevice = new Device("/dev/ttySB0", "csr" ); |
81 | } else { | 81 | } else { |
82 | if (btDevice) { | 82 | if (btDevice) { |
83 | delete btDevice; | 83 | delete btDevice; |
84 | btDevice = 0; | 84 | btDevice = 0; |
85 | } | 85 | } |
86 | } | 86 | } |
87 | return 0; | 87 | return 0; |
88 | } | 88 | } |
89 | 89 | ||
90 | int BluezApplet::checkBluezDiscoveryStatus() { | 90 | int BluezApplet::checkBluezDiscoveryStatus() { |
91 | } | 91 | } |
92 | 92 | ||
93 | int BluezApplet::setBluezDiscoveryStatus(int d) { | 93 | int BluezApplet::setBluezDiscoveryStatus(int d) { |
94 | } | 94 | } |
95 | 95 | ||
96 | void BluezApplet::mousePressEvent( QMouseEvent *) { | 96 | void BluezApplet::mousePressEvent( QMouseEvent *) { |
97 | 97 | ||
98 | QPopupMenu *menu = new QPopupMenu(); | 98 | QPopupMenu *menu = new QPopupMenu(); |
99 | QPopupMenu *signal = new QPopupMenu(); | 99 | QPopupMenu *signal = new QPopupMenu(); |
100 | int ret=0; | 100 | int ret=0; |
101 | 101 | ||
102 | /* Refresh active state */ | 102 | /* Refresh active state */ |
103 | timerEvent(NULL); | 103 | timerEvent(NULL); |
104 | 104 | ||
105 | 105 | ||
106 | if (bluezactive) { | 106 | if (bluezactive) { |
107 | menu->insertItem( tr("Disable Bluetooth"), 0 ); | 107 | menu->insertItem( tr("Disable Bluetooth"), 0 ); |
108 | } else { | 108 | } else { |
109 | menu->insertItem( tr("Enable Bluetooth"), 1 ); | 109 | menu->insertItem( tr("Enable Bluetooth"), 1 ); |
110 | } | 110 | } |
111 | 111 | ||
112 | menu->insertItem( tr("Launch manager"), 2 ); | 112 | menu->insertItem( tr("Launch manager"), 2 ); |
113 | 113 | ||
114 | menu->insertSeparator(6); | 114 | menu->insertSeparator(6); |
115 | menu->insertItem( tr("Signal strength"), signal, 5); | 115 | menu->insertItem( tr("Signal strength"), signal, 5); |
116 | menu->insertSeparator(8); | 116 | menu->insertSeparator(8); |
117 | 117 | ||
118 | if (bluezDiscoveryActive) { | 118 | if (bluezDiscoveryActive) { |
119 | menu->insertItem( tr("Disable discovery"), 3 ); | 119 | menu->insertItem( tr("Disable discovery"), 3 ); |
120 | } else { | 120 | } else { |
121 | menu->insertItem( tr("Enable discovery"), 4 ); | 121 | menu->insertItem( tr("Enable discovery"), 4 ); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | 125 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); |
126 | ret = menu->exec(p, 0); | 126 | ret = menu->exec(p, 0); |
127 | 127 | ||
128 | switch(ret) { | 128 | switch(ret) { |
129 | case 0: | 129 | case 0: |
130 | setBluezStatus(0); | 130 | setBluezStatus(0); |
131 | timerEvent(NULL); | ||
131 | break; | 132 | break; |
132 | case 1: | 133 | case 1: |
133 | setBluezStatus(1); | 134 | setBluezStatus(1); |
135 | timerEvent(NULL); | ||
134 | break; | 136 | break; |
135 | case 2: | 137 | case 2: |
136 | // start bluetoothmanager | 138 | // start bluetoothmanager |
137 | launchManager(); | 139 | launchManager(); |
140 | timerEvent(NULL); | ||
138 | break; | 141 | break; |
139 | case 3: | 142 | case 3: |
140 | setBluezDiscoveryStatus(0); | 143 | setBluezDiscoveryStatus(0); |
144 | timerEvent(NULL); | ||
141 | break; | 145 | break; |
142 | case 4: | 146 | case 4: |
143 | setBluezDiscoveryStatus(1); | 147 | setBluezDiscoveryStatus(1); |
148 | timerEvent(NULL); | ||
144 | break; | 149 | break; |
145 | //case 7: | 150 | //case 7: |
146 | // With table of currently-detected devices. | 151 | // With table of currently-detected devices. |
147 | } | 152 | } |
148 | 153 | ||
149 | timerEvent(NULL); | 154 | timerEvent(NULL); |
150 | delete signal; | 155 | delete signal; |
151 | delete menu; | 156 | delete menu; |
152 | } | 157 | } |
153 | 158 | ||
154 | 159 | ||
155 | /** | 160 | /** |
156 | * Launches the bluetooth manager | 161 | * Launches the bluetooth manager |
157 | */ | 162 | */ |
158 | void BluezApplet::launchManager() { | 163 | void BluezApplet::launchManager() { |
159 | QCopEnvelope e("QPE/System", "execute(QString)"); | 164 | QCopEnvelope e("QPE/System", "execute(QString)"); |
160 | e << QString("bluetooth-manager"); | 165 | e << QString("bluetooth-manager"); |
161 | } | 166 | } |
162 | 167 | ||
163 | /** | 168 | /** |
164 | * Refresh timer | 169 | * Refresh timer |
165 | * @param the timer event | 170 | * @param the timer event |
166 | */ | 171 | */ |
167 | void BluezApplet::timerEvent( QTimerEvent * ) { | 172 | void BluezApplet::timerEvent( QTimerEvent * ) { |
168 | int oldactive = bluezactive; | 173 | bool oldactive = bluezactive; |
169 | int olddiscovery = bluezDiscoveryActive; | 174 | int olddiscovery = bluezDiscoveryActive; |
170 | 175 | ||
171 | bluezactive = checkBluezStatus(); | 176 | bluezactive = checkBluezStatus(); |
172 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); | 177 | bluezDiscoveryActive = checkBluezDiscoveryStatus(); |
173 | 178 | ||
174 | if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) { | 179 | if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) { |
175 | paintEvent(NULL); | 180 | paintEvent(NULL); |
176 | } | 181 | } |
177 | } | 182 | } |
178 | 183 | ||
179 | /** | 184 | /** |
180 | * Implementation of the paint event | 185 | * Implementation of the paint event |
181 | * @param the QPaintEvent | 186 | * @param the QPaintEvent |
182 | */ | 187 | */ |
183 | void BluezApplet::paintEvent( QPaintEvent* ) { | 188 | void BluezApplet::paintEvent( QPaintEvent* ) { |
184 | QPainter p(this); | 189 | QPainter p(this); |
185 | qDebug("paint bluetooth pixmap"); | 190 | qDebug("paint bluetooth pixmap"); |
186 | 191 | ||
187 | p.eraseRect ( 0, 0, this->width(), this->height() ); | 192 | p.eraseRect ( 0, 0, this->width(), this->height() ); |
188 | 193 | ||
189 | if (bluezactive > 0) { | 194 | if (bluezactive > 0) { |
190 | p.drawPixmap( 0, 1, bluezOnPixmap ); | 195 | p.drawPixmap( 0, 1, bluezOnPixmap ); |
191 | } else { | 196 | } else { |
192 | p.drawPixmap( 0, 1, bluezOffPixmap ); | 197 | p.drawPixmap( 0, 1, bluezOffPixmap ); |
193 | } | 198 | } |
194 | 199 | ||
195 | if (bluezDiscoveryActive > 0) { | 200 | if (bluezDiscoveryActive > 0) { |
196 | p.drawPixmap( 0, 1, bluezDiscoveryOnPixmap ); | 201 | p.drawPixmap( 0, 1, bluezDiscoveryOnPixmap ); |
197 | } | 202 | } |
198 | } | 203 | } |
199 | }; | 204 | }; |
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index da05a18..6a8a00e 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h | |||
@@ -1,75 +1,75 @@ | |||
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; either version 2 of the License, | 9 | - . .-<_> .<> Foundation; either version 2 of the License, |
10 | ._= =} : or (at your option) any later version. | 10 | ._= =} : or (at your option) any later version. |
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 | 35 | ||
36 | namespace OpieTooth { | 36 | namespace OpieTooth { |
37 | class Device; | 37 | class Device; |
38 | 38 | ||
39 | class BluezApplet : public QWidget { | 39 | class BluezApplet : public QWidget { |
40 | Q_OBJECT | 40 | Q_OBJECT |
41 | public: | 41 | public: |
42 | BluezApplet( QWidget *parent = 0, const char *name=0 ); | 42 | BluezApplet( QWidget *parent = 0, const char *name=0 ); |
43 | ~BluezApplet(); | 43 | ~BluezApplet(); |
44 | 44 | ||
45 | protected: | 45 | protected: |
46 | void timerEvent(QTimerEvent *te ); | 46 | void timerEvent(QTimerEvent *te ); |
47 | 47 | ||
48 | public slots: | 48 | public slots: |
49 | private: | 49 | private: |
50 | void mousePressEvent( QMouseEvent * ); | 50 | void mousePressEvent( QMouseEvent * ); |
51 | void paintEvent( QPaintEvent* ); | 51 | void paintEvent( QPaintEvent* ); |
52 | void launchManager(); | 52 | void launchManager(); |
53 | int checkBluezStatus(); | 53 | bool checkBluezStatus(); |
54 | int setBluezStatus(int); | 54 | int setBluezStatus(int); |
55 | int checkBluezDiscoveryStatus(); | 55 | int checkBluezDiscoveryStatus(); |
56 | int setBluezDiscoveryStatus(int); | 56 | int setBluezDiscoveryStatus(int); |
57 | int sockfd; | 57 | int sockfd; |
58 | 58 | ||
59 | private: | 59 | private: |
60 | Device* btDevice; | 60 | Device* btDevice; |
61 | QPixmap bluezOnPixmap; | 61 | QPixmap bluezOnPixmap; |
62 | QPixmap bluezOffPixmap; | 62 | QPixmap bluezOffPixmap; |
63 | QPixmap bluezDiscoveryOnPixmap; | 63 | QPixmap bluezDiscoveryOnPixmap; |
64 | int bluezactive; | 64 | bool bluezactive; |
65 | int bluezDiscoveryActive; | 65 | int bluezDiscoveryActive; |
66 | 66 | ||
67 | private slots: | 67 | private slots: |
68 | 68 | ||
69 | 69 | ||
70 | }; | 70 | }; |
71 | }; | 71 | }; |
72 | 72 | ||
73 | 73 | ||
74 | #endif | 74 | #endif |
75 | 75 | ||