summaryrefslogtreecommitdiff
authorharlekin <harlekin>2004-06-04 17:46:18 (UTC)
committer harlekin <harlekin>2004-06-04 17:46:18 (UTC)
commit1989c6f43aecffc9ec1a7b677e98435beff54886 (patch) (side-by-side diff)
tree798d1255e59c120fda9b853c5b31a29bcbe07edf
parente3982ce0959fe630709aeba25f4c6d93df150ff5 (diff)
downloadopie-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
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/applets/cardmon/cardmon.cpp260
-rw-r--r--core/applets/cardmon/cardmon.h13
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 @@
#include <opie2/otaskbarapplet.h>
+#include <opie2/oprocess.h>
+
#include <qpe/applnk.h>
@@ -49,4 +51,3 @@ using namespace Opie::Ui;
CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ),
- pm( Resource::loadPixmap( "cardmon/pcmcia" ) )
-{
+pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) {
@@ -65,2 +66,3 @@ CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ),
cardInSd = FALSE;
+ m_process = 0;
@@ -77,14 +79,8 @@ CardMonitor::CardMonitor( QWidget * parent ) : QWidget( parent ),
-CardMonitor::~CardMonitor()
-{
- if ( popupMenu )
- {
- delete popupMenu;
- }
+CardMonitor::~CardMonitor() {
+ delete popupMenu;
}
-void CardMonitor::popUp( QString message, QString icon )
-{
- if ( !popupMenu )
- {
+void CardMonitor::popUp( QString message, QString icon ) {
+ if ( !popupMenu ) {
popupMenu = new QPopupMenu( this );
@@ -93,8 +89,5 @@ void CardMonitor::popUp( QString message, QString icon )
popupMenu->clear();
- if ( icon.isEmpty() )
- {
+ if ( icon.isEmpty() ) {
popupMenu->insertItem( message, 0 );
- }
- else
- {
+ } else {
popupMenu->insertItem( QIconSet( Resource::loadPixmap( icon ) ),
@@ -111,4 +104,3 @@ void CardMonitor::popUp( QString message, QString icon )
-void CardMonitor::popupTimeout()
-{
+void CardMonitor::popupTimeout() {
popupMenu->hide();
@@ -116,10 +108,7 @@ void CardMonitor::popupTimeout()
-void CardMonitor::mousePressEvent( QMouseEvent * )
-{
+void CardMonitor::mousePressEvent( QMouseEvent * ) {
QPopupMenu * menu = new QPopupMenu( this );
QString cmd;
- int err = 0;
- if ( cardInSd )
- {
+ if ( cardInSd ) {
menu->insertItem( QIconSet( Resource::loadPixmap( "cardmon/ide" ) ),
@@ -128,4 +117,3 @@ void CardMonitor::mousePressEvent( QMouseEvent * )
- if ( cardInPcmcia0 )
- {
+ if ( cardInPcmcia0 ) {
menu->
@@ -136,4 +124,3 @@ void CardMonitor::mousePressEvent( QMouseEvent * )
- if ( cardInPcmcia1 )
- {
+ if ( cardInPcmcia1 ) {
menu->
@@ -149,37 +136,16 @@ void CardMonitor::mousePressEvent( QMouseEvent * )
- if ( opt == 1 )
- {
- cmd = "/sbin/cardctl eject 0";
- err = system( ( const char * ) cmd );
- if ( err != 0 )
- {
- odebug << "Could not execute `/sbin/cardctl eject 0'! err=" << err << oendl;
- popUp( tr( "CF/PCMCIA card eject failed!" ) );
- }
- }
- else if ( opt == 0 )
- {
- if ( ODevice::inst() ->system() == System_Familiar )
- {
+ if ( opt == 1 ) {
+ m_commandOrig = 1;
+ execCommand("/sbin/cardctl eject 0");
+ } else if ( opt == 0 ) {
+ if ( ODevice::inst() ->system() == System_Familiar ) {
cmd = "umount /dev/mmc/part1";
- }
- else
- {
+ } else {
cmd = "umount /dev/mmcda1";
}
- err = system( ( const char * ) cmd );
- if ( err != 0 )
- {
- popUp( tr( "SD/MMC card eject failed!" ) );
- }
- }
- else if ( opt == 2 )
- {
- cmd = "/sbin/cardctl eject 1";
- err = system( ( const char * ) cmd );
- if ( err != 0 )
- {
- odebug << "Could not execute `/sbin/cardctl eject 1'! err=" << err << oendl;
- popUp( tr( "CF/PCMCIA card eject failed!" ) );
- }
+ m_commandOrig = 2;
+ execCommand( cmd );
+ } else if ( opt == 2 ) {
+ m_commandOrig = 3;
+ execCommand( "/sbin/cardctl eject 1" );
}
@@ -189,11 +155,7 @@ void CardMonitor::mousePressEvent( QMouseEvent * )
-void CardMonitor::cardMessage( const QCString & msg, const QByteArray & )
-{
- if ( msg == "stabChanged()" )
- {
+void CardMonitor::cardMessage( const QCString & msg, const QByteArray & ) {
+ if ( msg == "stabChanged()" ) {
// odebug << "Pcmcia: stabchanged" << oendl;
getStatusPcmcia();
- }
- else if ( msg == "mtabChanged()" )
- {
+ } else if ( msg == "mtabChanged()" ) {
// odebug << "CARDMONAPPLET: mtabchanged" << oendl;
@@ -203,4 +165,3 @@ void CardMonitor::cardMessage( const QCString & msg, const QByteArray & )
-bool CardMonitor::getStatusPcmcia( int showPopUp )
-{
+bool CardMonitor::getStatusPcmcia( int showPopUp ) {
@@ -212,12 +173,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
// one of these 3 files should exist
- if ( QFile::exists( "/var/run/stab" ) )
- {
+ if ( QFile::exists( "/var/run/stab" ) ) {
fileName = "/var/run/stab";
- }
- else if ( QFile::exists( "/var/state/pcmcia/stab" ) )
- {
+ } else if ( QFile::exists( "/var/state/pcmcia/stab" ) ) {
fileName = "/var/state/pcmcia/stab";
- }
- else
- {
+ } else {
fileName = "/var/lib/pcmcia/stab";
@@ -227,4 +183,3 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
- if ( f.open( IO_ReadOnly ) )
- {
+ if ( f.open( IO_ReadOnly ) ) {
QStringList list;
@@ -235,13 +190,8 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
for ( QStringList::Iterator line = list.begin(); line != list.end();
- line++ )
- {
- if ( ( *line ).startsWith( "Socket 0:" ) )
- {
- if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 )
- {
+ line++ ) {
+ if ( ( *line ).startsWith( "Socket 0:" ) ) {
+ if ( ( *line ).startsWith( "Socket 0: empty" ) && cardInPcmcia0 ) {
cardInPcmcia0 = FALSE;
- }
- else if ( !( *line ).startsWith( "Socket 0: empty" )
- && !cardInPcmcia0 )
- {
+ } else if ( !( *line ).startsWith( "Socket 0: empty" )
+ && !cardInPcmcia0 ) {
cardInPcmcia0Name =
@@ -257,12 +207,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
}
- }
- else if ( ( *line ).startsWith( "Socket 1:" ) )
- {
- if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 )
- {
+ } else if ( ( *line ).startsWith( "Socket 1:" ) ) {
+ if ( ( *line ).startsWith( "Socket 1: empty" ) && cardInPcmcia1 ) {
cardInPcmcia1 = FALSE;
- }
- else if ( !( *line ).startsWith( "Socket 1: empty" )
- && !cardInPcmcia1 )
- {
+ } else if ( !( *line ).startsWith( "Socket 1: empty" )
+ && !cardInPcmcia1 ) {
cardInPcmcia1Name =
@@ -283,15 +228,10 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
if ( !showPopUp
- && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) )
- {
+ && ( cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1 ) ) {
QString text = QString::null;
QString what = QString::null;
- if ( cardWas0 != cardInPcmcia0 )
- {
- if ( cardInPcmcia0 )
- {
+ if ( cardWas0 != cardInPcmcia0 ) {
+ if ( cardInPcmcia0 ) {
text += tr( "New card: " );
what = "on";
- }
- else
- {
+ } else {
text += tr( "Ejected: " );
@@ -303,11 +243,7 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
- if ( cardWas1 != cardInPcmcia1 )
- {
- if ( cardInPcmcia1 )
- {
+ if ( cardWas1 != cardInPcmcia1 ) {
+ if ( cardInPcmcia1 ) {
text += tr( "New card: " );
what = "on";
- }
- else
- {
+ } else {
text += tr( "Ejected: " );
@@ -318,10 +254,8 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
}
-#ifndef QT_NO_SOUND
+ #ifndef QT_NO_SOUND
QSound::play( Resource::findSound( "cardmon/card" + what ) );
-#endif
+ #endif
}
- }
- else
- {
+ } else {
// no file found
@@ -338,4 +272,3 @@ bool CardMonitor::getStatusPcmcia( int showPopUp )
-bool CardMonitor::getStatusSd( int showPopUp )
-{
+bool CardMonitor::getStatusSd( int showPopUp ) {
@@ -344,3 +277,4 @@ bool CardMonitor::getStatusSd( int showPopUp )
-#if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
+ #if defined(_OS_LINUX_) || defined(Q_OS_LINUX)
+
struct mntent *me;
@@ -348,6 +282,4 @@ bool CardMonitor::getStatusSd( int showPopUp )
- if ( mntfp )
- {
- while ( ( me = getmntent( mntfp ) ) != 0 )
- {
+ if ( mntfp ) {
+ while ( ( me = getmntent( mntfp ) ) != 0 ) {
QString fs = me->mnt_fsname;
@@ -355,4 +287,3 @@ bool CardMonitor::getStatusSd( int showPopUp )
if ( fs.left( 14 ) == "/dev/mmc/part1" || fs.left( 7 ) == "/dev/sd"
- || fs.left( 9 ) == "/dev/mmcd" )
- {
+ || fs.left( 9 ) == "/dev/mmcd" ) {
cardInSd = TRUE;
@@ -367,13 +298,9 @@ bool CardMonitor::getStatusSd( int showPopUp )
- if ( !showPopUp && cardWas != cardInSd )
- {
+ if ( !showPopUp && cardWas != cardInSd ) {
QString text = QString::null;
QString what = QString::null;
- if ( cardInSd )
- {
+ if ( cardInSd ) {
text += "New card: SD/MMC";
what = "on";
- }
- else
- {
+ } else {
text += "Ejected: SD/MMC";
@@ -382,10 +309,11 @@ bool CardMonitor::getStatusSd( int showPopUp )
//odebug << "TEXT: " + text << oendl;
-#ifndef QT_NO_SOUND
+ #ifndef QT_NO_SOUND
QSound::play( Resource::findSound( "cardmon/card" + what ) );
-#endif
+ #endif
+
popUp( text, "cardmon/ide" ); // XX add SD pic
}
-#else
-#error "Not on Linux"
-#endif
+ #else
+ #error "Not on Linux"
+ #endif
repaint( FALSE );
@@ -394,4 +322,3 @@ bool CardMonitor::getStatusSd( int showPopUp )
-void CardMonitor::paintEvent( QPaintEvent * )
-{
+void CardMonitor::paintEvent( QPaintEvent * ) {
@@ -399,9 +326,6 @@ void CardMonitor::paintEvent( QPaintEvent * )
- if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd )
- {
+ if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) {
p.drawPixmap( 0, 0, pm );
show();
- }
- else
- {
+ } else {
//p.eraseRect(rect());
@@ -411,4 +335,3 @@ void CardMonitor::paintEvent( QPaintEvent * )
-int CardMonitor::position()
-{
+int CardMonitor::position() {
return 7;
@@ -416,2 +339,41 @@ int CardMonitor::position()
+void CardMonitor::execCommand( const QString &command ) {
+
+ if ( m_process == 0 ) {
+ m_process = new OProcess();
+ QStringList strList = QStringList::split( " ", command );
+
+ for ( QStringList::Iterator it = strList.begin(); it != strList.end(); ++it ) {
+ *m_process << *it;
+ }
+
+ connect(m_process, SIGNAL( processExited(Opie::Core::OProcess*) ),
+ this, SLOT( slotExited(Opie::Core::OProcess* ) ) );
+
+ if(!m_process->start(OProcess::NotifyOnExit, OProcess::AllOutput ) ) {
+ delete m_process;
+ m_process = 0;
+ }
+ }
+}
+
+void CardMonitor::slotExited( OProcess* proc ) {
+
+ if( m_process->normalExit() ) {
+ int ret = m_process->exitStatus();
+ if( ret != 0 ) {
+ if ( m_commandOrig == 1 ) {
+ popUp( tr( "CF/PCMCIA card eject failed!" ) );
+ } else if ( m_commandOrig == 2 ) {
+ popUp( tr( "SD/MMC card eject failed!" ) );
+ } else if ( m_commandOrig == 3 ) {
+ popUp( tr( "CF/PCMCIA card eject failed!" ) );
+ }
+ }
+ }
+
+ delete m_process;
+ m_process = 0;
+}
+
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 @@
+namespace Opie {
+ namespace Core {
+ class OProcess;
+ }
+}
+
class CardMonitor : public QWidget {
@@ -35,2 +41,3 @@ private slots:
void cardMessage( const QCString &msg, const QByteArray & );
+ void slotExited( Opie::Core::OProcess* proc );
void popupTimeout();
@@ -40,3 +47,6 @@ protected:
void mousePressEvent( QMouseEvent * );
+
private:
+ void execCommand( const QString &command );
+ int m_commandOrig;
QPixmap pm;
@@ -54,3 +64,4 @@ private:
void popUp(QString message, QString icon = QString::null );
- };
+ Opie::Core::OProcess* m_process;
+};