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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed May 13 09:05:14 UTC 2009


Revision: 2472
          http://rkward.svn.sourceforge.net/rkward/?rev=2472&view=rev
Author:   tfry
Date:     2009-05-13 09:05:14 +0000 (Wed, 13 May 2009)

Log Message:
-----------
added basic error handling for run again links

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/plugin/rkcomponent.cpp
    trunk/rkward/rkward/plugin/rkcomponent.h
    trunk/rkward/rkward/plugin/rkcomponentmap.cpp

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2009-05-12 20:30:50 UTC (rev 2471)
+++ trunk/rkward/ChangeLog	2009-05-13 09:05:14 UTC (rev 2472)
@@ -1,5 +1,5 @@
 - Adjust some icons
-- Add "Run again" link for plugin generated output		TODO: add error handling, revisit plugins without header, what about wizard/dialog?
+- Add "Run again" link for plugin generated output		TODO: revisit plugins without header
 - Fixed: All objects in .Globalenv would be revisited if a single object was added / removed		TODO: backport? (r2466)
 - Fixed: Screen device in rkward was not seen as interactive by R	TODO: backport (r2462)
 

Modified: trunk/rkward/rkward/plugin/rkcomponent.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.cpp	2009-05-12 20:30:50 UTC (rev 2471)
+++ trunk/rkward/rkward/plugin/rkcomponent.cpp	2009-05-13 09:05:14 UTC (rev 2472)
@@ -94,7 +94,7 @@
 	return out;
 }
 
-bool RKComponentBase::unserializeState (const QString &state) {
+RKComponent::UnserializeError RKComponentBase::unserializeState (const QString &state) {
 	RK_TRACE (PLUGIN);
 
 	QMap<QString, QString> props;
@@ -103,13 +103,22 @@
 	for (int i = 0; i < lines.count (); ++i) {
 		QString line = lines[i];
 		int sep = line.indexOf ('=');
-		if (sep < 0) return false;		// TODO: message
+		if (sep < 0) return BadFormat;
 		props.insert (RKCommonFunctions::unescape (line.left (sep)), RKCommonFunctions::unescape (line.mid (sep+1)));
 	}
 
 	setPropertyValues (&props);
 
-	return true;
+	// verify
+	UnserializeError error = NoError;
+	for (QMap<QString, QString>::const_iterator it = props.constBegin (); it != props.constEnd (); ++it) {
+		if (fetchStringValue (it.key ()) != it.value ()) {
+			RK_DO(qDebug ("Tried to apply value %s to property %s, but got %s", qPrintable (it.value ()), qPrintable (it.key ()), qPrintable (fetchStringValue (it.key ()))), PLUGIN, DL_INFO);
+			error = NotAllSettingsApplied;
+		}
+	}
+
+	return error;
 }
 
 QString RKComponentBase::fetchStringValue (const QString &identifier) {

Modified: trunk/rkward/rkward/plugin/rkcomponent.h
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponent.h	2009-05-12 20:30:50 UTC (rev 2471)
+++ trunk/rkward/rkward/plugin/rkcomponent.h	2009-05-13 09:05:14 UTC (rev 2472)
@@ -61,6 +61,12 @@
 		ComponentContextHandler = 2900,
 		ComponentUser = 3000	/**< for user expansion */
 	};
+	enum UnserializeError {
+		NoError,
+		BadFormat,
+		NotAllSettingsApplied,
+		NoSuchComponent
+	};
 /** for RTTI. see RKComponentBase::RKComponentTypes */
 	virtual int type () = 0;
 /** tries to locate a component (or property) described by identifier as a child (of any generation) of this RKComponentBase. If found, a pointer to this is returned. Also, the modifier parameter is set to hold any remaining modifier contained in the identifier.
@@ -87,8 +93,8 @@
 /** serialize the state of this component / property and all its children. Note: Only the non-internal property-values are serialzed, not the components / properties themselves. @see fetchPropertyValuesRecursive() */
 	QString serializeState () const;
 /** set values from a string created with serializeState(). @see serializeState (), @see setPropertyValues ().
- at returns false if unserializing failed. */
-	bool unserializeState (const QString &state);
+ at returns status code */
+	UnserializeError unserializeState (const QString &state);
 protected:
 	QHash<QString, RKComponentBase*> child_map;
 	bool required;

Modified: trunk/rkward/rkward/plugin/rkcomponentmap.cpp
===================================================================
--- trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2009-05-12 20:30:50 UTC (rev 2471)
+++ trunk/rkward/rkward/plugin/rkcomponentmap.cpp	2009-05-13 09:05:14 UTC (rev 2472)
@@ -22,6 +22,7 @@
 
 #include <klocale.h>
 #include <kactioncollection.h>
+#include <kmessagebox.h>
 
 #include "rkcomponentcontext.h"
 #include "rkstandardcomponent.h"
@@ -127,7 +128,7 @@
 }
 
 /////////////////////////// END RKComponentXMLGUIClient /////////////////////////////////
-////////////////////////////// BEGIN RKComponentMap /////////////////////////////////////
+////////////////////////////// Bhttp://apps.sourceforge.net/mediawiki/rkward/nfs/project/r/rk/rkward/6/6d/RKWardApplicationDetached.pngEGIN RKComponentMap /////////////////////////////////////
 
 // static members
 RKComponentMap *RKComponentMap::component_map = 0;
@@ -235,14 +236,28 @@
 	RK_TRACE (PLUGIN);
 
 	RKComponentHandle *handle = getComponentHandle (component_id);
-	if (!handle) return false;
+	if (!handle) {
+		KMessageBox::sorry (RKWardMainWindow::getMain (), i18n ("You tried to invoke a plugin called '%1', but that plugin is currently unknown. Probably you need to load the corresponding PluginMap (Settings->Configure RKWard->Plugins), or perhaps the plugin was renamed.").arg (component_id), i18n ("No such plugin"));
+		return false;
+	}
 
 	RKStandardComponent *component = handle->invoke (0, 0);
 	RK_ASSERT (component);
 
-	bool ok = component->unserializeState (serialized_settings);
+	RKComponent::UnserializeError error = component->unserializeState (serialized_settings);
+	if (error == RKComponent::NoError) return true;
+	if (error == RKComponent::BadFormat) {
+		KMessageBox::error (component, i18n ("Bad serialization format while trying to invoke plugin '%1'. Please contact the RKWard team (Help->About RKWard->Authors).").arg (component_id), i18n ("Bad serialization format"));
+		return false;
+	}
+	if (error == RKComponent::NotAllSettingsApplied) {
+		KMessageBox::information (component, i18n ("Not all specified settings could be applied. Most likely this is because some R objects are no longer present in your current workspace."), i18n ("Not all settings applied"));
+		// TODO: Don't show again-box?
+		// not considered an error
+	}
+
 #warning TODO: support automatic submit
-	return ok;
+	return true;
 }
 
 int RKComponentMap::addPluginMap (const QString& plugin_map_file) {


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