[rkward-cvs] SF.net SVN: rkward:[3123] trunk/rkward/rkward/settings/ rksettingsmoduleplugins.cpp

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Oct 14 12:17:44 UTC 2010


Revision: 3123
          http://rkward.svn.sourceforge.net/rkward/?rev=3123&view=rev
Author:   tfry
Date:     2010-10-14 12:17:43 +0000 (Thu, 14 Oct 2010)

Log Message:
-----------
Work-around for old versions staying around after installing an updated plugin-pack.

Modified Paths:
--------------
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2010-10-14 08:25:21 UTC (rev 3122)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2010-10-14 12:17:43 UTC (rev 3123)
@@ -111,9 +111,8 @@
 	connect (map_choser, SIGNAL (listChanged ()), this, SLOT (settingChanged ()));
 	main_vbox->addWidget (map_choser);
 
-#warning REMEMBER TO CLEAN UP
 	main_vbox->addSpacing (2*RKGlobals::spacingHint ());
-	button = new QPushButton ("Push me, Meik", this);
+	button = new QPushButton (i18n ("Install or uninstall add-on plugin packs"), this);
 	main_vbox->addWidget (button);
 	connect (button, SIGNAL (clicked()), this, SLOT (downloadPlugins()));
 
@@ -228,6 +227,18 @@
 	QString basename = baseNameOfPluginPack (archive_file);
 	if (basename.isEmpty ()) return;
 
+	// remove any old versions of the same plugin. Unfortunately, KNewStuff does not clean up when installing updates.
+	QFileInfo archive_file_info (archive_file);
+	QFileInfo base_file_info (basename);
+	QDir base_dir = base_file_info.absoluteDir ();
+	QString base_filename = base_file_info.fileName ();
+	QStringList old_versions = base_dir.entryList (QDir::Files).filter (QRegExp ("^" + base_filename + "(-.*)?\\.(tar\\.gz|\\zip)$"));
+	foreach (const QString old_version, old_versions) {
+		if (old_version != archive_file_info.fileName ()) QFile::remove (base_dir.absoluteFilePath (old_version));
+	}
+	// finally, remove the previous unpacked installation, if any, to make sure we have a clean install
+	if (QDir().exists (basename)) KIO::del (KUrl::fromLocalFile (basename))->exec ();
+
 	KArchive* archive;
 	if (archive_file.endsWith (".zip", Qt::CaseInsensitive)) {
 		archive = new KZip (archive_file);
@@ -261,12 +272,24 @@
 QString RKSettingsModulePlugins::baseNameOfPluginPack (const QString &archive_file) {
 	RK_TRACE (SETTINGS);
 
-	if (archive_file.endsWith (".tar.gz", Qt::CaseInsensitive)) {
-		return (archive_file.left (archive_file.length () - 7));
-	} else if (archive_file.endsWith (".zip", Qt::CaseInsensitive)) {
-		return (archive_file.left (archive_file.length () - 4));
+	QFileInfo file_info (archive_file);
+	QDir dir = file_info.absoluteDir ();
+	QString name = file_info.fileName ();
+
+	// strip file-type ending
+	if (name.endsWith (".tar.gz", Qt::CaseInsensitive)) {
+		name = name.left (name.length () - 7);
+	} else if (name.endsWith (".zip", Qt::CaseInsensitive)) {
+		name = name.left (name.length () - 4);
+	} else {
+		return QString ();
 	}
-	return QString ();
+
+	// strip version (if any)
+	int where = name.indexOf ("-", 1);	// must have at least one char of name before version string
+	if (where > 0) name = name.left (where);
+
+	return dir.absoluteFilePath (name);
 }
 
 QStringList RKSettingsModulePlugins::findPluginMapsRecursive (const QString &basedir) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list