]> git.0d.be Git - empathy.git/commitdiff
factor out account_is_selected()
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 15 Mar 2012 13:55:39 +0000 (14:55 +0100)
committerGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Thu, 15 Mar 2012 15:14:31 +0000 (16:14 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=671035

src/empathy-accounts-dialog.c

index 189f22b58fefeb750a11cf7a66856a983a62a648..847e1a55ef7892c163e17b96c2df56f8779fd85b 100644 (file)
@@ -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)