From: Paweł Forysiuk Date: Mon, 31 Jan 2011 23:52:31 +0000 (+0100) Subject: Add support for exporting to Netscape HTML X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ab7b06976976b45f24fd4a48ff45882b11f9fa3a;p=midori Add support for exporting to Netscape HTML --- diff --git a/midori/midori-array.c b/midori/midori-array.c index 021afffa..c5582583 100644 --- a/midori/midori-array.c +++ b/midori/midori-array.c @@ -702,6 +702,48 @@ string_append_item (GString* string, g_free (metadata); } +static void +string_append_netscape_item (GString* string, + KatzeItem* item) +{ + g_return_if_fail (KATZE_IS_ITEM (item)); + + if (KATZE_IS_ARRAY (item)) + { + KatzeItem* _item; + KatzeArray* array = KATZE_ARRAY (item); + GList* list; + + g_string_append (string, "\t

"); + g_string_append (string, katze_item_get_name (item)); + g_string_append (string, "

\n"); + g_string_append (string, "\t

\n"); + KATZE_ARRAY_FOREACH_ITEM_L (_item, array, list) + { + g_string_append (string, "\t"); + string_append_netscape_item (string, _item); + } + g_string_append (string, "\t

\n"); + + g_list_free (list); + } + else if (katze_item_get_uri (item)) + { + g_string_append (string, "\t

"); + g_string_append (string, katze_item_get_name (item)); + g_string_append (string, "\n"); + + if (item->text && g_strcmp0 (item->text, "")) + { + g_string_append (string, "\t
"); + g_string_append (string, katze_item_get_text (item)); + g_string_append (string, "\n"); + } + } +} + static gchar* katze_item_metadata_to_xbel (KatzeItem* item) { @@ -788,15 +830,48 @@ katze_array_to_xbel (KatzeArray* array, return g_string_free (markup, FALSE); } +static gchar* +katze_array_to_netscape_html (KatzeArray* array, + GError** error) +{ + KatzeItem* item; + GList* list; + + /* The header, including the text, is the same as used in other browsers, + see http://msdn.microsoft.com/en-us/library/aa753582(v=vs.85).aspx */ + GString* markup = g_string_new ( + "\n" + "\n" + "\n" + "Bookmarks\n" + "

Bookmarks

\n" + "\n"); + g_string_append (markup, "

\n"); + KATZE_ARRAY_FOREACH_ITEM_L (item, array, list) + string_append_netscape_item (markup, item); + g_string_append (markup, "

\n"); + + g_list_free (list); + return g_string_free (markup, FALSE); +} + static gboolean -midori_array_to_file_xbel (KatzeArray* array, - const gchar* filename, - GError** error) +midori_array_to_file_format (KatzeArray* array, + const gchar* filename, + const gchar* format, + GError** error) { gchar* data; FILE* fp; - if (!(data = katze_array_to_xbel (array, error))) + if (!g_strcmp0 (format, "xbel")) + data = katze_array_to_xbel (array, error); + if (!g_strcmp0 (format, "netscape")) + data = katze_array_to_netscape_html (array, error); + + if (!data) return FALSE; if (!(fp = fopen (filename, "w"))) { @@ -833,8 +908,10 @@ midori_array_to_file (KatzeArray* array, g_return_val_if_fail (filename, FALSE); g_return_val_if_fail (!error || !*error, FALSE); - if (!g_strcmp0 (format, "xbel")) - return midori_array_to_file_xbel (array, filename, error); + if (!g_strcmp0 (format, "xbel") + || !g_strcmp0 (format, "netscape")) + return midori_array_to_file_format (array, filename, format, error); + g_critical ("Cannot write KatzeArray to unknown format '%s'.", format); return FALSE; }