diff options
author | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-14 17:54:23 +0100 |
---|---|---|
committer | TheJackiMonster <thejackimonster@gmail.com> | 2021-11-14 17:54:23 +0100 |
commit | bcf36809da07651976fc6528a391f3b51fc5ce0b (patch) | |
tree | 1ce3c1113026f2966abe6e17de2a2d550f99edd6 | |
parent | 56a206cd17e1caf23fbfd679c39752e5e194f35d (diff) | |
download | messenger-gtk-bcf36809da07651976fc6528a391f3b51fc5ce0b.tar.gz messenger-gtk-bcf36809da07651976fc6528a391f3b51fc5ce0b.zip |
Fixed segfault and added convenience
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r-- | src/ui/messenger.c | 19 | ||||
-rw-r--r-- | src/ui/new_platform.c | 52 |
2 files changed, 48 insertions, 23 deletions
diff --git a/src/ui/messenger.c b/src/ui/messenger.c index 2fc8c54..70d71b3 100644 --- a/src/ui/messenger.c +++ b/src/ui/messenger.c | |||
@@ -291,16 +291,17 @@ ui_messenger_init(MESSENGER_Application *app, | |||
291 | ); | 291 | ); |
292 | } | 292 | } |
293 | 293 | ||
294 | static void | ||
295 | _free_ui_chat_entry (gpointer user_data) | ||
296 | { | ||
297 | UI_CHAT_ENTRY_Handle* handle = (UI_CHAT_ENTRY_Handle*) user_data; | ||
298 | |||
299 | ui_chat_entry_delete(handle); | ||
300 | } | ||
301 | |||
302 | void | 294 | void |
303 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle) | 295 | ui_messenger_cleanup(UI_MESSENGER_Handle *handle) |
304 | { | 296 | { |
305 | g_list_free_full(handle->chat_entries, _free_ui_chat_entry); | 297 | GList *list = handle->chat_entries; |
298 | |||
299 | while (list) { | ||
300 | if (list->data) | ||
301 | ui_chat_entry_delete((UI_CHAT_ENTRY_Handle*) list->data); | ||
302 | |||
303 | list = list->next; | ||
304 | } | ||
305 | |||
306 | g_list_free(handle->chat_entries); | ||
306 | } | 307 | } |
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c index c1d4491..75966b5 100644 --- a/src/ui/new_platform.c +++ b/src/ui/new_platform.c | |||
@@ -27,6 +27,25 @@ | |||
27 | #include "../application.h" | 27 | #include "../application.h" |
28 | 28 | ||
29 | static void | 29 | static void |
30 | _open_new_platform(GtkEntry *entry, MESSENGER_Application *app) | ||
31 | { | ||
32 | const gchar *topic = gtk_entry_get_text(entry); | ||
33 | |||
34 | GString *topic_string = g_string_new(topic); | ||
35 | |||
36 | struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create( | ||
37 | app->chat.messenger.handle, | ||
38 | topic_string->str | ||
39 | ); | ||
40 | |||
41 | g_string_prepend_c(topic_string, '#'); | ||
42 | |||
43 | GNUNET_CHAT_group_set_name(group, topic_string->str); | ||
44 | |||
45 | g_string_free(topic_string, TRUE); | ||
46 | } | ||
47 | |||
48 | static void | ||
30 | handle_platform_entry_changed(GtkEditable *editable, | 49 | handle_platform_entry_changed(GtkEditable *editable, |
31 | gpointer user_data) | 50 | gpointer user_data) |
32 | { | 51 | { |
@@ -37,6 +56,17 @@ handle_platform_entry_changed(GtkEditable *editable, | |||
37 | } | 56 | } |
38 | 57 | ||
39 | static void | 58 | static void |
59 | handle_platform_entry_activate(GtkEntry *entry, | ||
60 | gpointer user_data) | ||
61 | { | ||
62 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | ||
63 | |||
64 | _open_new_platform(entry, app); | ||
65 | |||
66 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog)); | ||
67 | } | ||
68 | |||
69 | static void | ||
40 | handle_cancel_button_click(UNUSED GtkButton *button, | 70 | handle_cancel_button_click(UNUSED GtkButton *button, |
41 | gpointer user_data) | 71 | gpointer user_data) |
42 | { | 72 | { |
@@ -50,20 +80,7 @@ handle_confirm_button_click(UNUSED GtkButton *button, | |||
50 | { | 80 | { |
51 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; | 81 | MESSENGER_Application *app = (MESSENGER_Application*) user_data; |
52 | 82 | ||
53 | const gchar *topic = gtk_entry_get_text(app->ui.new_platform.platform_entry); | 83 | _open_new_platform(app->ui.new_platform.platform_entry, app); |
54 | |||
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); | ||
67 | 84 | ||
68 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog)); | 85 | gtk_window_close(GTK_WINDOW(app->ui.new_platform.platform_dialog)); |
69 | } | 86 | } |
@@ -109,6 +126,13 @@ ui_new_platform_dialog_init(MESSENGER_Application *app, | |||
109 | handle->platform_avatar | 126 | handle->platform_avatar |
110 | ); | 127 | ); |
111 | 128 | ||
129 | g_signal_connect( | ||
130 | handle->platform_entry, | ||
131 | "activate", | ||
132 | G_CALLBACK(handle_platform_entry_activate), | ||
133 | app | ||
134 | ); | ||
135 | |||
112 | handle->cancel_button = GTK_BUTTON( | 136 | handle->cancel_button = GTK_BUTTON( |
113 | gtk_builder_get_object(builder, "cancel_button") | 137 | gtk_builder_get_object(builder, "cancel_button") |
114 | ); | 138 | ); |