1 /* preferences dialog
2 */
3
4 /*
5
6 Copyright (C) 1991-2003 The National Gallery
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22 */
23
24 /*
25
26 These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
27
28 */
29
30 #include "ip.h"
31
32 /*
33 #define DEBUG
34 */
35
36 static iDialogClass *parent_class = NULL;
37
38 static void
prefs_destroy(GtkObject * object)39 prefs_destroy( GtkObject *object )
40 {
41 Prefs *prefs = PREFS( object );
42
43 #ifdef DEBUG
44 printf( "prefs_destroy\n" );
45 #endif /*DEBUG*/
46
47 if( prefs->ws ) {
48 Workspacegroup *wsg = workspace_get_workspacegroup( prefs->ws );
49 Filemodel *filemodel = FILEMODEL( wsg );
50
51 /* Force a recalc, in case we've changed the autorecalc
52 * settings. Also does a scan on any widgets.
53 */
54 symbol_recalculate_all_force( TRUE );
55
56 if( filemodel->modified &&
57 filemodel_top_save( filemodel, filemodel->filename ) )
58 filemodel_set_modified( filemodel, FALSE );
59 }
60
61 /* My instance destroy stuff.
62 */
63 FREESID( prefs->destroy_sid, prefs->ws );
64 IM_FREE( prefs->caption_filter );
65 prefs->ws = NULL;
66
67 GTK_OBJECT_CLASS( parent_class )->destroy( object );
68 }
69
70 static void
prefs_build(GtkWidget * widget)71 prefs_build( GtkWidget *widget )
72 {
73 Prefs *prefs = PREFS( widget );
74 GtkWidget *work;
75
76 #ifdef DEBUG
77 printf( "prefs_build: %p\n", prefs );
78 #endif /*DEBUG*/
79
80 /* Call all builds in superclasses.
81 */
82 IWINDOW_CLASS( parent_class )->build( widget );
83
84 work = IDIALOG( prefs )->work;
85
86 prefs->pwview = PREFWORKSPACEVIEW( prefworkspaceview_new() );
87 prefworkspaceview_set_caption_filter( prefs->pwview,
88 prefs->caption_filter );
89 view_link( VIEW( prefs->pwview ), MODEL( prefs->ws ), NULL );
90
91 if( prefs->caption_filter ) {
92 gtk_box_pack_start( GTK_BOX( work ),
93 GTK_WIDGET( prefs->pwview ), TRUE, TRUE, 0 );
94
95 gtk_widget_show( GTK_WIDGET( prefs->pwview ) );
96 }
97 else {
98 /* No caption_filter set, so this is probably a big prefs
99 * window. Build a scrolledwindow for the content.
100 */
101 GtkWidget *window;
102
103 window = gtk_scrolled_window_new( NULL, NULL );
104 gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( window ),
105 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
106 gtk_scrolled_window_add_with_viewport(
107 GTK_SCROLLED_WINDOW( window ),
108 GTK_WIDGET( prefs->pwview ) );
109 gtk_viewport_set_shadow_type(
110 GTK_VIEWPORT( GTK_BIN( window )->child ),
111 GTK_SHADOW_NONE );
112 gtk_box_pack_start( GTK_BOX( work ),
113 GTK_WIDGET( window ), TRUE, TRUE, 0 );
114
115 gtk_widget_show( GTK_WIDGET( prefs->pwview ) );
116 gtk_widget_show( window );
117 }
118 }
119
120 static void
prefs_class_init(PrefsClass * class)121 prefs_class_init( PrefsClass *class )
122 {
123 GtkObjectClass *gobject_class = (GtkObjectClass *) class;
124 iWindowClass *iwindow_class = (iWindowClass *) class;
125
126 parent_class = g_type_class_peek_parent( class );
127
128 gobject_class->destroy = prefs_destroy;
129
130 iwindow_class->build = prefs_build;
131
132 /* Create signals.
133 */
134
135 /* Init methods.
136 */
137 }
138
139 static void
prefs_init(Prefs * prefs)140 prefs_init( Prefs *prefs )
141 {
142 prefs->ws = NULL;
143 prefs->destroy_sid = 0;
144 }
145
146 GType
prefs_get_type(void)147 prefs_get_type( void )
148 {
149 static GType type = 0;
150
151 if( !type ) {
152 static const GTypeInfo info = {
153 sizeof( PrefsClass ),
154 NULL, /* base_init */
155 NULL, /* base_finalize */
156 (GClassInitFunc) prefs_class_init,
157 NULL, /* class_finalize */
158 NULL, /* class_data */
159 sizeof( Prefs ),
160 32, /* n_preallocs */
161 (GInstanceInitFunc) prefs_init,
162 };
163
164 type = g_type_register_static( TYPE_IDIALOG,
165 "Prefs", &info, 0 );
166 }
167
168 return( type );
169 }
170
171 static void
prefs_workspace_destroy_cb(Workspace * ws,Prefs * prefs)172 prefs_workspace_destroy_cb( Workspace *ws, Prefs *prefs )
173 {
174 prefs->destroy_sid = 0;
175 prefs->ws = NULL;
176
177 iwindow_kill( IWINDOW( prefs ) );
178 }
179
180 static void
prefs_link(Prefs * prefs,Workspace * ws)181 prefs_link( Prefs *prefs, Workspace *ws )
182 {
183 g_assert( !prefs->ws );
184
185 prefs->ws = ws;
186 prefs->ws->mode = WORKSPACE_MODE_NOEDIT;
187 prefs->destroy_sid = g_signal_connect( ws, "destroy",
188 G_CALLBACK( prefs_workspace_destroy_cb ), prefs );
189 }
190
191 static gint
prefs_column_compare(Column * a,Column * b)192 prefs_column_compare( Column *a, Column *b )
193 {
194 return( b->y - a->y );
195 }
196
197 Prefs *
prefs_new(const char * caption_filter)198 prefs_new( const char *caption_filter )
199 {
200 Symbol *wsr_sym = main_workspaceroot->sym;
201 Symbol *ws_sym = SYMBOL( icontainer_child_lookup(
202 ICONTAINER( wsr_sym->expr->compile ), "Preferences" ) );
203 Prefs *prefs;
204
205 if( !ws_sym ) {
206 /* Probably failed to load prefs on startup for some reason.
207 */
208 error_top( _( "Unable to display preferences." ) );
209 error_sub( _( "No preferences workspace was found. "
210 "Preferences probably failed to load when "
211 "%s started." ),
212 PACKAGE );
213 return( NULL );
214 }
215
216 icontainer_custom_sort( ICONTAINER( ws_sym->ws ),
217 (GCompareFunc) prefs_column_compare );
218 prefs = PREFS( g_object_new( TYPE_PREFS, NULL ) );
219 IM_SETSTR( prefs->caption_filter, caption_filter );
220 prefs_link( prefs, ws_sym->ws );
221
222 return( prefs );
223 }
224
225 gboolean
prefs_set(const char * name,const char * fmt,...)226 prefs_set( const char *name, const char *fmt, ... )
227 {
228 Watch *watch;
229
230 if( main_watchgroup &&
231 (watch = watch_find( main_watchgroup, name )) ) {
232 va_list args;
233
234 va_start( args, fmt );
235 watch_vset( watch, fmt, args );
236 va_end( args );
237 }
238
239 return( TRUE );
240 }
241