Use an empty string to pass the test in set_app_info.
[platform/upstream/glib.git] / glib / gbookmarkfile.c
index cf052fa..889937f 100644 (file)
@@ -250,20 +250,27 @@ static gchar *
 bookmark_app_info_dump (BookmarkAppInfo *app_info)
 {
   gchar *retval;
+  gchar *name, *exec;
 
   g_assert (app_info != NULL);
 
   if (app_info->count == 0)
     return NULL;
+
+  name = g_markup_escape_text (app_info->name, -1);
+  exec = g_markup_escape_text (app_info->exec, -1);
  
   retval = g_strdup_printf ("          <%s:%s %s=\"%s\" %s=\"%s\" %s=\"%ld\" %s=\"%u\"/>\n",
                             BOOKMARK_NAMESPACE_NAME,
                             BOOKMARK_APPLICATION_ELEMENT,
-                            BOOKMARK_NAME_ATTRIBUTE, app_info->name,
-                            BOOKMARK_EXEC_ATTRIBUTE, app_info->exec,
+                            BOOKMARK_NAME_ATTRIBUTE, name,
+                            BOOKMARK_EXEC_ATTRIBUTE, exec,
                             BOOKMARK_TIMESTAMP_ATTRIBUTE, (time_t) app_info->stamp,
                             BOOKMARK_COUNT_ATTRIBUTE, app_info->count);
 
+  g_free (name);
+  g_free (exec);
+
   return retval;
 }
 
@@ -370,8 +377,9 @@ bookmark_metadata_dump (BookmarkMetadata *metadata)
       
       for (l = g_list_last (metadata->groups); l != NULL; l = l->prev)
         {
-          gchar *group_name = (gchar *) l->data;
-          
+          gchar *group_name;
+
+         group_name = g_markup_escape_text ((gchar *) l->data, -1);
           g_string_append_printf (retval,
                                  "          <%s:%s>%s</%s:%s>\n",
                                  BOOKMARK_NAMESPACE_NAME,
@@ -379,6 +387,7 @@ bookmark_metadata_dump (BookmarkMetadata *metadata)
                                  group_name,
                                  BOOKMARK_NAMESPACE_NAME,
                                  BOOKMARK_GROUP_ELEMENT);
+         g_free (group_name);
         }
       
       /* close groups container */
@@ -519,7 +528,7 @@ bookmark_item_dump (BookmarkItem *item)
   modified = timestamp_to_iso8601 (item->modified);
   visited = timestamp_to_iso8601 (item->visited);
 
-  escaped_uri = g_markup_escape_text (item->uri, strlen (item->uri));
+  escaped_uri = g_markup_escape_text (item->uri, -1);
   
   g_string_append_printf (retval,
                           "  <%s %s=\"%s\" %s=\"%s\" %s=\"%s\" %s=\"%s\">\n",
@@ -537,7 +546,7 @@ bookmark_item_dump (BookmarkItem *item)
     {
       gchar *escaped_title;
       
-      escaped_title = g_markup_escape_text (item->title, strlen (item->title));
+      escaped_title = g_markup_escape_text (item->title, -1);
       g_string_append_printf (retval,
                              "    <%s>%s</%s>\n",
                              XBEL_TITLE_ELEMENT,
@@ -550,11 +559,11 @@ bookmark_item_dump (BookmarkItem *item)
     {
       gchar *escaped_desc;
       
-      escaped_desc = g_markup_escape_text (item->description, strlen (item->description));
+      escaped_desc = g_markup_escape_text (item->description, -1);
       g_string_append_printf (retval,
                              "    <%s>%s</%s>\n",
                              XBEL_DESC_ELEMENT,
-                             item->description,
+                             escaped_desc,
                              XBEL_DESC_ELEMENT);
       g_free (escaped_desc);
     }
@@ -1000,9 +1009,8 @@ is_element_full (ParseData   *parse_data,
                  const gchar *element,
                  const gchar  sep)
 {
-  gchar *ns_uri, *ns_name;
-  gchar *element_name, *resolved;
-  gchar *p, *s;
+  gchar *ns_uri, *ns_name, *s, *resolved;
+  const gchar *p, *element_name;
   gboolean retval;
  
   g_assert (parse_data != NULL);
@@ -1437,8 +1445,8 @@ g_bookmark_file_parse (GBookmarkFile  *bookmark,
 
 static gchar *
 g_bookmark_file_dump (GBookmarkFile  *bookmark,
-                       gsize            *length,
-                       GError          **error)
+                     gsize          *length,
+                     GError        **error)
 {
   GString *retval;
   GList *l;
@@ -2126,9 +2134,7 @@ g_bookmark_file_set_title (GBookmarkFile *bookmark,
   if (!uri)
     {
       g_free (bookmark->title);
-      
-      if (title && title[0] != '\0')
-        bookmark->title = g_strdup (title);
+      bookmark->title = g_strdup (title);
     }
   else
     {
@@ -2142,9 +2148,7 @@ g_bookmark_file_set_title (GBookmarkFile *bookmark,
         }
       
       g_free (item->title);
-      
-      if (title && title[0] != '\0')
-        item->title = g_strdup (title);
+      item->title = g_strdup (title);
       
       item->modified = time (NULL);
     }
@@ -2216,10 +2220,8 @@ g_bookmark_file_set_description (GBookmarkFile *bookmark,
 
   if (!uri)
     {
-      g_free (bookmark->description);
-      
-      if (description && description[0] != '\0')
-        bookmark->description = g_strdup (description);
+      g_free (bookmark->description); 
+      bookmark->description = g_strdup (description);
     }
   else
     {
@@ -2233,9 +2235,7 @@ g_bookmark_file_set_description (GBookmarkFile *bookmark,
         }
       
       g_free (item->description);
-      
-      if (description && description[0] != '\0')
-        item->description = g_strdup (description);
+      item->description = g_strdup (description);
       
       item->modified = time (NULL);
     }
@@ -3084,7 +3084,7 @@ g_bookmark_file_remove_application (GBookmarkFile  *bookmark,
   set_error = NULL;
   retval = g_bookmark_file_set_app_info (bookmark, uri,
                                         name,
-                                        NULL,
+                                        "",
                                         0,
                                         (time_t) -1,
                                         &set_error);
@@ -3290,14 +3290,16 @@ expand_exec_line (const gchar *exec_fmt,
      ch = *exec_fmt++;
      switch (ch)
        {
+       case '\0':
+        goto out;
        case 'u':
-         g_string_append_printf (exec, "%s", uri);
+         g_string_append (exec, uri);
          break;
        case 'f':
          {
-         gchar *file = g_filename_from_uri (uri, NULL, NULL);
-         g_string_append_printf (exec, "%s", file);
-         g_free (file);
+          gchar *file = g_filename_from_uri (uri, NULL, NULL);
+          g_string_append (exec, file);
+          g_free (file);
          }
          break;
        case '%':
@@ -3307,6 +3309,7 @@ expand_exec_line (const gchar *exec_fmt,
        }
    }
    
+ out:
   return g_string_free (exec, FALSE);
 }
 
@@ -3506,7 +3509,7 @@ g_bookmark_file_move_item (GBookmarkFile  *bookmark,
   
   g_return_val_if_fail (bookmark != NULL, FALSE);
   g_return_val_if_fail (old_uri != NULL, FALSE);
-  
+
   item = g_bookmark_file_lookup_item (bookmark, old_uri);
   if (!item)
     {
@@ -3530,11 +3533,15 @@ g_bookmark_file_move_item (GBookmarkFile  *bookmark,
               return FALSE;
             }
         }
+
+      g_hash_table_steal (bookmark->items_by_uri, item->uri);
       
       g_free (item->uri);
       item->uri = g_strdup (new_uri);
       item->modified = time (NULL);
-      
+
+      g_hash_table_replace (bookmark->items_by_uri, item->uri, item);
+
       return TRUE;
     }
   else
@@ -3547,9 +3554,9 @@ g_bookmark_file_move_item (GBookmarkFile  *bookmark,
           
           return FALSE;
         }
+
+      return TRUE;
     }
-  
-  return FALSE;
 }
 
 /**
@@ -3590,8 +3597,7 @@ g_bookmark_file_set_icon (GBookmarkFile *bookmark,
   g_free (item->metadata->icon_href);
   g_free (item->metadata->icon_mime);
   
-  if (href && href[0] != '\0')
-    item->metadata->icon_href = g_strdup (href);
+  item->metadata->icon_href = g_strdup (href);
   
   if (mime_type && mime_type[0] != '\0')
     item->metadata->icon_mime = g_strdup (mime_type);