#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;
PROP_NAME,
PROP_SUBJECT,
PROP_REMOTE_CONTACT,
+ PROP_SHOW_CONTACTS,
};
static guint signals[LAST_SIGNAL] = { 0 };
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;
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;
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) {
/* 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);
{
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);
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;
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
}
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");
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
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);
"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",
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 =
show_pending_messages (chat);
}
-McAccount *
+EmpathyAccount *
empathy_chat_get_account (EmpathyChat *chat)
{
EmpathyChatPriv *priv = GET_PRIV (chat);
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
/* 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);