From 3b02e2a868535628090567ed612d9fdb5b247f61 Mon Sep 17 00:00:00 2001 From: mickeyl Date: Mon, 20 Jun 2005 12:46:33 +0000 Subject: miscellaneous work towards completon of this applet - still some way to go though --- (limited to 'noncore/applets') diff --git a/noncore/applets/pcmcia/configdialog.cpp b/noncore/applets/pcmcia/configdialog.cpp index f961069..f5812ba 100644 --- a/noncore/applets/pcmcia/configdialog.cpp +++ b/noncore/applets/pcmcia/configdialog.cpp @@ -51,19 +51,27 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) txtManfid->setText( card->manufacturerIdentity() ); txtFunction->setText( card->function() ); - QString action = preferredAction( card ); + QString insertAction = preferredAction( card, "insert" ); + QString resumeAction = preferredAction( card, "resume" ); - odebug << "preferred action for card '" << card->name() << "' seems to be '" << action << "'" << oendl; + odebug << "pcmcia: preferred insertion action for card '" << card->name() << "' seems to be '" << insertAction << "'" << oendl; + odebug << "pcmcia: preferred resume action for card '" << card->name() << "' seems to be '" << resumeAction << "'" << oendl; - if ( !action.isEmpty() ) + if ( !insertAction.isEmpty() ) { - for ( int i; i < cbAction->count(); ++i ) - if ( cbAction->text( i ) == action ) cbAction->setCurrentItem( i ); + for ( int i; i < cbInsertAction->count(); ++i ) + if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i ); + } + + if ( !resumeAction.isEmpty() ) + { + for ( int i; i < cbResumeAction->count(); ++i ) + if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i ); } if ( !card->isUnsupported() ) { - odebug << "card is recognized - hiding bindings" << oendl; + odebug << "pcmcia: card is recognized - hiding bindings" << oendl; textInfo->hide(); textBindTo->hide(); cbBindTo->hide(); @@ -78,9 +86,6 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) } // parse possible bind entries out of /etc/pcmcia/*.conf - typedef QMap StringMap; - StringMap bindEntries; - QDir pcmciaconfdir( "/etc/pcmcia", "*.conf" ); for ( unsigned int i = 0; i < pcmciaconfdir.count(); ++i ) @@ -122,7 +127,7 @@ ConfigDialog::~ConfigDialog() { } -QString ConfigDialog::preferredAction( const OPcmciaSocket* card ) +void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value ) { OConfig cfg( "PCMCIA" ); cfg.setGroup( "Global" ); @@ -137,10 +142,36 @@ QString ConfigDialog::preferredAction( const OPcmciaSocket* card ) odebug << "comparing card '" << card->name() << "' with known card '" << name << "'" << oendl; if ( card->name() == name ) { - action = cfg.readEntry( "action" ); + cfg.writeEntry( key, value ); break; } } +} - return action; +QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue ) +{ + OConfig cfg( "PCMCIA" ); + cfg.setGroup( "Global" ); + int nCards = cfg.readNumEntry( "nCards", 0 ); + QString value; + + for ( int i = 0; i < nCards; ++i ) + { + QString cardSection = QString( "Card_%1" ).arg( i ); + cfg.setGroup( cardSection ); + QString name = cfg.readEntry( "name" ); + odebug << "comparing card '" << card->name() << "' with known card '" << name << "'" << oendl; + if ( card->name() == name ) + { + value = cfg.readEntry( key, defaultValue ); + break; + } + } + return value; +} + + +QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type ) +{ + return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" ); } diff --git a/noncore/applets/pcmcia/configdialog.h b/noncore/applets/pcmcia/configdialog.h index 321180d..169dadb 100644 --- a/noncore/applets/pcmcia/configdialog.h +++ b/noncore/applets/pcmcia/configdialog.h @@ -34,13 +34,18 @@ namespace Opie { namespace Core { class OPcmciaSocket; }; }; +typedef QMap StringMap; + class ConfigDialog : public ConfigDialogBase { Q_OBJECT public: ConfigDialog( const Opie::Core::OPcmciaSocket* card, QWidget* parent ); ~ConfigDialog(); - static QString preferredAction( const Opie::Core::OPcmciaSocket* card ); + static QString preferredAction( const Opie::Core::OPcmciaSocket* card, const QString& type ); + static QString readConfigEntry( const Opie::Core::OPcmciaSocket* card, const QString& key, const QString& defaultValue ); + static void writeConfigEntry( const Opie::Core::OPcmciaSocket* card, const QString& key, const QString& value ); + StringMap bindEntries; }; #endif diff --git a/noncore/applets/pcmcia/configdialogbase.ui b/noncore/applets/pcmcia/configdialogbase.ui index 829b71a..97d9a50 100644 --- a/noncore/applets/pcmcia/configdialogbase.ui +++ b/noncore/applets/pcmcia/configdialogbase.ui @@ -11,7 +11,7 @@ 0 0 - 215 + 211 329 @@ -28,7 +28,7 @@ margin - 5 + 6 spacing @@ -148,60 +148,7 @@ - - QLabel - - name - TextLabel2 - - - text - On insertion, - - - - QComboBox - - - text - suspend - - - - - text - activate - - - - - text - eject - - - - - text - prompt for - - - - name - cbAction - - - - QLabel - - name - TextLabel3 - - - text - card - - - + QLabel name @@ -212,7 +159,7 @@ Bind to: - + QComboBox @@ -244,7 +191,7 @@ false - + QLabel name @@ -271,7 +218,51 @@ <qt>CAUTION: This card is not yet recognized by your system. Without a valid binding, your card may not function correctly. Please choose a driver to bind the card to below:</qt> - + + QLabel + + name + TextLabel2 + + + text + On insertion, + + + + QLabel + + name + TextLabel3 + + + text + card + + + + QLabel + + name + TextLabel2_2 + + + text + On resume, + + + + QLabel + + name + TextLabel3_2 + + + text + card + + + name Spacer2 @@ -292,6 +283,68 @@ + + QComboBox + + + text + suspend + + + + + text + activate + + + + + text + eject + + + + + text + prompt for + + + + name + cbInsertAction + + + + QComboBox + + + text + suspend + + + + + text + activate + + + + + text + eject + + + + + text + prompt for + + + + name + cbResumeAction + + diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp index 1a2b619..186dfea 100644 --- a/noncore/applets/pcmcia/pcmcia.cpp +++ b/noncore/applets/pcmcia/pcmcia.cpp @@ -39,11 +39,13 @@ #include #include #include +#include #include using namespace Opie::Core; using namespace Opie::Ui; /* QT */ +#include #include #include #include @@ -178,7 +180,7 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) { if ( it.current()->isEmpty() ) { - odebug << "skipping empty card in socket " << it.current()->number() << oendl; + odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl; ++it; continue; } @@ -191,7 +193,7 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) QString cardSection = QString( "Card_%1" ).arg( i ); cfg.setGroup( cardSection ); QString name = cfg.readEntry( "name" ); - odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; + odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl; if ( cardName == name ) { newCard = false; @@ -207,26 +209,50 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace(); int result = QMessageBox::information( qApp->desktop(), tr( "PCMCIA/CF Subsystem" ), - tr( "You have inserted the card '%1'. This card is not yet configured. Do you want to configure it now?" ).arg( newCardName ), + tr( "You have inserted the card
%1
This card is not yet configured. Do you want to configure it now?
" ).arg( newCardName ), tr( "Yes" ), tr( "No" ), 0, 0, 1 ); - odebug << "result = " << result << oendl; + odebug << "pcmcia: result = " << result << oendl; if ( result == 0 ) { - bool configured = configure( theCard ); + QString insertAction; QString resumeAction; QString driver; QString conf; + bool configured = configure( theCard, insertAction, resumeAction, driver, conf ); if ( configured ) { - odebug << "card has been configured. writing out to dabase" << oendl; + odebug << "pcmcia: card has been configured. writing out to database" << oendl; cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); cfg.writeEntry( "name", newCardName ); - cfg.writeEntry( "insert", "suspend" ); + cfg.writeEntry( "insertAction", insertAction ); + cfg.writeEntry( "resumeAction", resumeAction ); cfg.setGroup( "Global" ); cfg.writeEntry( "nCards", nCards+1 ); cfg.write(); + + QFile confFile( QString( "/etc/pcmcia/%1" ).arg( conf ) ); + if ( confFile.open( IO_ReadWrite | IO_Append ) ) + { + QString entryCard = QString( "card \"%1\"" ).arg( newCardName ); + QString entryVersion( " version " ); + for ( QStringList::Iterator it = theCard->productIdentity().begin(); it != theCard->productIdentity().end(); ++it ) + { + entryVersion += QString( "\"%1\", " ).arg( *it ); + } + QString entryBind = QString( " bind %1" ).arg( driver ); + QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind ); + odebug << "pcmcia: writing entry...:" << entry << oendl; + + confFile.writeBlock( (const char*) entry, entry.length() ); + Global::statusMessage( "restarting pcmcia services..." ); + ::system( "/etc/init.d/pcmcia restart" ); + } + else + { + owarn << "pcmcia: couldn't write binding to '" << conf << "'." << oendl; + } } else { - odebug << "card has not been configured this time. leaving as unknown card" << oendl; + odebug << "pcmcia: card has not been configured this time. leaving as unknown card" << oendl; } } else @@ -236,9 +262,9 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) } else // it's an already configured card { - QString action = ConfigDialog::preferredAction( theCard ); + QString insertAction = ConfigDialog::preferredAction( theCard, "insert" ); odebug << "pcmcia: card has been previously configured" << oendl; - odebug << "pcmcia: need to perform action'" << action << "' now... sorry, not yet implemented..." << oendl; + odebug << "pcmcia: TODO: need to perform action'" << insertAction << "' now... sorry, not yet implemented..." << oendl; } repaint( true ); } @@ -271,7 +297,7 @@ void PcmciaManager::execCommand( const QStringList &strList ) void PcmciaManager::userCardAction( int action ) { - odebug << "user action on socket " << action / 100 << " requested. action = " << action << oendl; + odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl; int socket = action / 100; int what = action % 100; @@ -279,29 +305,42 @@ void PcmciaManager::userCardAction( int action ) switch ( what ) { - case CONFIGURE: configure( OPcmciaSystem::instance()->socket( socket ) ); success = true; break; + case CONFIGURE: + { + QString insertAction; QString resumeAction; QString driver; QString conf; + bool result = configure( OPcmciaSystem::instance()->socket( socket ), insertAction, resumeAction, driver, conf ); + success = true; + break; + } case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); break; case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); break; case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); break; case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); break; case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); break; - default: odebug << "not yet implemented" << oendl; + default: odebug << "pcmcia: not yet implemented" << oendl; } if ( !success ) { - owarn << "couldn't perform user action (" << strerror( errno ) << ")" << oendl; + owarn << "pcmcia: couldn't perform user action (" << strerror( errno ) << ")" << oendl; } } -bool PcmciaManager::configure( OPcmciaSocket* card ) +bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QString& resumeAction, QString& driver, QString& conf ) { configuring = true; ConfigDialog dialog( card, qApp->desktop() ); int configresult = QPEApplication::execDialog( &dialog, false ); configuring = false; odebug << "pcmcia: configresult = " << configresult << oendl; + if ( configresult ) + { + insertAction = dialog.cbInsertAction->currentText(); + resumeAction = dialog.cbResumeAction->currentText(); + driver = dialog.cbBindTo->currentText(); + conf = dialog.bindEntries[driver]; + } return configresult; } diff --git a/noncore/applets/pcmcia/pcmcia.h b/noncore/applets/pcmcia/pcmcia.h index eb9c513..94203d3 100644 --- a/noncore/applets/pcmcia/pcmcia.h +++ b/noncore/applets/pcmcia/pcmcia.h @@ -54,7 +54,7 @@ class PcmciaManager : public QWidget void mousePressEvent( QMouseEvent * ); private: - bool configure( Opie::Core::OPcmciaSocket* ); + bool configure( Opie::Core::OPcmciaSocket*, QString&, QString&, QString&, QString& ); void execCommand( const QStringList &command ); void popUp(QString message, QString icon = QString::null ); -- cgit v0.9.0.2