delete_messages.c (4231B)
1 /* 2 This file is part of GNUnet. 3 Copyright (C) 2022--2024 GNUnet e.V. 4 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 7 by the Free Software Foundation, either version 3 of the License, 8 or (at your option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 /* 21 * @author Tobias Frisch 22 * @file ui/delete_messages.c 23 */ 24 25 #include "delete_messages.h" 26 27 #include "../application.h" 28 #include "../ui.h" 29 30 static void 31 handle_cancel_button_click(UNUSED GtkButton *button, 32 gpointer user_data) 33 { 34 g_assert(user_data); 35 36 GtkDialog *dialog = GTK_DIALOG(user_data); 37 gtk_window_close(GTK_WINDOW(dialog)); 38 } 39 40 static void 41 handle_confirm_button_click(UNUSED GtkButton *button, 42 gpointer user_data) 43 { 44 g_assert(user_data); 45 46 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 47 48 app->settings.hide_delete_dialog = gtk_toggle_button_get_active( 49 GTK_TOGGLE_BUTTON(app->ui.delete_messages.hide_checkbox) 50 ); 51 52 GtkTreeModel *model = gtk_combo_box_get_model( 53 app->ui.delete_messages.delay_combobox 54 ); 55 56 gulong delay = 0; 57 58 GtkTreeIter iter; 59 if (gtk_combo_box_get_active_iter(app->ui.delete_messages.delay_combobox, &iter)) 60 gtk_tree_model_get(model, &iter, 1, &delay, -1); 61 62 if (app->ui.delete_messages.callback) 63 app->ui.delete_messages.callback( 64 app, 65 app->ui.delete_messages.selected, 66 delay 67 ); 68 69 gtk_window_close(GTK_WINDOW(app->ui.delete_messages.dialog)); 70 } 71 72 static void 73 handle_dialog_destroy(UNUSED GtkWidget *window, 74 gpointer user_data) 75 { 76 g_assert(user_data); 77 78 MESSENGER_Application *app = (MESSENGER_Application*) user_data; 79 80 ui_delete_messages_dialog_cleanup(&(app->ui.delete_messages)); 81 } 82 83 void 84 ui_delete_messages_dialog_init(MESSENGER_Application *app, 85 UI_DELETE_MESSAGES_Handle *handle) 86 { 87 g_assert((app) && (handle)); 88 89 handle->selected = NULL; 90 handle->callback = NULL; 91 92 handle->builder = ui_builder_from_resource( 93 application_get_resource_path(app, "ui/delete_messages.ui") 94 ); 95 96 handle->dialog = GTK_DIALOG( 97 gtk_builder_get_object(handle->builder, "delete_messages_dialog") 98 ); 99 100 gtk_window_set_transient_for( 101 GTK_WINDOW(handle->dialog), 102 GTK_WINDOW(app->ui.messenger.main_window) 103 ); 104 105 handle->delay_store = GTK_LIST_STORE( 106 gtk_builder_get_object(handle->builder, "delay_store") 107 ); 108 109 handle->delay_combobox = GTK_COMBO_BOX( 110 gtk_builder_get_object(handle->builder, "delay_combobox") 111 ); 112 113 handle->hide_checkbox = GTK_CHECK_BUTTON( 114 gtk_builder_get_object(handle->builder, "hide_checkbox") 115 ); 116 117 handle->cancel_button = GTK_BUTTON( 118 gtk_builder_get_object(handle->builder, "cancel_button") 119 ); 120 121 g_signal_connect( 122 handle->cancel_button, 123 "clicked", 124 G_CALLBACK(handle_cancel_button_click), 125 handle->dialog 126 ); 127 128 handle->confirm_button = GTK_BUTTON( 129 gtk_builder_get_object(handle->builder, "confirm_button") 130 ); 131 132 g_signal_connect( 133 handle->confirm_button, 134 "clicked", 135 G_CALLBACK(handle_confirm_button_click), 136 app 137 ); 138 139 g_signal_connect( 140 handle->dialog, 141 "destroy", 142 G_CALLBACK(handle_dialog_destroy), 143 app 144 ); 145 } 146 147 void 148 ui_delete_messages_dialog_link(UI_DELETE_MESSAGES_Handle *handle, 149 UI_DELETE_MESSAGES_Callback callback, 150 GList *selected) 151 { 152 g_assert((handle) && (callback)); 153 154 handle->selected = selected; 155 handle->callback = callback; 156 } 157 158 void 159 ui_delete_messages_dialog_cleanup(UI_DELETE_MESSAGES_Handle *handle) 160 { 161 g_assert(handle); 162 163 g_object_unref(handle->builder); 164 165 if (handle->selected) 166 g_list_free(handle->selected); 167 168 memset(handle, 0, sizeof(*handle)); 169 }