pidgin/pidgin

91d0671d4778
Parents 4e1bf25f5575
Children 637ba5491231
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/
--- a/pidgin/pidgincontactlist.c Thu Mar 23 23:11:59 2023 -0500
+++ b/pidgin/pidgincontactlist.c Wed Mar 29 23:21:05 2023 -0500
@@ -168,6 +168,57 @@
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_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);
}
/******************************************************************************
--- a/pidgin/resources/ContactList/widget.ui Thu Mar 23 23:11:59 2023 -0500
+++ b/pidgin/resources/ContactList/widget.ui Wed Mar 29 23:21:05 2023 -0500
@@ -70,14 +70,34 @@
<property name="vexpand">1</property>
<property name="valign">center</property>
<child>
- <object class="GtkLabel">
- <property name="xalign">0</property>
- <property name="use-markup">1</property>
- <binding name="label">
- <lookup name="name-for-display" type="PurplePerson">
- <lookup name="item">GtkListItem</lookup>
- </lookup>
- </binding>
+ <object class="GtkBox">
+ <property name="orientation">horizontal</property>
+
+ <child>
+ <object class="GtkLabel">
+ <property name="xalign">0</property>
+ <property name="use-markup">1</property>
+ <binding name="label">
+ <lookup name="name-for-display" type="PurplePerson">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </binding>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="xalign">0</property>
+ <binding name="label">
+ <closure type="gchararray" function="pidgin_contact_list_get_primitive_as_string">
+ <lookup name="presence" type="PurpleContactInfo">
+ <lookup name="priority-contact-info" type="PurplePerson">
+ <lookup name="item">GtkListItem</lookup>
+ </lookup>
+ </lookup>
+ </closure>
+ </binding>
+ </object>
+ </child>
</object>
</child>
<child>