summaryrefslogtreecommitdiff
authorharlekin <harlekin>2002-06-27 13:04:38 (UTC)
committer harlekin <harlekin>2002-06-27 13:04:38 (UTC)
commit540fd6a4a7cc86070c94f41833c4b9b9fa0e9824 (patch) (unidiff)
tree821cc0443c0a24fd19329791121cef625910cb72
parent56d22ac17fdc194a20fd0deba673943f85e940ea (diff)
downloadopie-540fd6a4a7cc86070c94f41833c4b9b9fa0e9824.zip
opie-540fd6a4a7cc86070c94f41833c4b9b9fa0e9824.tar.gz
opie-540fd6a4a7cc86070c94f41833c4b9b9fa0e9824.tar.bz2
cleanups
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.cpp19
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.h3
2 files changed, 10 insertions, 12 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp
index 8bb7a93..c0ad246 100644
--- a/noncore/net/opietooth/applet/bluezapplet.cpp
+++ b/noncore/net/opietooth/applet/bluezapplet.cpp
@@ -1,204 +1,203 @@
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
49namespace OpieTooth { 49namespace 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 bluezactive = false;
60 bluezDiscoveryActive = false;
59 61
60 } 62 }
61 63
62 BluezApplet::~BluezApplet() { 64 BluezApplet::~BluezApplet() {
63 } 65 }
64 66
65 bool BluezApplet::checkBluezStatus() { 67 bool BluezApplet::checkBluezStatus() {
66 if (btDevice) { 68 if (btDevice) {
67 if (btDevice->isLoaded() ) { 69 if (btDevice->isLoaded() ) {
68 return true; 70 return true;
69 } else { 71 } else {
70 return false; 72 return false;
71 } 73 }
72 } else { 74 } else {
73 return false; 75 return false;
74 } 76 }
75 } 77 }
76 78
77 int BluezApplet::setBluezStatus(int c) { 79 int BluezApplet::setBluezStatus(int c) {
78 80
79 if (c == 1) { 81 if (c == 1) {
80 btDevice = new Device("/dev/ttySB0", "csr" ); 82 btDevice = new Device("/dev/ttySB0", "csr" );
81 } else { 83 } else {
82 if (btDevice) { 84 if (btDevice) {
83 delete btDevice; 85 delete btDevice;
84 btDevice = 0; 86 btDevice = 0;
85 } 87 }
86 } 88 }
87 return 0; 89 return 0;
88 } 90 }
89 91
90 int BluezApplet::checkBluezDiscoveryStatus() { 92 int BluezApplet::checkBluezDiscoveryStatus() {
91 } 93 }
92 94
93 int BluezApplet::setBluezDiscoveryStatus(int d) { 95 int BluezApplet::setBluezDiscoveryStatus(int d) {
94 } 96 }
95 97
96 void BluezApplet::mousePressEvent( QMouseEvent *) { 98 void BluezApplet::mousePressEvent( QMouseEvent *) {
97 99
98 QPopupMenu *menu = new QPopupMenu(); 100 QPopupMenu *menu = new QPopupMenu();
99 QPopupMenu *signal = new QPopupMenu(); 101 QPopupMenu *signal = new QPopupMenu();
100 int ret=0; 102 int ret=0;
101 103
102 /* Refresh active state */ 104 /* Refresh active state */
103 timerEvent(NULL); 105 timerEvent( 0 );
104 106
105 107
106 if (bluezactive) { 108 if (bluezactive) {
107 menu->insertItem( tr("Disable Bluetooth"), 0 ); 109 menu->insertItem( tr("Disable Bluetooth"), 0 );
108 } else { 110 } else {
109 menu->insertItem( tr("Enable Bluetooth"), 1 ); 111 menu->insertItem( tr("Enable Bluetooth"), 1 );
110 } 112 }
111 113
112 menu->insertItem( tr("Launch manager"), 2 ); 114 menu->insertItem( tr("Launch manager"), 2 );
113 115
114 menu->insertSeparator(6); 116 menu->insertSeparator(6);
115 menu->insertItem( tr("Signal strength"), signal, 5); 117 menu->insertItem( tr("Signal strength"), signal, 5);
116 menu->insertSeparator(8); 118 menu->insertSeparator(8);
117 119
118 if (bluezDiscoveryActive) { 120 if (bluezDiscoveryActive) {
119 menu->insertItem( tr("Disable discovery"), 3 ); 121 menu->insertItem( tr("Disable discovery"), 3 );
120 } else { 122 } else {
121 menu->insertItem( tr("Enable discovery"), 4 ); 123 menu->insertItem( tr("Enable discovery"), 4 );
122 } 124 }
123 125
124 126
125 QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); 127 QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) );
126 ret = menu->exec(p, 0); 128 ret = menu->exec(p, 0);
127 129
128 switch(ret) { 130 switch(ret) {
129 case 0: 131 case 0:
130 setBluezStatus(0); 132 setBluezStatus(0);
131 timerEvent(NULL); 133 timerEvent( 0 );
132 break; 134 break;
133 case 1: 135 case 1:
134 setBluezStatus(1); 136 setBluezStatus(1);
135 timerEvent(NULL); 137 timerEvent( 0 );
136 break; 138 break;
137 case 2: 139 case 2:
138 // start bluetoothmanager 140 // start bluetoothmanager
139 launchManager(); 141 launchManager();
140 timerEvent(NULL); 142 timerEvent( 0 );
141 break; 143 break;
142 case 3: 144 case 3:
143 setBluezDiscoveryStatus(0); 145 setBluezDiscoveryStatus(0);
144 timerEvent(NULL); 146 timerEvent( 0 );
145 break; 147 break;
146 case 4: 148 case 4:
147 setBluezDiscoveryStatus(1); 149 setBluezDiscoveryStatus(1);
148 timerEvent(NULL); 150 timerEvent(0 );
149 break; 151 break;
150 //case 7: 152 //case 7:
151 // With table of currently-detected devices. 153 // With table of currently-detected devices.
152 } 154 }
153 155
154 timerEvent(NULL);
155 delete signal; 156 delete signal;
156 delete menu; 157 delete menu;
157 } 158 }
158 159
159 160
160/** 161/**
161 * Launches the bluetooth manager 162 * Launches the bluetooth manager
162 */ 163 */
163 void BluezApplet::launchManager() { 164 void BluezApplet::launchManager() {
164 QCopEnvelope e("QPE/System", "execute(QString)"); 165 QCopEnvelope e("QPE/System", "execute(QString)");
165 e << QString("bluetooth-manager"); 166 e << QString("bluetooth-manager");
166 } 167 }
167 168
168/** 169/**
169 * Refresh timer 170 * Refresh timer
170 * @param the timer event 171 * @param the timer event
171 */ 172 */
172 void BluezApplet::timerEvent( QTimerEvent * ) { 173 void BluezApplet::timerEvent( QTimerEvent * ) {
173 bool oldactive = bluezactive; 174 bool oldactive = bluezactive;
174 int olddiscovery = bluezDiscoveryActive; 175 int olddiscovery = bluezDiscoveryActive;
175 176
176 bluezactive = checkBluezStatus(); 177 bluezactive = checkBluezStatus();
177 bluezDiscoveryActive = checkBluezDiscoveryStatus(); 178 bluezDiscoveryActive = checkBluezDiscoveryStatus();
178 179
179 if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) { 180 if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) {
180 paintEvent(NULL); 181 update();
181 } 182 }
182 } 183 }
183 184
184/** 185/**
185 * Implementation of the paint event 186 * Implementation of the paint event
186 * @param the QPaintEvent 187 * @param the QPaintEvent
187 */ 188 */
188 void BluezApplet::paintEvent( QPaintEvent* ) { 189 void BluezApplet::paintEvent( QPaintEvent* ) {
189 QPainter p(this); 190 QPainter p(this);
190 qDebug("paint bluetooth pixmap"); 191 qDebug("paint bluetooth pixmap");
191 192
192 p.eraseRect ( 0, 0, this->width(), this->height() );
193
194 if (bluezactive > 0) { 193 if (bluezactive > 0) {
195 p.drawPixmap( 0, 1, bluezOnPixmap ); 194 p.drawPixmap( 0, 1, bluezOnPixmap );
196 } else { 195 } else {
197 p.drawPixmap( 0, 1, bluezOffPixmap ); 196 p.drawPixmap( 0, 1, bluezOffPixmap );
198 } 197 }
199 198
200 if (bluezDiscoveryActive > 0) { 199 if (bluezDiscoveryActive > 0) {
201 p.drawPixmap( 0, 1, bluezDiscoveryOnPixmap ); 200 p.drawPixmap( 0, 1, bluezDiscoveryOnPixmap );
202 } 201 }
203 } 202 }
204}; 203};
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h
index 6a8a00e..a8d91a5 100644
--- a/noncore/net/opietooth/applet/bluezapplet.h
+++ b/noncore/net/opietooth/applet/bluezapplet.h
@@ -1,75 +1,74 @@
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
36namespace OpieTooth { 36namespace 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
48public slots: 48public 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 bool 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;
58 57
59 private: 58 private:
60 Device* btDevice; 59 Device* btDevice;
61 QPixmap bluezOnPixmap; 60 QPixmap bluezOnPixmap;
62 QPixmap bluezOffPixmap; 61 QPixmap bluezOffPixmap;
63 QPixmap bluezDiscoveryOnPixmap; 62 QPixmap bluezDiscoveryOnPixmap;
64 bool bluezactive; 63 bool bluezactive;
65 int bluezDiscoveryActive; 64 bool bluezDiscoveryActive;
66 65
67private slots: 66private slots:
68 67
69 68
70 }; 69 };
71}; 70};
72 71
73 72
74#endif 73#endif
75 74