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, 2011 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.
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)
35 #include "base-dialog.h"
39 struct _BaseDialogClassPrivate
{
40 void *empty
; /* so that gcc -pedantic is happy */
43 /* private instance data
45 struct _BaseDialogPrivate
{
46 gboolean dispose_has_run
;
49 static BaseWindowClass
*st_parent_class
= NULL
;
51 static GType
register_type( void );
52 static void class_init( BaseDialogClass
*klass
);
53 static void instance_init( GTypeInstance
*instance
, gpointer klass
);
54 static void instance_dispose( GObject
*application
);
55 static void instance_finalize( GObject
*application
);
57 static int do_run( BaseWindow
*window
, GtkWindow
*toplevel
);
58 static gboolean
terminate_dialog( BaseDialog
*window
, GtkDialog
*toplevel
, int *code
);
59 static void dialog_cancel( BaseDialog
*window
);
60 static void dialog_ok( BaseDialog
*window
);
63 base_dialog_get_type( void )
65 static GType dialog_type
= 0;
68 dialog_type
= register_type();
71 return( dialog_type
);
77 static const gchar
*thisfn
= "base_dialog_register_type";
80 static GTypeInfo info
= {
81 sizeof( BaseDialogClass
),
82 ( GBaseInitFunc
) NULL
,
83 ( GBaseFinalizeFunc
) NULL
,
84 ( GClassInitFunc
) class_init
,
89 ( GInstanceInitFunc
) instance_init
92 g_debug( "%s", thisfn
);
94 type
= g_type_register_static( BASE_WINDOW_TYPE
, "BaseDialog", &info
, 0 );
100 class_init( BaseDialogClass
*klass
)
102 static const gchar
*thisfn
= "base_dialog_class_init";
103 GObjectClass
*object_class
;
104 BaseWindowClass
*base_class
;
106 g_debug( "%s: klass=%p", thisfn
, ( void * ) klass
);
108 st_parent_class
= g_type_class_peek_parent( klass
);
110 object_class
= G_OBJECT_CLASS( klass
);
111 object_class
->dispose
= instance_dispose
;
112 object_class
->finalize
= instance_finalize
;
114 base_class
= BASE_WINDOW_CLASS( klass
);
115 base_class
->run
= do_run
;
117 klass
->private = g_new0( BaseDialogClassPrivate
, 1 );
121 instance_init( GTypeInstance
*instance
, gpointer klass
)
123 static const gchar
*thisfn
= "base_dialog_instance_init";
126 g_return_if_fail( BASE_IS_DIALOG( instance
));
128 g_debug( "%s: instance=%p (%s), klass=%p",
129 thisfn
, ( void * ) instance
, G_OBJECT_TYPE_NAME( instance
), ( void * ) klass
);
131 self
= BASE_DIALOG( instance
);
133 self
->private = g_new0( BaseDialogPrivate
, 1 );
135 self
->private->dispose_has_run
= FALSE
;
139 instance_dispose( GObject
*window
)
141 static const gchar
*thisfn
= "base_dialog_instance_dispose";
144 g_return_if_fail( BASE_IS_DIALOG( window
));
146 self
= BASE_DIALOG( window
);
148 if( !self
->private->dispose_has_run
){
150 g_debug( "%s: window=%p (%s)", thisfn
, ( void * ) window
, G_OBJECT_TYPE_NAME( window
));
152 self
->private->dispose_has_run
= TRUE
;
154 /* chain up to the parent class */
155 if( G_OBJECT_CLASS( st_parent_class
)->dispose
){
156 G_OBJECT_CLASS( st_parent_class
)->dispose( window
);
162 instance_finalize( GObject
*window
)
164 static const gchar
*thisfn
= "base_dialog_instance_finalize";
167 g_return_if_fail( BASE_IS_DIALOG( window
));
169 g_debug( "%s: window=%p (%s)", thisfn
, ( void * ) window
, G_OBJECT_TYPE_NAME( window
));
171 self
= BASE_DIALOG( window
);
173 g_free( self
->private );
175 /* chain call to parent class */
176 if( G_OBJECT_CLASS( st_parent_class
)->finalize
){
177 G_OBJECT_CLASS( st_parent_class
)->finalize( window
);
182 * returns the response ID of the dialog box
185 do_run( BaseWindow
*window
, GtkWindow
*toplevel
)
187 static const gchar
*thisfn
= "base_dialog_do_run";
190 g_return_val_if_fail( BASE_IS_DIALOG( window
), BASE_EXIT_CODE_PROGRAM
);
191 g_return_val_if_fail( GTK_IS_DIALOG( toplevel
), BASE_EXIT_CODE_PROGRAM
);
193 code
= BASE_EXIT_CODE_INIT_FAIL
;
195 if( !BASE_DIALOG( window
)->private->dispose_has_run
){
196 g_debug( "%s: window=%p (%s), toplevel=%p (%s), starting gtk_dialog_run",
198 ( void * ) window
, G_OBJECT_TYPE_NAME( window
),
199 ( void * ) toplevel
, G_OBJECT_TYPE_NAME( toplevel
));
201 code
= gtk_dialog_run( GTK_DIALOG( toplevel
));
203 while( !terminate_dialog( BASE_DIALOG( window
), GTK_DIALOG( toplevel
), &code
));
210 * returns %TRUE to quit the dialog loop
213 terminate_dialog( BaseDialog
*window
, GtkDialog
*toplevel
, int *code
)
215 gboolean quit
= FALSE
;
218 case GTK_RESPONSE_NONE
:
219 case GTK_RESPONSE_DELETE_EVENT
:
220 case GTK_RESPONSE_CLOSE
:
221 case GTK_RESPONSE_CANCEL
:
222 dialog_cancel( window
);
223 *code
= GTK_RESPONSE_CANCEL
;
227 case GTK_RESPONSE_OK
:
237 dialog_cancel( BaseDialog
*window
)
239 if( BASE_DIALOG_GET_CLASS( window
)->cancel
){
240 BASE_DIALOG_GET_CLASS( window
)->cancel( window
);
245 dialog_ok( BaseDialog
*window
)
247 if( BASE_DIALOG_GET_CLASS( window
)->ok
){
248 BASE_DIALOG_GET_CLASS( window
)->ok( window
);