aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2021-12-21 22:31:34 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2021-12-21 22:31:34 +0100
commit412c7d4f210096c7cde549c48e3e2a2262724d00 (patch)
treed297321c014607c196df66fa2b66a0f54e38e935
parentbd545ea846e668112e5a54b702acc9c9f9231aea (diff)
downloadmessenger-gtk-412c7d4f210096c7cde549c48e3e2a2262724d00.tar.gz
messenger-gtk-412c7d4f210096c7cde549c48e3e2a2262724d00.zip
Added automatic scrolling to chats
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--resources/ui/chat.ui18
-rw-r--r--resources/ui/message_content.ui2
-rw-r--r--src/chat/messenger.c1
-rw-r--r--src/event.c4
-rw-r--r--src/ui/chat.c35
-rw-r--r--src/ui/chat.h3
-rw-r--r--src/ui/message.c33
-rw-r--r--src/ui/message.h8
8 files changed, 88 insertions, 16 deletions
diff --git a/resources/ui/chat.ui b/resources/ui/chat.ui
index 8d9cb02..c70eb40 100644
--- a/resources/ui/chat.ui
+++ b/resources/ui/chat.ui
@@ -145,7 +145,7 @@ Author: Tobias Frisch
145 </packing> 145 </packing>
146 </child> 146 </child>
147 <child> 147 <child>
148 <object class="GtkScrolledWindow"> 148 <object class="GtkScrolledWindow" id="chat_scrolled_window">
149 <property name="visible">True</property> 149 <property name="visible">True</property>
150 <property name="can-focus">True</property> 150 <property name="can-focus">True</property>
151 <child> 151 <child>
@@ -153,21 +153,11 @@ Author: Tobias Frisch
153 <property name="visible">True</property> 153 <property name="visible">True</property>
154 <property name="can-focus">False</property> 154 <property name="can-focus">False</property>
155 <child> 155 <child>
156 <object class="GtkStack"> 156 <object class="GtkListBox" id="messages_listbox">
157 <property name="visible">True</property> 157 <property name="visible">True</property>
158 <property name="can-focus">False</property> 158 <property name="can-focus">False</property>
159 <child> 159 <property name="selection-mode">none</property>
160 <object class="GtkListBox" id="messages_listbox"> 160 <property name="activate-on-single-click">False</property>
161 <property name="visible">True</property>
162 <property name="can-focus">False</property>
163 <property name="selection-mode">none</property>
164 <property name="activate-on-single-click">False</property>
165 </object>
166 <packing>
167 <property name="name">page0</property>
168 <property name="title" translatable="yes">page0</property>
169 </packing>
170 </child>
171 </object> 161 </object>
172 </child> 162 </child>
173 </object> 163 </object>
diff --git a/resources/ui/message_content.ui b/resources/ui/message_content.ui
index bca5165..a59c59e 100644
--- a/resources/ui/message_content.ui
+++ b/resources/ui/message_content.ui
@@ -71,7 +71,7 @@ Author: Tobias Frisch
71 </packing> 71 </packing>
72 </child> 72 </child>
73 <child> 73 <child>
74 <object class="GtkStack"> 74 <object class="GtkStack" id="content_stack">
75 <property name="visible">True</property> 75 <property name="visible">True</property>
76 <property name="can-focus">False</property> 76 <property name="can-focus">False</property>
77 <child> 77 <child>
diff --git a/src/chat/messenger.c b/src/chat/messenger.c
index c7eb033..ea8b450 100644
--- a/src/chat/messenger.c
+++ b/src/chat/messenger.c
@@ -146,6 +146,7 @@ _chat_messenger_message(void *cls,
146 break; 146 break;
147 } 147 }
148 case GNUNET_CHAT_KIND_TEXT: 148 case GNUNET_CHAT_KIND_TEXT:
149 case GNUNET_CHAT_KIND_FILE:
149 { 150 {
150 application_call_message_event( 151 application_call_message_event(
151 app, 152 app,
diff --git a/src/event.c b/src/event.c
index 2280785..a99f13d 100644
--- a/src/event.c
+++ b/src/event.c
@@ -304,11 +304,13 @@ event_receive_message(UNUSED MESSENGER_Application *app,
304 if (!handle) 304 if (!handle)
305 return; 305 return;
306 306
307 struct GNUNET_CHAT_File *file = GNUNET_CHAT_message_get_file(msg);
308
307 const int sent = GNUNET_CHAT_message_is_sent(msg); 309 const int sent = GNUNET_CHAT_message_is_sent(msg);
308 310
309 UI_MESSAGE_Handle *message = ui_message_new( 311 UI_MESSAGE_Handle *message = ui_message_new(
310 GNUNET_YES == sent? UI_MESSAGE_SENT : UI_MESSAGE_DEFAULT, 312 GNUNET_YES == sent? UI_MESSAGE_SENT : UI_MESSAGE_DEFAULT,
311 UI_MESSAGE_CONTENT_TEXT 313 file? UI_MESSAGE_CONTENT_FILE : UI_MESSAGE_CONTENT_TEXT
312 ); 314 );
313 315
314 const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( 316 const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender(
diff --git a/src/ui/chat.c b/src/ui/chat.c
index 42ccb9e..5dd11f6 100644
--- a/src/ui/chat.c
+++ b/src/ui/chat.c
@@ -95,6 +95,29 @@ handle_chat_contacts_listbox_row_activated(GtkListBox *listbox,
95} 95}
96 96
97static void 97static void
98handle_chat_messages_listbox_size_allocate(UNUSED GtkWidget *widget,
99 UNUSED GdkRectangle *allocation,
100 gpointer user_data)
101{
102 UI_CHAT_Handle *handle = (UI_CHAT_Handle*) user_data;
103
104 GtkAdjustment *adjustment = gtk_scrolled_window_get_vadjustment(
105 handle->chat_scrolled_window
106 );
107
108 const gdouble value = gtk_adjustment_get_value(adjustment);
109 const gdouble upper = gtk_adjustment_get_upper(adjustment);
110 const gdouble page_size = gtk_adjustment_get_page_size(adjustment);
111
112 const gdouble edge_value = upper - page_size;
113
114 if (value >= handle->edge_value)
115 gtk_adjustment_set_value(adjustment, edge_value);
116
117 handle->edge_value = upper - page_size;
118}
119
120static void
98handle_back_button_click(UNUSED GtkButton *button, 121handle_back_button_click(UNUSED GtkButton *button,
99 gpointer user_data) 122 gpointer user_data)
100{ 123{
@@ -254,6 +277,7 @@ ui_chat_new(MESSENGER_Application *app)
254 UI_MESSENGER_Handle *messenger = &(app->ui.messenger); 277 UI_MESSENGER_Handle *messenger = &(app->ui.messenger);
255 278
256 handle->messages = NULL; 279 handle->messages = NULL;
280 handle->edge_value = 0;
257 281
258 handle->builder = gtk_builder_new_from_file( 282 handle->builder = gtk_builder_new_from_file(
259 "resources/ui/chat.ui" 283 "resources/ui/chat.ui"
@@ -324,6 +348,10 @@ ui_chat_new(MESSENGER_Application *app)
324 gtk_builder_get_object(handle->builder, "chat_details_contacts_box") 348 gtk_builder_get_object(handle->builder, "chat_details_contacts_box")
325 ); 349 );
326 350
351 handle->chat_scrolled_window = GTK_SCROLLED_WINDOW(
352 gtk_builder_get_object(handle->builder, "chat_scrolled_window")
353 );
354
327 handle->chat_contacts_listbox = GTK_LIST_BOX( 355 handle->chat_contacts_listbox = GTK_LIST_BOX(
328 gtk_builder_get_object(handle->builder, "chat_contacts_listbox") 356 gtk_builder_get_object(handle->builder, "chat_contacts_listbox")
329 ); 357 );
@@ -339,6 +367,13 @@ ui_chat_new(MESSENGER_Application *app)
339 gtk_builder_get_object(handle->builder, "messages_listbox") 367 gtk_builder_get_object(handle->builder, "messages_listbox")
340 ); 368 );
341 369
370 g_signal_connect(
371 handle->messages_listbox,
372 "size-allocate",
373 G_CALLBACK(handle_chat_messages_listbox_size_allocate),
374 handle
375 );
376
342 handle->attach_file_button = GTK_BUTTON( 377 handle->attach_file_button = GTK_BUTTON(
343 gtk_builder_get_object(handle->builder, "attach_file_button") 378 gtk_builder_get_object(handle->builder, "attach_file_button")
344 ); 379 );
diff --git a/src/ui/chat.h b/src/ui/chat.h
index f065f61..6619506 100644
--- a/src/ui/chat.h
+++ b/src/ui/chat.h
@@ -37,6 +37,7 @@ typedef struct UI_PICKER_Handle UI_PICKER_Handle;
37typedef struct UI_CHAT_Handle 37typedef struct UI_CHAT_Handle
38{ 38{
39 GList *messages; 39 GList *messages;
40 gdouble edge_value;
40 41
41 GtkBuilder *builder; 42 GtkBuilder *builder;
42 GtkWidget *chat_box; 43 GtkWidget *chat_box;
@@ -53,6 +54,8 @@ typedef struct UI_CHAT_Handle
53 GtkButton *hide_chat_details_button; 54 GtkButton *hide_chat_details_button;
54 GtkBox *chat_details_contacts_box; 55 GtkBox *chat_details_contacts_box;
55 56
57 GtkScrolledWindow *chat_scrolled_window;
58
56 GtkListBox *chat_contacts_listbox; 59 GtkListBox *chat_contacts_listbox;
57 GtkListBox *messages_listbox; 60 GtkListBox *messages_listbox;
58 61
diff --git a/src/ui/message.c b/src/ui/message.c
index 4c89edb..6f379d7 100644
--- a/src/ui/message.c
+++ b/src/ui/message.c
@@ -106,6 +106,10 @@ ui_message_new(UI_MESSAGE_Type type,
106 gtk_builder_get_object(builder, "read_receipt_image") 106 gtk_builder_get_object(builder, "read_receipt_image")
107 ); 107 );
108 108
109 handle->content_stack = GTK_STACK(
110 gtk_builder_get_object(builder, "content_stack")
111 );
112
109 handle->text_label = GTK_LABEL( 113 handle->text_label = GTK_LABEL(
110 gtk_builder_get_object(builder, "text_label") 114 gtk_builder_get_object(builder, "text_label")
111 ); 115 );
@@ -129,9 +133,26 @@ ui_message_new(UI_MESSAGE_Type type,
129 133
130 switch (content_type) 134 switch (content_type)
131 { 135 {
136 case UI_MESSAGE_CONTENT_TEXT:
137 gtk_stack_set_visible_child(
138 handle->content_stack,
139 GTK_WIDGET(handle->text_label)
140 );
141 break;
132 case UI_MESSAGE_CONTENT_FILE: 142 case UI_MESSAGE_CONTENT_FILE:
143 gtk_stack_set_visible_child(
144 handle->content_stack,
145 GTK_WIDGET(handle->file_revealer)
146 );
147
133 gtk_revealer_set_reveal_child(handle->file_revealer, TRUE); 148 gtk_revealer_set_reveal_child(handle->file_revealer, TRUE);
134 break; 149 break;
150 case UI_MESSAGE_CONTENT_PREVIEW:
151 gtk_stack_set_visible_child(
152 handle->content_stack,
153 GTK_WIDGET(handle->preview_drawing_area)
154 );
155 break;
135 default: 156 default:
136 break; 157 break;
137 } 158 }
@@ -145,6 +166,18 @@ ui_message_new(UI_MESSAGE_Type type,
145} 166}
146 167
147void 168void
169ui_message_update(UI_MESSAGE_Handle *handle,
170 struct GNUNET_CHAT_Message *msg)
171{
172 struct GNUNET_CHAT_File *file = GNUNET_CHAT_message_get_file(msg);
173
174 if (!file)
175 return;
176
177 // TODO
178}
179
180void
148ui_message_delete(UI_MESSAGE_Handle *handle) 181ui_message_delete(UI_MESSAGE_Handle *handle)
149{ 182{
150 g_object_unref(handle->builder); 183 g_object_unref(handle->builder);
diff --git a/src/ui/message.h b/src/ui/message.h
index b380960..704c33f 100644
--- a/src/ui/message.h
+++ b/src/ui/message.h
@@ -30,6 +30,8 @@
30#include <gtk-3.0/gtk/gtk.h> 30#include <gtk-3.0/gtk/gtk.h>
31#include <libhandy-1/handy.h> 31#include <libhandy-1/handy.h>
32 32
33#include <gnunet/gnunet_chat_lib.h>
34
33typedef struct MESSENGER_Application MESSENGER_Application; 35typedef struct MESSENGER_Application MESSENGER_Application;
34 36
35typedef enum UI_MESSAGE_Type 37typedef enum UI_MESSAGE_Type
@@ -65,6 +67,8 @@ typedef struct UI_MESSAGE_Handle
65 GtkLabel *timestamp_label; 67 GtkLabel *timestamp_label;
66 GtkImage *read_receipt_image; 68 GtkImage *read_receipt_image;
67 69
70 GtkStack *content_stack;
71
68 GtkLabel *text_label; 72 GtkLabel *text_label;
69 GtkRevealer *file_revealer; 73 GtkRevealer *file_revealer;
70 GtkDrawingArea *preview_drawing_area; 74 GtkDrawingArea *preview_drawing_area;
@@ -75,6 +79,10 @@ ui_message_new(UI_MESSAGE_Type type,
75 UI_MESSAGE_ContentType content_type); 79 UI_MESSAGE_ContentType content_type);
76 80
77void 81void
82ui_message_update(UI_MESSAGE_Handle *handle,
83 struct GNUNET_CHAT_Message *message);
84
85void
78ui_message_delete(UI_MESSAGE_Handle *handle); 86ui_message_delete(UI_MESSAGE_Handle *handle);
79 87
80#endif /* UI_MESSAGE_H_ */ 88#endif /* UI_MESSAGE_H_ */