Diffstat (limited to 'noncore/applets/pcmcia/configdialog.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/applets/pcmcia/configdialog.cpp | 111 |
1 files changed, 85 insertions, 26 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> | ||
36 | using namespace Opie::Core; | 37 | using namespace Opie::Core; |
@@ -45,2 +46,6 @@ using namespace Opie::Core; | |||
45 | 46 | ||
47 | /* STD */ | ||
48 | #include <errno.h> | ||
49 | #include <string.h> | ||
50 | |||
46 | ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) | 51 | ConfigDialog::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,29 +136,36 @@ 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 ); | 139 | { |
135 | QString cardName = card->productIdentity(); | 140 | cfg->writeEntry( key, value ); |
136 | QString action; | 141 | } |
142 | delete cfg; // deleting a 0 pointer is within spec. | ||
143 | } | ||
137 | 144 | ||
138 | for ( int i = 0; i < nCards; ++i ) | 145 | QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue ) |
139 | { | 146 | { |
140 | QString cardSection = QString( "Card_%1" ).arg( i ); | 147 | QString value; |
141 | cfg.setGroup( cardSection ); | 148 | OConfig* cfg = cardConfig( card ); |
142 | QString name = cfg.readEntry( "name" ); | 149 | if ( cfg ) |
143 | odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; | ||
144 | if ( cardName == name ) | ||
145 | { | 150 | { |
146 | cfg.writeEntry( key, value ); | 151 | value = cfg->readEntry( key, defaultValue ); |
147 | break; | ||
148 | } | 152 | } |
153 | delete cfg; // deleting a 0 pointer is within spec. | ||
154 | return value; | ||
149 | } | 155 | } |
156 | |||
157 | |||
158 | QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type ) | ||
159 | { | ||
160 | return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" ); | ||
150 | } | 161 | } |
151 | 162 | ||
152 | QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue ) | 163 | |
164 | OConfig* ConfigDialog::cardConfig( const OPcmciaSocket* card ) | ||
153 | { | 165 | { |
154 | OConfig cfg( "PCMCIA" ); | 166 | OConfig* cardcfg = 0; |
155 | cfg.setGroup( "Global" ); | 167 | OConfig* cfg = new OConfig( "PCMCIA" ); |
156 | int nCards = cfg.readNumEntry( "nCards", 0 ); | 168 | cfg->setGroup( "Global" ); |
169 | int nCards = cfg->readNumEntry( "nCards", 0 ); | ||
157 | QString cardName = card->productIdentity(); | 170 | QString cardName = card->productIdentity(); |
158 | QString value; | ||
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 | ||
176 | QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type ) | 188 | void 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 | } | ||
179 | } | 236 | } |
237 | } | ||
238 | |||