1 /* confirm.c: Confirmation dialog box
2 Copyright (c) 2000-2015 Philip Kendall, Russell Marks
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 Author contact information:
19
20 E-mail: philip-fuse@shadowmagic.org.uk
21
22 */
23
24 #include <config.h>
25
26 #include <gdk/gdkkeysyms.h>
27 #include <gtk/gtk.h>
28
29 #include "compat.h"
30 #include "fuse.h"
31 #include "gtkcompat.h"
32 #include "gtkinternals.h"
33 #include "settings.h"
34 #include "ui/ui.h"
35
36 static void set_confirmed( GtkButton *button, gpointer user_data );
37 static void set_save( GtkButton *button, gpointer user_data );
38 static void set_dont_save( GtkButton *button, gpointer user_data );
39
40 int
gtkui_confirm(const char * string)41 gtkui_confirm( const char *string )
42 {
43 GtkWidget *dialog, *label, *content_area;
44 int confirm;
45
46 /* Return value isn't an error code, but signifies whether to undertake
47 the action */
48 if( !settings_current.confirm_actions ) return 1;
49
50 fuse_emulation_pause();
51
52 confirm = 0;
53
54 dialog = gtkstock_dialog_new( "Fuse - Confirm", NULL );
55
56 label = gtk_label_new( string );
57 content_area = gtk_dialog_get_content_area( GTK_DIALOG( dialog ) );
58 gtk_box_pack_start( GTK_BOX( content_area ), label, TRUE, TRUE, 5 );
59
60 gtkstock_create_ok_cancel( dialog, NULL, G_CALLBACK( set_confirmed ),
61 &confirm, DEFAULT_DESTROY, DEFAULT_DESTROY );
62
63 gtk_dialog_set_default_response( GTK_DIALOG( dialog ), GTK_RESPONSE_CANCEL );
64
65 gtk_widget_show_all( dialog );
66 gtk_main();
67
68 fuse_emulation_unpause();
69
70 return confirm;
71 }
72
73 static void
set_confirmed(GtkButton * button GCC_UNUSED,gpointer user_data)74 set_confirmed( GtkButton *button GCC_UNUSED, gpointer user_data )
75 {
76 int *ptr = user_data;
77
78 *ptr = 1;
79 }
80
81 ui_confirm_save_t
ui_confirm_save_specific(const char * message)82 ui_confirm_save_specific( const char *message )
83 {
84 GtkWidget *dialog, *label, *content_area;
85 ui_confirm_save_t confirm;
86
87 if( !settings_current.confirm_actions ) return UI_CONFIRM_SAVE_DONTSAVE;
88
89 fuse_emulation_pause();
90
91 confirm = UI_CONFIRM_SAVE_CANCEL;
92
93 dialog = gtkstock_dialog_new( "Fuse - Confirm", NULL );
94 content_area = gtk_dialog_get_content_area( GTK_DIALOG( dialog ) );
95
96 label = gtk_label_new( message );
97 gtk_box_pack_start( GTK_BOX( content_area ), label, TRUE, TRUE, 5 );
98
99 {
100 static gtkstock_button btn[] = {
101 { "_No", G_CALLBACK( set_dont_save ), NULL, DEFAULT_DESTROY, 0, 0, 0, 0, GTK_RESPONSE_NO },
102 { "_Cancel", NULL, NULL, DEFAULT_DESTROY, GDK_KEY_Escape, 0, 0, 0, GTK_RESPONSE_CANCEL },
103 { "_Save", G_CALLBACK( set_save ), NULL, DEFAULT_DESTROY, 0, 0, 0, 0, GTK_RESPONSE_YES }
104 };
105 btn[0].actiondata = btn[2].actiondata = &confirm;
106 gtkstock_create_buttons( dialog, NULL, btn, ARRAY_SIZE( btn ) );
107 }
108
109 gtk_dialog_set_default_response( GTK_DIALOG( dialog ), GTK_RESPONSE_CANCEL );
110
111 gtk_widget_show_all( dialog );
112 gtk_main();
113
114 fuse_emulation_unpause();
115
116 return confirm;
117 }
118
119 int
ui_query(const char * message)120 ui_query( const char *message )
121 {
122 return gtkui_confirm( message );
123 }
124
125 static void
set_save(GtkButton * button GCC_UNUSED,gpointer user_data)126 set_save( GtkButton *button GCC_UNUSED, gpointer user_data )
127 {
128 ui_confirm_save_t *ptr = user_data;
129
130 *ptr = UI_CONFIRM_SAVE_SAVE;
131 }
132
133 static void
set_dont_save(GtkButton * button GCC_UNUSED,gpointer user_data)134 set_dont_save( GtkButton *button GCC_UNUSED, gpointer user_data )
135 {
136 ui_confirm_save_t *ptr = user_data;
137
138 *ptr = UI_CONFIRM_SAVE_DONTSAVE;
139 }
140