summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-06-26 12:02:40 (UTC)
committer mickeyl <mickeyl>2005-06-26 12:02:40 (UTC)
commitd5a2b0d5ca4daa11894c52f3599dab56205bef4c (patch) (side-by-side diff)
tree590d9ba11f3999e4c2b2ebd353ea49af552d9d12
parent790aeb8898d635468c2b9e24fd16a70aab64b1dd (diff)
downloadopie-d5a2b0d5ca4daa11894c52f3599dab56205bef4c.zip
opie-d5a2b0d5ca4daa11894c52f3599dab56205bef4c.tar.gz
opie-d5a2b0d5ca4daa11894c52f3599dab56205bef4c.tar.bz2
- refactor miscellaneous things to make configuring work all the time
- add 'prompt for' dialog - applet completion state 100% for Version 1.2.1
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--ChangeLog1
-rw-r--r--noncore/applets/pcmcia/configdialog.cpp115
-rw-r--r--noncore/applets/pcmcia/configdialog.h4
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp114
-rw-r--r--noncore/applets/pcmcia/pcmcia.h2
-rw-r--r--noncore/applets/pcmcia/pcmcia.pro6
-rw-r--r--noncore/applets/pcmcia/promptactiondialog.ui58
7 files changed, 198 insertions, 102 deletions
diff --git a/ChangeLog b/ChangeLog
index a820c09..f47d948 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -15,2 +15,3 @@
* Opie-Console: read initial fixed font configuration from qpe.conf (mickeyl)
+ * Opie-PcmciaApplet: card monitoring applet lets you configure insert/resume actions and bind unsupported cards (mickeyl)
diff --git a/noncore/applets/pcmcia/configdialog.cpp b/noncore/applets/pcmcia/configdialog.cpp
index 3b1b40c..010d691 100644
--- a/noncore/applets/pcmcia/configdialog.cpp
+++ b/noncore/applets/pcmcia/configdialog.cpp
@@ -35,2 +35,3 @@
#include <opie2/opcmciasystem.h>
+#include <qpe/global.h>
using namespace Opie::Core;
@@ -45,2 +46,6 @@ using namespace Opie::Core;
+/* STD */
+#include <errno.h>
+#include <string.h>
+
ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
@@ -61,3 +66,3 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
{
- for ( int i; i < cbInsertAction->count(); ++i )
+ for ( unsigned int i = 0; i < cbInsertAction->count(); ++i )
if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i );
@@ -67,3 +72,3 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
{
- for ( int i; i < cbResumeAction->count(); ++i )
+ for ( unsigned int i = 0; i < cbResumeAction->count(); ++i )
if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i );
@@ -131,20 +136,8 @@ void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& k
{
- OConfig cfg( "PCMCIA" );
- cfg.setGroup( "Global" );
- int nCards = cfg.readNumEntry( "nCards", 0 );
- QString cardName = card->productIdentity();
- QString action;
-
- for ( int i = 0; i < nCards; ++i )
+ OConfig* cfg = cardConfig( card );
+ if ( cfg )
{
- QString cardSection = QString( "Card_%1" ).arg( i );
- cfg.setGroup( cardSection );
- QString name = cfg.readEntry( "name" );
- odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
- if ( cardName == name )
- {
- cfg.writeEntry( key, value );
- break;
- }
+ cfg->writeEntry( key, value );
}
+ delete cfg; // deleting a 0 pointer is within spec.
}
@@ -153,7 +146,26 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
{
- OConfig cfg( "PCMCIA" );
- cfg.setGroup( "Global" );
- int nCards = cfg.readNumEntry( "nCards", 0 );
- QString cardName = card->productIdentity();
QString value;
+ OConfig* cfg = cardConfig( card );
+ if ( cfg )
+ {
+ value = cfg->readEntry( key, defaultValue );
+ }
+ delete cfg; // deleting a 0 pointer is within spec.
+ return value;
+}
+
+
+QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type )
+{
+ return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" );
+}
+
+
+OConfig* ConfigDialog::cardConfig( const OPcmciaSocket* card )
+{
+ OConfig* cardcfg = 0;
+ OConfig* cfg = new OConfig( "PCMCIA" );
+ cfg->setGroup( "Global" );
+ int nCards = cfg->readNumEntry( "nCards", 0 );
+ QString cardName = card->productIdentity();
@@ -162,4 +174,4 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
QString cardSection = QString( "Card_%1" ).arg( i );
- cfg.setGroup( cardSection );
- QString name = cfg.readEntry( "name" );
+ cfg->setGroup( cardSection );
+ QString name = cfg->readEntry( "name" );
odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
@@ -167,3 +179,3 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
{
- value = cfg.readEntry( key, defaultValue );
+ cardcfg = cfg;
break;
@@ -171,3 +183,3 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
}
- return value;
+ return cardcfg;
}
@@ -175,5 +187,52 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
-QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type )
+void ConfigDialog::writeConfiguration( const OPcmciaSocket* card )
{
- return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" );
+ odebug << "pcmcia: ConfigDialog::writeConfiguration()" << oendl;
+ OConfig* cfg = cardConfig( card );
+ if ( !cfg )
+ {
+ cfg = new OConfig( "PCMCIA" );
+ cfg->setGroup( "Global" );
+ int nCards = cfg->readNumEntry( "nCards", 0 );
+ cfg->setGroup( QString( "Card_%1" ).arg( nCards ) );
+ cfg->writeEntry( "name", card->productIdentity() );
+ cfg->setGroup( "Global" );
+ cfg->writeEntry( "nCards", nCards+1 );
+ cfg->setGroup( QString( "Card_%1" ).arg( nCards ) );
+ }
+
+ cfg->writeEntry( "insertAction", cbInsertAction->currentText() );
+ cfg->writeEntry( "resumeAction", cbResumeAction->currentText() );
+ cfg->write();
+
+ if ( cbBindTo->isVisible() && cbBindTo->currentText() != "<None>" )
+ {
+ QString driver = cbBindTo->currentText();
+ QString conf = bindEntries[driver];
+
+ // write binding
+
+ QFile confFile( conf );
+ if ( confFile.open( IO_ReadWrite | IO_Append ) )
+ {
+ QString entryCard = QString( "card \"%1\"" ).arg( card->productIdentity() );
+ QString entryVersion( " version " );
+ for ( QStringList::Iterator it = card->productIdentityVector().begin(); it != card->productIdentityVector().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..." );
+ OPcmciaSystem::instance()->restart();
+ }
+ else
+ {
+ owarn << "pcmcia: couldn't write binding to '" << conf << "' ( " << strerror( errno ) << " )." << oendl;
+ }
+ }
}
+
diff --git a/noncore/applets/pcmcia/configdialog.h b/noncore/applets/pcmcia/configdialog.h
index 169dadb..eb081a1 100644
--- a/noncore/applets/pcmcia/configdialog.h
+++ b/noncore/applets/pcmcia/configdialog.h
@@ -34,3 +34,3 @@
-namespace Opie { namespace Core { class OPcmciaSocket; }; };
+namespace Opie { namespace Core { class OPcmciaSocket; class OConfig; }; };
@@ -47,2 +47,4 @@ class ConfigDialog : public ConfigDialogBase
static void writeConfigEntry( const Opie::Core::OPcmciaSocket* card, const QString& key, const QString& value );
+ static Opie::Core::OConfig* cardConfig( const Opie::Core::OPcmciaSocket* card );
+ void writeConfiguration( const Opie::Core::OPcmciaSocket* card );
StringMap bindEntries;
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index c6386cb..187adc6 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -2,3 +2,3 @@
                This file is part of the Opie Project
- =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
+ =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
@@ -31,2 +31,3 @@
#include "configdialog.h"
+#include "promptactiondialog.h"
@@ -140,4 +141,4 @@ void PcmciaManager::popupTimeout()
-enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE };
-static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur" };
+enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE, ACTIVATE };
+static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur", "activat" };
@@ -248,42 +249,3 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
{
- QString insertAction; QString resumeAction; QString driver; QString conf;
- bool configured = configure( theCard, insertAction, resumeAction, driver, conf );
-
- if ( configured )
- {
- odebug << "pcmcia: card has been configured. writing out to database" << oendl;
- cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
- cfg.writeEntry( "name", newCardName );
- cfg.writeEntry( "insertAction", insertAction );
- cfg.writeEntry( "resumeAction", resumeAction );
- cfg.setGroup( "Global" );
- cfg.writeEntry( "nCards", nCards+1 );
- cfg.write();
-
- QFile confFile( conf );
- if ( confFile.open( IO_ReadWrite | IO_Append ) )
- {
- QString entryCard = QString( "card \"%1\"" ).arg( newCardName );
- QString entryVersion( " version " );
- for ( QStringList::Iterator it = theCard->productIdentityVector().begin(); it != theCard->productIdentityVector().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 << "' ( " << strerror( errno ) << " )." << oendl;
- }
- }
- else
- {
- odebug << "pcmcia: card has not been configured this time. leaving as unknown card" << oendl;
- }
+ configure( theCard );
}
@@ -328,16 +290,18 @@ void PcmciaManager::userCardAction( int action )
QString insertAction; QString resumeAction; QString driver; QString conf;
- configure( OPcmciaSystem::instance()->socket( socket ), insertAction, resumeAction, driver, conf );
+ configure( OPcmciaSystem::instance()->socket( socket ) );
return;
}
- 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 << "pcmcia: not yet implemented" << oendl;
+ 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;
+ case ACTIVATE: success = true;
+ break;
+ default: odebug << "pcmcia: not yet implemented" << oendl;
}
@@ -346,2 +310,3 @@ void PcmciaManager::userCardAction( int action )
{
+ odebug << tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl;
popUp( tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) );
@@ -350,2 +315,3 @@ void PcmciaManager::userCardAction( int action )
{
+ odebug << tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl;
popUp( tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) );
@@ -354,3 +320,3 @@ void PcmciaManager::userCardAction( int action )
-bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QString& resumeAction, QString& driver, QString& conf )
+void PcmciaManager::configure( OPcmciaSocket* card )
{
@@ -358,13 +324,9 @@ bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QStri
ConfigDialog dialog( card, qApp->desktop() );
- int configresult = QPEApplication::execDialog( &dialog, false );
+ int result = QPEApplication::execDialog( &dialog, false );
configuring = false;
- odebug << "pcmcia: configresult = " << configresult << oendl;
- if ( configresult )
+ odebug << "pcmcia: configresult = " << result << oendl;
+ if ( result )
{
- insertAction = dialog.cbInsertAction->currentText();
- resumeAction = dialog.cbResumeAction->currentText();
- driver = dialog.cbBindTo->currentText();
- conf = dialog.bindEntries[driver];
+ dialog.writeConfiguration( card );
}
- return configresult;
}
@@ -376,10 +338,22 @@ void PcmciaManager::executeAction( Opie::Core::OPcmciaSocket* card, const QStrin
int intAction = card->number() * 100;
- if ( theAction == "activate" ) ;
- else if ( theAction == "eject" ) intAction += EJECT;
- else if ( theAction == "suspend" ) intAction += SUSPEND;
- else if ( theAction == "prompt for" )
+
+ if ( theAction == "prompt for" )
{
- odebug << "pcmcia: sorry, not 'prompt for' is not yet implemented!" << oendl;
- return;
+ PromptActionDialog dialog( qApp->desktop(), "promptfor", true );
+ dialog.setCaption( QString( "Choose action for card #%1" ).arg( card->number() ) );
+ int result = QPEApplication::execDialog( &dialog, true );
+ odebug << "pcmcia: configresult = " << result << oendl;
+ if ( result )
+ {
+ theAction = dialog.cbAction->currentText();
+ }
+ else
+ {
+ odebug << "pcmcia: prompted to do nothing" << oendl;
+ return;
+ }
}
+ if ( theAction == "activate" ) intAction += ACTIVATE;
+ else if ( theAction == "eject" ) intAction += EJECT;
+ else if ( theAction == "suspend" ) intAction += SUSPEND;
else
diff --git a/noncore/applets/pcmcia/pcmcia.h b/noncore/applets/pcmcia/pcmcia.h
index de7d6bf..0fe936c 100644
--- a/noncore/applets/pcmcia/pcmcia.h
+++ b/noncore/applets/pcmcia/pcmcia.h
@@ -57,3 +57,3 @@ class PcmciaManager : public QWidget
private:
- bool configure( Opie::Core::OPcmciaSocket*, QString&, QString&, QString&, QString& );
+ void configure( Opie::Core::OPcmciaSocket* );
void execCommand( const QStringList &command );
diff --git a/noncore/applets/pcmcia/pcmcia.pro b/noncore/applets/pcmcia/pcmcia.pro
index 4a893b5..b9af380 100644
--- a/noncore/applets/pcmcia/pcmcia.pro
+++ b/noncore/applets/pcmcia/pcmcia.pro
@@ -3,3 +3,4 @@ CONFIG += qt plugin warn_on
-INTERFACES = configdialogbase.ui
+INTERFACES = configdialogbase.ui \
+ promptactiondialog.ui
HEADERS = pcmcia.h \
@@ -11,2 +12,3 @@ TARGET = pcmciaapplet
DESTDIR = $(OPIEDIR)/plugins/applets
+
INCLUDEPATH += $(OPIEDIR)/include
@@ -15,3 +17,3 @@ DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopiecore2
-VERSION = 0.2.0
+VERSION = 0.9.0
diff --git a/noncore/applets/pcmcia/promptactiondialog.ui b/noncore/applets/pcmcia/promptactiondialog.ui
new file mode 100644
index 0000000..c351b48
--- a/dev/null
+++ b/noncore/applets/pcmcia/promptactiondialog.ui
@@ -0,0 +1,58 @@
+<!DOCTYPE UI><UI>
+<class>PromptActionDialog</class>
+<widget>
+ <class>QDialog</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>PromptActionDialog</cstring>
+ </property>
+ <property stdset="1">
+ <name>geometry</name>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>273</width>
+ <height>55</height>
+ </rect>
+ </property>
+ <property stdset="1">
+ <name>caption</name>
+ <string>Choose Action for Card</string>
+ </property>
+ <grid>
+ <property stdset="1">
+ <name>margin</name>
+ <number>11</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget row="0" column="0" >
+ <class>QComboBox</class>
+ <item>
+ <property>
+ <name>text</name>
+ <string>activate</string>
+ </property>
+ </item>
+ <item>
+ <property>
+ <name>text</name>
+ <string>suspend</string>
+ </property>
+ </item>
+ <item>
+ <property>
+ <name>text</name>
+ <string>eject</string>
+ </property>
+ </item>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>cbAction</cstring>
+ </property>
+ </widget>
+ </grid>
+</widget>
+</UI>