Use GIOChannel to import Opera bookmarks

The workaround for long lines is no longer needed.
This commit is contained in:
Paweł Forysiuk 2010-12-30 20:05:16 +01:00 committed by Christian Dywan
parent 47ae7b475b
commit e96ac0fabc

View file

@ -295,17 +295,27 @@ katze_array_from_xmlDocPtr (KatzeArray* array,
static gboolean static gboolean
katze_array_from_opera_file (KatzeArray* array, katze_array_from_opera_file (KatzeArray* array,
FILE* file) const gchar* filename)
{ {
gchar line[200]; gchar* line = NULL;
gchar* partial_line = NULL; GIOChannel* channel = g_io_channel_new_file (filename, "r", 0);
KatzeArray* folder = array; KatzeArray* folder = array;
KatzeItem* item = NULL; 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); 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') if (line[0] == '\0')
{ {
item = NULL; item = NULL;
@ -340,30 +350,7 @@ katze_array_from_opera_file (KatzeArray* array,
} }
else if (item) else if (item)
{ {
gchar** parts; gchar** parts = g_strsplit (line, "=", 2);
/* 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);
if (parts && parts[0] && parts[1]) if (parts && parts[0] && parts[1])
{ {
@ -392,6 +379,8 @@ katze_array_from_opera_file (KatzeArray* array,
else else
g_warning ("Unexpected property outside of element: %s", line); g_warning ("Unexpected property outside of element: %s", line);
} }
g_io_channel_shutdown (channel, FALSE, 0);
g_io_channel_unref (channel);
return TRUE; return TRUE;
} }
@ -454,7 +443,7 @@ midori_array_from_file (KatzeArray* array,
verify++; verify++;
else if (verify == 2) else if (verify == 2)
{ {
if (!katze_array_from_opera_file (array, file)) if (!katze_array_from_opera_file (array, filename))
{ {
/* Parsing failed */ /* Parsing failed */
fclose (file); fclose (file);