Manage locked and mandatory preferences
[nautilus-actions.git] / src / nact / nact-imimetypes-tab.c
blobcd314e9591b3bd99bb23a3bb261648f29aaa3eab
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>
37 #include <api/na-object-api.h>
39 #include "nact-main-tab.h"
40 #include "nact-match-list.h"
41 #include "nact-imimetypes-tab.h"
43 /* private interface data
45 struct NactIMimetypesTabInterfacePrivate {
46 void *empty; /* so that gcc -pedantic is happy */
49 #define ITAB_NAME "mimetypes"
51 static gboolean st_initialized = FALSE;
52 static gboolean st_finalized = FALSE;
54 static GType register_type( void );
55 static void interface_base_init( NactIMimetypesTabInterface *klass );
56 static void interface_base_finalize( NactIMimetypesTabInterface *klass );
58 static void on_tab_updatable_selection_changed( BaseWindow *window, gint count_selected );
60 static GSList *get_mimetypes( void *context );
61 static void set_mimetypes( void *context, GSList *filters );
63 GType
64 nact_imimetypes_tab_get_type( void )
66 static GType iface_type = 0;
68 if( !iface_type ){
69 iface_type = register_type();
72 return( iface_type );
75 static GType
76 register_type( void )
78 static const gchar *thisfn = "nact_imimetypes_tab_register_type";
79 GType type;
81 static const GTypeInfo info = {
82 sizeof( NactIMimetypesTabInterface ),
83 ( GBaseInitFunc ) interface_base_init,
84 ( GBaseFinalizeFunc ) interface_base_finalize,
85 NULL,
86 NULL,
87 NULL,
90 NULL
93 g_debug( "%s", thisfn );
95 type = g_type_register_static( G_TYPE_INTERFACE, "NactIMimetypesTab", &info, 0 );
97 g_type_interface_add_prerequisite( type, BASE_WINDOW_TYPE );
99 return( type );
102 static void
103 interface_base_init( NactIMimetypesTabInterface *klass )
105 static const gchar *thisfn = "nact_imimetypes_tab_interface_base_init";
107 if( !st_initialized ){
109 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
111 klass->private = g_new0( NactIMimetypesTabInterfacePrivate, 1 );
113 st_initialized = TRUE;
117 static void
118 interface_base_finalize( NactIMimetypesTabInterface *klass )
120 static const gchar *thisfn = "nact_imimetypes_tab_interface_base_finalize";
122 if( st_initialized && !st_finalized ){
124 g_debug( "%s: klass=%p", thisfn, ( void * ) klass );
126 st_finalized = TRUE;
128 g_free( klass->private );
133 * nact_imimetypes_tab_initial_load:
134 * @window: this #NactIMimetypesTab instance.
136 * Initializes the tab widget at initial load.
138 void
139 nact_imimetypes_tab_initial_load_toplevel( NactIMimetypesTab *instance )
141 static const gchar *thisfn = "nact_imimetypes_tab_initial_load_toplevel";
142 GtkWidget *list, *add, *remove;
144 g_return_if_fail( NACT_IS_IMIMETYPES_TAB( instance ));
146 if( st_initialized && !st_finalized ){
148 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
150 list = base_window_get_widget( BASE_WINDOW( instance ), "MimetypesTreeView" );
151 add = base_window_get_widget( BASE_WINDOW( instance ), "AddMimetypeButton" );
152 remove = base_window_get_widget( BASE_WINDOW( instance ), "RemoveMimetypeButton" );
154 nact_match_list_create_model(
155 BASE_WINDOW( instance ),
156 ITAB_NAME,
157 TAB_MIMETYPES,
158 list, add, remove,
159 ( pget_filters ) get_mimetypes,
160 ( pset_filters ) set_mimetypes,
161 NULL,
162 MATCH_LIST_MUST_MATCH_ONE_OF,
163 _( "Mimetype filter" ), TRUE );
168 * nact_imimetypes_tab_runtime_init:
169 * @window: this #NactIMimetypesTab instance.
171 * Initializes the tab widget at each time the widget will be displayed.
172 * Connect signals and setup runtime values.
174 void
175 nact_imimetypes_tab_runtime_init_toplevel( NactIMimetypesTab *instance )
177 static const gchar *thisfn = "nact_imimetypes_tab_runtime_init_toplevel";
179 g_return_if_fail( NACT_IS_IMIMETYPES_TAB( instance ));
181 if( st_initialized && !st_finalized ){
183 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
185 base_window_signal_connect(
186 BASE_WINDOW( instance ),
187 G_OBJECT( instance ),
188 MAIN_WINDOW_SIGNAL_SELECTION_CHANGED,
189 G_CALLBACK( on_tab_updatable_selection_changed ));
191 nact_match_list_init_view( BASE_WINDOW( instance ), ITAB_NAME );
195 void
196 nact_imimetypes_tab_all_widgets_showed( NactIMimetypesTab *instance )
198 static const gchar *thisfn = "nact_imimetypes_tab_all_widgets_showed";
200 g_return_if_fail( NACT_IS_IMIMETYPES_TAB( instance ));
202 if( st_initialized && !st_finalized ){
204 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
209 * nact_imimetypes_tab_dispose:
210 * @window: this #NactIMimetypesTab instance.
212 * Called at instance_dispose time.
214 void
215 nact_imimetypes_tab_dispose( NactIMimetypesTab *instance )
217 static const gchar *thisfn = "nact_imimetypes_tab_dispose";
219 g_return_if_fail( NACT_IS_IMIMETYPES_TAB( instance ));
221 if( st_initialized && !st_finalized ){
223 g_debug( "%s: instance=%p", thisfn, ( void * ) instance );
225 nact_match_list_dispose( BASE_WINDOW( instance ), ITAB_NAME );
229 static void
230 on_tab_updatable_selection_changed( BaseWindow *window, gint count_selected )
232 nact_match_list_on_selection_changed( window, ITAB_NAME, count_selected );
235 static GSList *
236 get_mimetypes( void *context )
238 return( na_object_get_mimetypes( context ));
241 static void
242 set_mimetypes( void *context, GSList *filters )
244 na_object_set_mimetypes( context, filters );