1 /*
2 * Nautilus-Actions
3 * A Nautilus extension which offers configurable context menu actions.
4 *
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006-2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009-2014 Pierre Wieser and others (see AUTHORS)
8 *
9 * Nautilus-Actions is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * Nautilus-Actions is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with Nautilus-Actions; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
22 *
23 * Authors:
24 * Frederic Ruaudel <grumz@grumz.net>
25 * Rodrigo Moya <rodrigo@gnome-db.org>
26 * Pierre Wieser <pwieser@trychlos.org>
27 * ... and many others (see AUTHORS)
28 */
29
30 #ifdef HAVE_CONFIG_H
31 #include <config.h>
32 #endif
33
34 #include "nact-confirm-logout.h"
35 #include "nact-menubar.h"
36
37 /* private class data
38 */
39 struct _NactConfirmLogoutClassPrivate {
40 void *empty; /* so that gcc -pedantic is happy */
41 };
42
43 /* private instance data
44 */
45 struct _NactConfirmLogoutPrivate {
46 gboolean dispose_has_run;
47 gboolean willing_to_quit;
48 };
49
50 enum {
51 BTN_QUIT_WITHOUT_SAVING = 1,
52 BTN_CANCEL,
53 BTN_SAVE_AND_QUIT
54 };
55
56 static const gchar *st_toplevel_name = "ConfirmLogoutDialog";
57 static const gchar *st_wsp_name = NA_IPREFS_CONFIRM_LOGOUT_WSP;
58
59 static BaseDialogClass *st_parent_class = NULL;
60
61 static GType register_type( void );
62 static void class_init( NactConfirmLogoutClass *klass );
63 static void instance_init( GTypeInstance *instance, gpointer klass );
64 static void instance_constructed( GObject *dialog );
65 static void instance_dispose( GObject *dialog );
66 static void instance_finalize( GObject *dialog );
67
68 static void on_base_initialize_window( NactConfirmLogout *editor, gpointer user_data );
69 static void on_quit_without_saving_clicked( GtkButton *button, NactConfirmLogout *editor );
70 static void on_cancel_clicked( GtkButton *button, NactConfirmLogout *editor );
71 static void on_save_and_quit_clicked( GtkButton *button, NactConfirmLogout *editor );
72 static void close_dialog( NactConfirmLogout *editor, gboolean willing_to );
73
74 GType
nact_confirm_logout_get_type(void)75 nact_confirm_logout_get_type( void )
76 {
77 static GType dialog_type = 0;
78
79 if( !dialog_type ){
80 dialog_type = register_type();
81 }
82
83 return( dialog_type );
84 }
85
86 static GType
register_type(void)87 register_type( void )
88 {
89 static const gchar *thisfn = "nact_confirm_logout_register_type";
90 GType type;
91
92 static GTypeInfo info = {
93 sizeof( NactConfirmLogoutClass ),
94 ( GBaseInitFunc ) NULL,
95 ( GBaseFinalizeFunc ) NULL,
96 ( GClassInitFunc ) class_init,
97 NULL,
98 NULL,
99 sizeof( NactConfirmLogout ),
100 0,
101 ( GInstanceInitFunc ) instance_init
102 };
103
104 g_debug( "%s", thisfn );
105
106 type = g_type_register_static( BASE_TYPE_DIALOG, "NactConfirmLogout", &info, 0 );
107
108 return( type );
109 }
110
111 static void
class_init(NactConfirmLogoutClass * klass)112 class_init( NactConfirmLogoutClass *klass )
113 {
114 static const gchar *thisfn = "nact_confirm_logout_class_init";
115 GObjectClass *object_class;
116
117 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
118
119 st_parent_class = g_type_class_peek_parent( klass );
120
121 object_class = G_OBJECT_CLASS( klass );
122 object_class->constructed = instance_constructed;
123 object_class->dispose = instance_dispose;
124 object_class->finalize = instance_finalize;
125
126 klass->private = g_new0( NactConfirmLogoutClassPrivate, 1 );
127 }
128
129 static void
instance_init(GTypeInstance * instance,gpointer klass)130 instance_init( GTypeInstance *instance, gpointer klass )
131 {
132 static const gchar *thisfn = "nact_confirm_logout_instance_init";
133 NactConfirmLogout *self;
134
135 g_debug( "%s: instance=%p (%s), klass=%p",
136 thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
137 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( instance ));
138 self = NACT_CONFIRM_LOGOUT( instance );
139
140 self->private = g_new0( NactConfirmLogoutPrivate, 1 );
141
142 self->private->dispose_has_run = FALSE;
143 }
144
145 static void
instance_constructed(GObject * dialog)146 instance_constructed( GObject *dialog )
147 {
148 static const gchar *thisfn = "nact_confirm_logout_instance_constructed";
149 NactConfirmLogoutPrivate *priv;
150
151 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( dialog ));
152
153 priv = NACT_CONFIRM_LOGOUT( dialog )->private;
154
155 if( !priv->dispose_has_run ){
156
157 /* chain up to the parent class */
158 if( G_OBJECT_CLASS( st_parent_class )->constructed ){
159 G_OBJECT_CLASS( st_parent_class )->constructed( dialog );
160 }
161
162 g_debug( "%s: dialog=%p (%s)", thisfn, ( void * ) dialog, G_OBJECT_TYPE_NAME( dialog ));
163
164 base_window_signal_connect(
165 BASE_WINDOW( dialog ),
166 G_OBJECT( dialog ),
167 BASE_SIGNAL_INITIALIZE_WINDOW,
168 G_CALLBACK( on_base_initialize_window ));
169 }
170 }
171
172 static void
instance_dispose(GObject * dialog)173 instance_dispose( GObject *dialog )
174 {
175 static const gchar *thisfn = "nact_confirm_logout_instance_dispose";
176 NactConfirmLogout *self;
177
178 g_debug( "%s: dialog=%p (%s)", thisfn, ( void * ) dialog, G_OBJECT_TYPE_NAME( dialog ));
179 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( dialog ));
180 self = NACT_CONFIRM_LOGOUT( dialog );
181
182 if( !self->private->dispose_has_run ){
183
184 self->private->dispose_has_run = TRUE;
185
186 /* chain up to the parent class */
187 if( G_OBJECT_CLASS( st_parent_class )->dispose ){
188 G_OBJECT_CLASS( st_parent_class )->dispose( dialog );
189 }
190 }
191 }
192
193 static void
instance_finalize(GObject * dialog)194 instance_finalize( GObject *dialog )
195 {
196 static const gchar *thisfn = "nact_confirm_logout_instance_finalize";
197 NactConfirmLogout *self;
198
199 g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );
200 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( dialog ));
201 self = NACT_CONFIRM_LOGOUT( dialog );
202
203 g_free( self->private );
204
205 /* chain call to parent class */
206 if( G_OBJECT_CLASS( st_parent_class )->finalize ){
207 G_OBJECT_CLASS( st_parent_class )->finalize( dialog );
208 }
209 }
210
211 /**
212 * nact_confirm_logout_run:
213 * @parent: the NactMainWindow parent of this dialog
214 * (usually the NactMainWindow).
215 *
216 * Initializes and runs the dialog.
217 */
218 gboolean
nact_confirm_logout_run(NactMainWindow * parent)219 nact_confirm_logout_run( NactMainWindow *parent )
220 {
221 static const gchar *thisfn = "nact_confirm_logout_run";
222 NactConfirmLogout *dialog;
223 gboolean willing_to;
224
225 g_return_val_if_fail( NACT_IS_MAIN_WINDOW( parent ), TRUE );
226
227 g_debug( "%s: parent=%p", thisfn, ( void * ) parent );
228
229 dialog = g_object_new( NACT_TYPE_CONFIRM_LOGOUT,
230 BASE_PROP_PARENT, parent,
231 BASE_PROP_TOPLEVEL_NAME, st_toplevel_name,
232 BASE_PROP_WSP_NAME, st_wsp_name,
233 NULL );
234
235 base_window_run( BASE_WINDOW( dialog ));
236
237 willing_to = dialog->private->willing_to_quit;
238
239 g_object_unref( dialog );
240
241 return( willing_to );
242 }
243
244 static void
on_base_initialize_window(NactConfirmLogout * dialog,gpointer user_data)245 on_base_initialize_window( NactConfirmLogout *dialog, gpointer user_data )
246 {
247 static const gchar *thisfn = "nact_confirm_logout_on_base_initialize_window";
248
249 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( dialog ));
250
251 if( !dialog->private->dispose_has_run ){
252
253 g_debug( "%s: dialog=%p, user_data=%p", thisfn, ( void * ) dialog, ( void * ) user_data );
254
255 base_window_signal_connect_by_name(
256 BASE_WINDOW( dialog ),
257 "QuitNoSaveButton",
258 "clicked",
259 G_CALLBACK( on_quit_without_saving_clicked ));
260
261 base_window_signal_connect_by_name(
262 BASE_WINDOW( dialog ),
263 "CancelQuitButton",
264 "clicked",
265 G_CALLBACK( on_cancel_clicked ));
266
267 base_window_signal_connect_by_name(
268 BASE_WINDOW( dialog ),
269 "SaveQuitButton",
270 "clicked",
271 G_CALLBACK( on_save_and_quit_clicked ));
272 }
273 }
274
275 static void
on_quit_without_saving_clicked(GtkButton * button,NactConfirmLogout * editor)276 on_quit_without_saving_clicked( GtkButton *button, NactConfirmLogout *editor )
277 {
278 static const gchar *thisfn = "nact_confirm_logout_on_quit_without_saving_clicked";
279
280 g_debug( "%s: button=%p, editor=%p", thisfn, ( void * ) button, ( void * ) editor );
281
282 close_dialog( editor, TRUE );
283 }
284
285 static void
on_cancel_clicked(GtkButton * button,NactConfirmLogout * editor)286 on_cancel_clicked( GtkButton *button, NactConfirmLogout *editor )
287 {
288 static const gchar *thisfn = "nact_confirm_logout_on_cancel_clicked";
289
290 g_debug( "%s: button=%p, editor=%p", thisfn, ( void * ) button, ( void * ) editor );
291
292 close_dialog( editor, FALSE );
293 }
294
295 static void
on_save_and_quit_clicked(GtkButton * button,NactConfirmLogout * editor)296 on_save_and_quit_clicked( GtkButton *button, NactConfirmLogout *editor )
297 {
298 static const gchar *thisfn = "nact_confirm_logout_on_cancel_clicked";
299 NactMainWindow *main_window;
300
301 g_debug( "%s: button=%p, editor=%p", thisfn, ( void * ) button, ( void * ) editor );
302
303 main_window = NACT_MAIN_WINDOW( base_window_get_parent( BASE_WINDOW( editor )));
304 nact_menubar_save_items( BASE_WINDOW( main_window ));
305
306 close_dialog( editor, TRUE );
307 }
308
309 static void
close_dialog(NactConfirmLogout * editor,gboolean willing_to)310 close_dialog( NactConfirmLogout *editor, gboolean willing_to )
311 {
312 static const gchar *thisfn = "nact_confirm_logout_close_dialog";
313 GtkWindow *toplevel;
314
315 g_debug( "%s: editor=%p, willing_to=%s", thisfn, ( void * ) editor, willing_to ? "True":"False" );
316
317 editor->private->willing_to_quit = willing_to;
318
319 toplevel = base_window_get_gtk_toplevel( BASE_WINDOW( editor ));
320 gtk_dialog_response( GTK_DIALOG( toplevel ), GTK_RESPONSE_CLOSE );
321 }
322