nautilus-global-preferences.c 26.8 KB
Newer Older
1 2
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

3 4
/* nautilus-global-preferences.c - Nautilus specific preference keys and
                                   functions.
5

6
   Copyright (C) 1999, 2000, 2001 Eazel, Inc.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

   The Gnome Library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.

   The Gnome Library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public
   License along with the Gnome Library; see the file COPYING.LIB.  If not,
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Authors: Ramiro Estrugo <ramiro@eazel.com>
*/

26
#include <config.h>
27
#include "nautilus-global-preferences.h"
28

29
#include "nautilus-file-utilities.h"
30 31
#include "nautilus-file.h"
#include "nautilus-icon-factory.h"
32
#include "nautilus-sidebar-functions.h"
33
#include <eel/eel-enumeration.h>
34 35 36 37
#include <eel/eel-glib-extensions.h>
#include <eel/eel-gtk-extensions.h>
#include <eel/eel-stock-dialogs.h>
#include <eel/eel-string.h>
38
#include <libgnome/gnome-i18n.h>
39
#include <libgnome/gnome-util.h>
40
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
41
#include <libgnomevfs/gnome-vfs-utils.h>
42

43
/* Constants */
44
#define STRING_LIST_DEFAULT_TOKENS_DELIMETER ","
45
#define PREFERENCES_SORT_ORDER_MANUALLY 100
46

47
/* Path for gnome-vfs preferences */
48 49 50
static const char *EXTRA_MONITOR_PATHS[] = { "/system/gnome-vfs",
					     "/desktop/gnome/file-views",
					     NULL };
51

52
/* Forward declarations */
53 54
static void     global_preferences_install_defaults      (void);
static void     global_preferences_register_enumerations (void);
55 56 57
static gpointer default_font_callback                    (void);
static gpointer default_home_location_callback           (void);
static gpointer default_default_folder_viewer_callback	 (void);
58
static void     import_old_preferences_if_needed         (void);
59

60
/* An enumeration used for installing type specific preferences defaults. */
Ramiro Estrugo's avatar
Ramiro Estrugo committed
61 62 63 64
typedef enum
{
	PREFERENCE_BOOLEAN = 1,
	PREFERENCE_INTEGER,
65 66
	PREFERENCE_STRING,
	PREFERENCE_STRING_LIST
Ramiro Estrugo's avatar
Ramiro Estrugo committed
67
} PreferenceType;
68

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

/* values for tracking the current preferences version so when
   key names are changed Nautilus can import the old preferences */

#define PREFERENCES_VERSION                    "preferences_version"
#define PREFERENCES_CURRENT_VERSION            2

typedef struct 
{
	const char *new_key;
	const char *old_key;
} PreferenceImportType;

/* format is { NEW_KEY, KEY_TO_IMPORT_FROM } */
static PreferenceImportType OLD_PREFERENCES_TO_IMPORT[] = { 
	{ NAUTILUS_PREFERENCES_THEME, 
	  "/apps/nautilus/preferences/theme", 
	},
	{ NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES, 
	  "/apps/nautilus/preferences/show_hidden_files", 
	}, 
	{ NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES, 
	  "/apps/nautilus/preferences/show_backup_files", 
	},
	{ NULL }
};



98 99 100 101 102 103 104 105 106
/* Enumerations used to qualify some INTEGER preferences */
static EelEnumerationEntry speed_tradeoff_enum_entries[] = {
	{ "always",	    N_("Always"),		NAUTILUS_SPEED_TRADEOFF_ALWAYS },
	{ "local_only",	    N_("Local Files Only"),	NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY },
	{ "never",	    N_("Never"),		NAUTILUS_SPEED_TRADEOFF_NEVER },
	{ NULL }
};

static EelEnumerationEntry default_zoom_level_enum_entries[] = {
Pablo Saratxaga's avatar
Pablo Saratxaga committed
107
	/* xgettext:no-c-format */
108
	{ "smallest",	    N_("25%"),		NAUTILUS_ZOOM_LEVEL_SMALLEST },
Pablo Saratxaga's avatar
Pablo Saratxaga committed
109
	/* xgettext:no-c-format */
110
	{ "smaller",	    N_("50%"),		NAUTILUS_ZOOM_LEVEL_SMALLER },
Pablo Saratxaga's avatar
Pablo Saratxaga committed
111
	/* xgettext:no-c-format */
112
	{ "small",	    N_("75%"),		NAUTILUS_ZOOM_LEVEL_SMALL },
Pablo Saratxaga's avatar
Pablo Saratxaga committed
113
	/* xgettext:no-c-format */
114
	{ "standard",	    N_("100%"),		NAUTILUS_ZOOM_LEVEL_STANDARD },
Pablo Saratxaga's avatar
Pablo Saratxaga committed
115
	/* xgettext:no-c-format */
116
	{ "large",	    N_("150%"),		NAUTILUS_ZOOM_LEVEL_LARGE },
Pablo Saratxaga's avatar
Pablo Saratxaga committed
117
	/* xgettext:no-c-format */
118
	{ "larger",	    N_("200%"),		NAUTILUS_ZOOM_LEVEL_LARGER },
Pablo Saratxaga's avatar
Pablo Saratxaga committed
119
	/* xgettext:no-c-format */
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
	{ "largest",	    N_("400%"),		NAUTILUS_ZOOM_LEVEL_LARGEST },
	{ NULL }
};

static EelEnumerationEntry file_size_enum_entries[] = {
	{ "102400",	    N_("100 K"),	102400 },
	{ "512000",	    N_("500 K"),	512000 },
	{ "1048576",	    N_("1 MB"),		1048576 },
	{ "3145728",	    N_("3 MB"),		3145728 },
	{ "5242880",	    N_("5 MB"),		5242880 },
	{ "10485760",	    N_("10 MB"),	10485760 },
	{ "104857600",	    N_("100 MB"),	104857600 },
	{ NULL }
};

static EelEnumerationEntry click_policy_enum_entries[] = {
	{ "single",
	  N_("Activate items with a single click"),
	  NAUTILUS_CLICK_POLICY_SINGLE
	},
	{ "double",
	  N_("Activate items with a double click"),
	  NAUTILUS_CLICK_POLICY_DOUBLE
	},
	{ NULL }
};

static EelEnumerationEntry executable_text_activation_enum_entries[] = {
	{ "launch",
	  N_("Execute files when they are clicked"),
	  NAUTILUS_EXECUTABLE_TEXT_LAUNCH
	},
	{ "display",
	  N_("Display files when they are clicked"),
	  NAUTILUS_EXECUTABLE_TEXT_DISPLAY
	},
	{ "ask",
	  N_("Ask each time"),
	  NAUTILUS_EXECUTABLE_TEXT_ASK
	},
	{ NULL }
};

static EelEnumerationEntry search_bar_type_enum_entries[] = {
	{ N_("search by text"),
	  N_("Search for files by file name only"),
	  NAUTILUS_SIMPLE_SEARCH_BAR
	},
	{ N_("search by text and properties"),
	  N_("Search for files by file name and file properties"),
	  NAUTILUS_COMPLEX_SEARCH_BAR
	},
	{ NULL }
};

static EelEnumerationEntry default_folder_viewer_enum_entries[] = {
	{ "icon_view",	    N_("Icon View"),	NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW },
	{ "list_view",	    N_("List View"),	NAUTILUS_DEFAULT_FOLDER_VIEWER_LIST_VIEW },
	{ NULL }
};

181 182 183
static EelEnumerationEntry default_icon_view_sort_order_enum_entries[] = {
	{ "manually",	       N_("Manually"),		    PREFERENCES_SORT_ORDER_MANUALLY },
	{ "--------",             "--------" },
184
	{ "name",	       N_("By Name"),		    NAUTILUS_FILE_SORT_BY_DISPLAY_NAME },
185 186
	{ "size",	       N_("By Size"),		    NAUTILUS_FILE_SORT_BY_SIZE },
	{ "type",	       N_("By Type"),		    NAUTILUS_FILE_SORT_BY_TYPE },
187 188 189 190 191 192
	{ "modification_date", N_("By Modification Date"),  NAUTILUS_FILE_SORT_BY_MTIME }, 
	{ "emblems",	       N_("By Emblems"),	    NAUTILUS_FILE_SORT_BY_EMBLEMS },
	{ NULL }
};

static EelEnumerationEntry default_list_view_sort_order_enum_entries[] = {
193
	{ "name",	       N_("By Name"),		    NAUTILUS_FILE_SORT_BY_DISPLAY_NAME },
194 195 196
	{ "size",	       N_("By Size"),		    NAUTILUS_FILE_SORT_BY_SIZE },
	{ "type",	       N_("By Type"),		    NAUTILUS_FILE_SORT_BY_TYPE },
	{ "modification_date", N_("By Modification Date"),  NAUTILUS_FILE_SORT_BY_MTIME }, 
197
	{ "emblems",	       N_("By Emblems"),	    NAUTILUS_FILE_SORT_BY_EMBLEMS },
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
	{ NULL }
};

static EelEnumerationEntry standard_font_size_entries[] = {
	{ "8",		   N_("8"),	8 },
	{ "10",		   N_("10"),	10 },
	{ "12",		   N_("12"),	12 },
	{ "14",		   N_("14"),	14 },
	{ "16",		   N_("16"),	16 },
	{ "18",		   N_("18"),	18 },
	{ "20",		   N_("20"),	20 },
	{ "22",		   N_("22"),	22 },
	{ "24",		   N_("24"),	24 },
	{ NULL }
};

214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
static EelEnumerationEntry icon_captions_enum_entries[] = {
	{ "size",	       N_("size"),		0 },
	{ "type",	       N_("type"),		1 },
	{ "date_modified",     N_("date modified"),	2 },
	{ "date_changed",      N_("date changed"),	3 }, 
	{ "date_accessed",     N_("date accessed"),	4 }, 
	{ "owner",	       N_("owner"),		5 }, 
	{ "group",	       N_("group"),		6 }, 
	{ "permissions",       N_("permissions"),	7 }, 
	{ "octal_permissions", N_("octal permissions"),	8 }, 
	{ "mime_type",	       N_("MIME type"),		9 }, 
	{ "none",	       N_("none"),		10 }, 
	{ NULL }
};

229 230 231 232 233
/* These enumerations are used in the preferences dialog to 
 * populate widgets and route preferences changes between the
 * storage (GConf) and the displayed values.
 */
static EelEnumerationInfo enumerations[] = {
234 235 236 237 238 239 240 241 242 243 244
	{ "click_policy",		   click_policy_enum_entries },
	{ "default_folder_viewer",	   default_folder_viewer_enum_entries },
	{ "default_icon_view_sort_order",  default_icon_view_sort_order_enum_entries },
	{ "default_list_view_sort_order",  default_list_view_sort_order_enum_entries },
	{ "default_zoom_level",		   default_zoom_level_enum_entries },
	{ "executable_text_activation",	   executable_text_activation_enum_entries },
	{ "file_size",			   file_size_enum_entries },
	{ "icon_captions",		   icon_captions_enum_entries },
	{ "search_bar_type",		   search_bar_type_enum_entries },
	{ "speed_tradeoff",		   speed_tradeoff_enum_entries },
	{ "standard_font_size",		   standard_font_size_entries },
245 246 247
	{ NULL }
};

248
/*
249
 * A callback which can be used to fetch dynamic fallback values.
250 251 252
 * For example, values that are dependent on the environment (such as user name) 
 * cannot be specified as constants.
 */
253
typedef gpointer (*PreferencesDefaultValueCallback) (void);
254

255
/* A structure that describes a single preference including defaults and visibility. */
Ramiro Estrugo's avatar
Ramiro Estrugo committed
256 257 258 259
typedef struct
{
	const char *name;
	PreferenceType type;
260 261 262
	const gpointer fallback_value;
	PreferencesDefaultValueCallback fallback_callback;
	GFreeFunc fallback_callback_result_free_function;
263
	const char *enumeration_id;
Ramiro Estrugo's avatar
Ramiro Estrugo committed
264
} PreferenceDefault;
265

266 267 268
/* The following table defines the default values and user level visibilities of
 * Nautilus preferences.  Each of these preferences does not necessarily need to
 * have a UI item in the preferences dialog.  To add an item to the preferences
269
 * dialog, see the NautilusPreferencesItemDescription tables later in this file.
270 271 272 273 274 275 276 277 278 279 280 281 282 283
 * 
 * Field definitions:
 *
 * 1. name
 *
 *    The name of the preference.  Usually defined in
 *    nautilus-global-preferences.h
 *
 * 2. type
 *    The preference type.  One of:
 *
 *	PREFERENCE_BOOLEAN
 *	PREFERENCE_INTEGER
 *	PREFERENCE_STRING
284
 *	PREFERENCE_STRING_LIST
285
 * 
286 287
 * 3. fallback_value
 *    Emergency fallback value if our gconf schemas are hosed somehow.
288
 * 
289 290
 * 4. fallback_callback
 *    callback to get dynamic fallback
291
 *
292 293
 * 5. fallback_callback_result_free_function
 *    free result of fallback_callback
294
 *
295 296 297 298 299
 * 6. enumeration_id
 *    An an enumeration id is a unique string that identifies an enumeration.
 *    If given, an enumeration id can be used to qualify a INTEGER preference.
 *    The preferences dialog widgetry will use this enumeration id to find out
 *    what choices and descriptions of choices to present to the user.
300
 */
301 302 303 304

/* NOTE THAT THE FALLBACKS HERE ARE NOT SUPPOSED TO BE USED -
 * YOU SHOULD EDIT THE SCHEMAS FILE TO CHANGE DEFAULTS.
 */
Ramiro Estrugo's avatar
Ramiro Estrugo committed
305 306 307
static const PreferenceDefault preference_defaults[] = {
	{ NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
	  PREFERENCE_BOOLEAN,
308
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
309 310 311
	},
	{ NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
	  PREFERENCE_BOOLEAN,
312
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
313 314 315
	},
	{ NAUTILUS_PREFERENCES_CONFIRM_TRASH,
	  PREFERENCE_BOOLEAN,
316
	  GINT_TO_POINTER (TRUE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
317 318 319
	},
	{ NAUTILUS_PREFERENCES_ENABLE_DELETE,
	  PREFERENCE_BOOLEAN,
320
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
321 322 323
	},
	{ NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
	  PREFERENCE_INTEGER,
324 325
	  GINT_TO_POINTER (NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY),
	  NULL, NULL,
326
	  "speed_tradeoff"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
327
	},
328 329 330 331
	/* Don't show remote directory item counts by default
	 * because computing them can be annoyingly slow, especially
	 * for FTP. If we make this fast enough for FTP in particular,
	 * we should change this default to ALWAYS.
Ramiro Estrugo's avatar
Ramiro Estrugo committed
332 333 334
	 */
	{ NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
	  PREFERENCE_INTEGER,
335 336
	  GINT_TO_POINTER (NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY),
	  NULL, NULL,
337
	  "speed_tradeoff"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
338 339 340
	},
	{ NAUTILUS_PREFERENCES_CLICK_POLICY,
	  PREFERENCE_INTEGER,
341 342
	  GINT_TO_POINTER (NAUTILUS_CLICK_POLICY_DOUBLE),
	  NULL, NULL,
343
	  "click_policy"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
344
	},
345 346 347 348 349 350 351 352 353 354
	{ NAUTILUS_PREFERENCES_XALF_ENABLED,
	  PREFERENCE_BOOLEAN,
	  GINT_TO_POINTER (TRUE),
	  NULL, NULL, NULL
	},
	{ NAUTILUS_PREFERENCES_XALF_OPTIONS,
	  PREFERENCE_STRING_LIST,
	  "",
	  NULL, NULL, NULL
	},
Ramiro Estrugo's avatar
Ramiro Estrugo committed
355 356
	{ NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
	  PREFERENCE_INTEGER,
357 358
	  GINT_TO_POINTER (NAUTILUS_EXECUTABLE_TEXT_ASK),
	  NULL, NULL,
359
	  "executable_text_activation"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
360 361 362
	},
	{ NAUTILUS_PREFERENCES_THEME,
	  PREFERENCE_STRING,
363
	  "default"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
364 365 366
	},
	{ NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
	  PREFERENCE_INTEGER,
367 368
	  GINT_TO_POINTER (NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY),
	  NULL, NULL,
369
	  "speed_tradeoff"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
370
	},
371 372
	{ NAUTILUS_PREFERENCES_IMAGE_FILE_THUMBNAIL_LIMIT,
	  PREFERENCE_INTEGER,
373 374
	  GINT_TO_POINTER (3145728),
	  NULL, NULL,
375
	  "file_size"
376
	},
Ramiro Estrugo's avatar
Ramiro Estrugo committed
377 378
	{ NAUTILUS_PREFERENCES_USE_PUBLIC_METADATA,
	  PREFERENCE_INTEGER,
379 380
	  GINT_TO_POINTER (NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY),
	  NULL, NULL,
381
	  "speed_tradeoff"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
382 383 384
	},
	{ NAUTILUS_PREFERENCES_PREVIEW_SOUND,
	  PREFERENCE_INTEGER,
385 386
	  GINT_TO_POINTER (NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY),
	  NULL, NULL,
387
	  "speed_tradeoff"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
388 389 390
	},
	{ NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
	  PREFERENCE_BOOLEAN,
391
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
392 393 394
	},
	{ NAUTILUS_PREFERENCES_SORT_DIRECTORIES_FIRST,
	  PREFERENCE_BOOLEAN,
395
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
396 397 398
	},
	{ NAUTILUS_PREFERENCES_SHOW_DESKTOP,
	  PREFERENCE_BOOLEAN,
399
	  GINT_TO_POINTER (TRUE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
400
	},
401 402
	{ NAUTILUS_PREFERENCES_DESKTOP_IS_HOME_DIR,
	  PREFERENCE_BOOLEAN,
403
	  GINT_TO_POINTER (FALSE)
404
	},
Ramiro Estrugo's avatar
Ramiro Estrugo committed
405 406
	{ NAUTILUS_PREFERENCES_CAN_ADD_CONTENT,
	  PREFERENCE_BOOLEAN,
407
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
408 409 410
	},
	{ NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
	  PREFERENCE_INTEGER,
411 412
	  GINT_TO_POINTER (NAUTILUS_SIMPLE_SEARCH_BAR),
	  NULL, NULL,
413
	  "search_bar_type"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
414 415 416
	},
	{ NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
	  PREFERENCE_BOOLEAN,
417
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
418
	},
419 420
	{ NAUTILUS_PREFERENCES_ICON_VIEW_CAPTIONS,
	  PREFERENCE_STRING_LIST,
421 422
	  "size,date_modified,type",
	  NULL, NULL,
423
	  "icon_captions"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
424 425 426
	},
	{ NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS,
	  PREFERENCE_BOOLEAN,
427
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
428 429 430
	},
	{ NAUTILUS_PREFERENCES_USE_EMACS_SHORTCUTS,
	  PREFERENCE_BOOLEAN,
431
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
432
	},
433
	/* FIXME bugzilla.gnome.org 41245: Saved in pixels instead of in %? */
Ramiro Estrugo's avatar
Ramiro Estrugo committed
434 435
	{ NAUTILUS_PREFERENCES_SIDEBAR_WIDTH,
	  PREFERENCE_INTEGER,
436
	  GINT_TO_POINTER (148)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
437 438 439
	},
	{ NAUTILUS_PREFERENCES_SEARCH_WEB_URI,
	  PREFERENCE_STRING,
440
	  "http://www.google.com"
Ramiro Estrugo's avatar
Ramiro Estrugo committed
441 442 443
	},
	{ NAUTILUS_PREFERENCES_START_WITH_TOOLBAR,
	  PREFERENCE_BOOLEAN,
444
	  GINT_TO_POINTER (TRUE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
445 446 447
	},
	{ NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR,
	  PREFERENCE_BOOLEAN,
448
	  GINT_TO_POINTER (TRUE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
449 450 451
	},
	{ NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR,
	  PREFERENCE_BOOLEAN,
452
	  GINT_TO_POINTER (TRUE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
453 454 455
	},
	{ NAUTILUS_PREFERENCES_START_WITH_SIDEBAR,
	  PREFERENCE_BOOLEAN,
456
	  GINT_TO_POINTER (TRUE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
457 458 459
	},
	{ NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
	  PREFERENCE_BOOLEAN,
460
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
461
	},
462

Ramiro Estrugo's avatar
Ramiro Estrugo committed
463
	/* Proxy defaults */
464
	{ NAUTILUS_PREFERENCES_HTTP_USE_PROXY,
Ramiro Estrugo's avatar
Ramiro Estrugo committed
465
	  PREFERENCE_BOOLEAN,
466
	  GINT_TO_POINTER (FALSE)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
467
	},
468
	{ NAUTILUS_PREFERENCES_HTTP_PROXY_PORT,
Ramiro Estrugo's avatar
Ramiro Estrugo committed
469
	  PREFERENCE_INTEGER,
470
	  GINT_TO_POINTER (8080)
Ramiro Estrugo's avatar
Ramiro Estrugo committed
471
	},
472 473
	{ NAUTILUS_PREFERENCES_HTTP_PROXY_USE_AUTH,
	  PREFERENCE_BOOLEAN,
474
	  GINT_TO_POINTER (FALSE)
475
	},
Ramiro Estrugo's avatar
Ramiro Estrugo committed
476

477 478 479
	/* Home URI */
	{ NAUTILUS_PREFERENCES_HOME_URI,
	  PREFERENCE_STRING,
480
	  NULL, default_home_location_callback, g_free
481
	},
482

483 484 485
	/* Default fonts */
	{ NAUTILUS_PREFERENCES_DEFAULT_FONT,
	  PREFERENCE_STRING,
486
	  NULL, default_font_callback, g_free
487 488 489
	},
	{ NAUTILUS_PREFERENCES_DEFAULT_FONT_SIZE,
	  PREFERENCE_INTEGER,
490 491
	  GINT_TO_POINTER (12),
	  NULL, NULL,
492 493 494
	  "standard_font_size"
	},
	
495 496 497
	/* View Preferences */
	{ NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER,
	  PREFERENCE_INTEGER,
498
	  NULL, default_default_folder_viewer_callback, NULL,
499 500 501 502
	  "default_folder_viewer"
	},

	/* Icon View Default Preferences */
503

504 505
	{ NAUTILUS_PREFERENCES_ICON_VIEW_FONT,
	  PREFERENCE_STRING,
506
	  NULL, default_font_callback, g_free
507 508 509
	},
	{ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL_FONT_SIZE,
	  PREFERENCE_INTEGER,
510 511
	  GINT_TO_POINTER (12),
	  NULL, NULL,
512 513
	  "standard_font_size"
	},
514 515
	{ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_SORT_ORDER,
	  PREFERENCE_INTEGER,
516 517
	  GINT_TO_POINTER (NAUTILUS_FILE_SORT_BY_DISPLAY_NAME),
	  NULL, NULL,
518 519 520 521
	  "default_icon_view_sort_order"
	},
	{ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_SORT_ORDER_OR_MANUAL_LAYOUT,
	  PREFERENCE_INTEGER,
522 523
	  GINT_TO_POINTER (NAUTILUS_FILE_SORT_BY_DISPLAY_NAME),
	  NULL, NULL,
524
	  "default_icon_view_sort_order"
525 526 527
	},
	{ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_SORT_IN_REVERSE_ORDER,
	  PREFERENCE_BOOLEAN,
528
	  GINT_TO_POINTER (FALSE)
529 530 531
	},
	{ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_USE_TIGHTER_LAYOUT,
	  PREFERENCE_BOOLEAN,
532
	  GINT_TO_POINTER (FALSE)
533
	},
534 535
	{ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_USE_MANUAL_LAYOUT,
	  PREFERENCE_BOOLEAN,
536
	  GINT_TO_POINTER (FALSE)
537
	},
538 539
	{ NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_ZOOM_LEVEL,
	  PREFERENCE_INTEGER,
540 541
	  GINT_TO_POINTER (NAUTILUS_ZOOM_LEVEL_STANDARD),
	  NULL, NULL,
542 543 544 545
	  "default_zoom_level"
	},

	/* List View Default Preferences */
546 547
	{ NAUTILUS_PREFERENCES_LIST_VIEW_FONT,
	  PREFERENCE_STRING,
548
	  NULL, default_font_callback, g_free
549 550 551
	},
	{ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL_FONT_SIZE,
	  PREFERENCE_INTEGER,
552 553
	  GINT_TO_POINTER (12),
	  NULL, NULL,
554 555
	  "standard_font_size"
	},
556 557
	{ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_SORT_ORDER,
	  PREFERENCE_INTEGER,
558 559
	  GINT_TO_POINTER (NAUTILUS_FILE_SORT_BY_DISPLAY_NAME),
	  NULL, NULL,
560
	  "default_list_view_sort_order"
561 562 563
	},
	{ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_SORT_IN_REVERSE_ORDER,
	  PREFERENCE_BOOLEAN,
564
	  GINT_TO_POINTER (FALSE)
565 566 567
	},
	{ NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL,
	  PREFERENCE_INTEGER,
568 569
	  GINT_TO_POINTER (NAUTILUS_ZOOM_LEVEL_SMALLER),
	  NULL, NULL,
570 571 572
	  "default_zoom_level"
	},

573
	/* Sidebar panel default */
574 575
	{ nautilus_sidebar_news_enabled_preference_name,
	  PREFERENCE_BOOLEAN,
576
	  GINT_TO_POINTER (TRUE)
577
	},
578
	{ nautilus_sidebar_notes_enabled_preference_name,
579
	  PREFERENCE_BOOLEAN,
580
	  GINT_TO_POINTER (TRUE)
581
	},
582
	{ nautilus_sidebar_history_enabled_preference_name,
583
	  PREFERENCE_BOOLEAN,
584
	  GINT_TO_POINTER (TRUE)
585
	},
586
	{ nautilus_sidebar_tree_enabled_preference_name,
587
	  PREFERENCE_BOOLEAN,
588
	  GINT_TO_POINTER (FALSE)
589
	},
590

591 592 593
	/* news panel preferences */
	{ NAUTILUS_PREFERENCES_NEWS_MAX_ITEMS,
	  PREFERENCE_INTEGER,
594
	  GINT_TO_POINTER (6)
595 596 597
	},
	{ NAUTILUS_PREFERENCES_NEWS_UPDATE_INTERVAL,
	  PREFERENCE_INTEGER,
598
	  GINT_TO_POINTER (5)
599
	},
600

601 602 603
	/* non-visible preferences */
	{ NAUTILUS_PREFERENCES_ADD_TO_SESSION,
	  PREFERENCE_BOOLEAN,
604
	  GINT_TO_POINTER (TRUE)
605 606
	},

Ramiro Estrugo's avatar
Ramiro Estrugo committed
607 608
	{ NULL }
};
609

610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
/**
 * global_preferences_register_enumerations
 *
 * Register enumerations for INTEGER preferences that need them.
 *
 * This function needs to be called before the preferences dialog
 * panes are populated, as they use the registered information to
 * create enumeration item widgets.
 */
static void
global_preferences_register_enumerations (void)
{
	guint i;

	/* Register the enumerations */
	eel_enumeration_register (enumerations);

	/* Set the enumeration ids for preferences that need them */
	for (i = 0; preference_defaults[i].name != NULL; i++) {
629 630 631
		if (eel_strlen (preference_defaults[i].enumeration_id) > 0) {
			g_assert (preference_defaults[i].type == PREFERENCE_INTEGER
				  || preference_defaults[i].type == PREFERENCE_STRING_LIST);
632 633
			eel_preferences_set_enumeration_id (preference_defaults[i].name,
							    preference_defaults[i].enumeration_id);
634 635 636 637
		}
	}
}

638 639 640
static void
global_preferences_install_one_default (const char *preference_name,
					PreferenceType preference_type,
641
					const PreferenceDefault *preference_default)
642 643
{
	gpointer value = NULL;
644
	EelStringList *string_list_value;
645
	
646 647
	g_return_if_fail (preference_name != NULL);
	g_return_if_fail (preference_type >= PREFERENCE_BOOLEAN);
648
	g_return_if_fail (preference_type <= PREFERENCE_STRING_LIST);
649
	g_return_if_fail (preference_default != NULL);
650 651

	/* If a callback is given, use that to fetch the default value */
652 653
	if (preference_default->fallback_callback != NULL) {
		value = (* preference_default->fallback_callback) ();
654
	} else {
655
		value = preference_default->fallback_value;
656 657 658 659
	}

	switch (preference_type) {
	case PREFERENCE_BOOLEAN:
660 661
		eel_preferences_set_emergency_fallback_boolean (preference_name,
								GPOINTER_TO_INT (value));
662 663 664
		break;
		
	case PREFERENCE_INTEGER:
665 666 667
		eel_preferences_set_emergency_fallback_integer (preference_name,
								
								GPOINTER_TO_INT (value));
668 669 670
		break;
		
	case PREFERENCE_STRING:
671 672
		eel_preferences_set_emergency_fallback_string (preference_name,
							       value);
673 674
		break;
		
675 676 677 678
	case PREFERENCE_STRING_LIST:
		string_list_value = eel_string_list_new_from_tokens (value,
								     STRING_LIST_DEFAULT_TOKENS_DELIMETER,
								     TRUE);
679 680
		eel_preferences_set_emergency_fallback_string_list (preference_name,
								    string_list_value);
681 682 683
		eel_string_list_free (string_list_value);
		break;
		
684 685 686 687 688
	default:
		g_assert_not_reached ();
	}

	/* Free the dynamic default value if needed */
689 690 691
	if (preference_default->fallback_callback != NULL
	    && preference_default->fallback_callback_result_free_function != NULL) {
		(* preference_default->fallback_callback_result_free_function) (value);
692 693 694
	}
}

695 696 697
/**
 * global_preferences_install_defaults
 *
698 699 700
 * Install defaults and visibilities.
 *
 * Most of the defaults come from the preference_defaults table above.
701
 *
702 703
 * Many preferences require their defaults to be computed, and so there
 * are special functions to install those.
704 705 706 707
 */
static void
global_preferences_install_defaults (void)
{
Ramiro Estrugo's avatar
Ramiro Estrugo committed
708
	guint i;
709

Ramiro Estrugo's avatar
Ramiro Estrugo committed
710
	for (i = 0; preference_defaults[i].name != NULL; i++) {
711 712
		global_preferences_install_one_default (preference_defaults[i].name,
							preference_defaults[i].type,
713
							&preference_defaults[i]);
Ramiro Estrugo's avatar
Ramiro Estrugo committed
714 715
	}
}
716

717
static gpointer
718
default_font_callback (void)
719
{
720
	return g_strdup ("sans");
721 722
}

723 724 725 726 727 728 729 730 731 732 733 734 735 736 737
static int
get_default_folder_viewer_preference_from_iid (const char *iid)
{
	g_return_val_if_fail (iid != NULL, NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW);

	if (strcmp (iid, NAUTILUS_LIST_VIEW_IID) == 0) {
		return NAUTILUS_DEFAULT_FOLDER_VIEWER_LIST_VIEW;
	} else if (strcmp (iid, NAUTILUS_ICON_VIEW_IID) == 0) {
		return NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW;
	}

	return NAUTILUS_DEFAULT_FOLDER_VIEWER_OTHER;
}

static gpointer
738
default_default_folder_viewer_callback (void)
739
{
740
	Bonobo_ServerInfo *bonobo_activation_info;
741 742
	int result;

743 744
	bonobo_activation_info = gnome_vfs_mime_get_default_component ("x-directory/normal");
	if (bonobo_activation_info == NULL) {
745
		result = NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW;
746
	} else {
747
		result = get_default_folder_viewer_preference_from_iid (bonobo_activation_info->iid);
748 749 750
		if (result == NAUTILUS_DEFAULT_FOLDER_VIEWER_OTHER) {
			result = NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW;
		}
751
		CORBA_free (bonobo_activation_info);
752 753 754 755 756
	}

	return GINT_TO_POINTER (result);
}

757
static gpointer
758
default_home_location_callback (void)
759
{
760
	return gnome_vfs_get_uri_from_local_path (g_get_home_dir ());
761 762
}

763 764 765
/*
 * Public functions
 */
766

767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783
static void
set_default_folder_viewer_in_gnome_vfs (const char *iid)
{
	gnome_vfs_mime_set_default_action_type ("x-directory/normal", GNOME_VFS_MIME_ACTION_TYPE_COMPONENT);
	gnome_vfs_mime_set_default_component ("x-directory/normal", iid);
}

/* Convert between gnome-vfs and gconf ways of storing this information. */
static void
default_folder_viewer_changed_callback (gpointer callback_data)
{
	int preference_value;
	const char *viewer_iid;

	g_assert (callback_data == NULL);

	preference_value = 
784
		eel_preferences_get_integer (NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER);
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811

	if (preference_value == NAUTILUS_DEFAULT_FOLDER_VIEWER_LIST_VIEW) {
		viewer_iid = NAUTILUS_LIST_VIEW_IID;
	} else {
		g_return_if_fail (preference_value == NAUTILUS_DEFAULT_FOLDER_VIEWER_ICON_VIEW);
		viewer_iid = NAUTILUS_ICON_VIEW_IID;
	}

	set_default_folder_viewer_in_gnome_vfs (viewer_iid);
}

void
nautilus_global_preferences_set_default_folder_viewer (const char *iid)
{
	int viewer_preference;

	set_default_folder_viewer_in_gnome_vfs (iid);

	viewer_preference = get_default_folder_viewer_preference_from_iid (iid);

	/* If viewer is set to one that the Preferences dialog doesn't know about,
	 * just change the underlying gnome-vfs setting but leave the Preferences dialog alone.
	 */
	if (viewer_preference == NAUTILUS_DEFAULT_FOLDER_VIEWER_OTHER) {
		return;		
	}
	
812 813
	eel_preferences_set_integer (NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER,
				     viewer_preference);
814 815
}

816 817 818 819 820 821 822 823 824 825 826 827 828 829
/* The icon view uses 2 variables to store the sort order and
 * whether to use manual layout.  However, the UI for these
 * preferences presensts them as single option menu.  So we
 * use the following preference as a proxy for the other two.
 * In nautilus-global-preferences.c we install callbacks for
 * the proxy preference and update the other 2 when it changes 
 */
static void
default_icon_view_sort_order_or_manual_layout_changed_callback (gpointer callback_data)
{
 	int default_sort_order_or_manual_layout;
 	int default_sort_order;

 	default_sort_order_or_manual_layout = 
830
 		eel_preferences_get_integer (NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_SORT_ORDER_OR_MANUAL_LAYOUT);
831

832 833
	eel_preferences_set_boolean (NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_USE_MANUAL_LAYOUT,
				     default_sort_order_or_manual_layout == PREFERENCES_SORT_ORDER_MANUALLY);
834 835 836 837

	if (default_sort_order_or_manual_layout != PREFERENCES_SORT_ORDER_MANUALLY) {
		default_sort_order = default_sort_order_or_manual_layout;

838
		g_return_if_fail (default_sort_order >= NAUTILUS_FILE_SORT_BY_DISPLAY_NAME);
839 840
		g_return_if_fail (default_sort_order <= NAUTILUS_FILE_SORT_BY_EMBLEMS);

841 842
		eel_preferences_set_integer (NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_SORT_ORDER,
					     default_sort_order);
843 844 845
	}
}

846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884

static void
import_old_preferences_if_needed (void)
{
	int i;
	int current_preferences_version;
	PreferenceImportType *to_import;
	GConfClient *client;
	GConfValue *value;
	GError *error;

	current_preferences_version = eel_preferences_get_integer (PREFERENCES_VERSION);

	if (current_preferences_version == PREFERENCES_CURRENT_VERSION) {
		return;
	}
	
	eel_preferences_set_integer (PREFERENCES_VERSION, PREFERENCES_CURRENT_VERSION);
	
	client = gconf_client_get_default ();

	/* generic updater, works when values have only moved */
	for (i=0; OLD_PREFERENCES_TO_IMPORT[i].new_key != NULL; i++) {
		to_import = & (OLD_PREFERENCES_TO_IMPORT[i]);

		error = NULL;
		value = gconf_client_get (client, to_import->old_key, &error);

		if ((error == NULL) && (value != NULL)) {
			gconf_client_set (client, to_import->new_key, value, NULL);
		} else {
			if (error != NULL) {
				g_error_free (error);
			}
		}
	}
}


885
void
886
nautilus_global_preferences_init (void)
887 888
{
	static gboolean initialized = FALSE;
889
	int i;
890

891 892 893 894 895
	if (initialized) {
		return;
	}

	initialized = TRUE;
896

897
	eel_preferences_init ("/apps/nautilus");
Ramiro Estrugo's avatar
Ramiro Estrugo committed
898

899 900
	import_old_preferences_if_needed ();
	
901 902
	/* Install defaults */
	global_preferences_install_defaults ();
903

904
	global_preferences_register_enumerations ();	
905 906 907 908 909

	/* Add monitors for any other GConf paths we have keys in */
	for (i=0; EXTRA_MONITOR_PATHS[i] != NULL; i++) {
		eel_preferences_monitor_directory (EXTRA_MONITOR_PATHS[i]);
	}
910

911
	/* Set up storage for values accessed in this file */
912 913 914
	eel_preferences_add_callback (NAUTILUS_PREFERENCES_DEFAULT_FOLDER_VIEWER, 
				      default_folder_viewer_changed_callback, 
				      NULL);
915

916 917 918
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_VIEW_DEFAULT_SORT_ORDER_OR_MANUAL_LAYOUT,
				      default_icon_view_sort_order_or_manual_layout_changed_callback, 
				      NULL);
919

920 921 922
	/* Preload everything in a big batch */
	eel_gconf_preload_cache ("/apps/nautilus/preferences",
				 GCONF_CLIENT_PRELOAD_ONELEVEL);
923
}
924