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