diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-03 02:37:49 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-03 02:37:49 +0100 |
commit | 62b509908be5b1ec54e0a08c042803b4bf4cadfd (patch) | |
tree | 0baae07e7b36351cbd9037d5a5c88d61734d03be | |
parent | 89363b9edd1d54c07d22ae563104d1d8a2a3a8cd (diff) | |
download | messenger-gtk-62b509908be5b1ec54e0a08c042803b4bf4cadfd.tar.gz messenger-gtk-62b509908be5b1ec54e0a08c042803b4bf4cadfd.zip |
Added some changing icons and (visually only) sending messages
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | resources/ui/messenger.ui | 12 | ||||
-rw-r--r-- | src/ui/messenger.c | 122 | ||||
-rw-r--r-- | src/ui/messenger.h | 7 | ||||
-rw-r--r-- | src/ui/new_platform.c | 15 |
4 files changed, 141 insertions, 15 deletions
diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui index 9ff5e9b..79ea388 100644 --- a/resources/ui/messenger.ui +++ b/resources/ui/messenger.ui | |||
@@ -248,7 +248,7 @@ Author: Tobias Frisch | |||
248 | <property name="valign">center</property> | 248 | <property name="valign">center</property> |
249 | <property name="relief">none</property> | 249 | <property name="relief">none</property> |
250 | <child> | 250 | <child> |
251 | <object class="GtkImage"> | 251 | <object class="GtkImage" id="account_details_symbol"> |
252 | <property name="visible">True</property> | 252 | <property name="visible">True</property> |
253 | <property name="can-focus">False</property> | 253 | <property name="can-focus">False</property> |
254 | <property name="icon-name">go-down-symbolic</property> | 254 | <property name="icon-name">go-down-symbolic</property> |
@@ -871,7 +871,7 @@ Author: Tobias Frisch | |||
871 | <property name="margin-bottom">4</property> | 871 | <property name="margin-bottom">4</property> |
872 | <property name="spacing">4</property> | 872 | <property name="spacing">4</property> |
873 | <child> | 873 | <child> |
874 | <object class="GtkButton"> | 874 | <object class="GtkButton" id="attach_file_button"> |
875 | <property name="visible">True</property> | 875 | <property name="visible">True</property> |
876 | <property name="can-focus">True</property> | 876 | <property name="can-focus">True</property> |
877 | <property name="receives-default">True</property> | 877 | <property name="receives-default">True</property> |
@@ -892,7 +892,7 @@ Author: Tobias Frisch | |||
892 | </packing> | 892 | </packing> |
893 | </child> | 893 | </child> |
894 | <child> | 894 | <child> |
895 | <object class="GtkTextView"> | 895 | <object class="GtkTextView" id="send_text_view"> |
896 | <property name="width-request">210</property> | 896 | <property name="width-request">210</property> |
897 | <property name="height-request">48</property> | 897 | <property name="height-request">48</property> |
898 | <property name="visible">True</property> | 898 | <property name="visible">True</property> |
@@ -912,7 +912,7 @@ Author: Tobias Frisch | |||
912 | </packing> | 912 | </packing> |
913 | </child> | 913 | </child> |
914 | <child> | 914 | <child> |
915 | <object class="GtkButton"> | 915 | <object class="GtkButton" id="emoji_button"> |
916 | <property name="visible">True</property> | 916 | <property name="visible">True</property> |
917 | <property name="can-focus">True</property> | 917 | <property name="can-focus">True</property> |
918 | <property name="receives-default">True</property> | 918 | <property name="receives-default">True</property> |
@@ -933,14 +933,14 @@ Author: Tobias Frisch | |||
933 | </packing> | 933 | </packing> |
934 | </child> | 934 | </child> |
935 | <child> | 935 | <child> |
936 | <object class="GtkButton"> | 936 | <object class="GtkButton" id="send_record_button"> |
937 | <property name="visible">True</property> | 937 | <property name="visible">True</property> |
938 | <property name="can-focus">True</property> | 938 | <property name="can-focus">True</property> |
939 | <property name="receives-default">True</property> | 939 | <property name="receives-default">True</property> |
940 | <property name="valign">center</property> | 940 | <property name="valign">center</property> |
941 | <property name="relief">none</property> | 941 | <property name="relief">none</property> |
942 | <child> | 942 | <child> |
943 | <object class="GtkImage"> | 943 | <object class="GtkImage" id="send_record_symbol"> |
944 | <property name="visible">True</property> | 944 | <property name="visible">True</property> |
945 | <property name="can-focus">False</property> | 945 | <property name="can-focus">False</property> |
946 | <property name="icon-name">audio-input-microphone-symbolic</property> | 946 | <property name="icon-name">audio-input-microphone-symbolic</property> |
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 4e31952..c62cad9 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -24,6 +24,7 @@ | |||
24 | 24 | ||
25 | #include "messenger.h" | 25 | #include "messenger.h" |
26 | 26 | ||
27 | #include "message.h" | ||
27 | #include "new_platform.h" | 28 | #include "new_platform.h" |
28 | #include "../application.h" | 29 | #include "../application.h" |
29 | 30 | ||
@@ -44,13 +45,22 @@ static void | |||
44 | handle_account_details_button_click(UNUSED GtkButton* button, | 45 | handle_account_details_button_click(UNUSED GtkButton* button, |
45 | gpointer user_data) | 46 | gpointer user_data) |
46 | { | 47 | { |
47 | GtkRevealer* revealer = GTK_REVEALER(user_data); | 48 | UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; |
48 | 49 | ||
49 | if (TRUE == gtk_revealer_get_reveal_child(revealer)) { | 50 | GtkRevealer *revealer = handle->account_details_revealer; |
50 | gtk_revealer_set_reveal_child(revealer, FALSE); | 51 | GtkImage *symbol = handle->account_details_symbol; |
51 | } else { | 52 | |
52 | gtk_revealer_set_reveal_child(revealer, TRUE); | 53 | gboolean old_state = gtk_revealer_get_reveal_child(revealer); |
53 | } | 54 | |
55 | gtk_revealer_set_reveal_child(revealer, !old_state); | ||
56 | |||
57 | gtk_image_set_from_icon_name( | ||
58 | symbol, | ||
59 | old_state? | ||
60 | "go-down-symbolic" : | ||
61 | "go-up-symbolic", | ||
62 | GTK_ICON_SIZE_BUTTON | ||
63 | ); | ||
54 | } | 64 | } |
55 | 65 | ||
56 | static void | 66 | static void |
@@ -94,6 +104,62 @@ handle_back_button_click(UNUSED GtkButton* button, | |||
94 | } | 104 | } |
95 | 105 | ||
96 | static void | 106 | static void |
107 | handle_send_text_buffer_changed(GtkTextBuffer *buffer, | ||
108 | gpointer user_data) | ||
109 | { | ||
110 | GtkImage *symbol = GTK_IMAGE(user_data); | ||
111 | |||
112 | GtkTextIter start, end; | ||
113 | gtk_text_buffer_get_start_iter(buffer, &start); | ||
114 | gtk_text_buffer_get_end_iter(buffer, &end); | ||
115 | |||
116 | const gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE); | ||
117 | |||
118 | gtk_image_set_from_icon_name( | ||
119 | symbol, | ||
120 | 0 < g_utf8_strlen(text, 1)? | ||
121 | "mail-send-symbolic" : | ||
122 | "audio-input-microphone-symbolic", | ||
123 | GTK_ICON_SIZE_BUTTON | ||
124 | ); | ||
125 | } | ||
126 | |||
127 | static void | ||
128 | handle_send_record_button_click(UNUSED GtkButton *button, | ||
129 | gpointer user_data) | ||
130 | { | ||
131 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
132 | |||
133 | GtkTextBuffer *buffer = gtk_text_view_get_buffer( | ||
134 | app->ui.messenger.send_text_view | ||
135 | ); | ||
136 | |||
137 | GtkTextIter start, end; | ||
138 | gtk_text_buffer_get_start_iter(buffer, &start); | ||
139 | gtk_text_buffer_get_end_iter(buffer, &end); | ||
140 | |||
141 | const gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE); | ||
142 | |||
143 | if (0 < g_utf8_strlen(text, 1)) | ||
144 | { | ||
145 | // TODO: Actually send the message with current chat context! | ||
146 | |||
147 | UI_MESSAGE_Handle *message = ui_message_new(app, TRUE); | ||
148 | |||
149 | gtk_label_set_text(message->text_label, text); | ||
150 | |||
151 | gtk_container_add(GTK_CONTAINER(app->ui.messenger.messages_listbox), message->message_box); | ||
152 | g_free(message); // TODO: this is just a test! | ||
153 | } | ||
154 | else | ||
155 | { | ||
156 | // TODO: record audio and attach as file? | ||
157 | } | ||
158 | |||
159 | gtk_text_buffer_delete(buffer, &start, &end); | ||
160 | } | ||
161 | |||
162 | static void | ||
97 | handle_main_window_destroy(UNUSED GtkWidget *window, | 163 | handle_main_window_destroy(UNUSED GtkWidget *window, |
98 | gpointer user_data) | 164 | gpointer user_data) |
99 | { | 165 | { |
@@ -202,6 +268,10 @@ ui_messenger_init(MESSENGER_Application *app, | |||
202 | gtk_builder_get_object(builder, "account_details_button") | 268 | gtk_builder_get_object(builder, "account_details_button") |
203 | ); | 269 | ); |
204 | 270 | ||
271 | handle->account_details_symbol = GTK_IMAGE( | ||
272 | gtk_builder_get_object(builder, "account_details_symbol") | ||
273 | ); | ||
274 | |||
205 | handle->account_details_revealer = GTK_REVEALER( | 275 | handle->account_details_revealer = GTK_REVEALER( |
206 | gtk_builder_get_object(builder, "account_details_revealer") | 276 | gtk_builder_get_object(builder, "account_details_revealer") |
207 | ); | 277 | ); |
@@ -210,7 +280,7 @@ ui_messenger_init(MESSENGER_Application *app, | |||
210 | handle->account_details_button, | 280 | handle->account_details_button, |
211 | "clicked", | 281 | "clicked", |
212 | G_CALLBACK(handle_account_details_button_click), | 282 | G_CALLBACK(handle_account_details_button_click), |
213 | handle->account_details_revealer | 283 | handle |
214 | ); | 284 | ); |
215 | 285 | ||
216 | handle->accounts_listbox = GTK_LIST_BOX( | 286 | handle->accounts_listbox = GTK_LIST_BOX( |
@@ -304,6 +374,44 @@ ui_messenger_init(MESSENGER_Application *app, | |||
304 | gtk_builder_get_object(builder, "messages_listbox") | 374 | gtk_builder_get_object(builder, "messages_listbox") |
305 | ); | 375 | ); |
306 | 376 | ||
377 | handle->attach_file_button = GTK_BUTTON( | ||
378 | gtk_builder_get_object(builder, "attach_file_button") | ||
379 | ); | ||
380 | |||
381 | handle->send_text_view = GTK_TEXT_VIEW( | ||
382 | gtk_builder_get_object(builder, "send_text_view") | ||
383 | ); | ||
384 | |||
385 | handle->emoji_button = GTK_BUTTON( | ||
386 | gtk_builder_get_object(builder, "emoji_button") | ||
387 | ); | ||
388 | |||
389 | handle->send_record_button = GTK_BUTTON( | ||
390 | gtk_builder_get_object(builder, "send_record_button") | ||
391 | ); | ||
392 | |||
393 | handle->send_record_symbol = GTK_IMAGE( | ||
394 | gtk_builder_get_object(builder, "send_record_symbol") | ||
395 | ); | ||
396 | |||
397 | GtkTextBuffer *send_text_buffer = gtk_text_view_get_buffer( | ||
398 | handle->send_text_view | ||
399 | ); | ||
400 | |||
401 | g_signal_connect( | ||
402 | send_text_buffer, | ||
403 | "changed", | ||
404 | G_CALLBACK(handle_send_text_buffer_changed), | ||
405 | handle->send_record_symbol | ||
406 | ); | ||
407 | |||
408 | g_signal_connect( | ||
409 | handle->send_record_button, | ||
410 | "clicked", | ||
411 | G_CALLBACK(handle_send_record_button_click), | ||
412 | app | ||
413 | ); | ||
414 | |||
307 | gtk_widget_show(GTK_WIDGET(handle->main_window)); | 415 | gtk_widget_show(GTK_WIDGET(handle->main_window)); |
308 | 416 | ||
309 | g_signal_connect( | 417 | g_signal_connect( |
diff --git a/src/ui/messenger.h b/src/ui/messenger.h index e923964..c2e53a1 100644 --- a/src/ui/messenger.h +++ b/src/ui/messenger.h | |||
@@ -48,6 +48,7 @@ typedef struct UI_MESSENGER_Handle | |||
48 | GtkButton *hide_user_details_button; | 48 | GtkButton *hide_user_details_button; |
49 | GtkButton *favourites_button; | 49 | GtkButton *favourites_button; |
50 | GtkButton *account_details_button; | 50 | GtkButton *account_details_button; |
51 | GtkImage *account_details_symbol; | ||
51 | 52 | ||
52 | GtkRevealer *account_details_revealer; | 53 | GtkRevealer *account_details_revealer; |
53 | GtkListBox *accounts_listbox; | 54 | GtkListBox *accounts_listbox; |
@@ -69,6 +70,12 @@ typedef struct UI_MESSENGER_Handle | |||
69 | GtkButton *hide_chat_details_button; | 70 | GtkButton *hide_chat_details_button; |
70 | 71 | ||
71 | GtkListBox *messages_listbox; | 72 | GtkListBox *messages_listbox; |
73 | |||
74 | GtkButton *attach_file_button; | ||
75 | GtkTextView *send_text_view; | ||
76 | GtkButton *emoji_button; | ||
77 | GtkButton *send_record_button; | ||
78 | GtkImage *send_record_symbol; | ||
72 | } UI_MESSENGER_Handle; | 79 | } UI_MESSENGER_Handle; |
73 | 80 | ||
74 | void | 81 | void |
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c index 46384c0..c1d4491 100644 --- a/src/ui/new_platform.c +++ b/src/ui/new_platform.c | |||
@@ -50,9 +50,20 @@ handle_confirm_button_click(UNUSED GtkButton *button, | |||
50 | { | 50 | { |
51 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 51 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
52 | 52 | ||
53 | const char *topic = gtk_entry_get_text(app->ui.new_platform.platform_entry); | 53 | const gchar *topic = gtk_entry_get_text(app->ui.new_platform.platform_entry); |
54 | 54 | ||
55 | GNUNET_CHAT_group_create(app->chat.messenger.handle, topic); | 55 | GString *topic_string = g_string_new(topic); |
56 | |||
57 | struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create( | ||
58 | app->chat.messenger.handle, | ||
59 | topic_string->str | ||
60 | ); | ||
61 | |||
62 | g_string_prepend_c(topic_string, '#'); | ||
63 | |||
64 | GNUNET_CHAT_group_set_name(group, topic_string->str); | ||
65 | |||
66 | g_string_free(topic_string, TRUE); | ||
56 | 67 | ||
57 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog)); | 68 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog)); |
58 | } | 69 | } |