From: Guillaume Desmottes Date: Thu, 15 Mar 2012 13:55:39 +0000 (+0100) Subject: factor out account_is_selected() X-Git-Url: https://git.0d.be/?p=empathy.git;a=commitdiff_plain;h=500ef8529e04b2e1606f35d9c0697ef96423a828 factor out account_is_selected() https://bugzilla.gnome.org/show_bug.cgi?id=671035 --- diff --git a/src/empathy-accounts-dialog.c b/src/empathy-accounts-dialog.c index 189f22b5..847e1a55 100644 --- a/src/empathy-accounts-dialog.c +++ b/src/empathy-accounts-dialog.c @@ -277,6 +277,32 @@ install_haze_cb (GObject *source, } } +static gboolean +account_is_selected (EmpathyAccountsDialog *dialog, + TpAccount *account) +{ + EmpathyAccountsDialogPriv *priv = GET_PRIV (dialog); + GtkTreeSelection *selection; + GtkTreeModel *model; + GtkTreeIter iter; + TpAccount *selected_account; + + if (account == NULL) + return FALSE; + + selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->treeview)); + + if (!gtk_tree_selection_get_selected (selection, &model, &iter)) + return FALSE; + + gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1); + + if (selected_account != NULL) + g_object_unref (selected_account); + + return account == selected_account; +} + static void accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, TpAccount *account) @@ -286,28 +312,13 @@ accounts_dialog_update_status_infobar (EmpathyAccountsDialog *dialog, guint status; guint reason; guint presence; - GtkTreeView *view; - GtkTreeModel *model; - GtkTreeSelection *selection; - GtkTreeIter iter; - TpAccount *selected_account; gboolean account_enabled; gboolean creating_account; TpStorageRestrictionFlags storage_restrictions = 0; gboolean display_switch = TRUE; - view = GTK_TREE_VIEW (priv->treeview); - selection = gtk_tree_view_get_selection (view); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - return; - - gtk_tree_model_get (model, &iter, COL_ACCOUNT, &selected_account, -1); - if (selected_account != NULL) - g_object_unref (selected_account); - /* do not update the infobar when the account is not selected */ - if (account != selected_account) + if (!account_is_selected (dialog, account)) return; if (account != NULL)