Change help menu item from Gtk default to Gnome (apparent) standard
[nautilus-actions.git] / src / nact / nact-confirm-logout.c
bloba811f9752d5a49caa420a42f2ad0a5ddc4f889d8
1 /*
2 * Nautilus Actions
3 * A Nautilus extension which offers configurable context menu actions.
5 * Copyright (C) 2005 The GNOME Foundation
6 * Copyright (C) 2006, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
7 * Copyright (C) 2009, 2010 Pierre Wieser and others (see AUTHORS)
9 * This Program 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.
14 * This Program 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
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public
20 * License along with this Library; see the file COPYING. If not,
21 * write to the Free Software Foundation, Inc., 59 Temple Place,
22 * Suite 330, Boston, MA 02111-1307, USA.
24 * Authors:
25 * Frederic Ruaudel <grumz@grumz.net>
26 * Rodrigo Moya <rodrigo@gnome-db.org>
27 * Pierre Wieser <pwieser@trychlos.org>
28 * ... and many others (see AUTHORS)
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
35 #include "nact-confirm-logout.h"
36 #include "nact-main-menubar-file.h"
38 /* private class data
40 struct NactConfirmLogoutClassPrivate {
41 void *empty; /* so that gcc -pedantic is happy */
44 /* private instance data
46 struct NactConfirmLogoutPrivate {
47 gboolean dispose_has_run;
48 gboolean willing_to_quit;
51 enum {
52 BTN_QUIT_WITHOUT_SAVING = 1,
53 BTN_CANCEL,
54 BTN_SAVE_AND_QUIT
57 static BaseDialogClass *st_parent_class = NULL;
59 static GType register_type( void );
60 static void class_init( NactConfirmLogoutClass *klass );
61 static void instance_init( GTypeInstance *instance, gpointer klass );
62 static void instance_dispose( GObject *dialog );
63 static void instance_finalize( GObject *dialog );
65 static NactConfirmLogout *confirm_logout_new( BaseWindow *parent );
67 static gchar *base_get_dialog_name( const BaseWindow *window );
68 static void on_base_initial_load_dialog( NactConfirmLogout *editor, gpointer user_data );
69 static void on_base_runtime_init_dialog( NactConfirmLogout *editor, gpointer user_data );
70 static void on_base_all_widgets_showed( NactConfirmLogout *editor, gpointer user_data );
71 static void on_quit_without_saving_clicked( GtkButton *button, NactConfirmLogout *editor );
72 static void on_cancel_clicked( GtkButton *button, NactConfirmLogout *editor );
73 static void on_save_and_quit_clicked( GtkButton *button, NactConfirmLogout *editor );
75 static gboolean base_dialog_response( GtkDialog *dialog, gint code, BaseWindow *window );
76 static void close_dialog( NactConfirmLogout *editor, gboolean willing_to );
78 GType
79 nact_confirm_logout_get_type( void )
81 static GType dialog_type = 0;
83 if( !dialog_type ){
84 dialog_type = register_type();
87 return( dialog_type );
90 static GType
91 register_type( void )
93 static const gchar *thisfn = "nact_confirm_logout_register_type";
94 GType type;
96 static GTypeInfo info = {
97 sizeof( NactConfirmLogoutClass ),
98 ( GBaseInitFunc ) NULL,
99 ( GBaseFinalizeFunc ) NULL,
100 ( GClassInitFunc ) class_init,
101 NULL,
102 NULL,
103 sizeof( NactConfirmLogout ),
105 ( GInstanceInitFunc ) instance_init
108 g_debug( "%s", thisfn );
110 type = g_type_register_static( BASE_DIALOG_TYPE, "NactConfirmLogout", &info, 0 );
112 return( type );
115 static void
116 class_init( NactConfirmLogoutClass *klass )
118 static const gchar *thisfn = "nact_confirm_logout_class_init";
119 GObjectClass *object_class;
120 BaseWindowClass *base_class;
122 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
124 st_parent_class = g_type_class_peek_parent( klass );
126 object_class = G_OBJECT_CLASS( klass );
127 object_class->dispose = instance_dispose;
128 object_class->finalize = instance_finalize;
130 klass->private = g_new0( NactConfirmLogoutClassPrivate, 1 );
132 base_class = BASE_WINDOW_CLASS( klass );
133 base_class->dialog_response = base_dialog_response;
134 base_class->get_toplevel_name = base_get_dialog_name;
137 static void
138 instance_init( GTypeInstance *instance, gpointer klass )
140 static const gchar *thisfn = "nact_confirm_logout_instance_init";
141 NactConfirmLogout *self;
143 g_debug( "%s: instance=%p (%s), klass=%p",
144 thisfn, ( void * ) instance, G_OBJECT_TYPE_NAME( instance ), ( void * ) klass );
145 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( instance ));
146 self = NACT_CONFIRM_LOGOUT( instance );
148 self->private = g_new0( NactConfirmLogoutPrivate, 1 );
150 base_window_signal_connect(
151 BASE_WINDOW( instance ),
152 G_OBJECT( instance ),
153 BASE_WINDOW_SIGNAL_INITIAL_LOAD,
154 G_CALLBACK( on_base_initial_load_dialog ));
156 base_window_signal_connect(
157 BASE_WINDOW( instance ),
158 G_OBJECT( instance ),
159 BASE_WINDOW_SIGNAL_RUNTIME_INIT,
160 G_CALLBACK( on_base_runtime_init_dialog ));
162 base_window_signal_connect(
163 BASE_WINDOW( instance ),
164 G_OBJECT( instance ),
165 BASE_WINDOW_SIGNAL_ALL_WIDGETS_SHOWED,
166 G_CALLBACK( on_base_all_widgets_showed));
168 self->private->dispose_has_run = FALSE;
171 static void
172 instance_dispose( GObject *dialog )
174 static const gchar *thisfn = "nact_confirm_logout_instance_dispose";
175 NactConfirmLogout *self;
177 g_debug( "%s: dialog=%p (%s)", thisfn, ( void * ) dialog, G_OBJECT_TYPE_NAME( dialog ));
178 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( dialog ));
179 self = NACT_CONFIRM_LOGOUT( dialog );
181 if( !self->private->dispose_has_run ){
183 self->private->dispose_has_run = TRUE;
185 /* chain up to the parent class */
186 if( G_OBJECT_CLASS( st_parent_class )->dispose ){
187 G_OBJECT_CLASS( st_parent_class )->dispose( dialog );
192 static void
193 instance_finalize( GObject *dialog )
195 static const gchar *thisfn = "nact_confirm_logout_instance_finalize";
196 NactConfirmLogout *self;
198 g_debug( "%s: dialog=%p", thisfn, ( void * ) dialog );
199 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( dialog ));
200 self = NACT_CONFIRM_LOGOUT( dialog );
202 g_free( self->private );
204 /* chain call to parent class */
205 if( G_OBJECT_CLASS( st_parent_class )->finalize ){
206 G_OBJECT_CLASS( st_parent_class )->finalize( dialog );
211 * Returns a newly allocated NactConfirmLogout object.
213 * @parent: the BaseWindow parent of this dialog (usually, the main
214 * toplevel window of the application).
216 static NactConfirmLogout *
217 confirm_logout_new( BaseWindow *parent )
219 return( g_object_new( NACT_CONFIRM_LOGOUT_TYPE, BASE_WINDOW_PROP_PARENT, parent, NULL ));
223 * nact_confirm_logout_run:
224 * @parent: the NactMainWindow parent of this dialog
225 * (usually the NactMainWindow).
227 * Initializes and runs the dialog.
229 gboolean
230 nact_confirm_logout_run( NactMainWindow *parent )
232 static const gchar *thisfn = "nact_confirm_logout_run";
233 NactConfirmLogout *editor;
234 gboolean willing_to;
236 g_debug( "%s: parent=%p", thisfn, ( void * ) parent );
237 g_return_val_if_fail( BASE_IS_WINDOW( parent ), TRUE );
239 editor = confirm_logout_new( BASE_WINDOW( parent ));
241 base_window_run( BASE_WINDOW( editor ));
242 willing_to = editor->private->willing_to_quit;
243 g_object_unref( editor );
245 return( willing_to );
248 static gchar *
249 base_get_dialog_name( const BaseWindow *window )
251 return( g_strdup( "ConfirmLogoutDialog" ));
254 static void
255 on_base_initial_load_dialog( NactConfirmLogout *editor, gpointer user_data )
257 static const gchar *thisfn = "nact_confirm_logout_on_initial_load_dialog";
259 g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
260 g_return_if_fail( NACT_IS_CONFIRM_LOGOUT( editor ));
263 static void
264 on_base_runtime_init_dialog( NactConfirmLogout *editor, gpointer user_data )
266 static const gchar *thisfn = "nact_confirm_logout_on_runtime_init_dialog";
268 g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
270 base_window_signal_connect_by_name(
271 BASE_WINDOW( editor ),
272 "QuitNoSaveButton",
273 "clicked",
274 G_CALLBACK( on_quit_without_saving_clicked ));
276 base_window_signal_connect_by_name(
277 BASE_WINDOW( editor ),
278 "CancelQuitButton",
279 "clicked",
280 G_CALLBACK( on_cancel_clicked ));
282 base_window_signal_connect_by_name(
283 BASE_WINDOW( editor ),
284 "SaveQuitButton",
285 "clicked",
286 G_CALLBACK( on_save_and_quit_clicked ));
289 static void
290 on_base_all_widgets_showed( NactConfirmLogout *editor, gpointer user_data )
292 static const gchar *thisfn = "nact_confirm_logout_on_all_widgets_showed";
294 g_debug( "%s: editor=%p, user_data=%p", thisfn, ( void * ) editor, ( void * ) user_data );
297 static void
298 on_quit_without_saving_clicked( GtkButton *button, NactConfirmLogout *editor )
300 static const gchar *thisfn = "nact_confirm_logout_on_quit_without_saving_clicked";
302 g_debug( "%s: button=%p, editor=%p", thisfn, ( void * ) button, ( void * ) editor );
304 close_dialog( editor, TRUE );
307 static void
308 on_cancel_clicked( GtkButton *button, NactConfirmLogout *editor )
310 static const gchar *thisfn = "nact_confirm_logout_on_cancel_clicked";
312 g_debug( "%s: button=%p, editor=%p", thisfn, ( void * ) button, ( void * ) editor );
314 close_dialog( editor, FALSE );
317 static void
318 on_save_and_quit_clicked( GtkButton *button, NactConfirmLogout *editor )
320 static const gchar *thisfn = "nact_confirm_logout_on_cancel_clicked";
321 NactMainWindow *main_window;
323 g_debug( "%s: button=%p, editor=%p", thisfn, ( void * ) button, ( void * ) editor );
325 main_window = NACT_MAIN_WINDOW( base_window_get_parent( BASE_WINDOW( editor )));
326 nact_main_menubar_file_save_items( main_window );
328 close_dialog( editor, TRUE );
331 static gboolean
332 base_dialog_response( GtkDialog *dialog, gint code, BaseWindow *window )
334 static const gchar *thisfn = "nact_confirm_logout_on_dialog_response";
335 NactConfirmLogout *editor;
337 g_debug( "%s: dialog=%p, code=%d, window=%p", thisfn, ( void * ) dialog, code, ( void * ) window );
338 g_assert( NACT_IS_CONFIRM_LOGOUT( window ));
339 editor = NACT_CONFIRM_LOGOUT( window );
341 switch( code ){
342 case GTK_RESPONSE_CLOSE:
344 return( TRUE );
345 break;
348 return( FALSE );
351 static void
352 close_dialog( NactConfirmLogout *editor, gboolean willing_to )
354 static const gchar *thisfn = "nact_confirm_logout_close_dialog";
355 GtkWindow *toplevel;
357 g_debug( "%s: editor=%p, willing_to=%s", thisfn, ( void * ) editor, willing_to ? "True":"False" );
359 editor->private->willing_to_quit = willing_to;
361 toplevel = base_window_get_toplevel( BASE_WINDOW( editor ));
362 gtk_dialog_response( GTK_DIALOG( toplevel ), GTK_RESPONSE_CLOSE );