[dia] Transport xmlError information via DiaContext



commit 78b19c3496ad88ed72e51d9fb30f2e8798685034
Author: Hans Breuer <hans breuer org>
Date:   Fri Feb 14 19:55:58 2014 +0100

    Transport xmlError information via DiaContext
    
    where appropriate. With diagram files these get visible in the UI.
    For other xml files they are converted to g_warning() or message_error.

 app/menus.c                      |   32 +++++++++++++++++++++++++++++++-
 app/winmain.c                    |   13 +++++++++++++
 dia-make.msc                     |    2 +-
 lib/dia_xml.c                    |   20 ++++++++++++--------
 lib/dia_xml_libxml.h             |    2 +-
 lib/sheet.c                      |    5 ++++-
 objects/custom/shape_info.c      |    6 ++++--
 objects/custom_lines/line_info.c |    6 ++++--
 plug-ins/svg/svg-import.c        |   13 ++++++++++---
 plug-ins/vdx/vdx-import.c        |    8 +++++---
 plug-ins/xslt/xslt.c             |   16 ++++++++++------
 11 files changed, 95 insertions(+), 28 deletions(-)
---
diff --git a/app/menus.c b/app/menus.c
index 72a3d9a..465b243 100644
--- a/app/menus.c
+++ b/app/menus.c
@@ -271,7 +271,13 @@ static const GtkRadioActionEntry display_select_radio_entries[] =
 /* need initialisation? */
 static gboolean initialise = TRUE;
 
-/* shared between toolbox and integrated code */
+/* shared between toolbox and integrated code
+
+ - One ui_manager from toolbox_ui_manager and integrated_ui_manager
+ - Two action groups for toolbox and display. In the integrated ui case
+   the latter should be disabled (or hidden) if there is no diagram
+
+ */
 static GtkUIManager *_ui_manager = NULL;
 
 /* toolbox */
@@ -885,6 +891,21 @@ static const gchar *ui_info =
 "</ui>";
 
 static void
+_action_start (GtkActionGroup *action_group,
+              GtkAction *action,
+              gpointer user_data)
+{
+  dia_log_message ("Start '%s'\n", gtk_action_get_name (action));
+}
+static void
+_action_done (GtkActionGroup *action_group,
+              GtkAction *action,
+              gpointer user_data)
+{
+  dia_log_message ("Done '%s'\n", gtk_action_get_name (action));
+}
+
+static void
 _setup_global_actions (void)
 {
   if (tool_actions)
@@ -908,6 +929,15 @@ _setup_global_actions (void)
                     "connect_proxy",
                    G_CALLBACK (_ui_manager_connect_proxy),
                    NULL);
+  g_signal_connect (G_OBJECT (_ui_manager), 
+                    "pre-activate",
+                   G_CALLBACK (_action_start),
+                   NULL);
+  g_signal_connect (G_OBJECT (_ui_manager), 
+                    "post-activate",
+                   G_CALLBACK (_action_done),
+                   NULL);
+
   gtk_ui_manager_set_add_tearoffs (_ui_manager, DIA_SHOW_TEAROFFS);
   gtk_ui_manager_insert_action_group (_ui_manager, toolbox_actions, 0);
 
diff --git a/app/winmain.c b/app/winmain.c
index 0be18db..f396560 100644
--- a/app/winmain.c
+++ b/app/winmain.c
@@ -29,6 +29,19 @@ WinMain (struct HINSTANCE__ *hInstance,
         char               *lpszCmdLine,
         int                 nCmdShow)
 {
+  typedef BOOL (WINAPI *PFN_SetProcessDPIAware) (VOID);
+  PFN_SetProcessDPIAware setProcessDPIAware;
+
+  /* Try to claim DPI awareness (should work from Vista). This disables automatic
+   * scaling of the user interface elements, so icons might get really small. But
+   * for reasonable high dpi that should still look better than, e.g. scaling our
+   * buttons to 125%.
+   */
+  setProcessDPIAware = (PFN_SetProcessDPIAware) GetProcAddress (GetModuleHandle ("user32.dll"),
+                                                               "SetProcessDPIAware");
+  if (setProcessDPIAware)
+    setProcessDPIAware ();
+
   dia_redirect_console ();
   
   app_init (__argc, __argv);
diff --git a/dia-make.msc b/dia-make.msc
index 9e33a88..3c29ba7 100644
--- a/dia-make.msc
+++ b/dia-make.msc
@@ -1 +1 @@
-!INCLUDE $(TOP)\glib\build\win32\make.msc
+!INCLUDE $(TOP)\glib-2\build\win32\make.msc
diff --git a/lib/dia_xml.c b/lib/dia_xml.c
index aaa6cca..13220cd 100644
--- a/lib/dia_xml.c
+++ b/lib/dia_xml.c
@@ -261,26 +261,30 @@ static xmlDocPtr
 xmlDiaParseFile(const char *filename, DiaContext *ctx)
 {
   const char *local_charset = NULL;
-  
+  xmlErrorPtr error_xml = NULL;
+  xmlDocPtr ret = NULL;
+
   if (   !g_get_charset(&local_charset)
       && local_charset) {
     /* we're not in an UTF-8 environment. */ 
     const gchar *fname = xml_file_check_encoding(filename,local_charset, ctx);
     if (fname != filename) {
       /* We've got a corrected file to parse. */
-      xmlDocPtr ret = xmlDoParseFile(fname);
+      xmlDocPtr ret = xmlDoParseFile(fname, &error_xml);
       unlink(fname);
       /* printf("has read %s instead of %s\n",fname,filename); */
       g_free((void *)fname);
-      return ret;
     } else {
       /* the XML file is good. libxml is "old enough" to handle it correctly.
        */
-      return xmlDoParseFile(filename);
+      ret = xmlDoParseFile(filename, &error_xml);
     }
   } else {
-    return xmlDoParseFile(filename);
+    ret = xmlDoParseFile(filename, &error_xml);
   }
+  if (error_xml)
+    dia_context_add_message (ctx, error_xml->message);
+  return ret;
 }
 
 /*!
@@ -290,14 +294,14 @@ xmlDiaParseFile(const char *filename, DiaContext *ctx)
  * \ingroup DiagramXmlIo
  */
 xmlDocPtr
-xmlDoParseFile(const char *filename)
+xmlDoParseFile(const char *filename, xmlErrorPtr *error)
 {
   xmlDocPtr doc;
   xmlErrorPtr err;
 
   doc = xmlParseFile(filename);
-  if (!doc)
-    err = xmlGetLastError ();
+  if (!doc && error)
+    *error = xmlGetLastError ();
 
   return doc;
 }
diff --git a/lib/dia_xml_libxml.h b/lib/dia_xml_libxml.h
index 5e331b5..8d74c31 100644
--- a/lib/dia_xml_libxml.h
+++ b/lib/dia_xml_libxml.h
@@ -25,7 +25,7 @@
 #include <libxml/parser.h>
 
 /* use this one instead of xmlParseFile */
-xmlDocPtr xmlDoParseFile(const char *filename); 
+xmlDocPtr xmlDoParseFile(const char *filename, xmlErrorPtr *error); 
 
 /* use this instead of xmlSaveFile/xmlSaveFileEnc. Set the encoding to
    UTF-8 at the very beginning ! */
diff --git a/lib/sheet.c b/lib/sheet.c
index 7f02e65..698b750 100644
--- a/lib/sheet.c
+++ b/lib/sheet.c
@@ -197,6 +197,7 @@ static void
 load_register_sheet(const gchar *dirname, const gchar *filename,
                     SheetScope scope)
 {
+  xmlErrorPtr error_xml = NULL;
   xmlDocPtr doc;
   xmlNsPtr ns;
   xmlNodePtr node, contents,subnode,root;
@@ -213,7 +214,9 @@ load_register_sheet(const gchar *dirname, const gchar *filename,
 
   /* the XML fun begins here. */
 
-  doc = xmlDoParseFile(filename);
+  doc = xmlDoParseFile(filename, &error_xml);
+  if (error_xml)
+    g_warning ("Sheet parser error %s", error_xml->message);
   if (!doc) return;
   root = doc->xmlRootNode;
   while (root && (root->type != XML_ELEMENT_NODE)) root=root->next;
diff --git a/objects/custom/shape_info.c b/objects/custom/shape_info.c
index 6a3e757..e36802e 100644
--- a/objects/custom/shape_info.c
+++ b/objects/custom/shape_info.c
@@ -685,7 +685,8 @@ update_bounds(ShapeInfo *info)
 static ShapeInfo *
 load_shape_info(const gchar *filename, ShapeInfo *preload)
 {
-  xmlDocPtr doc = xmlDoParseFile(filename);
+  xmlErrorPtr error_xml = NULL;
+  xmlDocPtr doc = xmlDoParseFile(filename, &error_xml);
   xmlNsPtr shape_ns, svg_ns;
   xmlNodePtr node, root, ext_node = NULL;
   ShapeInfo *info;
@@ -693,7 +694,8 @@ load_shape_info(const gchar *filename, ShapeInfo *preload)
   int i;
   
   if (!doc) {
-    g_warning("parse error for %s", filename);
+    g_warning("Custom shape parser error for %s\n%s", filename,
+             error_xml ? error_xml->message : "");
     return NULL;
   }
   /* skip (emacs) comments */
diff --git a/objects/custom_lines/line_info.c b/objects/custom_lines/line_info.c
index 5341ea4..ddedd63 100644
--- a/objects/custom_lines/line_info.c
+++ b/objects/custom_lines/line_info.c
@@ -325,12 +325,14 @@ LineInfo* line_info_clone(LineInfo* info)
 LineInfo* 
 line_info_load_and_apply_from_xmlfile(const gchar *filename, LineInfo* info)
 {
-  xmlDocPtr doc = xmlDoParseFile(filename);
+  xmlErrorPtr error_xml = NULL;
+  xmlDocPtr doc = xmlDoParseFile(filename, &error_xml);
   xmlNodePtr node, root;
   xmlChar *tmp;
 
   if (!doc) {
-    g_warning("parse error for %s", filename);
+    g_warning("Custom Line parser error for %s\n%s", filename,
+             error_xml ? error_xml->message : "");
     return NULL;
   }
   /* skip (emacs) comments */
diff --git a/plug-ins/svg/svg-import.c b/plug-ins/svg/svg-import.c
index 2bb7dde..69b1cb6 100644
--- a/plug-ins/svg/svg-import.c
+++ b/plug-ins/svg/svg-import.c
@@ -1902,12 +1902,19 @@ import_memory_svg (const guchar *p, guint size, DiagramData *dia,
 static gboolean
 import_file_svg(const gchar *filename, DiagramData *dia, DiaContext *ctx, void* user_data) 
 {
-  xmlDocPtr doc = xmlDoParseFile(filename);
+  xmlErrorPtr error_xml = NULL;
+  xmlDocPtr doc = xmlDoParseFile(filename, &error_xml);
 
   if (!doc) {
-    dia_context_add_message(ctx, _("Parse error for %s"), 
-                           dia_context_get_filename (ctx));
+    dia_context_add_message(ctx, _("SVG parser error for %s\n%s"), 
+                           dia_context_get_filename (ctx),
+                           error_xml ? error_xml->message : "");
     return FALSE;
+  } else if (error_xml) {
+    /* just a warning */
+    dia_context_add_message(ctx, _("SVG parser warning for %s\n%s"), 
+                           dia_context_get_filename (ctx),
+                           error_xml ? error_xml->message : "");
   }
   return import_svg (doc, dia, ctx, user_data);
 }
diff --git a/plug-ins/vdx/vdx-import.c b/plug-ins/vdx/vdx-import.c
index bbc25f8..8690f71 100644
--- a/plug-ins/vdx/vdx-import.c
+++ b/plug-ins/vdx/vdx-import.c
@@ -2874,7 +2874,8 @@ vdx_free(VDXDocument *theDoc)
 static gboolean
 import_vdx(const gchar *filename, DiagramData *dia, DiaContext *ctx, void* user_data)
 {
-    xmlDocPtr doc = xmlDoParseFile(filename);
+    xmlErrorPtr error_xml = NULL;
+    xmlDocPtr doc = xmlDoParseFile(filename, &error_xml);
     xmlNodePtr root, cur;
     struct VDXDocument *theDoc;
     const char *s;
@@ -2884,8 +2885,9 @@ import_vdx(const gchar *filename, DiagramData *dia, DiaContext *ctx, void* user_
     char* old_locale;
 
     if (!doc) {
-        dia_context_add_message(ctx, _("Parse error for %s"),
-                                dia_context_get_filename(ctx));
+        dia_context_add_message(ctx, _("VDX parser error for %s\n%s"),
+                               error_xml ? error_xml->message : "",
+                               dia_context_get_filename(ctx));
         return FALSE;
     }
     /* skip comments */
diff --git a/plug-ins/xslt/xslt.c b/plug-ins/xslt/xslt.c
index 892cb42..88f9695 100644
--- a/plug-ins/xslt/xslt.c
+++ b/plug-ins/xslt/xslt.c
@@ -82,7 +82,8 @@ xslt_ok(void)
        char *params[] = { "directory", NULL, NULL };
        xsltStylesheetPtr style, codestyle;
        xmlDocPtr doc, res;
-        gchar *directory = g_path_get_dirname(filename);
+       xmlErrorPtr error_xml = NULL;
+       gchar *directory = g_path_get_dirname(filename);
        gchar *uri = g_filename_to_uri (directory, NULL, NULL);
        g_free (directory);
 
@@ -107,11 +108,12 @@ xslt_ok(void)
        }
        
        xmlSubstituteEntitiesDefault(0);
-       doc = xmlDoParseFile(diafilename);
+       doc = xmlDoParseFile(diafilename, &error_xml);
 
        if(doc == NULL) {
-               message_error(_("Error while parsing %s\n"), 
-                             dia_message_filename(diafilename));
+               message_error(_("Error while parsing %s\n%s"),
+                             dia_message_filename(diafilename),
+                             error_xml ? error_xml->message : "");
                return;
        }
        
@@ -219,6 +221,7 @@ static PluginInitResult read_configuration(const char *config)
 {
     xmlDocPtr doc;
     xmlNodePtr cur;
+    xmlErrorPtr error_xml = NULL;
     /* Primary xsl */
     fromxsl_t *cur_from = NULL;
     gchar *path = NULL;
@@ -226,11 +229,12 @@ static PluginInitResult read_configuration(const char *config)
     if (!g_file_test(config, G_FILE_TEST_EXISTS))
        return DIA_PLUGIN_INIT_ERROR;
     
-    doc = xmlDoParseFile(config);
+    doc = xmlDoParseFile(config, &error_xml);
     
     if (doc == NULL) 
     {
-       g_error ("Couldn't parse XSLT plugin's configuration file %s", config);
+       g_error ("Couldn't parse XSLT plugin's configuration file %s\n%s",
+                config, error_xml ? error_xml->message : "");
        return DIA_PLUGIN_INIT_ERROR;
     }
     


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