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
@@ -33,6 +33,7 @@
33#include <opie2/oconfig.h> 33#include <opie2/oconfig.h>
34#include <opie2/odebug.h> 34#include <opie2/odebug.h>
35#include <opie2/opcmciasystem.h> 35#include <opie2/opcmciasystem.h>
36#include <qpe/global.h>
36using namespace Opie::Core; 37using namespace Opie::Core;
37 38
38/* QT */ 39/* QT */
@@ -43,6 +44,10 @@ using namespace Opie::Core;
43#include <qlabel.h> 44#include <qlabel.h>
44#include <qtextstream.h> 45#include <qtextstream.h>
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 )
47 :ConfigDialogBase( parent, "pcmcia config dialog", true ) 52 :ConfigDialogBase( parent, "pcmcia config dialog", true )
48{ 53{
@@ -59,13 +64,13 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
59 64
60 if ( !insertAction.isEmpty() ) 65 if ( !insertAction.isEmpty() )
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 );
64 } 69 }
65 70
66 if ( !resumeAction.isEmpty() ) 71 if ( !resumeAction.isEmpty() )
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 );
70 } 75 }
71 76
@@ -129,51 +134,105 @@ ConfigDialog::~ConfigDialog()
129 134
130void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value ) 135void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value )
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}
151 144
152QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue ) 145QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue )
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
160 for ( int i = 0; i < nCards; ++i ) 172 for ( int i = 0; i < nCards; ++i )
161 { 173 {
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;
166 if ( cardName == name ) 178 if ( cardName == name )
167 { 179 {
168 value = cfg.readEntry( key, defaultValue ); 180 cardcfg = cfg;
169 break; 181 break;
170 } 182 }
171 } 183 }
172 return value; 184 return cardcfg;
173} 185}
174 186
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