messenger-gtk

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

commit 7d6be3784f4f31a7e20ec5c9c4988e3fab864e8d
parent 2cb5059f0353f2dca0762a3eba714361a7e19a2e
Author: TheJackiMonster <thejackimonster@gmail.com>
Date:   Sun, 20 Mar 2022 15:45:21 +0100

Implement automatic delay settings

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

Diffstat:
Msrc/application.h | 8+++++++-
Msrc/event.c | 46+++++++++++++++++++++++++++++++++++++++++++++-
Msrc/ui/settings.c | 85+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 137 insertions(+), 2 deletions(-)

diff --git a/src/application.h b/src/application.h @@ -120,10 +120,16 @@ typedef struct MESSENGER_Application gboolean send_read_receipts; gboolean show_whispering; + gulong auto_delete_delay; + gboolean accept_all_invitations; - gboolean accept_all_files; + gulong delete_invitations_delay; + gboolean accept_all_files; gchar *download_folder_path; + gulong delete_files_delay; + + gulong leave_chats_delay; } settings; } MESSENGER_Application; diff --git a/src/event.c b/src/event.c @@ -328,6 +328,22 @@ event_update_profile(MESSENGER_Application *app) GNUNET_CHAT_iterate_groups(chat->handle, _iterate_profile_groups, app); } +gboolean +_delayed_context_drop(gpointer user_data) +{ + struct GNUNET_CHAT_Context *context = (struct GNUNET_CHAT_Context*) user_data; + + struct GNUNET_CHAT_Group *group = GNUNET_CHAT_context_get_group(context); + struct GNUNET_CHAT_Contact *contact = GNUNET_CHAT_context_get_contact(context); + + if (group) + GNUNET_CHAT_group_leave(group); + else if (contact) + GNUNET_CHAT_contact_delete(contact); + + return FALSE; +} + void event_update_chats(MESSENGER_Application *app, struct GNUNET_CHAT_Context *context, @@ -340,10 +356,19 @@ event_update_chats(MESSENGER_Application *app, ); if (GNUNET_CHAT_KIND_JOIN == kind) + { if (!handle) _add_new_chat_entry(app, context); else enqueue_chat_entry_update(handle); + + if (app->settings.leave_chats_delay > 0) + g_timeout_add_seconds( + app->settings.leave_chats_delay, + _delayed_context_drop, + context + ); + } else if (handle) _clear_chat_entry(gtk_widget_get_parent(handle->entry_box), app); @@ -485,6 +510,12 @@ event_invitation(MESSENGER_Application *app, if (!invitation) return; + if (app->settings.delete_invitations_delay > 0) + GNUNET_CHAT_message_delete(msg, GNUNET_TIME_relative_multiply( + GNUNET_TIME_relative_get_second_(), + app->settings.delete_invitations_delay + )); + const int sent = GNUNET_CHAT_message_is_sent(msg); if ((GNUNET_YES != sent) && (app->settings.send_read_receipts)) @@ -542,6 +573,14 @@ event_receive_message(MESSENGER_Application *app, if (!handle) return; + const int sent = GNUNET_CHAT_message_is_sent(msg); + + if ((sent) && (app->settings.auto_delete_delay > 0)) + GNUNET_CHAT_message_delete(msg, GNUNET_TIME_relative_multiply( + GNUNET_TIME_relative_get_second_(), + app->settings.auto_delete_delay + )); + const gboolean whispering = ( GNUNET_CHAT_KIND_WHISPER == GNUNET_CHAT_message_get_kind(msg) ); @@ -549,7 +588,6 @@ event_receive_message(MESSENGER_Application *app, if ((whispering) && (!(app->settings.show_whispering))) return; - const int sent = GNUNET_CHAT_message_is_sent(msg); const gchar *text = GNUNET_CHAT_message_get_text(msg); if (whispering) @@ -573,6 +611,12 @@ event_receive_message(MESSENGER_Application *app, { file_create_info(file); file_add_ui_message_to_info(file, message); + + if (app->settings.delete_files_delay > 0) + GNUNET_CHAT_message_delete(msg, GNUNET_TIME_relative_multiply( + GNUNET_TIME_relative_get_second_(), + app->settings.delete_files_delay + )); } ui_message_update(message, app, msg); diff --git a/src/ui/settings.c b/src/ui/settings.c @@ -45,12 +45,49 @@ handle_inverted_switch_state(GtkSwitch *widget, } static void +handle_general_combo_box_change(GtkComboBox *widget, + gpointer user_data) +{ + gulong *delay = (gulong*) user_data; + GtkTreeModel *model = gtk_combo_box_get_model(widget); + + GtkTreeIter iter; + if (gtk_combo_box_get_active_iter(widget, &iter)) + gtk_tree_model_get(model, &iter, 1, delay, -1); +} + +static void handle_dialog_destroy(UNUSED GtkWidget *window, gpointer user_data) { ui_settings_dialog_cleanup((UI_SETTINGS_Handle*) user_data); } +static void +_set_combobox_to_active_by_delay(GtkComboBox *widget, + gulong delay) +{ + GtkTreeModel *model = gtk_combo_box_get_model(widget); + + GtkTreeIter iter; + if (!gtk_tree_model_get_iter_first(model, &iter)) + return; + + gulong value; + + do { + gtk_tree_model_get(model, &iter, 1, &value, -1); + + if (value == delay) + goto set_active; + + } while (gtk_tree_model_iter_next(model, &iter)); + + return; +set_active: + gtk_combo_box_set_active_iter(widget, &iter); +} + void ui_settings_dialog_init(MESSENGER_Application *app, UI_SETTINGS_Handle *handle) @@ -120,6 +157,18 @@ ui_settings_dialog_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "auto_delete_combo_box") ); + _set_combobox_to_active_by_delay( + handle->auto_delete_combo_box, + app->settings.auto_delete_delay + ); + + g_signal_connect( + handle->auto_delete_combo_box, + "changed", + G_CALLBACK(handle_general_combo_box_change), + &(app->settings.auto_delete_delay) + ); + handle->auto_accept_invitations_switch = GTK_SWITCH( gtk_builder_get_object(handle->builder, "auto_accept_invitations_switch") ); @@ -140,6 +189,18 @@ ui_settings_dialog_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "delete_invitations_combo_box") ); + _set_combobox_to_active_by_delay( + handle->delete_invitations_combo_box, + app->settings.delete_invitations_delay + ); + + g_signal_connect( + handle->delete_invitations_combo_box, + "changed", + G_CALLBACK(handle_general_combo_box_change), + &(app->settings.delete_invitations_delay) + ); + handle->delete_invitations_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "delete_invitations_button") ); @@ -168,6 +229,18 @@ ui_settings_dialog_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "delete_files_combo_box") ); + _set_combobox_to_active_by_delay( + handle->delete_files_combo_box, + app->settings.delete_files_delay + ); + + g_signal_connect( + handle->delete_files_combo_box, + "changed", + G_CALLBACK(handle_general_combo_box_change), + &(app->settings.delete_files_delay) + ); + handle->delete_files_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "delete_files_button") ); @@ -176,6 +249,18 @@ ui_settings_dialog_init(MESSENGER_Application *app, gtk_builder_get_object(handle->builder, "leave_chats_combo_box") ); + _set_combobox_to_active_by_delay( + handle->leave_chats_combo_box, + app->settings.leave_chats_delay + ); + + g_signal_connect( + handle->leave_chats_combo_box, + "changed", + G_CALLBACK(handle_general_combo_box_change), + &(app->settings.leave_chats_delay) + ); + handle->leave_chats_button = GTK_BUTTON( gtk_builder_get_object(handle->builder, "leave_chats_button") );