aboutsummaryrefslogtreecommitdiff
path: root/src/ui/delete_messages.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/delete_messages.c')
-rw-r--r--src/ui/delete_messages.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/src/ui/delete_messages.c b/src/ui/delete_messages.c
new file mode 100644
index 0000000..df75484
--- /dev/null
+++ b/src/ui/delete_messages.c
@@ -0,0 +1,152 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2022 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
29static void
30handle_cancel_button_click(UNUSED GtkButton *button,
31 gpointer user_data)
32{
33 GtkDialog *dialog = GTK_DIALOG(user_data);
34 gtk_window_close(GTK_WINDOW(dialog));
35}
36
37static void
38handle_confirm_button_click(UNUSED GtkButton *button,
39 gpointer user_data)
40{
41 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
42
43 app->settings.hide_delete_dialog = gtk_toggle_button_get_active(
44 GTK_TOGGLE_BUTTON(app->ui.delete_messages.hide_checkbox)
45 );
46
47 GtkTreeModel *model = gtk_combo_box_get_model(
48 app->ui.delete_messages.delay_combobox
49 );
50
51 gulong delay = 0;
52
53 GtkTreeIter iter;
54 if (gtk_combo_box_get_active_iter(app->ui.delete_messages.delay_combobox,
55 &iter))
56 gtk_tree_model_get(model, &iter, 1, &delay, -1);
57
58 if (app->ui.delete_messages.callback)
59 app->ui.delete_messages.callback(
60 app->ui.bindings,
61 app->ui.delete_messages.selected,
62 delay
63 );
64
65 gtk_window_close(GTK_WINDOW(app->ui.delete_messages.dialog));
66}
67
68static void
69handle_dialog_destroy(UNUSED GtkWidget *window,
70 gpointer user_data)
71{
72 MESSENGER_Application *app = (MESSENGER_Application*) user_data;
73
74 ui_delete_messages_dialog_cleanup(&(app->ui.delete_messages));
75}
76
77void
78ui_delete_messages_dialog_init(MESSENGER_Application *app,
79 UI_DELETE_MESSAGES_Handle *handle)
80{
81 handle->selected = NULL;
82 handle->callback = NULL;
83
84 handle->builder = gtk_builder_new_from_resource(
85 application_get_resource_path(app, "ui/delete_messages.ui")
86 );
87
88 handle->dialog = GTK_DIALOG(
89 gtk_builder_get_object(handle->builder, "delete_messages_dialog")
90 );
91
92 gtk_window_set_transient_for(
93 GTK_WINDOW(handle->dialog),
94 GTK_WINDOW(app->ui.messenger.main_window)
95 );
96
97 handle->delay_store = GTK_LIST_STORE(
98 gtk_builder_get_object(handle->builder, "delay_store")
99 );
100
101 handle->delay_combobox = GTK_COMBO_BOX(
102 gtk_builder_get_object(handle->builder, "delay_combobox")
103 );
104
105 handle->hide_checkbox = GTK_CHECK_BUTTON(
106 gtk_builder_get_object(handle->builder, "hide_checkbox")
107 );
108
109 handle->cancel_button = GTK_BUTTON(
110 gtk_builder_get_object(handle->builder, "cancel_button")
111 );
112
113 g_signal_connect(
114 handle->cancel_button,
115 "clicked",
116 G_CALLBACK(handle_cancel_button_click),
117 handle->dialog
118 );
119
120 handle->confirm_button = GTK_BUTTON(
121 gtk_builder_get_object(handle->builder, "confirm_button")
122 );
123
124 g_signal_connect(
125 handle->confirm_button,
126 "clicked",
127 G_CALLBACK(handle_confirm_button_click),
128 app
129 );
130
131 g_signal_connect(
132 handle->dialog,
133 "destroy",
134 G_CALLBACK(handle_dialog_destroy),
135 app
136 );
137}
138
139void
140ui_delete_messages_dialog_link(UI_DELETE_MESSAGES_Handle *handle,
141 UI_DELETE_MESSAGES_Callback callback,
142 GList *selected)
143{
144 handle->selected = selected;
145 handle->callback = callback;
146}
147
148void
149ui_delete_messages_dialog_cleanup(UI_DELETE_MESSAGES_Handle *handle)
150{
151 g_object_unref(handle->builder);
152}