Skip to content
Browse files

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.
  • Loading branch information...
1 parent 950d9cf commit 26c7c829fed3423dbf93b7ce1a740dc12d3ef2e4 @kmoore134 kmoore134 committed
View
1 src-qt4/pc-pkgmanager/dialogConfirm.cpp
@@ -27,6 +27,7 @@ void dialogConfirm::setInfoText(QString text)
void dialogConfirm::slotCancel()
{
+ emit cancel();
close();
}
View
1 src-qt4/pc-pkgmanager/dialogConfirm.h
@@ -32,6 +32,7 @@ private slots:
signals:
void ok();
+ void cancel();
} ;
#endif // DIALOGCONFIRM_H
View
132 src-qt4/pc-pkgmanager/mainWin.cpp
@@ -38,6 +38,7 @@ void mainWin::ProgramInit(QString ch)
connect(pushPkgApply, SIGNAL( clicked() ), this, SLOT( slotApplyClicked() ) );
connect(action_Quit, SIGNAL( triggered(bool) ), this, SLOT( slotCloseClicked() ) );
connect(action_Configuration, SIGNAL( triggered(bool) ), this, SLOT( slotConfigClicked() ) );
+ connect(action_Cleanup_Packages, SIGNAL( triggered(bool) ), this, SLOT( slotPackageCleanupClicked() ) );
connect(tool_search, SIGNAL( clicked() ), this, SLOT( slotSearchPackages() ) );
connect(line_search, SIGNAL( returnPressed()), this, SLOT( slotSearchPackages()) );
@@ -81,6 +82,43 @@ void mainWin::ProgramInit(QString ch)
textDisplayOut->setPalette(palette);
}
+void mainWin::slotPackageCleanupClicked()
+{
+ if(QMessageBox::Yes == QMessageBox::question(this,tr("Package Cleanup"),tr("Do you want to start package cleanup?"),QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) ){
+ doPackageCleanup();
+ }
+}
+
+void mainWin::doPackageCleanup()
+{
+ dPackages = false;
+ uPackages = false;
+
+ // Set the type of pkg command
+ pkgProcessType="cleanupinit";
+ pkgCleanupList.clear();
+
+ // Init the pkg process
+ prepPkgProcess();
+
+ // Create our runlist of package commands
+ QStringList pCmds;
+
+ if ( wDir.isEmpty() )
+ pCmds << "pkg-static" << "autoremove" << "-n";
+ else
+ pCmds << "chroot" << wDir << "pkg-static" << "autoremove" << "-n";
+
+ // Setup our runList
+ pkgCmdList << pCmds;
+
+ // Start the updating now
+ startPkgProcess();
+
+ textStatus->setText(tr("Starting package cleanup..."));
+
+}
+
void mainWin::slotViewChanged()
{
QString mode;
@@ -391,8 +429,16 @@ void mainWin::startPkgProcess() {
uProc->setProcessChannelMode(QProcess::MergedChannels);
// Connect the slots
- connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgOutput()) );
- connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgDone()) );
+ if ( pkgProcessType == "cleanupinit" ) {
+ connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgCleanupOutput()) );
+ connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgCleanupDone()) );
+ } else if ( pkgProcessType == "cleanup" ) {
+ connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgCleanupOutput()) );
+ connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgDone()) );
+ } else {
+ connect( uProc, SIGNAL(readyReadStandardOutput()), this, SLOT(slotReadPkgOutput()) );
+ connect( uProc, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(slotPkgDone()) );
+ }
uProc->start(cmd, flags);
@@ -403,6 +449,88 @@ void mainWin::startPkgProcess() {
}
+void mainWin::slotCleanupOK()
+{
+ // Create our runlist of package commands
+ QStringList pCmds;
+
+ if ( wDir.isEmpty() )
+ pCmds << "pkg-static" << "autoremove" << "-y";
+ else
+ pCmds << "chroot" << wDir << "pkg-static" << "autoremove" << "-y";
+
+ // Setup our runList
+ pkgCmdList << pCmds;
+
+ // Start the real cleanup now
+ pkgProcessType="cleanup";
+
+ // Run the next command
+ slotPkgDone();
+}
+
+void mainWin::slotPkgCleanupDone()
+{
+ // Ask the user if they indeed want to remove these packages
+ askUserConfirm = new dialogConfirm();
+ connect(askUserConfirm, SIGNAL(ok()),this, SLOT(slotCleanupOK()) );
+ connect(askUserConfirm, SIGNAL(cancel()),this, SLOT(slotPkgDone()) );
+ askUserConfirm->programInit(tr("Package Cleanup"));
+ askUserConfirm->setInfoText(tr("The following packages will be removed. Continue?") + "\n\n" + pkgCleanupList.join("\n"));
+ askUserConfirm->exec();
+}
+
+void mainWin::slotReadPkgCleanupOutput()
+{
+ QString line, tmp;
+
+ if ( pkgProcessType == "cleanupinit" )
+ {
+ while (uProc->canReadLine()) {
+ line = uProc->readLine().simplified();
+ qDebug() << line;
+
+ // Empty line? We can skip it
+ if ( line.isEmpty() )
+ continue;
+
+ tmp = line;
+ tmp.truncate(50);
+
+ // Now show output on GUI
+ textDisplayOut->insertPlainText(line + "\n");
+ textDisplayOut->moveCursor(QTextCursor::End);
+
+ if ( tmp.indexOf("Deinstallation has") != -1 )
+ continue;
+
+ if ( tmp.indexOf("The deinstallation") != -1 )
+ continue;
+
+ // Save a list of packages we will be pruning
+ pkgCleanupList << tmp.simplified();
+ }
+ } else {
+ while (uProc->canReadLine()) {
+ line = uProc->readLine().simplified();
+ qDebug() << line;
+
+ // Empty line? We can skip it
+ if ( line.isEmpty() )
+ continue;
+
+ tmp = line;
+ tmp.truncate(50);
+
+ // Now show output on GUI
+ textDisplayOut->insertPlainText(line + "\n");
+ textDisplayOut->moveCursor(QTextCursor::End);
+
+ }
+ }
+
+}
+
void mainWin::slotReadPkgOutput() {
QString line, tmp, cur, tot, fname;
int curItem, totItem;
View
9 src-qt4/pc-pkgmanager/mainWin.h
@@ -84,6 +84,12 @@ private slots:
void slotConfigClicked();
void slotConfigFinished();
+ // User wants to do package cleanup
+ void slotPackageCleanupClicked();
+ void slotReadPkgCleanupOutput();
+ void slotPkgCleanupDone();
+ void slotCleanupOK();
+
private:
// Generic pkg process handlers
void prepPkgProcess();
@@ -111,6 +117,9 @@ private slots:
QString lastError;
QSocketNotifier *eSock;
+ // Start the package cleanup process
+ void doPackageCleanup();
+ QStringList pkgCleanupList;
// Meta-Packages
void initMetaWidget();
View
11 src-qt4/pc-pkgmanager/mainWin.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>913</width>
- <height>644</height>
+ <height>649</height>
</rect>
</property>
<property name="windowTitle">
@@ -434,13 +434,15 @@ p, li { white-space: pre-wrap; }
<x>0</x>
<y>0</y>
<width>913</width>
- <height>21</height>
+ <height>25</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;File</string>
</property>
+ <addaction name="action_Cleanup_Packages"/>
+ <addaction name="separator"/>
<addaction name="action_Quit"/>
</widget>
<widget class="QMenu" name="menu_View">
@@ -509,6 +511,11 @@ p, li { white-space: pre-wrap; }
<string>Shift+S</string>
</property>
</action>
+ <action name="action_Cleanup_Packages">
+ <property name="text">
+ <string>&amp;Cleanup Packages</string>
+ </property>
+ </action>
</widget>
<resources>
<include location="pc-pkgmanager.qrc"/>

0 comments on commit 26c7c82

Please sign in to comment.
Something went wrong with that request. Please try again.