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 | |||
@@ -24,57 +24,62 @@ | |||
24 | If not, write to the Free Software Foundation, | 24 | If not, write to the Free Software Foundation, |
25 | Inc., 59 Temple Place - Suite 330, | 25 | Inc., 59 Temple Place - Suite 330, |
26 | Boston, MA 02111-1307, USA. | 26 | Boston, MA 02111-1307, USA. |
27 | 27 | ||
28 | */ | 28 | */ |
29 | 29 | ||
30 | #include "configdialog.h" | 30 | #include "configdialog.h" |
31 | 31 | ||
32 | /* OPIE */ | 32 | /* OPIE */ |
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> | ||
36 | using namespace Opie::Core; | 37 | using namespace Opie::Core; |
37 | 38 | ||
38 | /* QT */ | 39 | /* QT */ |
39 | #include <qcombobox.h> | 40 | #include <qcombobox.h> |
40 | #include <qdir.h> | 41 | #include <qdir.h> |
41 | #include <qfile.h> | 42 | #include <qfile.h> |
42 | #include <qgroupbox.h> | 43 | #include <qgroupbox.h> |
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 | |||
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 ) |
48 | { | 53 | { |
49 | gbDetails->setTitle( QString( "Details for card in socket #%1" ).arg( card->number() ) ); | 54 | gbDetails->setTitle( QString( "Details for card in socket #%1" ).arg( card->number() ) ); |
50 | txtCardName->setText( card->productIdentity() ); | 55 | txtCardName->setText( card->productIdentity() ); |
51 | txtManfid->setText( card->manufacturerIdentity() ); | 56 | txtManfid->setText( card->manufacturerIdentity() ); |
52 | txtFunction->setText( card->function() ); | 57 | txtFunction->setText( card->function() ); |
53 | 58 | ||
54 | QString insertAction = preferredAction( card, "insert" ); | 59 | QString insertAction = preferredAction( card, "insert" ); |
55 | QString resumeAction = preferredAction( card, "resume" ); | 60 | QString resumeAction = preferredAction( card, "resume" ); |
56 | 61 | ||
57 | odebug << "pcmcia: preferred insertion action for card '" << card->productIdentity() << "' seems to be '" << insertAction << "'" << oendl; | 62 | odebug << "pcmcia: preferred insertion action for card '" << card->productIdentity() << "' seems to be '" << insertAction << "'" << oendl; |
58 | odebug << "pcmcia: preferred resume action for card '" << card->productIdentity() << "' seems to be '" << resumeAction << "'" << oendl; | 63 | odebug << "pcmcia: preferred resume action for card '" << card->productIdentity() << "' seems to be '" << resumeAction << "'" << oendl; |
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 | ||
72 | if ( !card->isUnsupported() ) | 77 | if ( !card->isUnsupported() ) |
73 | { | 78 | { |
74 | odebug << "pcmcia: card is recognized - hiding bindings" << oendl; | 79 | odebug << "pcmcia: card is recognized - hiding bindings" << oendl; |
75 | textInfo->hide(); | 80 | textInfo->hide(); |
76 | textBindTo->hide(); | 81 | textBindTo->hide(); |
77 | cbBindTo->hide(); | 82 | cbBindTo->hide(); |
78 | return; | 83 | return; |
79 | } | 84 | } |
80 | else | 85 | else |
@@ -120,60 +125,114 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent ) | |||
120 | { | 125 | { |
121 | odebug << "found binding '" << it.key() << "' defined in '" << it.data().latin1() << "'" << oendl; | 126 | odebug << "found binding '" << it.key() << "' defined in '" << it.data().latin1() << "'" << oendl; |
122 | cbBindTo->insertItem( it.key() ); | 127 | cbBindTo->insertItem( it.key() ); |
123 | } | 128 | } |
124 | } | 129 | } |
125 | 130 | ||
126 | ConfigDialog::~ConfigDialog() | 131 | ConfigDialog::~ConfigDialog() |
127 | { | 132 | { |
128 | } | 133 | } |
129 | 134 | ||
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 | |||