~ubuntu-branches/ubuntu/precise/nautilus-actions/precise

« back to all changes in this revision

Viewing changes to src/nact/nact-window.c

  • Committer: Bazaar Package Importer
  • Author(s): Christine Spang
  • Date: 2009-08-12 14:04:00 UTC
  • mfrom: (1.1.6 upstream) (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090812140400-ufe3o3jvr62lf0sf
Tags: 1.12.0-1
* New upstream stable release.
  - Actions can now be enabled/disabled: disabled actions will
    never show up in the nautilus context menu
  - Gnome Bugzilla bugs fixed:
    - #325519 asked by Frederic Ruaudel (enabled property)
    - #590398 reported by Pierre Wieser (install doc)
    - #590399 reported by Pierre Wieser (gtk_image_menu_item_set_image)
    - #590709 reported by Claude Paroz (markup in translatable strings)
    - #590711 reported by Claude Paroz (pipe char is ambiguous to translate)
 - Do not install GConf schemas if --disable-schemas-install option has
   been specified
 - New/updated es and fr translations

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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, 2007, 2008 Frederic Ruaudel and others (see AUTHORS)
 
7
 * Copyright (C) 2009 Pierre Wieser and others (see AUTHORS)
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 *
 
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)
 
29
 */
 
30
 
 
31
#ifdef HAVE_CONFIG_H
 
32
#include <config.h>
 
33
#endif
 
34
 
 
35
#include <glib.h>
 
36
#include <glib/gi18n.h>
 
37
 
 
38
#include <common/na-iio-provider.h>
 
39
 
 
40
#include "nact-application.h"
 
41
#include "nact-iprefs.h"
 
42
#include "nact-window.h"
 
43
 
 
44
/* private class data
 
45
 */
 
46
struct NactWindowClassPrivate {
 
47
};
 
48
 
 
49
/* private instance data
 
50
 */
 
51
struct NactWindowPrivate {
 
52
        gboolean dispose_has_run;
 
53
        GSList  *signals;
 
54
};
 
55
 
 
56
/* connected signal, to be disconnected at NactWindow dispose
 
57
 */
 
58
typedef struct {
 
59
        gpointer instance;
 
60
        gulong   handler_id;
 
61
}
 
62
        NactWindowRecordedSignal;
 
63
 
 
64
static GObjectClass *st_parent_class = NULL;
 
65
static gboolean      st_debug_signal_connect = FALSE;
 
66
 
 
67
static GType    register_type( void );
 
68
static void     class_init( NactWindowClass *klass );
 
69
static void     iprefs_iface_init( NactIPrefsInterface *iface );
 
70
static void     instance_init( GTypeInstance *instance, gpointer klass );
 
71
static void     instance_dispose( GObject *application );
 
72
static void     instance_finalize( GObject *application );
 
73
 
 
74
static gchar   *v_get_iprefs_window_id( NactWindow *window );
 
75
 
 
76
static void     on_runtime_init_toplevel( BaseWindow *window );
 
77
static void     on_all_widgets_showed( BaseWindow *dialog );
 
78
 
 
79
GType
 
80
nact_window_get_type( void )
 
81
{
 
82
        static GType window_type = 0;
 
83
 
 
84
        if( !window_type ){
 
85
                window_type = register_type();
 
86
        }
 
87
 
 
88
        return( window_type );
 
89
}
 
90
 
 
91
static GType
 
92
register_type( void )
 
93
{
 
94
        static const gchar *thisfn = "nact_window_register_type";
 
95
        g_debug( "%s", thisfn );
 
96
 
 
97
        g_type_init();
 
98
 
 
99
        static GTypeInfo info = {
 
100
                sizeof( NactWindowClass ),
 
101
                ( GBaseInitFunc ) NULL,
 
102
                ( GBaseFinalizeFunc ) NULL,
 
103
                ( GClassInitFunc ) class_init,
 
104
                NULL,
 
105
                NULL,
 
106
                sizeof( NactWindow ),
 
107
                0,
 
108
                ( GInstanceInitFunc ) instance_init
 
109
        };
 
110
 
 
111
        GType type = g_type_register_static( BASE_WINDOW_TYPE, "NactWindow", &info, 0 );
 
112
 
 
113
        /* implement IPrefs interface
 
114
         */
 
115
        static const GInterfaceInfo prefs_iface_info = {
 
116
                ( GInterfaceInitFunc ) iprefs_iface_init,
 
117
                NULL,
 
118
                NULL
 
119
        };
 
120
 
 
121
        g_type_add_interface_static( type, NACT_IPREFS_TYPE, &prefs_iface_info );
 
122
 
 
123
        return( type );
 
124
}
 
125
 
 
126
static void
 
127
class_init( NactWindowClass *klass )
 
128
{
 
129
        static const gchar *thisfn = "nact_window_class_init";
 
130
        g_debug( "%s: klass=%p", thisfn, klass );
 
131
 
 
132
        st_parent_class = g_type_class_peek_parent( klass );
 
133
 
 
134
        GObjectClass *object_class = G_OBJECT_CLASS( klass );
 
135
        object_class->dispose = instance_dispose;
 
136
        object_class->finalize = instance_finalize;
 
137
 
 
138
        klass->private = g_new0( NactWindowClassPrivate, 1 );
 
139
 
 
140
        BaseWindowClass *base_class = BASE_WINDOW_CLASS( klass );
 
141
        base_class->runtime_init_toplevel = on_runtime_init_toplevel;
 
142
        base_class->all_widgets_showed = on_all_widgets_showed;
 
143
 
 
144
        klass->get_iprefs_window_id = v_get_iprefs_window_id;
 
145
}
 
146
 
 
147
static void
 
148
iprefs_iface_init( NactIPrefsInterface *iface )
 
149
{
 
150
        static const gchar *thisfn = "nact_window_iprefs_iface_init";
 
151
        g_debug( "%s: iface=%p", thisfn, iface );
 
152
 
 
153
        iface->get_iprefs_window_id = v_get_iprefs_window_id;
 
154
}
 
155
 
 
156
static void
 
157
instance_init( GTypeInstance *instance, gpointer klass )
 
158
{
 
159
        static const gchar *thisfn = "nact_window_instance_init";
 
160
        g_debug( "%s: instance=%p, klass=%p", thisfn, instance, klass );
 
161
 
 
162
        g_assert( NACT_IS_WINDOW( instance ));
 
163
        NactWindow *self = NACT_WINDOW( instance );
 
164
 
 
165
        self->private = g_new0( NactWindowPrivate, 1 );
 
166
 
 
167
        self->private->dispose_has_run = FALSE;
 
168
        self->private->signals = NULL;
 
169
}
 
170
 
 
171
static void
 
172
instance_dispose( GObject *window )
 
173
{
 
174
        static const gchar *thisfn = "nact_window_instance_dispose";
 
175
        g_debug( "%s: window=%p", thisfn, window );
 
176
 
 
177
        g_assert( NACT_IS_WINDOW( window ));
 
178
        NactWindow *self = NACT_WINDOW( window );
 
179
 
 
180
        if( !self->private->dispose_has_run ){
 
181
 
 
182
                self->private->dispose_has_run = TRUE;
 
183
 
 
184
                nact_iprefs_save_window_position( NACT_WINDOW( window ));
 
185
 
 
186
                GSList *is;
 
187
                for( is = self->private->signals ; is ; is = is->next ){
 
188
                        NactWindowRecordedSignal *str = ( NactWindowRecordedSignal * ) is->data;
 
189
                        g_signal_handler_disconnect( str->instance, str->handler_id );
 
190
                        if( st_debug_signal_connect ){
 
191
                                g_debug( "%s: disconnecting signal handler %p:%lu", thisfn, str->instance, str->handler_id );
 
192
                        }
 
193
                        g_free( str );
 
194
                }
 
195
                g_slist_free( self->private->signals );
 
196
 
 
197
                /* chain up to the parent class */
 
198
                G_OBJECT_CLASS( st_parent_class )->dispose( window );
 
199
        }
 
200
}
 
201
 
 
202
static void
 
203
instance_finalize( GObject *window )
 
204
{
 
205
        static const gchar *thisfn = "nact_window_instance_finalize";
 
206
        g_debug( "%s: window=%p", thisfn, window );
 
207
 
 
208
        g_assert( NACT_IS_WINDOW( window ));
 
209
        NactWindow *self = ( NactWindow * ) window;
 
210
 
 
211
        g_free( self->private );
 
212
 
 
213
        /* chain call to parent class */
 
214
        if( st_parent_class->finalize ){
 
215
                G_OBJECT_CLASS( st_parent_class )->finalize( window );
 
216
        }
 
217
}
 
218
 
 
219
/**
 
220
 * Returns a pointer to the list of actions.
 
221
 */
 
222
NAPivot *
 
223
nact_window_get_pivot( NactWindow *window )
 
224
{
 
225
        NactApplication *application;
 
226
        g_object_get( G_OBJECT( window ), PROP_WINDOW_APPLICATION_STR, &application, NULL );
 
227
        g_return_val_if_fail( NACT_IS_APPLICATION( application ), NULL );
 
228
 
 
229
        NAPivot *pivot = nact_application_get_pivot( application );
 
230
        g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
 
231
 
 
232
        return( pivot );
 
233
}
 
234
 
 
235
/**
 
236
 * Set the current action.
 
237
 *
 
238
 * This is called by one of the editors to advertize the main window
 
239
 * that the newly selected action has changed.
 
240
 */
 
241
/*void
 
242
nact_window_set_current_action( NactWindow *window, const NAAction *action )
 
243
{
 
244
        if( NACT_WINDOW_GET_CLASS( window )->set_current_action ){
 
245
                NACT_WINDOW_GET_CLASS( window )->set_current_action( window, action );
 
246
        }
 
247
}*/
 
248
 
 
249
/**
 
250
 * Saves a modified action to the I/O storage subsystem.
 
251
 *
 
252
 * @window: this NactWindow object.
 
253
 *
 
254
 * @action: the modified action.
 
255
 */
 
256
gboolean
 
257
nact_window_save_action( NactWindow *window, NAAction *action )
 
258
{
 
259
        static const gchar *thisfn = "nact_window_save_action";
 
260
        g_debug( "%s: window=%p, action=%p", thisfn, window, action );
 
261
 
 
262
        NAPivot *pivot = nact_window_get_pivot( window );
 
263
        g_assert( NA_IS_PIVOT( pivot ));
 
264
 
 
265
        na_object_dump( NA_OBJECT( action ));
 
266
 
 
267
        gchar *msg = NULL;
 
268
        guint ret = na_pivot_write_action( pivot, action, &msg );
 
269
        if( msg ){
 
270
                base_window_error_dlg(
 
271
                                BASE_WINDOW( window ),
 
272
                                GTK_MESSAGE_WARNING, _( "An error has occured when trying to save the action" ), msg );
 
273
                g_free( msg );
 
274
        }
 
275
 
 
276
        return( ret == NA_IIO_PROVIDER_WRITE_OK );
 
277
}
 
278
 
 
279
/**
 
280
 * Deleted an action from the I/O storage subsystem.
 
281
 *
 
282
 * @window: this NactWindow object.
 
283
 *
 
284
 * @action: the action to delete.
 
285
 */
 
286
gboolean
 
287
nact_window_delete_action( NactWindow *window, NAAction *action )
 
288
{
 
289
        static const gchar *thisfn = "nact_window_delete_action";
 
290
        g_debug( "%s: window=%p, action=%p", thisfn, window, action );
 
291
 
 
292
        NAPivot *pivot = nact_window_get_pivot( window );
 
293
        g_assert( NA_IS_PIVOT( pivot ));
 
294
 
 
295
        na_object_dump( NA_OBJECT( action ));
 
296
 
 
297
        gchar *msg = NULL;
 
298
        guint ret = na_pivot_delete_action( pivot, action, &msg );
 
299
        if( msg ){
 
300
                base_window_error_dlg(
 
301
                                BASE_WINDOW( window ),
 
302
                                GTK_MESSAGE_WARNING, _( "An error has occured when trying to delete the action" ), msg );
 
303
                g_free( msg );
 
304
        }
 
305
 
 
306
        return( ret == NA_IIO_PROVIDER_WRITE_OK );
 
307
}
 
308
 
 
309
/**
 
310
 * Emits a warning if the action has been modified.
 
311
 *
 
312
 * @window: this NactWindow object.
 
313
 *
 
314
 * @count
 
315
 *
 
316
 * Returns TRUE if the user confirms he wants to quit.
 
317
 *
 
318
 * Note: the count of modified actions is subject to some approximation.
 
319
 * So, just say that 'actions have been modified'
 
320
 */
 
321
gboolean
 
322
nact_window_warn_count_modified( NactWindow *window, gint count )
 
323
{
 
324
        gchar *first;
 
325
        gchar *second;
 
326
        if( count == 1 ){
 
327
                first = g_strdup_printf( _( "One action has been modified." ));
 
328
                second = g_strdup( _( "Are you sure you want to quit without saving it ?" ));
 
329
        } else {
 
330
                /*first = g_strdup_printf( _( "%d actions have been modified." ), count );*/
 
331
                first = g_strdup_printf( _( "Actions have been modified." ));
 
332
                second = g_strdup( _( "Are you sure you want to quit without saving them ?" ));
 
333
        }
 
334
 
 
335
        gboolean ok = base_window_yesno_dlg( BASE_WINDOW( window ), GTK_MESSAGE_QUESTION, first, second );
 
336
 
 
337
        g_free( second );
 
338
        g_free( first );
 
339
 
 
340
        return( ok );
 
341
}
 
342
 
 
343
/**
 
344
 * Records a connected signal, to be disconnected at NactWindow dispose.
 
345
 */
 
346
void
 
347
nact_window_signal_connect( NactWindow *window, GObject *instance, const gchar *signal, GCallback fn )
 
348
{
 
349
        static const gchar *thisfn = "nact_window_signal_connect";
 
350
 
 
351
        gulong handler_id = g_signal_connect( instance, signal, fn, window );
 
352
 
 
353
        NactWindowRecordedSignal *str = g_new0( NactWindowRecordedSignal, 1 );
 
354
        str->instance = instance;
 
355
        str->handler_id = handler_id;
 
356
        window->private->signals = g_slist_prepend( window->private->signals, str );
 
357
 
 
358
        if( st_debug_signal_connect ){
 
359
                g_debug( "%s: connecting signal handler %p:%lu", thisfn, instance, handler_id );
 
360
        }
 
361
}
 
362
 
 
363
void
 
364
nact_window_signal_connect_by_name( NactWindow *window, const gchar *name, const gchar *signal, GCallback fn )
 
365
{
 
366
        GtkWidget *widget = base_window_get_widget( BASE_WINDOW( window ), name );
 
367
        if( GTK_IS_WIDGET( widget )){
 
368
                nact_window_signal_connect( window, G_OBJECT( widget ), signal, fn );
 
369
        }
 
370
}
 
371
 
 
372
static gchar *
 
373
v_get_iprefs_window_id( NactWindow *window )
 
374
{
 
375
        g_assert( NACT_IS_IPREFS( window ));
 
376
 
 
377
        if( NACT_WINDOW_GET_CLASS( window )->get_iprefs_window_id ){
 
378
                return( NACT_WINDOW_GET_CLASS( window )->get_iprefs_window_id( window ));
 
379
        }
 
380
 
 
381
        return( NULL );
 
382
}
 
383
 
 
384
static void
 
385
on_runtime_init_toplevel( BaseWindow *window )
 
386
{
 
387
        static const gchar *thisfn = "nact_window_on_runtime_init_toplevel";
 
388
 
 
389
        /* call parent class at the very beginning */
 
390
        if( BASE_WINDOW_CLASS( st_parent_class )->runtime_init_toplevel ){
 
391
                BASE_WINDOW_CLASS( st_parent_class )->runtime_init_toplevel( window );
 
392
        }
 
393
 
 
394
        g_debug( "%s: window=%p", thisfn, window );
 
395
        g_assert( NACT_IS_WINDOW( window ));
 
396
 
 
397
        nact_iprefs_position_window( NACT_WINDOW( window ));
 
398
}
 
399
 
 
400
static void
 
401
on_all_widgets_showed( BaseWindow *dialog )
 
402
{
 
403
        static const gchar *thisfn = "nact_window_on_all_widgets_showed";
 
404
 
 
405
        /* call parent class at the very beginning */
 
406
        if( BASE_WINDOW_CLASS( st_parent_class )->all_widgets_showed ){
 
407
                BASE_WINDOW_CLASS( st_parent_class )->all_widgets_showed( dialog );
 
408
        }
 
409
 
 
410
        g_debug( "%s: dialog=%p", thisfn, dialog );
 
411
}