messenger-gtk

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

commit ad8dbe9b406b8b0b13be34234c9c1a40f3df5778
parent 299174878a9deb2f077294ed02beb79599246ea6
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Wed, 30 Mar 2022 00:23:56 +0200

Added functions to solve utf8 conversion issues

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

Diffstat:
MMakefile | 1+
Msrc/application.c | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
Msrc/application.h | 1+
Msrc/contact.c | 15++++++++-------
Msrc/event.c | 56+++++++++++++++++++++++++++-----------------------------
Asrc/ui.c | 72++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/ui.h | 40++++++++++++++++++++++++++++++++++++++++
Msrc/ui/account_entry.c | 19+++++++------------
Msrc/ui/chat.c | 16+++++++---------
Msrc/ui/chat_entry.c | 10+++++-----
Msrc/ui/contact_entry.c | 23++++++-----------------
Msrc/ui/contact_info.c | 15++++++++++-----
Msrc/ui/message.c | 5++++-
Msrc/ui/messenger.c | 18++++++++++--------
Msrc/ui/new_account.c | 4+++-
Msrc/ui/new_contact.c | 14+++++++-------
Msrc/ui/new_group.c | 9++++-----
Msrc/ui/new_platform.c | 6+++++-
Msrc/ui/send_file.c | 1+
19 files changed, 288 insertions(+), 113 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,6 +12,7 @@ SOURCES = messenger_gtk.c\ event.c\ file.c\ resources.c\ + ui.c\ chat/messenger.c\ ui/about.c\ ui/account_entry.c\ diff --git a/src/application.c b/src/application.c @@ -53,6 +53,8 @@ _application_accounts(gpointer user_data) { MESSENGER_Application *app = (MESSENGER_Application*) user_data; + app->init = 0; + ui_accounts_dialog_init(app, &(app->ui.accounts)); ui_accounts_dialog_refresh(app, &(app->ui.accounts)); @@ -61,17 +63,71 @@ _application_accounts(gpointer user_data) } static void -_application_activate(UNUSED GtkApplication* application, - gpointer user_data) +_application_init(MESSENGER_Application *app) { - MESSENGER_Application *app = (MESSENGER_Application*) user_data; - ui_messenger_init(app, &(app->ui.messenger)); if (app->chat.identity) gtk_widget_show(GTK_WIDGET(app->ui.messenger.main_window)); else - g_idle_add(G_SOURCE_FUNC(_application_accounts), app); + app->init = g_idle_add(G_SOURCE_FUNC(_application_accounts), app); +} + +static void +_application_activate(GApplication* application, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + g_application_hold(application); + + _application_init(app); + + g_application_release(application); +} + +static void +_application_open(GApplication* application, + GFile **files, + gint n_files, + UNUSED gchar* hint, + gpointer user_data) +{ + MESSENGER_Application *app = (MESSENGER_Application*) user_data; + + g_application_hold(application); + + _application_init(app); + + for (gint i = 0; i < n_files; i++) { + if (!g_file_has_uri_scheme(files[i], "gnunet")) + continue; + + gchar *uri_string = g_file_get_uri(files[i]); + + if (!uri_string) + continue; + + char *emsg = NULL; + struct GNUNET_CHAT_Uri *uri = GNUNET_CHAT_uri_parse(uri_string, &emsg); + + if (emsg) + { + g_printerr("ERROR: %s\n", emsg); + GNUNET_free(emsg); + } + + if (!uri) + goto free_string; + + GNUNET_CHAT_lobby_join(app->chat.messenger.handle, uri); + GNUNET_CHAT_uri_destroy(uri); + + free_string: + g_free(uri_string); + } + + g_application_release(application); } void @@ -84,12 +140,13 @@ application_init(MESSENGER_Application *app, app->argc = argc; app->argv = argv; - gst_init (&argc, &argv); + gst_init(&argc, &argv); gtk_init(&argc, &argv); hdy_init(); app->application = gtk_application_new( MESSENGER_APPLICATION_ID, + G_APPLICATION_HANDLES_OPEN | G_APPLICATION_NON_UNIQUE ); @@ -136,6 +193,13 @@ application_init(MESSENGER_Application *app, G_CALLBACK(_application_activate), app ); + + g_signal_connect( + app->application, + "open", + G_CALLBACK(_application_open), + app + ); } const gchar* diff --git a/src/application.h b/src/application.h @@ -71,6 +71,7 @@ typedef struct MESSENGER_Application GtkApplication *application; GList *notifications; + guint init; struct { GQuark widget; diff --git a/src/contact.c b/src/contact.c @@ -24,6 +24,8 @@ #include "contact.h" +#include "ui.h" + void contact_create_info(struct GNUNET_CHAT_Contact *contact) { @@ -67,7 +69,8 @@ contact_add_name_label_to_info(const struct GNUNET_CHAT_Contact *contact, return; const char *name = GNUNET_CHAT_contact_get_name(contact); - gtk_label_set_text(label, name? name : ""); + + ui_label_set_text(label, name); info->name_labels = g_list_append(info->name_labels, label); } @@ -82,7 +85,8 @@ contact_add_name_avatar_to_info(const struct GNUNET_CHAT_Contact *contact, return; const char *name = GNUNET_CHAT_contact_get_name(contact); - hdy_avatar_set_text(avatar, name? name : ""); + + ui_avatar_set_text(avatar, name); info->name_avatars = g_list_append(info->name_avatars, avatar); } @@ -99,11 +103,8 @@ contact_update_info(const struct GNUNET_CHAT_Contact *contact) const char *name = GNUNET_CHAT_contact_get_name(contact); for (list = info->name_labels; list; list = list->next) - gtk_label_set_text(GTK_LABEL(list->data), name? name : ""); - - if (!name) - return; + ui_label_set_text(GTK_LABEL(list->data), name); for (list = info->name_avatars; list; list = list->next) - hdy_avatar_set_text(HDY_AVATAR(list->data), name); + ui_avatar_set_text(HDY_AVATAR(list->data), name); } diff --git a/src/event.c b/src/event.c @@ -26,8 +26,9 @@ #include "contact.h" #include "file.h" -#include "ui/account_entry.h" +#include "ui.h" +#include "ui/account_entry.h" #include "ui/chat_entry.h" #include "ui/contact_entry.h" #include "ui/message.h" @@ -50,9 +51,9 @@ static void _show_notification(MESSENGER_Application *app, UNUSED struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Contact *contact, - const gchar *text, - const gchar *icon, - const gchar *category) + const char *text, + const char *icon, + const char *category) { if (app->settings.disable_notifications) return; @@ -85,13 +86,13 @@ event_handle_warning(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, const struct GNUNET_CHAT_Message *msg) { - const gchar *text = GNUNET_CHAT_message_get_text(msg); + const char *text = GNUNET_CHAT_message_get_text(msg); const struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_message_get_sender( msg ); - fprintf(stderr, "ERROR: %s\n", text); + g_printerr("ERROR: %s\n", text); _show_notification( app, @@ -141,7 +142,7 @@ _select_chat_to_activate(gpointer user_data) { UI_CHAT_ENTRY_Handle *entry = (UI_CHAT_ENTRY_Handle*) user_data; - if (!(entry->chat)) + if ((!entry) || (!(entry->chat)) || (!(entry->entry_box))) return FALSE; MESSENGER_Application *app = entry->chat->app; @@ -149,12 +150,15 @@ _select_chat_to_activate(gpointer user_data) if (!app) return FALSE; - UI_MESSENGER_Handle *ui = &(app->ui.messenger); - GtkListBoxRow *row = GTK_LIST_BOX_ROW( gtk_widget_get_parent(entry->entry_box) ); + if (!row) + return FALSE; + + UI_MESSENGER_Handle *ui = &(app->ui.messenger); + gtk_list_box_select_row(ui->chats_listbox, row); gtk_list_box_invalidate_filter(ui->chats_listbox); @@ -224,9 +228,7 @@ _add_new_chat_entry(MESSENGER_Application *app, ui->chat_entries = g_list_append(ui->chat_entries, entry); - GtkListBoxRow *row = GTK_LIST_BOX_ROW( - gtk_widget_get_parent(entry->entry_box) - ); + GtkWidget *row = gtk_widget_get_parent(entry->entry_box); g_object_set_qdata( G_OBJECT(row), @@ -305,16 +307,12 @@ event_update_profile(MESSENGER_Application *app) const char *name = GNUNET_CHAT_get_name(chat->handle); - if (name) - { - hdy_avatar_set_text(ui->profile_avatar, name); - gtk_label_set_text(ui->profile_label, name); - } + ui_avatar_set_text(ui->profile_avatar, name); + ui_label_set_text(ui->profile_label, name); const char *key = GNUNET_CHAT_get_key(chat->handle); - if (key) - gtk_label_set_text(ui->profile_key_label, key); + ui_label_set_text(ui->profile_key_label, key); gtk_container_foreach( GTK_CONTAINER(ui->chats_listbox), @@ -430,7 +428,7 @@ event_presence_contact(MESSENGER_Application *app, contact_add_name_avatar_to_info(contact, message->sender_avatar); contact_add_name_label_to_info(contact, message->sender_label); - const gchar *presence_message = ( + const char *text = ( GNUNET_CHAT_KIND_JOIN == kind? _("joined the chat") : _("left the chat") ); @@ -439,7 +437,7 @@ event_presence_contact(MESSENGER_Application *app, app, context, contact, - presence_message, + text, "avatar-default-symbolic", "presence.online" ); @@ -448,10 +446,10 @@ event_presence_contact(MESSENGER_Application *app, msg ); - const gchar *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); + const char *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); - gtk_label_set_text(message->text_label, presence_message); - gtk_label_set_text(message->timestamp_label, time? time : ""); + ui_label_set_text(message->text_label, text); + ui_label_set_text(message->timestamp_label, time); ui_chat_add_message(handle->chat, app, message); @@ -531,7 +529,7 @@ event_invitation(MESSENGER_Application *app, contact_add_name_avatar_to_info(contact, message->sender_avatar); contact_add_name_label_to_info(contact, message->sender_label); - const gchar *invite_message = _("invited you to a chat"); + const char *invite_message = _("invited you to a chat"); if (!ui_messenger_is_context_active(&(app->ui.messenger), context)) _show_notification( @@ -543,7 +541,7 @@ event_invitation(MESSENGER_Application *app, "im.received" ); - gtk_label_set_text(message->text_label, invite_message); + ui_label_set_text(message->text_label, invite_message); g_signal_connect( message->accept_button, @@ -632,7 +630,7 @@ event_receive_message(MESSENGER_Application *app, msg ); - const gchar *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); + const char *time = GNUNET_STRINGS_absolute_time_to_string(timestamp); if ((!ui_messenger_is_context_active(&(app->ui.messenger), context)) && (GNUNET_YES != sent)) @@ -645,8 +643,8 @@ event_receive_message(MESSENGER_Application *app, "im.received" ); - gtk_label_set_text(message->text_label, text? text : ""); - gtk_label_set_text(message->timestamp_label, time? time : ""); + ui_label_set_text(message->text_label, text); + ui_label_set_text(message->timestamp_label, time); ui_chat_add_message(handle->chat, app, message); diff --git a/src/ui.c b/src/ui.c @@ -0,0 +1,72 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui.c + */ + +#include "ui.h" + +void +ui_label_set_text(GtkLabel *label, const char *text) +{ + if (!text) + { + gtk_label_set_text(label, ""); + return; + } + + gchar *_text = g_locale_to_utf8(text, -1, NULL, NULL, NULL); + gtk_label_set_text(label, _text); + g_free(_text); +} + +void +ui_entry_set_text(GtkEntry *entry, const char *text) +{ + if (!text) + { + gtk_entry_set_text(entry, ""); + return; + } + + gchar *_text = g_locale_to_utf8(text, -1, NULL, NULL, NULL); + gtk_entry_set_text(entry, _text); + g_free(_text); +} + +void +ui_avatar_set_text(HdyAvatar *avatar, const char *text) +{ + if (!text) + { + const gchar *state = hdy_avatar_get_text(avatar); + + if ((!state) || (!g_utf8_strlen(state, 1))) + return; + + hdy_avatar_set_text(avatar, ""); + return; + } + + gchar *_text = g_locale_to_utf8(text, -1, NULL, NULL, NULL); + hdy_avatar_set_text(avatar, _text); + g_free(_text); +} diff --git a/src/ui.h b/src/ui.h @@ -0,0 +1,40 @@ +/* + This file is part of GNUnet. + Copyright (C) 2022 GNUnet e.V. + + GNUnet is free software: you can redistribute it and/or modify it + under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, + or (at your option) any later version. + + GNUnet is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. + + SPDX-License-Identifier: AGPL3.0-or-later + */ +/* + * @author Tobias Frisch + * @file ui.h + */ + +#ifndef UI_H_ +#define UI_H_ + +#include <gtk-3.0/gtk/gtk.h> +#include <libhandy-1/handy.h> + +void +ui_label_set_text(GtkLabel *label, const char *text); + +void +ui_entry_set_text(GtkEntry *entry, const char *text); + +void +ui_avatar_set_text(HdyAvatar *avatar, const char *text); + +#endif /* UI_H_ */ diff --git a/src/ui/account_entry.c b/src/ui/account_entry.c @@ -25,6 +25,7 @@ #include "account_entry.h" #include "../application.h" +#include "../ui.h" UI_ACCOUNT_ENTRY_Handle* ui_account_entry_new(MESSENGER_Application *app) @@ -54,26 +55,20 @@ void ui_account_entry_set_account(UI_ACCOUNT_ENTRY_Handle* handle, const struct GNUNET_CHAT_Account *account) { - const gchar *name = GNUNET_CHAT_account_get_name(account); + const char *name = GNUNET_CHAT_account_get_name(account); - if (!name) - return; - - hdy_avatar_set_text(handle->entry_avatar, name); - gtk_label_set_text(handle->entry_label, name); + ui_avatar_set_text(handle->entry_avatar, name); + ui_label_set_text(handle->entry_label, name); } void ui_account_entry_set_contact(UI_ACCOUNT_ENTRY_Handle* handle, const struct GNUNET_CHAT_Contact *contact) { - const gchar *name = GNUNET_CHAT_contact_get_name(contact); - - if (!name) - return; + const char *name = GNUNET_CHAT_contact_get_name(contact); - hdy_avatar_set_text(handle->entry_avatar, name); - gtk_label_set_text(handle->entry_label, name); + ui_avatar_set_text(handle->entry_avatar, name); + ui_label_set_text(handle->entry_label, name); } void diff --git a/src/ui/chat.c b/src/ui/chat.c @@ -38,6 +38,7 @@ #include "../application.h" #include "../contact.h" #include "../file.h" +#include "../ui.h" static gboolean _flap_chat_details_reveal_switch(gpointer user_data) @@ -520,7 +521,7 @@ handle_send_record_button_click(GtkButton *button, { UI_FILE_LOAD_ENTRY_Handle *file_load = ui_file_load_entry_new(app); - gtk_label_set_text(file_load->file_label, handle->recording_filename); + ui_label_set_text(file_load->file_label, handle->recording_filename); gtk_progress_bar_set_fraction(file_load->load_progress_bar, 0.0); struct GNUNET_CHAT_File *file = GNUNET_CHAT_context_send_file( @@ -1493,17 +1494,14 @@ ui_chat_update(UI_CHAT_Handle *handle, ); } - hdy_avatar_set_text(handle->chat_avatar, title? title : ""); + ui_avatar_set_text(handle->chat_avatar, title); hdy_avatar_set_icon_name(handle->chat_avatar, icon); - hdy_avatar_set_text(handle->chat_details_avatar, title? title : ""); + ui_avatar_set_text(handle->chat_details_avatar, title); hdy_avatar_set_icon_name(handle->chat_details_avatar, icon); - if (title) - { - gtk_label_set_text(handle->chat_title, title); - gtk_label_set_text(handle->chat_details_label, title); - } + ui_label_set_text(handle->chat_title, title); + ui_label_set_text(handle->chat_details_label, title); if (subtitle->len > 0) gtk_label_set_text(handle->chat_subtitle, subtitle->str); @@ -1694,7 +1692,7 @@ ui_chat_remove_file_load(UI_CHAT_Handle *handle, gtk_container_remove( GTK_CONTAINER(handle->chat_load_listbox), - gtk_widget_get_parent(GTK_WIDGET(file_load->entry_box)) + gtk_widget_get_parent(file_load->entry_box) ); if (handle->loads) diff --git a/src/ui/chat_entry.c b/src/ui/chat_entry.c @@ -24,10 +24,11 @@ #include "chat_entry.h" +#include "message.h" + #include "../application.h" #include "../contact.h" - -#include "message.h" +#include "../ui.h" UI_CHAT_ENTRY_Handle* ui_chat_entry_new(MESSENGER_Application *app) @@ -99,9 +100,8 @@ ui_chat_entry_update(UI_CHAT_ENTRY_Handle *handle, icon = "system-users-symbolic"; } - gtk_label_set_text(handle->title_label, title? title : ""); - - hdy_avatar_set_text(handle->entry_avatar, title? title : ""); + ui_label_set_text(handle->title_label, title); + ui_avatar_set_text(handle->entry_avatar, title); hdy_avatar_set_icon_name(handle->entry_avatar, icon); if (!(handle->chat)) diff --git a/src/ui/contact_entry.c b/src/ui/contact_entry.c @@ -25,6 +25,7 @@ #include "contact_entry.h" #include "../application.h" +#include "../ui.h" UI_CONTACT_ENTRY_Handle* ui_contact_entry_new(MESSENGER_Application *app) @@ -59,24 +60,12 @@ ui_contact_entry_set_contact(UI_CONTACT_ENTRY_Handle* handle, const struct GNUNET_CHAT_Contact *contact) { - const gchar *name; - const gchar *key; + const char *name = GNUNET_CHAT_contact_get_name(contact); + const char *key = GNUNET_CHAT_contact_get_key(contact); - name = GNUNET_CHAT_contact_get_name(contact); - - if (!name) - goto skip_name; - - hdy_avatar_set_text(handle->entry_avatar, name); - gtk_label_set_text(handle->title_label, name); - -skip_name: - key = GNUNET_CHAT_contact_get_key(contact); - - if (!key) - return; - - gtk_label_set_text(handle->subtitle_label, name); + ui_avatar_set_text(handle->entry_avatar, name); + ui_label_set_text(handle->title_label, name); + ui_label_set_text(handle->subtitle_label, key); } void diff --git a/src/ui/contact_info.c b/src/ui/contact_info.c @@ -25,7 +25,9 @@ #include "contact_info.h" #include "chat_entry.h" + #include "../application.h" +#include "../ui.h" static void handle_contact_edit_button_click(UNUSED GtkButton *button, @@ -137,13 +139,16 @@ handle_open_chat_button_click(UNUSED GtkButton *button, UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context); - if (!entry) + if ((!entry) || (!(entry->entry_box))) return; GtkListBoxRow *row = GTK_LIST_BOX_ROW( gtk_widget_get_parent(entry->entry_box) ); + if (!row) + return; + gtk_list_box_select_row(handle->app->ui.messenger.chats_listbox, row); gtk_list_box_invalidate_filter(handle->app->ui.messenger.chats_listbox); @@ -415,8 +420,8 @@ ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle, { const char *name = GNUNET_CHAT_contact_get_name(contact); - hdy_avatar_set_text(handle->contact_avatar, name? name : ""); - gtk_entry_set_text(handle->contact_name_entry, name? name : ""); + ui_avatar_set_text(handle->contact_avatar, name); + ui_entry_set_text(handle->contact_name_entry, name); g_object_set_qdata( G_OBJECT(handle->contact_name_entry), @@ -440,12 +445,12 @@ ui_contact_info_dialog_update(UI_CONTACT_INFO_Handle *handle, else handle->qr = NULL; - gtk_label_set_text(handle->name_label, name? name : ""); + ui_label_set_text(handle->name_label, name); if (handle->id_drawing_area) gtk_widget_queue_draw(GTK_WIDGET(handle->id_drawing_area)); - gtk_entry_set_text(handle->id_entry, key? key : ""); + ui_entry_set_text(handle->id_entry, key); gtk_widget_set_sensitive( GTK_WIDGET(handle->reveal_identity_button), diff --git a/src/ui/message.c b/src/ui/message.c @@ -28,6 +28,7 @@ #include "../application.h" #include "../file.h" +#include "../ui.h" static void handle_downloading_file(void *cls, @@ -434,6 +435,8 @@ _update_file_message(UI_MESSAGE_Handle *handle, MESSENGER_Application *app, struct GNUNET_CHAT_File *file) { + const char *filename = GNUNET_CHAT_file_get_name(file); + uint64_t size = GNUNET_CHAT_file_get_size(file); uint64_t local_size = GNUNET_CHAT_file_get_local_size(file); @@ -498,7 +501,7 @@ file_progress: ); file_content: - gtk_label_set_text(handle->filename_label, GNUNET_CHAT_file_get_name(file)); + ui_label_set_text(handle->filename_label, filename); gtk_stack_set_visible_child( handle->content_stack, diff --git a/src/ui/messenger.c b/src/ui/messenger.c @@ -37,6 +37,7 @@ #include "settings.h" #include "../application.h" +#include "../ui.h" static gboolean _flap_user_details_reveal_switch(gpointer user_data) @@ -605,24 +606,22 @@ _messenger_iterate_accounts(void *cls, MESSENGER_Application *app = (MESSENGER_Application*) cls; UI_MESSENGER_Handle *ui = &(app->ui.messenger); - const gchar *name = GNUNET_CHAT_account_get_name(account); + const char *name = GNUNET_CHAT_account_get_name(account); UI_ACCOUNT_ENTRY_Handle *entry = ui_account_entry_new(app); - hdy_avatar_set_text(entry->entry_avatar, name); - gtk_label_set_text(entry->entry_label, name); + ui_avatar_set_text(entry->entry_avatar, name); + ui_label_set_text(entry->entry_label, name); gtk_list_box_prepend(ui->accounts_listbox, entry->entry_box); - GtkListBoxRow *row = GTK_LIST_BOX_ROW( - gtk_widget_get_parent(entry->entry_box) - ); + GtkWidget *row = gtk_widget_get_parent(entry->entry_box); g_object_set_qdata(G_OBJECT(row), app->quarks.data, account); if ((account == GNUNET_CHAT_get_connected(handle)) || ((app->chat.identity) && (0 == g_strcmp0(app->chat.identity, name)))) - gtk_widget_activate(GTK_WIDGET(row)); + gtk_widget_activate(row); ui_account_entry_delete(entry); return GNUNET_YES; @@ -673,13 +672,16 @@ ui_messenger_is_context_active(UI_MESSENGER_Handle *handle, UI_CHAT_ENTRY_Handle *entry = GNUNET_CHAT_context_get_user_pointer(context); - if (!entry) + if ((!entry) || (!(entry->entry_box))) return FALSE; GtkListBoxRow *row = GTK_LIST_BOX_ROW( gtk_widget_get_parent(entry->entry_box) ); + if (!row) + return FALSE; + return gtk_list_box_row_is_selected(row); } diff --git a/src/ui/new_account.c b/src/ui/new_account.c @@ -63,7 +63,9 @@ handle_account_entry_changed(GtkEditable *editable, HdyAvatar *avatar = HDY_AVATAR(user_data); GtkEntry *entry = GTK_ENTRY(editable); - hdy_avatar_set_text(avatar, gtk_entry_get_text(entry)); + const gchar *text = gtk_entry_get_text(entry); + + hdy_avatar_set_text(avatar, text); } static void diff --git a/src/ui/new_contact.c b/src/ui/new_contact.c @@ -49,18 +49,18 @@ handle_confirm_button_click(UNUSED GtkButton *button, gchar *emsg = NULL; struct GNUNET_CHAT_Uri *uri = GNUNET_CHAT_uri_parse(id_text, &emsg); - if (uri) - { - GNUNET_CHAT_lobby_join(app->chat.messenger.handle, uri); - GNUNET_CHAT_uri_destroy(uri); - } - if (emsg) { - printf("ERROR: %s\n", emsg); + g_printerr("ERROR: %s\n", emsg); GNUNET_free(emsg); } + if (!uri) + goto close_dialog; + + GNUNET_CHAT_lobby_join(app->chat.messenger.handle, uri); + GNUNET_CHAT_uri_destroy(uri); + close_dialog: gtk_window_close(GTK_WINDOW(app->ui.new_contact.dialog)); } diff --git a/src/ui/new_group.c b/src/ui/new_group.c @@ -68,7 +68,9 @@ handle_group_entry_changed(GtkEditable *editable, HdyAvatar *avatar = HDY_AVATAR(user_data); GtkEntry *entry = GTK_ENTRY(editable); - hdy_avatar_set_text(avatar, gtk_entry_get_text(entry)); + const gchar *text = gtk_entry_get_text(entry); + + hdy_avatar_set_text(avatar, text); } static void @@ -166,10 +168,7 @@ _iterate_contacts(void *cls, entry->entry_box ); - GtkListBoxRow *row = GTK_LIST_BOX_ROW( - gtk_widget_get_parent(entry->entry_box) - ); - + GtkWidget *row = gtk_widget_get_parent(entry->entry_box); g_object_set_qdata(G_OBJECT(row), app->quarks.data, contact); app->ui.new_group.contact_entries = g_list_append( diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c @@ -51,7 +51,11 @@ handle_platform_entry_changed(GtkEditable *editable, HdyAvatar *avatar = HDY_AVATAR(user_data); GtkEntry *entry = GTK_ENTRY(editable); - GString *topic_string = g_string_new(gtk_entry_get_text(entry)); + const gchar *text = gtk_entry_get_text(entry); + + hdy_avatar_set_text(avatar, text); + + GString *topic_string = g_string_new(text); g_string_prepend_c(topic_string, '#'); hdy_avatar_set_text(avatar, topic_string->str); diff --git a/src/ui/send_file.c b/src/ui/send_file.c @@ -30,6 +30,7 @@ #include "../application.h" #include "../file.h" +#include "../ui.h" static void handle_cancel_button_click(UNUSED GtkButton *button,