summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/opietooth/applet/bluezapplet.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp
index f1618ae..39c15ab 100644
--- a/noncore/net/opietooth/applet/bluezapplet.cpp
+++ b/noncore/net/opietooth/applet/bluezapplet.cpp
@@ -1,206 +1,218 @@
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 <opie/odevice.h>
39
38#include <qpoint.h> 40#include <qpoint.h>
39#include <qpainter.h> 41#include <qpainter.h>
40#include <qlayout.h> 42#include <qlayout.h>
41#include <qframe.h> 43#include <qframe.h>
42#include <qpixmap.h> 44#include <qpixmap.h>
43#include <qstring.h> 45#include <qstring.h>
44#include <qtimer.h> 46#include <qtimer.h>
45#include <qpopupmenu.h> 47#include <qpopupmenu.h>
46 48
47#include <device.h> 49#include <device.h>
48 50
51using namespace Opie;
52
49namespace OpieTooth { 53namespace OpieTooth {
50 54
51 BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { 55 BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) {
52 setFixedHeight( 18 ); 56 setFixedHeight( 18 );
53 setFixedWidth( 14 ); 57 setFixedWidth( 14 );
54 bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" ); 58 bluezOnPixmap = Resource::loadPixmap( "bluetoothapplet/bluezon" );
55 bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" ); 59 bluezOffPixmap = Resource::loadPixmap( "bluetoothapplet/bluezoff" );
56 // bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass" ); 60 // bluezDiscoveryOnPixmap = Resource::loadPixmap( "bluetoothapplet/magglass" );
57 startTimer(4000); 61 startTimer(4000);
58 btDevice = 0; 62 btDevice = 0;
59 bluezactive = false; 63 bluezactive = false;
60 bluezDiscoveryActive = false; 64 bluezDiscoveryActive = false;
61 65
62 } 66 }
63 67
64 BluezApplet::~BluezApplet() { 68 BluezApplet::~BluezApplet() {
65 if ( btDevice ) { 69 if ( btDevice ) {
66 delete btDevice; 70 delete btDevice;
67 } 71 }
68 } 72 }
69 73
70 bool BluezApplet::checkBluezStatus() { 74 bool BluezApplet::checkBluezStatus() {
71 if (btDevice) { 75 if (btDevice) {
72 if (btDevice->isLoaded() ) { 76 if (btDevice->isLoaded() ) {
73 return true; 77 return true;
74 } else { 78 } else {
75 return false; 79 return false;
76 } 80 }
77 } else { 81 } else {
78 return false; 82 return false;
79 } 83 }
80 } 84 }
81 85
82 int BluezApplet::setBluezStatus(int c) { 86 int BluezApplet::setBluezStatus(int c) {
83 87
84 if (c == 1) { 88 if ( c == 1 ) {
85 btDevice = new Device("/dev/ttySB0", "bcsp", "230400" ); 89 switch ( ODevice::inst()->model() ) {
90 case Model_iPAQ_H39xx:
91 btDevice = new Device( "/dev/tts/1", "bcsp", "921600" );
92 break;
93
94 default:
95 btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" );
96 break;
97 }
86 } else { 98 } else {
87 if (btDevice) { 99 if ( btDevice ) {
88 delete btDevice; 100 delete btDevice;
89 btDevice = 0; 101 btDevice = 0;
90 } 102 }
91 } 103 }
92 return 0; 104 return 0;
93 } 105 }
94 106
95 int BluezApplet::checkBluezDiscoveryStatus() { 107 int BluezApplet::checkBluezDiscoveryStatus() {
96 } 108 }
97 109
98 int BluezApplet::setBluezDiscoveryStatus(int d) { 110 int BluezApplet::setBluezDiscoveryStatus(int d) {
99 } 111 }
100 112
101 void BluezApplet::mousePressEvent( QMouseEvent *) { 113 void BluezApplet::mousePressEvent( QMouseEvent *) {
102 114
103 QPopupMenu *menu = new QPopupMenu(); 115 QPopupMenu *menu = new QPopupMenu();
104 QPopupMenu *signal = new QPopupMenu(); 116 QPopupMenu *signal = new QPopupMenu();
105 int ret=0; 117 int ret=0;
106 118
107 /* Refresh active state */ 119 /* Refresh active state */
108 timerEvent( 0 ); 120 timerEvent( 0 );
109 121
110 122
111 if (bluezactive) { 123 if (bluezactive) {
112 menu->insertItem( tr("Disable Bluetooth"), 0 ); 124 menu->insertItem( tr("Disable Bluetooth"), 0 );
113 } else { 125 } else {
114 menu->insertItem( tr("Enable Bluetooth"), 1 ); 126 menu->insertItem( tr("Enable Bluetooth"), 1 );
115 } 127 }
116 128
117 menu->insertItem( tr("Launch manager"), 2 ); 129 menu->insertItem( tr("Launch manager"), 2 );
118 130
119 menu->insertSeparator(6); 131 menu->insertSeparator(6);
120 menu->insertItem( tr("Signal strength"), signal, 5); 132 //menu->insertItem( tr("Signal strength"), signal, 5);
121 menu->insertSeparator(8); 133 //menu->insertSeparator(8);
122 134
123 if (bluezDiscoveryActive) { 135 if (bluezDiscoveryActive) {
124 menu->insertItem( tr("Disable discovery"), 3 ); 136 menu->insertItem( tr("Disable discovery"), 3 );
125 } else { 137 } else {
126 menu->insertItem( tr("Enable discovery"), 4 ); 138 menu->insertItem( tr("Enable discovery"), 4 );
127 } 139 }
128 140
129 141
130 QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); 142 QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) );
131 ret = menu->exec(p, 0); 143 ret = menu->exec(p, 0);
132 144
133 switch(ret) { 145 switch(ret) {
134 case 0: 146 case 0:
135 setBluezStatus(0); 147 setBluezStatus(0);
136 timerEvent( 0 ); 148 timerEvent( 0 );
137 break; 149 break;
138 case 1: 150 case 1:
139 setBluezStatus(1); 151 setBluezStatus(1);
140 timerEvent( 0 ); 152 timerEvent( 0 );
141 break; 153 break;
142 case 2: 154 case 2:
143 // start bluetoothmanager 155 // start bluetoothmanager
144 launchManager(); 156 launchManager();
145 timerEvent( 0 ); 157 timerEvent( 0 );
146 break; 158 break;
147 case 3: 159 case 3:
148 setBluezDiscoveryStatus(0); 160 setBluezDiscoveryStatus(0);
149 timerEvent( 0 ); 161 timerEvent( 0 );
150 break; 162 break;
151 case 4: 163 case 4:
152 setBluezDiscoveryStatus(1); 164 setBluezDiscoveryStatus(1);
153 timerEvent(0 ); 165 timerEvent(0 );
154 break; 166 break;
155 //case 7: 167 //case 7:
156 // With table of currently-detected devices. 168 // With table of currently-detected devices.
157 } 169 }
158 170
159 delete signal; 171 delete signal;
160 delete menu; 172 delete menu;
161 } 173 }
162 174
163 175
164/** 176/**
165 * Launches the bluetooth manager 177 * Launches the bluetooth manager
166 */ 178 */
167 void BluezApplet::launchManager() { 179 void BluezApplet::launchManager() {
168 QCopEnvelope e("QPE/System", "execute(QString)"); 180 QCopEnvelope e("QPE/System", "execute(QString)");
169 e << QString("bluetooth-manager"); 181 e << QString("bluetooth-manager");
170 } 182 }
171 183
172/** 184/**
173 * Refresh timer 185 * Refresh timer
174 * @param the timer event 186 * @param the timer event
175 */ 187 */
176 void BluezApplet::timerEvent( QTimerEvent * ) { 188 void BluezApplet::timerEvent( QTimerEvent * ) {
177 bool oldactive = bluezactive; 189 bool oldactive = bluezactive;
178 int olddiscovery = bluezDiscoveryActive; 190 int olddiscovery = bluezDiscoveryActive;
179 191
180 bluezactive = checkBluezStatus(); 192 bluezactive = checkBluezStatus();
181 bluezDiscoveryActive = checkBluezDiscoveryStatus(); 193 bluezDiscoveryActive = checkBluezDiscoveryStatus();
182 194
183 if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) { 195 if ((bluezactive != oldactive) || (bluezDiscoveryActive != olddiscovery)) {
184 update(); 196 update();
185 } 197 }
186 } 198 }
187 199
188/** 200/**
189 * Implementation of the paint event 201 * Implementation of the paint event
190 * @param the QPaintEvent 202 * @param the QPaintEvent
191 */ 203 */
192 void BluezApplet::paintEvent( QPaintEvent* ) { 204 void BluezApplet::paintEvent( QPaintEvent* ) {
193 QPainter p(this); 205 QPainter p(this);
194 qDebug("paint bluetooth pixmap"); 206 qDebug("paint bluetooth pixmap");
195 207
196 if (bluezactive > 0) { 208 if (bluezactive > 0) {
197 p.drawPixmap( 0, 1, bluezOnPixmap ); 209 p.drawPixmap( 0, 1, bluezOnPixmap );
198 } else { 210 } else {
199 p.drawPixmap( 0, 1, bluezOffPixmap ); 211 p.drawPixmap( 0, 1, bluezOffPixmap );
200 } 212 }
201 213
202 if (bluezDiscoveryActive > 0) { 214 if (bluezDiscoveryActive > 0) {
203 p.drawPixmap( 0, 1, bluezDiscoveryOnPixmap ); 215 p.drawPixmap( 0, 1, bluezDiscoveryOnPixmap );
204 } 216 }
205 } 217 }
206}; 218};