Update copyright message
[nautilus-actions.git] / src / nact / nact-ifolders-tab.c
blobb9de0f7a57316371886482163e6c0869066c9dd2
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, 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.
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 <glib/gi18n.h>
36 #include <string.h>
38 #include <api/na-core-utils.h>
39 #include <api/na-object-api.h>
41 #include <core/na-iprefs.h>
43 #include "base-iprefs.h"
44 #include "base-window.h"
45 #include "nact-gtk-utils.h"
46 #include "nact-iprefs.h"
47 #include "nact-application.h"
48 #include "nact-main-tab.h"
49 #include "nact-match-list.h"
50 #include "nact-ifolders-tab.h"
52 /* private interface data
54 struct NactIFoldersTabInterfacePrivate {
55 void *empty; /* so that gcc -pedantic is happy */
58 #define ITAB_NAME "folders"
60 #define IPREFS_FOLDERS_DIALOG "ifolders-chooser"
61 #define IPREFS_FOLDERS_PATH "ifolders-path"
63 static gboolean st_initialized = FALSE;
64 static gboolean st_finalized = FALSE;
66 static GType register_type( void );
67 static void interface_base_init( NactIFoldersTabInterface *klass );
68 static void interface_base_finalize( NactIFoldersTabInterface *klass );
70 static void on_tab_updatable_selection_changed( NactIFoldersTab *instance, gint count_selected );
72 static void on_browse_folder_clicked( GtkButton *button, BaseWindow *window );
73 static GSList *get_folders( void *context );
74 static void set_folders( void *context, GSList *filters );
76 GType
77 nact_ifolders_tab_get_type( void )
79 static GType iface_type = 0;
81 if( !iface_type ){
82 iface_type = register_type();
85 return( iface_type );
88 static GType
89 register_type( void )
91 static const gchar *thisfn = "nact_ifolders_tab_register_type";
92 GType type;
94 static const GTypeInfo info = {
95 sizeof( NactIFoldersTabInterface ),
96 ( GBaseInitFunc ) interface_base_init,
97 ( GBaseFinalizeFunc ) interface_base_finalize,
98 NULL,
99 NULL,
100 NULL,
103 NULL
106 g_debug( "%s", thisfn );
108 type = g_type_register_static( G_TYPE_INTERFACE, "NactIFoldersTab", &info, 0 );
110 g_type_interface_add_prerequisite( type, BASE_WINDOW_TYPE );
112 return( type );
115 static void
116 interface_base_init( NactIFoldersTabInterface *klass )
118 static const gchar *thisfn = "nact_ifolders_tab_interface_base_init";
120 if( !st_initialized ){
122 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
124 klass->private = g_new0( NactIFoldersTabInterfacePrivate, 1 );
126 st_initialized = TRUE;
130 static void
131 interface_base_finalize( NactIFoldersTabInterface *klass )
133 static const gchar *thisfn = "nact_ifolders_tab_interface_base_finalize";
135 if( st_initialized && !st_finalized ){
137 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
139 st_finalized = TRUE;
141 g_free( klass->private );
145 void
146 nact_ifolders_tab_initial_load_toplevel( NactIFoldersTab *instance )
148 static const gchar *thisfn = "nact_ifolders_tab_initial_load_toplevel";
149 GtkWidget *list, *add, *remove;
151 g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
153 if( st_initialized && !st_finalized ){
155 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
157 list = base_window_get_widget( BASE_WINDOW( instance ), "FoldersTreeView" );
158 add = base_window_get_widget( BASE_WINDOW( instance ), "AddFolderButton" );
159 remove = base_window_get_widget( BASE_WINDOW( instance ), "RemoveFolderButton" );
161 nact_match_list_create_model(
162 BASE_WINDOW( instance ),
163 ITAB_NAME,
164 TAB_FOLDERS,
165 list, add, remove,
166 ( pget_filters ) get_folders,
167 ( pset_filters ) set_folders,
168 NULL,
169 MATCH_LIST_MUST_MATCH_ONE_OF,
170 _( "Folder filter" ), TRUE );
174 void
175 nact_ifolders_tab_runtime_init_toplevel( NactIFoldersTab *instance )
177 static const gchar *thisfn = "nact_ifolders_tab_runtime_init_toplevel";
178 GtkWidget *button;
180 g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
182 if( st_initialized && !st_finalized ){
184 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
186 base_window_signal_connect(
187 BASE_WINDOW( instance ),
188 G_OBJECT( instance ),
189 MAIN_WINDOW_SIGNAL_SELECTION_CHANGED,
190 G_CALLBACK( on_tab_updatable_selection_changed ));
192 nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
194 button = base_window_get_widget( BASE_WINDOW( instance ), "FolderBrowseButton" );
195 base_window_signal_connect(
196 BASE_WINDOW( instance ),
197 G_OBJECT( button ),
198 "clicked",
199 G_CALLBACK( on_browse_folder_clicked ));
203 void
204 nact_ifolders_tab_all_widgets_showed( NactIFoldersTab *instance )
206 static const gchar *thisfn = "nact_ifolders_tab_all_widgets_showed";
208 g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
210 if( st_initialized && !st_finalized ){
212 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
216 void
217 nact_ifolders_tab_dispose( NactIFoldersTab *instance )
219 static const gchar *thisfn = "nact_ifolders_tab_dispose";
221 g_return_if_fail( NACT_IS_IFOLDERS_TAB( instance ));
223 if( st_initialized && !st_finalized ){
225 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
227 nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
231 static void
232 on_tab_updatable_selection_changed( NactIFoldersTab *instance, gint count_selected )
234 NAIContext *context;
235 gboolean editable;
236 GtkWidget *button;
238 nact_match_list_on_selection_changed( BASE_WINDOW( instance ), ITAB_NAME, count_selected );
240 context = nact_main_tab_get_context( NACT_MAIN_WINDOW( instance ), &editable );
241 button = base_window_get_widget( BASE_WINDOW( instance ), "FolderBrowseButton" );
242 nact_gtk_utils_set_editable( G_OBJECT( button ), editable );
245 static void
246 on_browse_folder_clicked( GtkButton *button, BaseWindow *window )
248 #if 0
249 /* this is the code I sent to gtk-app-devel list
250 * to know why one is not able to just enter '/' in the location entry
252 GtkWidget *dialog;
253 gchar *path;
255 dialog = gtk_file_chooser_dialog_new( _( "Select a folder" ),
256 NULL,
257 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
258 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
259 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
260 NULL );
262 gtk_file_chooser_set_filename( GTK_FILE_CHOOSER( dialog ), "/" );
264 if( gtk_dialog_run( GTK_DIALOG( dialog )) == GTK_RESPONSE_ACCEPT ){
265 path = gtk_file_chooser_get_filename( GTK_FILE_CHOOSER( dialog ));
266 g_debug( "nact_ifolders_tab_on_add_folder_clicked: path=%s", path );
267 g_free( path );
270 gtk_widget_destroy( dialog );
271 #endif
273 gchar *path;
274 GtkWindow *toplevel;
275 GtkWidget *dialog;
276 NactApplication *application;
277 NAUpdater *updater;
279 path = NULL;
280 toplevel = base_window_get_toplevel( window );
282 /* i18n: title of the FileChoose dialog when selecting an URI which
283 * will be compare to Nautilus 'current_folder'
285 dialog = gtk_file_chooser_dialog_new( _( "Select a folder" ),
286 toplevel,
287 GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER,
288 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
289 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
290 NULL );
292 application = NACT_APPLICATION( base_window_get_application( window ));
293 updater = nact_application_get_updater( application );
295 base_iprefs_position_named_window( window, GTK_WINDOW( dialog ), IPREFS_FOLDERS_DIALOG );
297 path = na_iprefs_read_string( NA_IPREFS( updater ), IPREFS_FOLDERS_PATH, "/" );
298 if( path && g_utf8_strlen( path, -1 )){
299 gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER( dialog ), path );
301 g_free( path );
303 if( gtk_dialog_run( GTK_DIALOG( dialog )) == GTK_RESPONSE_ACCEPT ){
304 path = gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER( dialog ));
305 nact_iprefs_write_string( window, IPREFS_FOLDERS_PATH, path );
307 nact_match_list_insert_row( window, ITAB_NAME, path, FALSE, FALSE );
309 g_free( path );
312 base_iprefs_save_named_window_position( window, GTK_WINDOW( dialog ), IPREFS_FOLDERS_DIALOG );
314 gtk_widget_destroy( dialog );
317 static GSList *
318 get_folders( void *context )
320 return( na_object_get_folders( context ));
323 static void
324 set_folders( void *context, GSList *filters )
326 na_object_set_folders( context, filters );