From bc08d45ad3b44b7ba7b5b0044f538338d2a6553e Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 17 Jun 2009 20:41:31 +0100 Subject: Print part reasons to conversation window --- libempathy-gtk/empathy-chat.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 0fb77f24c..e327b27d7 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -1165,14 +1165,48 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat, EmpathyChatPriv *priv = GET_PRIV (chat); if (priv->block_events_timeout_id == 0) { + const gchar *name = empathy_contact_get_name (contact); gchar *str; if (is_member) { str = g_strdup_printf (_("%s has joined the room"), - empathy_contact_get_name (contact)); + name); } else { - str = g_strdup_printf (_("%s has left the room"), - empathy_contact_get_name (contact)); + const gchar *action; + + if (EMP_STR_EMPTY (message)) { + switch (reason) { + case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: + action = _("%s has disconnected"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: + action = _("%s was kicked"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: + action = _("%s was banned"); + break; + default: + action = _("%s has left the room"); + } + + str = g_strdup_printf (action, name); + } else { + switch (reason) { + case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: + action = _("%s has disconnected (%s)"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: + action = _("%s was kicked (%s)"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: + action = _("%s was banned (%s)"); + break; + default: + action = _("%s has left the room (%s)"); + } + + str = g_strdup_printf (action, name, message); + } } empathy_chat_view_append_event (chat->view, str); g_free (str); -- cgit v1.2.3 From 17fb8fcf2f5cb1b535815dcabdc790b04969e6d5 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 17 Jun 2009 21:10:08 +0100 Subject: Return early from chat_members_changed_cb This avoids the function marching to the right quite so much. --- libempathy-gtk/empathy-chat.c | 85 ++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 42 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index e327b27d7..44f37a868 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -1163,54 +1163,55 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat, EmpathyChat *chat) { EmpathyChatPriv *priv = GET_PRIV (chat); + const gchar *name = empathy_contact_get_name (contact); + gchar *str; - if (priv->block_events_timeout_id == 0) { - const gchar *name = empathy_contact_get_name (contact); - gchar *str; + if (priv->block_events_timeout_id != 0) + return; + + if (is_member) { + str = g_strdup_printf (_("%s has joined the room"), + name); + } else { + const gchar *action; + + if (EMP_STR_EMPTY (message)) { + switch (reason) { + case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: + action = _("%s has disconnected"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: + action = _("%s was kicked"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: + action = _("%s was banned"); + break; + default: + action = _("%s has left the room"); + } - if (is_member) { - str = g_strdup_printf (_("%s has joined the room"), - name); + str = g_strdup_printf (action, name); } else { - const gchar *action; - - if (EMP_STR_EMPTY (message)) { - switch (reason) { - case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - action = _("%s has disconnected"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - action = _("%s was kicked"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - action = _("%s was banned"); - break; - default: - action = _("%s has left the room"); - } - - str = g_strdup_printf (action, name); - } else { - switch (reason) { - case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - action = _("%s has disconnected (%s)"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - action = _("%s was kicked (%s)"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - action = _("%s was banned (%s)"); - break; - default: - action = _("%s has left the room (%s)"); - } - - str = g_strdup_printf (action, name, message); + switch (reason) { + case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: + action = _("%s has disconnected (%s)"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: + action = _("%s was kicked (%s)"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: + action = _("%s was banned (%s)"); + break; + default: + action = _("%s has left the room (%s)"); } + + str = g_strdup_printf (action, name, message); } - empathy_chat_view_append_event (chat->view, str); - g_free (str); } + + empathy_chat_view_append_event (chat->view, str); + g_free (str); } static gboolean -- cgit v1.2.3 From 564562fd34a7a456e042041118ee326d3fae0069 Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Wed, 17 Jun 2009 21:17:33 +0100 Subject: Extract part message building to a function --- libempathy-gtk/empathy-chat.c | 79 ++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 35 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 44f37a868..44983004d 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -1153,6 +1153,48 @@ chat_contacts_completion_func (const gchar *s1, return ret; } +static gchar * +build_part_message (guint reason, + const gchar *name, + const gchar *message) +{ + const gchar *template; + + if (message == NULL) { + switch (reason) { + case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: + template = _("%s has disconnected"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: + template = _("%s was kicked"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: + template = _("%s was banned"); + break; + default: + template = _("%s has left the room"); + } + + return g_strdup_printf (template, name); + } else { + switch (reason) { + case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: + template = _("%s has disconnected (%s)"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: + template = _("%s was kicked (%s)"); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: + template = _("%s was banned (%s)"); + break; + default: + template = _("%s has left the room (%s)"); + } + + return g_strdup_printf (template, name, message); + } +} + static void chat_members_changed_cb (EmpathyTpChat *tp_chat, EmpathyContact *contact, @@ -1173,41 +1215,8 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat, str = g_strdup_printf (_("%s has joined the room"), name); } else { - const gchar *action; - - if (EMP_STR_EMPTY (message)) { - switch (reason) { - case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - action = _("%s has disconnected"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - action = _("%s was kicked"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - action = _("%s was banned"); - break; - default: - action = _("%s has left the room"); - } - - str = g_strdup_printf (action, name); - } else { - switch (reason) { - case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - action = _("%s has disconnected (%s)"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - action = _("%s was kicked (%s)"); - break; - case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - action = _("%s was banned (%s)"); - break; - default: - action = _("%s has left the room (%s)"); - } - - str = g_strdup_printf (action, name, message); - } + str = build_part_message (reason, name, + EMP_STR_EMPTY (message) ? NULL : message); } empathy_chat_view_append_event (chat->view, str); -- cgit v1.2.3 From 28acd3ce10a88f912f0d3f42d14c2e5a98d619bd Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 18 Jun 2009 11:04:54 +0100 Subject: Include actor in part message if possible --- libempathy-gtk/empathy-chat.c | 68 ++++++++++++++++++++++++++++++------------- 1 file changed, 47 insertions(+), 21 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 44983004d..c3fc7948f 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -1156,42 +1156,62 @@ chat_contacts_completion_func (const gchar *s1, static gchar * build_part_message (guint reason, const gchar *name, + const gchar *actor, const gchar *message) { - const gchar *template; - + /* Having an actor only really makes sense for a few actions... */ if (message == NULL) { switch (reason) { case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - template = _("%s has disconnected"); - break; + return g_strdup_printf (_("%s has disconnected"), name); case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - template = _("%s was kicked"); - break; + if (actor != NULL) { + return g_strdup_printf ( + _("%s was kicked by %s"), name, actor); + } else { + return g_strdup_printf (_("%s was kicked"), + name); + } case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - template = _("%s was banned"); - break; + if (actor != NULL) { + return g_strdup_printf ( + _("%s was banned by %s"), name, actor); + } else { + return g_strdup_printf (_("%s was banned"), + name); + } default: - template = _("%s has left the room"); + return g_strdup_printf (_("%s has left the room"), + name); } - - return g_strdup_printf (template, name); } else { switch (reason) { case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - template = _("%s has disconnected (%s)"); - break; + return g_strdup_printf (_("%s has disconnected (%s)"), + name, message); case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - template = _("%s was kicked (%s)"); - break; + if (actor != NULL) { + return g_strdup_printf ( + _("%s was kicked by %s (%s)"), name, + actor, message); + } else { + return g_strdup_printf ( + _("%s was kicked (%s)"), + name, message); + } case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - template = _("%s was banned (%s)"); - break; + if (actor != NULL) { + return g_strdup_printf ( + _("%s was banned by %s (%s)"), name, + actor, message); + } else { + return g_strdup_printf (_("%s was banned (%s)"), + name, message); + } default: - template = _("%s has left the room (%s)"); + return g_strdup_printf (_("%s has left the room (%s)"), + name, message); } - - return g_strdup_printf (template, name, message); } } @@ -1215,7 +1235,13 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat, str = g_strdup_printf (_("%s has joined the room"), name); } else { - str = build_part_message (reason, name, + const gchar *actor_name = NULL; + + if (actor != NULL) { + actor_name = empathy_contact_get_name (actor); + } + + str = build_part_message (reason, name, actor_name, EMP_STR_EMPTY (message) ? NULL : message); } -- cgit v1.2.3 From 08f02f53a10fd653cac56e23817f3c40d636ca5e Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 18 Jun 2009 21:16:51 +0100 Subject: Reduce format string duplication for part notifications. Xavier suggested that just appending " (%s)" to the common prefix when there is a message is probably okay from a translation point of view, as long as there's a comment to translators. --- libempathy-gtk/empathy-chat.c | 83 +++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 50 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index c3fc7948f..04b0cbd0f 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -1159,60 +1159,43 @@ build_part_message (guint reason, const gchar *actor, const gchar *message) { + GString *s = g_string_new (""); + /* Having an actor only really makes sense for a few actions... */ - if (message == NULL) { - switch (reason) { - case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - return g_strdup_printf (_("%s has disconnected"), name); - case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - if (actor != NULL) { - return g_strdup_printf ( - _("%s was kicked by %s"), name, actor); - } else { - return g_strdup_printf (_("%s was kicked"), - name); - } - case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - if (actor != NULL) { - return g_strdup_printf ( - _("%s was banned by %s"), name, actor); - } else { - return g_strdup_printf (_("%s was banned"), - name); - } - default: - return g_strdup_printf (_("%s has left the room"), - name); + 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 != NULL) { + g_string_append_printf (s, _("%s was kicked by %s"), + name, actor); + } else { + g_string_append_printf (s, _("%s was kicked"), name); } - } else { - switch (reason) { - case TP_CHANNEL_GROUP_CHANGE_REASON_OFFLINE: - return g_strdup_printf (_("%s has disconnected (%s)"), - name, message); - case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - if (actor != NULL) { - return g_strdup_printf ( - _("%s was kicked by %s (%s)"), name, - actor, message); - } else { - return g_strdup_printf ( - _("%s was kicked (%s)"), - name, message); - } - case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - if (actor != NULL) { - return g_strdup_printf ( - _("%s was banned by %s (%s)"), name, - actor, message); - } else { - return g_strdup_printf (_("%s was banned (%s)"), - name, message); - } - default: - return g_strdup_printf (_("%s has left the room (%s)"), - name, message); + break; + case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: + if (actor != NULL) { + g_string_append_printf (s, _("%s was banned by %s"), + name, actor); + } else { + g_string_append_printf (s, _("%s was banned"), name); } + break; + default: + g_string_append_printf (s, _("%s has left the room"), name); } + + if (message != NULL) { + /* 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 -- cgit v1.2.3 From ecbd33430aa9005131327e413d3e6eb267c6721a Mon Sep 17 00:00:00 2001 From: Will Thompson Date: Thu, 18 Jun 2009 21:26:04 +0100 Subject: Move string manipulation into build_part_message Xavier said he preferred this, and it's shorter, so... --- libempathy-gtk/empathy-chat.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'libempathy-gtk') diff --git a/libempathy-gtk/empathy-chat.c b/libempathy-gtk/empathy-chat.c index 04b0cbd0f..f25734a10 100644 --- a/libempathy-gtk/empathy-chat.c +++ b/libempathy-gtk/empathy-chat.c @@ -1154,12 +1154,17 @@ chat_contacts_completion_func (const gchar *s1, } static gchar * -build_part_message (guint reason, - const gchar *name, - const gchar *actor, - const gchar *message) +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) { @@ -1167,17 +1172,17 @@ build_part_message (guint reason, g_string_append_printf (s, _("%s has disconnected"), name); break; case TP_CHANNEL_GROUP_CHANGE_REASON_KICKED: - if (actor != NULL) { + if (actor_name != NULL) { g_string_append_printf (s, _("%s was kicked by %s"), - name, actor); + name, actor_name); } else { g_string_append_printf (s, _("%s was kicked"), name); } break; case TP_CHANNEL_GROUP_CHANGE_REASON_BANNED: - if (actor != NULL) { + if (actor_name != NULL) { g_string_append_printf (s, _("%s was banned by %s"), - name, actor); + name, actor_name); } else { g_string_append_printf (s, _("%s was banned"), name); } @@ -1186,7 +1191,7 @@ build_part_message (guint reason, g_string_append_printf (s, _("%s has left the room"), name); } - if (message != NULL) { + 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, @@ -1218,14 +1223,7 @@ chat_members_changed_cb (EmpathyTpChat *tp_chat, str = g_strdup_printf (_("%s has joined the room"), name); } else { - const gchar *actor_name = NULL; - - if (actor != NULL) { - actor_name = empathy_contact_get_name (actor); - } - - str = build_part_message (reason, name, actor_name, - EMP_STR_EMPTY (message) ? NULL : message); + str = build_part_message (reason, name, actor, message); } empathy_chat_view_append_event (chat->view, str); -- cgit v1.2.3