-rw-r--r-- | noncore/settings/aqpkg/networkpkgmgr.cpp | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/noncore/settings/aqpkg/networkpkgmgr.cpp b/noncore/settings/aqpkg/networkpkgmgr.cpp index 3ce7960..6f528a1 100644 --- a/noncore/settings/aqpkg/networkpkgmgr.cpp +++ b/noncore/settings/aqpkg/networkpkgmgr.cpp | |||
@@ -239,270 +239,286 @@ void NetworkPackageManager :: serverSelected( int ) | |||
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
242 | void NetworkPackageManager :: updateServer() | 242 | void NetworkPackageManager :: updateServer() |
243 | { | 243 | { |
244 | QString serverName = serversList->currentText(); | 244 | QString serverName = serversList->currentText(); |
245 | 245 | ||
246 | // Update the current server | 246 | // Update the current server |
247 | // Display dialog | 247 | // Display dialog |
248 | ProgressDlg *dlg = new ProgressDlg( this ); | 248 | ProgressDlg *dlg = new ProgressDlg( this ); |
249 | QString status = "Updating package lists..."; | 249 | QString status = "Updating package lists..."; |
250 | dlg->show(); | 250 | dlg->show(); |
251 | dlg->setText( status ); | 251 | dlg->setText( status ); |
252 | 252 | ||
253 | // Disable buttons to stop silly people clicking lots on them :) | 253 | // Disable buttons to stop silly people clicking lots on them :) |
254 | 254 | ||
255 | // First, write out ipkg_conf file so that ipkg can use it | 255 | // First, write out ipkg_conf file so that ipkg can use it |
256 | dataMgr->writeOutIpkgConf(); | 256 | dataMgr->writeOutIpkgConf(); |
257 | 257 | ||
258 | // if ( serverName == LOCAL_SERVER ) | 258 | // if ( serverName == LOCAL_SERVER ) |
259 | // ; | 259 | // ; |
260 | // else if ( serverName == LOCAL_IPKGS ) | 260 | // else if ( serverName == LOCAL_IPKGS ) |
261 | // ; | 261 | // ; |
262 | // else | 262 | // else |
263 | { | 263 | { |
264 | QString option = "update"; | 264 | QString option = "update"; |
265 | QString dummy = ""; | 265 | QString dummy = ""; |
266 | Ipkg ipkg; | 266 | Ipkg ipkg; |
267 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 267 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
268 | ipkg.setOption( option ); | 268 | ipkg.setOption( option ); |
269 | 269 | ||
270 | ipkg.runIpkg( ); | 270 | ipkg.runIpkg( ); |
271 | } | 271 | } |
272 | 272 | ||
273 | // Reload data | 273 | // Reload data |
274 | dataMgr->reloadServerData( serversList->currentText() ); | 274 | dataMgr->reloadServerData( serversList->currentText() ); |
275 | serverSelected(-1); | 275 | serverSelected(-1); |
276 | delete dlg; | 276 | delete dlg; |
277 | } | 277 | } |
278 | 278 | ||
279 | void NetworkPackageManager :: upgradePackages() | 279 | void NetworkPackageManager :: upgradePackages() |
280 | { | 280 | { |
281 | // We're gonna do an upgrade of all packages | 281 | // We're gonna do an upgrade of all packages |
282 | // First warn user that this isn't recommended | 282 | // First warn user that this isn't recommended |
283 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; | 283 | QString text = "WARNING: Upgrading while\nOpie/Qtopia is running\nis NOT recommended!\n\nAre you sure?\n"; |
284 | QMessageBox warn("Warning", text, QMessageBox::Warning, | 284 | QMessageBox warn("Warning", text, QMessageBox::Warning, |
285 | QMessageBox::Yes, | 285 | QMessageBox::Yes, |
286 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , | 286 | QMessageBox::No | QMessageBox::Escape | QMessageBox::Default , |
287 | 0, this ); | 287 | 0, this ); |
288 | warn.adjustSize(); | 288 | warn.adjustSize(); |
289 | 289 | ||
290 | if ( warn.exec() == QMessageBox::Yes ) | 290 | if ( warn.exec() == QMessageBox::Yes ) |
291 | { | 291 | { |
292 | // First, write out ipkg_conf file so that ipkg can use it | 292 | // First, write out ipkg_conf file so that ipkg can use it |
293 | dataMgr->writeOutIpkgConf(); | 293 | dataMgr->writeOutIpkgConf(); |
294 | 294 | ||
295 | // Now run upgrade | 295 | // Now run upgrade |
296 | InstallDlgImpl dlg( this, "Upgrade", true ); | 296 | InstallDlgImpl dlg( this, "Upgrade", true ); |
297 | dlg.showDlg(); | 297 | dlg.showDlg(); |
298 | 298 | ||
299 | // Reload data | 299 | // Reload data |
300 | dataMgr->reloadServerData( LOCAL_SERVER ); | 300 | dataMgr->reloadServerData( LOCAL_SERVER ); |
301 | 301 | ||
302 | dataMgr->reloadServerData( serversList->currentText() ); | 302 | dataMgr->reloadServerData( serversList->currentText() ); |
303 | serverSelected(-1); | 303 | serverSelected(-1); |
304 | } | 304 | } |
305 | } | 305 | } |
306 | 306 | ||
307 | 307 | ||
308 | void NetworkPackageManager :: downloadPackage() | 308 | void NetworkPackageManager :: downloadPackage() |
309 | { | 309 | { |
310 | if ( download->text() == "Download" ) | 310 | if ( download->text() == "Download" ) |
311 | { | 311 | { |
312 | // First, write out ipkg_conf file so that ipkg can use it | 312 | // First, write out ipkg_conf file so that ipkg can use it |
313 | dataMgr->writeOutIpkgConf(); | 313 | dataMgr->writeOutIpkgConf(); |
314 | 314 | ||
315 | // Display dialog to user asking where to download the files to | 315 | // Display dialog to user asking where to download the files to |
316 | bool ok = FALSE; | 316 | bool ok = FALSE; |
317 | QString dir = ""; | 317 | QString dir = ""; |
318 | #ifdef QWS | 318 | #ifdef QWS |
319 | // read download directory from config file | 319 | // read download directory from config file |
320 | Config cfg( "aqpkg" ); | 320 | Config cfg( "aqpkg" ); |
321 | cfg.setGroup( "settings" ); | 321 | cfg.setGroup( "settings" ); |
322 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); | 322 | dir = cfg.readEntry( "downloadDir", "/home/root/Documents/application/ipkg" ); |
323 | #endif | 323 | #endif |
324 | 324 | ||
325 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); | 325 | QString text = InputDialog::getText( tr( "Download to where" ), tr( "Enter path to download to" ), dir, &ok, this ); |
326 | if ( ok && !text.isEmpty() ) | 326 | if ( ok && !text.isEmpty() ) |
327 | dir = text; // user entered something and pressed ok | 327 | dir = text; // user entered something and pressed ok |
328 | else | 328 | else |
329 | return; // user entered nothing or pressed cancel | 329 | return; // user entered nothing or pressed cancel |
330 | 330 | ||
331 | #ifdef QWS | 331 | #ifdef QWS |
332 | // Store download directory in config file | 332 | // Store download directory in config file |
333 | cfg.writeEntry( "downloadDir", dir ); | 333 | cfg.writeEntry( "downloadDir", dir ); |
334 | #endif | 334 | #endif |
335 | 335 | ||
336 | // Get starting directory | 336 | // Get starting directory |
337 | char initDir[PATH_MAX]; | 337 | char initDir[PATH_MAX]; |
338 | getcwd( initDir, PATH_MAX ); | 338 | getcwd( initDir, PATH_MAX ); |
339 | 339 | ||
340 | // Download each package | 340 | // Download each package |
341 | Ipkg ipkg; | 341 | Ipkg ipkg; |
342 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); | 342 | connect( &ipkg, SIGNAL(outputText(const QString &)), this, SLOT(displayText(const QString &))); |
343 | 343 | ||
344 | ipkg.setOption( "download" ); | 344 | ipkg.setOption( "download" ); |
345 | ipkg.setRuntimeDirectory( dir ); | 345 | ipkg.setRuntimeDirectory( dir ); |
346 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 346 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
347 | item != 0 ; | 347 | item != 0 ; |
348 | item = (QCheckListItem *)item->nextSibling() ) | 348 | item = (QCheckListItem *)item->nextSibling() ) |
349 | { | 349 | { |
350 | if ( item->isOn() ) | 350 | if ( item->isOn() ) |
351 | { | 351 | { |
352 | QString name = item->text(); | 352 | QString name = item->text(); |
353 | int pos = name.find( "*" ); | 353 | int pos = name.find( "*" ); |
354 | name.truncate( pos ); | 354 | name.truncate( pos ); |
355 | 355 | ||
356 | // if (there is a (installed), remove it | 356 | // if (there is a (installed), remove it |
357 | pos = name.find( "(installed)" ); | 357 | pos = name.find( "(installed)" ); |
358 | if ( pos > 0 ) | 358 | if ( pos > 0 ) |
359 | name.truncate( pos - 1 ); | 359 | name.truncate( pos - 1 ); |
360 | 360 | ||
361 | ipkg.setPackage( name ); | 361 | ipkg.setPackage( name ); |
362 | ipkg.runIpkg( ); | 362 | ipkg.runIpkg( ); |
363 | } | 363 | } |
364 | } | 364 | } |
365 | } | 365 | } |
366 | else if ( download->text() == "Remove" ) | 366 | else if ( download->text() == "Remove" ) |
367 | { | 367 | { |
368 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 368 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
369 | item != 0 ; | 369 | item != 0 ; |
370 | item = (QCheckListItem *)item->nextSibling() ) | 370 | item = (QCheckListItem *)item->nextSibling() ) |
371 | { | 371 | { |
372 | if ( item->isOn() ) | 372 | if ( item->isOn() ) |
373 | { | 373 | { |
374 | QString name = item->text(); | 374 | QString name = item->text(); |
375 | int pos = name.find( "*" ); | 375 | int pos = name.find( "*" ); |
376 | name.truncate( pos ); | 376 | name.truncate( pos ); |
377 | 377 | ||
378 | // if (there is a (installed), remove it | 378 | // if (there is a (installed), remove it |
379 | pos = name.find( "(installed)" ); | 379 | pos = name.find( "(installed)" ); |
380 | if ( pos > 0 ) | 380 | if ( pos > 0 ) |
381 | name.truncate( pos - 1 ); | 381 | name.truncate( pos - 1 ); |
382 | 382 | ||
383 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); | 383 | Package *p = dataMgr->getServer( serversList->currentText() )->getPackage( name ); |
384 | QFile f( p->getFilename() ); | 384 | QFile f( p->getFilename() ); |
385 | f.remove(); | 385 | f.remove(); |
386 | } | 386 | } |
387 | } | 387 | } |
388 | } | 388 | } |
389 | 389 | ||
390 | dataMgr->reloadServerData( LOCAL_IPKGS ); | 390 | dataMgr->reloadServerData( LOCAL_IPKGS ); |
391 | serverSelected( -1 ); | 391 | serverSelected( -1 ); |
392 | } | 392 | } |
393 | 393 | ||
394 | 394 | ||
395 | void NetworkPackageManager :: applyChanges() | 395 | void NetworkPackageManager :: applyChanges() |
396 | { | 396 | { |
397 | // Disable buttons to stop silly people clicking lots on them :) | 397 | // Disable buttons to stop silly people clicking lots on them :) |
398 | 398 | ||
399 | // First, write out ipkg_conf file so that ipkg can use it | 399 | // First, write out ipkg_conf file so that ipkg can use it |
400 | dataMgr->writeOutIpkgConf(); | 400 | dataMgr->writeOutIpkgConf(); |
401 | 401 | ||
402 | // Now for each selected item | 402 | // Now for each selected item |
403 | // deal with it | 403 | // deal with it |
404 | 404 | ||
405 | vector<QString> workingPackages; | 405 | vector<QString> workingPackages; |
406 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 406 | for ( QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); |
407 | item != 0 ; | 407 | item != 0 ; |
408 | item = (QCheckListItem *)item->nextSibling() ) | 408 | item = (QCheckListItem *)item->nextSibling() ) |
409 | { | 409 | { |
410 | if ( item->isOn() ) | 410 | if ( item->isOn() ) |
411 | { | 411 | { |
412 | QString p = dealWithItem( item ); | 412 | QString p = dealWithItem( item ); |
413 | workingPackages.push_back( p ); | 413 | workingPackages.push_back( p ); |
414 | } | 414 | } |
415 | } | 415 | } |
416 | 416 | ||
417 | // do the stuff | 417 | // do the stuff |
418 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); | 418 | InstallDlgImpl dlg( workingPackages, dataMgr, this, "Install", true ); |
419 | dlg.showDlg(); | 419 | dlg.showDlg(); |
420 | 420 | ||
421 | // Reload data | 421 | // Reload data |
422 | dataMgr->reloadServerData( LOCAL_SERVER ); | 422 | dataMgr->reloadServerData( LOCAL_SERVER ); |
423 | 423 | ||
424 | dataMgr->reloadServerData( serversList->currentText() ); | 424 | dataMgr->reloadServerData( serversList->currentText() ); |
425 | serverSelected(-1); | 425 | serverSelected(-1); |
426 | 426 | ||
427 | #ifdef QWS | 427 | #ifdef QWS |
428 | // Finally let the main system update itself | 428 | // Finally let the main system update itself |
429 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); | 429 | QCopEnvelope e("QPE/System", "linkChanged(QString)"); |
430 | QString lf = QString::null; | 430 | QString lf = QString::null; |
431 | e << lf; | 431 | e << lf; |
432 | #endif | 432 | #endif |
433 | } | 433 | } |
434 | 434 | ||
435 | // decide what to do - either remove, upgrade or install | 435 | // decide what to do - either remove, upgrade or install |
436 | // Current rules: | 436 | // Current rules: |
437 | // If not installed - install | 437 | // If not installed - install |
438 | // If installed and different version available - upgrade | 438 | // If installed and different version available - upgrade |
439 | // If installed and version up to date - remove | 439 | // If installed and version up to date - remove |
440 | QString NetworkPackageManager :: dealWithItem( QCheckListItem *item ) | 440 | QString NetworkPackageManager :: dealWithItem( QCheckListItem *item ) |
441 | { | 441 | { |
442 | QString name = item->text(); | 442 | QString name = item->text(); |
443 | int pos = name.find( "*" ); | 443 | int pos = name.find( "*" ); |
444 | name.truncate( pos ); | 444 | name.truncate( pos ); |
445 | 445 | ||
446 | // if (there is a (installed), remove it | 446 | // if (there is a (installed), remove it |
447 | pos = name.find( "(installed)" ); | 447 | pos = name.find( "(installed)" ); |
448 | if ( pos > 0 ) | 448 | if ( pos > 0 ) |
449 | name.truncate( pos - 1 ); | 449 | name.truncate( pos - 1 ); |
450 | 450 | ||
451 | // Get package | 451 | // Get package |
452 | Server *s = dataMgr->getServer( serversList->currentText() ); | 452 | Server *s = dataMgr->getServer( serversList->currentText() ); |
453 | Package *p = s->getPackage( name ); | 453 | Package *p = s->getPackage( name ); |
454 | 454 | ||
455 | // If the package has a filename then it is a local file | 455 | // If the package has a filename then it is a local file |
456 | if ( p->isPackageStoredLocally() ) | 456 | if ( p->isPackageStoredLocally() ) |
457 | name = p->getFilename(); | 457 | name = p->getFilename(); |
458 | QString option; | 458 | QString option; |
459 | QString dest = "root"; | 459 | QString dest = "root"; |
460 | if ( !p->isInstalled() ) | 460 | if ( !p->isInstalled() ) |
461 | return QString( "I" ) + name; | 461 | return QString( "I" ) + name; |
462 | else | 462 | else |
463 | { | 463 | { |
464 | if ( p->getVersion() == p->getInstalledVersion() ) | 464 | if ( p->getVersion() == p->getInstalledVersion() ) |
465 | { | 465 | { |
466 | QString msgtext; | 466 | QString msgtext; |
467 | msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); | 467 | msgtext.sprintf( "Do you wish to remove or reinstall\n%s?", (const char *)name ); |
468 | switch( QMessageBox::information( this, "Remove or ReInstall", | 468 | switch( QMessageBox::information( this, "Remove or ReInstall", |
469 | msgtext, "Remove", "ReInstall" ) ) | 469 | msgtext, "Remove", "ReInstall" ) ) |
470 | { | 470 | { |
471 | case 0: // Try again or Enter | 471 | case 0: // Try again or Enter |
472 | return QString( "D" ) + name; | 472 | return QString( "D" ) + name; |
473 | break; | 473 | break; |
474 | case 1: // Quit or Escape | 474 | case 1: // Quit or Escape |
475 | return QString( "U" ) + name; | 475 | return QString( "U" ) + name; |
476 | break; | 476 | break; |
477 | } | 477 | } |
478 | 478 | ||
479 | // User hit cancel (on dlg - assume remove) | 479 | // User hit cancel (on dlg - assume remove) |
480 | return QString( "D" ) + name; | 480 | return QString( "D" ) + name; |
481 | } | 481 | } |
482 | else | 482 | else |
483 | return QString( "U" ) + name; | 483 | return QString( "U" ) + name; |
484 | } | 484 | } |
485 | } | 485 | } |
486 | 486 | ||
487 | void NetworkPackageManager :: displayText( const QString &t ) | 487 | void NetworkPackageManager :: displayText( const QString &t ) |
488 | { | 488 | { |
489 | cout << t << endl; | 489 | cout << t << endl; |
490 | } | 490 | } |
491 | 491 | ||
492 | 492 | ||
493 | void NetworkPackageManager :: letterPushed( QString t ) | 493 | void NetworkPackageManager :: letterPushed( QString t ) |
494 | { | 494 | { |
495 | QCheckListItem *item = (QCheckListItem *)packagesList->firstChild(); | 495 | QCheckListItem *top = (QCheckListItem *)packagesList->firstChild(); |
496 | QCheckListItem *start = (QCheckListItem *)packagesList->currentItem(); | ||
497 | if ( packagesList->firstChild() == 0 ) | ||
498 | return; | ||
499 | |||
500 | QCheckListItem *item; | ||
501 | if ( start == 0 ) | ||
502 | { | ||
503 | item = (QCheckListItem *)packagesList->firstChild(); | ||
504 | start = top; | ||
505 | } | ||
506 | else | ||
507 | item = (QCheckListItem *)start->nextSibling(); | ||
508 | |||
509 | if ( item == 0 ) | ||
510 | item = (QCheckListItem *)packagesList->firstChild(); | ||
496 | do | 511 | do |
497 | { | 512 | { |
498 | if ( item->text().lower().startsWith( t.lower() ) ) | 513 | if ( item->text().lower().startsWith( t.lower() ) ) |
499 | { | 514 | { |
500 | cout << "Found - item->text()" << endl; | ||
501 | packagesList->setSelected( item, true ); | 515 | packagesList->setSelected( item, true ); |
502 | packagesList->ensureItemVisible( item ); | 516 | packagesList->ensureItemVisible( item ); |
503 | break; | 517 | break; |
504 | } | 518 | } |
505 | 519 | ||
506 | item = (QCheckListItem *)item->nextSibling(); | 520 | item = (QCheckListItem *)item->nextSibling(); |
507 | } while ( item ); | 521 | if ( !item ) |
522 | item = (QCheckListItem *)packagesList->firstChild(); | ||
523 | } while ( item != start); | ||
508 | } | 524 | } |