Diffstat (limited to 'core/applets/cardmon/cardmon.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/cardmon/cardmon.cpp | 74 |
1 files changed, 51 insertions, 23 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 @@ -49,12 +49,12 @@ CardMonitor::CardMonitor( QWidget *parent ) : QWidget( parent ), 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() { } @@ -68,35 +68,39 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { 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); @@ -110,19 +114,21 @@ void CardMonitor::mousePressEvent( QMouseEvent * ) { 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; @@ -146,24 +152,23 @@ bool CardMonitor::getStatusPcmcia( void ) { 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(); } } @@ -172,20 +177,42 @@ bool CardMonitor::getStatusPcmcia( void ) { // 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; @@ -200,18 +227,17 @@ bool CardMonitor::getStatusSd( void ) { 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); @@ -221,10 +247,12 @@ void CardMonitor::paintEvent( QPaintEvent * ) { QPainter p( this ); if ( cardInPcmcia0 || cardInPcmcia1 || cardInSd ) { p.drawPixmap( 0, 0, pm ); + show(); } else { p.eraseRect( rect() ); + hide(); } } |