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 | |||
@@ -24,2 +24,4 @@ | |||
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> |
@@ -49,4 +51,3 @@ using namespace Opie::Ui; | |||
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 | ||
@@ -65,2 +66,3 @@ CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), | |||
65 | cardInSd = FALSE; | 66 | cardInSd = FALSE; |
67 | m_process = 0; | ||
66 | 68 | ||
@@ -77,14 +79,8 @@ CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ), | |||
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 ); |
@@ -93,8 +89,5 @@ void CardMonitor::popUp( QString message, QString icon ) | |||
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 ) ), |
@@ -111,4 +104,3 @@ void CardMonitor::popUp( QString message, QString icon ) | |||
111 | 104 | ||
112 | void CardMonitor::popupTimeout() | 105 | void CardMonitor::popupTimeout() { |
113 | { | ||
114 | popupMenu->hide(); | 106 | popupMenu->hide(); |
@@ -116,10 +108,7 @@ void CardMonitor::popupTimeout() | |||
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" ) ), |
@@ -128,4 +117,3 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) | |||
128 | 117 | ||
129 | if ( cardInPcmcia0 ) | 118 | if ( cardInPcmcia0 ) { |
130 | { | ||
131 | menu-> | 119 | menu-> |
@@ -136,4 +124,3 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) | |||
136 | 124 | ||
137 | if ( cardInPcmcia1 ) | 125 | if ( cardInPcmcia1 ) { |
138 | { | ||
139 | menu-> | 126 | menu-> |
@@ -149,37 +136,16 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) | |||
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 | } |
@@ -189,11 +155,7 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) | |||
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; |
@@ -203,4 +165,3 @@ void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) | |||
203 | 165 | ||
204 | bool CardMonitor::getStatusPcmcia( int showPopUp ) | 166 | bool CardMonitor::getStatusPcmcia( int showPopUp ) { |
205 | { | ||
206 | 167 | ||
@@ -212,12 +173,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
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"; |
@@ -227,4 +183,3 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
227 | 183 | ||
228 | if ( f.open( IO_ReadOnly ) ) | 184 | if ( f.open( IO_ReadOnly ) ) { |
229 | { | ||
230 | QStringList list; | 185 | QStringList list; |
@@ -235,13 +190,8 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
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 = |
@@ -257,12 +207,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
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 = |
@@ -283,15 +228,10 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
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: " ); |
@@ -303,11 +243,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
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: " ); |
@@ -318,10 +254,8 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
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 |
@@ -338,4 +272,3 @@ bool CardMonitor::getStatusPcmcia( int showPopUp ) | |||
338 | 272 | ||
339 | bool CardMonitor::getStatusSd( int showPopUp ) | 273 | bool CardMonitor::getStatusSd( int showPopUp ) { |
340 | { | ||
341 | 274 | ||
@@ -344,3 +277,4 @@ bool CardMonitor::getStatusSd( int showPopUp ) | |||
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; |
@@ -348,6 +282,4 @@ bool CardMonitor::getStatusSd( int showPopUp ) | |||
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; |
@@ -355,4 +287,3 @@ bool CardMonitor::getStatusSd( int showPopUp ) | |||
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; |
@@ -367,13 +298,9 @@ bool CardMonitor::getStatusSd( int showPopUp ) | |||
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"; |
@@ -382,10 +309,11 @@ bool CardMonitor::getStatusSd( int showPopUp ) | |||
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 ); |
@@ -394,4 +322,3 @@ bool CardMonitor::getStatusSd( int showPopUp ) | |||
394 | 322 | ||
395 | void CardMonitor::paintEvent( QPaintEvent * ) | 323 | void CardMonitor::paintEvent( QPaintEvent * ) { |
396 | { | ||
397 | 324 | ||
@@ -399,9 +326,6 @@ void CardMonitor::paintEvent( QPaintEvent * ) | |||
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()); |
@@ -411,4 +335,3 @@ void CardMonitor::paintEvent( QPaintEvent * ) | |||
411 | 335 | ||
412 | int CardMonitor::position() | 336 | int CardMonitor::position() { |
413 | { | ||
414 | return 7; | 337 | return 7; |
@@ -416,2 +339,41 @@ int CardMonitor::position() | |||
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 ) |
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 | |||
@@ -25,2 +25,8 @@ | |||
25 | 25 | ||
26 | namespace Opie { | ||
27 | namespace Core { | ||
28 | class OProcess; | ||
29 | } | ||
30 | } | ||
31 | |||
26 | class CardMonitor : public QWidget { | 32 | class CardMonitor : public QWidget { |
@@ -35,2 +41,3 @@ 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(); |
@@ -40,3 +47,6 @@ protected: | |||
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; |
@@ -54,3 +64,4 @@ private: | |||
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 | ||