CVS: sylpheedclaws/sylpheed-claws/src/common plugin.c,1.13.2.22,1.13.2.23 plugin.h,1.5.2.8,1.5.2.9

[email protected] Fri, 15 Dec 2006 16:41:00 +0000
Newsgroups gmane.mail.sylpheed.claws.cvs
Message-ID <[email protected]>
Update of /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/common
In directory sunsite.dk:/tmp/cvs-serv8976/src/common

Modified Files:
      Tag: gtk2
	plugin.c plugin.h 
Log Message:
2006-12-15 [wwp]	2.6.1cvs40

	* src/wizard.c
	* src/common/plugin.c
	* src/common/plugin.h
	* src/gtk/about.c
	* src/plugins/bogofilter/bogofilter.c
	* src/plugins/clamav/clamav_plugin.c
	* src/plugins/demo/demo.c
	* src/plugins/dillo_viewer/dillo_viewer.c
	* src/plugins/pgpcore/plugin.c
	* src/plugins/pgpinline/plugin.c
	* src/plugins/pgpmime/plugin.c
	* src/plugins/spamassassin/spamassassin.c
	* src/plugins/trayicon/trayicon.c
		factorize some translatable strings (plugins-related),
		fix missing punctuation in several places,
		remove useless translatable \n in about.c,
		and factorize plugin init code w/ a new function
		check_plugin_version() in common/plugin.c.
		Patch by Fabien Vantard <[email protected]>. 

Index: plugin.c
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/common/plugin.c,v
retrieving revision 1.13.2.22
retrieving revision 1.13.2.23
diff -u -d -r1.13.2.22 -r1.13.2.23
--- plugin.c	2006/11/07 10:40:07	1.13.2.22
+++ plugin.c	2006/12/15 16:40:56	1.13.2.23
@@ -32,6 +32,7 @@
 #include "utils.h"
 #include "plugin.h"
 #include "prefs.h"
+#include "claws.h"
 
 struct _Plugin
 {
@@ -519,4 +520,47 @@
 const gchar *plugin_get_error(Plugin *plugin)
 {
 	return plugin->error;
+}
+
+/* Generally called in plugin_init() function of each plugin. It check the
+ * minimal and compiled version of claws binary required by the plugin.
+ * If (@minimum_claws_version == 0 || @compiled_claws_version == 0), don't
+ * check the corresponding version.
+ *
+ * If an error occurs {
+ * 	If @error == NULL { don't allocate error string. }
+ *	If @error != NULL { error string is allocated and must be freed after 
+ *				call function. }
+ * }
+ * Returns: FALSE if an error occurs, TRUE if all is OK.
+ */
+gint check_plugin_version(guint32 minimum_claws_version,
+			 guint32 compiled_claws_version,
+			 const gchar *plugin_name,
+			 gchar **error)
+{
+	guint32 claws_version = claws_get_version();
+
+	if (compiled_claws_version != 0 && claws_version > compiled_claws_version) {
+		if (error != NULL) {
+			*error = (plugin_name && *plugin_name)
+				? g_strdup_printf(_("Your version of Claws Mail is newer than the "
+							"version the '%s' plugin was built with."),
+						plugin_name)
+				: g_strdup(_("Your version of Claws Mail is newer than the "
+							"version the plugin was built with."));
+		}
+		return FALSE;
+	}
+
+	if (minimum_claws_version != 0 && claws_version < minimum_claws_version) {
+		if (error != NULL) {
+			*error = (plugin_name && *plugin_name)
+				? g_strdup_printf(_("Your version of Claws Mail is too old for "
+							"the '%s' plugin."), plugin_name)
+				: g_strdup(_("Your version of Claws Mail is too old for the plugin."));
+		}
+		return FALSE;
+	}
+	return TRUE;
 }

Index: plugin.h
===================================================================
RCS file: /pack/anoncvs/sylpheedclaws/sylpheed-claws/src/common/plugin.h,v
retrieving revision 1.5.2.8
retrieving revision 1.5.2.9
diff -u -d -r1.5.2.8 -r1.5.2.9
--- plugin.h	2006/11/07 10:40:07	1.5.2.8
+++ plugin.h	2006/12/15 16:40:56	1.5.2.9
@@ -63,4 +63,8 @@
 const gchar *plugin_get_desc	(Plugin		 *plugin);
 const gchar *plugin_get_version	(Plugin		 *plugin);
 const gchar *plugin_get_error	(Plugin		 *plugin);
+gint check_plugin_version	(guint32 minimum_claws_version,
+				 guint32 compiled_claws_version,
+				 const gchar *plugin_name,
+				 gchar **error);
 #endif