summaryrefslogtreecommitdiff
path: root/noncore/applets/pcmcia/pcmcia.cpp
Side-by-side diff
Diffstat (limited to 'noncore/applets/pcmcia/pcmcia.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp69
1 files changed, 54 insertions, 15 deletions
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
@@ -30,29 +30,31 @@
#include "pcmcia.h"
#include "configdialog.h"
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/odevice.h>
#include <opie2/oconfig.h>
#include <opie2/oprocess.h>
#include <opie2/opcmciasystem.h>
#include <opie2/oresource.h>
#include <opie2/otaskbarapplet.h>
#include <qpe/applnk.h>
+#include <qpe/global.h>
#include <qpe/resource.h>
using namespace Opie::Core;
using namespace Opie::Ui;
/* QT */
+#include <qcombobox.h>
#include <qcopchannel_qws.h>
#include <qpainter.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qmessagebox.h>
#include <qsound.h>
#include <qtimer.h>
/* STD */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
@@ -169,85 +171,109 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
int nCards = cfg.readNumEntry( "nCards", 0 );
OPcmciaSystem* sys = OPcmciaSystem::instance();
OPcmciaSystem::CardIterator it = sys->iterator();
bool newCard = true;
OPcmciaSocket* theCard = 0;
while ( it.current() && newCard )
{
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;
}
else
{
theCard = it.current();
QString cardName = theCard->productIdentity().join( " " );
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 '" << cardName << "' with known card '" << name << "'" << oendl;
+ odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
if ( cardName == name )
{
newCard = false;
break;
}
}
if ( !newCard ) ++it; else break;
}
}
if ( newCard )
{
odebug << "pcmcia: unconfigured card detected" << oendl;
QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace();
int result = QMessageBox::information( qApp->desktop(),
tr( "PCMCIA/CF Subsystem" ),
- tr( "<qt>You have inserted the card '%1'. This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ),
+ tr( "<qt>You have inserted the card<br/><b>%1</b><br/>This card is not yet configured. Do you want to configure it now?</qt>" ).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
{
odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl;
}
}
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 );
}
void PcmciaManager::paintEvent( QPaintEvent * )
{
QPainter p( this );
odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl;
if ( OPcmciaSystem::instance()->cardCount() )
{
@@ -262,49 +288,62 @@ void PcmciaManager::paintEvent( QPaintEvent * )
int PcmciaManager::position()
{
return 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;
bool success = false;
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;
}
EXPORT_OPIE_APPLET_v1( PcmciaManager )