94a9591844426b8c0e62f18ceabc1504f6de482f
[framework/uifw/e17.git] / src / modules / illume2 / e_mod_config.c
1 #include "e_illume_private.h"
2 #include "e_mod_config.h"
3 #include "e_mod_config_animation.h"
4 #include "e_mod_config_windows.h"
5 #include "e_mod_config_policy.h"
6
7 /* local function prototypes */
8 static void _e_mod_illume_config_free(void);
9 static void _e_mod_illume_config_new(void);
10
11 /* local variables */
12 static E_Config_DD *_il_conf_edd = NULL;
13 static E_Config_DD *_il_conf_zone_edd = NULL;
14
15 /* external variables */
16 E_Illume_Config *_e_illume_cfg = NULL;
17
18 int 
19 e_mod_illume_config_init(void) 
20 {
21    /* create config structure for zones */
22    _il_conf_zone_edd = E_CONFIG_DD_NEW("Illume_Config_Zone", E_Illume_Config_Zone);
23 #undef T
24 #undef D
25 #define T E_Illume_Config_Zone
26 #define D _il_conf_zone_edd
27    E_CONFIG_VAL(D, T, id, INT);
28    E_CONFIG_VAL(D, T, mode.dual, INT);
29    E_CONFIG_VAL(D, T, mode.side, INT);
30
31    /* create config structure for module */
32    _il_conf_edd = E_CONFIG_DD_NEW("Illume_Config", E_Illume_Config);
33 #undef T
34 #undef D
35 #define T E_Illume_Config
36 #define D _il_conf_edd
37    E_CONFIG_VAL(D, T, version, INT);
38    E_CONFIG_VAL(D, T, animation.vkbd.duration, INT);
39    E_CONFIG_VAL(D, T, animation.quickpanel.duration, INT);
40    E_CONFIG_VAL(D, T, policy.name, STR);
41    E_CONFIG_VAL(D, T, policy.vkbd.class, STR);
42    E_CONFIG_VAL(D, T, policy.vkbd.name, STR);
43    E_CONFIG_VAL(D, T, policy.vkbd.title, STR);
44    E_CONFIG_VAL(D, T, policy.vkbd.type, INT);
45    E_CONFIG_VAL(D, T, policy.vkbd.match.class, INT);
46    E_CONFIG_VAL(D, T, policy.vkbd.match.name, INT);
47    E_CONFIG_VAL(D, T, policy.vkbd.match.title, INT);
48    E_CONFIG_VAL(D, T, policy.vkbd.match.type, INT);
49    E_CONFIG_VAL(D, T, policy.indicator.class, STR);
50    E_CONFIG_VAL(D, T, policy.indicator.name, STR);
51    E_CONFIG_VAL(D, T, policy.indicator.title, STR);
52    E_CONFIG_VAL(D, T, policy.indicator.type, INT);
53    E_CONFIG_VAL(D, T, policy.indicator.match.class, INT);
54    E_CONFIG_VAL(D, T, policy.indicator.match.name, INT);
55    E_CONFIG_VAL(D, T, policy.indicator.match.title, INT);
56    E_CONFIG_VAL(D, T, policy.indicator.match.type, INT);
57    E_CONFIG_VAL(D, T, policy.softkey.class, STR);
58    E_CONFIG_VAL(D, T, policy.softkey.name, STR);
59    E_CONFIG_VAL(D, T, policy.softkey.title, STR);
60    E_CONFIG_VAL(D, T, policy.softkey.type, INT);
61    E_CONFIG_VAL(D, T, policy.softkey.match.class, INT);
62    E_CONFIG_VAL(D, T, policy.softkey.match.name, INT);
63    E_CONFIG_VAL(D, T, policy.softkey.match.title, INT);
64    E_CONFIG_VAL(D, T, policy.softkey.match.type, INT);
65    E_CONFIG_VAL(D, T, policy.home.class, STR);
66    E_CONFIG_VAL(D, T, policy.home.name, STR);
67    E_CONFIG_VAL(D, T, policy.home.title, STR);
68    E_CONFIG_VAL(D, T, policy.home.type, INT);
69    E_CONFIG_VAL(D, T, policy.home.match.class, INT);
70    E_CONFIG_VAL(D, T, policy.home.match.name, INT);
71    E_CONFIG_VAL(D, T, policy.home.match.title, INT);
72    E_CONFIG_VAL(D, T, policy.home.match.type, INT);
73    E_CONFIG_LIST(D, T, policy.zones, _il_conf_zone_edd);
74
75    /* attempt to load existing configuration */
76    _e_illume_cfg = e_config_domain_load("module.illume2", _il_conf_edd);
77
78    /* check version */
79    if ((_e_illume_cfg) && ((_e_illume_cfg->version >> 16) < IL_CONFIG_MAJOR))
80      _e_mod_illume_config_free();
81
82    /* create new config if we need to */
83    if (!_e_illume_cfg) _e_mod_illume_config_new();
84
85    /* setup category for config panel */
86    e_configure_registry_category_add("illume", 0, _("Illume"), NULL, "preferences-illume");
87
88    /* add config items to category */
89    e_configure_registry_generic_item_add("illume/policy", 0, _("Policy"), 
90                                          NULL, "preferences-profiles", 
91                                          e_mod_illume_config_policy_show);
92    e_configure_registry_generic_item_add("illume/animation", 0, _("Animation"), 
93                                          NULL, "preferences-transitions", 
94                                          e_mod_illume_config_animation_show);
95    e_configure_registry_generic_item_add("illume/windows", 0, _("Windows"), 
96                                          NULL, "preferences-winlist", 
97                                          e_mod_illume_config_windows_show);
98
99    return 1;
100 }
101
102 int 
103 e_mod_illume_config_shutdown(void) 
104 {
105    /* destroy config item entries */
106    e_configure_registry_item_del("illume/windows");
107    e_configure_registry_item_del("illume/animation");
108    e_configure_registry_item_del("illume/policy");
109
110    /* destroy config category */
111    e_configure_registry_category_del("illume");
112
113    /* free config structure */
114    _e_mod_illume_config_free();
115
116    /* free data descriptors */
117    E_CONFIG_DD_FREE(_il_conf_zone_edd);
118    E_CONFIG_DD_FREE(_il_conf_edd);
119
120    return 1;
121 }
122
123 int 
124 e_mod_illume_config_save(void) 
125 {
126    return e_config_domain_save("module.illume2", _il_conf_edd, _e_illume_cfg);
127 }
128
129 /* local functions */
130 static void 
131 _e_mod_illume_config_free(void) 
132 {
133    E_Illume_Config_Zone *cz;
134
135    /* check for config */
136    if (!_e_illume_cfg) return;
137
138    /* cleanup any stringshares */
139    if (_e_illume_cfg->policy.name) 
140      eina_stringshare_del(_e_illume_cfg->policy.name);
141    _e_illume_cfg->policy.name = NULL;
142
143    if (_e_illume_cfg->policy.vkbd.class) 
144      eina_stringshare_del(_e_illume_cfg->policy.vkbd.class);
145    _e_illume_cfg->policy.vkbd.class = NULL;
146    if (_e_illume_cfg->policy.vkbd.name) 
147      eina_stringshare_del(_e_illume_cfg->policy.vkbd.name);
148    _e_illume_cfg->policy.vkbd.name = NULL;
149    if (_e_illume_cfg->policy.vkbd.title) 
150      eina_stringshare_del(_e_illume_cfg->policy.vkbd.title);
151    _e_illume_cfg->policy.vkbd.title = NULL;
152
153    if (_e_illume_cfg->policy.indicator.class) 
154      eina_stringshare_del(_e_illume_cfg->policy.indicator.class);
155    _e_illume_cfg->policy.indicator.class = NULL;
156    if (_e_illume_cfg->policy.indicator.name) 
157      eina_stringshare_del(_e_illume_cfg->policy.indicator.name);
158    _e_illume_cfg->policy.indicator.name = NULL;
159    if (_e_illume_cfg->policy.indicator.title) 
160      eina_stringshare_del(_e_illume_cfg->policy.indicator.title);
161    _e_illume_cfg->policy.indicator.title = NULL;
162
163    if (_e_illume_cfg->policy.softkey.class) 
164      eina_stringshare_del(_e_illume_cfg->policy.softkey.class);
165    _e_illume_cfg->policy.softkey.class = NULL;
166    if (_e_illume_cfg->policy.softkey.name) 
167      eina_stringshare_del(_e_illume_cfg->policy.softkey.name);
168    _e_illume_cfg->policy.softkey.name = NULL;
169    if (_e_illume_cfg->policy.softkey.title) 
170      eina_stringshare_del(_e_illume_cfg->policy.softkey.title);
171    _e_illume_cfg->policy.softkey.title = NULL;
172
173    if (_e_illume_cfg->policy.home.class) 
174      eina_stringshare_del(_e_illume_cfg->policy.home.class);
175    _e_illume_cfg->policy.home.class = NULL;
176    if (_e_illume_cfg->policy.home.name) 
177      eina_stringshare_del(_e_illume_cfg->policy.home.name);
178    _e_illume_cfg->policy.home.name = NULL;
179    if (_e_illume_cfg->policy.home.title) 
180      eina_stringshare_del(_e_illume_cfg->policy.home.title);
181    _e_illume_cfg->policy.home.title = NULL;
182
183    /* free configured zones */
184    EINA_LIST_FREE(_e_illume_cfg->policy.zones, cz)
185      E_FREE(cz);
186
187    /* free config structure */
188    E_FREE(_e_illume_cfg);
189 }
190
191 static void 
192 _e_mod_illume_config_new(void) 
193 {
194    E_Illume_Config_Zone *cz;
195
196    /* create initial config */
197    _e_illume_cfg = E_NEW(E_Illume_Config, 1);
198    _e_illume_cfg->version = 0;
199    _e_illume_cfg->animation.vkbd.duration = 1000;
200    _e_illume_cfg->animation.quickpanel.duration = 1000;
201    _e_illume_cfg->policy.name = eina_stringshare_add("illume");
202
203    _e_illume_cfg->policy.vkbd.class = eina_stringshare_add("Virtual-Keyboard");
204    _e_illume_cfg->policy.vkbd.name = eina_stringshare_add("Virtual-Keyboard");
205    _e_illume_cfg->policy.vkbd.title = eina_stringshare_add("Virtual Keyboard");
206    _e_illume_cfg->policy.vkbd.type = ECORE_X_WINDOW_TYPE_NORMAL;
207    _e_illume_cfg->policy.vkbd.match.class = 0;
208    _e_illume_cfg->policy.vkbd.match.name = 1;
209    _e_illume_cfg->policy.vkbd.match.title = 1;
210    _e_illume_cfg->policy.vkbd.match.type = 0;
211
212    _e_illume_cfg->policy.indicator.class = 
213      eina_stringshare_add("Illume-Indicator");
214    _e_illume_cfg->policy.indicator.name = 
215      eina_stringshare_add("Illume-Indicator");
216    _e_illume_cfg->policy.indicator.title = 
217      eina_stringshare_add("Illume Indicator");
218    _e_illume_cfg->policy.indicator.type = ECORE_X_WINDOW_TYPE_DOCK;
219    _e_illume_cfg->policy.indicator.match.class = 0;
220    _e_illume_cfg->policy.indicator.match.name = 1;
221    _e_illume_cfg->policy.indicator.match.title = 1;
222    _e_illume_cfg->policy.indicator.match.type = 0;
223
224    _e_illume_cfg->policy.softkey.class = 
225      eina_stringshare_add("Illume-Softkey");
226    _e_illume_cfg->policy.softkey.name = 
227      eina_stringshare_add("Illume-Softkey");
228    _e_illume_cfg->policy.softkey.title = 
229      eina_stringshare_add("Illume Softkey");
230    _e_illume_cfg->policy.softkey.type = ECORE_X_WINDOW_TYPE_DOCK;
231    _e_illume_cfg->policy.softkey.match.class = 0;
232    _e_illume_cfg->policy.softkey.match.name = 1;
233    _e_illume_cfg->policy.softkey.match.title = 1;
234    _e_illume_cfg->policy.softkey.match.type = 0;
235
236    _e_illume_cfg->policy.home.class = eina_stringshare_add("Illume-Home");
237    _e_illume_cfg->policy.home.name = eina_stringshare_add("Illume-Home");
238    _e_illume_cfg->policy.home.title = eina_stringshare_add("Illume Home");
239    _e_illume_cfg->policy.home.type = ECORE_X_WINDOW_TYPE_NORMAL;
240    _e_illume_cfg->policy.home.match.class = 0;
241    _e_illume_cfg->policy.home.match.name = 1;
242    _e_illume_cfg->policy.home.match.title = 1;
243    _e_illume_cfg->policy.home.match.type = 0;
244
245    /* create config for initial zone */
246    cz = E_NEW(E_Illume_Config_Zone, 1);
247    cz->id = 0;
248    cz->mode.dual = 0;
249    cz->mode.side = 0;
250
251    /* add zone config to main config structure */
252    _e_illume_cfg->policy.zones = 
253      eina_list_append(_e_illume_cfg->policy.zones, cz);
254
255    /* add any new config variables here */
256    /* if ((_e_illume_cfg->version & 0xffff) < 1) */
257
258    _e_illume_cfg->version = ((IL_CONFIG_MAJOR << 16) | IL_CONFIG_MINOR);
259 }