diff options
author | Jonny Lamb <jonny.lamb@collabora.co.uk> | 2008-10-17 20:47:45 +0800 |
---|---|---|
committer | Xavier Claessens <xclaesse@src.gnome.org> | 2008-10-17 20:47:45 +0800 |
commit | 53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a (patch) | |
tree | d47ce6783552ea2ac1b1739d0793bfcbaef2e843 | |
parent | a485f119dae6addfa5f1b186a0df6e2d7da04767 (diff) | |
download | gsoc2013-empathy-53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a.tar gsoc2013-empathy-53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a.tar.gz gsoc2013-empathy-53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a.tar.bz2 gsoc2013-empathy-53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a.tar.lz gsoc2013-empathy-53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a.tar.xz gsoc2013-empathy-53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a.tar.zst gsoc2013-empathy-53b4129ff7bc11c8f3f2c2a608778840c1e9ba8a.zip |
Moved some code around for clarity and also to parse accounts before the Glade file is loaded. (Jonny Lamb)
This prevents the glade being parsed, all the widgets being set up, and
then a single message dialog popping up saying there are no accounts to
import, just to then free it all.
Signed-off-by: Jonny Lamb <jonny.lamb@collabora.co.uk>
svn path=/trunk/; revision=1629
-rw-r--r-- | src/empathy-import-dialog.c | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/src/empathy-import-dialog.c b/src/empathy-import-dialog.c index 4a08bcee9..546109d87 100644 --- a/src/empathy-import-dialog.c +++ b/src/empathy-import-dialog.c @@ -102,6 +102,7 @@ typedef struct GtkWidget *button_ok; GtkWidget *button_cancel; gboolean not_imported; + GList *accounts; } EmpathyImportDialog; #define PIDGIN_ACCOUNT_TAG_NAME "name" @@ -460,7 +461,9 @@ import_dialog_tree_model_foreach (GtkTreeModel *model, static void import_dialog_free (EmpathyImportDialog *dialog) { - gtk_widget_destroy (dialog->window); + if (dialog->window) + gtk_widget_destroy (dialog->window); + g_list_free (dialog->accounts); g_slice_free (EmpathyImportDialog, dialog); } @@ -519,21 +522,16 @@ import_dialog_filter_mc_accounts (McAccount *account, return !result; } -static gboolean +static void import_dialog_add_accounts_to_model (EmpathyImportDialog *dialog) { GtkTreeModel *model; GtkTreeIter iter; - GList *accounts, *account; - guint length; + GList *account; model = gtk_tree_view_get_model (GTK_TREE_VIEW (dialog->treeview)); - accounts = import_dialog_pidgin_load (); - - length = g_list_length (accounts); - - for (account = accounts; account; account = account->next) + for (account = dialog->accounts; account; account = account->next) { GValue *value, *account_data; AccountData *data = (AccountData *) account->data; @@ -576,26 +574,6 @@ import_dialog_add_accounts_to_model (EmpathyImportDialog *dialog) COL_ACCOUNT_DATA, account_data, -1); } - - g_list_free (accounts); - - if (length == 0) - { - GtkWidget *message; - - message = gtk_message_dialog_new ( - gtk_window_get_transient_for (GTK_WINDOW (dialog->window)), - GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, - _("No accounts to import could be found. Empathy currently only " - "supports importing accounts from Pidgin.")); - - gtk_dialog_run (GTK_DIALOG (message)); - gtk_widget_destroy (message); - import_dialog_free (dialog); - return FALSE; - } - else - return TRUE; } static void @@ -619,7 +597,7 @@ import_dialog_cell_toggled_cb (GtkCellRendererToggle *cell_renderer, gtk_tree_path_free (path); } -static gboolean +static void import_dialog_set_up_account_list (EmpathyImportDialog *dialog) { GtkListStore *store; @@ -687,7 +665,7 @@ import_dialog_set_up_account_list (EmpathyImportDialog *dialog) gtk_tree_view_column_pack_start (column, cell, TRUE); gtk_tree_view_column_add_attribute (column, cell, "text", COL_SOURCE); - return import_dialog_add_accounts_to_model (dialog); + import_dialog_add_accounts_to_model (dialog); } void @@ -705,6 +683,24 @@ empathy_import_dialog_show (GtkWindow *parent) dialog = g_slice_new0 (EmpathyImportDialog); + dialog->accounts = import_dialog_pidgin_load (); + + if (g_list_length (dialog->accounts) == 0) + { + GtkWidget *message; + + message = gtk_message_dialog_new (parent, + GTK_DIALOG_MODAL, GTK_MESSAGE_WARNING, GTK_BUTTONS_CLOSE, + _("No accounts to import could be found. Empathy currently only " + "supports importing accounts from Pidgin.")); + + gtk_dialog_run (GTK_DIALOG (message)); + gtk_widget_destroy (message); + import_dialog_free (dialog); + dialog = NULL; + return; + } + filename = empathy_file_lookup ("empathy-import-dialog.glade", "src"); glade = empathy_glade_get_file (filename, "import_dialog", @@ -727,6 +723,7 @@ empathy_import_dialog_show (GtkWindow *parent) if (parent) gtk_window_set_transient_for (GTK_WINDOW (dialog->window), parent); - if (import_dialog_set_up_account_list (dialog)) - gtk_widget_show (dialog->window); + import_dialog_set_up_account_list (dialog); + + gtk_widget_show (dialog->window); } |