author | davipt <davipt> | 2002-06-20 19:10:03 (UTC) |
---|---|---|
committer | davipt <davipt> | 2002-06-20 19:10:03 (UTC) |
commit | 8c55fec6394ca27aebf49692c643d71db32b7ebf (patch) (side-by-side diff) | |
tree | 652f92eb31431ddae39fa6e7cb58e8f1e8b9d5af /core/applets/cardmon/cardmon.cpp | |
parent | e3b199e4b3ad71cb8d046e33e792402250a8faec (diff) | |
download | opie-8c55fec6394ca27aebf49692c643d71db32b7ebf.zip opie-8c55fec6394ca27aebf49692c643d71db32b7ebf.tar.gz opie-8c55fec6394ca27aebf49692c643d71db32b7ebf.tar.bz2 |
Fix cardmon applet visibility (now visible is some card is plugged) and added
popup on succesfull ejection or insertion of a card.
Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 84 |
1 files changed, 56 insertions, 28 deletions
diff --git a/core/applets/cardmon/cardmon.cpp b/core/applets/cardmon/cardmon.cpp index 9522b88..ac2aea2 100644 --- a/core/applets/cardmon/cardmon.cpp +++ b/core/applets/cardmon/cardmon.cpp @@ -41,96 +41,102 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), pm( Resource::loadPixmap( "cardmon/pcmcia" ) ) { QCopChannel* pcmciaChannel = new QCopChannel( "QPE/Card", this ); connect( pcmciaChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); QCopChannel* sdChannel = new QCopChannel( "QPE/Card", this ); connect( sdChannel, SIGNAL(received(const QCString &, const QByteArray &)), this, SLOT(cardMessage( const QCString &, const QByteArray &)) ); - setFixedSize( pm.size() ); - hide(); - getStatusPcmcia(); + getStatusPcmcia(TRUE); + getStatusSd(TRUE); + repaint(FALSE); } CardMonitor::~CardMonitor() { } void CardMonitor::mousePressEvent( QMouseEvent * ) { QPopupMenu *menu = new QPopupMenu(); QString cmd; int err=0; if ( cardInSd ) { - menu->insertItem( tr("Eject SD/ MMC card"), 0 ); + menu->insertItem( tr("Eject SD/MMC card"), 0 ); } if ( cardInPcmcia0 ) { - menu->insertItem( tr("Eject card (0) %1").arg(cardInPcmcia0Name), 1 ); + menu->insertItem( tr("Eject card 0: %1").arg(cardInPcmcia0Name), 1 ); } if ( cardInPcmcia1 ) { - menu->insertItem( tr("Eject card (1) %1").arg(cardInPcmcia1Name), 2 ); + menu->insertItem( tr("Eject card 1: %1").arg(cardInPcmcia1Name), 2 ); } - QPoint p = mapToGlobal( QPoint(1, -menu->sizeHint().height()-1) ); + QPoint p = mapToGlobal ( QPoint ( 0, 0 )); + QSize s = menu->sizeHint ( ); + int opt = menu->exec( QPoint ( + p. x ( ) + ( width ( ) / 2 ) - ( s. width ( ) / 2 ), + p. y ( ) - s. height ( ) ), 0); - if ( menu->exec( p, 1 ) == 1 ) { + if ( opt == 1 ) { cmd = "/sbin/cardctl eject 0"; err = system( (const char *) cmd ); if ( ( err == 127 ) || ( err < 0 ) ) { qDebug("Could not execute `/sbin/cardctl eject 0'! err=%d", err); QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), tr("&OK") ); - } - } else if ( menu->exec( p, 1 ) == 0 ) { + } + } else if ( opt == 0 ) { cmd = "/etc/sdcontrol compeject"; err = system( (const char *) cmd ); if ( ( err != 0 ) ) { qDebug("Could not execute `/etc/sdcontrol comeject'! err=%d", err); QMessageBox::warning( this, tr("CardMonitor"), tr("SD/MMC card eject failed!"), tr("&OK") ); - } - } else if ( menu->exec( p, 1 ) == 2 ) { + } + } else if ( opt == 2 ) { cmd = "/sbin/cardctl eject 1"; err = system( (const char *) cmd ); if ( ( err == 127 ) || ( err < 0 ) ) { qDebug("Could not execute `/sbin/cardctl eject 1'! err=%d", err); QMessageBox::warning( this, tr("CardMonitor"), tr("CF/PCMCIA card eject failed!"), tr("&OK") ); - } + } } delete menu; } void CardMonitor::cardMessage( const QCString &msg, const QByteArray & ) { if ( msg == "stabChanged()" ) { + // qDebug("Pcmcia: stabchanged"); if ( getStatusPcmcia() ) { repaint(FALSE); } } else if ( msg == "mtabChanged()" ) { + // qDebug("Pcmcia: mtabchanged"); if ( getStatusSd() ) { repaint(FALSE); } } } -bool CardMonitor::getStatusPcmcia( void ) { +bool CardMonitor::getStatusPcmcia( int showPopUp = FALSE ) { bool cardWas0 = cardInPcmcia0; // remember last state bool cardWas1 = cardInPcmcia1; QString fileName; // one of these 3 files should exist if (QFile::exists("/var/run/stab")) { fileName = "/var/run/stab"; } else if (QFile::exists("/var/state/pcmcia/stab")) { fileName="/var/state/pcmcia/stab"; } else { @@ -138,93 +144,115 @@ bool CardMonitor::getStatusPcmcia( void ) { } QFile f(fileName); if ( f.open(IO_ReadOnly) ) { QStringList list; QTextStream stream ( &f); QString streamIn; streamIn = stream.read(); list = QStringList::split("\n", streamIn); for(QStringList::Iterator line=list.begin(); line!=list.end(); line++) { if( (*line).startsWith("Socket 0:") ){ - // extendable, maybe read out card name if( (*line).startsWith("Socket 0: empty") && cardInPcmcia0 ){ cardInPcmcia0 = FALSE; - hide(); } else if ( !(*line).startsWith("Socket 0: empty") && !cardInPcmcia0 ){ cardInPcmcia0Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); + cardInPcmcia0Name.stripWhiteSpace(); cardInPcmcia0 = TRUE; show(); } } if( (*line).startsWith("Socket 1:") ){ if( (*line).startsWith("Socket 1: empty") && cardInPcmcia1 ){ cardInPcmcia1 = FALSE; - hide(); } else if ( !(*line).startsWith("Socket 1: empty") && !cardInPcmcia1 ){ cardInPcmcia1Name = (*line).mid(((*line).find(':')+1), (*line).length()-9 ); + cardInPcmcia1Name.stripWhiteSpace(); cardInPcmcia1 = TRUE; show(); } } } } else { // no file found qDebug("no file found"); cardInPcmcia0 = FALSE; cardInPcmcia1 = FALSE; - hide(); return FALSE; } + if(!cardInPcmcia0 && !cardInPcmcia1) { + qDebug("Pcmcia: no cards"); + } + + if( !showPopUp && (cardWas0 != cardInPcmcia0 || cardWas1 != cardInPcmcia1)) { + QString text = ""; + if(cardWas0 != cardInPcmcia0) { + if(cardInPcmcia0) { text += tr("New card: "); } + else { text += tr("Ejected: "); } + text += cardInPcmcia0Name; + } + if(cardWas0 != cardInPcmcia0 && cardWas1 != cardInPcmcia1) { + text += "\n"; + } + if(cardWas1 != cardInPcmcia1) { + if(cardInPcmcia1) { text += tr("New card: "); } + else { text += tr("Ejected: "); } + text += cardInPcmcia1Name; + } + QMessageBox::warning( this, tr("CardMonitor"), text, + tr("&OK") ); + } + f.close(); return ((cardWas0 == cardInPcmcia0 || cardWas1 == cardInPcmcia1) ? FALSE : TRUE); } -bool CardMonitor::getStatusSd( void ) { +bool CardMonitor::getStatusSd( int showPopUp = FALSE ) { bool cardWas=cardInSd; // remember last state cardInSd=false; #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) struct mntent *me; FILE *mntfp = setmntent( "/etc/mtab", "r" ); if ( mntfp ) { while ( (me = getmntent( mntfp )) != 0 ) { QString fs = me->mnt_fsname; if ( fs.left(7)=="/dev/sd" || fs.left(9) == "/dev/mmcd" ) { cardInSd=true; } } endmntent( mntfp ); - if (cardInSd!=cardWas) { - if (cardInSd) { - show(); - } else { - hide(); - } - } - } else { - hide(); } + if(!showPopUp && cardWas != cardInSd) { + QString text = ""; + if(cardInSd) { text += "SD Inserted"; } + else { text += "SD Removed"; } + QMessageBox::warning( this, tr("CardMonitor"), text, + tr("&OK") ); + } + #else #error "Not on Linux" #endif return ((cardWas == cardInSd) ? FALSE : TRUE); } void CardMonitor::paintEvent( QPaintEvent * ) { QPainter p( this ); if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { p.drawPixmap( 0, 0, pm ); + show(); } else { p.eraseRect( rect() ); + hide(); } } |