aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheJackiMonster <thejackimonster@gmail.com>2022-03-20 15:45:21 +0100
committerTheJackiMonster <thejackimonster@gmail.com>2022-03-20 15:45:21 +0100
commit7d6be3784f4f31a7e20ec5c9c4988e3fab864e8d (patch)
tree4afa7ce20b32b1c771ddab9a478af6000d62f3ef
parent2cb5059f0353f2dca0762a3eba714361a7e19a2e (diff)
downloadmessenger-gtk-7d6be3784f4f31a7e20ec5c9c4988e3fab864e8d.tar.gz
messenger-gtk-7d6be3784f4f31a7e20ec5c9c4988e3fab864e8d.zip
Implement automatic delay settings
Signed-off-by: TheJackiMonster <thejackimonster@gmail.com>
-rw-r--r--src/application.h8
-rw-r--r--src/event.c46
-rw-r--r--src/ui/settings.c85
3 files changed, 137 insertions, 2 deletions
diff --git a/src/application.h b/src/application.h
index 1fd14be..8c7b599 100644
--- a/src/application.h
+++ b/src/application.h
@@ -120,10 +120,16 @@ typedef struct MESSENGER_Application
120 gboolean send_read_receipts; 120 gboolean send_read_receipts;
121 gboolean show_whispering; 121 gboolean show_whispering;
122 122
123 gulong auto_delete_delay;
124
123 gboolean accept_all_invitations; 125 gboolean accept_all_invitations;
124 gboolean accept_all_files; 126 gulong delete_invitations_delay;
125 127
128 gboolean accept_all_files;
126 gchar *download_folder_path; 129 gchar *download_folder_path;
130 gulong delete_files_delay;
131
132 gulong leave_chats_delay;
127 } settings; 133 } settings;
128} MESSENGER_Application; 134} MESSENGER_Application;
129 135
diff --git a/src/event.c b/src/event.c
index 17a3a39..8cfdaa7 100644
--- a/src/event.c
+++ b/src/event.c
@@ -328,6 +328,22 @@ event_update_profile(MESSENGER_Application *app)
328 GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); 328 GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app);
329} 329}
330 330
331gboolean
332_delayed_context_drop(gpointer user_data)
333{
334 struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) user_data;
335
336 struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group(context);
337 struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_context_get_contact(context);
338
339 if (group)
340 GNUNET_CHAT_group_leave(group);
341 else if (contact)
342 GNUNET_CHAT_contact_delete(contact);
343
344 return FALSE;
345}
346
331void 347void
332event_update_chats(MESSENGER_Application *app, 348event_update_chats(MESSENGER_Application *app,
333 struct GNUNET_CHAT_Context *context, 349 struct GNUNET_CHAT_Context *context,
@@ -340,10 +356,19 @@ event_update_chats(MESSENGER_Application *app,
340 ); 356 );
341 357
342 if (GNUNET_CHAT_KIND_JOIN == kind) 358 if (GNUNET_CHAT_KIND_JOIN == kind)
359 {
343 if (!handle) 360 if (!handle)
344 _add_new_chat_entry(app, context); 361 _add_new_chat_entry(app, context);
345 else 362 else
346 enqueue_chat_entry_update(handle); 363 enqueue_chat_entry_update(handle);
364
365 if (app->settings.leave_chats_delay > 0)
366 g_timeout_add_seconds(
367 app->settings.leave_chats_delay,
368 _delayed_context_drop,
369 context
370 );
371 }
347 else if (handle) 372 else if (handle)
348 _clear_chat_entry(gtk_widget_get_parent(handle->entry_box), app); 373 _clear_chat_entry(gtk_widget_get_parent(handle->entry_box), app);
349 374
@@ -485,6 +510,12 @@ event_invitation(MESSENGER_Application *app,
485 if (!invitation) 510 if (!invitation)
486 return; 511 return;
487 512
513 if (app->settings.delete_invitations_delay > 0)
514 GNUNET_CHAT_message_delete(msg, GNUNET_TIME_relative_multiply(
515 GNUNET_TIME_relative_get_second_(),
516 app->settings.delete_invitations_delay
517 ));
518
488 const int sent = GNUNET_CHAT_message_is_sent(msg); 519 const int sent = GNUNET_CHAT_message_is_sent(msg);
489 520
490 if ((GNUNET_YES != sent) && (app->settings.send_read_receipts)) 521 if ((GNUNET_YES != sent) && (app->settings.send_read_receipts))
@@ -542,6 +573,14 @@ event_receive_message(MESSENGER_Application *app,
542 if (!handle) 573 if (!handle)
543 return; 574 return;
544 575
576 const int sent = GNUNET_CHAT_message_is_sent(msg);
577
578 if ((sent) && (app->settings.auto_delete_delay > 0))
579 GNUNET_CHAT_message_delete(msg, GNUNET_TIME_relative_multiply(
580 GNUNET_TIME_relative_get_second_(),
581 app->settings.auto_delete_delay
582 ));
583
545 const gboolean whispering = ( 584 const gboolean whispering = (
546 GNUNET_CHAT_KIND_WHISPER == GNUNET_CHAT_message_get_kind(msg) 585 GNUNET_CHAT_KIND_WHISPER == GNUNET_CHAT_message_get_kind(msg)
547 ); 586 );
@@ -549,7 +588,6 @@ event_receive_message(MESSENGER_Application *app,
549 if ((whispering) && (!(app->settings.show_whispering))) 588 if ((whispering) && (!(app->settings.show_whispering)))
550 return; 589 return;
551 590
552 const int sent = GNUNET_CHAT_message_is_sent(msg);
553 const gchar *text = GNUNET_CHAT_message_get_text(msg); 591 const gchar *text = GNUNET_CHAT_message_get_text(msg);
554 592
555 if (whispering) 593 if (whispering)
@@ -573,6 +611,12 @@ event_receive_message(MESSENGER_Application *app,
573 { 611 {
574 file_create_info(file); 612 file_create_info(file);
575 file_add_ui_message_to_info(file, message); 613 file_add_ui_message_to_info(file, message);
614
615 if (app->settings.delete_files_delay > 0)
616 GNUNET_CHAT_message_delete(msg, GNUNET_TIME_relative_multiply(
617 GNUNET_TIME_relative_get_second_(),
618 app->settings.delete_files_delay
619 ));
576 } 620 }
577 621
578 ui_message_update(message, app, msg); 622 ui_message_update(message, app, msg);
diff --git a/src/ui/settings.c b/src/ui/settings.c
index 87812f2..99b487b 100644
--- a/src/ui/settings.c
+++ b/src/ui/settings.c
@@ -45,12 +45,49 @@ handle_inverted_switch_state(GtkSwitch *widget,
45} 45}
46 46
47static void 47static void
48handle_general_combo_box_change(GtkComboBox *widget,
49 gpointer user_data)
50{
51 gulong *delay = (gulong*) user_data;
52 GtkTreeModel *model = gtk_combo_box_get_model(widget);
53
54 GtkTreeIter iter;
55 if (gtk_combo_box_get_active_iter(widget, &iter))
56 gtk_tree_model_get(model, &iter, 1, delay, -1);
57}
58
59static void
48handle_dialog_destroy(UNUSED GtkWidget *window, 60handle_dialog_destroy(UNUSED GtkWidget *window,
49 gpointer user_data) 61 gpointer user_data)
50{ 62{
51 ui_settings_dialog_cleanup((UI_SETTINGS_Handle*) user_data); 63 ui_settings_dialog_cleanup((UI_SETTINGS_Handle*) user_data);
52} 64}
53 65
66static void
67_set_combobox_to_active_by_delay(GtkComboBox *widget,
68 gulong delay)
69{
70 GtkTreeModel *model = gtk_combo_box_get_model(widget);
71
72 GtkTreeIter iter;
73 if (!gtk_tree_model_get_iter_first(model, &iter))
74 return;
75
76 gulong value;
77
78 do {
79 gtk_tree_model_get(model, &iter, 1, &value, -1);
80
81 if (value == delay)
82 goto set_active;
83
84 } while (gtk_tree_model_iter_next(model, &iter));
85
86 return;
87set_active:
88 gtk_combo_box_set_active_iter(widget, &iter);
89}
90
54void 91void
55ui_settings_dialog_init(MESSENGER_Application *app, 92ui_settings_dialog_init(MESSENGER_Application *app,
56 UI_SETTINGS_Handle *handle) 93 UI_SETTINGS_Handle *handle)
@@ -120,6 +157,18 @@ ui_settings_dialog_init(MESSENGER_Application *app,
120 gtk_builder_get_object(handle->builder, "auto_delete_combo_box") 157 gtk_builder_get_object(handle->builder, "auto_delete_combo_box")
121 ); 158 );
122 159
160 _set_combobox_to_active_by_delay(
161 handle->auto_delete_combo_box,
162 app->settings.auto_delete_delay
163 );
164
165 g_signal_connect(
166 handle->auto_delete_combo_box,
167 "changed",
168 G_CALLBACK(handle_general_combo_box_change),
169 &(app->settings.auto_delete_delay)
170 );
171
123 handle->auto_accept_invitations_switch = GTK_SWITCH( 172 handle->auto_accept_invitations_switch = GTK_SWITCH(
124 gtk_builder_get_object(handle->builder, "auto_accept_invitations_switch") 173 gtk_builder_get_object(handle->builder, "auto_accept_invitations_switch")
125 ); 174 );
@@ -140,6 +189,18 @@ ui_settings_dialog_init(MESSENGER_Application *app,
140 gtk_builder_get_object(handle->builder, "delete_invitations_combo_box") 189 gtk_builder_get_object(handle->builder, "delete_invitations_combo_box")
141 ); 190 );
142 191
192 _set_combobox_to_active_by_delay(
193 handle->delete_invitations_combo_box,
194 app->settings.delete_invitations_delay
195 );
196
197 g_signal_connect(
198 handle->delete_invitations_combo_box,
199 "changed",
200 G_CALLBACK(handle_general_combo_box_change),
201 &(app->settings.delete_invitations_delay)
202 );
203
143 handle->delete_invitations_button = GTK_BUTTON( 204 handle->delete_invitations_button = GTK_BUTTON(
144 gtk_builder_get_object(handle->builder, "delete_invitations_button") 205 gtk_builder_get_object(handle->builder, "delete_invitations_button")
145 ); 206 );
@@ -168,6 +229,18 @@ ui_settings_dialog_init(MESSENGER_Application *app,
168 gtk_builder_get_object(handle->builder, "delete_files_combo_box") 229 gtk_builder_get_object(handle->builder, "delete_files_combo_box")
169 ); 230 );
170 231
232 _set_combobox_to_active_by_delay(
233 handle->delete_files_combo_box,
234 app->settings.delete_files_delay
235 );
236
237 g_signal_connect(
238 handle->delete_files_combo_box,
239 "changed",
240 G_CALLBACK(handle_general_combo_box_change),
241 &(app->settings.delete_files_delay)
242 );
243
171 handle->delete_files_button = GTK_BUTTON( 244 handle->delete_files_button = GTK_BUTTON(
172 gtk_builder_get_object(handle->builder, "delete_files_button") 245 gtk_builder_get_object(handle->builder, "delete_files_button")
173 ); 246 );
@@ -176,6 +249,18 @@ ui_settings_dialog_init(MESSENGER_Application *app,
176 gtk_builder_get_object(handle->builder, "leave_chats_combo_box") 249 gtk_builder_get_object(handle->builder, "leave_chats_combo_box")
177 ); 250 );
178 251
252 _set_combobox_to_active_by_delay(
253 handle->leave_chats_combo_box,
254 app->settings.leave_chats_delay
255 );
256
257 g_signal_connect(
258 handle->leave_chats_combo_box,
259 "changed",
260 G_CALLBACK(handle_general_combo_box_change),
261 &(app->settings.leave_chats_delay)
262 );
263
179 handle->leave_chats_button = GTK_BUTTON( 264 handle->leave_chats_button = GTK_BUTTON(
180 gtk_builder_get_object(handle->builder, "leave_chats_button") 265 gtk_builder_get_object(handle->builder, "leave_chats_button")
181 ); 266 );