Diffstat (limited to 'noncore/applets/pcmcia/pcmcia.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/applets/pcmcia/pcmcia.cpp | 69 |
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 | |||
@@ -30,29 +30,31 @@ | |||
30 | #include "pcmcia.h" | 30 | #include "pcmcia.h" |
31 | #include "configdialog.h" | 31 | #include "configdialog.h" |
32 | 32 | ||
33 | /* OPIE */ | 33 | /* OPIE */ |
34 | #include <opie2/odebug.h> | 34 | #include <opie2/odebug.h> |
35 | #include <opie2/odevice.h> | 35 | #include <opie2/odevice.h> |
36 | #include <opie2/oconfig.h> | 36 | #include <opie2/oconfig.h> |
37 | #include <opie2/oprocess.h> | 37 | #include <opie2/oprocess.h> |
38 | #include <opie2/opcmciasystem.h> | 38 | #include <opie2/opcmciasystem.h> |
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> |
43 | using namespace Opie::Core; | 44 | using namespace Opie::Core; |
44 | using namespace Opie::Ui; | 45 | 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> |
49 | #include <qfile.h> | 51 | #include <qfile.h> |
50 | #include <qtextstream.h> | 52 | #include <qtextstream.h> |
51 | #include <qmessagebox.h> | 53 | #include <qmessagebox.h> |
52 | #include <qsound.h> | 54 | #include <qsound.h> |
53 | #include <qtimer.h> | 55 | #include <qtimer.h> |
54 | 56 | ||
55 | /* STD */ | 57 | /* STD */ |
56 | #include <stdio.h> | 58 | #include <stdio.h> |
57 | #include <unistd.h> | 59 | #include <unistd.h> |
58 | #include <stdlib.h> | 60 | #include <stdlib.h> |
@@ -169,85 +171,109 @@ void PcmciaManager::cardMessage( const QCString & msg, const QByteArray & ) | |||
169 | int nCards = cfg.readNumEntry( "nCards", 0 ); | 171 | int nCards = cfg.readNumEntry( "nCards", 0 ); |
170 | 172 | ||
171 | OPcmciaSystem* sys = OPcmciaSystem::instance(); | 173 | OPcmciaSystem* sys = OPcmciaSystem::instance(); |
172 | OPcmciaSystem::CardIterator it = sys->iterator(); | 174 | OPcmciaSystem::CardIterator it = sys->iterator(); |
173 | 175 | ||
174 | bool newCard = true; | 176 | bool newCard = true; |
175 | OPcmciaSocket* theCard = 0; | 177 | OPcmciaSocket* theCard = 0; |
176 | 178 | ||
177 | while ( it.current() && newCard ) | 179 | while ( it.current() && newCard ) |
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 | } |
185 | else | 187 | else |
186 | { | 188 | { |
187 | theCard = it.current(); | 189 | theCard = it.current(); |
188 | QString cardName = theCard->productIdentity().join( " " ); | 190 | QString cardName = theCard->productIdentity().join( " " ); |
189 | for ( int i = 0; i < nCards; ++i ) | 191 | for ( int i = 0; i < nCards; ++i ) |
190 | { | 192 | { |
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; |
198 | break; | 200 | break; |
199 | } | 201 | } |
200 | } | 202 | } |
201 | if ( !newCard ) ++it; else break; | 203 | if ( !newCard ) ++it; else break; |
202 | } | 204 | } |
203 | } | 205 | } |
204 | if ( newCard ) | 206 | if ( newCard ) |
205 | { | 207 | { |
206 | odebug << "pcmcia: unconfigured card detected" << oendl; | 208 | odebug << "pcmcia: unconfigured card detected" << oendl; |
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 |
233 | { | 259 | { |
234 | odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl; | 260 | odebug << "pcmcia: user doesn't want to configure " << newCardName << " now." << oendl; |
235 | } | 261 | } |
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 | } |
245 | 271 | ||
246 | 272 | ||
247 | void PcmciaManager::paintEvent( QPaintEvent * ) | 273 | void PcmciaManager::paintEvent( QPaintEvent * ) |
248 | { | 274 | { |
249 | QPainter p( this ); | 275 | QPainter p( this ); |
250 | odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl; | 276 | odebug << "sockets = " << OPcmciaSystem::instance()->count() << ", cards = " << OPcmciaSystem::instance()->cardCount() << oendl; |
251 | 277 | ||
252 | if ( OPcmciaSystem::instance()->cardCount() ) | 278 | if ( OPcmciaSystem::instance()->cardCount() ) |
253 | { | 279 | { |
@@ -262,49 +288,62 @@ void PcmciaManager::paintEvent( QPaintEvent * ) | |||
262 | 288 | ||
263 | int PcmciaManager::position() | 289 | int PcmciaManager::position() |
264 | { | 290 | { |
265 | return 7; | 291 | return 7; |
266 | } | 292 | } |
267 | 293 | ||
268 | void PcmciaManager::execCommand( const QStringList &strList ) | 294 | void PcmciaManager::execCommand( const QStringList &strList ) |
269 | { | 295 | { |
270 | } | 296 | } |
271 | 297 | ||
272 | void PcmciaManager::userCardAction( int action ) | 298 | void 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; |
278 | bool success = false; | 304 | bool success = false; |
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 | ||
298 | bool PcmciaManager::configure( OPcmciaSocket* card ) | 330 | bool 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 | ||
308 | 347 | ||
309 | EXPORT_OPIE_APPLET_v1( PcmciaManager ) | 348 | EXPORT_OPIE_APPLET_v1( PcmciaManager ) |
310 | 349 | ||