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 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 <gdk/gdkkeysyms.h>
37
#include <glib/gi18n.h>
39
#include "base-application.h"
40
#include "nact-assistant.h"
44
struct NactAssistantClassPrivate {
47
/* private instance data
49
struct NactAssistantPrivate {
50
gboolean dispose_has_run;
51
gboolean warn_on_cancel;
54
/* instance properties
57
PROP_ASSIST_WARN_ON_CANCEL = 1
60
#define PROP_ASSIST_WARN_ON_CANCEL_STR "nact-assist-warn-on-cancel"
62
static GObjectClass *st_parent_class = NULL;
64
static GType register_type( void );
65
static void class_init( NactAssistantClass *klass );
66
static void instance_init( GTypeInstance *instance, gpointer klass );
67
static void instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec );
68
static void instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec );
69
static void instance_dispose( GObject *application );
70
static void instance_finalize( GObject *application );
72
static GtkWindow * get_dialog( BaseWindow *window, const gchar *name );
74
static void v_assistant_apply( GtkAssistant *assistant, gpointer user_data );
75
static void v_assistant_cancel( GtkAssistant *assistant, gpointer user_data );
76
static void v_assistant_close( GtkAssistant *assistant, gpointer user_data );
77
static void v_assistant_prepare( GtkAssistant *assistant, GtkWidget *page, gpointer user_data );
79
static void on_runtime_init_toplevel( BaseWindow *window );
80
static gboolean on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, gpointer user_data );
81
static gboolean on_escape_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer user_data );
82
static void do_assistant_apply( NactAssistant *window, GtkAssistant *assistant );
83
static void do_assistant_cancel( NactAssistant *window, GtkAssistant *assistant );
84
static void do_assistant_close( NactAssistant *window, GtkAssistant *assistant );
85
static void do_assistant_prepare( NactAssistant *window, GtkAssistant *assistant, GtkWidget *page );
88
nact_assistant_get_type( void )
90
static GType window_type = 0;
93
window_type = register_type();
96
return( window_type );
100
register_type( void )
102
static const gchar *thisfn = "nact_assistant_register_type";
103
g_debug( "%s", thisfn );
107
static GTypeInfo info = {
108
sizeof( NactAssistantClass ),
109
( GBaseInitFunc ) NULL,
110
( GBaseFinalizeFunc ) NULL,
111
( GClassInitFunc ) class_init,
114
sizeof( NactAssistant ),
116
( GInstanceInitFunc ) instance_init
119
GType type = g_type_register_static( NACT_WINDOW_TYPE, "NactAssistant", &info, 0 );
125
class_init( NactAssistantClass *klass )
127
static const gchar *thisfn = "nact_assistant_class_init";
128
g_debug( "%s: klass=%p", thisfn, klass );
130
st_parent_class = g_type_class_peek_parent( klass );
132
GObjectClass *object_class = G_OBJECT_CLASS( klass );
133
object_class->dispose = instance_dispose;
134
object_class->finalize = instance_finalize;
135
object_class->get_property = instance_get_property;
136
object_class->set_property = instance_set_property;
139
spec = g_param_spec_boolean(
140
PROP_ASSIST_WARN_ON_CANCEL_STR,
141
PROP_ASSIST_WARN_ON_CANCEL_STR,
142
"Does the user should confirm when exiting the assistant ?", FALSE,
143
G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE );
144
g_object_class_install_property( object_class, PROP_ASSIST_WARN_ON_CANCEL, spec );
146
klass->private = g_new0( NactAssistantClassPrivate, 1 );
148
BaseWindowClass *base_class = BASE_WINDOW_CLASS( klass );
149
base_class->get_dialog = get_dialog;
150
base_class->runtime_init_toplevel = on_runtime_init_toplevel;
152
klass->on_escape_key_pressed = on_escape_key_pressed;
153
klass->on_assistant_apply = do_assistant_apply;
154
klass->on_assistant_close = do_assistant_close;
155
klass->on_assistant_cancel = do_assistant_cancel;
156
klass->on_assistant_prepare = do_assistant_prepare;
160
instance_init( GTypeInstance *instance, gpointer klass )
162
static const gchar *thisfn = "nact_assistant_instance_init";
163
g_debug( "%s: instance=%p, klass=%p", thisfn, instance, klass );
165
g_assert( NACT_IS_ASSISTANT( instance ));
166
NactAssistant *self = NACT_ASSISTANT( instance );
168
self->private = g_new0( NactAssistantPrivate, 1 );
170
self->private->dispose_has_run = FALSE;
174
instance_get_property( GObject *object, guint property_id, GValue *value, GParamSpec *spec )
176
g_assert( NACT_IS_ASSISTANT( object ));
177
NactAssistant *self = NACT_ASSISTANT( object );
179
switch( property_id ){
180
case PROP_ASSIST_WARN_ON_CANCEL:
181
g_value_set_boolean( value, self->private->warn_on_cancel );
185
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
191
instance_set_property( GObject *object, guint property_id, const GValue *value, GParamSpec *spec )
193
g_assert( NACT_IS_ASSISTANT( object ));
194
NactAssistant *self = NACT_ASSISTANT( object );
196
switch( property_id ){
197
case PROP_ASSIST_WARN_ON_CANCEL:
198
self->private->warn_on_cancel = g_value_get_boolean( value );
202
G_OBJECT_WARN_INVALID_PROPERTY_ID( object, property_id, spec );
208
instance_dispose( GObject *window )
210
static const gchar *thisfn = "nact_assistant_instance_dispose";
211
g_debug( "%s: window=%p", thisfn, window );
213
g_assert( NACT_IS_ASSISTANT( window ));
214
NactAssistant *self = NACT_ASSISTANT( window );
216
if( !self->private->dispose_has_run ){
218
self->private->dispose_has_run = TRUE;
220
/* chain up to the parent class */
221
G_OBJECT_CLASS( st_parent_class )->dispose( window );
226
instance_finalize( GObject *window )
228
static const gchar *thisfn = "nact_assistant_instance_finalize";
229
g_debug( "%s: window=%p", thisfn, window );
231
g_assert( NACT_IS_ASSISTANT( window ));
232
NactAssistant *self = ( NactAssistant * ) window;
234
g_free( self->private );
236
/* chain call to parent class */
237
if( st_parent_class->finalize ){
238
G_OBJECT_CLASS( st_parent_class )->finalize( window );
243
* cf. http://bugzilla.gnome.org/show_bug.cgi?id=589746 against Gtk+ 2.16
244
* a GtkFileChooseWidget embedded in a GtkAssistant is not displayed
245
* when run more than once
247
* as a work-around, reload the XML ui each time we run an assistant !
250
get_dialog( BaseWindow *window, const gchar *name )
252
GtkBuilder *builder = gtk_builder_new();
254
BaseApplication *appli = base_window_get_application( window );
256
gchar *fname = base_application_get_ui_filename( appli );
258
gtk_builder_add_from_file( builder, fname, NULL );
262
GtkWindow *dialog = GTK_WINDOW( gtk_builder_get_object( builder, name ));
268
* Set 'warn on close' property.
272
nact_assistant_set_warn_on_cancel( NactAssistant *window, gboolean warn )
274
g_assert( NACT_IS_ASSISTANT( window ));
275
g_object_set( G_OBJECT( window ), PROP_ASSIST_WARN_ON_CANCEL_STR, warn, NULL );
279
v_assistant_apply( GtkAssistant *assistant, gpointer user_data )
281
g_assert( NACT_IS_ASSISTANT( user_data ));
283
if( NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_apply ){
284
NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_apply( NACT_ASSISTANT( user_data ), assistant );
286
do_assistant_apply( NACT_ASSISTANT( user_data ), assistant );
291
v_assistant_cancel( GtkAssistant *assistant, gpointer user_data )
293
g_assert( NACT_IS_ASSISTANT( user_data ));
295
if( NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_cancel ){
296
NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_cancel( NACT_ASSISTANT( user_data ), assistant );
298
do_assistant_cancel( NACT_ASSISTANT( user_data ), assistant );
303
v_assistant_close( GtkAssistant *assistant, gpointer user_data )
305
g_assert( NACT_IS_ASSISTANT( user_data ));
307
if( NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_close ){
308
NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_close( NACT_ASSISTANT( user_data ), assistant );
310
do_assistant_close( NACT_ASSISTANT( user_data ), assistant );
315
v_assistant_prepare( GtkAssistant *assistant, GtkWidget *page, gpointer user_data )
317
g_assert( NACT_IS_ASSISTANT( user_data ));
319
if( NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_prepare ){
320
NACT_ASSISTANT_GET_CLASS( user_data )->on_assistant_prepare( NACT_ASSISTANT( user_data ), assistant, page );
322
do_assistant_prepare( NACT_ASSISTANT( user_data ), assistant, page );
327
on_runtime_init_toplevel( BaseWindow *window )
329
static const gchar *thisfn = "nact_assistant_on_runtime_init_toplevel";
331
/* call parent class at the very beginning */
332
if( BASE_WINDOW_CLASS( st_parent_class )->runtime_init_toplevel ){
333
BASE_WINDOW_CLASS( st_parent_class )->runtime_init_toplevel( window );
336
g_debug( "%s: window=%p", thisfn, window );
337
g_assert( NACT_IS_ASSISTANT( window ));
339
GtkWindow *toplevel = base_window_get_toplevel_dialog( window );
340
g_assert( GTK_IS_ASSISTANT( toplevel ));
342
nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( toplevel ), "key-press-event", G_CALLBACK( on_key_pressed_event ));
343
nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( toplevel ), "cancel", G_CALLBACK( v_assistant_cancel ));
344
nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( toplevel ), "close", G_CALLBACK( v_assistant_close ));
345
nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( toplevel ), "prepare", G_CALLBACK( v_assistant_prepare ));
346
nact_window_signal_connect( NACT_WINDOW( window ), G_OBJECT( toplevel ), "apply", G_CALLBACK( v_assistant_apply ));
348
nact_assistant_set_warn_on_cancel( NACT_ASSISTANT( window ), TRUE );
352
on_key_pressed_event( GtkWidget *widget, GdkEventKey *event, gpointer user_data )
354
/*static const gchar *thisfn = "nact_assistant_on_key_pressed_event";
355
g_debug( "%s: widget=%p, event=%p, user_data=%p", thisfn, widget, event, user_data );*/
357
gboolean stop = FALSE;
359
if( event->keyval == GDK_Escape ){
360
if( NACT_ASSISTANT_GET_CLASS( user_data )->on_escape_key_pressed ){
361
stop = NACT_ASSISTANT_GET_CLASS( user_data )->on_escape_key_pressed( widget, event, user_data );
369
on_escape_key_pressed( GtkWidget *widget, GdkEventKey *event, gpointer user_data )
371
static const gchar *thisfn = "nact_assistant_on_escape_key_pressed";
372
g_debug( "%s: widget=%p, event=%p, user_data=%p", thisfn, widget, event, user_data );
374
GtkWindow *toplevel = base_window_get_toplevel_dialog( BASE_WINDOW( user_data ));
375
v_assistant_cancel( GTK_ASSISTANT( toplevel ), user_data );
381
do_assistant_apply( NactAssistant *window, GtkAssistant *assistant )
383
static const gchar *thisfn = "nact_assistant_do_assistant_apply";
384
g_debug( "%s: window=%p, assistant=%p", thisfn, window, assistant );
388
* the 'Cancel' button is clicked
391
do_assistant_cancel( NactAssistant *window, GtkAssistant *assistant )
393
static const gchar *thisfn = "nact_assistant_do_assistant_cancel";
394
g_debug( "%s: window=%p, assistant=%p", thisfn, window, assistant );
398
if( window->private->warn_on_cancel ){
399
gchar *first = g_strdup( _( "Are you sure you want to quit this assistant ?" ));
400
ok = base_window_yesno_dlg( BASE_WINDOW( window ), GTK_MESSAGE_QUESTION, first, NULL );
405
do_assistant_close( window, assistant );
410
do_assistant_close( NactAssistant *window, GtkAssistant *assistant )
412
static const gchar *thisfn = "nact_assistant_do_assistant_close";
413
g_debug( "%s: window=%p, assistant=%p", thisfn, window, assistant );
415
g_object_unref( window );
419
do_assistant_prepare( NactAssistant *window, GtkAssistant *assistant, GtkWidget *page )
421
static const gchar *thisfn = "nact_assistant_do_assistant_prepare";
422
g_debug( "%s: window=%p, assistant=%p, page=%p", thisfn, window, assistant, page );