]> git.0d.be Git - empathy.git/commitdiff
Applied Xavier's comments
authorGabriel Millaire <millaire.gabriel@gmail.com>
Sun, 31 May 2009 21:35:27 +0000 (17:35 -0400)
committerXavier Claessens <xclaesse@gmail.com>
Thu, 18 Jun 2009 10:34:37 +0000 (12:34 +0200)
Added "show-contacts" property in empathy-chat with default value to preference.
Setter function show/hide contact list.
When Conv menu is opened in empathy-chat-window, update it with "show-contacts" value.
Uses "remote-contact" instead of "empathy_chat_is_room" for that.
Call setter function when Show Contacts menu is activated.

libempathy-gtk/empathy-chat.c
libempathy-gtk/empathy-chat.h
src/empathy-chat-window.c

index 69ada3a8139ac58576be8aaa784640aa62787719..ab31c608ede48f1b915f324d5f2771a751a937d6 100644 (file)
@@ -69,6 +69,7 @@ typedef struct {
        gchar             *name;
        gchar             *subject;
        EmpathyContact    *remote_contact;
+       gboolean           show_contacts;
 
        EmpathyLogManager *log_manager;
        EmpathyAccountManager *account_manager;
@@ -81,7 +82,6 @@ typedef struct {
        TpHandleType       handle_type;
        gint               contacts_width;
        gboolean           has_input_vscroll;
-       guint              notify_id; /* show contacts' notification */
 
        GtkWidget         *widget;
        GtkWidget         *hpaned;
@@ -108,6 +108,7 @@ enum {
        PROP_NAME,
        PROP_SUBJECT,
        PROP_REMOTE_CONTACT,
+       PROP_SHOW_CONTACTS,
 };
 
 static guint signals[LAST_SIGNAL] = { 0 };
@@ -142,6 +143,9 @@ chat_get_property (GObject    *object,
        case PROP_REMOTE_CONTACT:
                g_value_set_object (value, priv->remote_contact);
                break;
+       case PROP_SHOW_CONTACTS:
+               g_value_set_boolean (value, priv->show_contacts);
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -160,6 +164,9 @@ chat_set_property (GObject      *object,
        case PROP_TP_CHAT:
                empathy_chat_set_tp_chat (chat, EMPATHY_TP_CHAT (g_value_get_object (value)));
                break;
+       case PROP_SHOW_CONTACTS:
+               empathy_chat_set_show_contacts (chat, g_value_get_boolean (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
                break;
@@ -1188,21 +1195,19 @@ chat_reset_size_request (gpointer widget)
        return FALSE;
 }
 
-static void
-chat_set_show_contacts (EmpathyChat *chat, gboolean show)
+void
+empathy_chat_set_show_contacts (EmpathyChat *chat,
+                               gboolean     show)
 {
-       gboolean conf_show;
        EmpathyChatPriv *priv = GET_PRIV (chat);
+       
+       priv->show_contacts = show;
 
        if (!priv->scrolled_window_contacts) {
                return;
-       }       
+       }               
 
-       empathy_conf_get_bool (empathy_conf_get (),
-                              EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
-                              &conf_show);
-
-       if (show && conf_show) {
+       if (show) {
                EmpathyContactListStore *store;
                gint                     min_width;
 
@@ -1243,22 +1248,11 @@ chat_set_show_contacts (EmpathyChat *chat, gboolean show)
        }
 }
 
-static void
-chat_notify_show_contacts_cb (EmpathyConf *conf,
-                             const gchar *key,
-                             gpointer     user_data)
-{
-       EmpathyChatPriv *priv;
-       
-       priv = GET_PRIV (user_data);
-
-       chat_set_show_contacts (EMPATHY_CHAT (user_data), priv->remote_contact == NULL);
-}
-
 static void
 chat_remote_contact_changed_cb (EmpathyChat *chat)
 {
        EmpathyChatPriv *priv = GET_PRIV (chat);
+       gboolean         active;
 
        if (priv->remote_contact != NULL) {
                g_object_unref (priv->remote_contact);
@@ -1281,7 +1275,8 @@ chat_remote_contact_changed_cb (EmpathyChat *chat)
                priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
        }
 
-       chat_set_show_contacts (chat, priv->remote_contact == NULL);
+       active = (priv->remote_contact == NULL && priv->show_contacts == TRUE);
+       empathy_chat_set_show_contacts (chat, active);
 
        g_object_notify (G_OBJECT (chat), "remote-contact");
        g_object_notify (G_OBJECT (chat), "id");
@@ -1306,7 +1301,7 @@ chat_destroy_cb (EmpathyTpChat *tp_chat,
 
        empathy_chat_view_append_event (chat->view, _("Disconnected"));
        gtk_widget_set_sensitive (chat->input_text_view, FALSE);
-       chat_set_show_contacts (chat, FALSE);
+       empathy_chat_set_show_contacts (chat, FALSE);
 }
 
 static void
@@ -1334,6 +1329,7 @@ chat_create_ui (EmpathyChat *chat)
        GList           *list = NULL;
        gchar           *filename;
        GtkTextBuffer   *buffer;
+       gboolean         active;
 
        filename = empathy_file_lookup ("empathy-chat.ui",
                                        "libempathy-gtk");
@@ -1391,7 +1387,8 @@ chat_create_ui (EmpathyChat *chat)
        gtk_widget_show (chat->input_text_view);
 
        /* Create contact list */
-       chat_set_show_contacts (chat, priv->remote_contact == NULL);
+       active = (priv->remote_contact == NULL && priv->show_contacts == TRUE);
+       empathy_chat_set_show_contacts (chat, active);
 
        /* Initialy hide the topic, will be shown if not empty */
        gtk_widget_hide (priv->hbox_topic);
@@ -1509,8 +1506,6 @@ chat_finalize (GObject *object)
        if (priv->block_events_timeout_id) {
                g_source_remove (priv->block_events_timeout_id);
        }
-       
-       empathy_conf_notify_remove (empathy_conf_get (), priv->notify_id);
 
        g_free (priv->id);
        g_free (priv->name);
@@ -1587,6 +1582,13 @@ empathy_chat_class_init (EmpathyChatClass *klass)
                                                              "The remote contact is any",
                                                              EMPATHY_TYPE_CONTACT,
                                                              G_PARAM_READABLE));
+       g_object_class_install_property (object_class,
+                                        PROP_SHOW_CONTACTS,
+                                        g_param_spec_boolean ("show-contacts",
+                                                              "Contacts' visibility",
+                                                              "The visibility of the contacts' list",
+                                                              TRUE,
+                                                              G_PARAM_READWRITE));
 
        signals[COMPOSING] =
                g_signal_new ("composing",
@@ -1624,6 +1626,7 @@ chat_block_events_timeout_cb (gpointer data)
 static void
 empathy_chat_init (EmpathyChat *chat)
 {
+       gboolean         active;
        EmpathyChatPriv *priv = G_TYPE_INSTANCE_GET_PRIVATE (chat,
                EMPATHY_TYPE_CHAT, EmpathyChatPriv);
 
@@ -1638,12 +1641,13 @@ empathy_chat_init (EmpathyChat *chat)
                          "new-connection",
                          G_CALLBACK (chat_new_connection_cb),
                          chat);
-                         
-       priv->notify_id = empathy_conf_notify_add (empathy_conf_get (),
-                                    EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
-                                    chat_notify_show_contacts_cb,
-                                    chat);
 
+       empathy_conf_get_bool (empathy_conf_get (),
+                              EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
+                              &active);
+
+       empathy_chat_set_show_contacts (chat, active);
+                         
        /* Block events for some time to avoid having "has come online" or
         * "joined" messages. */
        priv->block_events_timeout_id =
index 12fac9617910f4e1a9a0406483fc1ab25262bc61..c38fd64a6c636092c26c70b315085ef738c48de4 100644 (file)
@@ -82,6 +82,8 @@ void               empathy_chat_correct_word         (EmpathyChat   *chat,
                                                      GtkTextIter   *end,
                                                      const gchar   *new_word);
 gboolean           empathy_chat_is_room              (EmpathyChat   *chat);
+void               empathy_chat_set_show_contacts    (EmpathyChat *chat,
+                                                      gboolean     show);
 G_END_DECLS
 
 #endif /* __EMPATHY_CHAT_H__ */
index 03e4c1059383e4076551467e10bdd63c4a5bc30e..130638a1ab97302cf9cb272aa9d6c7dda1098b80 100644 (file)
@@ -72,7 +72,6 @@ typedef struct {
        GtkWidget   *dialog;
        GtkWidget   *notebook;
        NotifyNotification *notification;
-       guint        notify_id; /* show contacts' notification */
 
        /* Menu items. */
        GtkUIManager *ui_manager;
@@ -135,21 +134,6 @@ chat_window_accel_cb (GtkAccelGroup    *accelgroup,
        }
 }
 
-static void
-chat_window_notify_show_contacts_cb (EmpathyConf *conf,
-                                    const gchar *key,
-                                    gpointer     user_data)
-{
-       gboolean value;
-       EmpathyChatWindowPriv *priv;
-       
-       priv = GET_PRIV (user_data);
-
-       if (empathy_conf_get_bool (empathy_conf_get (), key, &value)) {
-               gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (priv->menu_conv_toggle_contacts), value);
-       }
-}
-
 static EmpathyChatWindow *
 chat_window_find_chat (EmpathyChat *chat)
 {
@@ -564,6 +548,8 @@ chat_window_conv_activate_cb (GtkAction         *action,
 {
        EmpathyChatWindowPriv *priv = GET_PRIV (window);
        gboolean               is_room;
+       gboolean               active;
+       EmpathyContact        *remote_contact = NULL;
 
        /* Favorite room menu */
        is_room = empathy_chat_is_room (priv->current_chat);
@@ -582,7 +568,22 @@ chat_window_conv_activate_cb (GtkAction         *action,
                        GTK_TOGGLE_ACTION (priv->menu_conv_favorite), found);
        }
        gtk_action_set_visible (priv->menu_conv_favorite, is_room);
-       gtk_action_set_visible (priv->menu_conv_toggle_contacts, is_room);
+
+       /* Show contacts menu */
+       g_object_get (priv->current_chat,
+                     "remote-contact", &remote_contact,
+                     "show-contacts", &active,
+                     NULL);
+       if (remote_contact == NULL) {
+               gtk_toggle_action_set_active (
+                       GTK_TOGGLE_ACTION (priv->menu_conv_toggle_contacts),
+                                          active);
+       }
+       gtk_action_set_visible (priv->menu_conv_toggle_contacts,
+                               (remote_contact == NULL));
+       if (remote_contact != NULL) {
+               g_object_unref (remote_contact);
+       }
 }
 
 static void
@@ -630,13 +631,14 @@ static void
 chat_window_contacts_toggled_cb (GtkToggleAction   *toggle_action,
                                 EmpathyChatWindow *window)
 {
+       EmpathyChatWindowPriv *priv = GET_PRIV (window);
        gboolean               active;
 
        active = gtk_toggle_action_get_active (toggle_action);
-       
-       empathy_conf_set_bool (empathy_conf_get (),
-                              EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
-                              active);
+
+       g_object_set (priv->current_chat,
+                     "show-contacts", active,
+                     NULL);
 }
 
 static const gchar *
@@ -1350,8 +1352,6 @@ chat_window_finalize (GObject *object)
 
        chat_windows = g_list_remove (chat_windows, window);
        gtk_widget_destroy (priv->dialog);
-       
-       empathy_conf_notify_remove (empathy_conf_get (), priv->notify_id);
 
        G_OBJECT_CLASS (empathy_chat_window_parent_class)->finalize (object);
 }
@@ -1504,10 +1504,6 @@ empathy_chat_window_init (EmpathyChatWindow *window)
                          "page_removed",
                          G_CALLBACK (chat_window_page_removed_cb),
                          window);
-       priv->notify_id = empathy_conf_notify_add (empathy_conf_get (),
-                                    EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
-                                    chat_window_notify_show_contacts_cb,
-                                    window);
 
        /* Set up drag and drop */
        gtk_drag_dest_set (GTK_WIDGET (priv->notebook),