]> git.0d.be Git - empathy.git/blobdiff - libempathy-gtk/empathy-group-chat.c
Merge call branch from Elliot Fairweather with cleanups from Xavier Claessens.
[empathy.git] / libempathy-gtk / empathy-group-chat.c
index 88555339c34d31fde96f98220e282c29169bea84..4f86ef2bab2c2e88a868464184422389aff8dca8 100644 (file)
@@ -33,6 +33,8 @@
 #include <glade/glade.h>
 #include <glib/gi18n.h>
 
+#include <telepathy-glib/util.h>
+
 #include <libempathy/empathy-tp-chat.h>
 #include <libempathy/empathy-tp-chatroom.h>
 #include <libempathy/empathy-contact.h>
@@ -48,6 +50,8 @@
 //#include "empathy-sound.h"
 #include "empathy-images.h"
 #include "empathy-ui-utils.h"
+#include "empathy-conf.h"
+#include "empathy-preferences.h"
 
 #define DEBUG_DOMAIN "GroupChat"
 
@@ -171,22 +175,15 @@ group_chat_finalize (GObject *object)
 }
 
 EmpathyGroupChat *
-empathy_group_chat_new (McAccount *account,
-                       TpChan    *tp_chan)
+empathy_group_chat_new (EmpathyTpChatroom *tp_chat)
 {
-       EmpathyGroupChat     *chat;
-       EmpathyGroupChatPriv *priv;
+       EmpathyGroupChat *chat;
 
-       g_return_val_if_fail (MC_IS_ACCOUNT (account), NULL);
-       g_return_val_if_fail (TELEPATHY_IS_CHAN (tp_chan), NULL);
+       g_return_val_if_fail (EMPATHY_IS_TP_CHAT (tp_chat), NULL);
 
-       chat = g_object_new (EMPATHY_TYPE_GROUP_CHAT, NULL);
-
-       priv = GET_PRIV (chat);
-
-       EMPATHY_CHAT (chat)->account = g_object_ref (account);
-       priv->tp_chat = empathy_tp_chatroom_new (account, tp_chan);
-       empathy_chat_set_tp_chat (EMPATHY_CHAT (chat), EMPATHY_TP_CHAT (priv->tp_chat));
+       chat = g_object_new (EMPATHY_TYPE_GROUP_CHAT,
+                            "tp-chat", tp_chat,
+                            NULL);
 
        return chat;
 }
@@ -530,8 +527,14 @@ group_chat_set_tp_chat (EmpathyChat    *chat,
 
        /* Create contact list */
        priv->store = empathy_contact_list_store_new (EMPATHY_CONTACT_LIST (priv->tp_chat));
-       priv->view = empathy_contact_list_view_new (priv->store);
-       empathy_contact_list_view_set_interactive (priv->view, TRUE);
+       priv->view = empathy_contact_list_view_new (priv->store,
+                                                   EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CHAT |
+                                                   EMPATHY_CONTACT_LIST_FEATURE_CONTACT_CALL |
+                                                   EMPATHY_CONTACT_LIST_FEATURE_CONTACT_LOG |
+                                                   EMPATHY_CONTACT_LIST_FEATURE_CONTACT_FT |
+                                                   EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INVITE |
+                                                   EMPATHY_CONTACT_LIST_FEATURE_CONTACT_INFO);
+
        gtk_container_add (GTK_CONTAINER (priv->scrolled_window_contacts),
                           GTK_WIDGET (priv->view));
        gtk_widget_show (GTK_WIDGET (priv->view));
@@ -559,7 +562,7 @@ group_chat_subject_notify_cb (EmpathyTpChat   *tp_chat,
        priv = GET_PRIV (chat);
 
        g_object_get (priv->tp_chat, "subject", &str, NULL);
-       if (!empathy_strdiff (priv->topic, str)) {
+       if (!tp_strdiff (priv->topic, str)) {
                g_free (str);
                return;
        }
@@ -594,18 +597,16 @@ static gboolean
 group_chat_key_press_event (EmpathyChat *chat,
                            GdkEventKey *event)
 {
-       EmpathyGroupChatPriv *priv;
-       GtkTextBuffer        *buffer;
-       GtkTextIter           start, current;
-       gchar                *nick, *completed;
-       gint                  len;
-       GList                *list, *completed_list;
-       gboolean              is_start_of_buffer;
-
-       priv = GET_PRIV (chat);
+       EmpathyGroupChatPriv *priv = GET_PRIV (chat);
 
        if (!(event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) &&
            event->keyval == GDK_Tab) {
+               GtkTextBuffer *buffer;
+               GtkTextIter    start, current;
+               gchar         *nick, *completed;
+               GList         *list, *completed_list;
+               gboolean       is_start_of_buffer;
+
                buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (EMPATHY_CHAT (chat)->input_text_view));
                gtk_text_buffer_get_iter_at_mark (buffer, &current, gtk_text_buffer_get_insert (buffer));
 
@@ -614,14 +615,10 @@ group_chat_key_press_event (EmpathyChat *chat,
                gtk_text_iter_backward_word_start (&start);
                is_start_of_buffer = gtk_text_iter_is_start (&start);
 
-               nick = gtk_text_buffer_get_text (buffer, &start, &current, FALSE);
-
-               len = strlen (nick);
-
                list = empathy_contact_list_get_members (EMPATHY_CONTACT_LIST (priv->tp_chat));
-
                g_completion_add_items (priv->completion, list);
 
+               nick = gtk_text_buffer_get_text (buffer, &start, &current, FALSE);
                completed_list = g_completion_complete (priv->completion,
                                                        nick,
                                                        &completed);
@@ -629,8 +626,9 @@ group_chat_key_press_event (EmpathyChat *chat,
                g_free (nick);
 
                if (completed) {
-                       int          len;
+                       guint        len;
                        const gchar *text;
+                       gchar       *complete_char = NULL;
 
                        gtk_text_buffer_delete (buffer, &start, &current);
 
@@ -650,10 +648,16 @@ group_chat_key_press_event (EmpathyChat *chat,
 
                        gtk_text_buffer_insert_at_cursor (buffer, text, strlen (text));
 
-                       if (len == 1) {
-                               if (is_start_of_buffer) {
-                                       gtk_text_buffer_insert_at_cursor (buffer, ": ", 2);
-                               }
+                       if (len == 1 && is_start_of_buffer &&
+                           empathy_conf_get_string (empathy_conf_get (),
+                                                    EMPATHY_PREFS_CHAT_NICK_COMPLETION_CHAR,
+                                                    &complete_char) &&
+                           complete_char != NULL) {
+                               gtk_text_buffer_insert_at_cursor (buffer,
+                                                                 complete_char,
+                                                                 strlen (complete_char));
+                               gtk_text_buffer_insert_at_cursor (buffer, " ", 1);
+                               g_free (complete_char);
                        }
 
                        g_free (completed);