[bt-devel] RFC: Remove modules installed by the native package manager

Sveinung Kvilhaugsvik sveinung84 at users.sourceforge.net
Mon Apr 27 11:23:04 MST 2009


made it possible to remove modules installed by the system's package
manager if it supports PackageKit

=== modified file 'ChangeLog'
--- ChangeLog	2009-04-27 14:36:24 +0000
+++ ChangeLog	2009-04-27 14:53:58 +0000
@@ -1,6 +1,8 @@
 2009-04-27 Sveinung Kvilhaugsvik <sveinung84 at users.sourceforge.net>
     * Made cmake detect PackageKit
     * Added run time detection for PackageKit
+    * made it possible to remove modules installed by the systems
+      package manager if it supports PackageKit

 2009-04-26 Gary Holmlund
 	* Fix clicking of links in the Mag Window.

=== modified file 'src/frontend/bookshelfmanager/removepage/btremovepage.cpp'
--- src/frontend/bookshelfmanager/removepage/btremovepage.cpp	2009-04-27
14:36:24 +0000
+++ src/frontend/bookshelfmanager/removepage/btremovepage.cpp	2009-04-27
14:53:58 +0000
@@ -165,6 +165,37 @@
 			Client::instance()->setLocale(QLocale::system().name() );
 		    }
 		};
+
+		if (canUsePackageKit) {
+		    QList<CSwordModuleInfo*> alreadyDeleted;
+
+		    Client::Filters filter = Client::Filters() << Client::FilterInstalled;
+		    foreach ( CSwordModuleInfo* mInfo, toBeDeleted ) {
+			packageFoundGuard.lock();
+			packageFound = false;
+			PackageKit::Transaction *transaction =
Client::instance()->searchFile(mInfo->config(CSwordModuleInfo::AbsoluteDataPath)
, filter );
+			connect(transaction, SIGNAL(package(PackageKit::Package*)), this,
SLOT(slotModulePackaged(PackageKit::Package*)));
+			connect(transaction,
SIGNAL(finished(PackageKit::Transaction::ExitStatus, uint)), this,
SLOT(slotSearchFinished()));
+			packageFoundGuard.unlock();
+			waitForSearch.exec();
+			packageFoundGuard.lock();
+			if (packageFound) {
+			    alreadyDeleted.append(mInfo);
+			}
+			packageFoundGuard.unlock();
+		    }
+
+		    if (!toRemove.isEmpty()) {
+			PackageKit::Client::instance()->removePackages(toRemove);
+		    }
+		    toRemove.clear();
+
+		    // ensured that Sword won't remove modules PackageKit are removing
+		    foreach ( CSwordModuleInfo* mInfo, alreadyDeleted ) {
+			toBeDeleted.removeAll(mInfo);
+		    }
+		    qDeleteAll(alreadyDeleted);
+		}
 #endif

 		sword::InstallMgr installMgr;
@@ -243,3 +274,16 @@
 {
 	populateModuleList();
 }
+
+#ifdef PackageKitFound
+void BtRemovePage::slotModulePackaged(PackageKit::Package* package) {
+	packageFoundGuard.lock();
+	packageFound = true;
+	toRemove.append(package);
+	packageFoundGuard.unlock();
+}
+
+void BtRemovePage::slotSearchFinished() {
+	waitForSearch.quit();
+}
+#endif

=== modified file 'src/frontend/bookshelfmanager/removepage/btremovepage.h'
--- src/frontend/bookshelfmanager/removepage/btremovepage.h	2009-04-27
14:36:24 +0000
+++ src/frontend/bookshelfmanager/removepage/btremovepage.h	2009-04-27
14:53:58 +0000
@@ -56,6 +56,10 @@
 	/** Handles activating the Remove button. */
 	void slotSelectionChanged(QTreeWidgetItem* item, int column);
 	void slotItemDoubleClicked(QTreeWidgetItem* item, int column);
+#ifdef PackageKitFound
+	void slotModulePackaged(PackageKit::Package*);
+	void slotSearchFinished();
+#endif

 private: // methods
 	void addToTree(BTModuleTreeItem* item, QTreeWidgetItem* widgetItem);
@@ -65,6 +69,12 @@
 	QPushButton* m_removeButton;
 	/** Map of module name and install path (absolute path from the
moduleinfo config entry).*/
 	QList<CSwordModuleInfo*> m_selectedModules;
+#ifdef PackageKitFound
+	bool packageFound;
+	QMutex packageFoundGuard;
+	QList<PackageKit::Package*> toRemove;
+	QEventLoop waitForSearch;
+#endif
 	
 };



More information about the bt-devel mailing list