summaryrefslogtreecommitdiff
path: root/src/yelp-settings.c
blob: 8e7cd7a6cbce3735e2da3622e036636d3f7a66d0 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/*
 * Copyright (C) 2004 Shaun McCance <shaunm@gnome.org>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Shaun McCance <shaunm@gnome.org>
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gtk/gtk.h>
#include <glade/glade.h>
#include <gconf/gconf-client.h>
#include <libgnome/gnome-i18n.h>
#include <libgnomeui/gnome-href.h>
#include <string.h>
#include "yelp-settings.h"

#define KEY_GNOME_DIR           "/desktop/gnome/interface"
#define KEY_GNOME_VARIABLE_FONT KEY_GNOME_DIR "/font_name"
#define KEY_GNOME_FIXED_FONT    KEY_GNOME_DIR "/monospace_font_name"
#define KEY_GNOME_GTK_THEME     KEY_GNOME_DIR "/gtk_theme"

#define KEY_YELP_DIR            "/apps/yelp"
#define KEY_YELP_USE_CARET      KEY_YELP_DIR "/use_caret"
#define KEY_YELP_SYSTEM_FONTS   KEY_YELP_DIR "/use_system_fonts"
#define KEY_YELP_VARIABLE_FONT  KEY_YELP_DIR "/variable_font"
#define KEY_YELP_FIXED_FONT     KEY_YELP_DIR "/fixed_font"

#ifdef YELP_DEBUG
#define d(x) x
#else
#define d(x)
#endif

static const gchar *color_params[YELP_NUM_COLORS] = {
    "yelp.color.text",
    "yelp.color.anchor",
    "yelp.color.background",
    "yelp.color.rule",
    "yelp.color.base0",
    "yelp.color.base1",
    "yelp.color.base2",
    "yelp.color.base3",
    "yelp.color.selected0",
    "yelp.color.selected1",
    "yelp.color.selected2",
    "yelp.color.selected3",
};

static const gchar *icon_params[YELP_NUM_ICONS] = {
    "yelp.icon.blockquote",
    "yelp.icon.caution",
    "yelp.icon.important",
    "yelp.icon.note",
    "yelp.icon.programlisting",
    "yelp.icon.tip",
    "yelp.icon.warning"
};

static void           settings_update         (YelpSettingsType  type);
static void           prefs_system_fonts_cb   (GtkWidget        *widget);
static void           prefs_font_cb           (GtkWidget        *widget);
static void           prefs_use_caret_cb      (GtkWidget        *widget);
static void           toggle_font_table       (GtkWidget        *widget);
static void           gconf_system_fonts_cb   (GConfClient      *client,
					       guint             cnxn_id,
					       GConfEntry       *entry,
					       gpointer          data);
static void           gconf_font_cb           (GConfClient      *client,
					       guint             cnxn_id,
					       GConfEntry       *entry,
					       gpointer          data);
static void           gconf_use_caret_cb      (GConfClient      *client,
					       guint             cnxn_id,
					       GConfEntry       *entry,
					       gpointer          data);
static void           gtk_theme_changed       (GtkSettings      *settings,
					       gpointer          user_data);
static void           icon_theme_changed      (GtkIconTheme     *theme,
					       gpointer          user_data);

static GConfClient *gconf_client = NULL;

static GHookList    *hook_lists[YELP_SETTINGS_NUM_TYPES];

static GtkSettings  *gtk_settings;
static GtkIconTheme *icon_theme;
static gchar colors[YELP_NUM_COLORS][10];
static gchar *icon_names[YELP_NUM_ICONS] = {NULL,};

static GtkWidget    *prefs_dialog = NULL;
static GtkWidget    *system_fonts_widget  = NULL;
static GtkWidget    *font_table_widget    = NULL;
static GtkWidget    *variable_font_widget = NULL;
static GtkWidget    *fixed_font_widget    = NULL;
static GtkWidget    *use_caret_widget     = NULL;
gulong system_fonts_handler  = 0;
gulong variable_font_handler = 0;
gulong fixed_font_handler    = 0;
gulong use_caret_handler     = 0;

void
yelp_settings_init (void)
{
    gint i;

    for (i = 0; i < YELP_NUM_ICONS; i++) {
	switch (i) {
	case YELP_ICON_BLOCKQUOTE:
	    /* TRANSLATORS:
	       This is an image of the opening quote character used to watermark
	       blockquote elements.  Different languages use different opening
	       quote characters, so the icon name is translatable.  The name of
	       the icon should be "yelp-watermark-blockquote-XXXX", where XXXX
	       is the Unicode code point of the opening quote character.   For
	       example, some languages use the double angle quotation mark, so
	       those would use "yelp-watermark-blockquote-00AB".  However, the
	       image is not automagically created.  Do not translate this to a
	       value if there isn't a corresponding icon in yelp/data/icons.
	       If you need an image created, contact the maintainers.

	       Phew, now some notes on which character to use.  Languages that
	       use guillemets (angle quotations) should use either 00AB or AABB,
	       depending on whether the opening quotation is the left guillemet
	       or the right guillemet.  Languages that use inverted comma style
	       quotations should use 201C, 201D, or 201E.  Note that single
	       quotation marks don't make very nice watermarks.  So if you use
	       single quotes as your primary (outer) quotation marks, you should
	       just use the corresponding double quote watermark.
	    */
	    icon_names[i] = _("yelp-watermark-blockquote-201C");
	    break;
	case YELP_ICON_CAUTION:
	    icon_names[i] = "yelp-icon-caution";
	    break;
	case YELP_ICON_IMPORTANT:
	    icon_names[i] = "yelp-icon-important";
	    break;
	case YELP_ICON_NOTE:
	    icon_names[i] = "yelp-icon-note";
	    break;
	case YELP_ICON_PROGRAMLISTING:
	    icon_names[i] = "yelp-watermark-programlisting";
	    break;
	case YELP_ICON_TIP:
	    icon_names[i] = "yelp-icon-tip";
	    break;
	case YELP_ICON_WARNING:
	    icon_names[i] = "yelp-icon-warning";
	    break;
	default:
	    g_assert_not_reached ();
	}
    }

    gconf_client = gconf_client_get_default ();
    gconf_client_add_dir (gconf_client, KEY_GNOME_DIR,
			  GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
    gconf_client_add_dir (gconf_client, KEY_YELP_DIR,
			  GCONF_CLIENT_PRELOAD_ONELEVEL, NULL);
    gconf_client_notify_add (gconf_client,
			     KEY_GNOME_VARIABLE_FONT,
			     gconf_font_cb,
			     NULL, NULL, NULL);
    gconf_client_notify_add (gconf_client,
			     KEY_GNOME_FIXED_FONT,
			     gconf_font_cb,
			     NULL, NULL, NULL);
    gconf_client_notify_add (gconf_client,
			     KEY_YELP_SYSTEM_FONTS,
			     gconf_system_fonts_cb,
			     NULL, NULL, NULL);
    gconf_client_notify_add (gconf_client,
			     KEY_YELP_VARIABLE_FONT,
			     gconf_font_cb,
			     NULL, NULL, NULL);
    gconf_client_notify_add (gconf_client,
			     KEY_YELP_FIXED_FONT,
			     gconf_font_cb,
			     NULL, NULL, NULL);
    gconf_client_notify_add (gconf_client,
			     KEY_YELP_USE_CARET,
			     gconf_use_caret_cb,
			     NULL, NULL, NULL);

    for (i = 0; i < YELP_SETTINGS_NUM_TYPES; i++) {
	hook_lists[i] = g_new0 (GHookList, 1);
	g_hook_list_init (hook_lists[i], sizeof (GHook));
    }

    gtk_settings = gtk_settings_get_default ();
    g_signal_connect (gtk_settings,
		      "notify::gtk-theme-name",
		      (GCallback) gtk_theme_changed,
		      NULL);

    icon_theme = gtk_icon_theme_get_default ();
    gtk_icon_theme_append_search_path (icon_theme,
				       DATADIR "/yelp/icons");
    g_signal_connect (icon_theme,
		      "changed",
		      (GCallback) icon_theme_changed,
		      NULL);

    settings_update (YELP_SETTINGS_INFO_ALL);
}

void
yelp_settings_open_preferences (void)
{
    gchar *font;
    gboolean use;

    if (!prefs_dialog) {
	GladeXML *glade;
	glade = glade_xml_new (DATADIR "/yelp/ui/yelp.glade",
			       "prefs_dialog",
			       NULL);
	if (!glade) {
	    g_warning ("Could not find necessary glade file "
		       DATADIR "/yelp/ui/yelp.glade");
	    return;
	}

	prefs_dialog  = glade_xml_get_widget (glade, "prefs_dialog");
	use_caret_widget     = glade_xml_get_widget (glade, "use_caret");
	system_fonts_widget  = glade_xml_get_widget (glade, "use_system_fonts");
	font_table_widget    = glade_xml_get_widget (glade, "font_table");
	variable_font_widget = glade_xml_get_widget (glade, "variable_font");
	fixed_font_widget    = glade_xml_get_widget (glade, "fixed_font");

	use = gconf_client_get_bool (gconf_client, KEY_YELP_SYSTEM_FONTS, NULL);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (system_fonts_widget), use);
	gtk_widget_set_sensitive (font_table_widget, !use);

	font = gconf_client_get_string (gconf_client, KEY_YELP_VARIABLE_FONT, NULL);
	gtk_font_button_set_font_name (GTK_FONT_BUTTON (variable_font_widget), font);
	g_free (font);

	font = gconf_client_get_string (gconf_client, KEY_YELP_FIXED_FONT, NULL);
	gtk_font_button_set_font_name (GTK_FONT_BUTTON (fixed_font_widget), font);
	g_free (font);

	use_caret_handler =
	    g_signal_connect (G_OBJECT (use_caret_widget), "toggled",
			      G_CALLBACK (prefs_use_caret_cb), NULL);
	system_fonts_handler =
	    g_signal_connect (G_OBJECT (system_fonts_widget), "toggled",
			      G_CALLBACK (prefs_system_fonts_cb), NULL);
	variable_font_handler =
	    g_signal_connect (G_OBJECT (variable_font_widget), "font_set",
			      G_CALLBACK (prefs_font_cb), NULL);
	fixed_font_handler =
	    g_signal_connect (G_OBJECT (fixed_font_widget), "font_set",
			      G_CALLBACK (prefs_font_cb), NULL);

	g_signal_connect (G_OBJECT (system_fonts_widget), "toggled",
			  G_CALLBACK (toggle_font_table), NULL);

	g_signal_connect (G_OBJECT (prefs_dialog), "response",
			  G_CALLBACK (gtk_widget_hide), NULL);

	g_object_unref (glade);
    }

    gtk_window_present (GTK_WINDOW (prefs_dialog));
}

guint
yelp_settings_notify_add (YelpSettingsType type,
			  GHookFunc        func,
			  gpointer         data)
{
    GHook *hook;
    gint   i;

    for (i = 0; i < YELP_SETTINGS_NUM_TYPES; i++) {
	if (type & (1 << i)) {
	    hook = g_hook_alloc (hook_lists[i]);
	    hook->func = func;
	    hook->data = data;
	    g_hook_prepend (hook_lists[i], hook);
	    return hook->hook_id;
	}
    }

    return 0;
}

void
yelp_settings_notify_remove (YelpSettingsType type, guint id)
{
    gint   i;

    for (i = 0; i < YELP_SETTINGS_NUM_TYPES; i++)
	if (type & (1 << i))
	    g_hook_destroy (hook_lists[i], id);
}

/** Getters *******************************************************************/

const GtkIconTheme *
yelp_settings_get_icon_theme (void)
{
    return icon_theme;
}

GtkIconInfo *
yelp_settings_get_icon (YelpIconType icon)
{
    GtkIconInfo *info;

    g_return_val_if_fail (icon < YELP_NUM_ICONS, NULL);

    info = gtk_icon_theme_lookup_icon (icon_theme,
				       icon_names[icon],
				       36, 0);
    return info;
}

gchar *
yelp_settings_get_font (YelpFontType font)
{
    gchar *key;
    gboolean use;

    use = gconf_client_get_bool (gconf_client,
				 KEY_YELP_SYSTEM_FONTS,
				 NULL);

    switch (font) {
    case YELP_FONT_VARIABLE:
	key = (use ? KEY_GNOME_VARIABLE_FONT : KEY_YELP_VARIABLE_FONT);
	break;
    case YELP_FONT_FIXED:
	key = (use ? KEY_GNOME_FIXED_FONT : KEY_YELP_FIXED_FONT);
	break;
    default:
	g_assert_not_reached ();
    }

    return gconf_client_get_string (gconf_client, key, NULL);
}

const gchar *
yelp_settings_get_color (YelpColorType color)
{
    g_return_val_if_fail (color < YELP_NUM_COLORS, NULL);

    return colors[color];
}

const gchar *
yelp_settings_get_css_file (void)
{
    return "file://" DATADIR "/yelp/default.css";
}

gboolean
yelp_settings_get_caret (void)
{
    gboolean caret;
    caret = gconf_client_get_bool (gconf_client,
				   KEY_YELP_USE_CARET,
				   NULL);
    return caret;
}

/** Widget Callbacks **********************************************************/

static void
prefs_system_fonts_cb (GtkWidget *widget)
{
    gboolean use;

    g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));

    use = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));

    gconf_client_set_bool (gconf_client,
			   KEY_YELP_SYSTEM_FONTS,
			   use, NULL);
}

static void
prefs_font_cb (GtkWidget *widget)
{
    const gchar *key;
    const gchar *font;

    g_return_if_fail (GTK_IS_FONT_BUTTON (widget));

    font = gtk_font_button_get_font_name (GTK_FONT_BUTTON (widget));

    if (widget == variable_font_widget)
	key = KEY_YELP_VARIABLE_FONT;
    else if (widget == fixed_font_widget)
	key = KEY_YELP_FIXED_FONT;
    else
	g_assert_not_reached ();

    gconf_client_set_string (gconf_client,
			     key, font,
			     NULL);
}

static void
prefs_use_caret_cb (GtkWidget *widget)
{
    gboolean caret;

    g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));

    caret = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));

    gconf_client_set_bool (gconf_client,
			   KEY_YELP_USE_CARET,
			   caret, NULL);
}

static void
toggle_font_table (GtkWidget *widget)
{
    gboolean use;

    g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget));

    use = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget));

    gtk_widget_set_sensitive (font_table_widget, !use);
}

/** GConf Callbacks ***********************************************************/

static void
gconf_system_fonts_cb (GConfClient   *client,
		       guint          cnxn_id,
		       GConfEntry    *entry,
		       gpointer       data)
{
    gboolean use;

    d (g_print ("gconf_system_fonts_cb\n"));

    use = gconf_value_get_bool (gconf_entry_get_value (entry));

    if (prefs_dialog) {
	g_signal_handler_block (system_fonts_widget, system_fonts_handler);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (system_fonts_widget), use);
	g_signal_handler_unblock (system_fonts_widget, system_fonts_handler);
    }

    settings_update (YELP_SETTINGS_INFO_FONTS);
}

static void
gconf_font_cb (GConfClient   *client,
	       guint          cnxn_id,
	       GConfEntry    *entry,
	       gpointer       data)
{
    GtkFontButton *button;
    gulong handler;
    const gchar *font;

    d (g_print ("gconf_font_cb\n"));

    font = gconf_value_get_string (gconf_entry_get_value (entry));

    if (prefs_dialog) {
	if (g_str_equal (gconf_entry_get_key (entry), KEY_YELP_VARIABLE_FONT)) {
	    button = GTK_FONT_BUTTON (variable_font_widget);
	    handler = variable_font_handler;
	}
	else if (g_str_equal (gconf_entry_get_key (entry), KEY_YELP_FIXED_FONT)) {
	    button = GTK_FONT_BUTTON (fixed_font_widget);
	    handler = fixed_font_handler;
	}
	else
	    goto done;

	g_signal_handler_block (button, handler);
	gtk_font_button_set_font_name (button, font);
	g_signal_handler_unblock (button, handler);
    }

 done:
    settings_update (YELP_SETTINGS_INFO_FONTS);
}

static void
gconf_use_caret_cb (GConfClient  *client,
		    guint         cnxn_id,
		    GConfEntry   *entry,
		    gpointer      data)
{
    gboolean caret;

    caret = gconf_value_get_bool (gconf_entry_get_value (entry));

    if (prefs_dialog) {
	g_signal_handler_block (use_caret_widget, use_caret_handler);
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (use_caret_widget), caret);
	g_signal_handler_unblock (use_caret_widget, use_caret_handler);
    }

    settings_update (YELP_SETTINGS_INFO_A11Y);
}

/******************************************************************************/

static void
gtk_theme_changed (GtkSettings *settings, gpointer user_data)
{
    d (g_print ("gtk_theme_changed\n"));

    settings_update (YELP_SETTINGS_INFO_COLOR);
}

static void
icon_theme_changed (GtkIconTheme *theme, gpointer user_data)
{
    settings_update (YELP_SETTINGS_INFO_ICONS);
}

static void
settings_update (YelpSettingsType type)
{
    GtkWidget *widget;
    GtkStyle  *style;
    GdkColor  *color;
    GdkColor   blue = { 0, 0x0000, 0x0000, 0xffff };
    guint8     max_text;
    guint16    rval, gval, bval;
    gint i;

    d (g_print ("settings_update\n"));

    if (type & YELP_SETTINGS_INFO_COLOR) {
	style = gtk_rc_get_style_by_paths (gtk_settings,
					   "GtkTextView", "GtkTextView",
					   GTK_TYPE_TEXT_VIEW);
	if (style)
	    g_object_ref (G_OBJECT (style));
	else
	    style = gtk_style_new ();

	max_text = MAX(style->text[GTK_STATE_NORMAL].red,
		       MAX(style->text[GTK_STATE_NORMAL].green,
			   style->text[GTK_STATE_NORMAL].blue   )) >> 8;

	g_snprintf (colors[YELP_COLOR_TEXT], 8,
		    "#%02X%02X%02X",
		    style->text[GTK_STATE_NORMAL].red >> 8,
		    style->text[GTK_STATE_NORMAL].green >> 8,
		    style->text[GTK_STATE_NORMAL].blue >> 8);
	g_snprintf (colors[YELP_COLOR_BACKGROUND], 8,
		    "#%02X%02X%02X",
		    style->base[GTK_STATE_NORMAL].red >> 8,
		    style->base[GTK_STATE_NORMAL].green >> 8,
		    style->base[GTK_STATE_NORMAL].blue >> 8);

	g_snprintf (colors[YELP_COLOR_RULE], 8,
		    "#%02X%02X%02X",
		    ((style->base[GTK_STATE_NORMAL].red >> 8) + 
		     (style->bg[GTK_STATE_NORMAL].red >> 8) ) / 2,
		    ((style->base[GTK_STATE_NORMAL].green >> 8) + 
		     (style->bg[GTK_STATE_NORMAL].green >> 8) ) / 2,
		    ((style->base[GTK_STATE_NORMAL].blue >> 8) + 
		     (style->bg[GTK_STATE_NORMAL].blue >> 8) ) / 2);

	for (i = 0; i < 4; i++) {
	    rval = ((4 - i) * (style->bg[GTK_STATE_NORMAL].red   >> 8) +
		    i * max_text) / 4;
	    gval = ((4 - i) * (style->bg[GTK_STATE_NORMAL].green >> 8) +
		    i * max_text) / 4;
	    bval = ((4 - i) * (style->bg[GTK_STATE_NORMAL].blue  >> 8) +
		    i * max_text) / 4;
	    g_snprintf (colors[YELP_COLOR_BASE0 + i], 8,
			"#%02X%02X%02X", rval, gval, bval);
	}
	for (i = 0; i < 4; i++) {
	    rval = ((4 - i) * (style->bg[GTK_STATE_SELECTED].red   >> 8) +
		    i * max_text) / 4;
	    gval = ((4 - i) * (style->bg[GTK_STATE_SELECTED].green >> 8) +
		    i * max_text) / 4;
	    bval = ((4 - i) * (style->bg[GTK_STATE_SELECTED].blue  >> 8) +
		    i * max_text) / 4;
	    g_snprintf (colors[YELP_COLOR_SELECTED0 + i], 8,
			"#%02X%02X%02X", rval, gval, bval);
	}

	g_object_unref (G_OBJECT (style));

	widget = gnome_href_new ("http://www.gnome.org/", "GNOME");
	gtk_widget_style_get (widget, "link_color", &color, NULL);
	if (!color)
	    color = &blue;
	g_snprintf (colors[YELP_COLOR_ANCHOR], 8,
		    "#%02X%02X%02X",
		    color->red >> 8,
		    color->green >> 8,
		    color->blue >> 8);
	if (color != &blue)
	    gdk_color_free (color);
	gtk_object_sink (GTK_OBJECT (widget));
    }

    for (i = 0; i < YELP_SETTINGS_NUM_TYPES; i++)
	if (type & (1 << i))
	    g_hook_list_invoke (hook_lists[i], FALSE);
}

void
yelp_settings_params (gchar ***params,
		      gint    *params_i,
		      gint    *params_max)
{
    GtkIconInfo *icon_info;
    gchar *icon_file;
    gint colors_i, icons_i;

    if ((*params_i + 2 * (YELP_NUM_COLORS + YELP_NUM_ICONS)) >= *params_max) {
	*params_max += 2 * (YELP_NUM_COLORS + YELP_NUM_ICONS);
	*params = g_renew (gchar *, *params, *params_max);
    }

    for (colors_i = 0; colors_i < YELP_NUM_COLORS; colors_i++) {
	(*params)[(*params_i)++] = (gchar *) color_params[colors_i];
	(*params)[(*params_i)++] = g_strdup_printf ("\"%s\"",
						yelp_settings_get_color (colors_i));
    }

    for (icons_i = 0; icons_i < YELP_NUM_ICONS; icons_i++) {
	(*params)[(*params_i)++] = (gchar *) icon_params[icons_i];

	icon_info = yelp_settings_get_icon (icons_i);
	if (icon_info) {
	    icon_file = (gchar *) gtk_icon_info_get_filename (icon_info);
	    if (icon_file)
		(*params)[(*params_i)++] = g_strdup_printf ("\"%s\"", icon_file);
	    else 
		(*params)[(*params_i)++] = g_strdup ("\"\"");
	    gtk_icon_info_free (icon_info);
	} else {
	    (*params)[(*params_i)++] = g_strdup ("\"\"");
	}
    }
}