summaryrefslogtreecommitdiff
path: root/noncore/applets/pcmcia/pcmcia.cpp
Unidiff
Diffstat (limited to 'noncore/applets/pcmcia/pcmcia.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/pcmcia/pcmcia.cpp69
1 files changed, 54 insertions, 15 deletions
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
@@ -39,11 +39,13 @@
39#include <opie2/oresource.h> 39#include <opie2/oresource.h>
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;
44using namespace Opie::Ui; 45using 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>
49#include <qfile.h> 51#include <qfile.h>
@@ -178,7 +180,7 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
178 { 180 {
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;
184 } 186 }
@@ -191,7 +193,7 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
191 QString cardSection = QString( "Card_%1" ).arg( i ); 193 QString cardSection = QString( "Card_%1" ).arg( i );
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 {
197 newCard = false; 199 newCard = false;
@@ -207,26 +209,50 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
207 QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace(); 209 QString newCardName = theCard->productIdentity().join( " " ).stripWhiteSpace();
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 }
232 else 258 else
@@ -236,9 +262,9 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
236 } 262 }
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 );
244} 270}
@@ -271,7 +297,7 @@ void PcmciaManager::execCommand( const QStringList &strList )
271 297
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;
277 int what = action % 100; 303 int what = action % 100;
@@ -279,29 +305,42 @@ void PcmciaManager::userCardAction( int action )
279 305
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;
285 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); break; 317 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); break;
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;
301 ConfigDialog dialog( card, qApp->desktop() ); 333 ConfigDialog dialog( card, qApp->desktop() );
302 int configresult = QPEApplication::execDialog( &dialog, false ); 334 int configresult = QPEApplication::execDialog( &dialog, false );
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}
307 346