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.cpp114
1 files changed, 44 insertions, 70 deletions
diff --git a/noncore/applets/pcmcia/pcmcia.cpp b/noncore/applets/pcmcia/pcmcia.cpp
index c6386cb..187adc6 100644
--- a/noncore/applets/pcmcia/pcmcia.cpp
+++ b/noncore/applets/pcmcia/pcmcia.cpp
@@ -1,55 +1,56 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de> 3 =. (C) 2005 Michael 'Mickey' Lauer <mickey@Vanille.de>
4 .=l. 4 .=l.
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This program is free software; you can 6 _;:,     .>    :=|. This program is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 8:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This program is distributed in the hope that 13    .i_,=:_.      -<s. This program is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
18..}^=.=       =       ; Library General Public License for more 18..}^=.=       =       ; Library General Public License for more
19++=   -.     .`     .: details. 19++=   -.     .`     .: details.
20 :     =  ...= . :.=- 20 :     =  ...= . :.=-
21 -.   .:....=;==+<; You should have received a copy of the GNU 21 -.   .:....=;==+<; You should have received a copy of the GNU
22  -_. . .   )=.  = Library General Public License along with 22  -_. . .   )=.  = Library General Public License along with
23    --        :-=` this library; see the file COPYING.LIB. 23    --        :-=` this library; see the file COPYING.LIB.
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 "pcmcia.h" 30#include "pcmcia.h"
31#include "configdialog.h" 31#include "configdialog.h"
32#include "promptactiondialog.h"
32 33
33/* OPIE */ 34/* OPIE */
34#include <opie2/odebug.h> 35#include <opie2/odebug.h>
35#include <opie2/odevice.h> 36#include <opie2/odevice.h>
36#include <opie2/oconfig.h> 37#include <opie2/oconfig.h>
37#include <opie2/oprocess.h> 38#include <opie2/oprocess.h>
38#include <opie2/opcmciasystem.h> 39#include <opie2/opcmciasystem.h>
39#include <opie2/oresource.h> 40#include <opie2/oresource.h>
40#include <opie2/otaskbarapplet.h> 41#include <opie2/otaskbarapplet.h>
41#include <qpe/applnk.h> 42#include <qpe/applnk.h>
42#include <qpe/global.h> 43#include <qpe/global.h>
43#include <qpe/resource.h> 44#include <qpe/resource.h>
44using namespace Opie::Core; 45using namespace Opie::Core;
45using namespace Opie::Ui; 46using namespace Opie::Ui;
46 47
47/* QT */ 48/* QT */
48#include <qcombobox.h> 49#include <qcombobox.h>
49#include <qcopchannel_qws.h> 50#include <qcopchannel_qws.h>
50#include <qpainter.h> 51#include <qpainter.h>
51#include <qfile.h> 52#include <qfile.h>
52#include <qtextstream.h> 53#include <qtextstream.h>
53#include <qmessagebox.h> 54#include <qmessagebox.h>
54#include <qsound.h> 55#include <qsound.h>
55#include <qtimer.h> 56#include <qtimer.h>
@@ -117,50 +118,50 @@ void PcmciaManager::popUp( QString message, QString icon )
117 } 118 }
118 popupMenu->clear(); 119 popupMenu->clear();
119 120
120 if ( icon.isEmpty() ) { 121 if ( icon.isEmpty() ) {
121 popupMenu->insertItem( message, 0 ); 122 popupMenu->insertItem( message, 0 );
122 } else { 123 } else {
123 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ), 124 popupMenu->insertItem( QIconSet( Opie::Core::OResource::loadPixmap( icon, Opie::Core::OResource::SmallIcon ) ),
124 message, 0 ); 125 message, 0 );
125 } 126 }
126 127
127 QPoint p = mapToGlobal( QPoint( 0, 0 ) ); 128 QPoint p = mapToGlobal( QPoint( 0, 0 ) );
128 QSize s = popupMenu->sizeHint(); 129 QSize s = popupMenu->sizeHint();
129 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ), 130 popupMenu->popup( QPoint( p.x() + ( width() / 2 ) - ( s.width() / 2 ),
130 p.y() - s.height() ), 0 ); 131 p.y() - s.height() ), 0 );
131 132
132 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) ); 133 QTimer::singleShot( 2000, this, SLOT( popupTimeout() ) );
133} 134}
134 135
135 136
136void PcmciaManager::popupTimeout() 137void PcmciaManager::popupTimeout()
137{ 138{
138 popupMenu->hide(); 139 popupMenu->hide();
139} 140}
140 141
141enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE }; 142enum { EJECT, INSERT, SUSPEND, RESUME, RESET, CONFIGURE, ACTIVATE };
142static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur" }; 143static const char* actionText[] = { "eject", "insert", "suspend", "resum", "resett", "configur", "activat" };
143 144
144void PcmciaManager::mousePressEvent( QMouseEvent* ) 145void PcmciaManager::mousePressEvent( QMouseEvent* )
145{ 146{
146 QPopupMenu* menu = new QPopupMenu( this ); 147 QPopupMenu* menu = new QPopupMenu( this );
147 QStringList cmd; 148 QStringList cmd;
148 bool execute = true; 149 bool execute = true;
149 150
150 OPcmciaSystem* sys = OPcmciaSystem::instance(); 151 OPcmciaSystem* sys = OPcmciaSystem::instance();
151 sys->synchronize(); 152 sys->synchronize();
152 OPcmciaSystem::CardIterator it = sys->iterator(); 153 OPcmciaSystem::CardIterator it = sys->iterator();
153 if ( !sys->count() ) return; 154 if ( !sys->count() ) return;
154 155
155 int i = 0; 156 int i = 0;
156 while ( it.current() ) 157 while ( it.current() )
157 { 158 {
158 QPopupMenu* submenu = new QPopupMenu( menu ); 159 QPopupMenu* submenu = new QPopupMenu( menu );
159 submenu->insertItem( "&Eject", EJECT+i*100 ); 160 submenu->insertItem( "&Eject", EJECT+i*100 );
160 submenu->insertItem( "&Insert", INSERT+i*100 ); 161 submenu->insertItem( "&Insert", INSERT+i*100 );
161 submenu->insertItem( "&Suspend", SUSPEND+i*100 ); 162 submenu->insertItem( "&Suspend", SUSPEND+i*100 );
162 submenu->insertItem( "&Resume", RESUME+i*100 ); 163 submenu->insertItem( "&Resume", RESUME+i*100 );
163 submenu->insertItem( "Rese&t", RESET+i*100 ); 164 submenu->insertItem( "Rese&t", RESET+i*100 );
164 submenu->insertItem( "&Configure", CONFIGURE+i*100 ); 165 submenu->insertItem( "&Configure", CONFIGURE+i*100 );
165 166
166 bool isSuspended = it.current()->isSuspended(); 167 bool isSuspended = it.current()->isSuspended();
@@ -225,170 +226,143 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & )
225 QString name = cfg.readEntry( "name" ); 226 QString name = cfg.readEntry( "name" );
226 odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl; 227 odebug << "pcmcia: comparing card '" << cardName << "' with known card '" << name << "'" << oendl;
227 if ( cardName == name ) 228 if ( cardName == name )
228 { 229 {
229 newCard = false; 230 newCard = false;
230 odebug << "pcmcia: we have seen this card before" << oendl; 231 odebug << "pcmcia: we have seen this card before" << oendl;
231 executeAction( theCard, "insert" ); 232 executeAction( theCard, "insert" );
232 break; 233 break;
233 } 234 }
234 } 235 }
235 if ( !newCard ) ++it; else break; 236 if ( !newCard ) ++it; else break;
236 } 237 }
237 } 238 }
238 if ( newCard ) 239 if ( newCard )
239 { 240 {
240 odebug << "pcmcia: unconfigured card detected" << oendl; 241 odebug << "pcmcia: unconfigured card detected" << oendl;
241 QString newCardName = theCard->productIdentity(); 242 QString newCardName = theCard->productIdentity();
242 int result = QMessageBox::information( qApp->desktop(), 243 int result = QMessageBox::information( qApp->desktop(),
243 tr( "PCMCIA/CF Subsystem" ), 244 tr( "PCMCIA/CF Subsystem" ),
244 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 ), 245 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 ),
245 tr( "Yes" ), tr( "No" ), 0, 0, 1 ); 246 tr( "Yes" ), tr( "No" ), 0, 0, 1 );
246 odebug << "pcmcia: result = " << result << oendl; 247 odebug << "pcmcia: result = " << result << oendl;
247 if ( result == 0 ) 248 if ( result == 0 )
248 { 249 {
249 QString insertAction; QString resumeAction; QString driver; QString conf; 250 configure( theCard );
250 bool configured = configure( theCard, insertAction, resumeAction, driver, conf );
251
252 if ( configured )
253 {
254 odebug << "pcmcia: card has been configured. writing out to database" << oendl;
255 cfg.setGroup( QString( "Card_%1" ).arg( nCards ) );
256 cfg.writeEntry( "name", newCardName );
257 cfg.writeEntry( "insertAction", insertAction );
258 cfg.writeEntry( "resumeAction", resumeAction );
259 cfg.setGroup( "Global" );
260 cfg.writeEntry( "nCards", nCards+1 );
261 cfg.write();
262
263 QFile confFile( conf );
264 if ( confFile.open( IO_ReadWrite | IO_Append ) )
265 {
266 QString entryCard = QString( "card \"%1\"" ).arg( newCardName );
267 QString entryVersion( " version " );
268 for ( QStringList::Iterator it = theCard->productIdentityVector().begin(); it != theCard->productIdentityVector().end(); ++it )
269 {
270 entryVersion += QString( "\"%1\", " ).arg( *it );
271 }
272 QString entryBind = QString( " bind %1" ).arg( driver );
273 QString entry = QString( "\n%1\n%2\n%3\n" ).arg( entryCard ).arg( entryVersion ).arg( entryBind );
274 odebug << "pcmcia: writing entry...:" << entry << oendl;
275
276 confFile.writeBlock( (const char*) entry, entry.length() );
277 Global::statusMessage( "restarting pcmcia services..." );
278 ::system( "/etc/init.d/pcmcia restart" );
279 }
280 else
281 {
282 owarn << "pcmcia: couldn't write binding to '" << conf << "' ( " << strerror( errno ) << " )." << oendl;
283 }
284 }
285 else
286 {
287 odebug << "pcmcia: card has not been configured this time. leaving as unknown card" << oendl;
288 }
289 } 251 }
290 else 252 else
291 { 253 {
292 odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl; 254 odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl;
293 } 255 }
294 } 256 }
295 else // it's an already configured card 257 else // it's an already configured card
296 { 258 {
297 odebug << "pcmcia: doing nothing... why do we come here?" << oendl; 259 odebug << "pcmcia: doing nothing... why do we come here?" << oendl;
298 } 260 }
299} 261}
300 262
301void PcmciaManager::paintEvent( QPaintEvent * ) 263void PcmciaManager::paintEvent( QPaintEvent * )
302{ 264{
303 QPainter p( this ); 265 QPainter p( this );
304 p.drawPixmap( 0, 0, pm ); 266 p.drawPixmap( 0, 0, pm );
305} 267}
306 268
307int PcmciaManager::position() 269int PcmciaManager::position()
308{ 270{
309 return 7; 271 return 7;
310} 272}
311 273
312void PcmciaManager::execCommand( const QStringList &strList ) 274void PcmciaManager::execCommand( const QStringList &strList )
313{ 275{
314} 276}
315 277
316void PcmciaManager::userCardAction( int action ) 278void PcmciaManager::userCardAction( int action )
317{ 279{
318 odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl; 280 odebug << "pcmcia: user action on socket " << action / 100 << " requested. action = " << action << oendl;
319 281
320 int socket = action / 100; 282 int socket = action / 100;
321 int what = action % 100; 283 int what = action % 100;
322 bool success = false; 284 bool success = false;
323 285
324 switch ( what ) 286 switch ( what )
325 { 287 {
326 case CONFIGURE: 288 case CONFIGURE:
327 { 289 {
328 QString insertAction; QString resumeAction; QString driver; QString conf; 290 QString insertAction; QString resumeAction; QString driver; QString conf;
329 configure( OPcmciaSystem::instance()->socket( socket ), insertAction, resumeAction, driver, conf ); 291 configure( OPcmciaSystem::instance()->socket( socket ) );
330 return; 292 return;
331 } 293 }
332 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject(); 294 case EJECT: success = OPcmciaSystem::instance()->socket( socket )->eject();
333 break; 295 break;
334 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert(); 296 case INSERT: success = OPcmciaSystem::instance()->socket( socket )->insert();
335 break; 297 break;
336 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend(); 298 case SUSPEND: success = OPcmciaSystem::instance()->socket( socket )->suspend();
337 break; 299 break;
338 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume(); 300 case RESUME: success = OPcmciaSystem::instance()->socket( socket )->resume();
339 break; 301 break;
340 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset(); 302 case RESET: success = OPcmciaSystem::instance()->socket( socket )->reset();
341 break; 303 break;
342 default: odebug << "pcmcia: not yet implemented" << oendl; 304 case ACTIVATE: success = true;
305 break;
306 default: odebug << "pcmcia: not yet implemented" << oendl;
343 } 307 }
344 308
345 if ( success ) 309 if ( success )
346 { 310 {
311 odebug << tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl;
347 popUp( tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); 312 popUp( tr( "Successfully %1ed card in socket #%2" ).arg( actionText[action] ).arg( socket ) );
348 } 313 }
349 else 314 else
350 { 315 {
316 odebug << tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) << oendl;
351 popUp( tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) ); 317 popUp( tr( "Error while %1ing card in socket #%2" ).arg( actionText[action] ).arg( socket ) );
352 } 318 }
353} 319}
354 320
355bool PcmciaManager::configure( OPcmciaSocket* card, QString& insertAction, QString& resumeAction, QString& driver, QString& conf ) 321void PcmciaManager::configure( OPcmciaSocket* card )
356{ 322{
357 configuring = true; 323 configuring = true;
358 ConfigDialog dialog( card, qApp->desktop() ); 324 ConfigDialog dialog( card, qApp->desktop() );
359 int configresult = QPEApplication::execDialog( &dialog, false ); 325 int result = QPEApplication::execDialog( &dialog, false );
360 configuring = false; 326 configuring = false;
361 odebug << "pcmcia: configresult = " << configresult << oendl; 327 odebug << "pcmcia: configresult = " << result << oendl;
362 if ( configresult ) 328 if ( result )
363 { 329 {
364 insertAction = dialog.cbInsertAction->currentText(); 330 dialog.writeConfiguration( card );
365 resumeAction = dialog.cbResumeAction->currentText();
366 driver = dialog.cbBindTo->currentText();
367 conf = dialog.bindEntries[driver];
368 } 331 }
369 return configresult;
370} 332}
371 333
372void PcmciaManager::executeAction( Opie::Core::OPcmciaSocket* card, const QString& type ) 334void PcmciaManager::executeAction( Opie::Core::OPcmciaSocket* card, const QString& type )
373{ 335{
374 odebug << "pcmcia: performing " << type << " action ..." << oendl; 336 odebug << "pcmcia: performing " << type << " action ..." << oendl;
375 QString theAction = ConfigDialog::preferredAction( card, type ); 337 QString theAction = ConfigDialog::preferredAction( card, type );
376 int intAction = card->number() * 100; 338 int intAction = card->number() * 100;
377 if ( theAction == "activate" ) ; 339
378 else if ( theAction == "eject" ) intAction += EJECT; 340 if ( theAction == "prompt for" )
379 else if ( theAction == "suspend" ) intAction += SUSPEND;
380 else if ( theAction == "prompt for" )
381 { 341 {
382 odebug << "pcmcia: sorry, not 'prompt for' is not yet implemented!" << oendl; 342 PromptActionDialog dialog( qApp->desktop(), "promptfor", true );
383 return; 343 dialog.setCaption( QString( "Choose action for card #%1" ).arg( card->number() ) );
344 int result = QPEApplication::execDialog( &dialog, true );
345 odebug << "pcmcia: configresult = " << result << oendl;
346 if ( result )
347 {
348 theAction = dialog.cbAction->currentText();
349 }
350 else
351 {
352 odebug << "pcmcia: prompted to do nothing" << oendl;
353 return;
354 }
384 } 355 }
356 if ( theAction == "activate" ) intAction += ACTIVATE;
357 else if ( theAction == "eject" ) intAction += EJECT;
358 else if ( theAction == "suspend" ) intAction += SUSPEND;
385 else 359 else
386 { 360 {
387 owarn << "pcmcia: action '" << theAction << "' not known. Huh?" << oendl; 361 owarn << "pcmcia: action '" << theAction << "' not known. Huh?" << oendl;
388 return; 362 return;
389 } 363 }
390 userCardAction( intAction ); 364 userCardAction( intAction );
391} 365}
392 366
393EXPORT_OPIE_APPLET_v1( PcmciaManager ) 367EXPORT_OPIE_APPLET_v1( PcmciaManager )
394 368