Diffstat (limited to 'noncore/applets/pcmcia/configdialog.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/pcmcia/configdialog.cpp | 115 |
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 | |||
@@ -34,4 +34,5 @@ | |||
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> | ||
36 | using namespace Opie::Core; | 37 | using namespace Opie::Core; |
37 | 38 | ||
@@ -44,4 +45,8 @@ using namespace Opie::Core; | |||
44 | #include <qtextstream.h> | 45 | #include <qtextstream.h> |
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 ) |
47 | :ConfigDialogBase( parent, "pcmcia config dialog", true ) | 52 | :ConfigDialogBase( parent, "pcmcia config dialog", true ) |
@@ -60,5 +65,5 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) | |||
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 | } |
@@ -66,5 +71,5 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) | |||
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 | } |
@@ -130,50 +135,104 @@ ConfigDialog::~ConfigDialog() | |||
130 | void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value ) | 135 | void 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 | ||
152 | QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue ) | 145 | QString 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 | |||
158 | QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type ) | ||
159 | { | ||
160 | return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" ); | ||
161 | } | ||
162 | |||
163 | |||
164 | OConfig* 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 | ||
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 | } | ||
236 | } | ||
179 | } | 237 | } |
238 | |||