aboutsummaryrefslogtreecommitdiff
path: root/src/ui/settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/settings.c')
-rw-r--r--src/ui/settings.c331
1 files changed, 227 insertions, 104 deletions
diff --git a/src/ui/settings.c b/src/ui/settings.c
index b45a2b0..210f174 100644
--- a/src/ui/settings.c
+++ b/src/ui/settings.c
@@ -25,30 +25,99 @@
25#include "settings.h" 25#include "settings.h"
26 26
27#include "../application.h" 27#include "../application.h"
28#include "../request.h"
29
28#include <gnunet/gnunet_chat_lib.h> 30#include <gnunet/gnunet_chat_lib.h>
29#include <gnunet/gnunet_common.h> 31#include <gnunet/gnunet_common.h>
32#include <libportal/background.h>
30 33
31static gboolean 34static gboolean
32handle_general_switch_state(UNUSED GtkSwitch *widget, 35handle_general_switch_state(UNUSED GtkSwitch *widget,
33 gboolean state, 36 gboolean state,
34 gpointer user_data) 37 gpointer user_data)
35{ 38{
36 gboolean *setting = (gboolean*) user_data; 39 gboolean *setting = (gboolean*) user_data;
37 *setting = state; 40 *setting = state;
38 return FALSE; 41 return FALSE;
39} 42}
40 43
44static void
45_request_background_callback(GObject *source_object,
46 GAsyncResult *result,
47 gpointer user_data)
48{
49 XdpPortal *portal = XDP_PORTAL(source_object);
50 MESSENGER_Request *request = (MESSENGER_Request*) user_data;
51
52 request_cleanup(request);
53
54 MESSENGER_Application *app = request->application;
55 GtkSwitch *widget = GTK_SWITCH(request->user_data);
56
57 GError *error = NULL;
58 gboolean success = xdp_portal_request_background_finish(
59 portal, result, &error
60 );
61
62 if (!success) {
63 g_printerr("ERROR: %s\n", error->message);
64 g_error_free(error);
65
66 gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE);
67 gtk_switch_set_active(widget, FALSE);
68 return;
69 }
70
71 gboolean *setting = (gboolean*) (
72 g_object_get_qdata(G_OBJECT(widget), app->quarks.data)
73 );
74
75 handle_general_switch_state(widget, success, setting);
76}
77
78static gboolean
79handle_background_switch_state(GtkSwitch *widget,
80 gboolean state,
81 gpointer user_data)
82{
83 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
84
85 gboolean *setting = (gboolean*) (
86 g_object_get_qdata(G_OBJECT(widget), app->quarks.data)
87 );
88
89 if ((!state) || (!gtk_widget_is_sensitive(GTK_WIDGET(widget))))
90 return handle_general_switch_state(widget, state, setting);
91
92 XdpBackgroundFlags flags = XDP_BACKGROUND_FLAG_NONE;
93
94 if (&(app->settings.autostart) == setting)
95 flags |= XDP_BACKGROUND_FLAG_AUTOSTART;
96 if (&(app->settings.background_task) == setting)
97 flags |= XDP_BACKGROUND_FLAG_ACTIVATABLE;
98
99 request_new_background(
100 app,
101 flags,
102 _request_background_callback,
103 widget
104 );
105
106 gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE);
107 return FALSE;
108}
109
41static gboolean 110static gboolean
42handle_inverted_switch_state(GtkSwitch *widget, 111handle_inverted_switch_state(GtkSwitch *widget,
43 gboolean state, 112 gboolean state,
44 gpointer user_data) 113 gpointer user_data)
45{ 114{
46 return handle_general_switch_state(widget, !state, user_data); 115 return handle_general_switch_state(widget, !state, user_data);
47} 116}
48 117
49static void 118static void
50handle_general_combo_box_change(GtkComboBox *widget, 119handle_general_combo_box_change(GtkComboBox *widget,
51 gpointer user_data) 120 gpointer user_data)
52{ 121{
53 gulong *delay = (gulong*) user_data; 122 gulong *delay = (gulong*) user_data;
54 GtkTreeModel *model = gtk_combo_box_get_model(widget); 123 GtkTreeModel *model = gtk_combo_box_get_model(widget);
@@ -60,8 +129,8 @@ handle_general_combo_box_change(GtkComboBox *widget,
60 129
61int 130int
62_leave_group_iteration(UNUSED void *cls, 131_leave_group_iteration(UNUSED void *cls,
63 UNUSED struct GNUNET_CHAT_Handle *handle, 132 UNUSED struct GNUNET_CHAT_Handle *handle,
64 struct GNUNET_CHAT_Group *group) 133 struct GNUNET_CHAT_Group *group)
65{ 134{
66 GNUNET_CHAT_group_leave(group); 135 GNUNET_CHAT_group_leave(group);
67 return GNUNET_YES; 136 return GNUNET_YES;
@@ -69,8 +138,8 @@ _leave_group_iteration(UNUSED void *cls,
69 138
70int 139int
71_delete_contact_iteration(UNUSED void *cls, 140_delete_contact_iteration(UNUSED void *cls,
72 UNUSED struct GNUNET_CHAT_Handle *handle, 141 UNUSED struct GNUNET_CHAT_Handle *handle,
73 struct GNUNET_CHAT_Contact *contact) 142 struct GNUNET_CHAT_Contact *contact)
74{ 143{
75 GNUNET_CHAT_contact_delete(contact); 144 GNUNET_CHAT_contact_delete(contact);
76 return GNUNET_YES; 145 return GNUNET_YES;
@@ -78,20 +147,20 @@ _delete_contact_iteration(UNUSED void *cls,
78 147
79static void 148static void
80handle_leave_chats_button_click(UNUSED GtkButton* button, 149handle_leave_chats_button_click(UNUSED GtkButton* button,
81 gpointer user_data) 150 gpointer user_data)
82{ 151{
83 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 152 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
84 153
85 GNUNET_CHAT_iterate_groups( 154 GNUNET_CHAT_iterate_groups(
86 app->chat.messenger.handle, 155 app->chat.messenger.handle,
87 _leave_group_iteration, 156 _leave_group_iteration,
88 NULL 157 NULL
89 ); 158 );
90 159
91 GNUNET_CHAT_iterate_contacts( 160 GNUNET_CHAT_iterate_contacts(
92 app->chat.messenger.handle, 161 app->chat.messenger.handle,
93 _delete_contact_iteration, 162 _delete_contact_iteration,
94 NULL 163 NULL
95 ); 164 );
96} 165}
97 166
@@ -145,218 +214,272 @@ ui_settings_dialog_init(MESSENGER_Application *app,
145 UI_SETTINGS_Handle *handle) 214 UI_SETTINGS_Handle *handle)
146{ 215{
147 handle->builder = gtk_builder_new_from_resource( 216 handle->builder = gtk_builder_new_from_resource(
148 application_get_resource_path(app, "ui/settings.ui") 217 application_get_resource_path(app, "ui/settings.ui")
149 ); 218 );
150 219
151 handle->dialog = HDY_PREFERENCES_WINDOW( 220 handle->dialog = HDY_PREFERENCES_WINDOW(
152 gtk_builder_get_object(handle->builder, "settings_dialog") 221 gtk_builder_get_object(handle->builder, "settings_dialog")
153 ); 222 );
154 223
155 gtk_window_set_transient_for( 224 gtk_window_set_transient_for(
156 GTK_WINDOW(handle->dialog), 225 GTK_WINDOW(handle->dialog),
157 GTK_WINDOW(app->ui.messenger.main_window) 226 GTK_WINDOW(app->ui.messenger.main_window)
227 );
228
229 handle->start_on_login_switch = GTK_SWITCH(
230 gtk_builder_get_object(handle->builder, "start_on_login_switch")
231 );
232
233 gtk_switch_set_active(
234 handle->start_on_login_switch,
235 app->settings.autostart
236 );
237
238 gtk_widget_set_sensitive(
239 GTK_WIDGET(handle->start_on_login_switch),
240 !(app->settings.autostart)
241 );
242
243 g_object_set_qdata(
244 G_OBJECT(handle->start_on_login_switch),
245 app->quarks.data,
246 &(app->settings.autostart)
247 );
248
249 g_signal_connect(
250 handle->start_on_login_switch,
251 "state-set",
252 G_CALLBACK(handle_background_switch_state),
253 app
254 );
255
256 handle->run_in_background_switch = GTK_SWITCH(
257 gtk_builder_get_object(handle->builder, "run_in_background_switch")
258 );
259
260 gtk_switch_set_active(
261 handle->run_in_background_switch,
262 app->settings.background_task
263 );
264
265 gtk_widget_set_sensitive(
266 GTK_WIDGET(handle->run_in_background_switch),
267 !(app->settings.background_task)
268 );
269
270 g_object_set_qdata(
271 G_OBJECT(handle->run_in_background_switch),
272 app->quarks.data,
273 &(app->settings.background_task)
274 );
275
276 g_signal_connect(
277 handle->run_in_background_switch,
278 "state-set",
279 G_CALLBACK(handle_background_switch_state),
280 app
158 ); 281 );
159 282
160 handle->enable_notifications_switch = GTK_SWITCH( 283 handle->enable_notifications_switch = GTK_SWITCH(
161 gtk_builder_get_object(handle->builder, "enable_notifications_switch") 284 gtk_builder_get_object(handle->builder, "enable_notifications_switch")
162 ); 285 );
163 286
164 gtk_switch_set_active( 287 gtk_switch_set_active(
165 handle->enable_notifications_switch, 288 handle->enable_notifications_switch,
166 !(app->settings.disable_notifications) 289 !(app->settings.disable_notifications)
167 ); 290 );
168 291
169 g_signal_connect( 292 g_signal_connect(
170 handle->enable_notifications_switch, 293 handle->enable_notifications_switch,
171 "state-set", 294 "state-set",
172 G_CALLBACK(handle_inverted_switch_state), 295 G_CALLBACK(handle_inverted_switch_state),
173 &(app->settings.disable_notifications) 296 &(app->settings.disable_notifications)
174 ); 297 );
175 298
176 handle->blocked_label = GTK_LABEL( 299 handle->blocked_label = GTK_LABEL(
177 gtk_builder_get_object(handle->builder, "blocked_label") 300 gtk_builder_get_object(handle->builder, "blocked_label")
178 ); 301 );
179 302
180 guint blocked_count = 0; 303 guint blocked_count = 0;
181 GNUNET_CHAT_iterate_contacts( 304 GNUNET_CHAT_iterate_contacts(
182 app->chat.messenger.handle, 305 app->chat.messenger.handle,
183 _count_blocked_contacts, 306 _count_blocked_contacts,
184 &blocked_count 307 &blocked_count
185 ); 308 );
186 309
187 GString *blocked_text = g_string_new(NULL); 310 GString *blocked_text = g_string_new(NULL);
188 if (blocked_text) 311 if (blocked_text)
189 { 312 {
190 g_string_printf( 313 g_string_printf(
191 blocked_text, 314 blocked_text,
192 "%u blocked contacts", 315 "%u blocked contacts",
193 blocked_count 316 blocked_count
194 ); 317 );
195 318
196 gtk_label_set_text( 319 gtk_label_set_text(
197 handle->blocked_label, 320 handle->blocked_label,
198 blocked_text->str 321 blocked_text->str
199 ); 322 );
200 323
201 g_string_free(blocked_text, TRUE); 324 g_string_free(blocked_text, TRUE);
202 } 325 }
203 326
204 handle->read_receipts_switch = GTK_SWITCH( 327 handle->read_receipts_switch = GTK_SWITCH(
205 gtk_builder_get_object(handle->builder, "read_receipts_switch") 328 gtk_builder_get_object(handle->builder, "read_receipts_switch")
206 ); 329 );
207 330
208 gtk_switch_set_active( 331 gtk_switch_set_active(
209 handle->read_receipts_switch, 332 handle->read_receipts_switch,
210 app->settings.send_read_receipts 333 app->settings.send_read_receipts
211 ); 334 );
212 335
213 g_signal_connect( 336 g_signal_connect(
214 handle->read_receipts_switch, 337 handle->read_receipts_switch,
215 "state-set", 338 "state-set",
216 G_CALLBACK(handle_general_switch_state), 339 G_CALLBACK(handle_general_switch_state),
217 &(app->settings.send_read_receipts) 340 &(app->settings.send_read_receipts)
218 ); 341 );
219 342
220 handle->whispering_switch = GTK_SWITCH( 343 handle->whispering_switch = GTK_SWITCH(
221 gtk_builder_get_object(handle->builder, "whispering_switch") 344 gtk_builder_get_object(handle->builder, "whispering_switch")
222 ); 345 );
223 346
224 gtk_switch_set_active( 347 gtk_switch_set_active(
225 handle->whispering_switch, 348 handle->whispering_switch,
226 app->settings.show_whispering 349 app->settings.show_whispering
227 ); 350 );
228 351
229 g_signal_connect( 352 g_signal_connect(
230 handle->whispering_switch, 353 handle->whispering_switch,
231 "state-set", 354 "state-set",
232 G_CALLBACK(handle_general_switch_state), 355 G_CALLBACK(handle_general_switch_state),
233 &(app->settings.show_whispering) 356 &(app->settings.show_whispering)
234 ); 357 );
235 358
236 handle->auto_delete_combo_box = GTK_COMBO_BOX( 359 handle->auto_delete_combo_box = GTK_COMBO_BOX(
237 gtk_builder_get_object(handle->builder, "auto_delete_combo_box") 360 gtk_builder_get_object(handle->builder, "auto_delete_combo_box")
238 ); 361 );
239 362
240 _set_combobox_to_active_by_delay( 363 _set_combobox_to_active_by_delay(
241 handle->auto_delete_combo_box, 364 handle->auto_delete_combo_box,
242 app->settings.auto_delete_delay 365 app->settings.auto_delete_delay
243 ); 366 );
244 367
245 g_signal_connect( 368 g_signal_connect(
246 handle->auto_delete_combo_box, 369 handle->auto_delete_combo_box,
247 "changed", 370 "changed",
248 G_CALLBACK(handle_general_combo_box_change), 371 G_CALLBACK(handle_general_combo_box_change),
249 &(app->settings.auto_delete_delay) 372 &(app->settings.auto_delete_delay)
250 ); 373 );
251 374
252 handle->auto_accept_invitations_switch = GTK_SWITCH( 375 handle->auto_accept_invitations_switch = GTK_SWITCH(
253 gtk_builder_get_object(handle->builder, "auto_accept_invitations_switch") 376 gtk_builder_get_object(handle->builder, "auto_accept_invitations_switch")
254 ); 377 );
255 378
256 gtk_switch_set_active( 379 gtk_switch_set_active(
257 handle->auto_accept_invitations_switch, 380 handle->auto_accept_invitations_switch,
258 app->settings.accept_all_invitations 381 app->settings.accept_all_invitations
259 ); 382 );
260 383
261 g_signal_connect( 384 g_signal_connect(
262 handle->auto_accept_invitations_switch, 385 handle->auto_accept_invitations_switch,
263 "state-set", 386 "state-set",
264 G_CALLBACK(handle_general_switch_state), 387 G_CALLBACK(handle_general_switch_state),
265 &(app->settings.accept_all_invitations) 388 &(app->settings.accept_all_invitations)
266 ); 389 );
267 390
268 handle->delete_invitations_combo_box = GTK_COMBO_BOX( 391 handle->delete_invitations_combo_box = GTK_COMBO_BOX(
269 gtk_builder_get_object(handle->builder, "delete_invitations_combo_box") 392 gtk_builder_get_object(handle->builder, "delete_invitations_combo_box")
270 ); 393 );
271 394
272 _set_combobox_to_active_by_delay( 395 _set_combobox_to_active_by_delay(
273 handle->delete_invitations_combo_box, 396 handle->delete_invitations_combo_box,
274 app->settings.delete_invitations_delay 397 app->settings.delete_invitations_delay
275 ); 398 );
276 399
277 g_signal_connect( 400 g_signal_connect(
278 handle->delete_invitations_combo_box, 401 handle->delete_invitations_combo_box,
279 "changed", 402 "changed",
280 G_CALLBACK(handle_general_combo_box_change), 403 G_CALLBACK(handle_general_combo_box_change),
281 &(app->settings.delete_invitations_delay) 404 &(app->settings.delete_invitations_delay)
282 ); 405 );
283 406
284 handle->delete_invitations_button = GTK_BUTTON( 407 handle->delete_invitations_button = GTK_BUTTON(
285 gtk_builder_get_object(handle->builder, "delete_invitations_button") 408 gtk_builder_get_object(handle->builder, "delete_invitations_button")
286 ); 409 );
287 410
288 handle->auto_accept_files_switch = GTK_SWITCH( 411 handle->auto_accept_files_switch = GTK_SWITCH(
289 gtk_builder_get_object(handle->builder, "auto_accept_files_switch") 412 gtk_builder_get_object(handle->builder, "auto_accept_files_switch")
290 ); 413 );
291 414
292 gtk_switch_set_active( 415 gtk_switch_set_active(
293 handle->auto_accept_files_switch, 416 handle->auto_accept_files_switch,
294 app->settings.accept_all_files 417 app->settings.accept_all_files
295 ); 418 );
296 419
297 g_signal_connect( 420 g_signal_connect(
298 handle->auto_accept_files_switch, 421 handle->auto_accept_files_switch,
299 "state-set", 422 "state-set",
300 G_CALLBACK(handle_general_switch_state), 423 G_CALLBACK(handle_general_switch_state),
301 &(app->settings.accept_all_files) 424 &(app->settings.accept_all_files)
302 ); 425 );
303 426
304 handle->download_folder_button = GTK_FILE_CHOOSER_BUTTON( 427 handle->download_folder_button = GTK_FILE_CHOOSER_BUTTON(
305 gtk_builder_get_object(handle->builder, "download_folder_button") 428 gtk_builder_get_object(handle->builder, "download_folder_button")
306 ); 429 );
307 430
308 handle->delete_files_combo_box = GTK_COMBO_BOX( 431 handle->delete_files_combo_box = GTK_COMBO_BOX(
309 gtk_builder_get_object(handle->builder, "delete_files_combo_box") 432 gtk_builder_get_object(handle->builder, "delete_files_combo_box")
310 ); 433 );
311 434
312 _set_combobox_to_active_by_delay( 435 _set_combobox_to_active_by_delay(
313 handle->delete_files_combo_box, 436 handle->delete_files_combo_box,
314 app->settings.delete_files_delay 437 app->settings.delete_files_delay
315 ); 438 );
316 439
317 g_signal_connect( 440 g_signal_connect(
318 handle->delete_files_combo_box, 441 handle->delete_files_combo_box,
319 "changed", 442 "changed",
320 G_CALLBACK(handle_general_combo_box_change), 443 G_CALLBACK(handle_general_combo_box_change),
321 &(app->settings.delete_files_delay) 444 &(app->settings.delete_files_delay)
322 ); 445 );
323 446
324 handle->delete_files_button = GTK_BUTTON( 447 handle->delete_files_button = GTK_BUTTON(
325 gtk_builder_get_object(handle->builder, "delete_files_button") 448 gtk_builder_get_object(handle->builder, "delete_files_button")
326 ); 449 );
327 450
328 handle->leave_chats_combo_box = GTK_COMBO_BOX( 451 handle->leave_chats_combo_box = GTK_COMBO_BOX(
329 gtk_builder_get_object(handle->builder, "leave_chats_combo_box") 452 gtk_builder_get_object(handle->builder, "leave_chats_combo_box")
330 ); 453 );
331 454
332 _set_combobox_to_active_by_delay( 455 _set_combobox_to_active_by_delay(
333 handle->leave_chats_combo_box, 456 handle->leave_chats_combo_box,
334 app->settings.leave_chats_delay 457 app->settings.leave_chats_delay
335 ); 458 );
336 459
337 g_signal_connect( 460 g_signal_connect(
338 handle->leave_chats_combo_box, 461 handle->leave_chats_combo_box,
339 "changed", 462 "changed",
340 G_CALLBACK(handle_general_combo_box_change), 463 G_CALLBACK(handle_general_combo_box_change),
341 &(app->settings.leave_chats_delay) 464 &(app->settings.leave_chats_delay)
342 ); 465 );
343 466
344 handle->leave_chats_button = GTK_BUTTON( 467 handle->leave_chats_button = GTK_BUTTON(
345 gtk_builder_get_object(handle->builder, "leave_chats_button") 468 gtk_builder_get_object(handle->builder, "leave_chats_button")
346 ); 469 );
347 470
348 g_signal_connect( 471 g_signal_connect(
349 handle->leave_chats_button, 472 handle->leave_chats_button,
350 "clicked", 473 "clicked",
351 G_CALLBACK(handle_leave_chats_button_click), 474 G_CALLBACK(handle_leave_chats_button_click),
352 app 475 app
353 ); 476 );
354 477
355 g_signal_connect( 478 g_signal_connect(
356 handle->dialog, 479 handle->dialog,
357 "destroy", 480 "destroy",
358 G_CALLBACK(handle_dialog_destroy), 481 G_CALLBACK(handle_dialog_destroy),
359 handle 482 handle
360 ); 483 );
361} 484}
362 485