diff options
Diffstat (limited to 'src/ui/messenger.c')
-rw-r--r-- | src/ui/messenger.c | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index c62cad9..9976e18 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -24,6 +24,8 @@ | |||
24 | 24 | ||
25 | #include "messenger.h" | 25 | #include "messenger.h" |
26 | 26 | ||
27 | #include <gtk-3.0/gdk/gdkkeys.h> | ||
28 | |||
27 | #include "message.h" | 29 | #include "message.h" |
28 | #include "new_platform.h" | 30 | #include "new_platform.h" |
29 | #include "../application.h" | 31 | #include "../application.h" |
@@ -125,7 +127,7 @@ handle_send_text_buffer_changed(GtkTextBuffer *buffer, | |||
125 | } | 127 | } |
126 | 128 | ||
127 | static void | 129 | static void |
128 | handle_send_record_button_click(UNUSED GtkButton *button, | 130 | handle_send_record_button_click(GtkButton *button, |
129 | gpointer user_data) | 131 | gpointer user_data) |
130 | { | 132 | { |
131 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 133 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
@@ -142,14 +144,12 @@ handle_send_record_button_click(UNUSED GtkButton *button, | |||
142 | 144 | ||
143 | if (0 < g_utf8_strlen(text, 1)) | 145 | if (0 < g_utf8_strlen(text, 1)) |
144 | { | 146 | { |
145 | // TODO: Actually send the message with current chat context! | 147 | struct GNUNET_CHAT_Context *context = g_hash_table_lookup( |
146 | 148 | app->ui.bindings, button | |
147 | UI_MESSAGE_Handle *message = ui_message_new(app, TRUE); | 149 | ); |
148 | |||
149 | gtk_label_set_text(message->text_label, text); | ||
150 | 150 | ||
151 | gtk_container_add(GTK_CONTAINER(app->ui.messenger.messages_listbox), message->message_box); | 151 | if (context) |
152 | g_free(message); // TODO: this is just a test! | 152 | GNUNET_CHAT_context_send_text(context, text); |
153 | } | 153 | } |
154 | else | 154 | else |
155 | { | 155 | { |
@@ -159,6 +159,40 @@ handle_send_record_button_click(UNUSED GtkButton *button, | |||
159 | gtk_text_buffer_delete(buffer, &start, &end); | 159 | gtk_text_buffer_delete(buffer, &start, &end); |
160 | } | 160 | } |
161 | 161 | ||
162 | static gboolean | ||
163 | handle_send_text_key_press (GtkWidget *widget, | ||
164 | GdkEventKey *event, | ||
165 | gpointer user_data) | ||
166 | { | ||
167 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
168 | |||
169 | if ((event->state & GDK_SHIFT_MASK) || | ||
170 | ((event->keyval != GDK_KEY_Return) && | ||
171 | (event->keyval != GDK_KEY_KP_Enter))) | ||
172 | return FALSE; | ||
173 | |||
174 | GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (widget)); | ||
175 | |||
176 | GtkTextIter start, end; | ||
177 | gtk_text_buffer_get_start_iter(buffer, &start); | ||
178 | gtk_text_buffer_get_end_iter(buffer, &end); | ||
179 | |||
180 | const gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE); | ||
181 | |||
182 | if (0 == g_utf8_strlen(text, 1)) | ||
183 | return FALSE; | ||
184 | |||
185 | struct GNUNET_CHAT_Context *context = g_hash_table_lookup( | ||
186 | app->ui.bindings, widget | ||
187 | ); | ||
188 | |||
189 | if (context) | ||
190 | GNUNET_CHAT_context_send_text(context, text); | ||
191 | |||
192 | gtk_text_buffer_delete(buffer, &start, &end); | ||
193 | return TRUE; | ||
194 | } | ||
195 | |||
162 | static void | 196 | static void |
163 | handle_main_window_destroy(UNUSED GtkWidget *window, | 197 | handle_main_window_destroy(UNUSED GtkWidget *window, |
164 | gpointer user_data) | 198 | gpointer user_data) |
@@ -412,6 +446,13 @@ ui_messenger_init(MESSENGER_Application *app, | |||
412 | app | 446 | app |
413 | ); | 447 | ); |
414 | 448 | ||
449 | g_signal_connect( | ||
450 | handle->send_text_view, | ||
451 | "key-press-event", | ||
452 | G_CALLBACK(handle_send_text_key_press), | ||
453 | app | ||
454 | ); | ||
455 | |||
415 | gtk_widget_show(GTK_WIDGET(handle->main_window)); | 456 | gtk_widget_show(GTK_WIDGET(handle->main_window)); |
416 | 457 | ||
417 | g_signal_connect( | 458 | g_signal_connect( |