]> git.0d.be Git - empathy.git/commitdiff
Merge branch 'part-reasons'
authorWill Thompson <will.thompson@collabora.co.uk>
Wed, 1 Jul 2009 22:43:27 +0000 (23:43 +0100)
committerWill Thompson <will.thompson@collabora.co.uk>
Wed, 1 Jul 2009 22:43:27 +0000 (23:43 +0100)
1  2 
libempathy-gtk/empathy-chat.c
libempathy/empathy-tp-chat.c

index 1f522534836256af7a31e5c32479d5d1428574fe,f25734a10562a0cb25668d49dce188f207de8375..1729e53054f5de8a1311dfd2d41e80fe87d6479d
  #define GET_PRIV(obj) EMPATHY_GET_PRIV (obj, EmpathyChat)
  typedef struct {
        EmpathyTpChat     *tp_chat;
 -      McAccount         *account;
 +      EmpathyAccount    *account;
        gchar             *id;
        gchar             *name;
        gchar             *subject;
        EmpathyContact    *remote_contact;
 +      gboolean           show_contacts;
  
        EmpathyLogManager *log_manager;
        EmpathyAccountManager *account_manager;
@@@ -108,7 -107,6 +108,7 @@@ enum 
        PROP_NAME,
        PROP_SUBJECT,
        PROP_REMOTE_CONTACT,
 +      PROP_SHOW_CONTACTS,
  };
  
  static guint signals[LAST_SIGNAL] = { 0 };
@@@ -143,9 -141,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;
@@@ -164,9 -159,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;
@@@ -201,13 -193,13 +201,13 @@@ chat_new_connection_cb (EmpathyAccountM
                        EmpathyChat *chat)
  {
        EmpathyChatPriv *priv = GET_PRIV (chat);
 -      McAccount *account;
 +      EmpathyAccount *account;
  
        account = empathy_account_manager_get_account (manager, connection);
        if (!priv->tp_chat && empathy_account_equal (account, priv->account) &&
            priv->handle_type != TP_HANDLE_TYPE_NONE &&
            !EMP_STR_EMPTY (priv->id)) {
 -              
 +
                DEBUG ("Account reconnected, request a new Text channel");
  
                switch (priv->handle_type) {
@@@ -302,7 -294,7 +302,7 @@@ chat_sent_message_add (EmpathyChat  *ch
  
        /* Save the sent message in our repeat buffer */
        list = priv->sent_messages;
 -      
 +
        /* Remove any other occurances of this msg */
        while ((item = g_slist_find_custom (list, str, (GCompareFunc) strcmp)) != NULL) {
                list = g_slist_remove_link (list, item);
@@@ -333,7 -325,7 +333,7 @@@ chat_sent_message_get_next (EmpathyCha
  {
        EmpathyChatPriv *priv;
        gint            max;
 -      
 +
        priv = GET_PRIV (chat);
  
        if (!priv->sent_messages) {
        if (priv->sent_messages_index < max) {
                priv->sent_messages_index++;
        }
 -      
 +
        DEBUG ("Returning next message index:%d", priv->sent_messages_index);
  
        return g_slist_nth_data (priv->sent_messages, priv->sent_messages_index);
@@@ -360,7 -352,7 +360,7 @@@ chat_sent_message_get_last (EmpathyCha
        g_return_val_if_fail (EMPATHY_IS_CHAT (chat), NULL);
  
        priv = GET_PRIV (chat);
 -      
 +
        if (!priv->sent_messages) {
                DEBUG ("No sent messages, last message is NULL");
                return NULL;
@@@ -1161,6 -1153,56 +1161,56 @@@ chat_contacts_completion_func (const gc
        return ret;
  }
  
+ static gchar *
+ build_part_message (guint           reason,
+                   const gchar    *name,
+                   EmpathyContact *actor,
+                   const gchar    *message)
+ {
+       GString *s = g_string_new ("");
+       const gchar *actor_name = NULL;
+       if (actor != NULL) {
+               actor_name = empathy_contact_get_name (actor);
+       }
+       /* Having an actor only really makes sense for a few actions... */
+       switch (reason) {
+       case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE:
+               g_string_append_printf (s, _("%s has disconnected"), name);
+               break;
+       case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED:
+               if (actor_name != NULL) {
+                       g_string_append_printf (s, _("%s was kicked by %s"),
+                               name, actor_name);
+               } else {
+                       g_string_append_printf (s, _("%s was kicked"), name);
+               }
+               break;
+       case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED:
+               if (actor_name != NULL) {
+                       g_string_append_printf (s, _("%s was banned by %s"),
+                               name, actor_name);
+               } else {
+                       g_string_append_printf (s, _("%s was banned"), name);
+               }
+               break;
+       default:
+               g_string_append_printf (s, _("%s has left the room"), name);
+       }
+       if (!EMP_STR_EMPTY (message)) {
+               /* Note to translators: this string is appended to
+                * notifications like "foo has left the room", with the message
+                * given by the user living the room. If this poses a problem,
+                * please let us know. :-)
+                */
+               g_string_append_printf (s, _(" (%s)"), message);
+       }
+       return g_string_free (s, FALSE);
+ }
  static void
  chat_members_changed_cb (EmpathyTpChat  *tp_chat,
                         EmpathyContact *contact,
                         EmpathyChat    *chat)
  {
        EmpathyChatPriv *priv = GET_PRIV (chat);
+       const gchar *name = empathy_contact_get_name (contact);
+       gchar *str;
  
-       if (priv->block_events_timeout_id == 0) {
-               gchar *str;
+       if (priv->block_events_timeout_id != 0)
+               return;
  
-               if (is_member) {
-                       str = g_strdup_printf (_("%s has joined the room"),
-                                              empathy_contact_get_name (contact));
-               } else {
-                       str = g_strdup_printf (_("%s has left the room"),
-                                              empathy_contact_get_name (contact));
-               }
-               empathy_chat_view_append_event (chat->view, str);
-               g_free (str);
+       if (is_member) {
+               str = g_strdup_printf (_("%s has joined the room"),
+                                      name);
+       } else {
+               str = build_part_message (reason, name, actor, message);
        }
+       empathy_chat_view_append_event (chat->view, str);
+       g_free (str);
  }
  
  static gboolean
@@@ -1196,18 -1239,15 +1247,18 @@@ chat_reset_size_request (gpointer widge
  }
  
  static void
 -chat_set_show_contacts (EmpathyChat *chat, gboolean show)
 +chat_update_contacts_visibility (EmpathyChat *chat)
  {
        EmpathyChatPriv *priv = GET_PRIV (chat);
 +      gboolean show;
 +
 +      show = priv->remote_contact == NULL && priv->show_contacts;
  
        if (!priv->scrolled_window_contacts) {
                return;
        }
  
 -      if (show) {
 +      if (show && priv->contact_list_view == NULL) {
                EmpathyContactListStore *store;
                gint                     min_width;
  
                gtk_widget_show (priv->contact_list_view);
                gtk_widget_show (priv->scrolled_window_contacts);
                g_object_unref (store);
 -      } else {
 +      } else if (!show) {
                priv->contacts_width = gtk_paned_get_position (GTK_PANED (priv->hpaned));
                gtk_widget_hide (priv->scrolled_window_contacts);
 -              if (priv->contact_list_view) {
 +              if (priv->contact_list_view != NULL) {
                        gtk_widget_destroy (priv->contact_list_view);
                        priv->contact_list_view = NULL;
                }
        }
  }
  
 +void
 +empathy_chat_set_show_contacts (EmpathyChat *chat,
 +                              gboolean     show)
 +{
 +      EmpathyChatPriv *priv = GET_PRIV (chat);
 +
 +      priv->show_contacts = show;
 +
 +      chat_update_contacts_visibility (chat);
 +
 +      g_object_notify (G_OBJECT (chat), "show-contacts");
 +}
 +
  static void
  chat_remote_contact_changed_cb (EmpathyChat *chat)
  {
        EmpathyChatPriv *priv = GET_PRIV (chat);
  
 -      if (priv->remote_contact) {
 +      if (priv->remote_contact != NULL) {
                g_object_unref (priv->remote_contact);
                priv->remote_contact = NULL;
        }
  
        priv->remote_contact = empathy_tp_chat_get_remote_contact (priv->tp_chat);
 -      if (priv->remote_contact) {
 +      if (priv->remote_contact != NULL) {
                g_object_ref (priv->remote_contact);
                priv->handle_type = TP_HANDLE_TYPE_CONTACT;
                g_free (priv->id);
                priv->id = g_strdup (empathy_contact_get_id (priv->remote_contact));
        }
 -      else if (priv->tp_chat) {
 +      else if (priv->tp_chat != NULL) {
                TpChannel *channel;
  
                channel = empathy_tp_chat_get_channel (priv->tp_chat);
                priv->id = g_strdup (empathy_tp_chat_get_id (priv->tp_chat));
        }
  
 -      chat_set_show_contacts (chat, priv->remote_contact == NULL);
 +      chat_update_contacts_visibility (chat);
  
        g_object_notify (G_OBJECT (chat), "remote-contact");
        g_object_notify (G_OBJECT (chat), "id");
@@@ -1312,7 -1339,7 +1363,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
@@@ -1397,7 -1424,7 +1448,7 @@@ chat_create_ui (EmpathyChat *chat
        gtk_widget_show (chat->input_text_view);
  
        /* Create contact list */
 -      chat_set_show_contacts (chat, priv->remote_contact == NULL);
 +      chat_update_contacts_visibility (chat);
  
        /* Initialy hide the topic, will be shown if not empty */
        gtk_widget_hide (priv->hbox_topic);
@@@ -1555,56 -1582,42 +1606,56 @@@ empathy_chat_class_init (EmpathyChatCla
                                                              "The tp chat object",
                                                              EMPATHY_TYPE_TP_CHAT,
                                                              G_PARAM_CONSTRUCT |
 -                                                            G_PARAM_READWRITE));
 +                                                            G_PARAM_READWRITE |
 +                                                            G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (object_class,
                                         PROP_ACCOUNT,
                                         g_param_spec_object ("account",
                                                              "Account of the chat",
                                                              "The account of the chat",
 -                                                            MC_TYPE_ACCOUNT,
 -                                                            G_PARAM_READABLE));
 +                                                            EMPATHY_TYPE_ACCOUNT,
 +                                                            G_PARAM_READABLE |
 +                                                            G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (object_class,
                                         PROP_ID,
                                         g_param_spec_string ("id",
                                                              "Chat's id",
                                                              "The id of the chat",
                                                              NULL,
 -                                                            G_PARAM_READABLE));
 +                                                            G_PARAM_READABLE |
 +                                                            G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (object_class,
                                         PROP_NAME,
                                         g_param_spec_string ("name",
                                                              "Chat's name",
                                                              "The name of the chat",
                                                              NULL,
 -                                                            G_PARAM_READABLE));
 +                                                            G_PARAM_READABLE |
 +                                                            G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (object_class,
                                         PROP_SUBJECT,
                                         g_param_spec_string ("subject",
                                                              "Chat's subject",
                                                              "The subject or topic of the chat",
                                                              NULL,
 -                                                            G_PARAM_READABLE));
 +                                                            G_PARAM_READABLE |
 +                                                            G_PARAM_STATIC_STRINGS));
        g_object_class_install_property (object_class,
                                         PROP_REMOTE_CONTACT,
                                         g_param_spec_object ("remote-contact",
                                                              "The remote contact",
                                                              "The remote contact is any",
                                                              EMPATHY_TYPE_CONTACT,
 -                                                            G_PARAM_READABLE));
 +                                                            G_PARAM_READABLE |
 +                                                            G_PARAM_STATIC_STRINGS));
 +      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 |
 +                                                             G_PARAM_STATIC_STRINGS));
  
        signals[COMPOSING] =
                g_signal_new ("composing",
@@@ -1657,10 -1670,6 +1708,10 @@@ empathy_chat_init (EmpathyChat *chat
                          G_CALLBACK (chat_new_connection_cb),
                          chat);
  
 +      empathy_conf_get_bool (empathy_conf_get (),
 +                             EMPATHY_PREFS_CHAT_SHOW_CONTACTS_IN_ROOMS,
 +                             &priv->show_contacts);
 +
        /* Block events for some time to avoid having "has come online" or
         * "joined" messages. */
        priv->block_events_timeout_id =
@@@ -1753,7 -1762,7 +1804,7 @@@ empathy_chat_set_tp_chat (EmpathyCha
        show_pending_messages (chat);
  }
  
 -McAccount *
 +EmpathyAccount *
  empathy_chat_get_account (EmpathyChat *chat)
  {
        EmpathyChatPriv *priv = GET_PRIV (chat);
index ac61392e033268df517d89bfe62e96a1c3728145,6810476d19d5127d60bcc60bcbd04eb0e1a909ad..a3282818f09935fe04928e23a12be9ae4c14b2a0
@@@ -875,6 -875,34 +875,34 @@@ tp_chat_got_added_contacts_cb (EmpathyT
        tp_chat_check_if_ready (EMPATHY_TP_CHAT (chat));
  }
  
+ static EmpathyContact *
+ chat_lookup_contact (EmpathyTpChat *chat,
+                    TpHandle       handle,
+                    gboolean       remove)
+ {
+       EmpathyTpChatPriv *priv = GET_PRIV (chat);
+       GList *l;
+       for (l = priv->members; l; l = l->next) {
+               EmpathyContact *c = l->data;
+               if (empathy_contact_get_handle (c) != handle) {
+                       continue;
+               }
+               if (remove) {
+                       /* Caller takes the reference. */
+                       priv->members = g_list_delete_link (priv->members, l);
+               } else {
+                       g_object_ref (c);
+               }
+               return c;
+       }
+       return NULL;
+ }
  static void
  tp_chat_group_members_changed_cb (TpChannel     *self,
                                  gchar         *message,
  {
        EmpathyTpChatPriv *priv = GET_PRIV (chat);
        EmpathyContact *contact;
-       TpHandle handle;
+       EmpathyContact *actor_contact = NULL;
        guint i;
-       GList *l;
+       if (actor != 0) {
+               actor_contact = chat_lookup_contact (chat, actor, FALSE);
+               if (actor_contact == NULL) {
+                       /* FIXME: handle this a tad more gracefully: perhaps
+                        * the actor was a server op. We could use the
+                        * contact-ids detail of MembersChangedDetailed.
+                        */
+                       DEBUG ("actor %u not a channel member", actor);
+               }
+       }
  
        /* Remove contacts that are not members anymore */
        for (i = 0; i < removed->len; i++) {
-               for (l = priv->members; l; l = l->next) {
-                       contact = l->data;
-                       handle = empathy_contact_get_handle (contact);
-                       if (handle == g_array_index (removed, TpHandle, i)) {
-                               priv->members = g_list_delete_link (priv->members, l);
-                               g_signal_emit_by_name (chat, "members-changed",
-                                                      contact, NULL, reason,
-                                                      message, FALSE);
-                               g_object_unref (contact);
-                               break;
-                       }
+               contact = chat_lookup_contact (chat,
+                       g_array_index (removed, TpHandle, i), TRUE);
+               if (contact != NULL) {
+                       g_signal_emit_by_name (chat, "members-changed", contact,
+                                              actor_contact, reason, message,
+                                              FALSE);
+                       g_object_unref (contact);
                }
        }
  
        }
  
        tp_chat_update_remote_contact (chat);
+       if (actor_contact != NULL) {
+               g_object_unref (actor_contact);
+       }
  }
  
  static void
@@@ -993,7 -1032,7 +1032,7 @@@ tp_chat_constructor (GTyp
  
                /* Get initial member contacts */
                members = tp_channel_group_get_members (priv->channel);
 -              handles = tp_intset_to_array (members);         
 +              handles = tp_intset_to_array (members);
                empathy_tp_contact_factory_get_from_handles (priv->factory,
                        handles->len, (TpHandle *) handles->data,
                        tp_chat_got_added_contacts_cb, NULL, NULL, chat);