-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.cpp | 56 | ||||
-rw-r--r-- | noncore/net/opietooth/applet/bluezapplet.h | 2 |
2 files changed, 16 insertions, 42 deletions
diff --git a/noncore/net/opietooth/applet/bluezapplet.cpp b/noncore/net/opietooth/applet/bluezapplet.cpp index 9c6c71d..90b0c6d 100644 --- a/noncore/net/opietooth/applet/bluezapplet.cpp +++ b/noncore/net/opietooth/applet/bluezapplet.cpp | |||
@@ -54,9 +54,9 @@ using namespace Opie::Core; | |||
54 | 54 | ||
55 | /* STD */ | 55 | /* STD */ |
56 | #include <device.h> | 56 | #include <device.h> |
57 | 57 | ||
58 | // #define OPIE120 // undefine it fo the latest OPIE | 58 | #define OPIE120 // undefine it fo the latest OPIE |
59 | 59 | ||
60 | namespace OpieTooth { | 60 | namespace OpieTooth { |
61 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { | 61 | BluezApplet::BluezApplet( QWidget *parent, const char *name ) : QWidget( parent, name ) { |
62 | setFixedHeight( AppLnk::smallIconSize() ); | 62 | setFixedHeight( AppLnk::smallIconSize() ); |
@@ -82,18 +82,9 @@ namespace OpieTooth { | |||
82 | // TODO: determine whether this channel has to be closed at destruction time. | 82 | // TODO: determine whether this channel has to be closed at destruction time. |
83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); | 83 | QCopChannel* chan = new QCopChannel("QPE/Bluetooth", this ); |
84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), | 84 | connect(chan, SIGNAL(received(const QCString&,const QByteArray&) ), |
85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); | 85 | this, SLOT(slotMessage(const QCString&,const QByteArray&) ) ); |
86 | 86 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); | |
87 | OProcess* btstart = new OProcess(); | ||
88 | *btstart << "/etc/init.d/bluetooth" << "stop"; | ||
89 | btstart->setUseShell(true); | ||
90 | if (!btstart->start(OProcess::DontCare, OProcess::AllOutput)) | ||
91 | delete btstart; | ||
92 | else { | ||
93 | connect(btstart, SIGNAL(processExited(Opie::Core::OProcess*)), | ||
94 | this, SLOT(slotProcessExited(Opie::Core::OProcess*))); | ||
95 | } | ||
96 | } | 87 | } |
97 | 88 | ||
98 | BluezApplet::~BluezApplet() { | 89 | BluezApplet::~BluezApplet() { |
99 | if ( btDevice ) { | 90 | if ( btDevice ) { |
@@ -103,29 +94,31 @@ namespace OpieTooth { | |||
103 | delete btManager; | 94 | delete btManager; |
104 | } | 95 | } |
105 | } | 96 | } |
106 | 97 | ||
107 | int BluezApplet::position() | 98 | int BluezApplet::position() |
108 | { | 99 | { |
109 | return 6; | 100 | return 6; |
110 | } | 101 | } |
111 | 102 | ||
112 | 103 | ||
113 | bool BluezApplet::checkBluezStatus() { | 104 | bool BluezApplet::checkBluezStatus() { |
114 | if (btDevice) { | 105 | if (btDevice) { |
115 | if (btDevice->isLoaded() ) { | 106 | if (btDevice->isLoaded() ) { |
107 | odebug << "btDevice isLoaded" << oendl; | ||
116 | return true; | 108 | return true; |
117 | } else { | 109 | } else { |
110 | odebug << "btDevice is NOT loaded" << oendl; | ||
118 | return false; | 111 | return false; |
119 | } | 112 | } |
120 | } else { | 113 | } else { |
114 | odebug << "btDevice is ZERO" << oendl; | ||
121 | return false; | 115 | return false; |
122 | } | 116 | } |
123 | } | 117 | } |
124 | 118 | ||
125 | int BluezApplet::setBluezStatus(int c) { | 119 | int BluezApplet::setBluezStatus(int c) { |
126 | 120 | ||
127 | OProcess* btstart = new OProcess(); | ||
128 | if ( c == 1 ) { | 121 | if ( c == 1 ) { |
129 | switch ( ODevice::inst()->model() ) { | 122 | switch ( ODevice::inst()->model() ) { |
130 | case Model_iPAQ_H39xx: | 123 | case Model_iPAQ_H39xx: |
131 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); | 124 | btDevice = new Device( "/dev/tts/1", "bcsp", "921600" ); |
@@ -144,24 +137,15 @@ int BluezApplet::position() | |||
144 | default: | 137 | default: |
145 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); | 138 | btDevice = new Device( "/dev/ttySB0", "bcsp", "230400" ); |
146 | break; | 139 | break; |
147 | } | 140 | } |
148 | *btstart << "/etc/init.d/bluetooth" << "start"; | 141 | QCopEnvelope e("QPE/System", "execute(QString)"); |
149 | btstart->setUseShell(true); | 142 | e << QString("/etc/init.d/bluetooth start"); |
150 | if (!btstart->start(OProcess::DontCare, OProcess::AllOutput)) | ||
151 | delete btstart; | ||
152 | else { | ||
153 | connect(btstart, SIGNAL(processExited(Opie::Core::OProcess*)), | ||
154 | this, SLOT(slotProcessExited(Opie::Core::OProcess*))); | ||
155 | } | ||
156 | } else { | 143 | } else { |
157 | *btstart << "/etc/init.d/bluetooth" << "stop"; | 144 | ::system("/etc/init.d/bluetooth stop >/dev/null 2>/dev/null"); |
158 | btstart->setUseShell(true); | 145 | if ( btManager ) { |
159 | if (!btstart->start(OProcess::DontCare, OProcess::AllOutput)) | 146 | delete btManager; |
160 | delete btstart; | 147 | btManager = 0; |
161 | else { | ||
162 | connect(btstart, SIGNAL(processExited(Opie::Core::OProcess*)), | ||
163 | this, SLOT(slotProcessExited(Opie::Core::OProcess*))); | ||
164 | } | 148 | } |
165 | if ( btDevice ) { | 149 | if ( btDevice ) { |
166 | delete btDevice; | 150 | delete btDevice; |
167 | btDevice = 0; | 151 | btDevice = 0; |
@@ -196,9 +180,9 @@ int BluezApplet::position() | |||
196 | */ | 180 | */ |
197 | if (checkBluezStatus() && !m_wasOn) | 181 | if (checkBluezStatus() && !m_wasOn) |
198 | setBluezStatus(0); | 182 | setBluezStatus(0); |
199 | doListDevice = false; | 183 | doListDevice = false; |
200 | } | 184 | } |
201 | else if ( str == "listDevices()") { | 185 | else if ( str == "listDevices()") { |
202 | if (checkBluezStatus()) { | 186 | if (checkBluezStatus()) { |
203 | doListDevice = false; | 187 | doListDevice = false; |
204 | timerEvent(0); | 188 | timerEvent(0); |
@@ -261,8 +245,9 @@ int BluezApplet::position() | |||
261 | 245 | ||
262 | 246 | ||
263 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); | 247 | QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); |
264 | ret = menu->exec(p, 0); | 248 | ret = menu->exec(p, 0); |
249 | menu->hide(); | ||
265 | 250 | ||
266 | switch(ret) { | 251 | switch(ret) { |
267 | case 0: | 252 | case 0: |
268 | setBluezStatus(0); | 253 | setBluezStatus(0); |
@@ -347,17 +332,8 @@ int BluezApplet::position() | |||
347 | if (bluezDiscoveryActive) { | 332 | if (bluezDiscoveryActive) { |
348 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); | 333 | p.drawPixmap( 0, 0, bluezDiscoveryOnPixmap ); |
349 | } | 334 | } |
350 | } | 335 | } |
351 | |||
352 | /** | ||
353 | * Implementation of the process finish | ||
354 | * @param the finished process | ||
355 | */ | ||
356 | void BluezApplet::slotProcessExited(OProcess* proc) | ||
357 | { | ||
358 | delete proc; | ||
359 | } | ||
360 | }; | 336 | }; |
361 | 337 | ||
362 | 338 | ||
363 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) | 339 | EXPORT_OPIE_APPLET_v1( OpieTooth::BluezApplet ) |
diff --git a/noncore/net/opietooth/applet/bluezapplet.h b/noncore/net/opietooth/applet/bluezapplet.h index 85022bb..90bee3b 100644 --- a/noncore/net/opietooth/applet/bluezapplet.h +++ b/noncore/net/opietooth/applet/bluezapplet.h | |||
@@ -72,10 +72,8 @@ public slots: | |||
72 | bool m_wasOn; //If BT was started by menu? | 72 | bool m_wasOn; //If BT was started by menu? |
73 | 73 | ||
74 | private slots: | 74 | private slots: |
75 | void slotMessage( const QCString& , const QByteArray& ); | 75 | void slotMessage( const QCString& , const QByteArray& ); |
76 | void slotProcessExited(Opie::Core::OProcess* proc); | ||
77 | |||
78 | }; | 76 | }; |
79 | }; | 77 | }; |
80 | 78 | ||
81 | 79 | ||