[Xfce4-commits] <midori:master> Use GIOChannel to import Opera bookmarks

Christian Dywan noreply at xfce.org
Sat Jan 1 01:58:01 CET 2011


Updating branch refs/heads/master
         to e96ac0fabc6fd747dba589193782ebc39cc2cfdd (commit)
       from 47ae7b475b42b3a9f345ca42f4833eeb08c8af08 (commit)

commit e96ac0fabc6fd747dba589193782ebc39cc2cfdd
Author: Paweł Forysiuk <tuxator at o2.pl>
Date:   Thu Dec 30 20:05:16 2010 +0100

    Use GIOChannel to import Opera bookmarks
    
    The workaround for long lines is no longer needed.

 midori/midori-array.c |   49 +++++++++++++++++++------------------------------
 1 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/midori/midori-array.c b/midori/midori-array.c
index 25c68d0..9c2d4c2 100644
--- a/midori/midori-array.c
+++ b/midori/midori-array.c
@@ -295,17 +295,27 @@ katze_array_from_xmlDocPtr (KatzeArray* array,
 
 static gboolean
 katze_array_from_opera_file (KatzeArray* array,
-                             FILE*       file)
+                             const gchar*  filename)
 {
-    gchar line[200];
-    gchar* partial_line = NULL;
+    gchar* line = NULL;
+    GIOChannel* channel = g_io_channel_new_file (filename, "r", 0);
     KatzeArray* folder = array;
     KatzeItem* item = NULL;
 
-    while (fgets (line, 200, file))
+    if (!channel)
+        return FALSE;
+
+    while (g_io_channel_read_line (channel, &line, NULL, NULL, NULL)
+            == G_IO_STATUS_NORMAL)
     {
-        gboolean incomplete_line = (strlen (line) == 199);
         g_strstrip (line);
+        /* skip file header */
+        if (katze_str_equal (line, "Options: encoding = utf8, version=3")
+            || katze_str_equal (line, "Opera Hotlist version 2.0"))
+        {
+            item = NULL;
+            continue;
+        }
         if (line[0] == '\0')
         {
             item = NULL;
@@ -340,30 +350,7 @@ katze_array_from_opera_file (KatzeArray* array,
         }
         else if (item)
         {
-            gchar** parts;
-
-            /* Handle lines longer than 200 characters */
-            if (incomplete_line)
-            {
-                if (partial_line)
-                {
-                    gchar* chunk = g_strconcat (partial_line, line, NULL);
-                    katze_assign (partial_line, chunk);
-                }
-                else
-                    partial_line = g_strdup (line);
-                continue;
-            }
-
-            if (partial_line)
-            {
-                gchar* full_line = g_strconcat (partial_line, line, NULL);
-                katze_assign (partial_line, NULL);
-                parts = g_strsplit (full_line, "=", 2);
-                g_free (full_line);
-            }
-            else
-                parts = g_strsplit (line, "=", 2);
+            gchar** parts = g_strsplit (line, "=", 2);
 
             if (parts && parts[0] && parts[1])
             {
@@ -392,6 +379,8 @@ katze_array_from_opera_file (KatzeArray* array,
         else
             g_warning ("Unexpected property outside of element: %s", line);
     }
+    g_io_channel_shutdown (channel, FALSE, 0);
+    g_io_channel_unref (channel);
     return TRUE;
 }
 
@@ -454,7 +443,7 @@ midori_array_from_file (KatzeArray*  array,
                     verify++;
                 else if (verify == 2)
                 {
-                    if (!katze_array_from_opera_file (array, file))
+                    if (!katze_array_from_opera_file (array, filename))
                     {
                         /* Parsing failed */
                         fclose (file);



More information about the Xfce4-commits mailing list