Ignore:
Timestamp:
03/12/14 01:23:07 (4 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, releng/10.0.2
Children:
537479b1, 37d4a8c
Parents:
950d9cf
Message:

Add new "Package cleanup" functionality to package manager. This
will run 'pkg autoremove' and do cleanup of packages no longer
needed.

This needs some testing still.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/pc-pkgmanager/mainWin.cpp

    rd18dfae r26c7c82  
    3939  connect(action_Quit, SIGNAL( triggered(bool) ), this, SLOT( slotCloseClicked() ) ); 
    4040  connect(action_Configuration, SIGNAL( triggered(bool) ), this, SLOT( slotConfigClicked() ) ); 
     41  connect(action_Cleanup_Packages, SIGNAL( triggered(bool) ), this, SLOT( slotPackageCleanupClicked() ) ); 
    4142  connect(tool_search, SIGNAL( clicked() ), this, SLOT( slotSearchPackages() ) ); 
    4243  connect(line_search, SIGNAL( returnPressed()), this, SLOT( slotSearchPackages()) ); 
     
    8081  palette.setColor(QPalette::Text, Qt::white); 
    8182  textDisplayOut->setPalette(palette); 
     83} 
     84 
     85void mainWin::slotPackageCleanupClicked() 
     86{ 
     87  if(QMessageBox::Yes == QMessageBox::question(this,tr("Package Cleanup"),tr("Do you want to start package cleanup?"),QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ){ 
     88    doPackageCleanup(); 
     89  } 
     90} 
     91 
     92void mainWin::doPackageCleanup() 
     93{ 
     94  dPackages = false; 
     95  uPackages = false; 
     96 
     97  // Set the type of pkg command 
     98  pkgProcessType="cleanupinit"; 
     99  pkgCleanupList.clear(); 
     100 
     101  // Init the pkg process 
     102  prepPkgProcess(); 
     103 
     104  // Create our runlist of package commands 
     105  QStringList pCmds; 
     106 
     107  if ( wDir.isEmpty() ) 
     108    pCmds << "pkg-static" << "autoremove" << "-n"; 
     109  else 
     110    pCmds << "chroot" << wDir << "pkg-static" << "autoremove" << "-n"; 
     111 
     112  // Setup our runList 
     113  pkgCmdList << pCmds; 
     114 
     115  // Start the updating now 
     116  startPkgProcess(); 
     117 
     118  textStatus->setText(tr("Starting package cleanup...")); 
     119 
    82120} 
    83121 
     
    392430 
    393431  // Connect the slots 
    394   connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgOutput()) ); 
    395   connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgDone()) ); 
     432  if ( pkgProcessType == "cleanupinit" ) { 
     433    connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgCleanupOutput()) ); 
     434    connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgCleanupDone()) ); 
     435  } else if ( pkgProcessType == "cleanup" ) { 
     436    connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgCleanupOutput()) ); 
     437    connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgDone()) ); 
     438  } else { 
     439    connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgOutput()) ); 
     440    connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgDone()) ); 
     441  } 
    396442 
    397443  uProc->start(cmd, flags); 
     
    401447  progressUpdate->setRange(0, 0 ); 
    402448  progressUpdate->setValue(0); 
     449 
     450} 
     451 
     452void mainWin::slotCleanupOK() 
     453{ 
     454  // Create our runlist of package commands 
     455  QStringList pCmds; 
     456 
     457  if ( wDir.isEmpty() ) 
     458     pCmds << "pkg-static" << "autoremove" << "-y"; 
     459  else 
     460     pCmds << "chroot" << wDir << "pkg-static" << "autoremove" << "-y"; 
     461 
     462  // Setup our runList 
     463  pkgCmdList << pCmds; 
     464 
     465  // Start the real cleanup now 
     466  pkgProcessType="cleanup"; 
     467 
     468  // Run the next command 
     469  slotPkgDone(); 
     470} 
     471 
     472void mainWin::slotPkgCleanupDone() 
     473{ 
     474   // Ask the user if they indeed want to remove these packages 
     475   askUserConfirm = new dialogConfirm(); 
     476   connect(askUserConfirm, SIGNAL(ok()),this, SLOT(slotCleanupOK()) ); 
     477   connect(askUserConfirm, SIGNAL(cancel()),this, SLOT(slotPkgDone()) ); 
     478   askUserConfirm->programInit(tr("Package Cleanup")); 
     479   askUserConfirm->setInfoText(tr("The following packages will be removed. Continue?") + "\n\n" + pkgCleanupList.join("\n")); 
     480   askUserConfirm->exec(); 
     481} 
     482 
     483void mainWin::slotReadPkgCleanupOutput() 
     484{ 
     485  QString line, tmp; 
     486 
     487  if ( pkgProcessType == "cleanupinit" ) 
     488  { 
     489     while (uProc->canReadLine()) { 
     490       line = uProc->readLine().simplified(); 
     491       qDebug() << line; 
     492 
     493       // Empty line? We can skip it 
     494       if ( line.isEmpty() ) 
     495          continue; 
     496 
     497       tmp = line; 
     498       tmp.truncate(50); 
     499 
     500       // Now show output on GUI 
     501       textDisplayOut->insertPlainText(line + "\n"); 
     502       textDisplayOut->moveCursor(QTextCursor::End); 
     503 
     504       if ( tmp.indexOf("Deinstallation has") != -1 ) 
     505          continue; 
     506 
     507       if ( tmp.indexOf("The deinstallation") != -1 ) 
     508          continue; 
     509 
     510       // Save a list of packages we will be pruning 
     511       pkgCleanupList << tmp.simplified(); 
     512     } 
     513  } else { 
     514     while (uProc->canReadLine()) { 
     515       line = uProc->readLine().simplified(); 
     516       qDebug() << line; 
     517 
     518       // Empty line? We can skip it 
     519       if ( line.isEmpty() ) 
     520          continue; 
     521 
     522       tmp = line; 
     523       tmp.truncate(50); 
     524 
     525       // Now show output on GUI 
     526       textDisplayOut->insertPlainText(line + "\n"); 
     527       textDisplayOut->moveCursor(QTextCursor::End); 
     528 
     529     } 
     530  } 
    403531 
    404532} 
Note: See TracChangeset for help on using the changeset viewer.