author | harlekin <harlekin> | 2004-06-04 17:46:18 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2004-06-04 17:46:18 (UTC) |
commit | 1989c6f43aecffc9ec1a7b677e98435beff54886 (patch) (unidiff) | |
tree | 798d1255e59c120fda9b853c5b31a29bcbe07edf | |
parent | e3982ce0959fe630709aeba25f4c6d93df150ff5 (diff) | |
download | opie-1989c6f43aecffc9ec1a7b677e98435beff54886.zip opie-1989c6f43aecffc9ec1a7b677e98435beff54886.tar.gz opie-1989c6f43aecffc9ec1a7b677e98435beff54886.tar.bz2 |
using oprocess to trigger some unix commands instead of primitiv system(), hopefully fixes bug 218
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 260 | ||||
-rw-r--r-- | core/applets/cardmon/cardmon.h | 13 |
2 files changed, 123 insertions, 150 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index 3af3d03..3f07b41 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp | |||
@@ -22,6 +22,8 @@ | |||
22 | #include <opie2/odebug.h> | 22 | #include <opie2/odebug.h> |
23 | #include <opie2/odevice.h> | 23 | #include <opie2/odevice.h> |
24 | #include <opie2/otaskbarapplet.h> | 24 | #include <opie2/otaskbarapplet.h> |
25 | #include <opie2/oprocess.h> | ||
26 | |||
25 | #include <qpe/applnk.h> | 27 | #include <qpe/applnk.h> |
26 | #include <qpe/resource.h> | 28 | #include <qpe/resource.h> |
27 | using namespace Opie::Core; | 29 | using namespace Opie::Core; |
@@ -47,8 +49,7 @@ using namespace Opie::Ui; | |||
47 | #endif | 49 | #endif |
48 | 50 | ||
49 | CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), | 51 | CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), |
50 | pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) | 52 | pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { |
51 | { | ||
52 | 53 | ||
53 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); | 54 | QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); |
54 | connect( pcmciaChannel, | 55 | connect( pcmciaChannel, |
@@ -63,6 +64,7 @@ CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), | |||
63 | cardInPcmcia0 = FALSE; | 64 | cardInPcmcia0 = FALSE; |
64 | cardInPcmcia1 = FALSE; | 65 | cardInPcmcia1 = FALSE; |
65 | cardInSd = FALSE; | 66 | cardInSd = FALSE; |
67 | m_process = 0; | ||
66 | 68 | ||
67 | setFocusPolicy( NoFocus ); | 69 | setFocusPolicy( NoFocus ); |
68 | 70 | ||
@@ -75,28 +77,19 @@ CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), | |||
75 | popupMenu = 0; | 77 | popupMenu = 0; |
76 | } | 78 | } |
77 | 79 | ||
78 | CardMonitor::~CardMonitor() | 80 | CardMonitor::~CardMonitor() { |
79 | { | 81 | delete popupMenu; |
80 | if ( popupMenu ) | ||
81 | { | ||
82 | delete popupMenu; | ||
83 | } | ||
84 | } | 82 | } |
85 | 83 | ||
86 | void CardMonitor::popUp( QString message, QString icon ) | 84 | void CardMonitor::popUp( QString message, QString icon ) { |
87 | { | 85 | if ( !popupMenu ) { |
88 | if ( !popupMenu ) | ||
89 | { | ||
90 | popupMenu = new QPopupMenu( this ); | 86 | popupMenu = new QPopupMenu( this ); |
91 | } | 87 | } |
92 | 88 | ||
93 | popupMenu->clear(); | 89 | popupMenu->clear(); |
94 | if ( icon.isEmpty() ) | 90 | if ( icon.isEmpty() ) { |
95 | { | ||
96 | popupMenu->insertItem( message, 0 ); | 91 | popupMenu->insertItem( message, 0 ); |
97 | } | 92 | } else { |
98 | else | ||
99 | { | ||
100 | popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), | 93 | popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ), |
101 | message, 0 ); | 94 | message, 0 ); |
102 | } | 95 | } |
@@ -109,33 +102,27 @@ void CardMonitor::popUp( QString message, QString icon ) | |||
109 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); | 102 | QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); |
110 | } | 103 | } |
111 | 104 | ||
112 | void CardMonitor::popupTimeout() | 105 | void CardMonitor::popupTimeout() { |
113 | { | ||
114 | popupMenu->hide(); | 106 | popupMenu->hide(); |
115 | } | 107 | } |
116 | 108 | ||
117 | void CardMonitor::mousePressEvent( QMouseEvent * ) | 109 | void CardMonitor::mousePressEvent( QMouseEvent * ) { |
118 | { | ||
119 | QPopupMenu * menu = new QPopupMenu( this ); | 110 | QPopupMenu * menu = new QPopupMenu( this ); |
120 | QString cmd; | 111 | QString cmd; |
121 | int err = 0; | ||
122 | 112 | ||
123 | if ( cardInSd ) | 113 | if ( cardInSd ) { |
124 | { | ||
125 | menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), | 114 | menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ), |
126 | tr( "Eject SD/MMC card" ), 0 ); | 115 | tr( "Eject SD/MMC card" ), 0 ); |
127 | } | 116 | } |
128 | 117 | ||
129 | if ( cardInPcmcia0 ) | 118 | if ( cardInPcmcia0 ) { |
130 | { | ||
131 | menu-> | 119 | menu-> |
132 | insertItem( QIconSet | 120 | insertItem( QIconSet |
133 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), | 121 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia0Type ) ), |
134 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); | 122 | tr( "Eject card 0: %1" ).arg( cardInPcmcia0Name ), 1 ); |
135 | } | 123 | } |
136 | 124 | ||
137 | if ( cardInPcmcia1 ) | 125 | if ( cardInPcmcia1 ) { |
138 | { | ||
139 | menu-> | 126 | menu-> |
140 | insertItem( QIconSet | 127 | insertItem( QIconSet |
141 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), | 128 | ( Resource::loadPixmap( "cardmon/" + cardInPcmcia1Type ) ), |
@@ -147,62 +134,36 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) | |||
147 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), | 134 | int opt = menu->exec( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), |
148 | p.y() - s.height() ), 0 ); | 135 | p.y() - s.height() ), 0 ); |
149 | 136 | ||
150 | if ( opt == 1 ) | 137 | if ( opt == 1 ) { |
151 | { | 138 | m_commandOrig = 1; |
152 | cmd = "/sbin/cardctl eject 0"; | 139 | execCommand("/sbin/cardctl eject 0"); |
153 | err = system( ( const char * ) cmd ); | 140 | } else if ( opt == 0 ) { |
154 | if ( err != 0 ) | 141 | if ( ODevice::inst() ->system() == System_Familiar ) { |
155 | { | ||
156 | odebug << "Could not execute `/sbin/cardctl eject 0'! err=" << err << oendl; | ||
157 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | ||
158 | } | ||
159 | } | ||
160 | else if ( opt == 0 ) | ||
161 | { | ||
162 | if ( ODevice::inst() ->system() == System_Familiar ) | ||
163 | { | ||
164 | cmd = "umount /dev/mmc/part1"; | 142 | cmd = "umount /dev/mmc/part1"; |
165 | } | 143 | } else { |
166 | else | ||
167 | { | ||
168 | cmd = "umount /dev/mmcda1"; | 144 | cmd = "umount /dev/mmcda1"; |
169 | } | 145 | } |
170 | err = system( ( const char * ) cmd ); | 146 | m_commandOrig = 2; |
171 | if ( err != 0 ) | 147 | execCommand( cmd ); |
172 | { | 148 | } else if ( opt == 2 ) { |
173 | popUp( tr( "SD/MMC card eject failed!" ) ); | 149 | m_commandOrig = 3; |
174 | } | 150 | execCommand( "/sbin/cardctl eject 1" ); |
175 | } | ||
176 | else if ( opt == 2 ) | ||
177 | { | ||
178 | cmd = "/sbin/cardctl eject 1"; | ||
179 | err = system( ( const char * ) cmd ); | ||
180 | if ( err != 0 ) | ||
181 | { | ||
182 | odebug << "Could not execute `/sbin/cardctl eject 1'! err=" << err << oendl; | ||
183 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | ||
184 | } | ||
185 | } | 151 | } |
186 | delete menu; | 152 | delete menu; |
187 | } | 153 | } |
188 | 154 | ||
189 | 155 | ||
190 | void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) | 156 | void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) { |
191 | { | 157 | if ( msg == "stabChanged()" ) { |
192 | if ( msg == "stabChanged()" ) | ||
193 | { | ||
194 | // odebug << "Pcmcia: stabchanged" << oendl; | 158 | // odebug << "Pcmcia: stabchanged" << oendl; |
195 | getStatusPcmcia(); | 159 | getStatusPcmcia(); |
196 | } | 160 | } else if ( msg == "mtabChanged()" ) { |
197 | else if ( msg == "mtabChanged()" ) | ||
198 | { | ||
199 | // odebug << "CARDMONAPPLET: mtabchanged" << oendl; | 161 | // odebug << "CARDMONAPPLET: mtabchanged" << oendl; |
200 | getStatusSd(); | 162 | getStatusSd(); |
201 | } | 163 | } |
202 | } | 164 | } |
203 | 165 | ||
204 | bool CardMonitor::getStatusPcmcia( int showPopUp ) | 166 | bool CardMonitor::getStatusPcmcia( int showPopUp ) { |
205 | { | ||
206 | 167 | ||
207 | bool cardWas0 = cardInPcmcia0; // remember last state | 168 | bool cardWas0 = cardInPcmcia0; // remember last state |
208 | bool cardWas1 = cardInPcmcia1; | 169 | bool cardWas1 = cardInPcmcia1; |
@@ -210,40 +171,29 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
210 | QString fileName; | 171 | QString fileName; |
211 | 172 | ||
212 | // one of these 3 files should exist | 173 | // one of these 3 files should exist |
213 | if ( QFile::exists( "/var/run/stab" ) ) | 174 | if ( QFile::exists( "/var/run/stab" ) ) { |
214 | { | ||
215 | fileName = "/var/run/stab"; | 175 | fileName = "/var/run/stab"; |
216 | } | 176 | } else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) { |
217 | else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) | ||
218 | { | ||
219 | fileName = "/var/state/pcmcia/stab"; | 177 | fileName = "/var/state/pcmcia/stab"; |
220 | } | 178 | } else { |
221 | else | ||
222 | { | ||
223 | fileName = "/var/lib/pcmcia/stab"; | 179 | fileName = "/var/lib/pcmcia/stab"; |
224 | } | 180 | } |
225 | 181 | ||
226 | QFile f( fileName ); | 182 | QFile f( fileName ); |
227 | 183 | ||
228 | if ( f.open( IO_ReadOnly ) ) | 184 | if ( f.open( IO_ReadOnly ) ) { |
229 | { | ||
230 | QStringList list; | 185 | QStringList list; |
231 | QTextStream stream( &f ); | 186 | QTextStream stream( &f ); |
232 | QString streamIn; | 187 | QString streamIn; |
233 | streamIn = stream.read(); | 188 | streamIn = stream.read(); |
234 | list = QStringList::split( "\n", streamIn ); | 189 | list = QStringList::split( "\n", streamIn ); |
235 | for ( QStringList::Iterator line = list.begin(); line != list.end(); | 190 | for ( QStringList::Iterator line = list.begin(); line != list.end(); |
236 | line++ ) | 191 | line++ ) { |
237 | { | 192 | if ( ( *line ).startsWith( "Socket 0:" ) ) { |
238 | if ( ( *line ).startsWith( "Socket 0:" ) ) | 193 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) { |
239 | { | ||
240 | if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) | ||
241 | { | ||
242 | cardInPcmcia0 = FALSE; | 194 | cardInPcmcia0 = FALSE; |
243 | } | 195 | } else if ( !( *line ).startsWith( "Socket 0: empty" ) |
244 | else if ( !( *line ).startsWith( "Socket 0: empty" ) | 196 | && !cardInPcmcia0 ) { |
245 | && !cardInPcmcia0 ) | ||
246 | { | ||
247 | cardInPcmcia0Name = | 197 | cardInPcmcia0Name = |
248 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | 198 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
249 | ( *line ).length() - 9 ); | 199 | ( *line ).length() - 9 ); |
@@ -255,16 +205,11 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
255 | cardInPcmcia0Type = | 205 | cardInPcmcia0Type = |
256 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); | 206 | ( *line ).mid( pos, ( *line ).find( "\t", pos ) - pos ); |
257 | } | 207 | } |
258 | } | 208 | } else if ( ( *line ).startsWith( "Socket 1:" ) ) { |
259 | else if ( ( *line ).startsWith( "Socket 1:" ) ) | 209 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) { |
260 | { | ||
261 | if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) | ||
262 | { | ||
263 | cardInPcmcia1 = FALSE; | 210 | cardInPcmcia1 = FALSE; |
264 | } | 211 | } else if ( !( *line ).startsWith( "Socket 1: empty" ) |
265 | else if ( !( *line ).startsWith( "Socket 1: empty" ) | 212 | && !cardInPcmcia1 ) { |
266 | && !cardInPcmcia1 ) | ||
267 | { | ||
268 | cardInPcmcia1Name = | 213 | cardInPcmcia1Name = |
269 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), | 214 | ( *line ).mid( ( ( *line ).find( ':' ) + 1 ), |
270 | ( *line ).length() - 9 ); | 215 | ( *line ).length() - 9 ); |
@@ -281,19 +226,14 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
281 | f.close(); | 226 | f.close(); |
282 | 227 | ||
283 | if ( !showPopUp | 228 | if ( !showPopUp |
284 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) | 229 | && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) { |
285 | { | ||
286 | QString text = QString::null; | 230 | QString text = QString::null; |
287 | QString what = QString::null; | 231 | QString what = QString::null; |
288 | if ( cardWas0 != cardInPcmcia0 ) | 232 | if ( cardWas0 != cardInPcmcia0 ) { |
289 | { | 233 | if ( cardInPcmcia0 ) { |
290 | if ( cardInPcmcia0 ) | ||
291 | { | ||
292 | text += tr( "New card: " ); | 234 | text += tr( "New card: " ); |
293 | what = "on"; | 235 | what = "on"; |
294 | } | 236 | } else { |
295 | else | ||
296 | { | ||
297 | text += tr( "Ejected: " ); | 237 | text += tr( "Ejected: " ); |
298 | what = "off"; | 238 | what = "off"; |
299 | } | 239 | } |
@@ -301,29 +241,23 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
301 | popUp( text, "cardmon/" + cardInPcmcia0Type ); | 241 | popUp( text, "cardmon/" + cardInPcmcia0Type ); |
302 | } | 242 | } |
303 | 243 | ||
304 | if ( cardWas1 != cardInPcmcia1 ) | 244 | if ( cardWas1 != cardInPcmcia1 ) { |
305 | { | 245 | if ( cardInPcmcia1 ) { |
306 | if ( cardInPcmcia1 ) | ||
307 | { | ||
308 | text += tr( "New card: " ); | 246 | text += tr( "New card: " ); |
309 | what = "on"; | 247 | what = "on"; |
310 | } | 248 | } else { |
311 | else | ||
312 | { | ||
313 | text += tr( "Ejected: " ); | 249 | text += tr( "Ejected: " ); |
314 | what = "off"; | 250 | what = "off"; |
315 | } | 251 | } |
316 | text += cardInPcmcia1Name; | 252 | text += cardInPcmcia1Name; |
317 | popUp( text, "cardmon/" + cardInPcmcia1Type ); | 253 | popUp( text, "cardmon/" + cardInPcmcia1Type ); |
318 | } | 254 | } |
319 | #ifndef QT_NO_SOUND | 255 | #ifndef QT_NO_SOUND |
320 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | 256 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
321 | #endif | 257 | #endif |
322 | 258 | ||
323 | } | 259 | } |
324 | } | 260 | } else { |
325 | else | ||
326 | { | ||
327 | // no file found | 261 | // no file found |
328 | odebug << "no file found" << oendl; | 262 | odebug << "no file found" << oendl; |
329 | cardInPcmcia0 = FALSE; | 263 | cardInPcmcia0 = FALSE; |
@@ -336,25 +270,22 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
336 | } | 270 | } |
337 | 271 | ||
338 | 272 | ||
339 | bool CardMonitor::getStatusSd( int showPopUp ) | 273 | bool CardMonitor::getStatusSd( int showPopUp ) { |
340 | { | ||
341 | 274 | ||
342 | bool cardWas = cardInSd; // remember last state | 275 | bool cardWas = cardInSd; // remember last state |
343 | cardInSd = FALSE; | 276 | cardInSd = FALSE; |
344 | 277 | ||
345 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) | 278 | #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) |
279 | |||
346 | struct mntent *me; | 280 | struct mntent *me; |
347 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); | 281 | FILE *mntfp = setmntent( "/etc/mtab", "r" ); |
348 | 282 | ||
349 | if ( mntfp ) | 283 | if ( mntfp ) { |
350 | { | 284 | while ( ( me = getmntent( mntfp ) ) != 0 ) { |
351 | while ( ( me = getmntent( mntfp ) ) != 0 ) | ||
352 | { | ||
353 | QString fs = me->mnt_fsname; | 285 | QString fs = me->mnt_fsname; |
354 | //odebug << fs << oendl; | 286 | //odebug << fs << oendl; |
355 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" | 287 | if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd" |
356 | || fs.left( 9 ) == "/dev/mmcd" ) | 288 | || fs.left( 9 ) == "/dev/mmcd" ) { |
357 | { | ||
358 | cardInSd = TRUE; | 289 | cardInSd = TRUE; |
359 | show(); | 290 | show(); |
360 | } | 291 | } |
@@ -365,54 +296,85 @@ bool CardMonitor::getStatusSd( int showPopUp ) | |||
365 | endmntent( mntfp ); | 296 | endmntent( mntfp ); |
366 | } | 297 | } |
367 | 298 | ||
368 | if ( !showPopUp && cardWas != cardInSd ) | 299 | if ( !showPopUp && cardWas != cardInSd ) { |
369 | { | ||
370 | QString text = QString::null; | 300 | QString text = QString::null; |
371 | QString what = QString::null; | 301 | QString what = QString::null; |
372 | if ( cardInSd ) | 302 | if ( cardInSd ) { |
373 | { | ||
374 | text += "New card: SD/MMC"; | 303 | text += "New card: SD/MMC"; |
375 | what = "on"; | 304 | what = "on"; |
376 | } | 305 | } else { |
377 | else | ||
378 | { | ||
379 | text += "Ejected: SD/MMC"; | 306 | text += "Ejected: SD/MMC"; |
380 | what = "off"; | 307 | what = "off"; |
381 | } | 308 | } |
382 | //odebug << "TEXT: " + text << oendl; | 309 | //odebug << "TEXT: " + text << oendl; |
383 | #ifndef QT_NO_SOUND | 310 | #ifndef QT_NO_SOUND |
384 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); | 311 | QSound::play( Resource::findSound( "cardmon/card" + what ) ); |
385 | #endif | 312 | #endif |
313 | |||
386 | popUp( text, "cardmon/ide" ); // XX add SD pic | 314 | popUp( text, "cardmon/ide" ); // XX add SD pic |
387 | } | 315 | } |
388 | #else | 316 | #else |
389 | #error "Not on Linux" | 317 | #error "Not on Linux" |
390 | #endif | 318 | #endif |
391 | repaint( FALSE ); | 319 | repaint( FALSE ); |
392 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); | 320 | return ( ( cardWas == cardInSd ) ? FALSE : TRUE ); |
393 | } | 321 | } |
394 | 322 | ||
395 | void CardMonitor::paintEvent( QPaintEvent * ) | 323 | void CardMonitor::paintEvent( QPaintEvent * ) { |
396 | { | ||
397 | 324 | ||
398 | QPainter p( this ); | 325 | QPainter p( this ); |
399 | 326 | ||
400 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) | 327 | if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { |
401 | { | ||
402 | p.drawPixmap( 0, 0, pm ); | 328 | p.drawPixmap( 0, 0, pm ); |
403 | show(); | 329 | show(); |
404 | } | 330 | } else { |
405 | else | ||
406 | { | ||
407 | //p.eraseRect(rect()); | 331 | //p.eraseRect(rect()); |
408 | hide(); | 332 | hide(); |
409 | } | 333 | } |
410 | } | 334 | } |
411 | 335 | ||
412 | int CardMonitor::position() | 336 | int CardMonitor::position() { |
413 | { | ||
414 | return 7; | 337 | return 7; |
415 | } | 338 | } |
416 | 339 | ||
340 | void CardMonitor::execCommand( const QString &command ) { | ||
341 | |||
342 | if ( m_process == 0 ) { | ||
343 | m_process = new OProcess(); | ||
344 | QStringList strList = QStringList::split( " ", command ); | ||
345 | |||
346 | for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it ) { | ||
347 | *m_process << *it; | ||
348 | } | ||
349 | |||
350 | connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ), | ||
351 | this, SLOT( slotExited(Opie::Core::OProcess* ) ) ); | ||
352 | |||
353 | if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ) { | ||
354 | delete m_process; | ||
355 | m_process = 0; | ||
356 | } | ||
357 | } | ||
358 | } | ||
359 | |||
360 | void CardMonitor::slotExited( OProcess* proc ) { | ||
361 | |||
362 | if( m_process->normalExit() ) { | ||
363 | int ret = m_process->exitStatus(); | ||
364 | if( ret != 0 ) { | ||
365 | if ( m_commandOrig == 1 ) { | ||
366 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | ||
367 | } else if ( m_commandOrig == 2 ) { | ||
368 | popUp( tr( "SD/MMC card eject failed!" ) ); | ||
369 | } else if ( m_commandOrig == 3 ) { | ||
370 | popUp( tr( "CF/PCMCIA card eject failed!" ) ); | ||
371 | } | ||
372 | } | ||
373 | } | ||
374 | |||
375 | delete m_process; | ||
376 | m_process = 0; | ||
377 | } | ||
378 | |||
417 | EXPORT_OPIE_APPLET_v1( CardMonitor ) | 379 | EXPORT_OPIE_APPLET_v1( CardMonitor ) |
418 | 380 | ||
diff --git a/core/applets/cardmon/cardmon.h b/core/applets/cardmon/cardmon.h index 37de366..19d0394 100644 --- a/core/applets/cardmon/cardmon.h +++ b/core/applets/cardmon/cardmon.h | |||
@@ -23,6 +23,12 @@ | |||
23 | #include <qpixmap.h> | 23 | #include <qpixmap.h> |
24 | #include <qpopupmenu.h> | 24 | #include <qpopupmenu.h> |
25 | 25 | ||
26 | namespace Opie { | ||
27 | namespace Core { | ||
28 | class OProcess; | ||
29 | } | ||
30 | } | ||
31 | |||
26 | class CardMonitor : public QWidget { | 32 | class CardMonitor : public QWidget { |
27 | Q_OBJECT | 33 | Q_OBJECT |
28 | public: | 34 | public: |
@@ -33,12 +39,16 @@ public: | |||
33 | static int position(); | 39 | static int position(); |
34 | private slots: | 40 | private slots: |
35 | void cardMessage( const QCString &msg, const QByteArray & ); | 41 | void cardMessage( const QCString &msg, const QByteArray & ); |
42 | void slotExited( Opie::Core::OProcess* proc ); | ||
36 | void popupTimeout(); | 43 | void popupTimeout(); |
37 | 44 | ||
38 | protected: | 45 | protected: |
39 | void paintEvent( QPaintEvent* ); | 46 | void paintEvent( QPaintEvent* ); |
40 | void mousePressEvent( QMouseEvent * ); | 47 | void mousePressEvent( QMouseEvent * ); |
48 | |||
41 | private: | 49 | private: |
50 | void execCommand( const QString &command ); | ||
51 | int m_commandOrig; | ||
42 | QPixmap pm; | 52 | QPixmap pm; |
43 | // pcmcia socket 0 | 53 | // pcmcia socket 0 |
44 | bool cardInPcmcia0; | 54 | bool cardInPcmcia0; |
@@ -52,7 +62,8 @@ private: | |||
52 | void iconShow(); | 62 | void iconShow(); |
53 | QPopupMenu *popupMenu; | 63 | QPopupMenu *popupMenu; |
54 | void popUp(QString message, QString icon = QString::null ); | 64 | void popUp(QString message, QString icon = QString::null ); |
55 | }; | 65 | Opie::Core::OProcess* m_process; |
66 | }; | ||
56 | 67 | ||
57 | #endif | 68 | #endif |
58 | 69 | ||