summaryrefslogtreecommitdiff
path: root/libnautilus-extensions/nautilus-global-preferences.c
blob: 9a128d71e87b65f261195d445624e0bab98bbb16 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
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
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
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
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
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
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-prefs-dialog.c - Implementation for preferences dialog.

   Copyright (C) 1999, 2000 Eazel, Inc.

   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>
*/

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

#include "nautilus-file-utilities.h"
#include "nautilus-font-manager.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-extensions.h"
#include "nautilus-medusa-support.h"
#include "nautilus-preferences-dialog.h"
#include "nautilus-preferences-group.h"
#include "nautilus-preferences-item.h"
#include "nautilus-scalable-font.h"
#include "nautilus-string.h"
#include "nautilus-medusa-support.h"
#include "nautilus-stock-dialogs.h"
#include "nautilus-view-identifier.h"
#include <gconf/gconf.h>
#include <gconf/gconf-client.h>
#include <gtk/gtkbox.h>
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-util.h>
#include <liboaf/liboaf.h>
#include <libgnomevfs/gnome-vfs-utils.h>

/* Constants */
static const char untranslated_global_preferences_dialog_title[] = N_("Nautilus Preferences");
#define GLOBAL_PREFERENCES_DIALOG_TITLE _(untranslated_global_preferences_dialog_title)

static const char PROXY_HOST_KEY[] = "/system/gnome-vfs/http-proxy-host";
static const char PROXY_PORT_KEY[] = "/system/gnome-vfs/http-proxy-port";
static const char USE_PROXY_KEY[] = "/system/gnome-vfs/use-http-proxy";
static const char SYSTEM_GNOME_VFS_PATH[] = "/system/gnome-vfs";

/* Forward declarations */
static char *     global_preferences_get_sidebar_panel_key               (const char             *panel_iid);
static gboolean   global_preferences_is_sidebar_panel_enabled_cover      (gpointer                data,
									  gpointer                callback_data);
static GList *    global_preferences_get_sidebar_panel_view_identifiers  (void);
static gboolean   global_preferences_close_dialog_callback               (GtkWidget              *dialog,
									  gpointer                user_data);
static void       global_preferences_install_sidebar_panel_defaults      (void);
static void       global_preferences_install_sidebar_panel_descriptions  (void);
static void       global_preferences_install_defaults                    (void);
static void       global_preferences_install_visibility                  (void);
static void       global_preferences_install_speed_tradeoff_descriptions (const char             *name,
									  const char             *description);
static void       global_preferences_install_home_location_defaults      (void);
static void       global_preferences_install_medusa_defaults             (void);
static void       global_preferences_install_font_defaults               (void);
static void       global_preferences_install_descriptions                (void);
static int        compare_view_identifiers                               (gconstpointer           a,
									  gconstpointer           b);
static GtkWidget *global_preferences_create_dialog                       (void);
static GtkWidget *global_preferences_create_search_pane                  (NautilusPreferencesBox *preference_box);
static GtkWidget *global_preferences_create_font_group                   (NautilusPreferencesPane *appearance_pane);

static GtkWidget *global_prefs_dialog = NULL;

/**
 * global_preferences_install_descriptions
 *
 * Install descriptions for some preferences.  A preference needs a description
 * only if it appears in the preferences dialog.
 */
static void
global_preferences_install_descriptions (void)
{
	static gboolean preferences_registered = FALSE;
	g_return_if_fail (preferences_registered == FALSE);
	preferences_registered = TRUE;

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_THEME,
					      _("current theme"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
					      _("Open each file or folder in a separate window"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_CONFIRM_TRASH,
					      _("Ask before emptying the Trash"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_CLICK_POLICY,
					      _("Click Behavior"));
	
	nautilus_preferences_enumeration_insert (NAUTILUS_PREFERENCES_CLICK_POLICY,
						 _("single"),
						 _("Activate items with a single click"),
						 NAUTILUS_CLICK_POLICY_SINGLE);
	
	nautilus_preferences_enumeration_insert (NAUTILUS_PREFERENCES_CLICK_POLICY,
						 _("double"),
						 _("Activate items with a double click"),
						 NAUTILUS_CLICK_POLICY_DOUBLE);
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
					      _("Executable Text Files"));
	
	nautilus_preferences_enumeration_insert (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
						 _("launch"),
						 _("Execute files when they are clicked"),
						 NAUTILUS_EXECUTABLE_TEXT_LAUNCH);
	
	nautilus_preferences_enumeration_insert (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
						 _("display"),
						 _("Display files when they are clicked"),
						 NAUTILUS_EXECUTABLE_TEXT_DISPLAY);
	
	nautilus_preferences_enumeration_insert (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
						 _("ask"),
						 _("Ask each time"),
						 NAUTILUS_EXECUTABLE_TEXT_ASK);

	/* Note that I've changed all these descriptions to match the displayed text.
	 * The original intention was to use them differently, but currently they aren't
	 * used at all. By matching the displayed text, at least localizers won't have to
	 * localize two different strings. If we ever make them appear separately, we will
	 * have to reword them (as we would have had to anyway).
	 */
	global_preferences_install_speed_tradeoff_descriptions (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
								_("Show Text in Icons"));
	
	global_preferences_install_speed_tradeoff_descriptions (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
								_("Show Count of Items in Folders"));
	
	global_preferences_install_speed_tradeoff_descriptions (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
								_("Show Thumbnails for Image Files"));

	global_preferences_install_speed_tradeoff_descriptions (NAUTILUS_PREFERENCES_USE_PUBLIC_METADATA,
								_("Make Folder Appearance Details Public"));
	
	global_preferences_install_speed_tradeoff_descriptions (NAUTILUS_PREFERENCES_PREVIEW_SOUND,
								_("Preview Sound Files"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
					      _("Use smoother (but slower) graphics"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
					      _("Use this font family to display file names:"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
					      _("Use this font family to display file names:"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR,
					      _("Display toolbar in new windows"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR,
					      _("Display location bar in new windows"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR,
					      _("Display status bar in new windows"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR,
					      _("Display sidebar in new windows"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SHOW_DESKTOP,
					      _("Use Nautilus to draw the desktop"));
								  
	/* search tradeoffs */
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_USE_FAST_SEARCH,
					      _("Enable fast search (indexes your hard drive)"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
					      _("search type to do by default"));
	
	nautilus_preferences_enumeration_insert (NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
						 _("search by text"),
						 _("Search for files by file name only"),
						 NAUTILUS_SIMPLE_SEARCH_BAR);
	
	nautilus_preferences_enumeration_insert (NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
						 _("search by text and properties"),
						 _("Search for files by file name and file properties"),
						 NAUTILUS_COMPLEX_SEARCH_BAR);
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SEARCH_WEB_URI,
					      _("Search Engine Location"));

	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
					      _("Show hidden files (file names start with \".\")"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
					      _("Show backup files (file names end with \"~\")"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
					      _("Show special flags in Properties window"));
	
	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
					      _("Show only folders (no files) in the tree"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_CAN_ADD_CONTENT,
					      _("Can add Content"));

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS,
					      _("Don't include the built-in bookmarks in the Bookmarks menu"));
	

	nautilus_preferences_set_description (NAUTILUS_PREFERENCES_HOME_URI,
					      _("Location:"));

	global_preferences_install_sidebar_panel_descriptions ();
	
	nautilus_preferences_set_description (USE_PROXY_KEY, _("Use HTTP Proxy"));
	nautilus_preferences_set_description (PROXY_HOST_KEY, _("Location:"));
	nautilus_preferences_set_description (PROXY_PORT_KEY, _("Port:"));
}

/**
 * global_preferences_install_defaults
 *
 * Install defaults for some preferences.  Install defaults only for preferences
 * that need something other than 0 (integer) FALSE (boolean) or "" (string) as
 * their defaults.
 *
 * Its possible to have different defaults for different user levels  Its not 
 * required to have defaults for EACH user level.  If there is no default
 * installed for a high user level, the next lowest user level with a valid
 * default is used.
 */
static void
global_preferences_install_defaults (void)
{
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);

	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);

	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_CONFIRM_TRASH, 
						  NAUTILUS_USER_LEVEL_NOVICE,
						  TRUE);

	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);

	/* Don't show remote directory item counts for Beginner users 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.
	 */
	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
	
	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
						  NAUTILUS_USER_LEVEL_INTERMEDIATE,
						  NAUTILUS_SPEED_TRADEOFF_ALWAYS);
	
	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_CLICK_POLICY,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_CLICK_POLICY_DOUBLE);
	
	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_EXECUTABLE_TEXT_ASK);
	
	nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_THEME,
						 NAUTILUS_USER_LEVEL_NOVICE,
						 "default");
	
	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);

	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_USE_PUBLIC_METADATA,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
	
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  !nautilus_dumb_down_for_multi_byte_locale_hack ());
	
	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_PREVIEW_SOUND,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
	
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
						  NAUTILUS_USER_LEVEL_ADVANCED,
						  TRUE);
	
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_SHOW_DESKTOP,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  TRUE);
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_CAN_ADD_CONTENT,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_CAN_ADD_CONTENT,
						  NAUTILUS_USER_LEVEL_INTERMEDIATE,
						  TRUE);

	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  NAUTILUS_SIMPLE_SEARCH_BAR);

	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
						  NAUTILUS_USER_LEVEL_INTERMEDIATE,
						  NAUTILUS_COMPLEX_SEARCH_BAR);
	
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);

	nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_ICON_CAPTIONS,
						 NAUTILUS_USER_LEVEL_NOVICE,
						 "size|date_modified|type");
	
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);
	
	/* FIXME bugzilla.eazel.com 1245: Saved in pixels instead of in %? */
	nautilus_preferences_default_set_integer (NAUTILUS_PREFERENCES_SIDEBAR_WIDTH,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  148);
	
	nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_SEARCH_WEB_URI,
						 NAUTILUS_USER_LEVEL_NOVICE,
						 "http://www.eazel.com/websearch");

	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  TRUE);
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  TRUE);
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  TRUE);
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR, 
						  NAUTILUS_USER_LEVEL_NOVICE,
						  TRUE);

	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);

	/* Add the gnome-vfs path to the list of monitored directories - for proxy settings */
	nautilus_preferences_monitor_directory (SYSTEM_GNOME_VFS_PATH);
	
	/* Proxy defaults */
	nautilus_preferences_default_set_boolean (USE_PROXY_KEY,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  FALSE);
	nautilus_preferences_default_set_integer (PROXY_PORT_KEY,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  8080);

	/* Sidebar panel defaults */
	global_preferences_install_sidebar_panel_defaults ();

	/* Home location */
	global_preferences_install_home_location_defaults ();

	/* Fonts */
	global_preferences_install_font_defaults ();

	/* Medusa */
	global_preferences_install_medusa_defaults ();
}

/**
 * global_preferences_install_visibility
 *
 * Set the visibilities for restricted preferences.  The visible user level
 * is the first user level at which the preference is visible.  By default
 * all preferences have a visibility of 0.
 *
 * A preference with a value greater than 0, will be "visible" only at that
 * level or higher.  Any getters that ask for that preference at lower user
 * levels will always receive the default value.  Also, if the preference 
 * has an entry in the preferences dialog, it will not be shown unless the 
 * current user level is greater than or equal to the preference's visible
 * user level.
 * 
 */
static void
global_preferences_install_visibility (void)
{
	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_HOME_URI,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_CLICK_POLICY,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_CONFIRM_TRASH,
						     NAUTILUS_USER_LEVEL_ADVANCED);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
						     NAUTILUS_USER_LEVEL_ADVANCED);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
						     NAUTILUS_USER_LEVEL_ADVANCED);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_START_WITH_TOOLBAR,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_START_WITH_SIDEBAR,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_DESKTOP,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_PREVIEW_SOUND,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_USE_PUBLIC_METADATA,
						     NAUTILUS_USER_LEVEL_ADVANCED);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_USE_FAST_SEARCH,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_SEARCH_WEB_URI,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_HOME_URI,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);

	nautilus_preferences_set_visible_user_level (NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS,
						     NAUTILUS_USER_LEVEL_INTERMEDIATE);
}

/*
 * Private stuff
 */
static int
compare_view_identifiers (gconstpointer a, gconstpointer b)
{
 	NautilusViewIdentifier *idenfifier_a;
 	NautilusViewIdentifier *idenfifier_b;
	
 	g_assert (a != NULL);
 	g_assert (b != NULL);

 	idenfifier_a = (NautilusViewIdentifier*) a;
 	idenfifier_b = (NautilusViewIdentifier*) b;
	
	return nautilus_strcmp (idenfifier_a->name, idenfifier_b->name);
}

static GtkWidget *
global_preferences_create_dialog (void)
{
	GtkWidget		*prefs_dialog;
	NautilusPreferencesBox	*preference_box;
	GtkWidget		*directory_views_pane;
	GtkWidget		*windows_and_desktop_pane;
	GtkWidget		*sidebar_panels_pane;
	GtkWidget		*appearance_pane;
	GtkWidget		*tradeoffs_pane;
	GtkWidget		*navigation_pane;

	/*
	 * In the soon to come star trek future, the following widgetry
	 * might be either fetched from a glade file or generated from 
	 * an xml file.
	 */
	prefs_dialog = nautilus_preferences_dialog_new (GLOBAL_PREFERENCES_DIALOG_TITLE);

	gtk_window_set_wmclass (GTK_WINDOW (prefs_dialog), "global_preferences", "Nautilus");

	gtk_signal_connect (GTK_OBJECT (prefs_dialog),
			    "close",
			    GTK_SIGNAL_FUNC (global_preferences_close_dialog_callback),
			    NULL);

	/* Create a preference box */
	preference_box = NAUTILUS_PREFERENCES_BOX (nautilus_preferences_dialog_get_prefs_box
						   (NAUTILUS_PREFERENCES_DIALOG (prefs_dialog)));


	/*
	 * Appearance
	 */
	appearance_pane = nautilus_preferences_box_add_pane (preference_box,
							     _("Appearance"));
	
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Smoother Graphics"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
							 0,
							 NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);

	/*
	 * Fonts
	 */
	global_preferences_create_font_group (NAUTILUS_PREFERENCES_PANE (appearance_pane));


	/*
	 * Windows & Desktop pane
	 */
	windows_and_desktop_pane = nautilus_preferences_box_add_pane (preference_box,
								      _("Windows & Desktop"));

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane), _("Desktop"));
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
							 0,
							 NAUTILUS_PREFERENCES_SHOW_DESKTOP,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane), _("Opening New Windows"));
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
							 1,
							 NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
							 1,
							 NAUTILUS_PREFERENCES_START_WITH_TOOLBAR,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
							 1,
							 NAUTILUS_PREFERENCES_START_WITH_LOCATION_BAR,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
							 1,
							 NAUTILUS_PREFERENCES_START_WITH_STATUS_BAR,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
							 1,
							 NAUTILUS_PREFERENCES_START_WITH_SIDEBAR,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane), _("Trash Behavior"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (windows_and_desktop_pane),
							 2,
							 NAUTILUS_PREFERENCES_CONFIRM_TRASH,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	
	
	/*
	 * Folder Views pane
	 */
	directory_views_pane = nautilus_preferences_box_add_pane (preference_box,
								 _("Icon & List Views"));
	
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), _("Click Behavior"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
							 0,
							 NAUTILUS_PREFERENCES_CLICK_POLICY,
							 NAUTILUS_PREFERENCE_ITEM_ENUM);

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), _("Executable Text Files"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
							 1,
							 NAUTILUS_PREFERENCES_EXECUTABLE_TEXT_ACTIVATION,
							 NAUTILUS_PREFERENCE_ITEM_ENUM);

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane), _("Show/Hide Options"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
							 2,
							 NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);

	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
							 2,
							 NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);

	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (directory_views_pane),
							 2,
							 NAUTILUS_PREFERENCES_SHOW_SPECIAL_FLAGS,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);

	/*
	 * Sidebar panels pane
	 */
	sidebar_panels_pane = nautilus_preferences_box_add_pane (preference_box,
								 _("Sidebar Panels"));
	
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (sidebar_panels_pane), 
					     _("Tabs"));

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (sidebar_panels_pane), 
					     _("Tree"));

	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (sidebar_panels_pane),
							 1,
							 NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);

	{
		char *preference_key;
		GList *view_identifiers;
		GList *p;
		NautilusViewIdentifier *identifier;

		view_identifiers = global_preferences_get_sidebar_panel_view_identifiers ();

		view_identifiers = g_list_sort (view_identifiers, compare_view_identifiers);

		for (p = view_identifiers; p != NULL; p = p->next) {
			identifier = (NautilusViewIdentifier *) (p->data);
			
			preference_key = global_preferences_get_sidebar_panel_key (identifier->iid);

			g_assert (preference_key != NULL);

			nautilus_preferences_pane_add_item_to_nth_group 
				(NAUTILUS_PREFERENCES_PANE (sidebar_panels_pane),
				 0,
				 preference_key,
				 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	
			g_free (preference_key);

		}
	
		nautilus_view_identifier_list_free (view_identifiers);
	}

	/*
	 * Search Settings 
	 */
	global_preferences_create_search_pane (preference_box);

	/*
	 * Navigation
	 */
	navigation_pane = nautilus_preferences_box_add_pane (preference_box,
							    _("Navigation"));

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (navigation_pane), _("Home"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (navigation_pane),
							 0,
							 NAUTILUS_PREFERENCES_HOME_URI,
							 NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (navigation_pane), _("HTTP Proxy Settings"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (navigation_pane),
							 1,
							 USE_PROXY_KEY,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (navigation_pane),
							 1,
							 PROXY_HOST_KEY,
							 NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);

	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (navigation_pane),
							 1,
							 PROXY_PORT_KEY,
							 NAUTILUS_PREFERENCE_ITEM_INTEGER);

	/* built-in bookmarks */
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (navigation_pane),
					     _("Built-in Bookmarks"));
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (navigation_pane),
							 2,
							 NAUTILUS_PREFERENCES_HIDE_BUILT_IN_BOOKMARKS,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);


	/*
	 * Tradeoffs
	 */
	tradeoffs_pane = nautilus_preferences_box_add_pane (preference_box,
							    _("Speed Tradeoffs"));

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane), _("Show Text in Icons"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane),
							 0,
							 NAUTILUS_PREFERENCES_SHOW_TEXT_IN_ICONS,
							 NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane), _("Show Count of Items in Folders"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane),
							 1,
							 NAUTILUS_PREFERENCES_SHOW_DIRECTORY_ITEM_COUNTS,
							 NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane), _("Show Thumbnails for Image Files"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane),
							 2,
							 NAUTILUS_PREFERENCES_SHOW_IMAGE_FILE_THUMBNAILS,
							 NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);

	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane), _("Preview Sound Files"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane),
							 3,
							 NAUTILUS_PREFERENCES_PREVIEW_SOUND,
							 NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);

	
	/* FIXME bugzilla.eazel.com 2560: This title phrase needs improvement. */
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane), _("Make Folder Appearance Details Public"));
	
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (tradeoffs_pane),
							 4,
							 NAUTILUS_PREFERENCES_USE_PUBLIC_METADATA,
							 NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);


	/* Update the dialog so that the right items show up based on the current user level */
	nautilus_preferences_dialog_update (NAUTILUS_PREFERENCES_DIALOG (prefs_dialog));

	return prefs_dialog;
}

/* Update the sensitivity of the search pane when the medusa blocked state changes */
static void
global_preferences_medusa_blocked_changed_callback (gpointer callback_data)
{
	gboolean medusa_blocked;
	
	g_return_if_fail (GTK_IS_WIDGET (callback_data));

	medusa_blocked = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_MEDUSA_BLOCKED);

	gtk_widget_set_sensitive (GTK_WIDGET (callback_data), !medusa_blocked);
}

static GtkWidget *
global_preferences_create_search_pane (NautilusPreferencesBox *preference_box)
{
	GtkWidget *search_pane;
	GtkWidget *fast_search_group;
	
	g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_BOX (preference_box), NULL);


 	/*
 	 * Search Settings 
 	 */
	search_pane = nautilus_preferences_box_add_pane (preference_box,
							 _("Search"));
#ifdef HAVE_MEDUSA
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (search_pane),
					     _("Search Complexity Options"));
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (search_pane),
							 0,
							 NAUTILUS_PREFERENCES_SEARCH_BAR_TYPE,
							 NAUTILUS_PREFERENCE_ITEM_ENUM);
	fast_search_group = nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (search_pane),
								 _("Fast Search"));
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (search_pane),
							 1,
							 NAUTILUS_PREFERENCES_USE_FAST_SEARCH,
							 NAUTILUS_PREFERENCE_ITEM_BOOLEAN);
#endif
	nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (search_pane),
					     _("Search Engines"));
	nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (search_pane),
#ifdef HAVE_MEDUSA
							 2,
#else
							 0,
#endif
							 NAUTILUS_PREFERENCES_SEARCH_WEB_URI,
							 NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);

#ifdef HAVE_MEDUSA
	/* Setup callbacks so that we can update the sensitivity of
	 * the search pane when the medusa blocked state changes
	 */
	nautilus_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_MEDUSA_BLOCKED,
						       global_preferences_medusa_blocked_changed_callback,
						       fast_search_group,
						       GTK_OBJECT (fast_search_group));
	global_preferences_medusa_blocked_changed_callback (fast_search_group);
#endif
	return search_pane;
}

/*
 * We have 2 font picker items, but we only show one depending on 
 * the value of the SMOOTH_GRAPHICS preference.
 */
static void
appearance_pane_update (gpointer callback_data)
{
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_PANE (callback_data));

	nautilus_preferences_pane_update (NAUTILUS_PREFERENCES_PANE (callback_data));
}

static GtkWidget *
global_preferences_create_font_group (NautilusPreferencesPane *appearance_pane)
{
	GtkWidget *font_group;
	GtkWidget *font_picker_smooth_item;
	GtkWidget *font_picker_gdk_item;

	font_group =
		nautilus_preferences_pane_add_group (NAUTILUS_PREFERENCES_PANE (appearance_pane), _("Fonts"));

	font_picker_gdk_item = 
		nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
								 1,
								 NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
								 NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);

	nautilus_preferences_item_set_control_preference (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
							  NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE);
	nautilus_preferences_item_set_control_action (NAUTILUS_PREFERENCES_ITEM (font_picker_gdk_item),
						      NAUTILUS_PREFERENCE_ITEM_HIDE);

	font_picker_smooth_item =
		nautilus_preferences_pane_add_item_to_nth_group (NAUTILUS_PREFERENCES_PANE (appearance_pane),
								 1,
								 NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
								 NAUTILUS_PREFERENCE_ITEM_SMOOTH_FONT);
	
	nautilus_preferences_item_set_control_preference (NAUTILUS_PREFERENCES_ITEM (font_picker_smooth_item),
							  NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE);
	nautilus_preferences_item_set_control_action (NAUTILUS_PREFERENCES_ITEM (font_picker_smooth_item),
						      NAUTILUS_PREFERENCE_ITEM_SHOW);

 	nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_SMOOTH_GRAPHICS_MODE,
 					   appearance_pane_update,
 					   appearance_pane);
	
	return font_group;
}

/* Make a query to find out what sidebar panels are available. */
static GList *
global_preferences_get_sidebar_panel_view_identifiers (void)
{
	CORBA_Environment ev;
	const char *query;
        OAF_ServerInfoList *oaf_result;
	guint i;
	NautilusViewIdentifier *id;
	GList *view_identifiers;

	CORBA_exception_init (&ev);

	query = "nautilus:sidebar_panel_name.defined() AND repo_ids.has ('IDL:Bonobo/Control:1.0')";

	oaf_result = oaf_query (query, NULL, &ev);
		
	view_identifiers = NULL;

        if (ev._major == CORBA_NO_EXCEPTION && oaf_result != NULL) {
		for (i = 0; i < oaf_result->_length; i++) {
			id = nautilus_view_identifier_new_from_sidebar_panel
				(&oaf_result->_buffer[i]);
			view_identifiers = g_list_prepend (view_identifiers, id);
		}
		view_identifiers = g_list_reverse (view_identifiers);
	} 

	if (oaf_result != NULL) {
		CORBA_free (oaf_result);
	}
	
	CORBA_exception_free (&ev);

	return view_identifiers;
}

GList *
nautilus_global_preferences_get_enabled_sidebar_panel_view_identifiers (void)
{
	GList *enabled_view_identifiers;
 	GList *disabled_view_identifiers;
        
	enabled_view_identifiers = global_preferences_get_sidebar_panel_view_identifiers ();

	enabled_view_identifiers = nautilus_g_list_partition (enabled_view_identifiers,
							      global_preferences_is_sidebar_panel_enabled_cover,
							      NULL,
							      &disabled_view_identifiers);
	
	nautilus_view_identifier_list_free (disabled_view_identifiers);
	
        return enabled_view_identifiers;
}

static void
destroy_global_prefs_dialog (void)
{
	/* Free the dialog first, cause it has refs to preferences */
	if (global_prefs_dialog != NULL) {
		/* Since it's a top-level window, it's OK to destroy rather than unref'ing. */
		gtk_widget_destroy (global_prefs_dialog);
	}
}

static GtkWidget *
global_preferences_get_dialog (void)
{
	static gboolean set_up_exit = FALSE;

	nautilus_global_preferences_initialize ();

	if (global_prefs_dialog == NULL) {
		/* Install descriptions right before creating the dialog.
		 * The descriptions are only used within the preferences
		 * dialog.
		 */
		global_preferences_install_descriptions ();
		global_prefs_dialog = global_preferences_create_dialog ();
	}

	if (!set_up_exit) {
		g_atexit (destroy_global_prefs_dialog);
		set_up_exit = TRUE;
	}

	return global_prefs_dialog;
}

static struct 
{
	const char *name;
	gboolean novice_default;
	gboolean intermediate_default;
	gboolean advanced_default;
	int visible_user_level;
} known_sidebar_panels[] =
{
	{ "OAFIID:nautilus_notes_view:7f04c3cb-df79-4b9a-a577-38b19ccd4185",       TRUE,  TRUE,  TRUE,  NAUTILUS_USER_LEVEL_INTERMEDIATE},
	{ "OAFIID:hyperbola_navigation_tree:57542ce0-71ff-442d-a764-462c92514234", TRUE,  TRUE,  TRUE,  NAUTILUS_USER_LEVEL_INTERMEDIATE },
	{ "OAFIID:nautilus_history_view:a7a85bdd-2ecf-4bc1-be7c-ed328a29aacb",     TRUE,  TRUE,  TRUE,  NAUTILUS_USER_LEVEL_INTERMEDIATE },
	{ "OAFIID:nautilus_tree_view:2d826a6e-1669-4a45-94b8-23d65d22802d",        FALSE, TRUE,  TRUE,  NAUTILUS_USER_LEVEL_INTERMEDIATE },
};

static void
global_preferences_install_sidebar_panel_defaults (void)
{
	guint i;
	
	/* Install the user level on/off defaults for known sidebar panels */
	for (i = 0; i < NAUTILUS_N_ELEMENTS (known_sidebar_panels); i++) {
		char *key = global_preferences_get_sidebar_panel_key (known_sidebar_panels[i].name);
		
		nautilus_preferences_default_set_boolean (key,
							  NAUTILUS_USER_LEVEL_NOVICE,
							  known_sidebar_panels[i].novice_default);
		nautilus_preferences_default_set_boolean (key,
							  NAUTILUS_USER_LEVEL_INTERMEDIATE,
							  known_sidebar_panels[i].intermediate_default);
		nautilus_preferences_default_set_boolean (key,
							  NAUTILUS_USER_LEVEL_ADVANCED,
							  known_sidebar_panels[i].advanced_default);

		nautilus_preferences_set_visible_user_level (key,
							     known_sidebar_panels[i].visible_user_level);

		g_free (key);
	}
}

static void
global_preferences_install_sidebar_panel_descriptions (void)
{
 	GList *view_identifiers;
 	GList *iterator;
 	NautilusViewIdentifier *identifier;
 	char *key, *label;
	
	/* Install the descriptions for the available sidebar panels */
 	view_identifiers = global_preferences_get_sidebar_panel_view_identifiers ();

 	for (iterator = view_identifiers; iterator != NULL; iterator = iterator->next) {

 		identifier = iterator->data;
 		g_return_if_fail (identifier != NULL);
		
 		key = global_preferences_get_sidebar_panel_key (identifier->iid);
 		g_return_if_fail (key != NULL);

		label = g_strdup_printf (_("Display %s tab in sidebar"), identifier->name);
 		nautilus_preferences_set_description (key, label);
 		g_free (key);
 		g_free (label);
 	}

 	nautilus_view_identifier_list_free (view_identifiers);
}

static char *
global_preferences_get_sidebar_panel_key (const char *panel_iid)
{
	g_return_val_if_fail (panel_iid != NULL, NULL);

	return g_strdup_printf ("%s/%s", NAUTILUS_PREFERENCES_SIDEBAR_PANELS_NAMESPACE, panel_iid);
}

static gboolean
global_preferences_is_sidebar_panel_enabled (NautilusViewIdentifier *panel_identifier)
{
	gboolean enabled;
        gchar  *key;
	
	g_return_val_if_fail (panel_identifier != NULL, FALSE);
	g_return_val_if_fail (panel_identifier->iid != NULL, FALSE);
	
	key = global_preferences_get_sidebar_panel_key (panel_identifier->iid);
	g_return_val_if_fail (key != NULL, FALSE);
        enabled = nautilus_preferences_get_boolean (key);
        g_free (key);

        return enabled;
}

static gboolean
global_preferences_is_sidebar_panel_enabled_cover (gpointer data, gpointer callback_data)
{
	return global_preferences_is_sidebar_panel_enabled (data);
}

static void
global_preferences_install_speed_tradeoff_descriptions (const char *name,
							const char *description)
{							  
	nautilus_preferences_set_description (name, description);
	
 	nautilus_preferences_enumeration_insert (name,
						 _("always"),
						    _("Always"),
						 NAUTILUS_SPEED_TRADEOFF_ALWAYS);
 	nautilus_preferences_enumeration_insert (name,
						 _("local only"),
						 _("Local Files Only"),
						 NAUTILUS_SPEED_TRADEOFF_LOCAL_ONLY);
 	nautilus_preferences_enumeration_insert (name,
						 _("never"),
						 _("Never"),
						 NAUTILUS_SPEED_TRADEOFF_NEVER);
}							  

static void
global_preferences_install_home_location_defaults (void)
{
	char *default_novice_home_uri;
	char *default_intermediate_home_uri;
	char *user_main_directory;		
	
	user_main_directory = nautilus_get_user_main_directory ();
	
	default_novice_home_uri = gnome_vfs_get_uri_from_local_path (user_main_directory);
	default_intermediate_home_uri = gnome_vfs_get_uri_from_local_path (g_get_home_dir ());
	
	nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_HOME_URI,
						 NAUTILUS_USER_LEVEL_NOVICE,
						 default_novice_home_uri);
	
	nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_HOME_URI,
						 NAUTILUS_USER_LEVEL_INTERMEDIATE,
						 default_intermediate_home_uri);
	
	g_free (user_main_directory);
	g_free (default_novice_home_uri);
	g_free (default_intermediate_home_uri);
}

static void
global_preferences_install_font_defaults (void)
{
	char *default_smooth_font;

	nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_FONT_FAMILY,
						 NAUTILUS_USER_LEVEL_NOVICE,
						 _("helvetica"));

	/* The default smooth font */
	default_smooth_font = nautilus_font_manager_get_default_font ();
	
	nautilus_preferences_default_set_string (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT,
						 NAUTILUS_USER_LEVEL_NOVICE,
						 default_smooth_font);
	g_free (default_smooth_font);
}

static void
global_preferences_use_fast_search_changed_callback (gpointer callback_data)
{
	gboolean use_fast_search;
	gboolean services_are_blocked;
	NautilusCronStatus cron_status;

	if (global_prefs_dialog) {
		use_fast_search = nautilus_preferences_get_boolean (NAUTILUS_PREFERENCES_USE_FAST_SEARCH);
		
		nautilus_medusa_enable_services (use_fast_search);
		services_are_blocked = nautilus_medusa_blocked ();
		if (use_fast_search && !services_are_blocked) {
			cron_status = nautilus_medusa_check_cron_is_enabled ();
			switch (cron_status) {
			case NAUTILUS_CRON_STATUS_OFF:
				nautilus_show_info_dialog_with_details (_("Indexing is turned on, enabling the "
									  "fast search feature. However, indexing "
									  "currently can't be performed because "
									  "the program crond, which does "
									  "nightly tasks on your computer, "
									  "is turned off. To make sure fast "
									  "searches can be done, turn crond on."),
									_("Files May Not Be Indexed"),
									_("If you are running Linux, you can log "
									  "in as root and type these commands "
									  "to start cron:\n\n"
									  "/sbin/chkconfig --level 345 crond on\n"
									  "/etc/rc.d/init.d/cron start\n"),
									NULL);
				
				break;
			case NAUTILUS_CRON_STATUS_UNKNOWN:
				nautilus_show_info_dialog_with_details (_("Indexing is turned on, enabling the "
									  "fast search feature. However, indexing "
									  "may not be performed because the "
									  "program crond, which does nightly "
									  "tasks on your computer, may be turned "
									  "off. To make sure fast searches can be "
									  "done, check to make sure that crond "
									  "is turned on.\n\n"),
									_("Files May Not Be Indexed"),
									_("If you are running Linux, you can log "
									  "in as root and type these commands "
									  "to start cron:\n\n"
									  "/sbin/chkconfig --level 345 crond on\n"
									  "/etc/rc.d/init.d/cron start\n"),
									NULL);
				break;
			default:
				break;
			}
		}
	}
}
	
static void 
global_preferences_medusa_state_changed_callback (gpointer callback_data)
{
	nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_USE_FAST_SEARCH,
					  nautilus_medusa_services_have_been_enabled_by_user ());
	
	nautilus_preferences_set_boolean (NAUTILUS_PREFERENCES_MEDUSA_BLOCKED,
					  nautilus_medusa_blocked ());

}

static void
global_preferences_install_medusa_defaults (void)
{
	gboolean medusa_blocked;
	gboolean use_fast_search;

	medusa_blocked = nautilus_medusa_blocked ();
	use_fast_search = nautilus_medusa_services_have_been_enabled_by_user ();

	/* This one controls the sensitivity */
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_MEDUSA_BLOCKED,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  medusa_blocked);

	/* This is the one that appears in the preferences dialog */
	nautilus_preferences_default_set_boolean (NAUTILUS_PREFERENCES_USE_FAST_SEARCH,
						  NAUTILUS_USER_LEVEL_NOVICE,
						  use_fast_search);


	nautilus_preferences_add_callback (NAUTILUS_PREFERENCES_USE_FAST_SEARCH,
					   global_preferences_use_fast_search_changed_callback,
					   NULL);

	nautilus_medusa_add_system_state_changed_callback (global_preferences_medusa_state_changed_callback,
							   NULL);
}

static gboolean
global_preferences_close_dialog_callback (GtkWidget   *dialog,
					  gpointer    user_data)
{
	nautilus_global_preferences_hide_dialog ();

	return TRUE;
}


/*
 * Public functions
 */
void
nautilus_global_preferences_show_dialog (void)
{
	GtkWidget *dialog = global_preferences_get_dialog ();

	nautilus_gtk_window_present (GTK_WINDOW (dialog));
}

void
nautilus_global_preferences_hide_dialog (void)
{
	GtkWidget *dialog = global_preferences_get_dialog ();

	gtk_widget_hide (dialog);
}

void
nautilus_global_preferences_set_dialog_title (const char *title)
{
	GtkWidget *dialog;
	g_return_if_fail (title != NULL);
	
	dialog = global_preferences_get_dialog ();

	gtk_window_set_title (GTK_WINDOW (dialog), title);
}

/**
 * nautilus_global_preferences_get_smooth_font
 *
 * Return value: The user's preferred smooth font.  Need to 
 *               unref the returned GtkObject when done with it.
 */
NautilusScalableFont *
nautilus_global_preferences_get_smooth_font (void)
{
	NautilusScalableFont *scalable_font;
	char *font_file_name;

	font_file_name = nautilus_preferences_get (NAUTILUS_PREFERENCES_DIRECTORY_VIEW_SMOOTH_FONT);
	
	scalable_font = 
		(font_file_name && g_file_exists (font_file_name)) ?
		nautilus_scalable_font_new (font_file_name) :
		nautilus_scalable_font_get_default_font ();
	g_free (font_file_name);
	
	g_assert (NAUTILUS_IS_SCALABLE_FONT (scalable_font));

	return scalable_font;
}

/**
 * nautilus_global_preferences_get_smooth_bold_font
 *
 * Return value: A bold flavor on the user's preferred smooth font.  If
 *               no bold font is found, then the plain preffered font is
 *               used. Need to unref the returned GtkObject when done
 *               with it.
 */
NautilusScalableFont *
nautilus_global_preferences_get_smooth_bold_font (void)
{
	NautilusScalableFont *plain_font;
	NautilusScalableFont *bold_font;

	plain_font = nautilus_global_preferences_get_smooth_font ();
	g_assert (NAUTILUS_IS_SCALABLE_FONT (plain_font));

	bold_font = nautilus_scalable_font_make_bold (plain_font);

	if (bold_font == NULL) {
		bold_font = plain_font;
	} else {
		gtk_object_unref (GTK_OBJECT (plain_font));
	}

	g_assert (NAUTILUS_IS_SCALABLE_FONT (bold_font));
	return bold_font;
}

void
nautilus_global_preferences_initialize (void)
{
	static gboolean initialized = FALSE;

	if (initialized) {
		return;
	}

	initialized = TRUE;

	/* Install defaults */
	global_preferences_install_defaults ();

	/* Install visiblities */
	global_preferences_install_visibility ();
}