messenger-gtk

Gtk+3 graphical user interfaces for GNUnet Messenger
Log | Files | Refs | Submodules | README | LICENSE

commit 62b509908be5b1ec54e0a08c042803b4bf4cadfd
parent 89363b9edd1d54c07d22ae563104d1d8a2a3a8cd
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Wed,  3 Nov 2021 02:37:49 +0100

Added some changing icons and (visually only) sending messages

Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>

Diffstat:
Mresources/ui/messenger.ui | 12++++++------
Msrc/ui/messenger.c | 122++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Msrc/ui/messenger.h | 7+++++++
Msrc/ui/new_platform.c | 15+++++++++++++--
4 files changed, 141 insertions(+), 15 deletions(-)

diff --git a/resources/ui/messenger.ui b/resources/ui/messenger.ui @@ -248,7 +248,7 @@ Author: Tobias Frisch <property name="valign">center</property> <property name="relief">none</property> <child> - <object class="GtkImage"> + <object class="GtkImage" id="account_details_symbol"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="icon-name">go-down-symbolic</property> @@ -871,7 +871,7 @@ Author: Tobias Frisch <property name="margin-bottom">4</property> <property name="spacing">4</property> <child> - <object class="GtkButton"> + <object class="GtkButton" id="attach_file_button"> <property name="visible">True</property> <property name="can-focus">True</property> <property name="receives-default">True</property> @@ -892,7 +892,7 @@ Author: Tobias Frisch </packing> </child> <child> - <object class="GtkTextView"> + <object class="GtkTextView" id="send_text_view"> <property name="width-request">210</property> <property name="height-request">48</property> <property name="visible">True</property> @@ -912,7 +912,7 @@ Author: Tobias Frisch </packing> </child> <child> - <object class="GtkButton"> + <object class="GtkButton" id="emoji_button"> <property name="visible">True</property> <property name="can-focus">True</property> <property name="receives-default">True</property> @@ -933,14 +933,14 @@ Author: Tobias Frisch </packing> </child> <child> - <object class="GtkButton"> + <object class="GtkButton" id="send_record_button"> <property name="visible">True</property> <property name="can-focus">True</property> <property name="receives-default">True</property> <property name="valign">center</property> <property name="relief">none</property> <child> - <object class="GtkImage"> + <object class="GtkImage" id="send_record_symbol"> <property name="visible">True</property> <property name="can-focus">False</property> <property name="icon-name">audio-input-microphone-symbolic</property> diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -24,6 +24,7 @@ #include "messenger.h" +#include "message.h" #include "new_platform.h" #include "../application.h" @@ -44,13 +45,22 @@ static void handle_account_details_button_click(UNUSED GtkButton* button, gpointer user_data) { - GtkRevealer* revealer = GTK_REVEALER(user_data); + UI_MESSENGER_Handle *handle = (UI_MESSENGER_Handle*) user_data; - if (TRUE == gtk_revealer_get_reveal_child(revealer)) { - gtk_revealer_set_reveal_child(revealer, FALSE); - } else { - gtk_revealer_set_reveal_child(revealer, TRUE); - } + GtkRevealer *revealer = handle->account_details_revealer; + GtkImage *symbol = handle->account_details_symbol; + + gboolean old_state = gtk_revealer_get_reveal_child(revealer); + + gtk_revealer_set_reveal_child(revealer, !old_state); + + gtk_image_set_from_icon_name( + symbol, + old_state? + "go-down-symbolic" : + "go-up-symbolic", + GTK_ICON_SIZE_BUTTON + ); } static void @@ -94,6 +104,62 @@ handle_back_button_click(UNUSED GtkButton* button, } static void +handle_send_text_buffer_changed(GtkTextBuffer *buffer, + gpointer user_data) +{ + GtkImage *symbol = GTK_IMAGE(user_data); + + GtkTextIter start, end; + gtk_text_buffer_get_start_iter(buffer, &start); + gtk_text_buffer_get_end_iter(buffer, &end); + + const gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE); + + gtk_image_set_from_icon_name( + symbol, + 0 < g_utf8_strlen(text, 1)? + "mail-send-symbolic" : + "audio-input-microphone-symbolic", + GTK_ICON_SIZE_BUTTON + ); +} + +static void +handle_send_record_button_click(UNUSED GtkButton *button, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + GtkTextBuffer *buffer = gtk_text_view_get_buffer( + app->ui.messenger.send_text_view + ); + + GtkTextIter start, end; + gtk_text_buffer_get_start_iter(buffer, &start); + gtk_text_buffer_get_end_iter(buffer, &end); + + const gchar *text = gtk_text_buffer_get_text(buffer, &start, &end, TRUE); + + if (0 < g_utf8_strlen(text, 1)) + { + // TODO: Actually send the message with current chat context! + + UI_MESSAGE_Handle *message = ui_message_new(app, TRUE); + + gtk_label_set_text(message->text_label, text); + + gtk_container_add(GTK_CONTAINER(app->ui.messenger.messages_listbox), message->message_box); + g_free(message); // TODO: this is just a test! + } + else + { + // TODO: record audio and attach as file? + } + + gtk_text_buffer_delete(buffer, &start, &end); +} + +static void handle_main_window_destroy(UNUSED GtkWidget *window, gpointer user_data) { @@ -202,6 +268,10 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(builder, "account_details_button") ); + handle->account_details_symbol = GTK_IMAGE( + gtk_builder_get_object(builder, "account_details_symbol") + ); + handle->account_details_revealer = GTK_REVEALER( gtk_builder_get_object(builder, "account_details_revealer") ); @@ -210,7 +280,7 @@ ui_messenger_init(MESSENGER_Application *app, handle->account_details_button, "clicked", G_CALLBACK(handle_account_details_button_click), - handle->account_details_revealer + handle ); handle->accounts_listbox = GTK_LIST_BOX( @@ -304,6 +374,44 @@ ui_messenger_init(MESSENGER_Application *app, gtk_builder_get_object(builder, "messages_listbox") ); + handle->attach_file_button = GTK_BUTTON( + gtk_builder_get_object(builder, "attach_file_button") + ); + + handle->send_text_view = GTK_TEXT_VIEW( + gtk_builder_get_object(builder, "send_text_view") + ); + + handle->emoji_button = GTK_BUTTON( + gtk_builder_get_object(builder, "emoji_button") + ); + + handle->send_record_button = GTK_BUTTON( + gtk_builder_get_object(builder, "send_record_button") + ); + + handle->send_record_symbol = GTK_IMAGE( + gtk_builder_get_object(builder, "send_record_symbol") + ); + + GtkTextBuffer *send_text_buffer = gtk_text_view_get_buffer( + handle->send_text_view + ); + + g_signal_connect( + send_text_buffer, + "changed", + G_CALLBACK(handle_send_text_buffer_changed), + handle->send_record_symbol + ); + + g_signal_connect( + handle->send_record_button, + "clicked", + G_CALLBACK(handle_send_record_button_click), + app + ); + gtk_widget_show(GTK_WIDGET(handle->main_window)); g_signal_connect( diff --git a/src/ui/messenger.h b/src/ui/messenger.h @@ -48,6 +48,7 @@ typedef struct UI_MESSENGER_Handle GtkButton *hide_user_details_button; GtkButton *favourites_button; GtkButton *account_details_button; + GtkImage *account_details_symbol; GtkRevealer *account_details_revealer; GtkListBox *accounts_listbox; @@ -69,6 +70,12 @@ typedef struct UI_MESSENGER_Handle GtkButton *hide_chat_details_button; GtkListBox *messages_listbox; + + GtkButton *attach_file_button; + GtkTextView *send_text_view; + GtkButton *emoji_button; + GtkButton *send_record_button; + GtkImage *send_record_symbol; } UI_MESSENGER_Handle; void diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c @@ -50,9 +50,20 @@ handle_confirm_button_click(UNUSED GtkButton *button, { MESSENGER_Application *app = (MESSENGER_Application*) user_data; - const char *topic = gtk_entry_get_text(app->ui.new_platform.platform_entry); + const gchar *topic = gtk_entry_get_text(app->ui.new_platform.platform_entry); - GNUNET_CHAT_group_create(app->chat.messenger.handle, topic); + GString *topic_string = g_string_new(topic); + + struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create( + app->chat.messenger.handle, + topic_string->str + ); + + g_string_prepend_c(topic_string, '#'); + + GNUNET_CHAT_group_set_name(group, topic_string->str); + + g_string_free(topic_string, TRUE); gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog)); }