-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 19 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 3 |
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 | |||
@@ -35,170 +35,169 @@ | |||
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 | 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 | |||
@@ -33,43 +33,42 @@ | |||
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 | 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 | ||
67 | private slots: | 66 | private slots: |
68 | 67 | ||
69 | 68 | ||
70 | }; | 69 | }; |
71 | }; | 70 | }; |
72 | 71 | ||
73 | 72 | ||
74 | #endif | 73 | #endif |
75 | 74 | ||