diff options
Diffstat (limited to 'src/ui/messenger.c')
-rw-r--r-- | src/ui/messenger.c | 122 |
1 files changed, 115 insertions, 7 deletions
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( |