1 /*
2 ** 1999-04-05 - Configuration module to deal with individual built-in commands'
3 ** configuration. Deep, huh? Relies heavily on the "cmdseq_config"
4 ** module.
5 */
6
7 #include "gentoo.h"
8
9 #include "cmdseq_config.h"
10
11 #include "configure.h"
12 #include "cfg_module.h"
13
14 #include "cfg_cmdcfg.h"
15
16 #define NODE "CommandConfig"
17
18 /* ----------------------------------------------------------------------------------------- */
19
20 typedef struct {
21 CmdCfg *cmc;
22 gpointer instance;
23 GtkWidget *gui;
24 } CmdPair;
25
26 typedef struct {
27 GtkWidget *vbox; /* This is required. */
28
29 MainInfo *min;
30 CmdPair *cmd; /* Vector of cmc-instance pairs. */
31 guint cmd_num; /* Length of above vector. */
32 guint cmd_index; /* Current, used during setup. */
33 } P_CmdCfg;
34
35 static P_CmdCfg the_page;
36
37 /* ----------------------------------------------------------------------------------------- */
38
39 /* 1999-04-05 - Create editing instances for all registered cmc's out there. */
create_instance(CmdCfg * cmc,gpointer user)40 static void create_instance(CmdCfg *cmc, gpointer user)
41 {
42 P_CmdCfg *page = user;
43
44 page->cmd[page->cmd_index].cmc = cmc;
45 page->cmd[page->cmd_index].instance = cmc_instance_new_from_base(cmc);
46 page->cmd[page->cmd_index].gui = NULL;
47 page->cmd_index++;
48 }
49
50 /* 1999-04-05 - Initialize the command config interface. Actually quite simple. */
ccc_init(MainInfo * min,gchar ** name)51 static GtkWidget * ccc_init(MainInfo *min, gchar **name)
52 {
53 P_CmdCfg *page = &the_page;
54 const gchar *label;
55 guint i;
56
57 page->min = min;
58 page->cmd_num = cmc_config_registered_num();
59 page->cmd = g_malloc(page->cmd_num * sizeof *page->cmd);
60 page->cmd_index = 0;
61 cmc_config_registered_foreach(create_instance, page);
62
63 page->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
64
65 gtk_widget_show_all(page->vbox);
66 cfg_tree_level_begin(_("Options"));
67 for(i = 0; i < page->cmd_num; i++)
68 {
69 label = cmc_config_get_name(page->cmd[i].cmc);
70 page->cmd[i].gui = gtk_label_new("(dummy)");
71 cfg_tree_level_append(label, page->cmd[i].gui);
72 }
73 cfg_tree_level_end();
74 cfg_tree_level_end();
75 return NULL;
76 }
77
78 /* ----------------------------------------------------------------------------------------- */
79
80 /* 1999-04-05 - The configuration window is opening up; make sure our page is up-to-date.
81 ** This involves refreshing the editing data from the base instances, and
82 ** building new widgets.
83 */
ccc_update(MainInfo * min)84 static void ccc_update(MainInfo *min)
85 {
86 P_CmdCfg *page = &the_page;
87 GtkWidget *subpage;
88 guint i;
89
90 for(i = 0; i < page->cmd_num; i++)
91 {
92 cmc_instance_copy_from_base(page->cmd[i].cmc, page->cmd[i].instance);
93 if((subpage = cmc_instance_build(page->cmd[i].cmc, page->cmd[i].instance)) != NULL)
94 {
95 cfg_tree_level_replace(page->cmd[i].gui, subpage);
96 page->cmd[i].gui = subpage;
97 }
98 }
99 }
100
101 /* ----------------------------------------------------------------------------------------- */
102
103 /* 1999-04-05 - Accept the current settings, thus copying our editing instances over the
104 ** commands' base ones
105 */
ccc_accept(MainInfo * min)106 static void ccc_accept(MainInfo *min)
107 {
108 P_CmdCfg *page = &the_page;
109 guint i;
110
111 for(i = 0; i < page->cmd_num; i++)
112 {
113 if(cmc_instance_get_modified(page->cmd[i].cmc, page->cmd[i].instance))
114 cmc_instance_copy_to_base(page->cmd[i].cmc, page->cmd[i].instance);
115 }
116 }
117
118 /* ----------------------------------------------------------------------------------------- */
119
cmdcfg_save(CmdCfg * cmc,gpointer user)120 static void cmdcfg_save(CmdCfg *cmc, gpointer user)
121 {
122 cmc_config_base_save(cmc, user);
123 }
124
125 /* 1999-04-05 - Write command configuration data into open file at <out>. Note that this does
126 ** not use the editing instances, since they are not necessarily up-to-date.
127 */
ccc_save(MainInfo * min,FILE * out)128 static gint ccc_save(MainInfo *min, FILE *out)
129 {
130 xml_put_node_open(out, NODE);
131 cmc_config_registered_foreach(cmdcfg_save, out);
132 xml_put_node_close(out, NODE);
133
134 return 1;
135 }
136
137 /* ----------------------------------------------------------------------------------------- */
138
139 /* 1999-04-05 - Look for node with <cmc>'s name in XML tree at <user>, and load (parse) the
140 ** data into the base instance.
141 */
cmdcfg_load(CmdCfg * cmc,gpointer user)142 static void cmdcfg_load(CmdCfg *cmc, gpointer user)
143 {
144 const XmlNode *tree = user, *data;
145
146 if((data = xml_tree_search(tree, cmc_config_get_name(cmc))) != NULL)
147 cmc_config_base_load(cmc, data);
148 }
149
150 /* 1999-04-05 - Load command config data from tree rooted at <node>. As all other config loaders,
151 ** this actually does *not* load into the editing copies of the data being configured,
152 ** but rather into the actual config data in use (the base instances here).
153 */
ccc_load(MainInfo * min,const XmlNode * node)154 static void ccc_load(MainInfo *min, const XmlNode *node)
155 {
156 cmc_config_registered_foreach(cmdcfg_load, (gpointer) node);
157 }
158
159 /* ----------------------------------------------------------------------------------------- */
160
161 /* 1999-04-05 - That ever-present page describing function. */
ccc_describe(MainInfo * min)162 const CfgModule * ccc_describe(MainInfo *min)
163 {
164 static const CfgModule desc = { NODE, ccc_init, ccc_update, ccc_accept, ccc_save, ccc_load, NULL };
165
166 return &desc;
167 }
168