summaryrefslogtreecommitdiff
path: root/packages/gnome1/examples/gconfexample.pp
blob: 4334623e7fb2db97252c7bc3f8f0cdafb73a651e (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
Program gconfexample;

Uses glib, gtk, gconf, gconfclient;

Const
  PATH : PChar = '/apps/GNOMEnclature/gconf_example';
  KEY : PChar= '/apps/GNOMEnclature/gconf_example/my_option';

{ Update the GConf key when the user toggles the check button. }
Procedure button_toggled_cb (button : PGtkWidget; data : gpointer); cdecl;
var
  client : PGConfClient;
  thevalue : gboolean;
begin
  client := gconf_client_get_default ();

  thevalue := gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button));

  gconf_client_set_bool (client, KEY, thevalue, nil);
end;

{ This is called when our key is changed. }
Procedure gconf_notify_func (client : PGConfClient; cnxn_id : guint;
                   entry : PGConfEntry; user_data : gpointer); cdecl;
var
  check_button : PGtkWidget;
  thevalue : PGConfValue;
  checked : gboolean;
begin
  check_button := GTK_WIDGET (user_data);

  thevalue := gconf_entry_get_value (entry);

  checked := gconf_value_get_bool (thevalue);

  { Update the check button accordingly. }
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                checked);
end;

var
  window : PGtkWidget;
  check_button : PGTKWidget;
  client : PGConfClient;
  thevalue : gboolean;

begin
  gtk_init (@argc, @argv);
  gconf_init(argc, argv, nil);

  client := gconf_client_get_default ();

  window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect(GTK_OBJECT (window), 'destroy',
                   @gtk_main_quit, nil);

  { Get the initial value from GConf. }
  thevalue := gconf_client_get_bool (client, KEY, nil);

  check_button := gtk_check_button_new_with_label ('My option');
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check_button),
                                      thevalue);

  gtk_signal_connect (GTK_OBJECT (check_button), 'toggled',
                          gtk_SIGNAL_FUNC(@button_toggled_cb), nil);

  gtk_container_add (GTK_CONTAINER (window), check_button);

  gtk_widget_show_all (window);

  (* Add our directory to the list of directories the GConfClient will
   * watch.
   *)

  gconf_client_add_dir (client, PATH, GCONF_CLIENT_PRELOAD_NONE, nil);

  { Listen to changes to our key. }

  gconf_client_notify_add (client, KEY, @gconf_notify_func, check_button, nil, nil);

  gtk_main ();

end.