summaryrefslogtreecommitdiff
path: root/libnautilus-extensions/nautilus-preferences-item.c
blob: fad42497391ae8da7c52fa8b3f2b5c80807f3911 (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
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */

/* nautilus-preferences-item.c - Implementation for an individual prefs item.

   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-preferences-item.h"
#include "nautilus-preferences.h"
#include "nautilus-file-utilities.h"
#include "nautilus-glib-extensions.h"
#include "nautilus-gtk-macros.h"
#include "nautilus-string.h"
#include <libgnomevfs/gnome-vfs.h>

#include <libgnome/gnome-i18n.h>
#include <gtk/gtkcheckbutton.h>
#include <gtk/gtksignal.h>
#include <gtk/gtklabel.h>
#include <gtk/gtkmain.h>

#include "nautilus-radio-button-group.h"
#include "nautilus-string-picker.h"
#include "nautilus-text-caption.h"

#include "nautilus-global-preferences.h"

static const guint PREFERENCES_ITEM_TITLE_SPACING = 4;
static const guint PREFERENCES_ITEM_FRAME_BORDER_WIDTH = 6;
static const NautilusPreferencesItemType PREFERENCES_ITEM_UNDEFINED_ITEM = -1U;
static gboolean text_idle_handler = FALSE;
static gboolean integer_idle_handler = FALSE;

struct _NautilusPreferencesItemDetails
{
	char *preference_name;
	NautilusPreferencesItemType item_type;
	GtkWidget *child;
	guint change_signal_ID;
};

/* GtkObjectClass methods */
static void nautilus_preferences_item_initialize_class       (NautilusPreferencesItemClass *preferences_item_class);
static void nautilus_preferences_item_initialize             (NautilusPreferencesItem      *preferences_item);
static void preferences_item_destroy                         (GtkObject                    *object);

/* Private stuff */
static void preferences_item_construct                       (NautilusPreferencesItem      *item,
							      const char                   *preference_name,
							      NautilusPreferencesItemType   item_type);
static void preferences_item_create_enum                     (NautilusPreferencesItem      *item,
							      const char                   *preference_name);
static void preferences_item_create_short_enum               (NautilusPreferencesItem      *item,
							      const char                   *preference_name);
static void preferences_item_create_boolean                  (NautilusPreferencesItem      *item,
							      const char                   *preference_name);
static void preferences_item_create_editable_string          (NautilusPreferencesItem      *item,
							      const char                   *preference_name);
static void preferences_item_create_integer                  (NautilusPreferencesItem      *item,
							      const char                   *preference_name);
static void preferences_item_create_font_family              (NautilusPreferencesItem      *item,
							      const char                   *preference_name);
static void preferences_item_update_text_settings_at_idle    (NautilusPreferencesItem      *preferences_item);
static void preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem      *preferences_item);
static void enum_radio_group_changed_callback                (GtkWidget                    *button_group,
							      GtkWidget                    *button,
							      gpointer                      user_data);
static void boolean_button_toggled_callback                  (GtkWidget                    *button_group,
							      gpointer                      user_data);
static void text_item_changed_callback                       (GtkWidget                    *string_picker,
							      gpointer                      user_data);
static void editable_string_changed_callback                 (GtkWidget                    *caption,
							      gpointer                      user_data);
static void integer_changed_callback                         (GtkWidget                    *caption,
							      gpointer                      user_data);

NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusPreferencesItem, nautilus_preferences_item, GTK_TYPE_VBOX)

/* NautilusPreferencesItemClass methods */
static void
nautilus_preferences_item_initialize_class (NautilusPreferencesItemClass *preferences_item_class)
{
	GtkObjectClass *object_class;
	GtkWidgetClass *widget_class;
	
	object_class = GTK_OBJECT_CLASS (preferences_item_class);
	widget_class = GTK_WIDGET_CLASS (preferences_item_class);

 	parent_class = gtk_type_class (gtk_vbox_get_type ());

	/* GtkObjectClass */
	object_class->destroy = preferences_item_destroy;
}

static void
nautilus_preferences_item_initialize (NautilusPreferencesItem *item)
{
	item->details = g_new0 (NautilusPreferencesItemDetails, 1);
	item->details->item_type = PREFERENCES_ITEM_UNDEFINED_ITEM;
}

/* GtkObjectClass methods */
static void
preferences_item_destroy (GtkObject *object)
{
	NautilusPreferencesItem * item;
	
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (object));
	
	item = NAUTILUS_PREFERENCES_ITEM (object);

	g_free (item->details->preference_name);
	g_free (item->details);
	
	/* Chain destroy */
	NAUTILUS_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
}

/*
 * Private stuff
 */
static void
preferences_item_construct (NautilusPreferencesItem	*item,
			    const char			*preference_name,
			    NautilusPreferencesItemType	item_type)
{
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));

	g_return_if_fail (nautilus_strlen (preference_name) > 0);
	g_assert (item_type != PREFERENCES_ITEM_UNDEFINED_ITEM);

	g_assert (item->details->child == NULL);

	g_assert (item->details->preference_name == NULL);
	
	item->details->preference_name = g_strdup (preference_name);
	item->details->item_type = item_type;

	/* Create the child widget according to the item type */
	switch (item_type)
	{
	case NAUTILUS_PREFERENCE_ITEM_BOOLEAN:
		preferences_item_create_boolean (item, preference_name);
		break;
		
	case NAUTILUS_PREFERENCE_ITEM_ENUM:
		preferences_item_create_enum (item, preference_name);
		break;

	case NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM:
		preferences_item_create_short_enum (item, preference_name);
		break;

	case NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY:
		preferences_item_create_font_family (item, preference_name);
		break;
	
	case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
		preferences_item_create_editable_string (item, preference_name);
		break;	

	case NAUTILUS_PREFERENCE_ITEM_INTEGER:
		preferences_item_create_integer (item, preference_name);
		break;	
	}

	g_assert (item->details->child != NULL);
	g_assert (item->details->change_signal_ID != 0);

	nautilus_preferences_item_update_displayed_value (item);

	gtk_box_pack_start (GTK_BOX (item),
			    item->details->child,
			    FALSE,
			    FALSE,
			    0);
	
	gtk_widget_show (item->details->child);
}

static void
preferences_item_update_enum (const NautilusPreferencesItem *item)
{
	int value;
	char *preference_name;
	guint i;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_ENUM);

	preference_name = item->details->preference_name;
 	value = nautilus_preferences_get_integer (preference_name);

	for (i = 0; i < nautilus_preferences_enumeration_get_num_entries (preference_name); i++) {
		if (value == nautilus_preferences_enumeration_get_nth_value (preference_name, i)) {
			nautilus_radio_button_group_set_active_index (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), i);
		}
	}
}

static void
preferences_item_create_enum (NautilusPreferencesItem	*item,
			      const char 	*preference_name)
{
	guint	i;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (nautilus_strlen (preference_name) > 0);

	g_assert (item->details->preference_name != NULL);

	item->details->child = nautilus_radio_button_group_new (FALSE);
		
	for (i = 0; i < nautilus_preferences_enumeration_get_num_entries (preference_name); i++) {
		char *description;
		
		description = nautilus_preferences_enumeration_get_nth_description (preference_name, i);
		
		g_assert (description != NULL);
		
		nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child),
						    description);

		g_free (description);
	}
	
	item->details->change_signal_ID = 
		gtk_signal_connect (GTK_OBJECT (item->details->child),
			    	    "changed",
			    	    GTK_SIGNAL_FUNC (enum_radio_group_changed_callback),
			    	    (gpointer) item);
}

static void
preferences_item_update_short_enum (const NautilusPreferencesItem *item)
{
	int value;
	char *preference_name;
	guint i;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM);

	preference_name = item->details->preference_name;
 	value = nautilus_preferences_get_integer (preference_name);

	for (i = 0; i < nautilus_preferences_enumeration_get_num_entries (preference_name); i++) {
		if (value == nautilus_preferences_enumeration_get_nth_value (preference_name, i)) {
			nautilus_radio_button_group_set_active_index (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child), i);
		}
	}
}

/* This is just like preferences_item_create_enum except the choices
 * are laid out horizontally instead of vertically (hence it works decently
 * only with short text for the choices).
 */
static void
preferences_item_create_short_enum (NautilusPreferencesItem	*item,
			      	    const char 	*preference_name)
{
	guint	i;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (nautilus_strlen (preference_name) > 0);

	g_assert (item->details->preference_name != NULL);

	item->details->child = nautilus_radio_button_group_new (TRUE);
		
	for (i = 0; i < nautilus_preferences_enumeration_get_num_entries (preference_name); i++) {
		char *description;
		
		description = nautilus_preferences_enumeration_get_nth_description (preference_name, i);

		g_assert (description != NULL);

		nautilus_radio_button_group_insert (NAUTILUS_RADIO_BUTTON_GROUP (item->details->child),
						    description);

		g_free (description);
	}
	
	item->details->change_signal_ID = 
		gtk_signal_connect (GTK_OBJECT (item->details->child),
			    	    "changed",
			    	    GTK_SIGNAL_FUNC (enum_radio_group_changed_callback),
			    	    (gpointer) item);
}

static void
preferences_item_update_boolean (const NautilusPreferencesItem *item)
{
	gboolean value;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_BOOLEAN);

	value = nautilus_preferences_get_boolean (item->details->preference_name);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (item->details->child), value);
}

static void
preferences_item_create_boolean (NautilusPreferencesItem	*item,
				 const char 	*preference_name)
{
	char		*description;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (nautilus_strlen (preference_name) > 0);

	g_assert (item->details->preference_name != NULL);
	description = nautilus_preferences_get_description (preference_name);

	g_assert (description != NULL);

	item->details->child = gtk_check_button_new_with_label (description);
	gtk_label_set_justify (GTK_LABEL (GTK_BIN (item->details->child)->child), GTK_JUSTIFY_LEFT);

	g_free (description);
				      
	item->details->change_signal_ID = 
		gtk_signal_connect (GTK_OBJECT (item->details->child),
			    	    "toggled",
			    	    GTK_SIGNAL_FUNC (boolean_button_toggled_callback),
			    	    (gpointer) item);
}

static void
preferences_item_update_editable_string (const NautilusPreferencesItem *item)
{
	char	*current_value;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING);

	current_value = nautilus_preferences_get (item->details->preference_name);

	g_assert (current_value != NULL);
	nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (item->details->child), current_value);
	g_free (current_value);
}

static void
preferences_item_create_editable_string (NautilusPreferencesItem	*item,
					 const char 	*preference_name)
{
	char	*description;
	
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (nautilus_strlen (preference_name) > 0);

	description = nautilus_preferences_get_description (preference_name);
	g_assert (description != NULL);
	
	item->details->child = nautilus_text_caption_new ();

	/* FIXME This is a special case for the home uri preference,
	   in the future this should be generalized. */
	if (g_strcasecmp (preference_name, NAUTILUS_PREFERENCES_HOME_URI) == 0)
	{
		nautilus_text_caption_set_expand_tilde (NAUTILUS_TEXT_CAPTION (item->details->child), TRUE);
	}

	nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);

	g_free (description);
	
	item->details->change_signal_ID = 
		gtk_signal_connect (GTK_OBJECT (item->details->child),
	 			    "changed",
	 			    GTK_SIGNAL_FUNC (editable_string_changed_callback),
			    	    (gpointer) item);
}

static void
preferences_item_update_integer (const NautilusPreferencesItem *item)
{
	char *current_value;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_INTEGER);

	current_value = g_strdup_printf ("%d", nautilus_preferences_get_integer (item->details->preference_name));

	g_assert (current_value != NULL);
	nautilus_text_caption_set_text (NAUTILUS_TEXT_CAPTION (item->details->child), current_value);
	g_free (current_value);
}

static void
preferences_item_create_integer (NautilusPreferencesItem	*item,
				 const char 	*preference_name)
{
	char	*description;
	
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (nautilus_strlen (preference_name) > 0);

	description = nautilus_preferences_get_description (preference_name);
	
	g_assert (description != NULL);
	
	item->details->child = nautilus_text_caption_new ();

	nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);

	g_free (description);

	item->details->change_signal_ID = 
		gtk_signal_connect (GTK_OBJECT (item->details->child),
	 			    "changed",
	 			    GTK_SIGNAL_FUNC (integer_changed_callback),
			    	    (gpointer) item);
}

static void
preferences_item_update_font_family (const NautilusPreferencesItem *item)
{
	char *current_value;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (item->details->item_type == NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY);

	current_value = nautilus_preferences_get (item->details->preference_name);
	g_assert (current_value != NULL);

	nautilus_string_picker_set_selected_string (NAUTILUS_STRING_PICKER (item->details->child), current_value);

	g_free (current_value);
}

static void
preferences_item_create_font_family (NautilusPreferencesItem *item,
				  const char *preference_name)
{
	char *description;
	NautilusStringList *font_list;

	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));
	g_return_if_fail (nautilus_strlen (preference_name) > 0);

	description = nautilus_preferences_get_description (preference_name);
	g_return_if_fail (description != NULL);
	
	item->details->child = nautilus_string_picker_new ();
	nautilus_caption_set_title_label (NAUTILUS_CAPTION (item->details->child), description);
	
	g_free (description);

	/* FIXME bugzilla.eazel.com 1274: Need to query system for available fonts */
	font_list = nautilus_string_list_new (TRUE);

	nautilus_string_list_insert (font_list, _("helvetica"));
	nautilus_string_list_insert (font_list, _("times"));
	nautilus_string_list_insert (font_list, _("courier"));
	nautilus_string_list_insert (font_list, _("lucida"));

	nautilus_string_picker_set_string_list (NAUTILUS_STRING_PICKER (item->details->child), font_list);
	nautilus_string_list_free (font_list);

	item->details->change_signal_ID = gtk_signal_connect (GTK_OBJECT (item->details->child),
							      "changed",
							      GTK_SIGNAL_FUNC (text_item_changed_callback),
							      (gpointer) item);
}

/* NautilusPreferencesItem public methods */
GtkWidget *
nautilus_preferences_item_new (const char			*preference_name,
			       NautilusPreferencesItemType	item_type)
{
	NautilusPreferencesItem * item;

	g_return_val_if_fail (preference_name != NULL, NULL);

	item = NAUTILUS_PREFERENCES_ITEM
		(gtk_widget_new (nautilus_preferences_item_get_type (), NULL));

	/* Cast away the constness so that the preferences object can be
	 * refed in this object. */
	preferences_item_construct (item, preference_name, item_type);

	return GTK_WIDGET (item);
}

static void
enum_radio_group_changed_callback (GtkWidget *buttons, GtkWidget * button, gpointer user_data)
{
	NautilusPreferencesItem	*item;
	int i;

	g_assert (user_data != NULL);
	g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));
	
	item = NAUTILUS_PREFERENCES_ITEM (user_data);

	g_assert (item->details->preference_name != NULL);

	i = nautilus_radio_button_group_get_active_index (NAUTILUS_RADIO_BUTTON_GROUP (buttons));
	
	nautilus_preferences_set_integer (item->details->preference_name,
					  nautilus_preferences_enumeration_get_nth_value (item->details->preference_name, i));
}

static void
boolean_button_toggled_callback (GtkWidget *button, gpointer user_data)
{
	NautilusPreferencesItem	*item;
	gboolean		active_state;

	g_assert (user_data != NULL);
	g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));
	
	item = NAUTILUS_PREFERENCES_ITEM (user_data);

	active_state = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));

	nautilus_preferences_set_boolean (item->details->preference_name, active_state);
}

static void
text_item_changed_callback (GtkWidget *button, gpointer user_data)
{
	NautilusPreferencesItem	*item;

	g_assert (user_data != NULL);
	g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));

	item = NAUTILUS_PREFERENCES_ITEM (user_data);

	g_assert (item->details->child != NULL);
	g_assert (NAUTILUS_IS_STRING_PICKER (item->details->child));

	preferences_item_update_text_settings_at_idle (item);
}

static void
editable_string_changed_callback (GtkWidget *button, gpointer user_data)
{
	NautilusPreferencesItem	*item;
	
	g_assert (user_data != NULL);
	g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));

	item = NAUTILUS_PREFERENCES_ITEM (user_data);

	g_assert (item->details->child != NULL);
	g_assert (NAUTILUS_IS_TEXT_CAPTION (item->details->child));

	preferences_item_update_text_settings_at_idle (item);
}

static void
integer_changed_callback (GtkWidget *button, gpointer user_data)
{
	NautilusPreferencesItem	*item;
	
	g_assert (user_data != NULL);
	g_assert (NAUTILUS_IS_PREFERENCES_ITEM (user_data));

	item = NAUTILUS_PREFERENCES_ITEM (user_data);

	g_assert (item->details->child != NULL);
	g_assert (NAUTILUS_IS_TEXT_CAPTION (item->details->child));

	preferences_item_update_integer_settings_at_idle (item);
}

char *
nautilus_preferences_item_get_name (const NautilusPreferencesItem *preferences_item)
{
	g_return_val_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item), NULL);

	return g_strdup (preferences_item->details->preference_name);
}

void
nautilus_preferences_item_update_displayed_value (const NautilusPreferencesItem *item)
{
	NautilusPreferencesItemType item_type;
	
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (item));

	item_type = item->details->item_type;

	g_return_if_fail (item->details->item_type != PREFERENCES_ITEM_UNDEFINED_ITEM);

	/* Block the change signal while we update the widget to match the preference */
	g_assert (item->details->change_signal_ID != 0);
	g_assert (GTK_IS_WIDGET (item->details->child));
	gtk_signal_handler_block (GTK_OBJECT (item->details->child),
				  item->details->change_signal_ID);

	/* Update the child widget according to the item type */
	switch (item_type)
	{
	case NAUTILUS_PREFERENCE_ITEM_BOOLEAN:
		preferences_item_update_boolean (item);
		break;
		
	case NAUTILUS_PREFERENCE_ITEM_ENUM:
		preferences_item_update_enum (item);
		break;

	case NAUTILUS_PREFERENCE_ITEM_SHORT_ENUM:
		preferences_item_update_short_enum (item);
		break;

	case NAUTILUS_PREFERENCE_ITEM_FONT_FAMILY:
		preferences_item_update_font_family (item);
		break;
	
	case NAUTILUS_PREFERENCE_ITEM_EDITABLE_STRING:
		preferences_item_update_editable_string (item);
		break;	

	case NAUTILUS_PREFERENCE_ITEM_INTEGER:
		preferences_item_update_integer (item);
		break;
	default:
		g_assert_not_reached ();
	}

	gtk_signal_handler_unblock (GTK_OBJECT (item->details->child),
				    item->details->change_signal_ID);
}

static gboolean
update_text_settings_at_idle (NautilusPreferencesItem *preferences_item)
{
	char *text;

	text = nautilus_text_caption_get_text (NAUTILUS_TEXT_CAPTION (preferences_item->details->child));

	if (text != NULL) {
		nautilus_preferences_set (preferences_item->details->preference_name, text);
		g_free (text);
	}
	
	text_idle_handler = FALSE;

	return FALSE;
}

static void
preferences_item_update_text_settings_at_idle (NautilusPreferencesItem *preferences_item)
{
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item));

	if (text_idle_handler == FALSE) {
		gtk_idle_add ((GtkFunction) update_text_settings_at_idle, preferences_item);
		text_idle_handler = TRUE;
	}
}

static gboolean
update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item)
{
	int value = 0;
	char *text;

	text = nautilus_text_caption_get_text (NAUTILUS_TEXT_CAPTION (preferences_item->details->child));

	if (text != NULL) {
		nautilus_eat_str_to_int (text, &value);
	}
	
	nautilus_preferences_set_integer (preferences_item->details->preference_name, value);

	integer_idle_handler = FALSE;

	return FALSE;
}

static void
preferences_item_update_integer_settings_at_idle (NautilusPreferencesItem *preferences_item)
{
	g_return_if_fail (NAUTILUS_IS_PREFERENCES_ITEM (preferences_item));

	if (integer_idle_handler == FALSE) {
		gtk_idle_add ((GtkFunction) update_integer_settings_at_idle, preferences_item);
		integer_idle_handler = TRUE;
	}
}