]> git.street.me.uk Git - andy/viking.git/blobdiff - src/vikgotoxmltool.c
Clarify text on map layer menu
[andy/viking.git] / src / vikgotoxmltool.c
index 07800a4619049c1d4abb19ed1156bebf4e3b62a3..d0b6a009f90d068266e997b98fedd393d30c2667 100644 (file)
@@ -107,6 +107,7 @@ _goto_xml_tool_set_property (GObject      *object,
 {
   VikGotoXmlTool *self = VIK_GOTO_XML_TOOL (object);
   VikGotoXmlToolPrivate *priv = GOTO_XML_TOOL_GET_PRIVATE (self);
 {
   VikGotoXmlTool *self = VIK_GOTO_XML_TOOL (object);
   VikGotoXmlToolPrivate *priv = GOTO_XML_TOOL_GET_PRIVATE (self);
+  gchar **splitted = NULL;
 
   switch (property_id)
     {
 
   switch (property_id)
     {
@@ -116,23 +117,53 @@ _goto_xml_tool_set_property (GObject      *object,
       break;
 
     case PROP_LAT_PATH:
       break;
 
     case PROP_LAT_PATH:
+      splitted = g_strsplit (g_value_get_string (value), "@", 2);
       g_free (priv->lat_path);
       g_free (priv->lat_path);
-      priv->lat_path = g_value_dup_string (value);
+      priv->lat_path = splitted[0];
+      if (splitted[1])
+      {
+        g_object_set (object, "lat-attr", splitted[1], NULL);
+        g_free (splitted[1]);
+      }
+      /* only free the tab, not the strings */
+      g_free (splitted);
+      splitted = NULL;
       break;
 
     case PROP_LAT_ATTR:
       break;
 
     case PROP_LAT_ATTR:
-      g_free (priv->lat_attr);
-      priv->lat_attr = g_value_dup_string (value);
+      /* Avoid to overwrite XPATH value */
+      /* NB: This disable future overwriting,
+         but as property is CONSTRUCT_ONLY there is no matter */
+      if (!priv->lat_attr || g_value_get_string (value))
+      {
+        g_free (priv->lat_attr);
+        priv->lat_attr = g_value_dup_string (value);
+      }
       break;
 
     case PROP_LON_PATH:
       break;
 
     case PROP_LON_PATH:
+      splitted = g_strsplit (g_value_get_string (value), "@", 2);
       g_free (priv->lon_path);
       g_free (priv->lon_path);
-      priv->lon_path = g_value_dup_string (value);
+      priv->lon_path = splitted[0];
+      if (splitted[1])
+      {
+        g_object_set (object, "lon-attr", splitted[1], NULL);
+        g_free (splitted[1]);
+      }
+      /* only free the tab, not the strings */
+      g_free (splitted);
+      splitted = NULL;
       break;
 
     case PROP_LON_ATTR:
       break;
 
     case PROP_LON_ATTR:
-      g_free (priv->lon_attr);
-      priv->lon_attr = g_value_dup_string (value);
+      /* Avoid to overwrite XPATH value */
+      /* NB: This disable future overwriting,
+         but as property is CONSTRUCT_ONLY there is no matter */
+      if (!priv->lon_attr || g_value_get_string (value))
+      {
+        g_free (priv->lon_attr);
+        priv->lon_attr = g_value_dup_string (value);
+      }
       break;
 
     default:
       break;
 
     default:
@@ -367,11 +398,16 @@ static gboolean
 _goto_xml_tool_parse_file_for_latlon(VikGotoTool *self, gchar *filename, struct LatLon *ll)
 {
        GMarkupParser xml_parser;
 _goto_xml_tool_parse_file_for_latlon(VikGotoTool *self, gchar *filename, struct LatLon *ll)
 {
        GMarkupParser xml_parser;
-       GMarkupParseContext *xml_context;
-       GError *error;
+       GMarkupParseContext *xml_context = NULL;
+       GError *error = NULL;
        VikGotoXmlToolPrivate *priv = GOTO_XML_TOOL_GET_PRIVATE (self);
   g_return_val_if_fail(priv != NULL, FALSE);
 
        VikGotoXmlToolPrivate *priv = GOTO_XML_TOOL_GET_PRIVATE (self);
   g_return_val_if_fail(priv != NULL, FALSE);
 
+  g_debug ("%s: %s@%s, %s@%s",
+           __FUNCTION__,
+           priv->lat_path, priv->lat_attr,
+           priv->lon_path, priv->lon_attr);
+
        FILE *file = g_fopen (filename, "r");
        if (file == NULL)
                /* TODO emit warning */
        FILE *file = g_fopen (filename, "r");
        if (file == NULL)
                /* TODO emit warning */
@@ -400,16 +436,28 @@ _goto_xml_tool_parse_file_for_latlon(VikGotoTool *self, gchar *filename, struct
        
        gchar buff[BUFSIZ];
        size_t nb;
        
        gchar buff[BUFSIZ];
        size_t nb;
-       while ((nb = fread (buff, sizeof(gchar), BUFSIZ, file)) > 0)
+       while (xml_context &&
+              (nb = fread (buff, sizeof(gchar), BUFSIZ, file)) > 0)
        {
                if (!g_markup_parse_context_parse(xml_context, buff, nb, &error))
        {
                if (!g_markup_parse_context_parse(xml_context, buff, nb, &error))
-                       fprintf(stderr, "%s: parsing error.\n", __FUNCTION__);
+               {
+                       fprintf(stderr, "%s: parsing error: %s.\n",
+                               __FUNCTION__, error->message);
+                       g_markup_parse_context_free(xml_context);
+                       xml_context = NULL;
+               }
+               g_clear_error (&error);
        }
        /* cleanup */
        }
        /* cleanup */
-       if (!g_markup_parse_context_end_parse(xml_context, &error))
-               fprintf(stderr, "%s: errors occurred reading file.\n", __FUNCTION__);
+       if (xml_context &&
+           !g_markup_parse_context_end_parse(xml_context, &error))
+               fprintf(stderr, "%s: errors occurred while reading file: %s.\n",
+                       __FUNCTION__, error->message);
+       g_clear_error (&error);
        
        
-       g_markup_parse_context_free(xml_context);
+       if (xml_context)
+               g_markup_parse_context_free(xml_context);
+       xml_context = NULL;
        fclose (file);
   
   if (ll != NULL)
        fclose (file);
   
   if (ll != NULL)