[empathy: 2/8] ContactWidget: show IRC channel list.
- From: Will Thompson <wjt src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [empathy: 2/8] ContactWidget: show IRC channel list.
- Date: Mon, 16 May 2011 13:17:40 +0000 (UTC)
commit e92e9e9c411ec02dacc1bb11f15aa4682fd64cdf
Author: Will Thompson <will thompson collabora co uk>
Date: Tue May 10 17:14:16 2011 +0100
ContactWidget: show IRC channel list.
Very recent versions of Idle expose the list of channels provided in
WHOIS replies. The data is provided as a bunch of x-irc-channel fields
with a single value, namely the name of the channel. Here we expose that
data to the user as a comma-separated list of links; clicking a link
ensures that channel.
https://bugzilla.gnome.org/show_bug.cgi?id=592795
libempathy-gtk/empathy-contact-widget.c | 74 +++++++++++++++++++++++++++++++
1 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/libempathy-gtk/empathy-contact-widget.c b/libempathy-gtk/empathy-contact-widget.c
index c4e3748..4f37ccb 100644
--- a/libempathy-gtk/empathy-contact-widget.c
+++ b/libempathy-gtk/empathy-contact-widget.c
@@ -526,12 +526,73 @@ contact_widget_details_update_edit (EmpathyContactWidget *information)
return n_rows;
}
+static gboolean
+channel_name_activated_cb (
+ GtkLabel *label,
+ gchar *uri,
+ EmpathyContactWidget *information)
+{
+ TpAccount *account = empathy_contact_get_account (information->contact);
+
+ empathy_join_muc (account, uri, empathy_get_current_action_time ());
+ return TRUE;
+}
+
+static void
+add_channel_list (
+ EmpathyContactWidget *information,
+ GPtrArray *channels,
+ guint row)
+{
+ GtkWidget *w;
+ GString *label_markup = g_string_new ("");
+ guint i;
+
+ w = gtk_label_new (_("Channels:"));
+ gtk_table_attach (GTK_TABLE (information->table_details),
+ w, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0);
+ gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+ gtk_widget_show (w);
+
+ for (i = 0; i < channels->len; i++)
+ {
+ const gchar *channel_name = g_ptr_array_index (channels, i);
+ /* We abuse the URI of the link to hold the channel name. It seems to
+ * be okay to just use it essentially verbatim, rather than trying to
+ * ensure it's actually a valid URI. g_string_append_uri_escaped()
+ * escapes way more than we actually need to; so we're just using
+ * g_markup_escape_text directly.
+ */
+ gchar *escaped = g_markup_escape_text (channel_name, -1);
+
+ if (i > 0)
+ g_string_append (label_markup, ", ");
+
+ g_string_append_printf (label_markup, "<a href='%s'>%s</a>",
+ escaped, channel_name);
+ g_free (escaped);
+ }
+
+ w = gtk_label_new (NULL);
+ gtk_label_set_markup (GTK_LABEL (w), label_markup->str);
+ gtk_label_set_line_wrap (GTK_LABEL (w), TRUE);
+ g_signal_connect (w, "activate-link",
+ (GCallback) channel_name_activated_cb, information);
+ gtk_table_attach_defaults (GTK_TABLE (information->table_details),
+ w, 1, 2, row, row + 1);
+ gtk_misc_set_alignment (GTK_MISC (w), 0, 0.5);
+ gtk_widget_show (w);
+
+ g_string_free (label_markup, TRUE);
+}
+
static guint
contact_widget_details_update_show (EmpathyContactWidget *information)
{
TpContact *contact;
GList *info, *l;
guint n_rows = 0;
+ GPtrArray *channels = g_ptr_array_new ();
contact = empathy_contact_get_tp_contact (information->contact);
info = tp_contact_get_contact_info (contact);
@@ -548,6 +609,12 @@ contact_widget_details_update_show (EmpathyContactWidget *information)
value = field->field_value[0];
+ if (!tp_strdiff (field->field_name, "x-irc-channel"))
+ {
+ g_ptr_array_add (channels, (gpointer) value);
+ continue;
+ }
+
field_data = find_info_field_data (field->field_name);
if (field_data == NULL)
{
@@ -585,6 +652,13 @@ contact_widget_details_update_show (EmpathyContactWidget *information)
}
g_list_free (info);
+ if (channels->len > 0)
+ {
+ add_channel_list (information, channels, n_rows);
+ n_rows++;
+ }
+
+ g_ptr_array_unref (channels);
return n_rows;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]