From 36ee35009dc6a0e85be95ed9a1757c589582e4e8 Mon Sep 17 00:00:00 2001 From: Emilio Pozuelo Monfort Date: Mon, 9 May 2011 19:53:32 +0100 Subject: LogWindow: better logic for the buttons sensitivity --- libempathy-gtk/empathy-log-window.c | 67 ++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 12 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-log-window.c b/libempathy-gtk/empathy-log-window.c index e1c9856cb..648a6af6f 100644 --- a/libempathy-gtk/empathy-log-window.c +++ b/libempathy-gtk/empathy-log-window.c @@ -1499,9 +1499,60 @@ log_window_search_entry_icon_pressed_cb (GtkEntry *entry, "", -1); } -/* - * Chats Code - */ +static void +log_window_update_buttons_sensitivity (EmpathyLogWindow *window, + GtkTreeModel *model, + GtkTreeSelection *selection) +{ + EmpathyContact *contact; + EmpathyCapabilities capabilities; + TpAccount *account; + TplEntity *target; + GtkTreeIter iter; + GList *paths; + GtkTreePath *path; + gboolean profile, chat, call, video; + + profile = chat = call = video = FALSE; + + if (!gtk_tree_model_get_iter_first (model, &iter)) + goto out; + + if (gtk_tree_selection_count_selected_rows (selection) != 1) + goto out; + + if (gtk_tree_selection_iter_is_selected (selection, &iter)) + goto out; + + paths = gtk_tree_selection_get_selected_rows (selection, &model); + g_return_if_fail (paths != NULL); + + path = paths->data; + gtk_tree_model_get_iter (model, &iter, path); + gtk_tree_model_get (model, &iter, + COL_WHO_ACCOUNT, &account, + COL_WHO_TARGET, &target, + -1); + + g_list_free_full (paths, (GDestroyNotify) gtk_tree_path_free); + + contact = empathy_contact_from_tpl_contact (account, target); + + g_object_unref (account); + g_object_unref (target); + + capabilities = empathy_contact_get_capabilities (contact); + + profile = chat = TRUE; + call = capabilities & EMPATHY_CAPABILITIES_AUDIO; + video = capabilities & EMPATHY_CAPABILITIES_VIDEO; + + out: + gtk_widget_set_sensitive (window->button_profile, profile); + gtk_widget_set_sensitive (window->button_chat, chat); + gtk_widget_set_sensitive (window->button_call, call); + gtk_widget_set_sensitive (window->button_video, video); +} static void log_window_who_changed_cb (GtkTreeSelection *selection, @@ -1510,7 +1561,6 @@ log_window_who_changed_cb (GtkTreeSelection *selection, GtkTreeView *view; GtkTreeModel *model; GtkTreeIter iter; - gboolean someone = FALSE; DEBUG ("log_window_who_changed_cb"); @@ -1533,16 +1583,9 @@ log_window_who_changed_cb (GtkTreeSelection *selection, log_window_who_changed_cb, window); } - else if (gtk_tree_selection_count_selected_rows (selection) == 1) - { - someone = TRUE; - } } - gtk_widget_set_sensitive (window->button_profile, someone); - gtk_widget_set_sensitive (window->button_chat, someone); - gtk_widget_set_sensitive (window->button_call, someone); - gtk_widget_set_sensitive (window->button_video, someone); + log_window_update_buttons_sensitivity (window, model, selection); /* The contact changed, so the dates need to be updated */ log_window_chats_get_messages (window, TRUE); -- cgit v1.2.3