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