author | drw <drw> | 2004-11-17 00:43:35 (UTC) |
---|---|---|
committer | drw <drw> | 2004-11-17 00:43:35 (UTC) |
commit | 718a7a8ba68e10faa1a22fcc6bdc26e1723b2a40 (patch) (unidiff) | |
tree | a6bf4f10db4141ba7098d76d0444bd4d1dd759c1 /noncore/settings/packagemanager/mainwindow.cpp | |
parent | 216434aff5921f3c3c2efc9adb58e653a5d224b3 (diff) | |
download | opie-718a7a8ba68e10faa1a22fcc6bdc26e1723b2a40.zip opie-718a7a8ba68e10faa1a22fcc6bdc26e1723b2a40.tar.gz opie-718a7a8ba68e10faa1a22fcc6bdc26e1723b2a40.tar.bz2 |
Some code clean-up items (thanks to zecke)
Diffstat (limited to 'noncore/settings/packagemanager/mainwindow.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/packagemanager/mainwindow.cpp | 42 |
1 files changed, 16 insertions, 26 deletions
diff --git a/noncore/settings/packagemanager/mainwindow.cpp b/noncore/settings/packagemanager/mainwindow.cpp index 349094d..5e15874 100644 --- a/noncore/settings/packagemanager/mainwindow.cpp +++ b/noncore/settings/packagemanager/mainwindow.cpp | |||
@@ -304,25 +304,25 @@ void MainWindow::searchForPackage( const QString &text ) | |||
304 | m_packageList.ensureItemVisible( item ); | 304 | m_packageList.ensureItemVisible( item ); |
305 | m_packageList.setCurrentItem( item ); | 305 | m_packageList.setCurrentItem( item ); |
306 | break; | 306 | break; |
307 | } | 307 | } |
308 | } | 308 | } |
309 | } | 309 | } |
310 | } | 310 | } |
311 | 311 | ||
312 | void MainWindow::installLocalPackage( const QString &ipkFile ) | 312 | void MainWindow::installLocalPackage( const QString &ipkFile ) |
313 | { | 313 | { |
314 | // Install selected file | 314 | // Install selected file |
315 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Install local package" ), true, | 315 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Install local package" ), true, |
316 | OPackage::Install, new QStringList( ipkFile ) ); | 316 | OPackage::Install, ipkFile ); |
317 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); | 317 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); |
318 | 318 | ||
319 | // Display widget | 319 | // Display widget |
320 | m_widgetStack.addWidget( dlg, 3 ); | 320 | m_widgetStack.addWidget( dlg, 3 ); |
321 | m_widgetStack.raiseWidget( dlg ); | 321 | m_widgetStack.raiseWidget( dlg ); |
322 | } | 322 | } |
323 | 323 | ||
324 | void MainWindow::setDocument( const QString &ipkFile ) | 324 | void MainWindow::setDocument( const QString &ipkFile ) |
325 | { | 325 | { |
326 | QString file = ipkFile; | 326 | QString file = ipkFile; |
327 | DocLnk lnk( ipkFile ); | 327 | DocLnk lnk( ipkFile ); |
328 | if ( lnk.isValid() ) | 328 | if ( lnk.isValid() ) |
@@ -401,35 +401,35 @@ void MainWindow::slotUpgrade() | |||
401 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Upgrade installed packages" ), false, | 401 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Upgrade installed packages" ), false, |
402 | OPackage::Upgrade ); | 402 | OPackage::Upgrade ); |
403 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); | 403 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); |
404 | 404 | ||
405 | // Display widget | 405 | // Display widget |
406 | m_widgetStack.addWidget( dlg, 3 ); | 406 | m_widgetStack.addWidget( dlg, 3 ); |
407 | m_widgetStack.raiseWidget( dlg ); | 407 | m_widgetStack.raiseWidget( dlg ); |
408 | } | 408 | } |
409 | 409 | ||
410 | void MainWindow::slotDownload() | 410 | void MainWindow::slotDownload() |
411 | { | 411 | { |
412 | // Retrieve list of packages selected for download (if any) | 412 | // Retrieve list of packages selected for download (if any) |
413 | QStringList *workingPackages = new QStringList(); | 413 | QStringList workingPackages; |
414 | 414 | ||
415 | for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); | 415 | for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); |
416 | item != 0 ; | 416 | item != 0 ; |
417 | item = static_cast<QCheckListItem *>(item->nextSibling()) ) | 417 | item = static_cast<QCheckListItem *>(item->nextSibling()) ) |
418 | { | 418 | { |
419 | if ( item->isOn() ) | 419 | if ( item->isOn() ) |
420 | workingPackages->append( item->text() ); | 420 | workingPackages.append( item->text() ); |
421 | } | 421 | } |
422 | 422 | ||
423 | if ( workingPackages->isEmpty() ) | 423 | if ( workingPackages.isEmpty() ) |
424 | { | 424 | { |
425 | QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); | 425 | QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); |
426 | return; | 426 | return; |
427 | } | 427 | } |
428 | else | 428 | else |
429 | { | 429 | { |
430 | // Download selected packages | 430 | // Download selected packages |
431 | m_config.setGroup( "settings" ); | 431 | m_config.setGroup( "settings" ); |
432 | QString workingDir = m_config.readEntry( "DownloadDir", "/tmp" ); | 432 | QString workingDir = m_config.readEntry( "DownloadDir", "/tmp" ); |
433 | 433 | ||
434 | bool ok = false; | 434 | bool ok = false; |
435 | QString text = EntryDlg::getText( tr( "Download" ), tr( "Enter path to download package to:" ), workingDir, &ok, this ); | 435 | QString text = EntryDlg::getText( tr( "Download" ), tr( "Enter path to download package to:" ), workingDir, &ok, this ); |
@@ -448,105 +448,95 @@ void MainWindow::slotDownload() | |||
448 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Download packages" ), false, | 448 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Download packages" ), false, |
449 | OPackage::Download, workingPackages ); | 449 | OPackage::Download, workingPackages ); |
450 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); | 450 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); |
451 | 451 | ||
452 | // Display widget | 452 | // Display widget |
453 | m_widgetStack.addWidget( dlg, 3 ); | 453 | m_widgetStack.addWidget( dlg, 3 ); |
454 | m_widgetStack.raiseWidget( dlg ); | 454 | m_widgetStack.raiseWidget( dlg ); |
455 | } | 455 | } |
456 | } | 456 | } |
457 | 457 | ||
458 | void MainWindow::slotApply() | 458 | void MainWindow::slotApply() |
459 | { | 459 | { |
460 | QStringList *removeList = 0x0; | 460 | QStringList removeList; |
461 | QStringList *installList = 0x0; | 461 | QStringList installList; |
462 | QStringList *upgradeList = 0x0; | 462 | QStringList upgradeList; |
463 | 463 | ||
464 | for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); | 464 | for ( QCheckListItem *item = static_cast<QCheckListItem *>(m_packageList.firstChild()); |
465 | item != 0 ; | 465 | item != 0 ; |
466 | item = static_cast<QCheckListItem *>(item->nextSibling()) ) | 466 | item = static_cast<QCheckListItem *>(item->nextSibling()) ) |
467 | { | 467 | { |
468 | if ( item->isOn() ) | 468 | if ( item->isOn() ) |
469 | { | 469 | { |
470 | OPackage *package = m_packman.findPackage( item->text() ); | 470 | OPackage *package = m_packman.findPackage( item->text() ); |
471 | if ( package ) | 471 | if ( package ) |
472 | { | 472 | { |
473 | if ( !package->versionInstalled().isNull() ) | 473 | if ( !package->versionInstalled().isNull() ) |
474 | { | 474 | { |
475 | if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 ) | 475 | if ( m_packman.compareVersions( package->version(), package->versionInstalled() ) == 1 ) |
476 | { | 476 | { |
477 | // Remove/upgrade package | 477 | // Remove/upgrade package |
478 | int answer = PromptDlg::ask( tr( "Remove or upgrade" ), | 478 | int answer = PromptDlg::ask( tr( "Remove or upgrade" ), |
479 | tr( QString( "Do you wish to remove or upgrade\n%1?" ).arg( item->text() ) ), | 479 | tr( QString( "Do you wish to remove or upgrade\n%1?" ).arg( item->text() ) ), |
480 | tr( "Remove" ), tr( "Upgrade" ), this ); | 480 | tr( "Remove" ), tr( "Upgrade" ), this ); |
481 | if ( answer == 1 ) // Remove | 481 | if ( answer == 1 ) // Remove |
482 | { | 482 | { |
483 | if ( !removeList ) | 483 | removeList.append( item->text() ); |
484 | removeList = new QStringList(); | ||
485 | removeList->append( item->text() ); | ||
486 | } | 484 | } |
487 | else if ( answer == 2 ) // Upgrade | 485 | else if ( answer == 2 ) // Upgrade |
488 | { | 486 | { |
489 | if ( !upgradeList ) | 487 | upgradeList.append( item->text() ); |
490 | upgradeList = new QStringList(); | ||
491 | upgradeList->append( item->text() ); | ||
492 | } | 488 | } |
493 | } | 489 | } |
494 | else | 490 | else |
495 | { | 491 | { |
496 | // Remove/reinstall package | 492 | // Remove/reinstall package |
497 | int answer = PromptDlg::ask( tr( "Remove or reinstall" ), | 493 | int answer = PromptDlg::ask( tr( "Remove or reinstall" ), |
498 | tr( QString( "Do you wish to remove or reinstall\n%1?" ).arg( item->text() ) ), | 494 | tr( QString( "Do you wish to remove or reinstall\n%1?" ).arg( item->text() ) ), |
499 | tr( "Remove" ), tr( "Reinstall" ), this ); | 495 | tr( "Remove" ), tr( "Reinstall" ), this ); |
500 | if ( answer == 1 ) // Remove | 496 | if ( answer == 1 ) // Remove |
501 | { | 497 | { |
502 | if ( !removeList ) | 498 | removeList.append( item->text() ); |
503 | removeList = new QStringList(); | ||
504 | removeList->append( item->text() ); | ||
505 | } | 499 | } |
506 | else if ( answer == 2 ) // Reinstall | 500 | else if ( answer == 2 ) // Reinstall |
507 | { | 501 | { |
508 | if ( !installList ) | 502 | installList.append( item->text() ); |
509 | installList = new QStringList(); | ||
510 | installList->append( item->text() ); | ||
511 | } | 503 | } |
512 | } | 504 | } |
513 | } | 505 | } |
514 | else | 506 | else |
515 | { | 507 | { |
516 | // Install package | 508 | // Install package |
517 | if ( !installList ) | 509 | installList.append( item->text() ); |
518 | installList = new QStringList(); | ||
519 | installList->append( item->text() ); | ||
520 | } | 510 | } |
521 | } | 511 | } |
522 | } | 512 | } |
523 | } | 513 | } |
524 | 514 | ||
525 | // If nothing is selected, display message and exit | 515 | // If nothing is selected, display message and exit |
526 | if ( !removeList && !installList && !upgradeList ) | 516 | if ( removeList.isEmpty() && installList.isEmpty() && upgradeList.isEmpty() ) |
527 | { | 517 | { |
528 | QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); | 518 | QMessageBox::information( this, tr( "Nothing to do" ), tr( "No packages selected" ), tr( "OK" ) ); |
529 | return; | 519 | return; |
530 | } | 520 | } |
531 | 521 | ||
532 | // Send command only if there are packages to process | 522 | // Send command only if there are packages to process |
533 | OPackage::Command removeCmd = OPackage::NotDefined; | 523 | OPackage::Command removeCmd = OPackage::NotDefined; |
534 | if ( removeList && !removeList->isEmpty() ) | 524 | if ( !removeList.isEmpty() ) |
535 | removeCmd = OPackage::Remove; | 525 | removeCmd = OPackage::Remove; |
536 | OPackage::Command installCmd = OPackage::NotDefined; | 526 | OPackage::Command installCmd = OPackage::NotDefined; |
537 | if ( installList && !installList->isEmpty() ) | 527 | if ( !installList.isEmpty() ) |
538 | installCmd = OPackage::Install; | 528 | installCmd = OPackage::Install; |
539 | OPackage::Command upgradeCmd = OPackage::NotDefined; | 529 | OPackage::Command upgradeCmd = OPackage::NotDefined; |
540 | if ( upgradeList && !upgradeList->isEmpty() ) | 530 | if ( !upgradeList.isEmpty() ) |
541 | upgradeCmd = OPackage::Upgrade; | 531 | upgradeCmd = OPackage::Upgrade; |
542 | 532 | ||
543 | // Create package manager output widget | 533 | // Create package manager output widget |
544 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Apply changes" ), true, | 534 | InstallDlg *dlg = new InstallDlg( this, &m_packman, tr( "Apply changes" ), true, |
545 | removeCmd, removeList, | 535 | removeCmd, removeList, |
546 | installCmd, installList, | 536 | installCmd, installList, |
547 | upgradeCmd, upgradeList ); | 537 | upgradeCmd, upgradeList ); |
548 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); | 538 | connect( dlg, SIGNAL(closeInstallDlg()), this, SLOT(slotCloseDlg()) ); |
549 | 539 | ||
550 | // Display widget | 540 | // Display widget |
551 | m_widgetStack.addWidget( dlg, 3 ); | 541 | m_widgetStack.addWidget( dlg, 3 ); |
552 | m_widgetStack.raiseWidget( dlg ); | 542 | m_widgetStack.raiseWidget( dlg ); |