commit 2ed903525356c027d16fc3ae7cef16a7ee1775af
parent ddbfde655bbb235ebd94e1309db3c05b75cbe3b8
Author: TheJackiMonster <thejackimonster@gmail.com>
Date: Fri, 18 Mar 2022 00:02:59 +0100
Sorting chats by timestamp and additional safety for touchscreen with flaps
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
Diffstat:
6 files changed, 149 insertions(+), 14 deletions(-)
diff --git a/resources/ui/contact_info.ui b/resources/ui/contact_info.ui
@@ -110,23 +110,23 @@ Author: Tobias Frisch
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">1</property>
+ <property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkBox">
+ <property name="width-request">250</property>
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">4</property>
<child>
<object class="GtkEntry" id="contact_name">
- <property name="width-request">210</property>
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can-focus">True</property>
</object>
<packing>
- <property name="expand">False</property>
+ <property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
@@ -147,6 +147,7 @@ Author: Tobias Frisch
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
+ <property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
@@ -154,7 +155,7 @@ Author: Tobias Frisch
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">2</property>
+ <property name="position">3</property>
</packing>
</child>
<child>
@@ -167,7 +168,7 @@ Author: Tobias Frisch
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">3</property>
+ <property name="position">4</property>
</packing>
</child>
<child>
@@ -180,7 +181,7 @@ Author: Tobias Frisch
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
- <property name="position">4</property>
+ <property name="position">5</property>
</packing>
</child>
</object>
@@ -189,17 +190,80 @@ Author: Tobias Frisch
</packing>
</child>
<child>
- <object class="GtkDrawingArea" id="id_drawing_area">
- <property name="height-request">250</property>
+ <object class="GtkBox" id="identity_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
- <property name="margin-start">16</property>
- <property name="margin-end">16</property>
- <property name="margin-top">16</property>
- <property name="margin-bottom">16</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="border-width">8</property>
+ <property name="orientation">vertical</property>
+ <property name="spacing">4</property>
+ <child>
+ <object class="GtkLabel" id="name_label">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="border-width">8</property>
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkDrawingArea" id="id_drawing_area">
+ <property name="height-request">250</property>
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkLabel">
+ <property name="visible">True</property>
+ <property name="can-focus">False</property>
+ <property name="label" translatable="yes">ID:</property>
+ <property name="xalign">0</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">2</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkEntry" id="id_entry">
+ <property name="width-request">250</property>
+ <property name="visible">True</property>
+ <property name="can-focus">True</property>
+ <property name="editable">False</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
<packing>
- <property name="name">drawing_page</property>
+ <property name="name">page0</property>
+ <property name="title" translatable="yes">page0</property>
<property name="position">1</property>
</packing>
</child>
diff --git 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
@@ -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
@@ -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
@@ -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
@@ -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,