aboutsummaryrefslogtreecommitdiff
path: root/src/ui/new_platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/new_platform.c')
-rw-r--r--src/ui/new_platform.c95
1 files changed, 56 insertions, 39 deletions
diff --git a/src/ui/new_platform.c b/src/ui/new_platform.c
index 1216239..ac7da16 100644
--- a/src/ui/new_platform.c
+++ b/src/ui/new_platform.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2021--2022 GNUnet e.V. 3 Copyright (C) 2021--2024 GNUnet e.V.
4 4
5 GNUnet is free software: you can redistribute it and/or modify it 5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published 6 under the terms of the GNU Affero General Public License as published
@@ -27,15 +27,18 @@
27#include "../application.h" 27#include "../application.h"
28 28
29static void 29static void
30_open_new_platform(GtkEntry *entry, MESSENGER_Application *app) 30_open_new_platform(GtkEntry *entry,
31 MESSENGER_Application *app)
31{ 32{
33 g_assert((entry) && (app));
34
32 const gchar *topic = gtk_entry_get_text(entry); 35 const gchar *topic = gtk_entry_get_text(entry);
33 36
34 GString *topic_string = g_string_new(topic); 37 GString *topic_string = g_string_new(topic);
35 38
36 struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create( 39 struct GNUNET_CHAT_Group *group = GNUNET_CHAT_group_create(
37 app->chat.messenger.handle, 40 app->chat.messenger.handle,
38 topic_string->str 41 topic_string->str
39 ); 42 );
40 43
41 g_string_prepend_c(topic_string, '#'); 44 g_string_prepend_c(topic_string, '#');
@@ -46,8 +49,10 @@ _open_new_platform(GtkEntry *entry, MESSENGER_Application *app)
46 49
47static void 50static void
48handle_platform_entry_changed(GtkEditable *editable, 51handle_platform_entry_changed(GtkEditable *editable,
49 gpointer user_data) 52 gpointer user_data)
50{ 53{
54 g_assert((editable) && (user_data));
55
51 HdyAvatar *avatar = HDY_AVATAR(user_data); 56 HdyAvatar *avatar = HDY_AVATAR(user_data);
52 GtkEntry *entry = GTK_ENTRY(editable); 57 GtkEntry *entry = GTK_ENTRY(editable);
53 58
@@ -65,8 +70,10 @@ handle_platform_entry_changed(GtkEditable *editable,
65 70
66static void 71static void
67handle_platform_entry_activate(GtkEntry *entry, 72handle_platform_entry_activate(GtkEntry *entry,
68 gpointer user_data) 73 gpointer user_data)
69{ 74{
75 g_assert((entry) && (user_data));
76
70 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 77 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
71 78
72 _open_new_platform(entry, app); 79 _open_new_platform(entry, app);
@@ -76,16 +83,20 @@ handle_platform_entry_activate(GtkEntry *entry,
76 83
77static void 84static void
78handle_cancel_button_click(UNUSED GtkButton *button, 85handle_cancel_button_click(UNUSED GtkButton *button,
79 gpointer user_data) 86 gpointer user_data)
80{ 87{
88 g_assert(user_data);
89
81 GtkDialog *dialog = GTK_DIALOG(user_data); 90 GtkDialog *dialog = GTK_DIALOG(user_data);
82 gtk_window_close(GTK_WINDOW(dialog)); 91 gtk_window_close(GTK_WINDOW(dialog));
83} 92}
84 93
85static void 94static void
86handle_confirm_button_click(UNUSED GtkButton *button, 95handle_confirm_button_click(UNUSED GtkButton *button,
87 gpointer user_data) 96 gpointer user_data)
88{ 97{
98 g_assert(user_data);
99
89 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 100 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
90 101
91 _open_new_platform(app->ui.new_platform.platform_entry, app); 102 _open_new_platform(app->ui.new_platform.platform_entry, app);
@@ -95,87 +106,93 @@ handle_confirm_button_click(UNUSED GtkButton *button,
95 106
96static void 107static void
97handle_dialog_destroy(UNUSED GtkWidget *window, 108handle_dialog_destroy(UNUSED GtkWidget *window,
98 gpointer user_data) 109 gpointer user_data)
99{ 110{
111 g_assert(user_data);
112
100 ui_new_platform_dialog_cleanup((UI_NEW_PLATFORM_Handle*) user_data); 113 ui_new_platform_dialog_cleanup((UI_NEW_PLATFORM_Handle*) user_data);
101} 114}
102 115
103void 116void
104ui_new_platform_dialog_init(MESSENGER_Application *app, 117ui_new_platform_dialog_init(MESSENGER_Application *app,
105 UI_NEW_PLATFORM_Handle *handle) 118 UI_NEW_PLATFORM_Handle *handle)
106{ 119{
120 g_assert((app) && (handle));
121
107 handle->builder = gtk_builder_new_from_resource( 122 handle->builder = gtk_builder_new_from_resource(
108 application_get_resource_path(app, "ui/new_platform.ui") 123 application_get_resource_path(app, "ui/new_platform.ui")
109 ); 124 );
110 125
111 handle->dialog = GTK_DIALOG( 126 handle->dialog = GTK_DIALOG(
112 gtk_builder_get_object(handle->builder, "new_platform_dialog") 127 gtk_builder_get_object(handle->builder, "new_platform_dialog")
113 ); 128 );
114 129
115 gtk_window_set_transient_for( 130 gtk_window_set_transient_for(
116 GTK_WINDOW(handle->dialog), 131 GTK_WINDOW(handle->dialog),
117 GTK_WINDOW(app->ui.messenger.main_window) 132 GTK_WINDOW(app->ui.messenger.main_window)
118 ); 133 );
119 134
120 handle->platform_avatar = HDY_AVATAR( 135 handle->platform_avatar = HDY_AVATAR(
121 gtk_builder_get_object(handle->builder, "platform_avatar") 136 gtk_builder_get_object(handle->builder, "platform_avatar")
122 ); 137 );
123 138
124 handle->platform_avatar_file = GTK_FILE_CHOOSER_BUTTON( 139 handle->platform_avatar_file = GTK_FILE_CHOOSER_BUTTON(
125 gtk_builder_get_object(handle->builder, "platform_avatar_file") 140 gtk_builder_get_object(handle->builder, "platform_avatar_file")
126 ); 141 );
127 142
128 handle->platform_entry = GTK_ENTRY( 143 handle->platform_entry = GTK_ENTRY(
129 gtk_builder_get_object(handle->builder, "platform_entry") 144 gtk_builder_get_object(handle->builder, "platform_entry")
130 ); 145 );
131 146
132 g_signal_connect( 147 g_signal_connect(
133 handle->platform_entry, 148 handle->platform_entry,
134 "changed", 149 "changed",
135 G_CALLBACK(handle_platform_entry_changed), 150 G_CALLBACK(handle_platform_entry_changed),
136 handle->platform_avatar 151 handle->platform_avatar
137 ); 152 );
138 153
139 g_signal_connect( 154 g_signal_connect(
140 handle->platform_entry, 155 handle->platform_entry,
141 "activate", 156 "activate",
142 G_CALLBACK(handle_platform_entry_activate), 157 G_CALLBACK(handle_platform_entry_activate),
143 app 158 app
144 ); 159 );
145 160
146 handle->cancel_button = GTK_BUTTON( 161 handle->cancel_button = GTK_BUTTON(
147 gtk_builder_get_object(handle->builder, "cancel_button") 162 gtk_builder_get_object(handle->builder, "cancel_button")
148 ); 163 );
149 164
150 g_signal_connect( 165 g_signal_connect(
151 handle->cancel_button, 166 handle->cancel_button,
152 "clicked", 167 "clicked",
153 G_CALLBACK(handle_cancel_button_click), 168 G_CALLBACK(handle_cancel_button_click),
154 handle->dialog 169 handle->dialog
155 ); 170 );
156 171
157 handle->confirm_button = GTK_BUTTON( 172 handle->confirm_button = GTK_BUTTON(
158 gtk_builder_get_object(handle->builder, "confirm_button") 173 gtk_builder_get_object(handle->builder, "confirm_button")
159 ); 174 );
160 175
161 g_signal_connect( 176 g_signal_connect(
162 handle->confirm_button, 177 handle->confirm_button,
163 "clicked", 178 "clicked",
164 G_CALLBACK(handle_confirm_button_click), 179 G_CALLBACK(handle_confirm_button_click),
165 app 180 app
166 ); 181 );
167 182
168 g_signal_connect( 183 g_signal_connect(
169 handle->dialog, 184 handle->dialog,
170 "destroy", 185 "destroy",
171 G_CALLBACK(handle_dialog_destroy), 186 G_CALLBACK(handle_dialog_destroy),
172 handle 187 handle
173 ); 188 );
174} 189}
175 190
176void 191void
177ui_new_platform_dialog_cleanup(UI_NEW_PLATFORM_Handle *handle) 192ui_new_platform_dialog_cleanup(UI_NEW_PLATFORM_Handle *handle)
178{ 193{
194 g_assert(handle);
195
179 g_object_unref(handle->builder); 196 g_object_unref(handle->builder);
180 197
181 memset(handle, 0, sizeof(*handle)); 198 memset(handle, 0, sizeof(*handle));