preferences-dialog.c 74.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/* The GIMP -- an image manipulation program
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */
18
19
#include <string.h>

20
21
#include "appenv.h"
#include "colormaps.h"
22
#include "context_manager.h"
23
#include "gdisplay_ops.h"
24
#include "gdisplay.h"
25
#include "gimprc.h"
26
#include "gimpui.h"
27
#include "image_render.h"
28
#include "lc_dialog.h"
29
#include "layer_select.h"
30
#include "session.h"
31

32
#include "config.h"
33
#include "libgimp/gimpchainbutton.h"
34
35
#include "libgimp/gimpfileselection.h"
#include "libgimp/gimppatheditor.h"
36
#include "libgimp/gimpsizeentry.h"
37
#include "libgimp/gimplimits.h"
38
#include "libgimp/gimpintl.h"
39
40

/*  preferences local functions  */
41
42
static void file_prefs_ok_callback     (GtkWidget *, GtkWidget *);
static void file_prefs_save_callback   (GtkWidget *, GtkWidget *);
43
static void file_prefs_cancel_callback (GtkWidget *, GtkWidget *);
44

45
46
static void file_prefs_toggle_callback             (GtkWidget *, gpointer);
static void file_prefs_preview_size_callback       (GtkWidget *, gpointer);
47
static void file_prefs_nav_preview_size_callback   (GtkWidget *, gpointer);
48
49
50
51
52
53
static void file_prefs_mem_size_callback           (GtkWidget *, gpointer);
static void file_prefs_mem_size_unit_callback      (GtkWidget *, gpointer);
static void file_prefs_int_adjustment_callback     (GtkAdjustment *, gpointer);
static void file_prefs_string_callback             (GtkWidget *, gpointer);
static void file_prefs_filename_callback           (GtkWidget *, gpointer);
static void file_prefs_path_callback               (GtkWidget *, gpointer);
54
static void file_prefs_clear_session_info_callback (GtkWidget *, gpointer);
55
static void file_prefs_default_size_callback       (GtkWidget *, gpointer);
56
static void file_prefs_default_resolution_callback (GtkWidget *, gpointer);
57
static void file_prefs_res_source_callback         (GtkWidget *, gpointer);
58
static void file_prefs_monitor_resolution_callback (GtkWidget *, gpointer);
59
60

/*  static variables  */
61
62
63
64
65
66
67
68
static int        old_perfectmouse;
static int        old_transparency_type;
static int        old_transparency_size;
static int        old_levels_of_undo;
static int        old_marching_speed;
static int        old_allow_resize_windows;
static int        old_auto_save;
static int        old_preview_size;
69
static int        old_nav_preview_size;
70
71
72
73
static int        old_no_cursor_updating;
static int        old_show_tool_tips;
static int        old_show_rulers;
static int        old_show_statusbar;
74
static InterpolationType old_interpolation_type;
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
static int        old_confirm_on_close;
static int        old_save_session_info;
static int        old_save_device_status;
static int        old_always_restore_session;
static int        old_default_width;
static int        old_default_height;
static GUnit      old_default_units;
static double     old_default_xresolution;
static double     old_default_yresolution;
static GUnit      old_default_resolution_units;
static int        old_default_type;
static int        old_stingy_memory_use;
static int        old_tile_cache_size;
static int        old_install_cmap;
static int        old_cycled_marching_ants;
static int        old_last_opened_size;
static char *     old_temp_path;
static char *     old_swap_path;
static char *     old_plug_in_path;
static char *     old_module_path;
static char *     old_brush_path;
96
static char *     old_brush_vbr_path;
97
98
99
100
101
102
103
104
105
106
static char *     old_pattern_path;
static char *     old_palette_path;
static char *     old_gradient_path;
static double     old_monitor_xres;
static double     old_monitor_yres;
static int        old_using_xserver_resolution;
static int        old_num_processors;
static char *     old_image_title_format;
static int        old_global_paint_options;
static int        old_max_new_image_size;
107
static int        old_thumbnail_mode;
108
static int 	  old_show_indicators;
109
static int	  old_trust_dirty_flag;
110
static int        old_use_help;
111
static int        old_nav_window_per_display;
112

Michael Natterer's avatar
Michael Natterer committed
113
/*  variables which can't be changed on the fly  */
114
115
116
117
118
119
120
121
122
123
124
static int        edit_stingy_memory_use;
static int        edit_tile_cache_size;
static int        edit_install_cmap;
static int        edit_cycled_marching_ants;
static int        edit_last_opened_size;
static int        edit_num_processors;
static char *     edit_temp_path = NULL;
static char *     edit_swap_path = NULL;
static char *     edit_plug_in_path = NULL;
static char *     edit_module_path = NULL;
static char *     edit_brush_path = NULL;
125
static char *     edit_brush_vbr_path = NULL;
126
127
128
static char *     edit_pattern_path = NULL;
static char *     edit_palette_path = NULL;
static char *     edit_gradient_path = NULL;
129
static int        edit_nav_window_per_display;
130
131

static GtkWidget *prefs_dlg = NULL;
132
133

/* Some information regarding preferences, compiled by Raph Levien 11/3/97.
134
   updated by Michael Natterer 27/3/99
135
136
137
138
139
140
141
142
143

   The following preference items cannot be set on the fly (at least
   according to the existing pref code - it may be that changing them
   so they're set on the fly is not hard).

   stingy-memory-use
   tile-cache-size
   install-cmap
   cycled-marching-ants
144
   last-opened-size
145
   num-processors
Michael Natterer's avatar
Michael Natterer committed
146
147
148
149
150
151
152
153
   temp-path
   swap-path
   plug-in-path
   module-path
   brush-path
   pattern-path
   palette-path
   gradient-path
154
   nav-window-per-display
155
156
157
158
159
160
161
162
163
164
165
166

   All of these now have variables of the form edit_temp_path, which
   are copied from the actual variables (e.g. temp_path) the first time
   the dialog box is started.

   Variables of the form old_temp_path represent the values at the
   time the dialog is opened - a cancel copies them back from old to
   the real variables or the edit variables, depending on whether they
   can be set on the fly.

   Here are the remaining issues as I see them:

167
168
169
   Still no settings for default-gradient, default-palette,
   gamma-correction, color-cube.

170
   No widget for confirm-on-close although a lot of stuff is there.
171
172
173
174
175
176
177
178
179

   The semantics of "save" are a little funny - it only saves the
   settings that are different from the way they were when the dialog
   was opened. So you can set something, close the window, open it
   up again, click "save" and have nothing happen. To change this
   to more intuitive semantics, we should have a whole set of init_
   variables that are set the first time the dialog is opened (along
   with the edit_ variables that are currently set). Then, the save
   callback checks against the init_ variable rather than the old_.
180
*/
181
182
183
184

/* Copy the string from source to destination, freeing the string stored
   in the destination if there is one there already. */
static void
185
186
file_prefs_strset (gchar **dst,
		   gchar  *src)
187
{
188
  if (*dst)
189
    g_free (*dst);
190

191
192
193
194
  *dst = g_strdup (src);
}

/* Duplicate the string, but treat NULL as the empty string. */
195
196
static gchar *
file_prefs_strdup (gchar *src)
197
198
199
200
201
202
{
  return g_strdup (src == NULL ? "" : src);
}

/* Compare two strings, but treat NULL as the empty string. */
static int
203
204
file_prefs_strcmp (gchar *src1,
		   gchar *src2)
205
206
{
  return strcmp (src1 == NULL ? "" : src1,
207
		 src2 == NULL ? "" : src2);
208
209
210
211
212
213
214
215
}

static void
file_prefs_ok_callback (GtkWidget *widget,
			GtkWidget *dlg)
{
  if (levels_of_undo < 0) 
    {
216
      g_message (_("Error: Levels of undo must be zero or greater."));
217
218
219
      levels_of_undo = old_levels_of_undo;
      return;
    }
220
221
222
223
224
225
  if (num_processors < 1 || num_processors > 30) 
    {
      g_message (_("Error: Number of processors must be between 1 and 30."));
      num_processors = old_num_processors;
      return;
    }
226
227
  if (marching_speed < 50)
    {
228
      g_message (_("Error: Marching speed must be 50 or greater."));
229
230
231
232
233
      marching_speed = old_marching_speed;
      return;
    }
  if (default_width < 1)
    {
234
      g_message (_("Error: Default width must be one or greater."));
235
236
237
238
239
      default_width = old_default_width;
      return;
    }
  if (default_height < 1)
    {
240
      g_message (_("Error: Default height must be one or greater."));
241
242
      default_height = old_default_height;
      return;
243
    }
244
245
246
  if (default_units < UNIT_INCH ||
      default_units >= gimp_unit_get_number_of_units ())
    {
Michael Natterer's avatar
Michael Natterer committed
247
      g_message (_("Error: Default unit must be within unit range."));
248
249
250
      default_units = old_default_units;
      return;
    }
251
252
  if (default_xresolution < GIMP_MIN_RESOLUTION ||
      default_yresolution < GIMP_MIN_RESOLUTION)
253
    {
Sven Neumann's avatar
Sven Neumann committed
254
      g_message (_("Error: Default resolution must not be zero."));
255
256
257
258
259
260
261
      default_xresolution = old_default_xresolution;
      default_yresolution = old_default_yresolution;
      return;
    }
  if (default_resolution_units < UNIT_INCH ||
      default_resolution_units >= gimp_unit_get_number_of_units ())
    {
Michael Natterer's avatar
Michael Natterer committed
262
      g_message (_("Error: Default resolution unit must be within unit range."));
263
264
265
      default_resolution_units = old_default_resolution_units;
      return;
    }
266
267
  if (monitor_xres < GIMP_MIN_RESOLUTION ||
      monitor_yres < GIMP_MIN_RESOLUTION)
268
    {
Michael Natterer's avatar
Michael Natterer committed
269
      g_message (_("Error: Monitor resolution must not be zero."));
270
271
272
273
      monitor_xres = old_monitor_xres;
      monitor_yres = old_monitor_yres;
      return;
    }
274
275
  if (image_title_format == NULL)
    {
Michael Natterer's avatar
Michael Natterer committed
276
      g_message (_("Error: Image title format must not be NULL."));
277
278
279
      image_title_format = old_image_title_format;
      return;
    }
280

281
282
283
284
  gtk_widget_destroy (dlg);
  prefs_dlg = NULL;

  if (show_tool_tips)
285
    gimp_help_enable_tooltips ();
286
  else
287
    gimp_help_disable_tooltips ();
288
289
290
291
292

  /* This needs modification to notify the user of which simply cannot be
   * changed on the fly.  Currently it ignores these options if only OK is
   * pressed.
   */
293
294
295
296
297
298
299
300
}

static void
file_prefs_save_callback (GtkWidget *widget,
			  GtkWidget *dlg)
{
  GList *update = NULL; /* options that should be updated in .gimprc */
  GList *remove = NULL; /* options that should be commented out */
Michael Natterer's avatar
Michael Natterer committed
301

302
303
304
305
306
  int    save_stingy_memory_use;
  int    save_tile_cache_size;
  int    save_install_cmap;
  int    save_cycled_marching_ants;
  int    save_last_opened_size;
Michael Natterer's avatar
Michael Natterer committed
307
  int    save_num_processors;
308
  int    save_nav_window_per_display;
309
310
  gchar *save_temp_path;
  gchar *save_swap_path;
Michael Natterer's avatar
Michael Natterer committed
311
312
  gchar *save_plug_in_path;
  gchar *save_module_path;
313
  gchar *save_brush_path;
314
  gchar *save_brush_vbr_path;
315
316
317
  gchar *save_pattern_path;
  gchar *save_palette_path;
  gchar *save_gradient_path;
Michael Natterer's avatar
Michael Natterer committed
318

319
  int    restart_notification = FALSE;
320
321
322
323
324
325
326
327

  file_prefs_ok_callback (widget, dlg);

  /* Save variables so that we can restore them later */
  save_stingy_memory_use = stingy_memory_use;
  save_tile_cache_size = tile_cache_size;
  save_install_cmap = install_cmap;
  save_cycled_marching_ants = cycled_marching_ants;
328
  save_last_opened_size = last_opened_size;
Michael Natterer's avatar
Michael Natterer committed
329
  save_num_processors = num_processors;
330
331
  save_temp_path = temp_path;
  save_swap_path = swap_path;
Michael Natterer's avatar
Michael Natterer committed
332
333
  save_plug_in_path = plug_in_path;
  save_module_path = module_path;
334
  save_brush_path = brush_path;
335
  save_brush_vbr_path = brush_vbr_path;
336
337
338
  save_pattern_path = pattern_path;
  save_palette_path = palette_path;
  save_gradient_path = gradient_path;
339
  save_nav_window_per_display = nav_window_per_display;
340
341
342
343
344

  if (levels_of_undo != old_levels_of_undo)
    update = g_list_append (update, "undo-levels");
  if (marching_speed != old_marching_speed)
    update = g_list_append (update, "marching-ants-speed");
345
346
  if (last_opened_size != old_last_opened_size)
    update = g_list_append (update, "last-opened-size");
347
  if (allow_resize_windows != old_allow_resize_windows)
348
349
350
351
    {
      update = g_list_append (update, "allow-resize-windows");
      remove = g_list_append (remove, "dont-allow-resize-windows");
    }
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
  if (auto_save != old_auto_save)
    {
      update = g_list_append (update, "auto-save");
      remove = g_list_append (remove, "dont-auto-save");
    }
  if (no_cursor_updating != old_no_cursor_updating)
    {
      update = g_list_append (update, "cursor-updating");
      remove = g_list_append (remove, "no-cursor-updating");
    }
  if (show_tool_tips != old_show_tool_tips)
    {
      update = g_list_append (update, "show-tool-tips");
      remove = g_list_append (remove, "dont-show-tool-tips");
    }
367
368
369
370
371
372
373
374
375
376
  if (show_rulers != old_show_rulers)
    {
      update = g_list_append (update, "show-rulers");
      remove = g_list_append (remove, "dont-show-rulers");
    }
  if (show_statusbar != old_show_statusbar)
    {
      update = g_list_append (update, "show-statusbar");
      remove = g_list_append (remove, "dont-show-statusbar");
    }
377
378
  if (interpolation_type != old_interpolation_type)
    update = g_list_append (update, "interpolation-type");
379
  if (confirm_on_close != old_confirm_on_close)
380
381
382
383
    {
      update = g_list_append (update, "confirm-on-close");
      remove = g_list_append (remove, "dont-confirm-on-close");
    }
384
  if (save_session_info != old_save_session_info)
385
    {
386
387
      update = g_list_append (update, "save-session-info");
      remove = g_list_append (remove, "dont-save-session-info");
388
    }
Sven Neumann's avatar
Sven Neumann committed
389
390
391
392
393
  if (save_device_status!= old_save_device_status)
    {
      update = g_list_append (update, "save-device-status");
      remove = g_list_append (remove, "dont-save-device-status");
    }
394
395
396
397
398
399
  if (show_indicators != old_show_indicators)
    {
      update = g_list_append (update, "show-indicators");
      remove = g_list_append (remove, "dont-show-indicators");
      restart_notification = TRUE;
    }
400
401
  if (always_restore_session != old_always_restore_session)
    update = g_list_append (update, "always-restore-session");
402
403
404
  if (default_width != old_default_width ||
      default_height != old_default_height)
    update = g_list_append (update, "default-image-size");
405
406
  if (default_units != old_default_units)
    update = g_list_append (update, "default-units");
407
  if (ABS(default_xresolution - old_default_xresolution) > GIMP_MIN_RESOLUTION)
408
    update = g_list_append (update, "default-xresolution");
409
  if (ABS(default_yresolution - old_default_yresolution) > GIMP_MIN_RESOLUTION)
410
411
412
    update = g_list_append (update, "default-yresolution");
  if (default_resolution_units != old_default_resolution_units)
    update = g_list_append (update, "default-resolution-units");
413
414
415
416
  if (default_type != old_default_type)
    update = g_list_append (update, "default-image-type");
  if (preview_size != old_preview_size)
    update = g_list_append (update, "preview-size");
417
418
  if (nav_preview_size != old_nav_preview_size)
    update = g_list_append (update, "nav-preview-size");
419
420
  if (perfectmouse != old_perfectmouse)
    update = g_list_append (update, "perfect-mouse");
421
422
423
424
  if (transparency_type != old_transparency_type)
    update = g_list_append (update, "transparency-type");
  if (transparency_size != old_transparency_size)
    update = g_list_append (update, "transparency-size");
425
  if (using_xserver_resolution != old_using_xserver_resolution ||
426
      ABS(monitor_xres - old_monitor_xres) > GIMP_MIN_RESOLUTION)
427
428
    update = g_list_append (update, "monitor-xresolution");
  if (using_xserver_resolution != old_using_xserver_resolution ||
429
      ABS(monitor_yres - old_monitor_yres) > GIMP_MIN_RESOLUTION)
430
    update = g_list_append (update, "monitor-yresolution");
431
432
  if (edit_num_processors != num_processors)
    update = g_list_append (update, "num-processors");
433
434
435
436
437
438
  if (edit_stingy_memory_use != stingy_memory_use)
    {
      update = g_list_append (update, "stingy-memory-use");
      stingy_memory_use = edit_stingy_memory_use;
      restart_notification = TRUE;
    }
439
  if (edit_tile_cache_size != tile_cache_size)
440
441
    {
      update = g_list_append (update, "tile-cache-size");
442
      tile_cache_size = edit_tile_cache_size;
443
444
445
446
447
448
449
450
451
452
453
454
455
456
      restart_notification = TRUE;
    }
  if (edit_install_cmap != old_install_cmap)
    {
      update = g_list_append (update, "install-colormap");
      install_cmap = edit_install_cmap;
      restart_notification = TRUE;
    }
  if (edit_cycled_marching_ants != cycled_marching_ants)
    {
      update = g_list_append (update, "colormap-cycling");
      cycled_marching_ants = edit_cycled_marching_ants;
      restart_notification = TRUE;
    }
457
458
459
460
461
462
  if (edit_last_opened_size != last_opened_size)
    {
      update = g_list_append (update, "last-opened-size");
      last_opened_size = edit_last_opened_size;
      restart_notification = TRUE;
    }
463
464
465
466
467
468
469
470
471
472
473
474
  if (file_prefs_strcmp (temp_path, edit_temp_path))
    {
      update = g_list_append (update, "temp-path");
      temp_path = edit_temp_path;
      restart_notification = TRUE;
    }
  if (file_prefs_strcmp (swap_path, edit_swap_path))
    {
      update = g_list_append (update, "swap-path");
      swap_path = edit_swap_path;
      restart_notification = TRUE;
    }
Michael Natterer's avatar
Michael Natterer committed
475
476
477
478
479
480
481
482
483
484
485
486
  if (file_prefs_strcmp (plug_in_path, edit_plug_in_path))
    {
      update = g_list_append (update, "plug-in-path");
      plug_in_path = edit_plug_in_path;
      restart_notification = TRUE;
    }
  if (file_prefs_strcmp (module_path, edit_module_path))
    {
      update = g_list_append (update, "module-path");
      module_path = edit_module_path;
      restart_notification = TRUE;
    }
487
488
489
490
491
492
  if (file_prefs_strcmp (brush_path, edit_brush_path))
    {
      update = g_list_append (update, "brush-path");
      brush_path = edit_brush_path;
      restart_notification = TRUE;
    }
493
494
495
496
497
498
  if (file_prefs_strcmp (brush_vbr_path, edit_brush_vbr_path))
    {
      update = g_list_append (update, "brush-vbr-path");
      brush_vbr_path = edit_brush_vbr_path;
      restart_notification = TRUE;
    }
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
  if (file_prefs_strcmp (pattern_path, edit_pattern_path))
    {
      update = g_list_append (update, "pattern-path");
      pattern_path = edit_pattern_path;
      restart_notification = TRUE;
    }
  if (file_prefs_strcmp (palette_path, edit_palette_path))
    {
      update = g_list_append (update, "palette-path");
      palette_path = edit_palette_path;
      restart_notification = TRUE;
    }
  if (file_prefs_strcmp (gradient_path, edit_gradient_path))
    {
      update = g_list_append (update, "gradient-path");
      gradient_path = edit_gradient_path;
      restart_notification = TRUE;
    }
517
518
519
520
521
522
523
  if (using_xserver_resolution)
    {
      /* special value of 0 for either x or y res in the gimprc file
       * means use the xserver's current resolution */
      monitor_xres = 0.0;
      monitor_yres = 0.0;
    }
524
525
  if (file_prefs_strcmp (image_title_format, old_image_title_format))
    update = g_list_append (update, "image-title-format");
526
527
528
529
530
  if (global_paint_options != old_global_paint_options)
    {
      update = g_list_append (update, "global-paint-options");
      remove = g_list_append (remove, "no-global-paint-options");
    }
531
532
  if (max_new_image_size != old_max_new_image_size)
    update = g_list_append (update, "max-new-image-size");
533
534
  if (thumbnail_mode != old_thumbnail_mode)
    update = g_list_append (update, "thumbnail-mode");
535
  if (trust_dirty_flag != old_trust_dirty_flag)
Sven Neumann's avatar
Sven Neumann committed
536
537
538
539
    {
      update = g_list_append (update, "trust-dirty-flag");
      remove = g_list_append (update, "dont-trust-dirty-flag");
    }
540
541
542
543
544
  if (use_help != old_use_help)
    {
      update = g_list_append (update, "use-help");
      remove = g_list_append (remove, "dont-use-help");
    }
545
546
547
548
549
550
551
  if (edit_nav_window_per_display != old_nav_window_per_display)
    {
      update = g_list_append (update, "nav-window-per-display");
      remove = g_list_append (remove, "nav-window-follows-auto");
      nav_window_per_display = edit_nav_window_per_display;
      restart_notification = TRUE;
    }
552

553
554
  save_gimprc (&update, &remove);

555
  if (using_xserver_resolution)
556
    gdisplay_xserver_resolution (&monitor_xres, &monitor_yres);
557

558
559
560
561
562
  /* Restore variables which must not change */
  stingy_memory_use = save_stingy_memory_use;
  tile_cache_size = save_tile_cache_size;
  install_cmap = save_install_cmap;
  cycled_marching_ants = save_cycled_marching_ants;
563
  last_opened_size = save_last_opened_size;
Michael Natterer's avatar
Michael Natterer committed
564
  num_processors = save_num_processors;
565
566
  temp_path = save_temp_path;
  swap_path = save_swap_path;
Michael Natterer's avatar
Michael Natterer committed
567
568
  plug_in_path = save_plug_in_path;
  module_path = save_module_path;
569
  brush_path = save_brush_path;
570
  brush_vbr_path = save_brush_vbr_path;
571
572
573
  pattern_path = save_pattern_path;
  palette_path = save_palette_path;
  gradient_path = save_gradient_path;
574
  nav_window_per_display = save_nav_window_per_display;
575
576

  if (restart_notification)
577
578
579
    g_message (_("You will need to restart GIMP for these changes to take "
		 "effect."));

580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
  g_list_free (update);
  g_list_free (remove);
}

static void
file_prefs_cancel_callback (GtkWidget *widget,
			    GtkWidget *dlg)
{
  gtk_widget_destroy (dlg);
  prefs_dlg = NULL;

  levels_of_undo = old_levels_of_undo;
  marching_speed = old_marching_speed;
  allow_resize_windows = old_allow_resize_windows;
  auto_save = old_auto_save;
  no_cursor_updating = old_no_cursor_updating;
596
  perfectmouse = old_perfectmouse;
597
  show_tool_tips = old_show_tool_tips;
598
599
  show_rulers = old_show_rulers;
  show_statusbar = old_show_statusbar;
600
  interpolation_type = old_interpolation_type;
601
  confirm_on_close = old_confirm_on_close;
602
  save_session_info = old_save_session_info;
Sven Neumann's avatar
Sven Neumann committed
603
  save_device_status = old_save_device_status;
604
605
  default_width = old_default_width;
  default_height = old_default_height;
606
607
608
609
  default_units = old_default_units;
  default_xresolution = old_default_xresolution;
  default_yresolution = old_default_yresolution;
  default_resolution_units = old_default_resolution_units;
610
  default_type = old_default_type;
611
612
613
  monitor_xres = old_monitor_xres;
  monitor_yres = old_monitor_yres;
  using_xserver_resolution = old_using_xserver_resolution;
614
  num_processors = old_num_processors;
615
  max_new_image_size = old_max_new_image_size;
616
  thumbnail_mode = old_thumbnail_mode;
617
  show_indicators = old_show_indicators;
618
  trust_dirty_flag = old_trust_dirty_flag;
619
  use_help = old_use_help;
620
  nav_window_per_display = old_nav_window_per_display;
621

622
623
624
625
626
627
  if (preview_size != old_preview_size)
    {
      lc_dialog_rebuild (old_preview_size);
      layer_select_update_preview_size ();
    }

628
629
630
631
632
633
  if (nav_preview_size != old_nav_preview_size)
    {
      nav_preview_size = old_nav_preview_size;
      gdisplays_nav_preview_resized();
    }

634
635
636
637
638
639
640
  if ((transparency_type != old_transparency_type) ||
      (transparency_size != old_transparency_size))
    {
      transparency_type = old_transparency_type;
      transparency_size = old_transparency_size;

      render_setup (transparency_type, transparency_size);
641
      gimage_foreach ((GFunc)layer_invalidate_previews, NULL);
642
643
644
645
646
647
648
649
650
      gimage_invalidate_previews ();
      gdisplays_expose_full ();
      gdisplays_flush ();
    }

  edit_stingy_memory_use = old_stingy_memory_use;
  edit_tile_cache_size = old_tile_cache_size;
  edit_install_cmap = old_install_cmap;
  edit_cycled_marching_ants = old_cycled_marching_ants;
651
  edit_last_opened_size = old_last_opened_size;
652
  edit_nav_window_per_display = nav_window_per_display;
653

654
655
  file_prefs_strset (&edit_temp_path, old_temp_path);
  file_prefs_strset (&edit_swap_path, old_swap_path);
Michael Natterer's avatar
Michael Natterer committed
656
657
  file_prefs_strset (&edit_plug_in_path, old_plug_in_path);
  file_prefs_strset (&edit_module_path, old_module_path);
658
  file_prefs_strset (&edit_brush_path, old_brush_path);
659
  file_prefs_strset (&edit_brush_vbr_path, old_brush_vbr_path);
660
661
662
  file_prefs_strset (&edit_pattern_path, old_pattern_path);
  file_prefs_strset (&edit_palette_path, old_palette_path);
  file_prefs_strset (&edit_gradient_path, old_gradient_path);
663
664

  file_prefs_strset (&image_title_format, old_image_title_format);
665

666
  context_manager_set_global_paint_options (old_global_paint_options);
667
668
669
670
671
672
673
674
}

static void
file_prefs_toggle_callback (GtkWidget *widget,
			    gpointer   data)
{
  int *val;

675
  if (data == &allow_resize_windows)
676
    allow_resize_windows = GTK_TOGGLE_BUTTON (widget)->active;
677
  else if (data == &auto_save)
678
    auto_save = GTK_TOGGLE_BUTTON (widget)->active;
679
  else if (data == &no_cursor_updating)
680
    no_cursor_updating = GTK_TOGGLE_BUTTON (widget)->active;
681
682
  else if (data == &perfectmouse)
    perfectmouse = GTK_TOGGLE_BUTTON (widget)->active;
683
  else if (data == &show_tool_tips)
684
    show_tool_tips = GTK_TOGGLE_BUTTON (widget)->active;
685
686
687
688
  else if (data == &show_rulers)
    show_rulers = GTK_TOGGLE_BUTTON (widget)->active;
  else if (data == &show_statusbar)
    show_statusbar = GTK_TOGGLE_BUTTON (widget)->active;
689
  else if (data == &confirm_on_close)
690
    confirm_on_close = GTK_TOGGLE_BUTTON (widget)->active;
691
692
  else if (data == &save_session_info)
    save_session_info = GTK_TOGGLE_BUTTON (widget)->active;
Sven Neumann's avatar
Sven Neumann committed
693
694
  else if (data == &save_device_status)
    save_device_status = GTK_TOGGLE_BUTTON (widget)->active;
695
696
  else if (data == &always_restore_session)
    always_restore_session = GTK_TOGGLE_BUTTON (widget)->active;
697
  else if (data == &edit_stingy_memory_use)
698
    edit_stingy_memory_use = GTK_TOGGLE_BUTTON (widget)->active;
699
  else if (data == &edit_install_cmap)
700
    edit_install_cmap = GTK_TOGGLE_BUTTON (widget)->active;
701
  else if (data == &edit_cycled_marching_ants)
702
    edit_cycled_marching_ants = GTK_TOGGLE_BUTTON (widget)->active;
703
  else if (data == &default_type)
704
705
706
    {
      default_type = (long) gtk_object_get_user_data (GTK_OBJECT (widget));
    } 
707
708
  else if ((data == &transparency_type) ||
	   (data == &transparency_size))
709
710
711
712
    {
      val = data;
      *val = (long) gtk_object_get_user_data (GTK_OBJECT (widget));
      render_setup (transparency_type, transparency_size);
713
      gimage_foreach ((GFunc)layer_invalidate_previews, NULL);
714
715
716
717
      gimage_invalidate_previews ();
      gdisplays_expose_full ();
      gdisplays_flush ();
    }
718
  else if (data == &global_paint_options)
719
    context_manager_set_global_paint_options (GTK_TOGGLE_BUTTON (widget)->active);
720
721
  else if (data == &show_indicators)
    show_indicators = GTK_TOGGLE_BUTTON (widget)->active;
722
723
  else if (data == &thumbnail_mode || data == &interpolation_type ||
           data == &trust_dirty_flag)
724
725
726
727
    {
      val = data;
      *val = (long) gtk_object_get_user_data (GTK_OBJECT (widget));
    }
728
729
  else if (data == &use_help)
    use_help = GTK_TOGGLE_BUTTON (widget)->active;
730
731
  else if (data == &edit_nav_window_per_display)
    edit_nav_window_per_display = GTK_TOGGLE_BUTTON (widget)->active;
732
733
734
735
736
737
738
  else
    {
      /* Are you a gimp-hacker who is getting this message?  You
	 probably want to do the same as the &thumbnail_mode case
	 above is doing. */
      g_warning("Unknown file_prefs_toggle_callback() invoker - ignored.");
    }
739
740
741
742
743
744
}

static void
file_prefs_preview_size_callback (GtkWidget *widget,
                                  gpointer   data)
{
745
  lc_dialog_rebuild ((long) data);
746
747
748
  layer_select_update_preview_size ();
}

749
750
751
752
static void
file_prefs_nav_preview_size_callback (GtkWidget *widget,
				      gpointer   data)
{
753
754
  nav_preview_size = (gint) data;
  gdisplays_nav_preview_resized ();
755
756
}

757
758
759
760
static void
file_prefs_mem_size_callback (GtkWidget *widget,
			      gpointer   data)
{
761
762
763
  gint *mem_size;
  gint  divided_mem_size;
  gint  mem_size_unit;
764
765
766
767

  if (! (mem_size = gtk_object_get_data (GTK_OBJECT (widget), "mem_size")))
    return;

768
769
770
771
  divided_mem_size = (int) gtk_object_get_data (GTK_OBJECT (widget),
						"divided_mem_size");
  mem_size_unit = (int) gtk_object_get_data (GTK_OBJECT (widget),
					     "mem_size_unit");
772

773
774
  divided_mem_size = GTK_ADJUSTMENT (widget)->value;
  *mem_size = divided_mem_size * mem_size_unit;
775

776
777
  gtk_object_set_data (GTK_OBJECT (widget), "divided_mem_size",
		       (gpointer) divided_mem_size);
778
779
}

Sven Neumann's avatar
Sven Neumann committed
780
781
static void
file_prefs_mem_size_unit_callback (GtkWidget *widget,
782
				   gpointer   data)
Sven Neumann's avatar
Sven Neumann committed
783
{
784
  GtkObject *adjustment;
785
786
787
788
  gint  new_unit;
  gint *mem_size;
  gint  divided_mem_size;
  gint  mem_size_unit;
Sven Neumann's avatar
Sven Neumann committed
789

790
  adjustment = GTK_OBJECT (data);
Sven Neumann's avatar
Sven Neumann committed
791

792
  new_unit = (int) gtk_object_get_user_data (GTK_OBJECT (widget));
793
794
795
796

  if (! (mem_size = gtk_object_get_data (GTK_OBJECT (adjustment), "mem_size")))
    return;

797
798
799
800
  divided_mem_size = (int) gtk_object_get_data (GTK_OBJECT (adjustment),
						"divided_mem_size");
  mem_size_unit = (int) gtk_object_get_data (GTK_OBJECT (adjustment),
					     "mem_size_unit");
801

802
  if (new_unit != mem_size_unit)
803
    {
804
805
806
807
808
809
      divided_mem_size = *mem_size / new_unit;
      mem_size_unit = new_unit;

      gtk_signal_handler_block_by_data (GTK_OBJECT (adjustment), mem_size);
      gtk_adjustment_set_value (GTK_ADJUSTMENT (adjustment), divided_mem_size);
      gtk_signal_handler_unblock_by_data (GTK_OBJECT (adjustment), mem_size);
Sven Neumann's avatar
Sven Neumann committed
810
    }
811
812
813
814
815

  gtk_object_set_data (GTK_OBJECT (adjustment), "divided_mem_size",
		       (gpointer) divided_mem_size);
  gtk_object_set_data (GTK_OBJECT (adjustment), "mem_size_unit",
		       (gpointer) mem_size_unit);
Sven Neumann's avatar
Sven Neumann committed
816
817
}

818
static void
819
820
file_prefs_int_adjustment_callback (GtkAdjustment *adj,
				    gpointer       data)
Sven Neumann's avatar
Sven Neumann committed
821
{
822
  gint *val;
Sven Neumann's avatar
Sven Neumann committed
823
824

  val = data;
825
  *val = (int) adj->value;
Sven Neumann's avatar
Sven Neumann committed
826
827
}

828
829
830
831
832
833
834
835
836
837
static void
file_prefs_string_callback (GtkWidget *widget,
			    gpointer   data)
{
  gchar **val;

  val = data;
  file_prefs_strset (val, gtk_entry_get_text (GTK_ENTRY (widget)));
}

838
839
840
841
842
static void
file_prefs_filename_callback (GtkWidget *widget,
			      gpointer   data)
{
  gchar **val;
Sven Neumann's avatar
Sven Neumann committed
843
  gchar *filename;
844
845

  val = data;
Sven Neumann's avatar
Sven Neumann committed
846
847
848
  filename = gimp_file_selection_get_filename (GIMP_FILE_SELECTION (widget));
  file_prefs_strset (val, filename);
  g_free (filename);
849
850
851
852
853
854
855
}

static void
file_prefs_path_callback (GtkWidget *widget,
			  gpointer   data)
{
  gchar **val;
Sven Neumann's avatar
Sven Neumann committed
856
  gchar *path;
857
858

  val = data;
Sven Neumann's avatar
Sven Neumann committed
859
860
861
  path =  gimp_path_editor_get_path (GIMP_PATH_EDITOR (widget));
  file_prefs_strset (val, path);
  g_free (path);
862
863
}

864
static void
865
file_prefs_clear_session_info_callback (GtkWidget *widget,
866
					gpointer   data)
867
{
868
869
  g_list_free (session_info_updates);
  session_info_updates = NULL;
870
871
}

872
static void
873
file_prefs_default_size_callback (GtkWidget *widget,
874
				  gpointer   data)
875
{
876
877
878
879
  default_width = 
    (int) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0) + 0.5);
  default_height =
    (int) (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1) + 0.5);
880
881
882
883
884
  default_units = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (widget));
}

static void
file_prefs_default_resolution_callback (GtkWidget *widget,
885
					gpointer   data)
886
{
887
  GtkWidget *size_sizeentry;
888
889
890
891
  static gdouble xres = 0.0;
  static gdouble yres = 0.0;
  gdouble new_xres;
  gdouble new_yres;
892
893
894
895

  new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
  new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);

896
897
  size_sizeentry = gtk_object_get_data (GTK_OBJECT (widget), "size_sizeentry");

898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
  if (gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (data)))
    {
      if (new_xres != xres)
	{
	  yres = new_yres = xres = new_xres;
	  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 1, yres);
	}

      if (new_yres != yres)
	{
	  xres = new_xres = yres = new_yres;
	  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 0, xres);
	}
    }
  else
    {
      if (new_xres != xres)
	xres = new_xres;
      if (new_yres != yres)
	yres = new_yres;
    }

920
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry),
921
				  0, xres, FALSE);
922
  gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (size_sizeentry),
923
924
				  1, yres, FALSE);

925
926
927
928
  default_width = (gint)
    (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (size_sizeentry), 0) + 0.5);
  default_height = (gint)
    (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (size_sizeentry), 1) + 0.5);
929
930
931
932
933
  default_xresolution = xres;
  default_yresolution = yres;
  default_resolution_units = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (widget));
}

934
935
936
937
static void
file_prefs_res_source_callback (GtkWidget *widget,
				gpointer   data)
{
938
939
  GtkWidget *resolution_xserver_label;
  GtkWidget *monitor_resolution_sizeentry;
940

941
942
943
944
945
946
947
948
949
  resolution_xserver_label =
    gtk_object_get_data (GTK_OBJECT (widget), "resolution_xserver_label");
  monitor_resolution_sizeentry =
    gtk_object_get_data (GTK_OBJECT (widget), "monitor_resolution_sizeentry");

  gtk_widget_set_sensitive (resolution_xserver_label,
			    GTK_TOGGLE_BUTTON (widget)->active);
  gtk_widget_set_sensitive (monitor_resolution_sizeentry,
			    ! GTK_TOGGLE_BUTTON (widget)->active);
950
951
952

  if (GTK_TOGGLE_BUTTON (widget)->active)
    {
953
      gdisplay_xserver_resolution (&monitor_xres, &monitor_yres);
954
955
956
957
958
959
      using_xserver_resolution = TRUE;
    }
  else
    {
      if (monitor_resolution_sizeentry)
	{
960
961
962
963
	  monitor_xres = gimp_size_entry_get_refval
	    (GIMP_SIZE_ENTRY (monitor_resolution_sizeentry), 0);
	  monitor_yres = gimp_size_entry_get_refval
	    (GIMP_SIZE_ENTRY (monitor_resolution_sizeentry), 1);
964
965
966
967
968
	}
      using_xserver_resolution = FALSE;
    }
}

969
970
static void
file_prefs_monitor_resolution_callback (GtkWidget *widget,
971
					gpointer   data)
972
{
973
974
975
976
  static gdouble xres = 0.0;
  static gdouble yres = 0.0;
  gdouble new_xres;
  gdouble new_yres;
977
978
979
980

  new_xres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0);
  new_yres = gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1);

981
  if (gimp_chain_button_get_active (GIMP_CHAIN_BUTTON (data)))
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
    {
      if (new_xres != xres)
	{
	  yres = new_yres = xres = new_xres;
	  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 1, yres);
	}

      if (new_yres != yres)
	{
	  xres = new_xres = yres = new_yres;
	  gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (widget), 0, xres);
	}
    }
  else
    {
      if (new_xres != xres)
	xres = new_xres;
      if (new_yres != yres)
	yres = new_yres;
    }

  monitor_xres = xres;
  monitor_yres = yres;
}
1006

1007
/*  create a new notebook page  */
1008
static GtkWidget *
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
file_prefs_notebook_append_page (GtkNotebook   *notebook,
				 gchar         *notebook_label,
				 GtkCTree      *ctree,
				 gchar         *tree_label,
				 GtkCTreeNode  *parent,
				 GtkCTreeNode **new_node,
				 gint           page_index)
{
  GtkWidget *out_vbox;
  GtkWidget *vbox;
1019
1020
  GtkWidget *frame;
  GtkWidget *label;
1021
1022
1023
1024
1025
  gchar     *titles[1];

  out_vbox = gtk_vbox_new (FALSE, 0);
  gtk_widget_show (out_vbox);

1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
  frame = gtk_frame_new (NULL);
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
  gtk_box_pack_start (GTK_BOX (out_vbox), frame, FALSE, TRUE, 0);
  gtk_widget_show (frame);

  label = gtk_label_new (notebook_label);
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
  gtk_misc_set_padding (GTK_MISC (label), 2, 1);
  gtk_container_add (GTK_CONTAINER (frame), label);
  gtk_widget_show (label);
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045

  vbox = gtk_vbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (vbox), 4);
  gtk_container_add (GTK_CONTAINER (out_vbox), vbox);
  gtk_widget_show (vbox);

  titles[0] = tree_label;
  *new_node = gtk_ctree_insert_node (ctree, parent, NULL,
				     titles, 0,
				     NULL, NULL, NULL, NULL,
1046
				     FALSE, TRUE);
1047
  gtk_ctree_node_set_row_data (ctree, *new_node, (gpointer) page_index);
1048
1049
1050
1051
  gtk_notebook_append_page (notebook, out_vbox, NULL);

  return vbox;
}
1052

1053
1054
1055
1056
1057
1058
1059
/*  select a notebook page  */
static void
file_pref_tree_select_callback (GtkWidget    *widget,
				GtkCTreeNode *node)
{
  GtkNotebook *notebook;
  gint         page;
1060

1061
1062
  if (! GTK_CLIST (widget)->selection)
    return;
1063

1064
1065
  notebook = (GtkNotebook*) gtk_object_get_user_data (GTK_OBJECT (widget));
  page = (gint) gtk_ctree_node_get_row_data (GTK_CTREE (widget), node);
1066

1067
1068
  gtk_notebook_set_page (notebook, page);
}
1069

1070
1071
1072
1073
1074
1075
1076
1077
/*  create a frame with title and a vbox  */
static GtkWidget *
file_prefs_frame_new (gchar  *label,
		      GtkBox *vbox)
{
  GtkWidget *frame;
  GtkWidget *vbox2;

1078
  frame = gtk_frame_new (label);
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
  gtk_box_pack_start (vbox, frame, FALSE, FALSE, 0);
  gtk_widget_show (frame);

  vbox2 = gtk_vbox_new (FALSE, 2);
  gtk_container_set_border_width (GTK_CONTAINER (vbox2), 2);
  gtk_container_add (GTK_CONTAINER (frame), vbox2);
  gtk_widget_show (vbox2);

  return vbox2;
}

1090
1091
1092
1093
1094
1095
1096
/************************************************************************
 *  create the preferences dialog
 */
void
file_pref_cmd_callback (GtkWidget *widget,
			gpointer   client_data)
{
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
  GtkWidget    *ctree;
  gchar        *titles[1];
  GtkCTreeNode *top_insert;
  GtkCTreeNode *child_insert;
  gint          page_index;

  GtkWidget *frame;
  GtkWidget *notebook;
  GtkWidget *vbox;
  GtkWidget *vbox2;
  GtkWidget *hbox;
  GtkWidget *abox;
  GtkWidget *button;
  GtkWidget *fileselection;
  GtkWidget *patheditor;
  GtkWidget *spinbutton;
  GtkWidget *combo;
  GtkWidget *comboitem;
  GtkWidget *optionmenu;
  GtkWidget *table;
  GtkWidget *label;
  GtkObject *adjustment;
  GtkWidget *sizeentry;
  GtkWidget *sizeentry2;
  GSList    *group;

1123
1124
1125
  gint i;
  gint divided_mem_size;
  gint mem_size_unit;
1126
1127
1128
1129
1130
1131

  if (prefs_dlg)
    {
      gdk_window_raise (GTK_WIDGET (prefs_dlg)->window);
      return;
    }
1132

1133
1134
1135
1136
  if (edit_temp_path == NULL)
    {
      /* first time dialog is opened - copy config vals to edit
	 variables. */
Michael Natterer's avatar
Michael Natterer committed
1137
1138
1139
1140
1141
      edit_stingy_memory_use = stingy_memory_use;
      edit_tile_cache_size = tile_cache_size;
      edit_install_cmap = install_cmap;
      edit_cycled_marching_ants = cycled_marching_ants;
      edit_last_opened_size = last_opened_size;
1142
1143
1144
      edit_temp_path = file_prefs_strdup (temp_path);	
      edit_swap_path = file_prefs_strdup (swap_path);
      edit_brush_path = file_prefs_strdup (brush_path);
1145
      edit_brush_vbr_path = file_prefs_strdup (brush_vbr_path);
1146
1147
1148
1149
1150
      edit_pattern_path = file_prefs_strdup (pattern_path);
      edit_palette_path = file_prefs_strdup (palette_path);
      edit_plug_in_path = file_prefs_strdup (plug_in_path);
      edit_module_path = file_prefs_strdup (module_path);
      edit_gradient_path = file_prefs_strdup (gradient_path);
1151
      edit_nav_window_per_display = nav_window_per_display;
1152
1153
1154
1155
1156
1157
1158
1159
1160
    }
  old_perfectmouse = perfectmouse;
  old_transparency_type = transparency_type;
  old_transparency_size = transparency_size;
  old_levels_of_undo = levels_of_undo;
  old_marching_speed = marching_speed;
  old_allow_resize_windows = allow_resize_windows;
  old_auto_save = auto_save;
  old_preview_size = preview_size;
1161
  old_nav_preview_size = nav_preview_size;
1162
1163
1164
1165
  old_no_cursor_updating = no_cursor_updating;
  old_show_tool_tips = show_tool_tips;
  old_show_rulers = show_rulers;
  old_show_statusbar = show_statusbar;
1166
  old_interpolation_type = interpolation_type;
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183