remove e_comp_list(), deprecate all related functions for pending removal
[platform/upstream/enlightenment.git] / src / modules / policy_mobile / e_mod_config.c
1 #include "e_mod_main.h"
2
3 static void         _pol_conf_desk_add(Config *conf, E_Desk *desk);
4 static void         _pol_conf_desk_del(Config *conf, Config_Desk *d);
5 static Config_Desk *_pol_conf_desk_get(Config *conf, Config_Desk *d);
6
7 static void        *_pol_cfd_data_create(E_Config_Dialog *cfd);
8 static void         _pol_cfd_data_free(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
9 static int          _pol_cfd_data_basic_apply(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
10 static void         _pol_cfd_desk_list_update(E_Config_Dialog_Data *cfdata, E_Zone *zone);
11 static void         _pol_cfd_hook_zone_change(void *data, Evas_Object *obj);
12 static Evas_Object *_pol_cfd_data_basic_widgets_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata);
13
14 static void
15 _pol_conf_desk_add(Config *conf, E_Desk *desk)
16 {
17    Config_Desk *d;
18
19    d = E_NEW(Config_Desk, 1);
20    d->comp_num = desk->zone->comp->num;
21    d->zone_num = desk->zone->num;
22    d->x = desk->x;
23    d->y = desk->y;
24    d->enable = 1;
25
26    conf->desks = eina_list_append(conf->desks, d);
27 }
28
29 static void
30 _pol_conf_desk_del(Config *conf, Config_Desk *d)
31 {
32    conf->desks = eina_list_remove(conf->desks, d);
33    free(d);
34 }
35
36 static Config_Desk *
37 _pol_conf_desk_get(Config *conf, Config_Desk *d)
38 {
39    Eina_List *l;
40    Config_Desk *d2;
41
42    EINA_LIST_FOREACH(conf->desks, l, d2)
43      {
44         if ((d2->comp_num == d->comp_num) &&
45             (d2->zone_num == d->zone_num) &&
46             (d2->x == d->x) && (d2->y == d->y))
47           {
48              return d2;
49           }
50      }
51
52    return NULL;
53 }
54
55 static void *
56 _pol_cfd_data_create(E_Config_Dialog *cfd)
57 {
58    E_Config_Dialog_Data *cfdata = NULL;
59
60    cfdata = E_NEW(E_Config_Dialog_Data, 1);
61    cfdata->conf = E_NEW(Config, 1);
62    cfdata->conf->launcher.title = eina_stringshare_ref(_pol_mod->conf->launcher.title);
63    cfdata->conf->launcher.clas = eina_stringshare_ref(_pol_mod->conf->launcher.clas);
64    cfdata->conf->launcher.type = _pol_mod->conf->launcher.type;
65    cfdata->conf->use_softkey = _pol_mod->conf->use_softkey;
66    cfdata->conf->softkey_size = _pol_mod->conf->softkey_size;
67
68    _pol_mod->conf_dialog = cfd;
69
70    return cfdata;
71 }
72
73 static void
74 _pol_cfd_data_free(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
75 {
76    _pol_mod->conf_dialog = NULL;
77    E_FREE_LIST(cfdata->conf->desks, free);
78    eina_stringshare_del(cfdata->conf->launcher.title);
79    eina_stringshare_del(cfdata->conf->launcher.clas);
80    free(cfdata->conf);
81    free(cfdata);
82 }
83
84 static int
85 _pol_cfd_data_basic_apply(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
86 {
87    E_Zone *zone;
88    E_Desk *desk;
89    Pol_Softkey *softkey;
90    Pol_Desk *pd;
91    Config_Desk *d, *d2;
92    Eina_Bool changed = EINA_FALSE;
93    const Eina_List *l;
94    Eina_Inlist *il;
95    Eina_Iterator *it;
96
97    if (_pol_mod->conf->use_softkey != cfdata->conf->use_softkey)
98      {
99         _pol_mod->conf->use_softkey = cfdata->conf->use_softkey;
100         if (_pol_mod->conf->use_softkey)
101           {
102              it = eina_hash_iterator_data_new(hash_pol_desks);
103              while (eina_iterator_next(it, (void **)&pd))
104                {
105                   softkey = e_mod_pol_softkey_get(pd->zone);
106                   if (!softkey)
107                     softkey = e_mod_pol_softkey_add(pd->zone);
108                   if (e_desk_current_get(pd->zone) == pd->desk)
109                     e_mod_pol_softkey_show(softkey);
110                }
111              eina_iterator_free(it);
112           }
113         else
114           {
115              EINA_INLIST_FOREACH_SAFE(_pol_mod->softkeys, il, softkey)
116                e_mod_pol_softkey_del(softkey);
117           }
118
119         changed = EINA_TRUE;
120      }
121
122    if (_pol_mod->conf->softkey_size != cfdata->conf->softkey_size)
123      {
124         _pol_mod->conf->softkey_size = cfdata->conf->softkey_size;
125         if (_pol_mod->conf->use_softkey)
126           {
127              EINA_INLIST_FOREACH(_pol_mod->softkeys, softkey)
128                e_mod_pol_softkey_update(softkey);
129           }
130         changed = EINA_TRUE;
131      }
132
133    EINA_LIST_FOREACH(cfdata->conf->desks, l, d)
134      {
135         zone = e_comp_zone_number_get(e_comp, d->zone_num);
136         desk = e_desk_at_xy_get(zone, d->x, d->y);
137         if (!desk) continue;
138
139         d2 = _pol_conf_desk_get(_pol_mod->conf, d);
140         if (d2)
141           {
142              /* disable policy for this desktop */
143              if (d2->enable != d->enable)
144                {
145                   pd = eina_hash_find(hash_pol_desks, &desk);
146                   if (pd) e_mod_pol_desk_del(pd);
147                   _pol_conf_desk_del(_pol_mod->conf, d2);
148                   changed = EINA_TRUE;
149                }
150           }
151         else
152           {
153              /* apply policy for all clients in this desk,
154               * and add desk to configuration list and desk hash */
155              if (d->enable)
156                {
157                   e_mod_pol_desk_add(desk);
158                   _pol_conf_desk_add(_pol_mod->conf, desk);
159                   changed = EINA_TRUE;
160                }
161           }
162      }
163
164    if (changed)
165      e_config_save_queue();
166
167    return 1;
168 }
169
170 static void
171 _pol_cfd_desk_list_update(E_Config_Dialog_Data *cfdata, E_Zone *zone)
172 {
173    Evas_Object *o, *ch;
174    Evas *evas;
175    E_Desk *desk;
176    Config_Desk *d, *d2;
177    int i, n;
178
179    evas = evas_object_evas_get(cfdata->o_list);
180    evas_object_del(cfdata->o_desks);
181    E_FREE_LIST(cfdata->conf->desks, free);
182
183    o = e_widget_list_add(evas, 1, 0);
184    cfdata->o_desks = o;
185
186    n = zone->desk_y_count * zone->desk_x_count;
187    for (i = 0; i < n; i++)
188      {
189         desk = zone->desks[i];
190
191         d = E_NEW(Config_Desk, 1);
192         d->comp_num = zone->comp->num;
193         d->zone_num = zone->num;
194         d->x = desk->x;
195         d->y = desk->y;
196         d->enable = 0;
197
198         d2 = _pol_conf_desk_get(_pol_mod->conf, d);
199         if (d2)
200           d->enable = d2->enable;
201
202         ch = e_widget_check_add(evas, desk->name, &d->enable);
203         e_widget_list_object_append(o, ch, 1, 1, 0.5);
204
205         cfdata->conf->desks = eina_list_append(cfdata->conf->desks, d);
206      }
207
208    e_widget_list_object_append(cfdata->o_list, o, 1, 1, 0.5);
209 }
210
211 static void
212 _pol_cfd_hook_zone_change(void *data, Evas_Object *obj)
213 {
214    E_Config_Dialog_Data *cfdata;
215    E_Zone *zone;
216    int n;
217
218    cfdata = data;
219    n = e_widget_ilist_selected_get(obj);
220    zone = e_widget_ilist_nth_data_get(obj, n);
221    if (zone)
222      _pol_cfd_desk_list_update(cfdata, zone);
223 }
224
225 static Evas_Object *
226 _pol_cfd_data_basic_widgets_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata)
227 {
228    Evas_Object *base, *fl, *lb, *lo, *o;
229    E_Comp *comp;
230    E_Zone *zone;
231    Eina_List *l;
232
233    comp = e_comp_get(NULL);
234
235    base = e_widget_list_add(evas, 0, 0);
236
237    fl = e_widget_framelist_add(evas, _("Softkey"), 0);
238    o = e_widget_check_add(evas, _("Use softkey for navigation among the windows"),
239                           &cfdata->conf->use_softkey);
240    e_widget_framelist_object_append(fl, o);
241    o = e_widget_label_add(evas, _("Icon Size"));
242    e_widget_framelist_object_append(fl, o);
243    o = e_widget_slider_add(evas, 1, 0, "%1.0f", 32, 256, 1, 0, NULL,
244                            &(cfdata->conf->softkey_size), 150);
245    e_widget_framelist_object_append(fl, o);
246    e_widget_list_object_append(base, fl, 1, 1, 0.5);
247
248    fl = e_widget_framelist_add(evas, _("Virtual Desktops"), 0);
249    lb = e_widget_label_add(evas, _("Enable mobile policy per desktop"));
250    e_widget_framelist_object_append(fl, lb);
251
252    lo = e_widget_list_add(evas, 0, 1);
253    cfdata->o_list = lo;
254    o = e_widget_ilist_add(evas, 0, 0, NULL);
255    e_widget_ilist_multi_select_set(o, EINA_FALSE);
256    e_widget_size_min_set(o, 100, 100);
257    e_widget_on_change_hook_set(o, _pol_cfd_hook_zone_change, cfdata);
258    EINA_LIST_REVERSE_FOREACH(comp->zones, l, zone)
259      e_widget_ilist_append(o, NULL, zone->name, NULL, zone, NULL);
260    e_widget_ilist_go(o);
261    e_widget_ilist_selected_set(o, 0);
262    e_widget_list_object_append(lo, o, 1, 1, 0.5);
263
264    /* update virtual desktops of first zone */
265    zone = eina_list_data_get(comp->zones);
266    _pol_cfd_desk_list_update(cfdata, zone);
267
268    e_widget_framelist_object_append(fl, lo);
269    e_widget_list_object_append(base, fl, 1, 1, 0.5);
270
271    return base;
272 }
273
274 void
275 e_mod_pol_conf_init(Mod *mod)
276 {
277    E_Comp *comp;
278    E_Zone *zone;
279    E_Desk *desk;
280    Config *conf;
281
282    mod->conf_desk_edd = E_CONFIG_DD_NEW("Policy_Mobile_Config_Desk", Config_Desk);
283 #undef T
284 #undef D
285 #define T Config_Desk
286 #define D mod->conf_desk_edd
287    E_CONFIG_VAL(D, T, comp_num, INT);
288    E_CONFIG_VAL(D, T, zone_num, UINT);
289    E_CONFIG_VAL(D, T, x, INT);
290    E_CONFIG_VAL(D, T, y, INT);
291    E_CONFIG_VAL(D, T, enable, INT);
292
293    mod->conf_edd = E_CONFIG_DD_NEW("Policy_Mobile_Config", Config);
294 #undef T
295 #undef D
296 #define T Config
297 #define D mod->conf_edd
298    E_CONFIG_VAL(D, T, launcher.title, STR);
299    E_CONFIG_VAL(D, T, launcher.clas, STR);
300    E_CONFIG_VAL(D, T, launcher.type, UINT);
301    E_CONFIG_LIST(D, T, desks, mod->conf_desk_edd);
302    E_CONFIG_VAL(D, T, use_softkey, INT);
303    E_CONFIG_VAL(D, T, softkey_size, INT);
304
305 #undef T
306 #undef D
307
308    mod->conf = e_config_domain_load("module.policy-mobile", mod->conf_edd);
309    if (!mod->conf)
310      {
311         conf = E_NEW(Config, 1);
312         mod->conf = conf;
313         conf->launcher.title = eina_stringshare_add("Illume Home");
314         conf->launcher.clas = eina_stringshare_add("Illume-Home");
315         conf->launcher.type = E_WINDOW_TYPE_NORMAL;
316         conf->use_softkey = 1;
317         conf->softkey_size = 42;
318
319         comp = e_comp_get(NULL);
320         zone = e_zone_current_get(comp);
321         desk = e_desk_current_get(zone);
322         _pol_conf_desk_add(conf, desk);
323      }
324 }
325
326 void
327 e_mod_pol_conf_shutdown(Mod *mod)
328 {
329    Config *conf;
330
331    if (mod->conf)
332      {
333         conf = mod->conf;
334         E_FREE_LIST(conf->desks, free);
335         eina_stringshare_del(conf->launcher.title);
336         eina_stringshare_del(conf->launcher.clas);
337         free(mod->conf);
338      }
339
340    E_CONFIG_DD_FREE(mod->conf_desk_edd);
341    E_CONFIG_DD_FREE(mod->conf_edd);
342 }
343
344 Config_Desk *
345 e_mod_pol_conf_desk_get_by_nums(Config *conf, unsigned int comp_num, unsigned int zone_num, int x, int y)
346 {
347    Eina_List *l;
348    Config_Desk *d2;
349
350    EINA_LIST_FOREACH(conf->desks, l, d2)
351      {
352         if ((d2->comp_num == comp_num) &&
353             (d2->zone_num == zone_num) &&
354             (d2->x == x) && (d2->y == y))
355           {
356              return d2;
357           }
358      }
359
360    return NULL;
361 }
362
363 E_Config_Dialog *
364 e_int_config_pol_mobile(Evas_Object *parent EINA_UNUSED, const char *params EINA_UNUSED)
365 {
366    E_Config_Dialog *cfd;
367    E_Config_Dialog_View *v;
368    char buf[PATH_MAX];
369
370    if (e_config_dialog_find("E", "windows/policy-mobile"))
371      return NULL;
372
373    v = E_NEW(E_Config_Dialog_View, 1);
374    v->create_cfdata = _pol_cfd_data_create;
375    v->free_cfdata = _pol_cfd_data_free;
376    v->basic.apply_cfdata = _pol_cfd_data_basic_apply;
377    v->basic.create_widgets = _pol_cfd_data_basic_widgets_create;
378
379    snprintf(buf, sizeof(buf), "%s/e-module-policy-mobile.edj",
380             e_module_dir_get(_pol_mod->module));
381
382    cfd = e_config_dialog_new(NULL, _("Mobile Policy Configuration"), "E",
383                              "windows/policy-mobile", buf, 0, v, NULL);
384    return cfd;
385 }