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