Tue, 10 Oct 2023 03:02:41 -0500
Add tooltips to timestamps in PidginConversation
This allows you to get a tooltip for the timestamp and the edited label that
displays the time in the locale's default format. The edited label was tested
by forcing the demo protocol plugin to mark messages as edited.
Testing Done:
Sent a bunch of messages with the echo bot and verified the timestamp tooltip on IRCv3 as well.
Reviewed at https://reviews.imfreedom.org/r/2645/
| pidgin/pidginconversation.c | file | annotate | diff | comparison | revisions | |
| pidgin/resources/Conversations/message.ui | file | annotate | diff | comparison | revisions |
--- a/pidgin/pidginconversation.c Tue Oct 10 01:21:52 2023 -0500 +++ b/pidgin/pidginconversation.c Tue Oct 10 03:02:41 2023 -0500 @@ -78,6 +78,40 @@ } } +/** + * pidgin_conversation_set_tooltip_for_timestamp: (skip) + * @tooltip: The tooltip to update. + * @timestamp: The timestamp to set. + * + * Updates @tooltip to display @timestamp. This is meant to be called from + * a GtkWidget::query-tooltip signal and its return value should be returned + * from that handler. + * + * Returns: %TRUE if a tooltip was set, otherwise %FALSE. + * + * Since: 3.0.0 + */ +static gboolean +pidgin_conversation_set_tooltip_for_timestamp(GtkTooltip *tooltip, + GDateTime *timestamp) +{ + GDateTime *local = NULL; + char *text = NULL; + + if(timestamp == NULL) { + return FALSE; + } + + local = g_date_time_to_local(timestamp); + text = g_date_time_format(local, "%c"); + g_clear_pointer(&local, g_date_time_unref); + + gtk_tooltip_set_text(tooltip, text); + g_clear_pointer(&text, g_free); + + return TRUE; +} + /****************************************************************************** * Callbacks *****************************************************************************/ @@ -171,6 +205,47 @@ return NULL; } +static gboolean +pidgin_conversation_query_tooltip_timestamp_cb(G_GNUC_UNUSED GtkWidget *self, + G_GNUC_UNUSED gint x, + G_GNUC_UNUSED gint y, + G_GNUC_UNUSED gboolean keyboard_mode, + GtkTooltip *tooltip, + gpointer data) +{ + + PurpleMessage *message = gtk_list_item_get_item(data); + GDateTime *timestamp = NULL; + + if(!PURPLE_IS_MESSAGE(message)) { + return FALSE; + } + + timestamp = purple_message_get_timestamp(message); + + return pidgin_conversation_set_tooltip_for_timestamp(tooltip, timestamp); +} + +static gboolean +pidgin_conversation_query_tooltip_edited_cb(G_GNUC_UNUSED GtkWidget *self, + G_GNUC_UNUSED gint x, + G_GNUC_UNUSED gint y, + G_GNUC_UNUSED gboolean keyboard_mode, + GtkTooltip *tooltip, + gpointer data) +{ + PurpleMessage *message = gtk_list_item_get_item(data); + GDateTime *timestamp = NULL; + + if(!PURPLE_IS_MESSAGE(message)) { + return FALSE; + } + + timestamp = purple_message_get_edited_at(message); + + return pidgin_conversation_set_tooltip_for_timestamp(tooltip, timestamp); +} + /****************************************************************************** * GObject Implementation *****************************************************************************/ @@ -269,6 +344,10 @@ pidgin_conversation_get_author_attributes); gtk_widget_class_bind_template_callback(widget_class, pidgin_converation_get_timestamp_string); + gtk_widget_class_bind_template_callback(widget_class, + pidgin_conversation_query_tooltip_timestamp_cb); + gtk_widget_class_bind_template_callback(widget_class, + pidgin_conversation_query_tooltip_edited_cb); } /******************************************************************************
--- a/pidgin/resources/Conversations/message.ui Tue Oct 10 01:21:52 2023 -0500 +++ b/pidgin/resources/Conversations/message.ui Tue Oct 10 03:02:41 2023 -0500 @@ -55,12 +55,20 @@ <lookup name="item">GtkListItem</lookup> </closure> </binding> + <property name="has-tooltip">1</property> + <signal name="query-tooltip" handler="pidgin_conversation_query_tooltip_timestamp_cb"/> </object> </child> <child> <object class="GtkLabel" id="edited"> - <property name="visible">0</property> + <binding name="visible"> + <lookup name="edited" type="PurpleMessage"> + <lookup name="item">GtkListItem</lookup> + </lookup> + </binding> <property name="label" translatable="yes">(edited)</property> + <property name="has-tooltip">1</property> + <signal name="query-tooltip" handler="pidgin_conversation_query_tooltip_edited_cb"/> </object> </child> </object>