~noskcaj/ubuntu/trusty/ekiga/ftbfs

« back to all changes in this revision

Viewing changes to lib/gui/gmpreferences.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2006-01-28 18:49:20 UTC
  • Revision ID: james.westby@ubuntu.com-20060128184920-v525ihmiv7id40xs
Tags: upstream-1.99.0
ImportĀ upstreamĀ versionĀ 1.99.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* GnomeMeeting -- A Video-Conferencing application
 
3
 * Copyright (C) 2000-2006 Damien Sandras
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
18
 *
 
19
 *
 
20
 * GnomeMeting is licensed under the GPL license and as a special exception,
 
21
 * you have permission to link or otherwise combine this program with the
 
22
 * programs OpenH323 and Pwlib, and distribute the combination, without
 
23
 * applying the requirements of the GNU GPL to the OpenH323 program, as long
 
24
 * as you do follow the requirements of the GNU GPL for all the rest of the
 
25
 * software thus combined.
 
26
 */
 
27
 
 
28
 
 
29
/*
 
30
 *                         gnome_prefs_window.c  -  description 
 
31
 *                         ------------------------------------
 
32
 *   begin                : Mon Oct 15 2003, but based on older code
 
33
 *   copyright            : (C) 2000-2006 by Damien Sandras
 
34
 *   description          : Helpers to create GNOME compliant prefs windows.
 
35
 *
 
36
 */
 
37
 
 
38
 
 
39
#include "gmpreferences.h"
 
40
 
 
41
#include "gmconfwidgets.h"
 
42
 
 
43
 
 
44
static void tree_selection_changed_cb (GtkTreeSelection *,
 
45
                                       gpointer);
 
46
 
 
47
 
 
48
typedef struct _GnomePrefsWindow {
 
49
 
 
50
  GtkWidget *notebook;
 
51
  GtkWidget *section_label;
 
52
  GtkWidget *sections_tree_view;
 
53
  GtkTreeIter iter;
 
54
  GtkTooltips *tips;
 
55
  int last_page;
 
56
  
 
57
} GnomePrefsWindow;
 
58
 
 
59
 
 
60
/* GTK Callbacks */
 
61
 
 
62
/* DESCRIPTION  :  This callback is called when the user clicks in the
 
63
 *                 categories and subcategories GtkTreeView.
 
64
 * BEHAVIOR     :  Display the logo if he clicked in a category, or the
 
65
 *                 different blocks of options corresponding to a subcategory
 
66
 *                 if he clicked in a specific subcategory.
 
67
 * PRE          :  /
 
68
 */
 
69
static void
 
70
tree_selection_changed_cb (GtkTreeSelection *selection,
 
71
                           gpointer data)
 
72
{
 
73
  int page = 0;
 
74
  gchar *name = NULL;
 
75
  GtkTreeIter iter;
 
76
  GtkTreeModel *model = NULL;
 
77
  GnomePrefsWindow *gpw = NULL;
 
78
 
 
79
  if (!data)
 
80
    return;
 
81
  
 
82
  if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
 
83
 
 
84
    gpw = (GnomePrefsWindow *) data;
 
85
    
 
86
    gtk_tree_model_get (GTK_TREE_MODEL (model),
 
87
                        &iter, 1, &page, -1);
 
88
 
 
89
    gtk_tree_model_get (GTK_TREE_MODEL (model),
 
90
                        &iter, 0, &name, -1);
 
91
 
 
92
    gtk_label_set_text (GTK_LABEL (gpw->section_label), name);
 
93
 
 
94
    gtk_notebook_set_current_page (GTK_NOTEBOOK (gpw->notebook), page);
 
95
  }
 
96
}
 
97
 
 
98
 
 
99
/* The public functions */
 
100
GtkWidget *
 
101
gnome_prefs_entry_new (GtkWidget *table,
 
102
                       gchar *label_txt,
 
103
                       gchar *conf_key,
 
104
                       gchar *tooltip,
 
105
                       int row,
 
106
                       gboolean box)
 
107
{
 
108
  GnomePrefsWindow *gpw = NULL;
 
109
  GValue value = { 0 };
 
110
  int cols = 0;
 
111
  GtkWidget *entry = NULL;
 
112
  GtkWidget *label = NULL;
 
113
  GtkWidget *hbox = NULL;
 
114
  
 
115
  gchar *conf_string = NULL;
 
116
  gboolean writable = FALSE;
 
117
  
 
118
  writable = gm_conf_is_key_writable (conf_key);
 
119
  
 
120
  if (box) {
 
121
    
 
122
    hbox = gtk_hbox_new (FALSE, 0);
 
123
    g_value_init (&value, G_TYPE_INT);
 
124
    g_object_get_property (G_OBJECT (table), "n-columns", &value);
 
125
    cols = g_value_get_int (&value);
 
126
    g_value_unset (&value);
 
127
  }
 
128
  
 
129
  label = gtk_label_new_with_mnemonic (label_txt);
 
130
  if (!writable)
 
131
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
132
  
 
133
  if (box)
 
134
    gtk_box_pack_start (GTK_BOX (hbox), label,
 
135
                        FALSE, FALSE, 1 * 2);
 
136
  else
 
137
    gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
 
138
                      (GtkAttachOptions) (GTK_FILL),
 
139
                      (GtkAttachOptions) (GTK_FILL),
 
140
                      0, 0);
 
141
 
 
142
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
143
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
 
144
 
 
145
  entry = gtk_entry_new ();
 
146
  gtk_label_set_mnemonic_widget (GTK_LABEL(label), entry);
 
147
  if (!writable)
 
148
    gtk_widget_set_sensitive (GTK_WIDGET (entry), FALSE);
 
149
  
 
150
  if (box)
 
151
    gtk_box_pack_start (GTK_BOX (hbox), entry,
 
152
                        FALSE, FALSE, 1 * 2);
 
153
  else
 
154
    gtk_table_attach (GTK_TABLE (table), entry, 1, 2, row, row+1,
 
155
                      (GtkAttachOptions) (NULL),
 
156
                      (GtkAttachOptions) (NULL),
 
157
                      0, 0);
 
158
  
 
159
  conf_string =
 
160
    gm_conf_get_string (conf_key);
 
161
 
 
162
  if (conf_string != NULL)
 
163
    gtk_entry_set_text (GTK_ENTRY (entry), conf_string);
 
164
 
 
165
  g_free (conf_string);
 
166
 
 
167
  g_signal_connect_after (G_OBJECT (entry), "focus-out-event",
 
168
                          G_CALLBACK (entry_focus_changed), conf_key);
 
169
 
 
170
  g_signal_connect_after (G_OBJECT (entry), "activate",
 
171
                          G_CALLBACK (entry_activate_changed), conf_key);
 
172
 
 
173
  gm_conf_notifier_add (conf_key, entry_changed_nt, (gpointer) entry);
 
174
 
 
175
  if (box)
 
176
    gtk_table_attach (GTK_TABLE (table), hbox, 0, cols, row, row+1,
 
177
                      (GtkAttachOptions) (NULL),
 
178
                      (GtkAttachOptions) (NULL),
 
179
                      0, 0);
 
180
 
 
181
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw");
 
182
  if (gpw && tooltip)
 
183
    gtk_tooltips_set_tip (gpw->tips, entry, tooltip, NULL);
 
184
 
 
185
  gtk_widget_show_all (table);
 
186
  
 
187
  return entry;
 
188
}                                                                              
 
189
                                                                               
 
190
                                                                               
 
191
GtkWidget *
 
192
gnome_prefs_toggle_new (GtkWidget *table,
 
193
                        gchar *label_txt,
 
194
                        gchar *conf_key,
 
195
                        gchar *tooltip,
 
196
                        int row)
 
197
{
 
198
  GnomePrefsWindow *gpw = NULL;
 
199
  GValue value = { 0 };
 
200
  GtkWidget *toggle = NULL;
 
201
  gboolean writable = FALSE;
 
202
  int cols = 0;
 
203
  
 
204
  writable = gm_conf_is_key_writable (conf_key);
 
205
  
 
206
  g_value_init (&value, G_TYPE_INT);
 
207
  g_object_get_property (G_OBJECT (table), "n-columns", &value);
 
208
  cols = g_value_get_int (&value);
 
209
  g_value_unset (&value);
 
210
  
 
211
  toggle = gtk_check_button_new_with_mnemonic (label_txt);
 
212
  if (!writable)
 
213
    gtk_widget_set_sensitive (GTK_WIDGET (toggle), FALSE);
 
214
  
 
215
  gtk_table_attach (GTK_TABLE (table), toggle, 0, cols, row, row+1,
 
216
                    (GtkAttachOptions) (GTK_FILL),
 
217
                    (GtkAttachOptions) (GTK_FILL),
 
218
                    0, 0);
 
219
                                                                               
 
220
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
 
221
                                gm_conf_get_bool (conf_key));
 
222
 
 
223
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw");
 
224
  if (gpw && tooltip)
 
225
    gtk_tooltips_set_tip (gpw->tips, toggle, tooltip, NULL);
 
226
 
 
227
  g_signal_connect (G_OBJECT (toggle), "toggled",
 
228
                    G_CALLBACK (toggle_changed), (gpointer) conf_key);
 
229
  
 
230
  gm_conf_notifier_add (conf_key, toggle_changed_nt, (gpointer) toggle);
 
231
 
 
232
  gtk_widget_show_all (table);
 
233
  
 
234
  return toggle;
 
235
}                                                                              
 
236
 
 
237
 
 
238
GtkWidget *
 
239
gnome_prefs_scale_new (GtkWidget *table,       
 
240
                       gchar *down_label_txt,
 
241
                       gchar *up_label_txt,
 
242
                       gchar *conf_key,       
 
243
                       gchar *tooltip,
 
244
                       double min,
 
245
                       double max,
 
246
                       double step,
 
247
                       int row)
 
248
{
 
249
  GnomePrefsWindow *gpw = NULL;
 
250
  GtkWidget *hbox = NULL;
 
251
  GtkAdjustment *adj = NULL;
 
252
  GtkWidget *label = NULL;
 
253
  GtkWidget *hscale = NULL;
 
254
 
 
255
  gboolean writable = FALSE;
 
256
 
 
257
  writable = gm_conf_is_key_writable (conf_key);
 
258
 
 
259
  hbox = gtk_hbox_new (FALSE, 0);
 
260
 
 
261
  label = gtk_label_new_with_mnemonic (down_label_txt);
 
262
  if (!writable)
 
263
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
264
 
 
265
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE,
 
266
                      1 * 2);
 
267
  
 
268
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
269
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
 
270
 
 
271
  adj = (GtkAdjustment *) 
 
272
    gtk_adjustment_new (gm_conf_get_int (conf_key),
 
273
                        min, max, step,
 
274
                        2.0, 1.0);
 
275
 
 
276
  hscale = gtk_hscale_new (adj);
 
277
  gtk_scale_set_draw_value (GTK_SCALE (hscale), FALSE);
 
278
  gtk_widget_set_size_request (GTK_WIDGET (hscale), 150, -1);
 
279
  gtk_range_set_update_policy (GTK_RANGE (hscale),
 
280
                               GTK_UPDATE_DELAYED);
 
281
  if (!writable)
 
282
    gtk_widget_set_sensitive (GTK_WIDGET (hscale), FALSE);
 
283
 
 
284
  gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE,
 
285
                      1 * 2);
 
286
 
 
287
 
 
288
  label = gtk_label_new_with_mnemonic (up_label_txt);
 
289
  if (!writable)
 
290
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
291
 
 
292
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE,
 
293
                      1 * 2);
 
294
 
 
295
  gtk_table_attach (GTK_TABLE (table), hbox, 0, 1, row, row+1,
 
296
                    (GtkAttachOptions) (GTK_FILL),
 
297
                    (GtkAttachOptions) (GTK_FILL),
 
298
                    0, 0);
 
299
 
 
300
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw");
 
301
  if (gpw && tooltip)
 
302
    gtk_tooltips_set_tip (gpw->tips, hscale, tooltip, NULL);
 
303
 
 
304
  g_signal_connect (G_OBJECT (adj), "value-changed",
 
305
                    G_CALLBACK (adjustment_changed),
 
306
                    (gpointer) conf_key);
 
307
 
 
308
  gm_conf_notifier_add (conf_key, adjustment_changed_nt,
 
309
                        (gpointer) adj);
 
310
 
 
311
  gtk_widget_show_all (table);
 
312
 
 
313
  return hscale;
 
314
}
 
315
 
 
316
 
 
317
GtkWidget *
 
318
gnome_prefs_spin_new (GtkWidget *table,       
 
319
                      gchar *label_txt,
 
320
                      gchar *conf_key,       
 
321
                      gchar *tooltip,
 
322
                      double min,
 
323
                      double max,
 
324
                      double step,
 
325
                      int row,
 
326
                      gchar *label_txt2,
 
327
                      gboolean box)
 
328
{
 
329
  GnomePrefsWindow *gpw = NULL;
 
330
  GtkWidget *hbox = NULL;
 
331
  GtkAdjustment *adj = NULL;
 
332
  GtkWidget *label = NULL;
 
333
  GtkWidget *spin_button = NULL;
 
334
 
 
335
  gboolean writable = FALSE;
 
336
  
 
337
  writable = gm_conf_is_key_writable (conf_key);
 
338
 
 
339
  
 
340
  if (box)
 
341
    hbox = gtk_hbox_new (FALSE, 0);
 
342
  
 
343
  label = gtk_label_new_with_mnemonic (label_txt);
 
344
  if (!writable)
 
345
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
346
  
 
347
  if (box)
 
348
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE,
 
349
                        1 * 2);
 
350
  else
 
351
    gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
 
352
                      (GtkAttachOptions) (GTK_FILL),
 
353
                      (GtkAttachOptions) (GTK_FILL),
 
354
                      0, 0);
 
355
 
 
356
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
357
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
 
358
  
 
359
  adj = (GtkAdjustment *) 
 
360
    gtk_adjustment_new (gm_conf_get_int (conf_key),
 
361
                        min, max, step,
 
362
                        2.0, 1.0);
 
363
  
 
364
  spin_button = gtk_spin_button_new (adj, 1.0, 0);
 
365
  if (!writable)
 
366
    gtk_widget_set_sensitive (GTK_WIDGET (spin_button), FALSE);
 
367
  
 
368
  if (box)
 
369
    gtk_box_pack_start (GTK_BOX (hbox), spin_button, FALSE, FALSE,
 
370
                        1 * 2);
 
371
  else
 
372
    gtk_table_attach (GTK_TABLE (table), spin_button, 1, 2, row, row+1,
 
373
                      (GtkAttachOptions) (GTK_FILL),
 
374
                      (GtkAttachOptions) (GTK_FILL),
 
375
                      0, 0);
 
376
 
 
377
  if (box && label_txt2) {
 
378
    
 
379
    label = gtk_label_new_with_mnemonic (label_txt2);
 
380
    if (!writable)
 
381
      gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
382
    
 
383
    gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE,
 
384
                        1 * 2);
 
385
  }
 
386
 
 
387
  if (box) {
 
388
   
 
389
    gtk_table_attach (GTK_TABLE (table), hbox, 
 
390
                      0, GTK_TABLE (table)->ncols, row, row+1,
 
391
                      (GtkAttachOptions) (GTK_FILL),
 
392
                      (GtkAttachOptions) (GTK_FILL),
 
393
                      0, 0);
 
394
  }
 
395
 
 
396
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw");
 
397
  if (gpw && tooltip)
 
398
    gtk_tooltips_set_tip (gpw->tips, spin_button, tooltip, NULL);
 
399
 
 
400
  g_signal_connect (G_OBJECT (adj), "value-changed",
 
401
                    G_CALLBACK (adjustment_changed),
 
402
                    (gpointer) conf_key);
 
403
 
 
404
  gm_conf_notifier_add (conf_key, adjustment_changed_nt,
 
405
                        (gpointer) adj);
 
406
 
 
407
  gtk_widget_show_all (table);
 
408
  
 
409
  return spin_button;
 
410
}
 
411
 
 
412
 
 
413
void
 
414
gnome_prefs_range_new (GtkWidget *table,
 
415
                       gchar *label1_txt,
 
416
                       GtkWidget **spin1,
 
417
                       gchar *label2_txt,
 
418
                       GtkWidget **spin2,
 
419
                       gchar *label3_txt,
 
420
                       gchar *spin1_conf_key,
 
421
                       gchar *spin2_conf_key,
 
422
                       gchar *spin1_tooltip,
 
423
                       gchar *spin2_tooltip,
 
424
                       double spin1_min,
 
425
                       double spin2_min,
 
426
                       double spin1_max,
 
427
                       double spin2_max,
 
428
                       double spins_step,
 
429
                       int row)
 
430
{
 
431
  GnomePrefsWindow *gpw = NULL;
 
432
  int val1 = 0, val2 = 0;
 
433
  gboolean writable = FALSE;
 
434
  GtkWidget *hbox = NULL;
 
435
  GtkAdjustment *adj1 = NULL;
 
436
  GtkWidget *spin_button1 = NULL;
 
437
  GtkWidget *spin_button2 = NULL;
 
438
  GtkAdjustment *adj2 = NULL;
 
439
  GtkWidget *label = NULL;
 
440
 
 
441
  writable =
 
442
    (gm_conf_is_key_writable (spin1_conf_key)
 
443
     &&
 
444
     gm_conf_is_key_writable (spin2_conf_key));
 
445
  
 
446
  hbox = gtk_hbox_new (FALSE, 0);
 
447
  label = gtk_label_new_with_mnemonic (label1_txt);
 
448
  if (!writable)
 
449
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
450
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE,
 
451
                      1 * 2);
 
452
  
 
453
  val1 = gm_conf_get_int (spin1_conf_key);
 
454
  adj1 = (GtkAdjustment *) 
 
455
    gtk_adjustment_new (val1, spin1_min, spin1_max, spins_step, 2.0, 1.0);
 
456
  spin_button1 = gtk_spin_button_new (adj1, 1.0, 0);
 
457
  if (!writable)
 
458
    gtk_widget_set_sensitive (GTK_WIDGET (spin_button1), FALSE);
 
459
  gtk_box_pack_start (GTK_BOX (hbox), spin_button1, FALSE, FALSE,
 
460
                      1 * 2);
 
461
 
 
462
  label = gtk_label_new_with_mnemonic (label2_txt);
 
463
  if (!writable)
 
464
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
465
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE,
 
466
                      1 * 2);
 
467
 
 
468
  val2 = gm_conf_get_int (spin2_conf_key);
 
469
  adj2 = (GtkAdjustment *) 
 
470
    gtk_adjustment_new (val2, spin2_min, spin2_max, spins_step, 2.0, 1.0);
 
471
  spin_button2 = gtk_spin_button_new (adj2, 1.0, 0);
 
472
  if (!writable)
 
473
    gtk_widget_set_sensitive (GTK_WIDGET (spin_button2), FALSE);
 
474
  gtk_box_pack_start (GTK_BOX (hbox), spin_button2, FALSE, FALSE,
 
475
                      1 * 2);
 
476
  
 
477
  label = gtk_label_new_with_mnemonic (label3_txt);
 
478
  if (!writable)
 
479
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
480
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE,
 
481
                      1 * 2);
 
482
 
 
483
  gtk_table_attach (GTK_TABLE (table), hbox, 0, 1, row, row+1,
 
484
                    (GtkAttachOptions) (NULL),
 
485
                    (GtkAttachOptions) (NULL),
 
486
                    0, 0);
 
487
 
 
488
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw");
 
489
  if (gpw && spin1_tooltip && spin2_tooltip) {
 
490
    gtk_tooltips_set_tip (gpw->tips, spin_button1, spin1_tooltip, NULL);
 
491
    gtk_tooltips_set_tip (gpw->tips, spin_button2, spin2_tooltip, NULL);
 
492
  }
 
493
  
 
494
 
 
495
  g_signal_connect (G_OBJECT (adj1), "value-changed",
 
496
                    G_CALLBACK (adjustment_changed),
 
497
                    (gpointer) spin1_conf_key);
 
498
  gm_conf_notifier_add (spin1_conf_key, adjustment_changed_nt,
 
499
                        (gpointer) adj1);
 
500
  
 
501
  g_signal_connect (G_OBJECT (adj2), "value-changed",
 
502
                    G_CALLBACK (adjustment_changed),
 
503
                    (gpointer) spin2_conf_key);
 
504
  gm_conf_notifier_add (spin2_conf_key, adjustment_changed_nt,
 
505
                        (gpointer) adj2);
 
506
 
 
507
  if (spin1)
 
508
    *spin1 = spin_button1;
 
509
 
 
510
  if (spin2)
 
511
    *spin2 = spin_button2;
 
512
}                                                                              
 
513
 
 
514
 
 
515
GtkWidget *
 
516
gnome_prefs_int_option_menu_new (GtkWidget *table,
 
517
                                 gchar *label_txt,
 
518
                                 gchar **options,
 
519
                                 gchar *conf_key,
 
520
                                 gchar *tooltip,
 
521
                                 int row)
 
522
{
 
523
  GnomePrefsWindow *gpw = NULL;
 
524
  GtkWidget *item = NULL;
 
525
  GtkWidget *label = NULL;
 
526
  GtkWidget *option_menu = NULL;
 
527
  GtkWidget *menu = NULL;
 
528
 
 
529
  int cpt = 0;
 
530
  gboolean writable = FALSE;
 
531
  
 
532
  writable = gm_conf_is_key_writable (conf_key);
 
533
  
 
534
  label = gtk_label_new_with_mnemonic (label_txt);
 
535
  if (!writable)
 
536
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
537
  
 
538
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,
 
539
                    (GtkAttachOptions) (GTK_FILL),
 
540
                    (GtkAttachOptions) (GTK_FILL),
 
541
                    0, 0);
 
542
 
 
543
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
 
544
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
 
545
 
 
546
  menu = gtk_menu_new ();
 
547
  option_menu = gtk_option_menu_new ();
 
548
  if (!writable)
 
549
    gtk_widget_set_sensitive (GTK_WIDGET (option_menu), FALSE);
 
550
  
 
551
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), option_menu);
 
552
 
 
553
  while (options [cpt]) {
 
554
 
 
555
    item = gtk_menu_item_new_with_label (options [cpt]);
 
556
    gtk_widget_show (item);
 
557
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 
558
    cpt++;
 
559
  }
 
560
 
 
561
  gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
 
562
  gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu),
 
563
                               gm_conf_get_int (conf_key));
 
564
 
 
565
  gtk_table_attach (GTK_TABLE (table), option_menu, 1, 2, row, row+1,
 
566
                    (GtkAttachOptions) (GTK_FILL),
 
567
                    (GtkAttachOptions) (GTK_FILL),
 
568
                    0, 0);
 
569
 
 
570
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw");
 
571
  if (gpw && tooltip)
 
572
    gtk_tooltips_set_tip (gpw->tips, option_menu, tooltip, NULL);
 
573
 
 
574
  
 
575
  g_signal_connect (G_OBJECT (GTK_OPTION_MENU (option_menu)->menu),
 
576
                    "deactivate", G_CALLBACK (int_option_menu_changed),
 
577
                    (gpointer) conf_key);
 
578
  gm_conf_notifier_add (conf_key, int_option_menu_changed_nt,
 
579
                        (gpointer) option_menu);
 
580
 
 
581
  gtk_widget_show_all (table);
 
582
  
 
583
  return option_menu;
 
584
}                                                                              
 
585
 
 
586
 
 
587
GtkWidget *
 
588
gnome_prefs_string_option_menu_new (GtkWidget *table,       
 
589
                                    gchar *label_txt, 
 
590
                                    gchar **options,
 
591
                                    gchar *conf_key,       
 
592
                                    gchar *tooltip,         
 
593
                                    int row)       
 
594
{
 
595
  GnomePrefsWindow *gpw = NULL;
 
596
  
 
597
  GtkWidget *item = NULL;
 
598
  GtkWidget *label = NULL;                                                     
 
599
  GtkWidget *option_menu = NULL;
 
600
  GtkWidget *menu = NULL;
 
601
  gchar *conf_string = NULL;
 
602
  int history = -1;
 
603
  int cpt = 0;
 
604
  gboolean writable = FALSE;
 
605
 
 
606
  writable = gm_conf_is_key_writable (conf_key);
 
607
 
 
608
  label = gtk_label_new (label_txt);                                           
 
609
  if (!writable)
 
610
    gtk_widget_set_sensitive (GTK_WIDGET (label), FALSE);
 
611
  
 
612
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, row, row+1,                
 
613
                    (GtkAttachOptions) (GTK_FILL),
 
614
                    (GtkAttachOptions) (GTK_FILL),
 
615
                    0, 0);
 
616
                                                                               
 
617
  gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);                         
 
618
  gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
 
619
 
 
620
 
 
621
  menu = gtk_menu_new ();
 
622
  option_menu = gtk_option_menu_new ();
 
623
  if (!writable)
 
624
    gtk_widget_set_sensitive (GTK_WIDGET (option_menu), FALSE);
 
625
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), option_menu);
 
626
 
 
627
  conf_string = gm_conf_get_string (conf_key);
 
628
 
 
629
  while (options [cpt]) {
 
630
 
 
631
    if (conf_string != NULL)
 
632
      if (!strcmp (conf_string, options [cpt]))
 
633
        history = cpt;
 
634
 
 
635
    item = gtk_menu_item_new_with_label (options [cpt]);
 
636
    gtk_widget_show (item);
 
637
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 
638
    cpt++;
 
639
  }
 
640
 
 
641
  if (history == -1) {
 
642
 
 
643
    if (options [0])
 
644
      gm_conf_set_string (conf_key, options [0]);
 
645
    history = 0;
 
646
  }
 
647
 
 
648
  gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
 
649
  gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), 
 
650
                               history);
 
651
 
 
652
 
 
653
  gtk_table_attach (GTK_TABLE (table), option_menu, 1, 2, row, row+1,
 
654
                    (GtkAttachOptions) (GTK_FILL),                
 
655
                    (GtkAttachOptions) (GTK_FILL),                
 
656
                    0, 0);           
 
657
                                                                               
 
658
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (table), "gpw");
 
659
  if (gpw && tooltip)
 
660
    gtk_tooltips_set_tip (gpw->tips, option_menu, tooltip, NULL);
 
661
 
 
662
  g_signal_connect (G_OBJECT (GTK_OPTION_MENU (option_menu)->menu), 
 
663
                    "deactivate", G_CALLBACK (string_option_menu_changed),
 
664
                    (gpointer) conf_key);                                   
 
665
  gm_conf_notifier_add (conf_key, string_option_menu_changed_nt,
 
666
                        (gpointer) option_menu);
 
667
  
 
668
  g_free (conf_string); 
 
669
 
 
670
  gtk_widget_show_all (table);
 
671
  
 
672
  return option_menu;
 
673
}
 
674
 
 
675
 
 
676
void
 
677
gnome_prefs_string_option_menu_update (GtkWidget *option_menu,
 
678
                                       gchar **options,
 
679
                                       gchar *conf_key)
 
680
{
 
681
  GtkWidget *menu = NULL;
 
682
  GtkWidget *item = NULL;
 
683
 
 
684
  gchar *conf_string = NULL;
 
685
  
 
686
  int history = -1;
 
687
  int cpt = 0;                                                   
 
688
 
 
689
  if (!options || !conf_key)
 
690
    return;
 
691
  
 
692
  conf_string = gm_conf_get_string (conf_key);
 
693
 
 
694
  gtk_option_menu_remove_menu (GTK_OPTION_MENU (option_menu));
 
695
  menu = gtk_menu_new ();
 
696
                                          
 
697
  cpt = 0;
 
698
  while (options [cpt]) {
 
699
 
 
700
    if (conf_string && !strcmp (options [cpt], conf_string)) 
 
701
      history = cpt;
 
702
 
 
703
    item = gtk_menu_item_new_with_label (options [cpt]);
 
704
    gtk_widget_show (item);
 
705
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
 
706
 
 
707
    cpt++;
 
708
  }
 
709
 
 
710
 
 
711
  if (history == -1) {
 
712
    
 
713
    history = 0;
 
714
 
 
715
    if (options [0])
 
716
      gm_conf_set_string (conf_key, options [0]);
 
717
  }
 
718
 
 
719
  gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu);
 
720
  gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), history);
 
721
 
 
722
  
 
723
  g_signal_connect (G_OBJECT (GTK_OPTION_MENU (option_menu)->menu), 
 
724
                    "deactivate", G_CALLBACK (string_option_menu_changed),
 
725
                    (gpointer) conf_key);                                   
 
726
 
 
727
  g_free (conf_string); 
 
728
}
 
729
 
 
730
 
 
731
GtkWidget *
 
732
gnome_prefs_subsection_new (GtkWidget *window,
 
733
                            GtkWidget *container,
 
734
                            gchar *frame_name,       
 
735
                            int rows,
 
736
                            int cols)      
 
737
{
 
738
  GnomePrefsWindow *gpw  = NULL;
 
739
  
 
740
  GtkWidget *hbox = NULL;
 
741
  GtkWidget *frame = NULL;
 
742
  GtkWidget *table = NULL;
 
743
  GtkWidget *label = NULL;
 
744
  
 
745
  PangoAttrList *attrs = NULL;
 
746
  PangoAttribute *attr = NULL;
 
747
 
 
748
  if (window)
 
749
    gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (window), "gpw");
 
750
  
 
751
  hbox = gtk_hbox_new (FALSE, 6);
 
752
 
 
753
  frame = gtk_frame_new (frame_name);
 
754
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
 
755
  
 
756
  attrs = pango_attr_list_new ();
 
757
  attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
 
758
  attr->start_index = 0;
 
759
  attr->end_index = -1;
 
760
  pango_attr_list_insert (attrs, attr);
 
761
 
 
762
  label = gtk_frame_get_label_widget (GTK_FRAME (frame));
 
763
  gtk_label_set_attributes (GTK_LABEL (label), attrs);
 
764
  pango_attr_list_unref (attrs);
 
765
 
 
766
  gtk_box_pack_start (GTK_BOX (container), frame,
 
767
                      FALSE, FALSE, 0);
 
768
  table = gtk_table_new (rows, cols, FALSE);                                   
 
769
                                                                              
 
770
  gtk_container_add (GTK_CONTAINER (frame), hbox); 
 
771
 
 
772
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 3);
 
773
  gtk_container_set_border_width (GTK_CONTAINER (frame), 6);
 
774
 
 
775
  label = gtk_label_new ("    ");
 
776
  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
 
777
  gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, FALSE, 0);
 
778
                                                                               
 
779
  gtk_table_set_row_spacings (GTK_TABLE (table), 2);     
 
780
  gtk_table_set_col_spacings (GTK_TABLE (table), 6);     
 
781
 
 
782
  if (gpw)
 
783
    g_object_set_data (G_OBJECT (table), "gpw", gpw);
 
784
 
 
785
  gtk_widget_show_all (table);
 
786
  
 
787
  return table;
 
788
}                                                                              
 
789
 
 
790
 
 
791
GtkWidget *
 
792
gnome_prefs_window_new (gchar *logo_name)
 
793
{
 
794
  GnomePrefsWindow *gpw = NULL;
 
795
  
 
796
  GtkTreeSelection *selection = NULL;
 
797
  GtkCellRenderer *cell = NULL;
 
798
  GtkTreeStore *model = NULL;
 
799
  GtkTreeViewColumn *column = NULL;
 
800
 
 
801
  GtkWidget *window = NULL;
 
802
  GtkWidget *event_box = NULL;
 
803
  GtkWidget *hbox = NULL;
 
804
  GtkWidget *vbox = NULL;
 
805
  GtkWidget *frame = NULL;
 
806
  GtkWidget *pixmap = NULL;
 
807
  GtkWidget *hsep = NULL;
 
808
 
 
809
  GdkColor cwhite;
 
810
 
 
811
  PangoAttrList *attrs = NULL; 
 
812
  PangoAttribute *attr = NULL; 
 
813
 
 
814
  /* Box inside the prefs window */
 
815
  GtkWidget *dialog_vbox = NULL;
 
816
 
 
817
  /* Build the window */
 
818
  window = gtk_dialog_new ();
 
819
 
 
820
  gpw = (GnomePrefsWindow *) g_malloc (sizeof (GnomePrefsWindow));
 
821
  gpw->last_page = 1;
 
822
  
 
823
  g_object_set_data_full (G_OBJECT (window), "gpw", (gpointer) gpw, g_free);
 
824
  
 
825
  gtk_dialog_add_button (GTK_DIALOG (window), GTK_STOCK_CLOSE, 0);
 
826
 
 
827
  
 
828
  /* The sections */
 
829
  gpw->notebook = gtk_notebook_new ();
 
830
  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (gpw->notebook), FALSE);
 
831
  gtk_notebook_set_show_border (GTK_NOTEBOOK (gpw->notebook), FALSE);
 
832
  gtk_notebook_popup_enable (GTK_NOTEBOOK (gpw->notebook));
 
833
 
 
834
  pixmap =  gtk_image_new_from_file (logo_name);
 
835
 
 
836
  event_box = gtk_event_box_new ();
 
837
  gtk_container_add (GTK_CONTAINER (event_box),
 
838
                     GTK_WIDGET (pixmap));
 
839
 
 
840
  gdk_color_white (gdk_colormap_get_system (), &cwhite); 
 
841
  gtk_widget_modify_bg (GTK_WIDGET (event_box),
 
842
                        GTK_STATE_NORMAL, &cwhite);
 
843
 
 
844
  gtk_notebook_prepend_page (GTK_NOTEBOOK (gpw->notebook), event_box, NULL);
 
845
 
 
846
 
 
847
  /* The sections */
 
848
  dialog_vbox = GTK_DIALOG (window)->vbox;
 
849
  
 
850
  hbox = gtk_hbox_new (FALSE, 6);
 
851
  gtk_container_set_border_width (GTK_CONTAINER (hbox), 6);
 
852
  gtk_container_add (GTK_CONTAINER (dialog_vbox), hbox);
 
853
 
 
854
 
 
855
  /* The tooltips */
 
856
  gpw->tips = gtk_tooltips_new ();
 
857
 
 
858
 
 
859
  /* Build the TreeView on the left */
 
860
  frame = gtk_frame_new (NULL);
 
861
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
 
862
  gtk_box_pack_start (GTK_BOX (hbox), frame, FALSE, FALSE, 0);
 
863
  model = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_INT);
 
864
  gpw->sections_tree_view = gtk_tree_view_new ();
 
865
  gtk_tree_view_set_model (GTK_TREE_VIEW (gpw->sections_tree_view),
 
866
                           GTK_TREE_MODEL (model));
 
867
  selection =
 
868
    gtk_tree_view_get_selection (GTK_TREE_VIEW (gpw->sections_tree_view));
 
869
  gtk_container_add (GTK_CONTAINER (frame), gpw->sections_tree_view);
 
870
  gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (gpw->sections_tree_view),
 
871
                                     FALSE);
 
872
  cell = gtk_cell_renderer_text_new ();
 
873
 
 
874
  column = gtk_tree_view_column_new_with_attributes (NULL, cell, "text", 0,
 
875
                                                     NULL);
 
876
 
 
877
  gtk_tree_view_append_column (GTK_TREE_VIEW (gpw->sections_tree_view),
 
878
                               GTK_TREE_VIEW_COLUMN (column));
 
879
  gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
 
880
                               GTK_SELECTION_BROWSE);
 
881
 
 
882
  
 
883
  /* Some design stuff to put the notebook pages in it */
 
884
  frame = gtk_frame_new (NULL);
 
885
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
 
886
  gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
 
887
  gtk_widget_show (frame);
 
888
  
 
889
  vbox = gtk_vbox_new (FALSE, 0);
 
890
  gtk_container_add (GTK_CONTAINER (frame), vbox);
 
891
  gtk_widget_show (vbox);
 
892
  
 
893
  
 
894
  gpw->section_label = gtk_label_new (NULL);
 
895
  frame = gtk_frame_new (NULL);
 
896
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
 
897
  gtk_container_set_border_width (GTK_CONTAINER (frame), 4);
 
898
  gtk_misc_set_alignment (GTK_MISC (gpw->section_label), 0.0, 0.5);
 
899
  gtk_container_add (GTK_CONTAINER (frame), gpw->section_label);
 
900
  gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0);
 
901
  attrs = pango_attr_list_new ();
 
902
  attr = pango_attr_scale_new (PANGO_SCALE_LARGE);
 
903
  attr->start_index = 0;
 
904
  attr->end_index = G_MAXUINT; 
 
905
  pango_attr_list_insert (attrs, attr); 
 
906
  attr = pango_attr_weight_new (PANGO_WEIGHT_HEAVY);
 
907
  attr->start_index = 0;
 
908
  attr->end_index = G_MAXUINT;
 
909
  pango_attr_list_insert (attrs, attr);
 
910
  gtk_label_set_attributes (GTK_LABEL (gpw->section_label), attrs);
 
911
  pango_attr_list_unref (attrs);
 
912
  gtk_widget_show (gpw->section_label);
 
913
 
 
914
  hsep = gtk_hseparator_new ();
 
915
  gtk_box_pack_start (GTK_BOX (vbox), hsep, FALSE, FALSE, 0); 
 
916
  gtk_box_pack_start (GTK_BOX (vbox), gpw->notebook, TRUE, TRUE, 0);
 
917
 
 
918
  gtk_widget_show_all (GTK_WIDGET (dialog_vbox));
 
919
  gtk_widget_show_all (GTK_WIDGET (gpw->sections_tree_view));
 
920
 
 
921
  g_signal_connect (selection, "changed",
 
922
                    G_CALLBACK (tree_selection_changed_cb),
 
923
                    gpw);
 
924
 
 
925
  
 
926
  return window;
 
927
}
 
928
 
 
929
 
 
930
void
 
931
gnome_prefs_window_section_new (GtkWidget *window,
 
932
                                gchar *section_name)
 
933
{
 
934
  GnomePrefsWindow *gpw = NULL;
 
935
  GtkTreeModel *model = NULL;
 
936
    
 
937
  if (!window)
 
938
    return;
 
939
 
 
940
  if (window)
 
941
    gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (window), "gpw");
 
942
 
 
943
  if (!gpw || !section_name)
 
944
    return;
 
945
 
 
946
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (gpw->sections_tree_view));
 
947
  gtk_tree_store_append (GTK_TREE_STORE (model), &gpw->iter, NULL);
 
948
  gtk_tree_store_set (GTK_TREE_STORE (model), &gpw->iter, 0,
 
949
                      section_name, 1, 0, -1);
 
950
  gtk_tree_view_expand_all (GTK_TREE_VIEW (gpw->sections_tree_view));
 
951
}
 
952
 
 
953
 
 
954
GtkWidget *
 
955
gnome_prefs_window_subsection_new (GtkWidget *window,
 
956
                                   gchar *section_name)
 
957
{
 
958
  GnomePrefsWindow *gpw = NULL;
 
959
  GtkWidget *container = NULL;
 
960
  GtkTreeModel *model = NULL;
 
961
  GtkTreeIter child_iter;
 
962
    
 
963
  if (!window)
 
964
    return NULL;
 
965
  
 
966
  gpw = (GnomePrefsWindow *) g_object_get_data (G_OBJECT (window), "gpw");
 
967
 
 
968
  if (!gpw || !section_name)
 
969
    return NULL;
 
970
 
 
971
  container = gtk_vbox_new (FALSE, 4);
 
972
  model = gtk_tree_view_get_model (GTK_TREE_VIEW (gpw->sections_tree_view));
 
973
  gtk_tree_store_append (GTK_TREE_STORE (model), &child_iter, &gpw->iter);
 
974
  gtk_tree_store_set (GTK_TREE_STORE (model), &child_iter, 0, section_name,
 
975
                      1, gpw->last_page, -1);
 
976
  gtk_tree_view_expand_all (GTK_TREE_VIEW (gpw->sections_tree_view));
 
977
  
 
978
  gpw->last_page++;
 
979
  
 
980
  gtk_notebook_append_page (GTK_NOTEBOOK (gpw->notebook),
 
981
                            container, NULL);
 
982
 
 
983
  gtk_widget_show_all (container);
 
984
  
 
985
  return container;
 
986
}