diff --git a/midori/main.c b/midori/main.c index c31b4754..a52f521b 100644 --- a/midori/main.c +++ b/midori/main.c @@ -50,6 +50,12 @@ #include #endif +#if HAVE_HILDON + #define BOOKMARK_FILE "/home/user/.bookmarks/MyBookmarks.xml" +#else + #define BOOKMARK_FILE "bookmarks.xbel" +#endif + #define MIDORI_HISTORY_ERROR g_quark_from_string("MIDORI_HISTORY_ERROR") typedef enum @@ -62,7 +68,11 @@ typedef enum static gchar* build_config_filename (const gchar* filename) { - const gchar* path = sokoke_set_config_dir (NULL); + const gchar* path; + + if (g_path_is_absolute (filename)) + return g_strdup (filename); + path = sokoke_set_config_dir (NULL); return g_build_filename (path, filename, NULL); } @@ -805,7 +815,7 @@ midori_bookmarks_notify_item_cb (KatzeArray* folder, gchar* config_file; GError* error; - config_file = build_config_filename ("bookmarks.xbel"); + config_file = build_config_filename (BOOKMARK_FILE); error = NULL; if (!midori_array_to_file (bookmarks, config_file, "xbel", &error)) { @@ -833,7 +843,7 @@ midori_bookmarks_add_item_cb (KatzeArray* folder, gchar* config_file; GError* error; - config_file = build_config_filename ("bookmarks.xbel"); + config_file = build_config_filename (BOOKMARK_FILE); error = NULL; if (!midori_array_to_file (bookmarks, config_file, "xbel", &error)) { @@ -862,7 +872,7 @@ midori_bookmarks_remove_item_cb (KatzeArray* folder, gchar* config_file; GError* error; - config_file = build_config_filename ("bookmarks.xbel"); + config_file = build_config_filename (BOOKMARK_FILE); error = NULL; if (!midori_array_to_file (bookmarks, config_file, "xbel", &error)) { @@ -1864,7 +1874,7 @@ main (int argc, } bookmarks = katze_array_new (KATZE_TYPE_ARRAY); #if HAVE_LIBXML - katze_assign (config_file, build_config_filename ("bookmarks.xbel")); + katze_assign (config_file, build_config_filename (BOOKMARK_FILE)); error = NULL; if (!midori_array_from_file (bookmarks, config_file, "xbel", &error)) { @@ -2016,8 +2026,9 @@ main (int argc, G_CALLBACK (midori_search_engines_modify_cb), search_engines); } } - katze_assign (config_file, build_config_filename ("bookmarks.xbel")); - if (1) + katze_assign (config_file, build_config_filename (BOOKMARK_FILE)); + /* Don't save bookmarks if they are not our own */ + if (!g_path_is_absolute (BOOKMARK_FILE)) { g_signal_connect_after (bookmarks, "add-item", G_CALLBACK (midori_bookmarks_add_item_cb), bookmarks); diff --git a/midori/midori-array.c b/midori/midori-array.c index e68a3077..18aeece0 100644 --- a/midori/midori-array.c +++ b/midori/midori-array.c @@ -93,11 +93,13 @@ katze_array_from_xmlNodePtr (xmlNodePtr cur) { key = xmlNodeGetContent (cur); katze_item_set_name (KATZE_ITEM (array), g_strstrip ((gchar*)key)); + xmlFree (key); } else if (!xmlStrcmp (cur->name, (const xmlChar*)"desc")) { key = xmlNodeGetContent (cur); katze_item_set_text (KATZE_ITEM (array), g_strstrip ((gchar*)key)); + xmlFree (key); } else if (!xmlStrcmp (cur->name, (const xmlChar*)"folder")) { @@ -129,19 +131,26 @@ katze_xbel_parse_info (KatzeItem* item, if (!xmlStrcmp (cur->name, (const xmlChar*)"metadata")) { xmlChar* owner = xmlGetProp (cur, (xmlChar*)"owner"); - g_strstrip ((gchar*)owner); + if (owner) + g_strstrip ((gchar*)owner); + else + /* Albeit required, "owner" is not set by MicroB */ + owner = (xmlChar*)NULL; /* FIXME: Save metadata from unknown owners */ - if (!g_strcmp0 ((gchar*)owner, "http://www.twotoasts.de")) + if (!owner || !strcmp ((gchar*)owner, "http://www.twotoasts.de")) { xmlAttrPtr properties = cur->properties; + xmlNodePtr children = cur->children; while (properties) { + xmlChar* value; + if (!xmlStrcmp (properties->name, (xmlChar*)"owner")) { properties = properties->next; continue; } - xmlChar* value = xmlGetProp (cur, properties->name); + value = xmlGetProp (cur, properties->name); if (properties->ns && properties->ns->prefix) { gchar* ns_value = g_strdup_printf ("%s:%s", @@ -156,6 +165,26 @@ katze_xbel_parse_info (KatzeItem* item, xmlFree (value); properties = properties->next; } + while (children) + { + xmlNodePtr grand_children = children->children; + while (grand_children) + { + xmlChar* value = grand_children->content; + gchar* ns_value; + if (!owner) + ns_value = g_strdup_printf (":%s", children->name); + else if (xmlStrEqual (owner, (xmlChar*)"http://www.twotoasts.de")) + ns_value = g_strdup_printf ("midori:%s", children->name); + else /* FIXME: Save metadata from unknown owners */ + ns_value = g_strdup_printf (":%s", children->name); + katze_item_set_meta_string (item, ns_value, (gchar*)value); + g_free (ns_value); + grand_children = grand_children->next; + } + + children = children->next; + } } xmlFree (owner); } @@ -211,6 +240,16 @@ katze_array_from_xmlDocPtr (KatzeArray* array, item = katze_item_new (); else if (!xmlStrcmp (cur->name, (const xmlChar*)"info")) katze_xbel_parse_info (KATZE_ITEM (array), cur); + else if (!xmlStrcmp (cur->name, (xmlChar*)"title")) + { + xmlNodePtr node = cur->xmlChildrenNode; + katze_item_set_name (KATZE_ITEM (array), (gchar*)node->content); + } + else if (!xmlStrcmp (cur->name, (xmlChar*)"desc")) + { + xmlNodePtr node = cur->xmlChildrenNode; + katze_item_set_text (KATZE_ITEM (array), (gchar*)node->content); + } if (item) katze_array_add_item (array, item); cur = cur->next; @@ -480,28 +519,47 @@ katze_item_metadata_to_xbel (KatzeItem* item) { GList* keys = katze_item_get_meta_keys (item); GString* markup; - /* FIXME: Allow specifying an alternative namespace/ URI */ - const gchar* namespace_uri = "http://www.twotoasts.de"; - const gchar* namespace = "midori"; + GString* markdown; + /* FIXME: Allow specifying an alternative default namespace */ + /* FIXME: Support foreign namespaces with their own URI */ + gchar* namespace = NULL; + const gchar* namespace_uri; gsize i; const gchar* key; + const gchar* value; if (!keys) return g_strdup (""); - markup = g_string_new ("\n\n%s\n", key, escaped, key); + } + else if (namespace) + g_string_append_printf (markup, " %s=\"%s\"", key, escaped); + else + g_string_append_printf (markup, " midori:%s=\"%s\"", key, escaped); g_free (escaped); } - g_string_append_printf (markup, "/>\n\n"); + if (!namespace) + { + namespace_uri = "http://www.twotoasts.de"; + g_string_append_printf (markup, " owner=\"%s\"", namespace_uri); + } + if (markdown->len) + g_string_append_printf (markup, ">\n%s\n\n", markdown->str); + else + g_string_append_printf (markup, "/>\n\n"); + g_string_free (markdown, TRUE); return g_string_free (markup, FALSE); }