aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-18 00:02:59 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-18 00:02:59 +0100
commit2ed903525356c027d16fc3ae7cef16a7ee1775af (patch)
tree4af4304a50eccaec315842313c5f8a042e850284
parentddbfde655bbb235ebd94e1309db3c05b75cbe3b8 (diff)
downloadmessenger-gtk-2ed903525356c027d16fc3ae7cef16a7ee1775af.tar.gz
messenger-gtk-2ed903525356c027d16fc3ae7cef16a7ee1775af.zip
Sorting chats by timestamp and additional safety for touchscreen with flaps
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--resources/ui/contact_info.ui90
-rw-r--r--src/ui/chat_entry.c6
-rw-r--r--src/ui/chat_entry.h2
-rw-r--r--src/ui/contact_info.c18
-rw-r--r--src/ui/contact_info.h4
-rw-r--r--src/ui/messenger.c43
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
110 <packing> 110 <packing>
111 <property name="expand">False</property> 111 <property name="expand">False</property>
112 <property name="fill">True</property> 112 <property name="fill">True</property>
113 <property name="position">1</property> 113 <property name="position">2</property>
114 </packing> 114 </packing>
115 </child> 115 </child>
116 <child> 116 <child>
117 <object class="GtkBox"> 117 <object class="GtkBox">
118 <property name="width-request">250</property>
118 <property name="visible">True</property> 119 <property name="visible">True</property>
119 <property name="can-focus">False</property> 120 <property name="can-focus">False</property>
120 <property name="spacing">4</property> 121 <property name="spacing">4</property>
121 <child> 122 <child>
122 <object class="GtkEntry" id="contact_name"> 123 <object class="GtkEntry" id="contact_name">
123 <property name="width-request">210</property>
124 <property name="visible">True</property> 124 <property name="visible">True</property>
125 <property name="sensitive">False</property> 125 <property name="sensitive">False</property>
126 <property name="can-focus">True</property> 126 <property name="can-focus">True</property>
127 </object> 127 </object>
128 <packing> 128 <packing>
129 <property name="expand">False</property> 129 <property name="expand">True</property>
130 <property name="fill">True</property> 130 <property name="fill">True</property>
131 <property name="position">0</property> 131 <property name="position">0</property>
132 </packing> 132 </packing>
@@ -147,6 +147,7 @@ Author: Tobias Frisch
147 <packing> 147 <packing>
148 <property name="expand">False</property> 148 <property name="expand">False</property>
149 <property name="fill">True</property> 149 <property name="fill">True</property>
150 <property name="pack-type">end</property>
150 <property name="position">1</property> 151 <property name="position">1</property>
151 </packing> 152 </packing>
152 </child> 153 </child>
@@ -154,7 +155,7 @@ Author: Tobias Frisch
154 <packing> 155 <packing>
155 <property name="expand">False</property> 156 <property name="expand">False</property>
156 <property name="fill">True</property> 157 <property name="fill">True</property>
157 <property name="position">2</property> 158 <property name="position">3</property>
158 </packing> 159 </packing>
159 </child> 160 </child>
160 <child> 161 <child>
@@ -167,7 +168,7 @@ Author: Tobias Frisch
167 <packing> 168 <packing>
168 <property name="expand">False</property> 169 <property name="expand">False</property>
169 <property name="fill">True</property> 170 <property name="fill">True</property>
170 <property name="position">3</property> 171 <property name="position">4</property>
171 </packing> 172 </packing>
172 </child> 173 </child>
173 <child> 174 <child>
@@ -180,7 +181,7 @@ Author: Tobias Frisch
180 <packing> 181 <packing>
181 <property name="expand">False</property> 182 <property name="expand">False</property>
182 <property name="fill">True</property> 183 <property name="fill">True</property>
183 <property name="position">4</property> 184 <property name="position">5</property>
184 </packing> 185 </packing>
185 </child> 186 </child>
186 </object> 187 </object>
@@ -189,17 +190,80 @@ Author: Tobias Frisch
189 </packing> 190 </packing>
190 </child> 191 </child>
191 <child> 192 <child>
192 <object class="GtkDrawingArea" id="id_drawing_area"> 193 <object class="GtkBox" id="identity_box">
193 <property name="height-request">250</property>
194 <property name="visible">True</property> 194 <property name="visible">True</property>
195 <property name="can-focus">False</property> 195 <property name="can-focus">False</property>
196 <property name="margin-start">16</property> 196 <property name="halign">center</property>
197 <property name="margin-end">16</property> 197 <property name="valign">center</property>
198 <property name="margin-top">16</property> 198 <property name="border-width">8</property>
199 <property name="margin-bottom">16</property> 199 <property name="orientation">vertical</property>
200 <property name="spacing">4</property>
201 <child>
202 <object class="GtkLabel" id="name_label">
203 <property name="visible">True</property>
204 <property name="can-focus">False</property>
205 </object>
206 <packing>
207 <property name="expand">False</property>
208 <property name="fill">True</property>
209 <property name="position">0</property>
210 </packing>
211 </child>
212 <child>
213 <object class="GtkBox">
214 <property name="visible">True</property>
215 <property name="can-focus">False</property>
216 <property name="border-width">8</property>
217 <property name="orientation">vertical</property>
218 <child>
219 <object class="GtkDrawingArea" id="id_drawing_area">
220 <property name="height-request">250</property>
221 <property name="visible">True</property>
222 <property name="can-focus">False</property>
223 </object>
224 <packing>
225 <property name="expand">False</property>
226 <property name="fill">True</property>
227 <property name="position">0</property>
228 </packing>
229 </child>
230 </object>
231 <packing>
232 <property name="expand">False</property>
233 <property name="fill">True</property>
234 <property name="position">1</property>
235 </packing>
236 </child>
237 <child>
238 <object class="GtkLabel">
239 <property name="visible">True</property>
240 <property name="can-focus">False</property>
241 <property name="label" translatable="yes">ID:</property>
242 <property name="xalign">0</property>
243 </object>
244 <packing>
245 <property name="expand">False</property>
246 <property name="fill">True</property>
247 <property name="position">2</property>
248 </packing>
249 </child>
250 <child>
251 <object class="GtkEntry" id="id_entry">
252 <property name="width-request">250</property>
253 <property name="visible">True</property>
254 <property name="can-focus">True</property>
255 <property name="editable">False</property>
256 </object>
257 <packing>
258 <property name="expand">False</property>
259 <property name="fill">True</property>
260 <property name="position">3</property>
261 </packing>
262 </child>
200 </object> 263 </object>
201 <packing> 264 <packing>
202 <property name="name">drawing_page</property> 265 <property name="name">page0</property>
266 <property name="title" translatable="yes">page0</property>
203 <property name="position">1</property> 267 <property name="position">1</property>
204 </packing> 268 </packing>
205 </child> 269 </child>
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)
36 36
37 memset(handle, 0, sizeof(*handle)); 37 memset(handle, 0, sizeof(*handle));
38 38
39 handle->timestamp = GNUNET_TIME_absolute_get_zero_();
40
39 handle->chat = ui_chat_new(app); 41 handle->chat = ui_chat_new(app);
40 handle->builder = gtk_builder_new_from_resource( 42 handle->builder = gtk_builder_new_from_resource(
41 application_get_resource_path(app, "ui/chat_entry.ui") 43 application_get_resource_path(app, "ui/chat_entry.ui")
@@ -114,6 +116,8 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
114 (UI_MESSAGE_Handle*) handle->chat->messages->data 116 (UI_MESSAGE_Handle*) handle->chat->messages->data
115 ); 117 );
116 118
119 handle->timestamp = message->timestamp;
120
117 const gchar *text = gtk_label_get_text(message->text_label); 121 const gchar *text = gtk_label_get_text(message->text_label);
118 const gchar *time = gtk_label_get_text(message->timestamp_label); 122 const gchar *time = gtk_label_get_text(message->timestamp_label);
119 123
@@ -143,6 +147,8 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle,
143 GTK_WIDGET(message->read_receipt_image) 147 GTK_WIDGET(message->read_receipt_image)
144 ) : FALSE 148 ) : FALSE
145 ); 149 );
150
151 gtk_list_box_invalidate_sort(app->ui.messenger.chats_listbox);
146} 152}
147 153
148void 154void
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
31{ 31{
32 guint update; 32 guint update;
33 33
34 struct GNUNET_TIME_Absolute timestamp;
35
34 UI_CHAT_Handle *chat; 36 UI_CHAT_Handle *chat;
35 GtkBuilder *builder; 37 GtkBuilder *builder;
36 38
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)
95 95
96 gtk_stack_set_visible_child( 96 gtk_stack_set_visible_child(
97 handle->contact_info_stack, 97 handle->contact_info_stack,
98 GTK_WIDGET(handle->id_drawing_area) 98 handle->identity_box
99 ); 99 );
100} 100}
101 101
@@ -355,6 +355,14 @@ ui_contact_info_dialog_init(MESSENGER_Application *app,
355 handle 355 handle
356 ); 356 );
357 357
358 handle->identity_box = GTK_WIDGET(
359 gtk_builder_get_object(handle->builder, "identity_box")
360 );
361
362 handle->name_label = GTK_LABEL(
363 gtk_builder_get_object(handle->builder, "name_label")
364 );
365
358 handle->id_drawing_area = GTK_DRAWING_AREA( 366 handle->id_drawing_area = GTK_DRAWING_AREA(
359 gtk_builder_get_object(handle->builder, "id_drawing_area") 367 gtk_builder_get_object(handle->builder, "id_drawing_area")
360 ); 368 );
@@ -366,6 +374,10 @@ ui_contact_info_dialog_init(MESSENGER_Application *app,
366 handle 374 handle
367 ); 375 );
368 376
377 handle->id_entry = GTK_ENTRY(
378 gtk_builder_get_object(handle->builder, "id_entry")
379 );
380
369 handle->back_button = GTK_BUTTON( 381 handle->back_button = GTK_BUTTON(
370 gtk_builder_get_object(handle->builder, "back_button") 382 gtk_builder_get_object(handle->builder, "back_button")
371 ); 383 );
@@ -428,9 +440,13 @@ ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle,
428 else 440 else
429 handle->qr = NULL; 441 handle->qr = NULL;
430 442
443 gtk_label_set_text(handle->name_label, name? name : "");
444
431 if (handle->id_drawing_area) 445 if (handle->id_drawing_area)
432 gtk_widget_queue_draw(GTK_WIDGET(handle->id_drawing_area)); 446 gtk_widget_queue_draw(GTK_WIDGET(handle->id_drawing_area));
433 447
448 gtk_entry_set_text(handle->id_entry, key? key : "");
449
434 gtk_widget_set_sensitive( 450 gtk_widget_set_sensitive(
435 GTK_WIDGET(handle->reveal_identity_button), 451 GTK_WIDGET(handle->reveal_identity_button),
436 key? TRUE : FALSE 452 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
50 GtkButton *reveal_identity_button; 50 GtkButton *reveal_identity_button;
51 GtkButton *open_chat_button; 51 GtkButton *open_chat_button;
52 52
53 GtkWidget *identity_box;
54 GtkLabel *name_label;
55
53 GtkDrawingArea *id_drawing_area; 56 GtkDrawingArea *id_drawing_area;
54 gulong id_draw_signal; 57 gulong id_draw_signal;
58 GtkEntry *id_entry;
55 59
56 GtkButton *back_button; 60 GtkButton *back_button;
57 GtkButton *close_button; 61 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)
50 hdy_flap_set_reveal_flap(flap, TRUE); 50 hdy_flap_set_reveal_flap(flap, TRUE);
51 } 51 }
52 52
53 gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_search), TRUE);
53 gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_listbox), TRUE); 54 gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_listbox), TRUE);
54 return FALSE; 55 return FALSE;
55} 56}
@@ -60,6 +61,7 @@ handle_user_details_via_button_click(UNUSED GtkButton* button,
60{ 61{
61 UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; 62 UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data;
62 63
64 gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_search), FALSE);
63 gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_listbox), FALSE); 65 gtk_widget_set_sensitive(GTK_WIDGET(handle->chats_listbox), FALSE);
64 g_idle_add( 66 g_idle_add(
65 G_SOURCE_FUNC(_flap_user_details_reveal_switch), 67 G_SOURCE_FUNC(_flap_user_details_reveal_switch),
@@ -236,6 +238,40 @@ handle_chats_listbox_row_activated(UNUSED GtkListBox* listbox,
236 gtk_stack_set_visible_child(stack, entry->chat->chat_box); 238 gtk_stack_set_visible_child(stack, entry->chat->chat_box);
237} 239}
238 240
241static gint
242handle_chats_listbox_sort_func(GtkListBoxRow* row0,
243 GtkListBoxRow* row1,
244 gpointer user_data)
245{
246 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
247
248 if ((!row0) || (!row1) ||
249 (!gtk_list_box_row_get_selectable(row0)) ||
250 (!gtk_list_box_row_get_selectable(row1)))
251 return 0;
252
253 UI_CHAT_ENTRY_Handle *entry0 = (UI_CHAT_ENTRY_Handle*) (
254 g_object_get_qdata(G_OBJECT(row0), app->quarks.ui)
255 );
256
257 UI_CHAT_ENTRY_Handle *entry1 = (UI_CHAT_ENTRY_Handle*) (
258 g_object_get_qdata(G_OBJECT(row1), app->quarks.ui)
259 );
260
261 if ((!entry0) || (!entry1))
262 return 0;
263
264 struct GNUNET_TIME_Absolute timestamp0 = entry0->timestamp;
265 struct GNUNET_TIME_Absolute timestamp1 = entry1->timestamp;
266
267 if (GNUNET_TIME_absolute_cmp(timestamp0, >, timestamp1))
268 return -1;
269 else if (GNUNET_TIME_absolute_cmp(timestamp0, <, timestamp1))
270 return +1;
271 else
272 return 0;
273}
274
239static gboolean 275static gboolean
240handle_chats_listbox_filter_func(GtkListBoxRow *row, 276handle_chats_listbox_filter_func(GtkListBoxRow *row,
241 gpointer user_data) 277 gpointer user_data)
@@ -517,6 +553,13 @@ ui_messenger_init(MESSENGER_Application *app,
517 gtk_builder_get_object(handle->builder, "chats_listbox") 553 gtk_builder_get_object(handle->builder, "chats_listbox")
518 ); 554 );
519 555
556 gtk_list_box_set_sort_func(
557 handle->chats_listbox,
558 handle_chats_listbox_sort_func,
559 app,
560 NULL
561 );
562
520 gtk_list_box_set_filter_func( 563 gtk_list_box_set_filter_func(
521 handle->chats_listbox, 564 handle->chats_listbox,
522 handle_chats_listbox_filter_func, 565 handle_chats_listbox_filter_func,