summaryrefslogtreecommitdiff
path: root/noncore/applets/pcmcia/configdialog.cpp
authormickeyl <mickeyl>2005-06-26 12:02:40 (UTC)
committer mickeyl <mickeyl>2005-06-26 12:02:40 (UTC)
commitd5a2b0d5ca4daa11894c52f3599dab56205bef4c (patch) (unidiff)
tree590d9ba11f3999e4c2b2ebd353ea49af552d9d12 /noncore/applets/pcmcia/configdialog.cpp
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 (limited to 'noncore/applets/pcmcia/configdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/configdialog.cpp115
1 files changed, 87 insertions, 28 deletions
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 @@
35#include <opie2/opcmciasystem.h> 35#include <opie2/opcmciasystem.h>
36#include <qpe/global.h>
36using namespace Opie::Core; 37using namespace Opie::Core;
@@ -45,2 +46,6 @@ using namespace Opie::Core;
45 46
47/* STD */
48#include <errno.h>
49#include <string.h>
50
46ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) 51ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
@@ -61,3 +66,3 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
61 { 66 {
62 for ( int i; i < cbInsertAction->count(); ++i ) 67 for ( unsigned int i = 0; i < cbInsertAction->count(); ++i )
63 if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i ); 68 if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i );
@@ -67,3 +72,3 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
67 { 72 {
68 for ( int i; i < cbResumeAction->count(); ++i ) 73 for ( unsigned int i = 0; i < cbResumeAction->count(); ++i )
69 if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i ); 74 if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i );
@@ -131,20 +136,8 @@ void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& k
131{ 136{
132 OConfig cfg( "PCMCIA" ); 137 OConfig* cfg = cardConfig( card );
133 cfg.setGroup( "Global" ); 138 if ( cfg )
134 int nCards = cfg.readNumEntry( "nCards", 0 );
135 QString cardName = card->productIdentity();
136 QString action;
137
138 for ( int i = 0; i < nCards; ++i )
139 { 139 {
140 QString cardSection = QString( "Card_%1" ).arg( i ); 140 cfg->writeEntry( key, value );
141 cfg.setGroup( cardSection );
142 QString name = cfg.readEntry( "name" );
143 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
144 if ( cardName == name )
145 {
146 cfg.writeEntry( key, value );
147 break;
148 }
149 } 141 }
142 delete cfg; // deleting a 0 pointer is within spec.
150} 143}
@@ -153,7 +146,26 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
153{ 146{
154 OConfig cfg( "PCMCIA" );
155 cfg.setGroup( "Global" );
156 int nCards = cfg.readNumEntry( "nCards", 0 );
157 QString cardName = card->productIdentity();
158 QString value; 147 QString value;
148 OConfig* cfg = cardConfig( card );
149 if ( cfg )
150 {
151 value = cfg->readEntry( key, defaultValue );
152 }
153 delete cfg; // deleting a 0 pointer is within spec.
154 return value;
155}
156
157
158QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type )
159{
160 return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" );
161}
162
163
164OConfig* ConfigDialog::cardConfig( const OPcmciaSocket* card )
165{
166 OConfig* cardcfg = 0;
167 OConfig* cfg = new OConfig( "PCMCIA" );
168 cfg->setGroup( "Global" );
169 int nCards = cfg->readNumEntry( "nCards", 0 );
170 QString cardName = card->productIdentity();
159 171
@@ -162,4 +174,4 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
162 QString cardSection = QString( "Card_%1" ).arg( i ); 174 QString cardSection = QString( "Card_%1" ).arg( i );
163 cfg.setGroup( cardSection ); 175 cfg->setGroup( cardSection );
164 QString name = cfg.readEntry( "name" ); 176 QString name = cfg->readEntry( "name" );
165 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 177 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
@@ -167,3 +179,3 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
167 { 179 {
168 value = cfg.readEntry( key, defaultValue ); 180 cardcfg = cfg;
169 break; 181 break;
@@ -171,3 +183,3 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
171 } 183 }
172 return value; 184 return cardcfg;
173} 185}
@@ -175,5 +187,52 @@ QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString&
175 187
176QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type ) 188void ConfigDialog::writeConfiguration( const OPcmciaSocket* card )
177{ 189{
178 return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" ); 190 odebug << "pcmcia: ConfigDialog::writeConfiguration()" << oendl;
191 OConfig* cfg = cardConfig( card );
192 if ( !cfg )
193 {
194 cfg = new OConfig( "PCMCIA" );
195 cfg->setGroup( "Global" );
196 int nCards = cfg->readNumEntry( "nCards", 0 );
197 cfg->setGroup( QString( "Card_%1" ).arg( nCards ) );
198 cfg->writeEntry( "name", card->productIdentity() );
199 cfg->setGroup( "Global" );
200 cfg->writeEntry( "nCards", nCards+1 );
201 cfg->setGroup( QString( "Card_%1" ).arg( nCards ) );
202 }
203
204 cfg->writeEntry( "insertAction", cbInsertAction->currentText() );
205 cfg->writeEntry( "resumeAction", cbResumeAction->currentText() );
206 cfg->write();
207
208 if ( cbBindTo->isVisible() && cbBindTo->currentText() != "<None>" )
209 {
210 QString driver = cbBindTo->currentText();
211 QString conf = bindEntries[driver];
212
213 // write binding
214
215 QFile confFile( conf );
216 if ( confFile.open( IO_ReadWrite | IO_Append ) )
217 {
218 QString entryCard = QString( "card \"%1\"" ).arg( card->productIdentity() );
219 QString entryVersion( " version " );
220 for ( QStringList::Iterator it = card->productIdentityVector().begin(); it != card->productIdentityVector().end(); ++it )
221 {
222 entryVersion += QString( "\"%1\", " ).arg( *it );
223 }
224 QString entryBind = QString( " bind %1" ).arg( driver );
225 QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind );
226 odebug << "pcmcia: writing entry...:" << entry << oendl;
227
228 confFile.writeBlock( (const char*) entry, entry.length() );
229 Global::statusMessage( "restarting pcmcia services..." );
230 OPcmciaSystem::instance()->restart();
231 }
232 else
233 {
234 owarn << "pcmcia: couldn't write binding to '" << conf << "' ( " << strerror( errno ) << " )." << oendl;
235 }
236 }
179} 237}
238