dia r3976 - in trunk: . lib plug-ins/pixbuf plug-ins/python



Author: hans
Date: Fri May  2 11:43:04 2008
New Revision: 3976
URL: http://svn.gnome.org/viewvc/dia?rev=3976&view=rev

Log:
2008-05-02  Hans Breuer  <hans breuer org>

	* lib/filter.[hc] : introduce the ability to influence guessing of
	import/export -filters. If one is marked as FILTER_DONT_GUESS it is 
	only selected by the guessing if it is the only one registering a 
	certain extension
	* lib/plug-in.h : increase DIA_PLUGIN_API_VERSION
	* plug-ins/python/diamodule.c : set FILTER_DONT_GUESS for all filters
	implemented in Python
	* plug-ins/pixbuf/pixbuf.c : set FILTER_DONT_GUESS for vector formats
	supported by GdkPixbuf. This way a Dia importer capable to process
	vectors gets preferred



Modified:
   trunk/ChangeLog
   trunk/lib/filter.c
   trunk/lib/filter.h
   trunk/lib/plug-ins.h
   trunk/plug-ins/pixbuf/pixbuf.c
   trunk/plug-ins/python/diamodule.c

Modified: trunk/lib/filter.c
==============================================================================
--- trunk/lib/filter.c	(original)
+++ trunk/lib/filter.c	Fri May  2 11:43:04 2008
@@ -86,12 +86,17 @@
 
 /* Guess the filter for a given filename. 
  * Returns the first filter found that matches the extension on the filename,
- * or NULL if none such are found. */
+ * or NULL if none such are found.  
+ * If there are multiple filters registered for the same extension some are
+ * excluded from being returned here by the hint FILTER_DONT_GUESS.
+ */
 DiaExportFilter *
 filter_guess_export_filter(const gchar *filename)
 {
   GList *tmp;
   gchar *ext;
+  gint   no_guess = 0;
+  DiaExportFilter *dont_guess = NULL;
 
   ext = strrchr(filename, '.');
   if (ext)
@@ -103,11 +108,17 @@
     DiaExportFilter *ef = tmp->data;
     gint i;
 
-    for (i = 0; ef->extensions[i] != NULL; i++)
+    for (i = 0; ef->extensions[i] != NULL; i++) {
+      if (ef->hints & FILTER_DONT_GUESS) {
+        dont_guess = ef;
+	++no_guess;
+        continue;
+      }
       if (!g_strcasecmp(ef->extensions[i], ext))
 	return ef;
+    }
   }
-  return NULL;
+  return (no_guess == 1) ? dont_guess : NULL;
 }
 
 /** Get an export filter by unique name.
@@ -184,12 +195,17 @@
   return ret;
 }
 
-/* guess the filter for a given filename. */
+/* guess the filter for a given filename. 
+ * If there are multiple filters registered for the same extension some are
+ * excluded from being returned here by the hint FILTER_DONT_GUESS.
+ */
 DiaImportFilter *
 filter_guess_import_filter(const gchar *filename)
 {
   GList *tmp;
   gchar *ext;
+  int no_guess = 0;
+  DiaImportFilter *dont_guess = NULL;
 
   ext = strrchr(filename, '.');
   if (ext)
@@ -198,14 +214,20 @@
     ext = "";
 
   for (tmp = import_filters; tmp != NULL; tmp = tmp->next) {
-    DiaImportFilter *efilter = tmp->data;
+    DiaImportFilter *ifilter = tmp->data;
     gint i;
 
-    for (i = 0; efilter->extensions[i] != NULL; i++)
-      if (!g_strcasecmp(efilter->extensions[i], ext))
-	return efilter;
+    for (i = 0; ifilter->extensions[i] != NULL; i++) {
+      if (ifilter->hints & FILTER_DONT_GUESS) {
+        dont_guess = ifilter;
+        ++no_guess;
+        continue;
+      }
+      if (!g_strcasecmp(ifilter->extensions[i], ext))
+	return ifilter;
+    }
   }
-  return NULL;
+  return (no_guess == 1) ? dont_guess : NULL;
 }
 
 /* register a new callback from a plug-in */

Modified: trunk/lib/filter.h
==============================================================================
--- trunk/lib/filter.h	(original)
+++ trunk/lib/filter.h	Fri May  2 11:43:04 2008
@@ -27,6 +27,10 @@
 
 G_BEGIN_DECLS
 
+enum FilterFlags {
+  FILTER_DONT_GUESS = (1<<0)
+};
+
 typedef void (* DiaExportFunc) (DiagramData *dia, const gchar *filename,
 				const gchar *diafilename, void* user_data);
 
@@ -43,6 +47,8 @@
    * treated seperately for this.
    */
   const gchar *unique_name;
+  /* additional hints for export */
+  guint hints;
 };
 
 /* returns FALSE on error loading diagram */
@@ -62,6 +68,8 @@
    * treated seperately for this.
    */
   const gchar *unique_name;
+  /* additional hints for export */
+  guint hints;
 };
 
 /* gets called as menu callback */

Modified: trunk/lib/plug-ins.h
==============================================================================
--- trunk/lib/plug-ins.h	(original)
+++ trunk/lib/plug-ins.h	Fri May  2 11:43:04 2008
@@ -48,7 +48,7 @@
  * The list is by no means complete. If in doubt about your change
  * please ask on dia-list or alternative increment ;-)      --hb
  */
-#define DIA_PLUGIN_API_VERSION 8
+#define DIA_PLUGIN_API_VERSION 9
 
 typedef enum {
   DIA_PLUGIN_INIT_OK,

Modified: trunk/plug-ins/pixbuf/pixbuf.c
==============================================================================
--- trunk/plug-ins/pixbuf/pixbuf.c	(original)
+++ trunk/plug-ins/pixbuf/pixbuf.c	Fri May  2 11:43:04 2008
@@ -260,6 +260,12 @@
           ifilter->user_data = gdk_pixbuf_format_get_name (format);
           /* they are in differnt namespaces aren't they? */
           ifilter->unique_name = g_strdup_printf ("pixbuf-%s", name);
+	  /* don't use pixbuf loader for vector formats */
+	  if (   strcmp (name, "svg") == 0
+	      || strcmp (name, "svgz") == 0
+	      || strcmp (name, "wmf") == 0
+	      || strcmp (name, "emf") == 0)
+	    ifilter->hints = FILTER_DONT_GUESS;
           g_free (name);
           _import_filters = g_list_append (_import_filters, ifilter);
           filter_register_import(ifilter);

Modified: trunk/plug-ins/python/diamodule.c
==============================================================================
--- trunk/plug-ins/python/diamodule.c	(original)
+++ trunk/plug-ins/python/diamodule.c	Fri May  2 11:43:04 2008
@@ -236,6 +236,7 @@
     filter->export_func = &PyDia_export_data;
     filter->user_data = renderer;
     filter->unique_name = g_strdup_printf ("%s-py", ext);
+    filter->hints = FILTER_DONT_GUESS;
     obj = PyDiaExportFilter_New(filter);
 
     filter_register_export(filter);
@@ -311,6 +312,7 @@
     filter->import_func = &PyDia_import_data;
     filter->user_data = func;
     filter->unique_name = g_strdup_printf ("%s-py", ext);
+    filter->hints = FILTER_DONT_GUESS;
 
     filter_register_import(filter);
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]