-
Notifications
You must be signed in to change notification settings - Fork 2
/
gconf.c
1456 lines (1206 loc) · 36.6 KB
/
gconf.c
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
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2002-2003 Romain Lievin <[email protected]>
*/
#include <stdlib.h>
#include "lkc.h"
#include "images.h"
#include <glade/glade.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <gdk/gdkkeysyms.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <time.h>
enum {
SINGLE_VIEW, SPLIT_VIEW, FULL_VIEW
};
enum {
OPT_NORMAL, OPT_ALL, OPT_PROMPT
};
static gint view_mode = FULL_VIEW;
static gboolean show_name = TRUE;
static gboolean show_range = TRUE;
static gboolean show_value = TRUE;
static gboolean resizeable = FALSE;
static int opt_mode = OPT_NORMAL;
GtkWidget *main_wnd = NULL;
GtkWidget *tree1_w = NULL; // left frame
GtkWidget *tree2_w = NULL; // right frame
GtkWidget *text_w = NULL;
GtkWidget *hpaned = NULL;
GtkWidget *vpaned = NULL;
GtkWidget *back_btn = NULL;
GtkWidget *save_btn = NULL;
GtkWidget *save_menu_item = NULL;
GtkTextTag *tag1, *tag2;
GdkColor color;
GtkTreeStore *tree1, *tree2, *tree;
GtkTreeModel *model1, *model2;
static GtkTreeIter *parents[256];
static gint indent;
static struct menu *current; // current node for SINGLE view
static struct menu *browsed; // browsed node for SPLIT view
enum {
COL_OPTION, COL_NAME, COL_NO, COL_MOD, COL_YES, COL_VALUE,
COL_MENU, COL_COLOR, COL_EDIT, COL_PIXBUF,
COL_PIXVIS, COL_BTNVIS, COL_BTNACT, COL_BTNINC, COL_BTNRAD,
COL_NUMBER
};
static void display_list(void);
static void display_tree(struct menu *menu);
static void display_tree_part(void);
static void update_tree(struct menu *src, GtkTreeIter * dst);
static void set_node(GtkTreeIter * node, struct menu *menu, gchar ** row);
static gchar **fill_row(struct menu *menu);
static void conf_changed(void);
static void replace_button_icon(GladeXML *xml, GdkDrawable *window,
GtkStyle *style, gchar *btn_name, gchar **xpm)
{
GdkPixmap *pixmap;
GdkBitmap *mask;
GtkToolButton *button;
GtkWidget *image;
pixmap = gdk_pixmap_create_from_xpm_d(window, &mask,
&style->bg[GTK_STATE_NORMAL],
xpm);
button = GTK_TOOL_BUTTON(glade_xml_get_widget(xml, btn_name));
image = gtk_image_new_from_pixmap(pixmap, mask);
gtk_widget_show(image);
gtk_tool_button_set_icon_widget(button, image);
}
/* Main Window Initialization */
static void init_main_window(const gchar *glade_file)
{
GladeXML *xml;
GtkWidget *widget;
GtkTextBuffer *txtbuf;
GtkStyle *style;
xml = glade_xml_new(glade_file, "window1", NULL);
if (!xml)
g_error("GUI loading failed !\n");
glade_xml_signal_autoconnect(xml);
main_wnd = glade_xml_get_widget(xml, "window1");
hpaned = glade_xml_get_widget(xml, "hpaned1");
vpaned = glade_xml_get_widget(xml, "vpaned1");
tree1_w = glade_xml_get_widget(xml, "treeview1");
tree2_w = glade_xml_get_widget(xml, "treeview2");
text_w = glade_xml_get_widget(xml, "textview3");
back_btn = glade_xml_get_widget(xml, "button1");
gtk_widget_set_sensitive(back_btn, FALSE);
widget = glade_xml_get_widget(xml, "show_name1");
gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
show_name);
widget = glade_xml_get_widget(xml, "show_range1");
gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
show_range);
widget = glade_xml_get_widget(xml, "show_data1");
gtk_check_menu_item_set_active((GtkCheckMenuItem *) widget,
show_value);
save_btn = glade_xml_get_widget(xml, "button3");
save_menu_item = glade_xml_get_widget(xml, "save1");
conf_set_changed_callback(conf_changed);
style = gtk_widget_get_style(main_wnd);
widget = glade_xml_get_widget(xml, "toolbar1");
replace_button_icon(xml, main_wnd->window, style,
"button4", (gchar **) xpm_single_view);
replace_button_icon(xml, main_wnd->window, style,
"button5", (gchar **) xpm_split_view);
replace_button_icon(xml, main_wnd->window, style,
"button6", (gchar **) xpm_tree_view);
txtbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
tag1 = gtk_text_buffer_create_tag(txtbuf, "mytag1",
"foreground", "red",
"weight", PANGO_WEIGHT_BOLD,
NULL);
tag2 = gtk_text_buffer_create_tag(txtbuf, "mytag2",
/*"style", PANGO_STYLE_OBLIQUE, */
NULL);
gtk_window_set_title(GTK_WINDOW(main_wnd), rootmenu.prompt->text);
gtk_widget_show(main_wnd);
}
static void init_tree_model(void)
{
gint i;
tree = tree2 = gtk_tree_store_new(COL_NUMBER,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_POINTER, GDK_TYPE_COLOR,
G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF,
G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN);
model2 = GTK_TREE_MODEL(tree2);
for (parents[0] = NULL, i = 1; i < 256; i++)
parents[i] = (GtkTreeIter *) g_malloc(sizeof(GtkTreeIter));
tree1 = gtk_tree_store_new(COL_NUMBER,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_POINTER, GDK_TYPE_COLOR,
G_TYPE_BOOLEAN, GDK_TYPE_PIXBUF,
G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN, G_TYPE_BOOLEAN,
G_TYPE_BOOLEAN);
model1 = GTK_TREE_MODEL(tree1);
}
static void init_left_tree(void)
{
GtkTreeView *view = GTK_TREE_VIEW(tree1_w);
GtkCellRenderer *renderer;
GtkTreeSelection *sel;
GtkTreeViewColumn *column;
gtk_tree_view_set_model(view, model1);
gtk_tree_view_set_headers_visible(view, TRUE);
gtk_tree_view_set_rules_hint(view, TRUE);
column = gtk_tree_view_column_new();
gtk_tree_view_append_column(view, column);
gtk_tree_view_column_set_title(column, "Options");
renderer = gtk_cell_renderer_toggle_new();
gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
renderer, FALSE);
gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
renderer,
"active", COL_BTNACT,
"inconsistent", COL_BTNINC,
"visible", COL_BTNVIS,
"radio", COL_BTNRAD, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
renderer, FALSE);
gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
renderer,
"text", COL_OPTION,
"foreground-gdk",
COL_COLOR, NULL);
sel = gtk_tree_view_get_selection(view);
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
gtk_widget_realize(tree1_w);
}
static void renderer_edited(GtkCellRendererText * cell,
const gchar * path_string,
const gchar * new_text, gpointer user_data);
static void init_right_tree(void)
{
GtkTreeView *view = GTK_TREE_VIEW(tree2_w);
GtkCellRenderer *renderer;
GtkTreeSelection *sel;
GtkTreeViewColumn *column;
gint i;
gtk_tree_view_set_model(view, model2);
gtk_tree_view_set_headers_visible(view, TRUE);
gtk_tree_view_set_rules_hint(view, TRUE);
column = gtk_tree_view_column_new();
gtk_tree_view_append_column(view, column);
gtk_tree_view_column_set_title(column, "Options");
renderer = gtk_cell_renderer_pixbuf_new();
gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
renderer, FALSE);
gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
renderer,
"pixbuf", COL_PIXBUF,
"visible", COL_PIXVIS, NULL);
renderer = gtk_cell_renderer_toggle_new();
gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
renderer, FALSE);
gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
renderer,
"active", COL_BTNACT,
"inconsistent", COL_BTNINC,
"visible", COL_BTNVIS,
"radio", COL_BTNRAD, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_column_pack_start(GTK_TREE_VIEW_COLUMN(column),
renderer, FALSE);
gtk_tree_view_column_set_attributes(GTK_TREE_VIEW_COLUMN(column),
renderer,
"text", COL_OPTION,
"foreground-gdk",
COL_COLOR, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(view, -1,
"Name", renderer,
"text", COL_NAME,
"foreground-gdk",
COL_COLOR, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(view, -1,
"N", renderer,
"text", COL_NO,
"foreground-gdk",
COL_COLOR, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(view, -1,
"M", renderer,
"text", COL_MOD,
"foreground-gdk",
COL_COLOR, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(view, -1,
"Y", renderer,
"text", COL_YES,
"foreground-gdk",
COL_COLOR, NULL);
renderer = gtk_cell_renderer_text_new();
gtk_tree_view_insert_column_with_attributes(view, -1,
"Value", renderer,
"text", COL_VALUE,
"editable",
COL_EDIT,
"foreground-gdk",
COL_COLOR, NULL);
g_signal_connect(G_OBJECT(renderer), "edited",
G_CALLBACK(renderer_edited), NULL);
column = gtk_tree_view_get_column(view, COL_NAME);
gtk_tree_view_column_set_visible(column, show_name);
column = gtk_tree_view_get_column(view, COL_NO);
gtk_tree_view_column_set_visible(column, show_range);
column = gtk_tree_view_get_column(view, COL_MOD);
gtk_tree_view_column_set_visible(column, show_range);
column = gtk_tree_view_get_column(view, COL_YES);
gtk_tree_view_column_set_visible(column, show_range);
column = gtk_tree_view_get_column(view, COL_VALUE);
gtk_tree_view_column_set_visible(column, show_value);
if (resizeable) {
for (i = 0; i < COL_VALUE; i++) {
column = gtk_tree_view_get_column(view, i);
gtk_tree_view_column_set_resizable(column, TRUE);
}
}
sel = gtk_tree_view_get_selection(view);
gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE);
}
/* Utility Functions */
static void text_insert_help(struct menu *menu)
{
GtkTextBuffer *buffer;
GtkTextIter start, end;
const char *prompt = menu_get_prompt(menu);
struct gstr help = str_new();
menu_get_ext_help(menu, &help);
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
gtk_text_buffer_get_bounds(buffer, &start, &end);
gtk_text_buffer_delete(buffer, &start, &end);
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_w), 15);
gtk_text_buffer_get_end_iter(buffer, &end);
gtk_text_buffer_insert_with_tags(buffer, &end, prompt, -1, tag1,
NULL);
gtk_text_buffer_insert_at_cursor(buffer, "\n\n", 2);
gtk_text_buffer_get_end_iter(buffer, &end);
gtk_text_buffer_insert_with_tags(buffer, &end, str_get(&help), -1, tag2,
NULL);
str_free(&help);
}
static void text_insert_msg(const char *title, const char *message)
{
GtkTextBuffer *buffer;
GtkTextIter start, end;
const char *msg = message;
buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_w));
gtk_text_buffer_get_bounds(buffer, &start, &end);
gtk_text_buffer_delete(buffer, &start, &end);
gtk_text_view_set_left_margin(GTK_TEXT_VIEW(text_w), 15);
gtk_text_buffer_get_end_iter(buffer, &end);
gtk_text_buffer_insert_with_tags(buffer, &end, title, -1, tag1,
NULL);
gtk_text_buffer_insert_at_cursor(buffer, "\n\n", 2);
gtk_text_buffer_get_end_iter(buffer, &end);
gtk_text_buffer_insert_with_tags(buffer, &end, msg, -1, tag2,
NULL);
}
/* Main Windows Callbacks */
void on_save_activate(GtkMenuItem * menuitem, gpointer user_data);
gboolean on_window1_delete_event(GtkWidget * widget, GdkEvent * event,
gpointer user_data)
{
GtkWidget *dialog, *label;
gint result;
if (!conf_get_changed())
return FALSE;
dialog = gtk_dialog_new_with_buttons("Warning !",
GTK_WINDOW(main_wnd),
(GtkDialogFlags)
(GTK_DIALOG_MODAL |
GTK_DIALOG_DESTROY_WITH_PARENT),
GTK_STOCK_OK,
GTK_RESPONSE_YES,
GTK_STOCK_NO,
GTK_RESPONSE_NO,
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL, NULL);
gtk_dialog_set_default_response(GTK_DIALOG(dialog),
GTK_RESPONSE_CANCEL);
label = gtk_label_new("\nSave configuration ?\n");
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), label);
gtk_widget_show(label);
result = gtk_dialog_run(GTK_DIALOG(dialog));
switch (result) {
case GTK_RESPONSE_YES:
on_save_activate(NULL, NULL);
return FALSE;
case GTK_RESPONSE_NO:
return FALSE;
case GTK_RESPONSE_CANCEL:
case GTK_RESPONSE_DELETE_EVENT:
default:
gtk_widget_destroy(dialog);
return TRUE;
}
return FALSE;
}
void on_window1_destroy(GtkObject * object, gpointer user_data)
{
gtk_main_quit();
}
void
on_window1_size_request(GtkWidget * widget,
GtkRequisition * requisition, gpointer user_data)
{
static gint old_h;
gint w, h;
if (widget->window == NULL)
gtk_window_get_default_size(GTK_WINDOW(main_wnd), &w, &h);
else
gdk_window_get_size(widget->window, &w, &h);
if (h == old_h)
return;
old_h = h;
gtk_paned_set_position(GTK_PANED(vpaned), 2 * h / 3);
}
/* Menu & Toolbar Callbacks */
static void
load_filename(GtkFileSelection * file_selector, gpointer user_data)
{
const gchar *fn;
fn = gtk_file_selection_get_filename(GTK_FILE_SELECTION
(user_data));
if (conf_read(fn))
text_insert_msg("Error", "Unable to load configuration !");
else
display_tree_part();
}
void on_load1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkWidget *fs;
fs = gtk_file_selection_new("Load file...");
g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked",
G_CALLBACK(load_filename), (gpointer) fs);
g_signal_connect_swapped(GTK_OBJECT
(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", G_CALLBACK(gtk_widget_destroy),
(gpointer) fs);
g_signal_connect_swapped(GTK_OBJECT
(GTK_FILE_SELECTION(fs)->cancel_button),
"clicked", G_CALLBACK(gtk_widget_destroy),
(gpointer) fs);
gtk_widget_show(fs);
}
void on_save_activate(GtkMenuItem * menuitem, gpointer user_data)
{
if (conf_write(NULL))
text_insert_msg("Error", "Unable to save configuration !");
conf_write_autoconf(0);
}
static void
store_filename(GtkFileSelection * file_selector, gpointer user_data)
{
const gchar *fn;
fn = gtk_file_selection_get_filename(GTK_FILE_SELECTION
(user_data));
if (conf_write(fn))
text_insert_msg("Error", "Unable to save configuration !");
gtk_widget_destroy(GTK_WIDGET(user_data));
}
void on_save_as1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkWidget *fs;
fs = gtk_file_selection_new("Save file as...");
g_signal_connect(GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
"clicked",
G_CALLBACK(store_filename), (gpointer) fs);
g_signal_connect_swapped(GTK_OBJECT
(GTK_FILE_SELECTION(fs)->ok_button),
"clicked", G_CALLBACK(gtk_widget_destroy),
(gpointer) fs);
g_signal_connect_swapped(GTK_OBJECT
(GTK_FILE_SELECTION(fs)->cancel_button),
"clicked", G_CALLBACK(gtk_widget_destroy),
(gpointer) fs);
gtk_widget_show(fs);
}
void on_quit1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
if (!on_window1_delete_event(NULL, NULL, NULL))
gtk_widget_destroy(GTK_WIDGET(main_wnd));
}
void on_show_name1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkTreeViewColumn *col;
show_name = GTK_CHECK_MENU_ITEM(menuitem)->active;
col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_NAME);
if (col)
gtk_tree_view_column_set_visible(col, show_name);
}
void on_show_range1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkTreeViewColumn *col;
show_range = GTK_CHECK_MENU_ITEM(menuitem)->active;
col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_NO);
if (col)
gtk_tree_view_column_set_visible(col, show_range);
col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_MOD);
if (col)
gtk_tree_view_column_set_visible(col, show_range);
col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_YES);
if (col)
gtk_tree_view_column_set_visible(col, show_range);
}
void on_show_data1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkTreeViewColumn *col;
show_value = GTK_CHECK_MENU_ITEM(menuitem)->active;
col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), COL_VALUE);
if (col)
gtk_tree_view_column_set_visible(col, show_value);
}
void
on_set_option_mode1_activate(GtkMenuItem *menuitem, gpointer user_data)
{
opt_mode = OPT_NORMAL;
gtk_tree_store_clear(tree2);
display_tree(&rootmenu); /* instead of update_tree to speed-up */
}
void
on_set_option_mode2_activate(GtkMenuItem *menuitem, gpointer user_data)
{
opt_mode = OPT_ALL;
gtk_tree_store_clear(tree2);
display_tree(&rootmenu); /* instead of update_tree to speed-up */
}
void
on_set_option_mode3_activate(GtkMenuItem *menuitem, gpointer user_data)
{
opt_mode = OPT_PROMPT;
gtk_tree_store_clear(tree2);
display_tree(&rootmenu); /* instead of update_tree to speed-up */
}
void on_introduction1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkWidget *dialog;
const gchar *intro_text =
"Welcome to gconfig, the GTK+ graphical configuration tool.\n"
"For each option, a blank box indicates the feature is disabled, a\n"
"check indicates it is enabled, and a dot indicates that it is to\n"
"be compiled as a module. Clicking on the box will cycle through the three states.\n"
"\n"
"If you do not see an option (e.g., a device driver) that you\n"
"believe should be present, try turning on Show All Options\n"
"under the Options menu.\n"
"Although there is no cross reference yet to help you figure out\n"
"what other options must be enabled to support the option you\n"
"are interested in, you can still view the help of a grayed-out\n"
"option.";
dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE, "%s", intro_text);
g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
G_CALLBACK(gtk_widget_destroy),
GTK_OBJECT(dialog));
gtk_widget_show_all(dialog);
}
void on_about1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkWidget *dialog;
const gchar *about_text =
"gconfig is copyright (c) 2002 Romain Lievin <[email protected]>.\n"
"Based on the source code from Roman Zippel.\n";
dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE, "%s", about_text);
g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
G_CALLBACK(gtk_widget_destroy),
GTK_OBJECT(dialog));
gtk_widget_show_all(dialog);
}
void on_license1_activate(GtkMenuItem * menuitem, gpointer user_data)
{
GtkWidget *dialog;
const gchar *license_text =
"gconfig is released under the terms of the GNU GPL v2.\n"
"For more information, please see the source code or\n"
"visit http://www.fsf.org/licenses/licenses.html\n";
dialog = gtk_message_dialog_new(GTK_WINDOW(main_wnd),
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE, "%s", license_text);
g_signal_connect_swapped(GTK_OBJECT(dialog), "response",
G_CALLBACK(gtk_widget_destroy),
GTK_OBJECT(dialog));
gtk_widget_show_all(dialog);
}
void on_back_clicked(GtkButton * button, gpointer user_data)
{
enum prop_type ptype;
current = current->parent;
ptype = current->prompt ? current->prompt->type : P_UNKNOWN;
if (ptype != P_MENU)
current = current->parent;
display_tree_part();
if (current == &rootmenu)
gtk_widget_set_sensitive(back_btn, FALSE);
}
void on_load_clicked(GtkButton * button, gpointer user_data)
{
on_load1_activate(NULL, user_data);
}
void on_single_clicked(GtkButton * button, gpointer user_data)
{
view_mode = SINGLE_VIEW;
gtk_widget_hide(tree1_w);
current = &rootmenu;
display_tree_part();
}
void on_split_clicked(GtkButton * button, gpointer user_data)
{
gint w, h;
view_mode = SPLIT_VIEW;
gtk_widget_show(tree1_w);
gtk_window_get_default_size(GTK_WINDOW(main_wnd), &w, &h);
gtk_paned_set_position(GTK_PANED(hpaned), w / 2);
if (tree2)
gtk_tree_store_clear(tree2);
display_list();
/* Disable back btn, like in full mode. */
gtk_widget_set_sensitive(back_btn, FALSE);
}
void on_full_clicked(GtkButton * button, gpointer user_data)
{
view_mode = FULL_VIEW;
gtk_widget_hide(tree1_w);
if (tree2)
gtk_tree_store_clear(tree2);
display_tree(&rootmenu);
gtk_widget_set_sensitive(back_btn, FALSE);
}
void on_collapse_clicked(GtkButton * button, gpointer user_data)
{
gtk_tree_view_collapse_all(GTK_TREE_VIEW(tree2_w));
}
void on_expand_clicked(GtkButton * button, gpointer user_data)
{
gtk_tree_view_expand_all(GTK_TREE_VIEW(tree2_w));
}
/* CTree Callbacks */
/* Change hex/int/string value in the cell */
static void renderer_edited(GtkCellRendererText * cell,
const gchar * path_string,
const gchar * new_text, gpointer user_data)
{
GtkTreePath *path = gtk_tree_path_new_from_string(path_string);
GtkTreeIter iter;
const char *old_def, *new_def;
struct menu *menu;
struct symbol *sym;
if (!gtk_tree_model_get_iter(model2, &iter, path))
return;
gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
sym = menu->sym;
gtk_tree_model_get(model2, &iter, COL_VALUE, &old_def, -1);
new_def = new_text;
sym_set_string_value(sym, new_def);
update_tree(&rootmenu, NULL);
gtk_tree_path_free(path);
}
/* Change the value of a symbol and update the tree */
static void change_sym_value(struct menu *menu, gint col)
{
struct symbol *sym = menu->sym;
tristate newval;
if (!sym)
return;
if (col == COL_NO)
newval = no;
else if (col == COL_MOD)
newval = mod;
else if (col == COL_YES)
newval = yes;
else
return;
switch (sym_get_type(sym)) {
case S_BOOLEAN:
case S_TRISTATE:
if (!sym_tristate_within_range(sym, newval))
newval = yes;
sym_set_tristate_value(sym, newval);
if (view_mode == FULL_VIEW)
update_tree(&rootmenu, NULL);
else if (view_mode == SPLIT_VIEW) {
update_tree(browsed, NULL);
display_list();
}
else if (view_mode == SINGLE_VIEW)
display_tree_part(); //fixme: keep exp/coll
break;
case S_INT:
case S_HEX:
case S_STRING:
default:
break;
}
}
static void toggle_sym_value(struct menu *menu)
{
if (!menu->sym)
return;
sym_toggle_tristate_value(menu->sym);
if (view_mode == FULL_VIEW)
update_tree(&rootmenu, NULL);
else if (view_mode == SPLIT_VIEW) {
update_tree(browsed, NULL);
display_list();
}
else if (view_mode == SINGLE_VIEW)
display_tree_part(); //fixme: keep exp/coll
}
static gint column2index(GtkTreeViewColumn * column)
{
gint i;
for (i = 0; i < COL_NUMBER; i++) {
GtkTreeViewColumn *col;
col = gtk_tree_view_get_column(GTK_TREE_VIEW(tree2_w), i);
if (col == column)
return i;
}
return -1;
}
/* User click: update choice (full) or goes down (single) */
gboolean
on_treeview2_button_press_event(GtkWidget * widget,
GdkEventButton * event, gpointer user_data)
{
GtkTreeView *view = GTK_TREE_VIEW(widget);
GtkTreePath *path;
GtkTreeViewColumn *column;
GtkTreeIter iter;
struct menu *menu;
gint col;
#if GTK_CHECK_VERSION(2,1,4) // bug in ctree with earlier version of GTK
gint tx = (gint) event->x;
gint ty = (gint) event->y;
gint cx, cy;
gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
&cy);
#else
gtk_tree_view_get_cursor(view, &path, &column);
#endif
if (path == NULL)
return FALSE;
if (!gtk_tree_model_get_iter(model2, &iter, path))
return FALSE;
gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
col = column2index(column);
if (event->type == GDK_2BUTTON_PRESS) {
enum prop_type ptype;
ptype = menu->prompt ? menu->prompt->type : P_UNKNOWN;
if (ptype == P_MENU && view_mode != FULL_VIEW && col == COL_OPTION) {
// goes down into menu
current = menu;
display_tree_part();
gtk_widget_set_sensitive(back_btn, TRUE);
} else if (col == COL_OPTION) {
toggle_sym_value(menu);
gtk_tree_view_expand_row(view, path, TRUE);
}
} else {
if (col == COL_VALUE) {
toggle_sym_value(menu);
gtk_tree_view_expand_row(view, path, TRUE);
} else if (col == COL_NO || col == COL_MOD
|| col == COL_YES) {
change_sym_value(menu, col);
gtk_tree_view_expand_row(view, path, TRUE);
}
}
return FALSE;
}
/* Key pressed: update choice */
gboolean
on_treeview2_key_press_event(GtkWidget * widget,
GdkEventKey * event, gpointer user_data)
{
GtkTreeView *view = GTK_TREE_VIEW(widget);
GtkTreePath *path;
GtkTreeViewColumn *column;
GtkTreeIter iter;
struct menu *menu;
gint col;
gtk_tree_view_get_cursor(view, &path, &column);
if (path == NULL)
return FALSE;
if (event->keyval == GDK_space) {
if (gtk_tree_view_row_expanded(view, path))
gtk_tree_view_collapse_row(view, path);
else
gtk_tree_view_expand_row(view, path, FALSE);
return TRUE;
}
if (event->keyval == GDK_KP_Enter) {
}
if (widget == tree1_w)
return FALSE;
gtk_tree_model_get_iter(model2, &iter, path);
gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
if (!strcasecmp(event->string, "n"))
col = COL_NO;
else if (!strcasecmp(event->string, "m"))
col = COL_MOD;
else if (!strcasecmp(event->string, "y"))
col = COL_YES;
else
col = -1;
change_sym_value(menu, col);
return FALSE;
}
/* Row selection changed: update help */
void
on_treeview2_cursor_changed(GtkTreeView * treeview, gpointer user_data)
{
GtkTreeSelection *selection;
GtkTreeIter iter;
struct menu *menu;
selection = gtk_tree_view_get_selection(treeview);
if (gtk_tree_selection_get_selected(selection, &model2, &iter)) {
gtk_tree_model_get(model2, &iter, COL_MENU, &menu, -1);
text_insert_help(menu);
}
}
/* User click: display sub-tree in the right frame. */
gboolean
on_treeview1_button_press_event(GtkWidget * widget,
GdkEventButton * event, gpointer user_data)
{
GtkTreeView *view = GTK_TREE_VIEW(widget);
GtkTreePath *path;
GtkTreeViewColumn *column;
GtkTreeIter iter;
struct menu *menu;
gint tx = (gint) event->x;
gint ty = (gint) event->y;
gint cx, cy;
gtk_tree_view_get_path_at_pos(view, tx, ty, &path, &column, &cx,
&cy);
if (path == NULL)
return FALSE;
gtk_tree_model_get_iter(model1, &iter, path);
gtk_tree_model_get(model1, &iter, COL_MENU, &menu, -1);
if (event->type == GDK_2BUTTON_PRESS) {
toggle_sym_value(menu);
current = menu;
display_tree_part();
} else {
browsed = menu;
display_tree_part();
}
gtk_widget_realize(tree2_w);
gtk_tree_view_set_cursor(view, path, NULL, FALSE);
gtk_widget_grab_focus(tree2_w);
return FALSE;
}
/* Fill a row of strings */
static gchar **fill_row(struct menu *menu)
{
static gchar *row[COL_NUMBER];
struct symbol *sym = menu->sym;
const char *def;
int stype;