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