[rkward-cvs] SF.net SVN: rkward:[3106] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Tue Oct 5 16:31:24 UTC 2010


Revision: 3106
          http://rkward.svn.sourceforge.net/rkward/?rev=3106&view=rev
Author:   tfry
Date:     2010-10-05 16:31:24 +0000 (Tue, 05 Oct 2010)

Log Message:
-----------
Automatically add / remove pluginmaps after installing / uninstalling plugins

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.h
    trunk/rkward/rkward/settings/rkward.knsrc

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2010-10-05 07:07:39 UTC (rev 3105)
+++ trunk/rkward/ChangeLog	2010-10-05 16:31:24 UTC (rev 3106)
@@ -1,3 +1,5 @@
+- Fixed: Would crash on tcl/tk events in some cases
+
 --- Version 0.5.4 - Oct-04-2010
 - Fixed: Running user commands would crash with R 2.12.0
 - Added full-featured plot history for the onscreen graphics device

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2010-10-05 07:07:39 UTC (rev 3105)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2010-10-05 16:31:24 UTC (rev 3106)
@@ -22,6 +22,9 @@
 #include <kmessagebox.h>
 #include <khbox.h>
 #include <knewstuff2/engine.h>
+#include <ktar.h>
+#include <kzip.h>
+#include <kio/deletejob.h>
 
 #include <qlayout.h>
 #include <qlabel.h>
@@ -74,7 +77,7 @@
 	button_group->addButton (button, PreferWizard);
 	if ((button = button_group->button (interface_pref))) button->setChecked (true);
 
-	connect (button_group, SIGNAL (buttonClicked (int)), this, SLOT (settingChanged (int)));
+	connect (button_group, SIGNAL (buttonClicked (int)), this, SLOT (settingChanged ()));
 	main_vbox->addWidget (button_box);
 
 
@@ -86,14 +89,14 @@
 
 	show_code_box = new QCheckBox (i18n ("Code shown by default"), code_frame);
 	show_code_box->setChecked (show_code);
-	connect (show_code_box, SIGNAL (stateChanged (int)), this, SLOT (settingChanged (int)));
+	connect (show_code_box, SIGNAL (stateChanged (int)), this, SLOT (settingChanged ()));
 	group_layout->addWidget (show_code_box);
 
 	KHBox *code_size_hbox = new KHBox (code_frame);
 	new QLabel (i18n ("Default height of code display (pixels)"), code_size_hbox);
 	code_size_box = new RKSpinBox (code_size_hbox);
 	code_size_box->setIntMode (20, 5000, code_size);
-	connect (code_size_box, SIGNAL (valueChanged (int)), this, SLOT (settingChanged (int)));
+	connect (code_size_box, SIGNAL (valueChanged (int)), this, SLOT (settingChanged ()));
 	group_layout->addWidget (code_size_hbox);
 
 	main_vbox->addWidget (code_frame);
@@ -105,7 +108,7 @@
 	map_choser = new MultiStringSelector (i18n ("Select .pluginmap file(s)"), this);
 	map_choser->setValues (plugin_maps);
 	connect (map_choser, SIGNAL (getNewStrings (QStringList*)), this, SLOT (browseRequest (QStringList*)));
-	connect (map_choser, SIGNAL (listChanged ()), this, SLOT (pathsChanged ()));
+	connect (map_choser, SIGNAL (listChanged ()), this, SLOT (settingChanged ()));
 	main_vbox->addWidget (map_choser);
 
 #warning REMEMBER TO CLEAN UP
@@ -121,16 +124,11 @@
 	RK_TRACE (SETTINGS);
 }
 
-void RKSettingsModulePlugins::pathsChanged () {
+void RKSettingsModulePlugins::settingChanged () {
 	RK_TRACE (SETTINGS);
 	change ();
 }
 
-void RKSettingsModulePlugins::settingChanged (int) {
-	RK_TRACE (SETTINGS);
-	change ();
-}
-
 void RKSettingsModulePlugins::browseRequest (QStringList* strings) {
 	RK_TRACE (SETTINGS);
 
@@ -190,11 +188,102 @@
 void RKSettingsModulePlugins::downloadPlugins () {
 	RK_TRACE (SETTINGS);
 
+	QStringList oldmaps = plugin_maps;
+
+	#warning TODO: temporary hack
+// Some KNS is smart enough to remove the .rkward/plugins director if it is no longer used, but not smart enough to add it back, when needed....
+	QDir::home ().mkpath (".rkward/plugins");
+
 	KNS::Engine engine (0);
-	if (engine.init ("rkward.knsrc")) {
-		engine.downloadDialogModal (this);
+	if (!engine.init ("rkward.knsrc")) return;
+	KNS::Entry::List list = engine.downloadDialogModal (this);
+
+	for (int i = 0; i < list.size (); ++i) {
+		foreach (const QString inst, list[i]->installedFiles ()) {
+			installPluginPack (inst);
+		}
+		foreach (const QString inst, list[i]->uninstalledFiles ()) {
+			uninstallPluginPack (inst);
+		}
 	}
+
+	// new pluginmaps were already added in installPluginPack. Now let's check, whether there's any maps to remove, too:
+	for (int i = 0; i < plugin_maps.size (); ++i) {
+		QFileInfo info (plugin_maps[i]);
+		if (!info.isReadable ()) {
+			plugin_maps.removeAt (i);
+			--i;
+		}
+	}
+
+	if (plugin_maps != oldmaps) {
+		map_choser->setValues (plugin_maps);
+		change ();
+	}
 }
 
+void RKSettingsModulePlugins::installPluginPack (const QString &archive_file) {
+	RK_TRACE (SETTINGS);
 
+	QString basename = baseNameOfPluginPack (archive_file);
+	if (basename.isEmpty ()) return;
+
+	KArchive* archive;
+	if (archive_file.endsWith (".zip", Qt::CaseInsensitive)) {
+		archive = new KZip (archive_file);
+	} else {
+		archive = new KTar (archive_file);
+	}
+	if (!archive->open (QIODevice::ReadOnly)) {
+#warning TODO: show error message
+		RK_ASSERT (false);
+		return;
+	}
+	archive->directory ()->copyTo (basename, true);
+	delete (archive);
+
+	QStringList installed_maps = findPluginMapsRecursive (basename);
+	foreach (const QString map, installed_maps) {
+		if (!plugin_maps.contains (map)) plugin_maps.append (map);
+	}
+}
+
+void RKSettingsModulePlugins::uninstallPluginPack (const QString &archive_file) {
+	RK_TRACE (SETTINGS);
+
+	QString basename = baseNameOfPluginPack (archive_file);
+	if (basename.isEmpty ()) return;
+
+	// Well, calling exec is ugly, but so much simpler than handling this asynchronously...
+	KIO::del (KUrl::fromLocalFile (basename))->exec ();
+}
+
+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));
+	}
+	return QString ();
+}
+
+QStringList RKSettingsModulePlugins::findPluginMapsRecursive (const QString &basedir) {
+	RK_TRACE (SETTINGS);
+
+	QDir dir (basedir);
+	QStringList maps = dir.entryList (QDir::Files).filter (QRegExp (".*\\.pluginmap$"));
+	QStringList ret;
+	foreach (const QString &map, maps) ret.append (dir.absoluteFilePath (map));
+
+	QStringList subdirs = dir.entryList (QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot);
+	foreach (const QString subdir, subdirs) {
+		ret.append (findPluginMapsRecursive (dir.absoluteFilePath (subdir)));
+	}
+
+	return ret;
+}
+
+
 #include "rksettingsmoduleplugins.moc"

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2010-10-05 07:07:39 UTC (rev 3105)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2010-10-05 16:31:24 UTC (rev 3106)
@@ -52,8 +52,7 @@
 	static bool showCodeByDefault () { return show_code; };
 	static int defaultCodeHeight () { return code_size; };
 public slots:
-	void pathsChanged ();
-	void settingChanged (int);
+	void settingChanged ();
 	void browseRequest (QStringList* strings);
 	/** Invoke the plugin download dialog. */
 	void downloadPlugins ();
@@ -67,6 +66,11 @@
 	static PluginPrefs interface_pref;
 	static bool show_code;
 	static int code_size;
+
+	static void installPluginPack (const QString &archive_file);
+	static void uninstallPluginPack (const QString &archive_file);
+	static QString baseNameOfPluginPack (const QString &archive_file);
+	static QStringList findPluginMapsRecursive (const QString &basedir);
 };
 
 #endif

Modified: trunk/rkward/rkward/settings/rkward.knsrc
===================================================================
--- trunk/rkward/rkward/settings/rkward.knsrc	2010-10-05 07:07:39 UTC (rev 3105)
+++ trunk/rkward/rkward/settings/rkward.knsrc	2010-10-05 16:31:24 UTC (rev 3106)
@@ -1,4 +1,4 @@
 [KNewStuff2]
 ProvidersUrl=http://R.reaktanz.de/GHNS/reaktanz-provider.xml
-Uncompress=archive
+Uncompress=never
 InstallPath=.rkward/plugins/


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