author | mickeyl <mickeyl> | 2005-06-20 12:46:33 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-06-20 12:46:33 (UTC) |
commit | 3b02e2a868535628090567ed612d9fdb5b247f61 (patch) (side-by-side diff) | |
tree | 6bc0281825b61316c594747b111b479f68115f37 | |
parent | 1a3c172bd98026a555d65e802647f0511e80d3a6 (diff) | |
download | opie-3b02e2a868535628090567ed612d9fdb5b247f61.zip opie-3b02e2a868535628090567ed612d9fdb5b247f61.tar.gz opie-3b02e2a868535628090567ed612d9fdb5b247f61.tar.bz2 |
miscellaneous work towards completon of this applet - still some way to go though
-rw-r--r-- | noncore/applets/pcmcia/configdialog.cpp | 55 | ||||
-rw-r--r-- | noncore/applets/pcmcia/configdialog.h | 7 | ||||
-rw-r--r-- | noncore/applets/pcmcia/configdialogbase.ui | 171 | ||||
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.cpp | 69 | ||||
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.h | 2 |
5 files changed, 216 insertions, 88 deletions
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 @@ -6,141 +6,172 @@ _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "configdialog.h" /* OPIE */ #include <opie2/oconfig.h> #include <opie2/odebug.h> #include <opie2/opcmciasystem.h> using namespace Opie::Core; /* QT */ #include <qcombobox.h> #include <qdir.h> #include <qfile.h> #include <qgroupbox.h> #include <qlabel.h> #include <qtextstream.h> ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) :ConfigDialogBase( parent, "pcmcia config dialog", true ) { gbDetails->setTitle( QString( "Details for card in socket #%1" ).arg( card->number() ) ); txtCardName->setText( card->productIdentity().join( " " ) ); 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(); return; } else { odebug << "card is unsupported yet - showing possible bindings" << oendl; textInfo->show(); textBindTo->show(); cbBindTo->show(); } // parse possible bind entries out of /etc/pcmcia/*.conf - typedef QMap<QString,QString> StringMap; - StringMap bindEntries; - QDir pcmciaconfdir( "/etc/pcmcia", "*.conf" ); for ( unsigned int i = 0; i < pcmciaconfdir.count(); ++i ) { odebug << "processing conf file '" << pcmciaconfdir[i] << "'" << oendl; QString conffilename = QString( "%1/%2" ).arg( pcmciaconfdir.absPath() ).arg( pcmciaconfdir[i] ); QFile conffile( conffilename ); if ( conffile.open( IO_ReadOnly ) ) { QTextStream ts( &conffile ); while ( !ts.atEnd() ) { QString word; ts >> word; if ( word == "bind" ) { word = ts.readLine(); bindEntries[ word.stripWhiteSpace() ] = conffilename; continue; } ts.readLine(); } } else { owarn << "couldn't open '" << conffile.name() << "' for reading" << oendl; continue; } } for ( StringMap::Iterator it = bindEntries.begin(); it != bindEntries.end(); ++it ) { odebug << "found binding '" << it.key() << "' defined in '" << it.data().latin1() << "'" << oendl; cbBindTo->insertItem( it.key() ); } } 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" ); int nCards = cfg.readNumEntry( "nCards", 0 ); QString action; 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 ) { - 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 @@ -1,46 +1,51 @@ /* This file is part of the Opie Project =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef CONFIGDIALOG_H #define CONFIGDIALOG_H #include "configdialogbase.h" namespace Opie { namespace Core { class OPcmciaSocket; }; }; +typedef QMap<QString,QString> 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 @@ -1,79 +1,79 @@ <!DOCTYPE UI><UI> <class>ConfigDialogBase</class> <widget> <class>QDialog</class> <property stdset="1"> <name>name</name> <cstring>ConfigDialogBase</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>215</width> + <width>211</width> <height>329</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>Configure PCMCIA/CF Card</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> - <number>5</number> + <number>6</number> </property> <property stdset="1"> <name>spacing</name> <number>2</number> </property> <widget row="0" column="0" rowspan="1" colspan="3" > <class>QGroupBox</class> <property stdset="1"> <name>name</name> <cstring>gbDetails</cstring> </property> <property stdset="1"> <name>title</name> <string>Details</string> </property> <property> <name>layoutMargin</name> </property> <property> <name>layoutSpacing</name> </property> <grid> <property stdset="1"> <name>margin</name> <number>6</number> </property> <property stdset="1"> <name>spacing</name> <number>4</number> </property> <widget row="0" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>labelCardName</cstring> </property> <property stdset="1"> <name>text</name> <string>CardName:</string> </property> </widget> <widget row="2" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>labelFunction</cstring> </property> <property stdset="1"> @@ -103,195 +103,248 @@ <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>TextLabel6</string> </property> </widget> <widget row="2" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>txtFunction</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>TextLabel7</string> </property> </widget> <widget row="0" column="1" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>txtCardName</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>7</hsizetype> <vsizetype>1</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>text</name> <string>TextLabel3</string> </property> </widget> </grid> </widget> - <widget row="1" column="0" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel2</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>On insertion,</string> - </property> - </widget> - <widget row="1" column="1" > - <class>QComboBox</class> - <item> - <property> - <name>text</name> - <string>suspend</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>activate</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>eject</string> - </property> - </item> - <item> - <property> - <name>text</name> - <string>prompt for</string> - </property> - </item> - <property stdset="1"> - <name>name</name> - <cstring>cbAction</cstring> - </property> - </widget> - <widget row="1" column="2" > - <class>QLabel</class> - <property stdset="1"> - <name>name</name> - <cstring>TextLabel3</cstring> - </property> - <property stdset="1"> - <name>text</name> - <string>card</string> - </property> - </widget> - <widget row="4" column="0" > + <widget row="5" column="0" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>textBindTo</cstring> </property> <property stdset="1"> <name>text</name> <string>Bind to:</string> </property> </widget> - <widget row="4" column="1" rowspan="1" colspan="2" > + <widget row="5" column="1" rowspan="1" colspan="2" > <class>QComboBox</class> <item> <property> <name>text</name> <string><None></string> </property> </item> <property stdset="1"> <name>name</name> <cstring>cbBindTo</cstring> </property> <property stdset="1"> <name>sizePolicy</name> <sizepolicy> <hsizetype>5</hsizetype> <vsizetype>0</vsizetype> </sizepolicy> </property> <property stdset="1"> <name>editable</name> <bool>true</bool> </property> <property stdset="1"> <name>currentItem</name> <number>0</number> </property> <property stdset="1"> <name>autoResize</name> <bool>false</bool> </property> </widget> - <widget row="3" column="0" rowspan="1" colspan="3" > + <widget row="4" column="0" rowspan="1" colspan="3" > <class>QLabel</class> <property stdset="1"> <name>name</name> <cstring>textInfo</cstring> </property> <property stdset="1"> <name>frameShape</name> <enum>Box</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Raised</enum> </property> <property stdset="1"> <name>lineWidth</name> <number>2</number> </property> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>text</name> <string><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></string> </property> </widget> - <spacer row="2" column="1" > + <widget row="1" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>On insertion,</string> + </property> + </widget> + <widget row="1" column="2" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel3</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>card</string> + </property> + </widget> + <widget row="2" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>On resume,</string> + </property> + </widget> + <widget row="2" column="2" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel3_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>card</string> + </property> + </widget> + <spacer row="3" column="1" > <property> <name>name</name> <cstring>Spacer2</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> + <widget row="1" column="1" > + <class>QComboBox</class> + <item> + <property> + <name>text</name> + <string>suspend</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>activate</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>eject</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>prompt for</string> + </property> + </item> + <property stdset="1"> + <name>name</name> + <cstring>cbInsertAction</cstring> + </property> + </widget> + <widget row="2" column="1" > + <class>QComboBox</class> + <item> + <property> + <name>text</name> + <string>suspend</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>activate</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>eject</string> + </property> + </item> + <item> + <property> + <name>text</name> + <string>prompt for</string> + </property> + </item> + <property stdset="1"> + <name>name</name> + <cstring>cbResumeAction</cstring> + </property> + </widget> </grid> </widget> </UI> 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 @@ -1,94 +1,96 @@ /* This file is part of the Opie Project =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #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> #include <string.h> #include <errno.h> #include <fcntl.h> #if defined(_OS_LINUX_) || defined(Q_OS_LINUX) #include <sys/vfs.h> #include <mntent.h> #endif PcmciaManager::PcmciaManager( QWidget * parent ) : QWidget( parent ) { QCopChannel * pcmciaChannel = new QCopChannel( "QPE/Card", this ); connect( pcmciaChannel, SIGNAL( received(const QCString&,const QByteArray&) ), this, SLOT( cardMessage(const QCString&,const QByteArray&) ) ); setFocusPolicy( NoFocus ); setFixedWidth ( AppLnk::smallIconSize() ); setFixedHeight ( AppLnk::smallIconSize() ); pm = Opie::Core::OResource::loadPixmap( "cardmon/pcmcia", Opie::Core::OResource::SmallIcon ); configuring = false; } PcmciaManager::~PcmciaManager() { } void PcmciaManager::popUp( QString message, QString icon ) { if ( !popupMenu ) { popupMenu = new QPopupMenu( this ); } popupMenu->clear(); if ( icon.isEmpty() ) { @@ -133,178 +135,215 @@ void PcmciaManager::mousePressEvent( QMouseEvent* ) submenu->insertItem( "&Suspend", SUSPEND+i*100 ); submenu->insertItem( "&Resume", RESUME+i*100 ); submenu->insertItem( "Rese&t", RESET+i*100 ); submenu->insertItem( "&Configure", CONFIGURE+i*100 ); submenu->setItemEnabled( EJECT+i*100, !it.current()->isEmpty() ); submenu->setItemEnabled( INSERT+i*100, it.current()->isEmpty() ); submenu->setItemEnabled( SUSPEND+i*100, !it.current()->isEmpty() && it.current()->isSuspended() ); submenu->setItemEnabled( RESUME+i*100, !it.current()->isEmpty() && !it.current()->isSuspended() ); submenu->setItemEnabled( CONFIGURE+i*100, !it.current()->isEmpty() && !configuring ); connect( submenu, SIGNAL(activated(int)), this, SLOT(userCardAction(int)) ); menu->insertItem( tr( "%1: %2" ).arg( i++ ).arg( it.current()->identity() ), submenu, 1 ); ++it; } 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 ); qDebug( "pcmcia: menu result = %d", opt ); delete menu; } void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) { odebug << "PcmciaManager::cardMessage( '" << msg << "' )" << oendl; if ( msg != "stabChanged()" ) return; /* check if a previously unknown card has been inserted */ OPcmciaSystem::instance()->synchronize(); if ( !OPcmciaSystem::instance()->cardCount() ) return; OConfig cfg( "PCMCIA" ); cfg.setGroup( "Global" ); 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() ) { p.drawPixmap( 0, 0, pm ); show(); } else { hide(); } } 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 ) 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 @@ -9,62 +9,62 @@ .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; : .. .:, . . . without even the implied warranty of =_ + =;=|` MERCHANTABILITY or FITNESS FOR A _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU ..}^=.= = ; Library General Public License for more ++= -. .` .: details. : = ...= . :.=- -. .:....=;==+<; You should have received a copy of the GNU -_. . . )=. = Library General Public License along with -- :-=` this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef PCMCIA_H #define PCMCIA_H #include <qwidget.h> #include <qpixmap.h> #include <qpopupmenu.h> namespace Opie { namespace Core { class OPcmciaSocket; } }; class PcmciaManager : public QWidget { Q_OBJECT public: PcmciaManager( QWidget *parent = 0 ); ~PcmciaManager(); static int position(); private slots: void cardMessage( const QCString& msg, const QByteArray& ); void userCardAction( int action ); void popupTimeout(); protected: void paintEvent( QPaintEvent* ); 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 ); private: bool configuring; int commandOrig; QPixmap pm; QPopupMenu *popupMenu; }; #endif |