From 2ed903525356c027d16fc3ae7cef16a7ee1775af Mon Sep 17 00:00:00 2001 From: TheJackiMonster Date: Fri, 18 Mar 2022 00:02:59 +0100 Subject: Sorting chats by timestamp and additional safety for touchscreen with flaps Signed-off-by: TheJackiMonster --- resources/ui/contact_info.ui | 90 +++++++++++++++++++++++++++++++++++++------- src/ui/chat_entry.c | 6 +++ src/ui/chat_entry.h | 2 + src/ui/contact_info.c | 18 ++++++++- src/ui/contact_info.h | 4 ++ src/ui/messenger.c | 43 +++++++++++++++++++++ 6 files changed, 149 insertions(+), 14 deletions(-) diff --git a/resources/ui/contact_info.ui b/resources/ui/contact_info.ui index 4f69d59..8928783 100644 --- a/resources/ui/contact_info.ui +++ b/resources/ui/contact_info.ui @@ -110,23 +110,23 @@ Author: Tobias Frisch False True - 1 + 2 + 250 True False 4 - 210 True False True - False + True True 0 @@ -147,6 +147,7 @@ Author: Tobias Frisch False True + end 1 @@ -154,7 +155,7 @@ Author: Tobias Frisch False True - 2 + 3 @@ -167,7 +168,7 @@ Author: Tobias Frisch False True - 3 + 4 @@ -180,7 +181,7 @@ Author: Tobias Frisch False True - 4 + 5 @@ -189,17 +190,80 @@ Author: Tobias Frisch - - 250 + True False - 16 - 16 - 16 - 16 + center + center + 8 + vertical + 4 + + + True + False + + + False + True + 0 + + + + + True + False + 8 + vertical + + + 250 + True + False + + + False + True + 0 + + + + + False + True + 1 + + + + + True + False + ID: + 0 + + + False + True + 2 + + + + + 250 + True + True + False + + + False + True + 3 + + - drawing_page + page0 + page0 1 diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c index 7ba67d2..85684f0 100644 --- a/src/ui/chat_entry.c +++ b/src/ui/chat_entry.c @@ -36,6 +36,8 @@ ui_chat_entry_new(MESSENGER_Application *app) memset(handle, 0, sizeof(*handle)); + handle->timestamp = GNUNET_TIME_absolute_get_zero_(); + handle->chat = ui_chat_new(app); handle->builder = gtk_builder_new_from_resource( application_get_resource_path(app, "ui/chat_entry.ui") @@ -114,6 +116,8 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, (UI_MESSAGE_Handle*) handle->chat->messages->data ); + handle->timestamp = message->timestamp; + const gchar *text = gtk_label_get_text(message->text_label); const gchar *time = gtk_label_get_text(message->timestamp_label); @@ -143,6 +147,8 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, GTK_WIDGET(message->read_receipt_image) ) : FALSE ); + + gtk_list_box_invalidate_sort(app->ui.messenger.chats_listbox); } void diff --git a/src/ui/chat_entry.h b/src/ui/chat_entry.h index 2515e2c..1e2896f 100644 --- a/src/ui/chat_entry.h +++ b/src/ui/chat_entry.h @@ -31,6 +31,8 @@ typedef struct UI_CHAT_ENTRY_Handle { guint update; + struct GNUNET_TIME_Absolute timestamp; + UI_CHAT_Handle *chat; GtkBuilder *builder; diff --git a/src/ui/contact_info.c b/src/ui/contact_info.c index 1592a76..05f12a6 100644 --- a/src/ui/contact_info.c +++ b/src/ui/contact_info.c @@ -95,7 +95,7 @@ _contact_info_reveal_identity(UI_CONTACT_INFO_Handle *handle) gtk_stack_set_visible_child( handle->contact_info_stack, - GTK_WIDGET(handle->id_drawing_area) + handle->identity_box ); } @@ -355,6 +355,14 @@ ui_contact_info_dialog_init(MESSENGER_Application *app, handle ); + handle->identity_box = GTK_WIDGET( + gtk_builder_get_object(handle->builder, "identity_box") + ); + + handle->name_label = GTK_LABEL( + gtk_builder_get_object(handle->builder, "name_label") + ); + handle->id_drawing_area = GTK_DRAWING_AREA( gtk_builder_get_object(handle->builder, "id_drawing_area") ); @@ -366,6 +374,10 @@ ui_contact_info_dialog_init(MESSENGER_Application *app, handle ); + handle->id_entry = GTK_ENTRY( + gtk_builder_get_object(handle->builder, "id_entry") + ); + handle->back_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "back_button") ); @@ -428,9 +440,13 @@ ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle, else handle->qr = NULL; + gtk_label_set_text(handle->name_label, name? name : ""); + if (handle->id_drawing_area) gtk_widget_queue_draw(GTK_WIDGET(handle->id_drawing_area)); + gtk_entry_set_text(handle->id_entry, key? key : ""); + gtk_widget_set_sensitive( GTK_WIDGET(handle->reveal_identity_button), key? TRUE : FALSE diff --git a/src/ui/contact_info.h b/src/ui/contact_info.h index 9b89f3c..f602073 100644 --- a/src/ui/contact_info.h +++ b/src/ui/contact_info.h @@ -50,8 +50,12 @@ typedef struct UI_CONTACT_INFO_Handle GtkButton *reveal_identity_button; GtkButton *open_chat_button; + GtkWidget *identity_box; + GtkLabel *name_label; + GtkDrawingArea *id_drawing_area; gulong id_draw_signal; + GtkEntry *id_entry; GtkButton *back_button; GtkButton *close_button; diff --git a/src/ui/messenger.c b/src/ui/messenger.c index e6ea657..69200f9 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c @@ -50,6 +50,7 @@ _flap_user_details_reveal_switch(gpointer user_data) hdy_flap_set_reveal_flap(flap, TRUE); } + gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_search), TRUE); gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_listbox), TRUE); return FALSE; } @@ -60,6 +61,7 @@ handle_user_details_via_button_click(UNUSED GtkButton* button, { UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; + gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_search), FALSE); gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_listbox), FALSE); g_idle_add( G_SOURCE_FUNC(_flap_user_details_reveal_switch), @@ -236,6 +238,40 @@ handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox, gtk_stack_set_visible_child(stack, entry->chat->chat_box); } +static gint +handle_chats_listbox_sort_func(GtkListBoxRow* row0, + GtkListBoxRow* row1, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + if ((!row0) || (!row1) || + (!gtk_list_box_row_get_selectable(row0)) || + (!gtk_list_box_row_get_selectable(row1))) + return 0; + + UI_CHAT_ENTRY_Handle *entry0 = (UI_CHAT_ENTRY_Handle*) ( + g_object_get_qdata(G_OBJECT(row0), app->quarks.ui) + ); + + UI_CHAT_ENTRY_Handle *entry1 = (UI_CHAT_ENTRY_Handle*) ( + g_object_get_qdata(G_OBJECT(row1), app->quarks.ui) + ); + + if ((!entry0) || (!entry1)) + return 0; + + struct GNUNET_TIME_Absolute timestamp0 = entry0->timestamp; + struct GNUNET_TIME_Absolute timestamp1 = entry1->timestamp; + + if (GNUNET_TIME_absolute_cmp(timestamp0, >, timestamp1)) + return -1; + else if (GNUNET_TIME_absolute_cmp(timestamp0, <, timestamp1)) + return +1; + else + return 0; +} + static gboolean handle_chats_listbox_filter_func(GtkListBoxRow *row, gpointer user_data) @@ -517,6 +553,13 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "chats_listbox") ); + gtk_list_box_set_sort_func( + handle->chats_listbox, + handle_chats_listbox_sort_func, + app, + NULL + ); + gtk_list_box_set_filter_func( handle->chats_listbox, handle_chats_listbox_filter_func, -- cgit v1.2.3