summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Kramlich <grim@reaperworld.com>2023-03-29 23:21:05 -0500
committerGary Kramlich <grim@reaperworld.com>2023-03-29 23:21:05 -0500
commit775b3b5f985f0f45afccc5449778978bb6d7e6aa (patch)
tree95f9fd56377e6c89bc56425db43c4dda4daffd4e
parent360291de4b74d2c7c23e7fc9d80e1cded9dab8e3 (diff)
downloadpidgin-775b3b5f985f0f45afccc5449778978bb6d7e6aa.tar.gz
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/
-rw-r--r--pidgin/pidgincontactlist.c53
-rw-r--r--pidgin/resources/ContactList/widget.ui36
2 files changed, 81 insertions, 8 deletions
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 <https://www.gnu.org/licenses/>.
<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>