summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2005-06-20 12:46:33 (UTC)
committer mickeyl <mickeyl>2005-06-20 12:46:33 (UTC)
commit3b02e2a868535628090567ed612d9fdb5b247f61 (patch) (unidiff)
tree6bc0281825b61316c594747b111b479f68115f37
parent1a3c172bd98026a555d65e802647f0511e80d3a6 (diff)
downloadopie-3b02e2a868535628090567ed612d9fdb5b247f61.zip
opie-3b02e2a868535628090567ed612d9fdb5b247f61.tar.gz
opie-3b02e2a868535628090567ed612d9fdb5b247f61.tar.bz2
miscellaneous work towards completon of this applet - still some way to go though
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/configdialog.cpp55
-rw-r--r--noncore/applets/pcmcia/configdialog.h7
-rw-r--r--noncore/applets/pcmcia/configdialogbase.ui171
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp69
-rw-r--r--noncore/applets/pcmcia/pcmcia.h2
5 files changed, 216 insertions, 88 deletions
diff --git a/noncore/applets/pcmcia/configdialog.cpp b/noncore/applets/pcmcia/configdialog.cpp
index f961069..f5812ba 100644
--- a/noncore/applets/pcmcia/configdialog.cpp
+++ b/noncore/applets/pcmcia/configdialog.cpp
@@ -52,17 +52,25 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
52 txtFunction->setText( card->function() ); 52 txtFunction->setText( card->function() );
53 53
54 QString action = preferredAction( card ); 54 QString insertAction = preferredAction( card, "insert" );
55 QString resumeAction = preferredAction( card, "resume" );
55 56
56 odebug << "preferred action for card '" << card->name() << "' seems to be '" << action << "'" << oendl; 57 odebug << "pcmcia: preferred insertion action for card '" << card->name() << "' seems to be '" << insertAction << "'" << oendl;
58 odebug << "pcmcia: preferred resume action for card '" << card->name() << "' seems to be '" << resumeAction << "'" << oendl;
57 59
58 if ( !action.isEmpty() ) 60 if ( !insertAction.isEmpty() )
59 { 61 {
60 for ( int i; i < cbAction->count(); ++i ) 62 for ( int i; i < cbInsertAction->count(); ++i )
61 if ( cbAction->text( i ) == action ) cbAction->setCurrentItem( i ); 63 if ( cbInsertAction->text( i ) == insertAction ) cbInsertAction->setCurrentItem( i );
64 }
65
66 if ( !resumeAction.isEmpty() )
67 {
68 for ( int i; i < cbResumeAction->count(); ++i )
69 if ( cbResumeAction->text( i ) == resumeAction ) cbResumeAction->setCurrentItem( i );
62 } 70 }
63 71
64 if ( !card->isUnsupported() ) 72 if ( !card->isUnsupported() )
65 { 73 {
66 odebug << "card is recognized - hiding bindings" << oendl; 74 odebug << "pcmcia: card is recognized - hiding bindings" << oendl;
67 textInfo->hide(); 75 textInfo->hide();
68 textBindTo->hide(); 76 textBindTo->hide();
@@ -79,7 +87,4 @@ ConfigDialog::ConfigDialog( const OPcmciaSocket* card, QWidget* parent )
79 87
80 // parse possible bind entries out of /etc/pcmcia/*.conf 88 // parse possible bind entries out of /etc/pcmcia/*.conf
81 typedef QMap<QString,QString> StringMap;
82 StringMap bindEntries;
83
84 QDir pcmciaconfdir( "/etc/pcmcia", "*.conf" ); 89 QDir pcmciaconfdir( "/etc/pcmcia", "*.conf" );
85 90
@@ -123,5 +128,5 @@ ConfigDialog::~ConfigDialog()
123} 128}
124 129
125QString ConfigDialog::preferredAction( const OPcmciaSocket* card ) 130void ConfigDialog::writeConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& value )
126{ 131{
127 OConfig cfg( "PCMCIA" ); 132 OConfig cfg( "PCMCIA" );
@@ -138,9 +143,35 @@ QString ConfigDialog::preferredAction( const OPcmciaSocket* card )
138 if ( card->name() == name ) 143 if ( card->name() == name )
139 { 144 {
140 action = cfg.readEntry( "action" ); 145 cfg.writeEntry( key, value );
141 break; 146 break;
142 } 147 }
143 } 148 }
149}
144 150
145 return action; 151QString ConfigDialog::readConfigEntry( const OPcmciaSocket* card, const QString& key, const QString& defaultValue )
152{
153 OConfig cfg( "PCMCIA" );
154 cfg.setGroup( "Global" );
155 int nCards = cfg.readNumEntry( "nCards", 0 );
156 QString value;
157
158 for ( int i = 0; i < nCards; ++i )
159 {
160 QString cardSection = QString( "Card_%1" ).arg( i );
161 cfg.setGroup( cardSection );
162 QString name = cfg.readEntry( "name" );
163 odebug << "comparing card '" << card->name() << "' with known card '" << name << "'" << oendl;
164 if ( card->name() == name )
165 {
166 value = cfg.readEntry( key, defaultValue );
167 break;
168 }
169 }
170 return value;
171}
172
173
174QString ConfigDialog::preferredAction( const OPcmciaSocket* card, const QString& type )
175{
176 return ConfigDialog::readConfigEntry( card, QString( "%1Action" ).arg( type ), "suspend" );
146} 177}
diff --git a/noncore/applets/pcmcia/configdialog.h b/noncore/applets/pcmcia/configdialog.h
index 321180d..169dadb 100644
--- a/noncore/applets/pcmcia/configdialog.h
+++ b/noncore/applets/pcmcia/configdialog.h
@@ -35,4 +35,6 @@
35namespace Opie { namespace Core { class OPcmciaSocket; }; }; 35namespace Opie { namespace Core { class OPcmciaSocket; }; };
36 36
37typedef QMap<QString,QString> StringMap;
38
37class ConfigDialog : public ConfigDialogBase 39class ConfigDialog : public ConfigDialogBase
38{ 40{
@@ -41,5 +43,8 @@ class ConfigDialog : public ConfigDialogBase
41 ConfigDialog( const Opie::Core::OPcmciaSocket* card, QWidget* parent ); 43 ConfigDialog( const Opie::Core::OPcmciaSocket* card, QWidget* parent );
42 ~ConfigDialog(); 44 ~ConfigDialog();
43 static QString preferredAction( const Opie::Core::OPcmciaSocket* card ); 45 static QString preferredAction( const Opie::Core::OPcmciaSocket* card, const QString& type );
46 static QString readConfigEntry( const Opie::Core::OPcmciaSocket* card, const QString& key, const QString& defaultValue );
47 static void writeConfigEntry( const Opie::Core::OPcmciaSocket* card, const QString& key, const QString& value );
48 StringMap bindEntries;
44}; 49};
45 50
diff --git a/noncore/applets/pcmcia/configdialogbase.ui b/noncore/applets/pcmcia/configdialogbase.ui
index 829b71a..97d9a50 100644
--- a/noncore/applets/pcmcia/configdialogbase.ui
+++ b/noncore/applets/pcmcia/configdialogbase.ui
@@ -12,5 +12,5 @@
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>215</width> 14 <width>211</width>
15 <height>329</height> 15 <height>329</height>
16 </rect> 16 </rect>
@@ -29,5 +29,5 @@
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>5</number> 31 <number>6</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
@@ -149,58 +149,5 @@
149 </grid> 149 </grid>
150 </widget> 150 </widget>
151 <widget row="1" column="0" > 151 <widget row="5" column="0" >
152 <class>QLabel</class>
153 <property stdset="1">
154 <name>name</name>
155 <cstring>TextLabel2</cstring>
156 </property>
157 <property stdset="1">
158 <name>text</name>
159 <string>On insertion,</string>
160 </property>
161 </widget>
162 <widget row="1" column="1" >
163 <class>QComboBox</class>
164 <item>
165 <property>
166 <name>text</name>
167 <string>suspend</string>
168 </property>
169 </item>
170 <item>
171 <property>
172 <name>text</name>
173 <string>activate</string>
174 </property>
175 </item>
176 <item>
177 <property>
178 <name>text</name>
179 <string>eject</string>
180 </property>
181 </item>
182 <item>
183 <property>
184 <name>text</name>
185 <string>prompt for</string>
186 </property>
187 </item>
188 <property stdset="1">
189 <name>name</name>
190 <cstring>cbAction</cstring>
191 </property>
192 </widget>
193 <widget row="1" column="2" >
194 <class>QLabel</class>
195 <property stdset="1">
196 <name>name</name>
197 <cstring>TextLabel3</cstring>
198 </property>
199 <property stdset="1">
200 <name>text</name>
201 <string>card</string>
202 </property>
203 </widget>
204 <widget row="4" column="0" >
205 <class>QLabel</class> 152 <class>QLabel</class>
206 <property stdset="1"> 153 <property stdset="1">
@@ -213,5 +160,5 @@
213 </property> 160 </property>
214 </widget> 161 </widget>
215 <widget row="4" column="1" rowspan="1" colspan="2" > 162 <widget row="5" column="1" rowspan="1" colspan="2" >
216 <class>QComboBox</class> 163 <class>QComboBox</class>
217 <item> 164 <item>
@@ -245,5 +192,5 @@
245 </property> 192 </property>
246 </widget> 193 </widget>
247 <widget row="3" column="0" rowspan="1" colspan="3" > 194 <widget row="4" column="0" rowspan="1" colspan="3" >
248 <class>QLabel</class> 195 <class>QLabel</class>
249 <property stdset="1"> 196 <property stdset="1">
@@ -272,5 +219,49 @@
272 </property> 219 </property>
273 </widget> 220 </widget>
274 <spacer row="2" column="1" > 221 <widget row="1" column="0" >
222 <class>QLabel</class>
223 <property stdset="1">
224 <name>name</name>
225 <cstring>TextLabel2</cstring>
226 </property>
227 <property stdset="1">
228 <name>text</name>
229 <string>On insertion,</string>
230 </property>
231 </widget>
232 <widget row="1" column="2" >
233 <class>QLabel</class>
234 <property stdset="1">
235 <name>name</name>
236 <cstring>TextLabel3</cstring>
237 </property>
238 <property stdset="1">
239 <name>text</name>
240 <string>card</string>
241 </property>
242 </widget>
243 <widget row="2" column="0" >
244 <class>QLabel</class>
245 <property stdset="1">
246 <name>name</name>
247 <cstring>TextLabel2_2</cstring>
248 </property>
249 <property stdset="1">
250 <name>text</name>
251 <string>On resume,</string>
252 </property>
253 </widget>
254 <widget row="2" column="2" >
255 <class>QLabel</class>
256 <property stdset="1">
257 <name>name</name>
258 <cstring>TextLabel3_2</cstring>
259 </property>
260 <property stdset="1">
261 <name>text</name>
262 <string>card</string>
263 </property>
264 </widget>
265 <spacer row="3" column="1" >
275 <property> 266 <property>
276 <name>name</name> 267 <name>name</name>
@@ -293,4 +284,66 @@
293 </property> 284 </property>
294 </spacer> 285 </spacer>
286 <widget row="1" column="1" >
287 <class>QComboBox</class>
288 <item>
289 <property>
290 <name>text</name>
291 <string>suspend</string>
292 </property>
293 </item>
294 <item>
295 <property>
296 <name>text</name>
297 <string>activate</string>
298 </property>
299 </item>
300 <item>
301 <property>
302 <name>text</name>
303 <string>eject</string>
304 </property>
305 </item>
306 <item>
307 <property>
308 <name>text</name>
309 <string>prompt for</string>
310 </property>
311 </item>
312 <property stdset="1">
313 <name>name</name>
314 <cstring>cbInsertAction</cstring>
315 </property>
316 </widget>
317 <widget row="2" column="1" >
318 <class>QComboBox</class>
319 <item>
320 <property>
321 <name>text</name>
322 <string>suspend</string>
323 </property>
324 </item>
325 <item>
326 <property>
327 <name>text</name>
328 <string>activate</string>
329 </property>
330 </item>
331 <item>
332 <property>
333 <name>text</name>
334 <string>eject</string>
335 </property>
336 </item>
337 <item>
338 <property>
339 <name>text</name>
340 <string>prompt for</string>
341 </property>
342 </item>
343 <property stdset="1">
344 <name>name</name>
345 <cstring>cbResumeAction</cstring>
346 </property>
347 </widget>
295 </grid> 348 </grid>
296</widget> 349</widget>
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index 1a2b619..186dfea 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -40,4 +40,5 @@
40#include <opie2/otaskbarapplet.h> 40#include <opie2/otaskbarapplet.h>
41#include <qpe/applnk.h> 41#include <qpe/applnk.h>
42#include <qpe/global.h>
42#include <qpe/resource.h> 43#include <qpe/resource.h>
43using namespace Opie::Core; 44using namespace Opie::Core;
@@ -45,4 +46,5 @@ using namespace Opie::Ui;
45 46
46/* QT */ 47/* QT */
48#include <qcombobox.h>
47#include <qcopchannel_qws.h> 49#include <qcopchannel_qws.h>
48#include <qpainter.h> 50#include <qpainter.h>
@@ -179,5 +181,5 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
179 if ( it.current()->isEmpty() ) 181 if ( it.current()->isEmpty() )
180 { 182 {
181 odebug << "skipping empty card in socket " << it.current()->number() << oendl; 183 odebug << "pcmcia: skipping empty card in socket " << it.current()->number() << oendl;
182 ++it; 184 ++it;
183 continue; 185 continue;
@@ -192,5 +194,5 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
192 cfg.setGroup( cardSection ); 194 cfg.setGroup( cardSection );
193 QString name = cfg.readEntry( "name" ); 195 QString name = cfg.readEntry( "name" );
194 odebug << "comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 196 odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
195 if ( cardName == name ) 197 if ( cardName == name )
196 { 198 {
@@ -208,24 +210,48 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
208 int result = QMessageBox::information( qApp->desktop(), 210 int result = QMessageBox::information( qApp->desktop(),
209 tr( "PCMCIA/CF Subsystem" ), 211 tr( "PCMCIA/CF Subsystem" ),
210 tr( "<qt>You have inserted the card '%1'. This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ), 212 tr( "<qt>You have inserted the card<br/><b>%1</b><br/>This card is not yet configured. Do you want to configure it now?</qt>" ).arg( newCardName ),
211 tr( "Yes" ), tr( "No" ), 0, 0, 1 ); 213 tr( "Yes" ), tr( "No" ), 0, 0, 1 );
212 odebug << "result = " << result << oendl; 214 odebug << "pcmcia: result = " << result << oendl;
213 if ( result == 0 ) 215 if ( result == 0 )
214 { 216 {
215 bool configured = configure( theCard ); 217 QString insertAction; QString resumeAction; QString driver; QString conf;
218 bool configured = configure( theCard, insertAction, resumeAction, driver, conf );
216 219
217 if ( configured ) 220 if ( configured )
218 { 221 {
219 odebug << "card has been configured. writing out to dabase" << oendl; 222 odebug << "pcmcia: card has been configured. writing out to database" << oendl;
220 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) ); 223 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
221 cfg.writeEntry( "name", newCardName ); 224 cfg.writeEntry( "name", newCardName );
222 cfg.writeEntry( "insert", "suspend" ); 225 cfg.writeEntry( "insertAction", insertAction );
226 cfg.writeEntry( "resumeAction", resumeAction );
223 cfg.setGroup( "Global" ); 227 cfg.setGroup( "Global" );
224 cfg.writeEntry( "nCards", nCards+1 ); 228 cfg.writeEntry( "nCards", nCards+1 );
225 cfg.write(); 229 cfg.write();
230
231 QFile confFile( QString( "/etc/pcmcia/%1" ).arg( conf ) );
232 if ( confFile.open( IO_ReadWrite | IO_Append ) )
233 {
234 QString entryCard = QString( "card \"%1\"" ).arg( newCardName );
235 QString entryVersion( " version " );
236 for ( QStringList::Iterator it = theCard->productIdentity().begin(); it != theCard->productIdentity().end(); ++it )
237 {
238 entryVersion += QString( "\"%1\", " ).arg( *it );
239 }
240 QString entryBind = QString( " bind %1" ).arg( driver );
241 QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind );
242 odebug << "pcmcia: writing entry...:" << entry << oendl;
243
244 confFile.writeBlock( (const char*) entry, entry.length() );
245 Global::statusMessage( "restarting pcmcia services..." );
246 ::system( "/etc/init.d/pcmcia restart" );
247 }
248 else
249 {
250 owarn << "pcmcia: couldn't write binding to '" << conf << "'." << oendl;
251 }
226 } 252 }
227 else 253 else
228 { 254 {
229 odebug << "card has not been configured this time. leaving as unknown card" << oendl; 255 odebug << "pcmcia: card has not been configured this time. leaving as unknown card" << oendl;
230 } 256 }
231 } 257 }
@@ -237,7 +263,7 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
237 else // it's an already configured card 263 else // it's an already configured card
238 { 264 {
239 QString action = ConfigDialog::preferredAction( theCard ); 265 QString insertAction = ConfigDialog::preferredAction( theCard, "insert" );
240 odebug << "pcmcia: card has been previously configured" << oendl; 266 odebug << "pcmcia: card has been previously configured" << oendl;
241 odebug << "pcmcia: need to perform action'" << action << "' now... sorry, not yet implemented..." << oendl; 267 odebug << "pcmcia: TODO: need to perform action'" << insertAction << "' now... sorry, not yet implemented..." << oendl;
242 } 268 }
243 repaint( true ); 269 repaint( true );
@@ -272,5 +298,5 @@ void PcmciaManager::execCommand( const QStringList &strList )
272void PcmciaManager::userCardAction( int action ) 298void PcmciaManager::userCardAction( int action )
273{ 299{
274 odebug << "user action on socket " << action / 100 << " requested. action = " << action << oendl; 300 odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl;
275 301
276 int socket = action / 100; 302 int socket = action / 100;
@@ -280,5 +306,11 @@ void PcmciaManager::userCardAction( int action )
280 switch ( what ) 306 switch ( what )
281 { 307 {
282 case CONFIGURE: configure( OPcmciaSystem::instance()->socket( socket ) ); success = true; break; 308 case CONFIGURE:
309 {
310 QString insertAction; QString resumeAction; QString driver; QString conf;
311 bool result = configure( OPcmciaSystem::instance()->socket( socket ), insertAction, resumeAction, driver, conf );
312 success = true;
313 break;
314 }
283 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); break; 315 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); break;
284 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); break; 316 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); break;
@@ -286,15 +318,15 @@ void PcmciaManager::userCardAction( int action )
286 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); break; 318 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); break;
287 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); break; 319 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); break;
288 default: odebug << "not yet implemented" << oendl; 320 default: odebug << "pcmcia: not yet implemented" << oendl;
289 } 321 }
290 322
291 if ( !success ) 323 if ( !success )
292 { 324 {
293 owarn << "couldn't perform user action (" << strerror( errno ) << ")" << oendl; 325 owarn << "pcmcia: couldn't perform user action (" << strerror( errno ) << ")" << oendl;
294 } 326 }
295 327
296} 328}
297 329
298bool PcmciaManager::configure( OPcmciaSocket* card ) 330bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QString& resumeAction, QString& driver, QString& conf )
299{ 331{
300 configuring = true; 332 configuring = true;
@@ -303,4 +335,11 @@ bool PcmciaManager::configure( OPcmciaSocket* card )
303 configuring = false; 335 configuring = false;
304 odebug << "pcmcia: configresult = " << configresult << oendl; 336 odebug << "pcmcia: configresult = " << configresult << oendl;
337 if ( configresult )
338 {
339 insertAction = dialog.cbInsertAction->currentText();
340 resumeAction = dialog.cbResumeAction->currentText();
341 driver = dialog.cbBindTo->currentText();
342 conf = dialog.bindEntries[driver];
343 }
305 return configresult; 344 return configresult;
306} 345}
diff --git a/noncore/applets/pcmcia/pcmcia.h b/noncore/applets/pcmcia/pcmcia.h
index eb9c513..94203d3 100644
--- a/noncore/applets/pcmcia/pcmcia.h
+++ b/noncore/applets/pcmcia/pcmcia.h
@@ -55,5 +55,5 @@ class PcmciaManager : public QWidget
55 55
56 private: 56 private:
57 bool configure( Opie::Core::OPcmciaSocket* ); 57 bool configure( Opie::Core::OPcmciaSocket*, QString&, QString&, QString&, QString& );
58 void execCommand( const QStringList &command ); 58 void execCommand( const QStringList &command );
59 void popUp(QString message, QString icon = QString::null ); 59 void popUp(QString message, QString icon = QString::null );