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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Fri Sep 9 07:28:47 UTC 2011


Revision: 3732
          http://rkward.svn.sourceforge.net/rkward/?rev=3732&view=rev
Author:   tfry
Date:     2011-09-09 07:28:46 +0000 (Fri, 09 Sep 2011)
Log Message:
-----------
Check for new RKWard plugin maps among R packages, and install any maps which have not previously been deactivated by the user.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
    trunk/rkward/rkward/rbackend/rinterface.cpp
    trunk/rkward/rkward/rbackend/rinterface.h
    trunk/rkward/rkward/rbackend/rksessionvars.cpp
    trunk/rkward/rkward/rbackend/rksessionvars.h
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
    trunk/rkward/rkward/settings/rksettingsmoduleplugins.h

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/ChangeLog	2011-09-09 07:28:46 UTC (rev 3732)
@@ -1,5 +1,6 @@
+- Added support for RKWard plugins shipped inside R packages 
 - Fixed: PDFs and many other types of documents linked from help pages would not be opened, correctly
-- Add support R 2.14.x
+- Added support R 2.14.x
 - Removed option to set options("printcmd")
 - New option to run arbitrary (setup) commands in each session
 - Added new pseudo graphics device "rk.printer.device" to provide printing via the KDE printer dialog

Modified: trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp
===================================================================
--- trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/rkward/dialogs/rkloadlibsdialog.cpp	2011-09-09 07:28:46 UTC (rev 3732)
@@ -397,7 +397,9 @@
 	installed_view->clear ();
 	loaded_view->clear ();
 
-	RKGlobals::rInterface ()->issueCommand (".rk.get.installed.packages ()", RCommand::App | RCommand::Sync | RCommand::GetStructuredData, QString::null, this, GET_INSTALLED_PACKAGES, parent->chain);
+	RCommand *c = new RCommand (".rk.get.installed.packages ()", RCommand::App | RCommand::Sync | RCommand::GetStructuredData, QString::null, this, GET_INSTALLED_PACKAGES);
+	connect (c->notifier (), SIGNAL (commandFinished(RCommand*)), RKGlobals::rInterface (), SLOT (installedPackagesCommandFinished(RCommand*)));
+	RKGlobals::rInterface ()->issueCommand (c, parent->chain);
 	RKGlobals::rInterface ()->issueCommand (".packages ()", RCommand::App | RCommand::Sync | RCommand::GetStringVector, QString::null, this, GET_LOADED_PACKAGES, parent->chain);
 }
 

Modified: trunk/rkward/rkward/rbackend/rinterface.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.cpp	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/rkward/rbackend/rinterface.cpp	2011-09-09 07:28:46 UTC (rev 3732)
@@ -25,6 +25,7 @@
 #include "../settings/rksettingsmodulegeneral.h"
 #include "../settings/rksettingsmoduleoutput.h"
 #include "../settings/rksettingsmodulegraphics.h"
+#include "../settings/rksettingsmoduleplugins.h"
 #include "../settings/rksettingsmoduledebug.h"
 #include "../core/robjectlist.h"
 #include "../core/renvironmentobject.h"
@@ -103,10 +104,15 @@
 	// create a fake init command
 	RCommand *fake = new RCommand (i18n ("R Startup"), RCommand::App | RCommand::Sync | RCommand::ObjectListUpdate, i18n ("R Startup"), this, STARTUP_PHASE2_COMPLETE);
 	issueCommand (fake);
+
 	new RKSessionVars (this);
-
 	new RKRBackendProtocolFrontend (this);
 	RKRBackendProtocolFrontend::instance ()->setupBackend ();
+
+	// Further initialization commands, which do not necessarily have to run before everything else can be queued, here.
+	RCommand *c = new RCommand (".rk.get.installed.packages()", RCommand::App | RCommand::Sync | RCommand::GetStructuredData);
+	connect (c->notifier (), SIGNAL (commandFinished(RCommand*)), this, SLOT (installedPackagesCommandFinished(RCommand*)));
+	issueCommand (c);
 }
 
 void RInterface::issueCommand (const QString &command, int type, const QString &rk_equiv, RCommandReceiver *receiver, int flags, RCommandChain *chain) {
@@ -247,6 +253,24 @@
 	command_requests.pop_back ();
 }
 
+void RInterface::installedPackagesCommandFinished (RCommand *command) {
+	RK_TRACE (RBACKEND);
+
+	if (command->succeeded () && (command->getDataType () == RData::StructureVector) && (command->getDataLength() >= 6)) {
+		RData *dummy = command->getStructureVector ()[0];
+		if (dummy->getDataType () == RData::StringVector) RKSessionVars::instance ()->setInstalledPackages (dummy->getStringVector ());
+		else RK_ASSERT (false);
+
+		dummy = command->getStructureVector ()[5];
+		if (dummy->getDataType () == RData::StringVector) RKSettingsModulePlugins::registerPluginMaps (dummy->getStringVector ());
+		else RK_ASSERT (false);
+
+		return;
+	}
+
+	RK_ASSERT (false);
+}
+
 void RInterface::rCommandDone (RCommand *command) {
 	RK_TRACE (RBACKEND);
 

Modified: trunk/rkward/rkward/rbackend/rinterface.h
===================================================================
--- trunk/rkward/rkward/rbackend/rinterface.h	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/rkward/rbackend/rinterface.h	2011-09-09 07:28:46 UTC (rev 3732)
@@ -75,6 +75,9 @@
 	bool backendIsIdle ();
 	static bool isNaReal (double value) { return na_real == value; };
 	static bool isNaInt (int value) { return na_int == value; };
+public slots:
+/** Public for hacky reasons. Can be connected to .rk.get.installed.packages() */
+	void installedPackagesCommandFinished (RCommand *command);
 private:
 	void timerEvent (QTimerEvent *);
 	int flush_timer_id;

Modified: trunk/rkward/rkward/rbackend/rksessionvars.cpp
===================================================================
--- trunk/rkward/rkward/rbackend/rksessionvars.cpp	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/rkward/rbackend/rksessionvars.cpp	2011-09-09 07:28:46 UTC (rev 3732)
@@ -28,10 +28,6 @@
 	RK_ASSERT (!_instance);
 
 	_instance = this;
-
-	RCommand *initc = new RCommand (".rk.get.installed.packages()[[1]]", RCommand::App | RCommand::Sync | RCommand::GetStringVector);
-	connect (initc->notifier (), SIGNAL (commandFinished(RCommand*)), this, SLOT (installedPackagesCommandFinished(RCommand*)));
-	parent->issueCommand (initc);
 }
 
 RKSessionVars::~RKSessionVars () {
@@ -45,15 +41,4 @@
 	emit (installedPackagesChanged ());
 }
 
-void RKSessionVars::installedPackagesCommandFinished (RCommand *command) {
-	RK_TRACE (RBACKEND);
-
-	if (command->succeeded () && (command->getDataType () == RData::StringVector)) {
-		setInstalledPackages (command->getStringVector ());
-		return;
-	}
-
-	RK_ASSERT (false);
-}
-
 #include "rksessionvars.moc"

Modified: trunk/rkward/rkward/rbackend/rksessionvars.h
===================================================================
--- trunk/rkward/rkward/rbackend/rksessionvars.h	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/rkward/rbackend/rksessionvars.h	2011-09-09 07:28:46 UTC (rev 3732)
@@ -41,8 +41,6 @@
 	static RKSessionVars* _instance;
 
 	QStringList installed_packages;
-private slots:
-	void installedPackagesCommandFinished (RCommand *command);
 };
 
 #endif

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.cpp	2011-09-09 07:28:46 UTC (rev 3732)
@@ -50,6 +50,7 @@
 
 // static members
 QStringList RKSettingsModulePlugins::plugin_maps;
+QStringList RKSettingsModulePlugins::known_plugin_maps;
 RKSettingsModulePlugins::PluginPrefs RKSettingsModulePlugins::interface_pref;
 bool RKSettingsModulePlugins::show_code;
 int RKSettingsModulePlugins::code_size;
@@ -157,6 +158,7 @@
 	show_code = show_code_box->isChecked ();
 	code_size = code_size_box->intValue ();
 
+	fixPluginMapLists ();
 	RKWardMainWindow::getMain ()->initPlugins();
 }
 
@@ -170,6 +172,7 @@
 
 	KConfigGroup cg = config->group ("Plugin Settings");
 	cg.writeEntry ("Plugin Maps", plugin_maps);
+	cg.writeEntry ("All known plugin maps", known_plugin_maps);
 	cg.writeEntry ("Interface Preferences", static_cast<int> (interface_pref));
 	cg.writeEntry ("Code display default", show_code);
 	cg.writeEntry ("Code display size", code_size);
@@ -180,15 +183,55 @@
 
 	KConfigGroup cg = config->group ("Plugin Settings");
 	plugin_maps = cg.readEntry ("Plugin Maps", QStringList ());
+	known_plugin_maps = cg.readEntry ("All known plugin maps", QStringList ());
 	if (plugin_maps.isEmpty ()) {
 		plugin_maps.append (RKCommonFunctions::getRKWardDataDir () + "/all.pluginmap");
 	}
+	fixPluginMapLists ();
 
 	interface_pref = static_cast<PluginPrefs> (cg.readEntry ("Interface Preferences", static_cast<int> (PreferRecommended)));
 	show_code = cg.readEntry ("Code display default", false);
 	code_size = cg.readEntry ("Code display size", 40);
 }
 
+// static
+void RKSettingsModulePlugins::registerPluginMaps (const QStringList &maps) {
+	RK_TRACE (SETTINGS);
+
+	bool added = false;
+	foreach (const QString &map, maps) {
+		if (map.isEmpty ()) continue;
+		if (known_plugin_maps.contains (map)) continue;
+		known_plugin_maps.append (map);
+
+		if (plugin_maps.contains (map)) continue;
+		plugin_maps.append (map);
+		added = true;
+	}
+
+	if (added) {
+		KMessageBox::information (RKWardMainWindow::getMain (), i18n ("New RKWard plugin packs have been found. They will be activated, automatically. To de-activate selected plugin packs, use Settings->Configure RKWard->Plugins"), i18n ("New plugins found"), "new_plugins_found");
+		RKWardMainWindow::getMain ()->initPlugins();
+	}
+}
+
+void RKSettingsModulePlugins::fixPluginMapLists () {
+	RK_TRACE (SETTINGS);
+
+	for (int i = 0; i < plugin_maps.size (); ++i) {
+		QFileInfo info (plugin_maps[i]);
+		if (!info.isReadable ()) {
+			known_plugin_maps.removeAll (plugin_maps[i]);
+			plugin_maps.removeAt (i);
+			--i;
+		}
+	}
+
+	foreach (const QString &map, plugin_maps) {
+		if (!known_plugin_maps.contains (map)) known_plugin_maps.append (map);
+	}
+}
+
 void RKSettingsModulePlugins::downloadPlugins () {
 	RK_TRACE (SETTINGS);
 
@@ -221,13 +264,7 @@
 	}
 
 	// new pluginmaps were already added in installPluginPack. Now let's check, whether there any to be removed:
-	for (int i = 0; i < plugin_maps.size (); ++i) {
-		QFileInfo info (plugin_maps[i]);
-		if (!info.isReadable ()) {
-			plugin_maps.removeAt (i);
-			--i;
-		}
-	}
+	fixPluginMapLists ();
 
 	if (plugin_maps != oldmaps) {
 		map_choser->setValues (plugin_maps);

Modified: trunk/rkward/rkward/settings/rksettingsmoduleplugins.h
===================================================================
--- trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2011-09-08 09:36:57 UTC (rev 3731)
+++ trunk/rkward/rkward/settings/rksettingsmoduleplugins.h	2011-09-09 07:28:46 UTC (rev 3732)
@@ -51,6 +51,8 @@
 	static PluginPrefs getInterfacePreference () { return interface_pref; };
 	static bool showCodeByDefault () { return show_code; };
 	static int defaultCodeHeight () { return code_size; };
+	/** register a list of available plugin-maps (which may or may not already be known). New maps are activated, automatically. */
+	static void registerPluginMaps (const QStringList &maps);
 public slots:
 	void settingChanged ();
 	void browseRequest (QStringList* strings);
@@ -61,8 +63,11 @@
 	QButtonGroup *button_group;
 	QCheckBox *show_code_box;
 	RKSpinBox *code_size_box;
-	
+
+	/** active plugin maps */
 	static QStringList plugin_maps;
+	/** plugin maps which are not necessarily active, but have been encountered, before. @see plugin_maps */
+	static QStringList known_plugin_maps;
 	static PluginPrefs interface_pref;
 	static bool show_code;
 	static int code_size;
@@ -71,6 +76,7 @@
 	static void uninstallPluginPack (const QString &archive_file);
 	static QString baseNameOfPluginPack (const QString &archive_file);
 	static QStringList findPluginMapsRecursive (const QString &basedir);
+	static void fixPluginMapLists ();
 };
 
 #endif

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