From 775b3b5f985f0f45afccc5449778978bb6d7e6aa Mon Sep 17 00:00:00 2001 From: Gary Kramlich Date: Wed, 29 Mar 2023 23:21:05 -0500 Subject: Add the presence primitive and idle time to the contact list The idle time is getting overwritten by something right now which is unrelated and will be addressed separately. Testing Done: Connected the demo protocol plugin and looked at the contact list. Reviewed at https://reviews.imfreedom.org/r/2391/ --- pidgin/pidgincontactlist.c | 53 ++++++++++++++++++++++++++++++++++ pidgin/resources/ContactList/widget.ui | 36 ++++++++++++++++++----- 2 files changed, 81 insertions(+), 8 deletions(-) (limited to 'pidgin') diff --git a/pidgin/pidgincontactlist.c b/pidgin/pidgincontactlist.c index 91a4047927..fd09bbe6a4 100644 --- a/pidgin/pidgincontactlist.c +++ b/pidgin/pidgincontactlist.c @@ -168,6 +168,57 @@ pidgin_contact_list_message_visible_cb(G_GNUC_UNUSED GtkListItem *item, return !purple_strempty(message); } +static char * +pidgin_contact_list_get_primitive_as_string(G_GNUC_UNUSED GObject *self, + PurplePresence *presence, + G_GNUC_UNUSED gpointer data) +{ + PurplePresencePrimitive primitive; + GDateTime *idle = NULL; + GString *str = g_string_new(NULL); + const char *tmp = NULL; + + if(!PURPLE_IS_PRESENCE(presence)) { + return g_string_free(str, FALSE); + } + + primitive = purple_presence_get_primitive(presence); + tmp = purple_presence_primitive_to_string(primitive); + if(tmp != NULL) { + g_string_append_printf(str, " - %s", tmp); + } + + idle = purple_presence_get_idle_time(presence); + if(idle != NULL) { + GDateTime *now = NULL; + GTimeSpan duration; + guint days; + guint hours; + guint minutes; + + now = g_date_time_new_now_utc(); + duration = g_date_time_difference(now, idle); + g_date_time_unref(now); + + days = duration / G_TIME_SPAN_DAY; + duration %= G_TIME_SPAN_DAY; + hours = duration / G_TIME_SPAN_HOUR; + duration %= G_TIME_SPAN_HOUR; + minutes = duration / G_TIME_SPAN_MINUTE; + + if(days > 0) { + g_string_append_printf(str, _(" Idle %dd %dh %02dm"), days, hours, + minutes); + } else if(hours > 0) { + g_string_append_printf(str, _(" Idle %dh %02dm"), hours, minutes); + } else if(minutes > 0) { + g_string_append_printf(str, _(" Idle %02dm"), minutes); + } + } + + return g_string_free(str, FALSE); +} + /****************************************************************************** * GObject Implementation *****************************************************************************/ @@ -212,6 +263,8 @@ pidgin_contact_list_class_init(PidginContactListClass *klass) { pidgin_contact_list_activate_cb); gtk_widget_class_bind_template_callback(widget_class, pidgin_contact_list_message_visible_cb); + gtk_widget_class_bind_template_callback(widget_class, + pidgin_contact_list_get_primitive_as_string); } /****************************************************************************** diff --git a/pidgin/resources/ContactList/widget.ui b/pidgin/resources/ContactList/widget.ui index d32a3e055b..db28d6f354 100644 --- a/pidgin/resources/ContactList/widget.ui +++ b/pidgin/resources/ContactList/widget.ui @@ -70,14 +70,34 @@ along with this library; if not, see . 1 center - - 0 - 1 - - - GtkListItem - - + + horizontal + + + + 0 + 1 + + + GtkListItem + + + + + + + 0 + + + + + GtkListItem + + + + + + -- cgit v1.2.1