From ec64c0ae745a2ea34556565cefaf263b31117b38 Mon Sep 17 00:00:00 2001 From: Jonny Lamb Date: Fri, 17 Oct 2008 12:46:32 +0000 Subject: Simplified the node looping code further. (Jonny Lamb) Signed-off-by: Jonny Lamb svn path=/trunk/; revision=1607 --- src/empathy-import-dialog.c | 135 ++++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 69 deletions(-) (limited to 'src/empathy-import-dialog.c') diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index d6d28eee2..89792f77a 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -276,92 +276,89 @@ empathy_import_dialog_pidgin_import_accounts () for (node = rootnode->children; node; node = node->next) { - if (strcmp ((gchar *) node->name, PIDGIN_ACCOUNT_TAG_ACCOUNT) == 0) - { - child = node->children; + if (strcmp ((gchar *) node->name, PIDGIN_ACCOUNT_TAG_ACCOUNT) != 0) + continue; + + settings = g_hash_table_new (g_str_hash, g_str_equal); - settings = g_hash_table_new (g_str_hash, g_str_equal); + for (child = node->children; child; child = child->next) + { - while (child) + if (strcmp ((gchar *) child->name, + PIDGIN_ACCOUNT_TAG_PROTOCOL) == 0) { + protocol = (gchar *) xmlNodeGetContent (child); - if (strcmp ((gchar *) child->name, - PIDGIN_ACCOUNT_TAG_PROTOCOL) == 0) - { - protocol = (gchar *) xmlNodeGetContent (child); + if (g_str_has_prefix (protocol, "prpl-")) + protocol = strchr (protocol, '-') + 1; - if (g_str_has_prefix (protocol, "prpl-")) - protocol = strchr (protocol, '-') + 1; + if (strcmp (protocol, PIDGIN_PROTOCOL_BONJOUR) == 0) + protocol = "salut"; + else if (strcmp (protocol, PIDGIN_PROTOCOL_NOVELL) == 0) + protocol = "groupwise"; - if (strcmp (protocol, PIDGIN_PROTOCOL_BONJOUR) == 0) - protocol = "salut"; - else if (strcmp (protocol, PIDGIN_PROTOCOL_NOVELL) == 0) - protocol = "groupwise"; + empathy_import_dialog_add_setting (settings, "protocol", + (gpointer) protocol, + EMPATHY_IMPORT_SETTING_TYPE_STRING); - empathy_import_dialog_add_setting (settings, "protocol", - (gpointer) protocol, - EMPATHY_IMPORT_SETTING_TYPE_STRING); + } + else if (strcmp ((gchar *) child->name, + PIDGIN_ACCOUNT_TAG_NAME) == 0) + { + name = (gchar *) xmlNodeGetContent (child); - } - else if (strcmp ((gchar *) child->name, - PIDGIN_ACCOUNT_TAG_NAME) == 0) + if (g_strrstr (name, "/") != NULL) { - name = (gchar *) xmlNodeGetContent (child); - - if (g_strrstr (name, "/") != NULL) - { - gchar **name_resource; - name_resource = g_strsplit (name, "/", 2); - username = g_strdup(name_resource[0]); - g_free (name_resource); - } - else - username = name; - - if (strstr (name, "@") && strcmp (protocol, "irc") == 0) - { - gchar **nick_server; - nick_server = g_strsplit (name, "@", 2); - username = nick_server[0]; - empathy_import_dialog_add_setting (settings, - "server", (gpointer) nick_server[1], - EMPATHY_IMPORT_SETTING_TYPE_STRING); - } - - empathy_import_dialog_add_setting (settings, "account", - (gpointer) username, EMPATHY_IMPORT_SETTING_TYPE_STRING); - + gchar **name_resource; + name_resource = g_strsplit (name, "/", 2); + username = g_strdup(name_resource[0]); + g_free (name_resource); } - else if (strcmp ((gchar *) child->name, - PIDGIN_ACCOUNT_TAG_PASSWORD) == 0) - { - empathy_import_dialog_add_setting (settings, "password", - (gpointer) xmlNodeGetContent (child), - EMPATHY_IMPORT_SETTING_TYPE_STRING); + else + username = name; + + if (strstr (name, "@") && strcmp (protocol, "irc") == 0) + { + gchar **nick_server; + nick_server = g_strsplit (name, "@", 2); + username = nick_server[0]; + empathy_import_dialog_add_setting (settings, + "server", (gpointer) nick_server[1], + EMPATHY_IMPORT_SETTING_TYPE_STRING); + } + + empathy_import_dialog_add_setting (settings, "account", + (gpointer) username, EMPATHY_IMPORT_SETTING_TYPE_STRING); - } - else if (strcmp ((gchar *) child->name, - PIDGIN_ACCOUNT_TAG_SETTINGS) == 0) - { - setting = child->children; + } + else if (strcmp ((gchar *) child->name, + PIDGIN_ACCOUNT_TAG_PASSWORD) == 0) + { + empathy_import_dialog_add_setting (settings, "password", + (gpointer) xmlNodeGetContent (child), + EMPATHY_IMPORT_SETTING_TYPE_STRING); - while (setting) - { - empathy_import_dialog_pidgin_parse_setting (protocol, - setting, settings); - setting = setting->next; - } + } + else if (strcmp ((gchar *) child->name, + PIDGIN_ACCOUNT_TAG_SETTINGS) == 0) + { + setting = child->children; + while (setting) + { + empathy_import_dialog_pidgin_parse_setting (protocol, + setting, settings); + setting = setting->next; } - child = child->next; + } + } - if (g_hash_table_size (settings) > 0) - empathy_import_dialog_add_account (protocol, settings); + if (g_hash_table_size (settings) > 0) + empathy_import_dialog_add_account (protocol, settings); - g_free (username); - g_hash_table_unref (settings); - } + g_free (username); + g_hash_table_unref (settings); } -- cgit v1.2.3