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)
36
#include <glib/gi18n.h>
38
#include <common/na-iio-provider.h>
40
#include "nact-application.h"
41
#include "nact-iprefs.h"
42
#include "nact-window.h"
46
struct NactWindowClassPrivate {
49
/* private instance data
51
struct NactWindowPrivate {
52
gboolean dispose_has_run;
56
/* connected signal, to be disconnected at NactWindow dispose
62
NactWindowRecordedSignal;
64
static GObjectClass *st_parent_class = NULL;
65
static gboolean st_debug_signal_connect = FALSE;
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 );
74
static gchar *v_get_iprefs_window_id( NactWindow *window );
76
static void on_runtime_init_toplevel( BaseWindow *window );
77
static void on_all_widgets_showed( BaseWindow *dialog );
80
nact_window_get_type( void )
82
static GType window_type = 0;
85
window_type = register_type();
88
return( window_type );
94
static const gchar *thisfn = "nact_window_register_type";
95
g_debug( "%s", thisfn );
99
static GTypeInfo info = {
100
sizeof( NactWindowClass ),
101
( GBaseInitFunc ) NULL,
102
( GBaseFinalizeFunc ) NULL,
103
( GClassInitFunc ) class_init,
106
sizeof( NactWindow ),
108
( GInstanceInitFunc ) instance_init
111
GType type = g_type_register_static( BASE_WINDOW_TYPE, "NactWindow", &info, 0 );
113
/* implement IPrefs interface
115
static const GInterfaceInfo prefs_iface_info = {
116
( GInterfaceInitFunc ) iprefs_iface_init,
121
g_type_add_interface_static( type, NACT_IPREFS_TYPE, &prefs_iface_info );
127
class_init( NactWindowClass *klass )
129
static const gchar *thisfn = "nact_window_class_init";
130
g_debug( "%s: klass=%p", thisfn, klass );
132
st_parent_class = g_type_class_peek_parent( klass );
134
GObjectClass *object_class = G_OBJECT_CLASS( klass );
135
object_class->dispose = instance_dispose;
136
object_class->finalize = instance_finalize;
138
klass->private = g_new0( NactWindowClassPrivate, 1 );
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;
144
klass->get_iprefs_window_id = v_get_iprefs_window_id;
148
iprefs_iface_init( NactIPrefsInterface *iface )
150
static const gchar *thisfn = "nact_window_iprefs_iface_init";
151
g_debug( "%s: iface=%p", thisfn, iface );
153
iface->get_iprefs_window_id = v_get_iprefs_window_id;
157
instance_init( GTypeInstance *instance, gpointer klass )
159
static const gchar *thisfn = "nact_window_instance_init";
160
g_debug( "%s: instance=%p, klass=%p", thisfn, instance, klass );
162
g_assert( NACT_IS_WINDOW( instance ));
163
NactWindow *self = NACT_WINDOW( instance );
165
self->private = g_new0( NactWindowPrivate, 1 );
167
self->private->dispose_has_run = FALSE;
168
self->private->signals = NULL;
172
instance_dispose( GObject *window )
174
static const gchar *thisfn = "nact_window_instance_dispose";
175
g_debug( "%s: window=%p", thisfn, window );
177
g_assert( NACT_IS_WINDOW( window ));
178
NactWindow *self = NACT_WINDOW( window );
180
if( !self->private->dispose_has_run ){
182
self->private->dispose_has_run = TRUE;
184
nact_iprefs_save_window_position( NACT_WINDOW( window ));
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 );
195
g_slist_free( self->private->signals );
197
/* chain up to the parent class */
198
G_OBJECT_CLASS( st_parent_class )->dispose( window );
203
instance_finalize( GObject *window )
205
static const gchar *thisfn = "nact_window_instance_finalize";
206
g_debug( "%s: window=%p", thisfn, window );
208
g_assert( NACT_IS_WINDOW( window ));
209
NactWindow *self = ( NactWindow * ) window;
211
g_free( self->private );
213
/* chain call to parent class */
214
if( st_parent_class->finalize ){
215
G_OBJECT_CLASS( st_parent_class )->finalize( window );
220
* Returns a pointer to the list of actions.
223
nact_window_get_pivot( NactWindow *window )
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 );
229
NAPivot *pivot = nact_application_get_pivot( application );
230
g_return_val_if_fail( NA_IS_PIVOT( pivot ), NULL );
236
* Set the current action.
238
* This is called by one of the editors to advertize the main window
239
* that the newly selected action has changed.
242
nact_window_set_current_action( NactWindow *window, const NAAction *action )
244
if( NACT_WINDOW_GET_CLASS( window )->set_current_action ){
245
NACT_WINDOW_GET_CLASS( window )->set_current_action( window, action );
250
* Saves a modified action to the I/O storage subsystem.
252
* @window: this NactWindow object.
254
* @action: the modified action.
257
nact_window_save_action( NactWindow *window, NAAction *action )
259
static const gchar *thisfn = "nact_window_save_action";
260
g_debug( "%s: window=%p, action=%p", thisfn, window, action );
262
NAPivot *pivot = nact_window_get_pivot( window );
263
g_assert( NA_IS_PIVOT( pivot ));
265
na_object_dump( NA_OBJECT( action ));
268
guint ret = na_pivot_write_action( pivot, action, &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 );
276
return( ret == NA_IIO_PROVIDER_WRITE_OK );
280
* Deleted an action from the I/O storage subsystem.
282
* @window: this NactWindow object.
284
* @action: the action to delete.
287
nact_window_delete_action( NactWindow *window, NAAction *action )
289
static const gchar *thisfn = "nact_window_delete_action";
290
g_debug( "%s: window=%p, action=%p", thisfn, window, action );
292
NAPivot *pivot = nact_window_get_pivot( window );
293
g_assert( NA_IS_PIVOT( pivot ));
295
na_object_dump( NA_OBJECT( action ));
298
guint ret = na_pivot_delete_action( pivot, action, &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 );
306
return( ret == NA_IIO_PROVIDER_WRITE_OK );
310
* Emits a warning if the action has been modified.
312
* @window: this NactWindow object.
316
* Returns TRUE if the user confirms he wants to quit.
318
* Note: the count of modified actions is subject to some approximation.
319
* So, just say that 'actions have been modified'
322
nact_window_warn_count_modified( NactWindow *window, gint count )
327
first = g_strdup_printf( _( "One action has been modified." ));
328
second = g_strdup( _( "Are you sure you want to quit without saving it ?" ));
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 ?" ));
335
gboolean ok = base_window_yesno_dlg( BASE_WINDOW( window ), GTK_MESSAGE_QUESTION, first, second );
344
* Records a connected signal, to be disconnected at NactWindow dispose.
347
nact_window_signal_connect( NactWindow *window, GObject *instance, const gchar *signal, GCallback fn )
349
static const gchar *thisfn = "nact_window_signal_connect";
351
gulong handler_id = g_signal_connect( instance, signal, fn, window );
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 );
358
if( st_debug_signal_connect ){
359
g_debug( "%s: connecting signal handler %p:%lu", thisfn, instance, handler_id );
364
nact_window_signal_connect_by_name( NactWindow *window, const gchar *name, const gchar *signal, GCallback fn )
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 );
373
v_get_iprefs_window_id( NactWindow *window )
375
g_assert( NACT_IS_IPREFS( window ));
377
if( NACT_WINDOW_GET_CLASS( window )->get_iprefs_window_id ){
378
return( NACT_WINDOW_GET_CLASS( window )->get_iprefs_window_id( window ));
385
on_runtime_init_toplevel( BaseWindow *window )
387
static const gchar *thisfn = "nact_window_on_runtime_init_toplevel";
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 );
394
g_debug( "%s: window=%p", thisfn, window );
395
g_assert( NACT_IS_WINDOW( window ));
397
nact_iprefs_position_window( NACT_WINDOW( window ));
401
on_all_widgets_showed( BaseWindow *dialog )
403
static const gchar *thisfn = "nact_window_on_all_widgets_showed";
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 );
410
g_debug( "%s: dialog=%p", thisfn, dialog );