1 #include "e.h"
2 
3 #define TEXT_NO_PARAMS           _("<None>")
4 
5 struct _E_Config_Dialog_Data
6 {
7    Evas *evas;
8    struct
9    {
10       Eina_List *signal;
11    } binding;
12    struct
13    {
14       const char *binding, *action;
15       char       *params;
16       const char *cur;
17       int         button;
18       int         cur_act;
19       const char *signal;
20       const char *source;
21 
22       E_Dialog   *dia;
23       char *dia_source;
24       char *dia_signal;
25    } locals;
26    struct
27    {
28       Evas_Object *o_add, *o_del, *o_del_all;
29       Evas_Object *o_binding_list, *o_action_list;
30       Evas_Object *o_params, *o_selector;
31    } gui;
32 
33    const char      *params;
34 
35    int              fullscreen_flip;
36    int              multiscreen_flip;
37 
38    E_Config_Dialog *cfd;
39 };
40 
41 static E_Config_Binding_Signal *
_signal_binding_copy(E_Config_Binding_Signal * bi)42 _signal_binding_copy(E_Config_Binding_Signal *bi)
43 {
44    E_Config_Binding_Signal *bi2;
45    if (!bi) return NULL;
46 
47    if (!bi->signal) return NULL;
48    if (!bi->source) return NULL;
49    bi2 = E_NEW(E_Config_Binding_Signal, 1);
50    bi2->context = bi->context;
51    bi2->modifiers = bi->modifiers;
52    bi2->any_mod = bi->any_mod;
53    bi2->action = (bi->action && bi->action[0]) ? eina_stringshare_ref(bi->action) : NULL;
54    bi2->params = (bi->params && bi->params[0]) ? eina_stringshare_ref(bi->params) : NULL;
55    bi2->signal = eina_stringshare_ref(bi->signal);
56    bi2->source = eina_stringshare_ref(bi->source);
57    return bi2;
58 }
59 
60 static void
_signal_binding_free(E_Config_Binding_Signal * bi)61 _signal_binding_free(E_Config_Binding_Signal *bi)
62 {
63    if (!bi) return;
64    eina_stringshare_del(bi->action);
65    eina_stringshare_del(bi->params);
66    eina_stringshare_del(bi->signal);
67    eina_stringshare_del(bi->source);
68    free(bi);
69 }
70 
71 
72 static void
_auto_apply_changes(E_Config_Dialog_Data * cfdata)73 _auto_apply_changes(E_Config_Dialog_Data *cfdata)
74 {
75    int n, g, a, ok;
76    E_Config_Binding_Signal *bi;
77    E_Action_Group *actg;
78    E_Action_Description *actd;
79 
80    if ((!cfdata->locals.cur) || (!cfdata->locals.cur[0]) ||
81        (!cfdata->locals.action) || (!cfdata->locals.action[0])) return;
82 
83    if (sscanf(cfdata->locals.cur, "s%d", &n) != 1)
84      return;
85    if (sscanf(cfdata->locals.action, "%d %d", &g, &a) != 2)
86      return;
87 
88    bi = eina_list_nth(cfdata->binding.signal, n);
89    if (!bi) return;
90 
91    actg = eina_list_nth(e_action_groups_get(), g);
92    if (!actg) return;
93    actd = eina_list_nth(actg->acts, a);
94    if (!actd) return;
95 
96    eina_stringshare_del(bi->action);
97    bi->action = NULL;
98 
99    if (actd->act_cmd) bi->action = eina_stringshare_add(actd->act_cmd);
100 
101    eina_stringshare_del(bi->params);
102    bi->params = NULL;
103 
104    if (actd->act_params)
105      bi->params = eina_stringshare_add(actd->act_params);
106    else
107      {
108         ok = 1;
109         if (cfdata->locals.params)
110           {
111              if (!strcmp(cfdata->locals.params, TEXT_NO_PARAMS))
112                ok = 0;
113 
114              if ((actd->param_example) && (!strcmp(cfdata->locals.params, actd->param_example)))
115                ok = 0;
116           }
117         else
118           ok = 0;
119 
120         if (ok)
121           bi->params = eina_stringshare_add(cfdata->locals.params);
122      }
123 }
124 
125 static void
_fill_data(E_Config_Dialog_Data * cfdata)126 _fill_data(E_Config_Dialog_Data *cfdata)
127 {
128    E_Config_Binding_Signal *bi, *bi2;
129    Eina_List *l;
130 
131    cfdata->locals.params = strdup("");
132    cfdata->locals.action = eina_stringshare_add("");
133    cfdata->locals.binding = eina_stringshare_add("");
134    cfdata->locals.signal = eina_stringshare_add("");
135    cfdata->locals.source = eina_stringshare_add("");
136    cfdata->locals.cur = NULL;
137    cfdata->locals.dia = NULL;
138    cfdata->binding.signal = NULL;
139 
140    EINA_LIST_FOREACH(e_bindings->signal_bindings, l, bi)
141      {
142         if (!bi) continue;
143         bi2 = _signal_binding_copy(bi);
144         cfdata->binding.signal = eina_list_append(cfdata->binding.signal, bi2);
145      }
146 }
147 
148 static void *
_create_data(E_Config_Dialog * cfd)149 _create_data(E_Config_Dialog *cfd)
150 {
151    E_Config_Dialog_Data *cfdata;
152 
153    cfdata = E_NEW(E_Config_Dialog_Data, 1);
154    cfdata->cfd = cfd;
155    _fill_data(cfdata);
156 
157    return cfdata;
158 }
159 
160 static void
_free_data(E_Config_Dialog * cfd EINA_UNUSED,E_Config_Dialog_Data * cfdata)161 _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
162 {
163    E_FREE_LIST(cfdata->binding.signal, _signal_binding_free);
164 
165    eina_stringshare_del(cfdata->locals.cur);
166    eina_stringshare_del(cfdata->params);
167    eina_stringshare_del(cfdata->locals.binding);
168    eina_stringshare_del(cfdata->locals.action);
169    eina_stringshare_del(cfdata->locals.signal);
170    eina_stringshare_del(cfdata->locals.source);
171 
172    if (cfdata->locals.dia) e_object_del(E_OBJECT(cfdata->locals.dia));
173 
174    free(cfdata->locals.params);
175    E_FREE(cfdata);
176 }
177 
178 
179 static void
_update_action_params(E_Config_Dialog_Data * cfdata)180 _update_action_params(E_Config_Dialog_Data *cfdata)
181 {
182    int g, a, b;
183    E_Action_Group *actg;
184    E_Action_Description *actd;
185    E_Config_Binding_Signal *bi;
186    const char *action, *params;
187 
188 #define SIGNAL_EXAMPLE_PARAMS                                         \
189   if ((!actd->param_example) || (!actd->param_example[0]))          \
190     e_widget_entry_text_set(cfdata->gui.o_params, TEXT_NO_PARAMS);  \
191   else                                                              \
192     e_widget_entry_text_set(cfdata->gui.o_params, actd->param_example)
193 
194    if ((!cfdata->locals.action) || (!cfdata->locals.action[0]))
195      {
196         e_widget_disabled_set(cfdata->gui.o_params, 1);
197         e_widget_entry_clear(cfdata->gui.o_params);
198         return;
199      }
200    if (sscanf(cfdata->locals.action, "%d %d", &g, &a) != 2)
201      return;
202 
203    actg = eina_list_nth(e_action_groups_get(), g);
204    if (!actg) return;
205    actd = eina_list_nth(actg->acts, a);
206    if (!actd) return;
207 
208    if (actd->act_params)
209      {
210         e_widget_disabled_set(cfdata->gui.o_params, 1);
211         e_widget_entry_text_set(cfdata->gui.o_params, actd->act_params);
212         return;
213      }
214 
215    if ((!cfdata->locals.cur) || (!cfdata->locals.cur[0]))
216      {
217         e_widget_disabled_set(cfdata->gui.o_params, 1);
218         SIGNAL_EXAMPLE_PARAMS;
219         return;
220      }
221 
222    if (!actd->editable)
223      e_widget_disabled_set(cfdata->gui.o_params, 1);
224    else
225      e_widget_disabled_set(cfdata->gui.o_params, 0);
226 
227    if (cfdata->locals.cur[0] == 's')
228      {
229         if (sscanf(cfdata->locals.cur, "s%d", &b) != 1)
230           {
231              e_widget_disabled_set(cfdata->gui.o_params, 1);
232              SIGNAL_EXAMPLE_PARAMS;
233              return;
234           }
235 
236         bi = eina_list_nth(cfdata->binding.signal, b);
237         if (!bi)
238           {
239              e_widget_disabled_set(cfdata->gui.o_params, 1);
240              SIGNAL_EXAMPLE_PARAMS;
241              return;
242           }
243         action = bi->action;
244         params = bi->params;
245      }
246    else
247      {
248         e_widget_disabled_set(cfdata->gui.o_params, 1);
249         SIGNAL_EXAMPLE_PARAMS;
250         return;
251      }
252 
253    if (action)
254      {
255         if (!strcmp(action, actd->act_cmd))
256           {
257              if ((!params) || (!params[0]))
258                SIGNAL_EXAMPLE_PARAMS;
259              else
260                e_widget_entry_text_set(cfdata->gui.o_params, params);
261           }
262         else
263           SIGNAL_EXAMPLE_PARAMS;
264      }
265    else
266      SIGNAL_EXAMPLE_PARAMS;
267 }
268 
269 static void
_action_change_cb(void * data)270 _action_change_cb(void *data)
271 {
272    E_Config_Dialog_Data *cfdata;
273 
274    cfdata = data;
275    _update_action_params(cfdata);
276 }
277 
278 
279 static int
_signal_binding_sort_cb(E_Config_Binding_Signal * a,E_Config_Binding_Signal * b)280 _signal_binding_sort_cb(E_Config_Binding_Signal *a, E_Config_Binding_Signal *b)
281 {
282    int ret;
283 
284    ret = strcmp(a->source, b->source);
285    if (ret) return ret;
286    return strcmp(a->signal, b->signal);
287 }
288 
289 
290 static void
_update_buttons(E_Config_Dialog_Data * cfdata)291 _update_buttons(E_Config_Dialog_Data *cfdata)
292 {
293    if (e_widget_ilist_count(cfdata->gui.o_binding_list))
294      e_widget_disabled_set(cfdata->gui.o_del_all, 0);
295    else
296      e_widget_disabled_set(cfdata->gui.o_del_all, 1);
297 
298    if (!cfdata->locals.cur)
299      {
300         e_widget_disabled_set(cfdata->gui.o_del, 1);
301         return;
302      }
303    e_widget_disabled_set(cfdata->gui.o_del, 0);
304 }
305 
306 
307 static void
_find_signal_binding_action(const char * action,const char * params,int * g,int * a,int * n)308 _find_signal_binding_action(const char *action, const char *params, int *g, int *a, int *n)
309 {
310    Eina_List *l, *l2;
311    int gg = -1, aa = -1, nn = -1, found;
312    E_Action_Group *actg;
313    E_Action_Description *actd;
314 
315    if (g) *g = -1;
316    if (a) *a = -1;
317    if (n) *n = -1;
318 
319    found = 0;
320    for (l = e_action_groups_get(), gg = 0, nn = 0; l; l = l->next, gg++)
321      {
322         actg = l->data;
323 
324         for (l2 = actg->acts, aa = 0; l2; l2 = l2->next, aa++)
325           {
326              actd = l2->data;
327              if (!strcmp((!action ? "" : action), (!actd->act_cmd ? "" : actd->act_cmd)))
328                {
329                   if (!params || !params[0])
330                     {
331                        if ((!actd->act_params) || (!actd->act_params[0]))
332                          {
333                             if (g) *g = gg;
334                             if (a) *a = aa;
335                             if (n) *n = nn;
336                             return;
337                          }
338                        else
339                          continue;
340                     }
341                   else
342                     {
343                        if ((!actd->act_params) || (!actd->act_params[0]))
344                          {
345                             if (g) *g = gg;
346                             if (a) *a = aa;
347                             if (n) *n = nn;
348                             found = 1;
349                          }
350                        else
351                          {
352                             if (!strcmp(params, actd->act_params))
353                               {
354                                  if (g) *g = gg;
355                                  if (a) *a = aa;
356                                  if (n) *n = nn;
357                                  return;
358                               }
359                          }
360                     }
361                }
362              nn++;
363           }
364         if (found) break;
365      }
366 
367    if (!found)
368      {
369         if (g) *g = -1;
370         if (a) *a = -1;
371         if (n) *n = -1;
372      }
373 }
374 
375 static void
_update_action_list(E_Config_Dialog_Data * cfdata)376 _update_action_list(E_Config_Dialog_Data *cfdata)
377 {
378    E_Config_Binding_Signal *bi;
379    int j = -1, i, n;
380    const char *action, *params;
381 
382    if (!cfdata->locals.cur) return;
383 
384    if (cfdata->locals.cur[0] == 's')
385      {
386         if (sscanf(cfdata->locals.cur, "s%d", &n) != 1)
387           return;
388 
389         bi = eina_list_nth(cfdata->binding.signal, n);
390         if (!bi)
391           {
392              e_widget_ilist_unselect(cfdata->gui.o_action_list);
393              e_widget_entry_clear(cfdata->gui.o_params);
394              e_widget_disabled_set(cfdata->gui.o_params, 1);
395              return;
396           }
397         action = bi->action;
398         params = bi->params;
399      }
400    else
401      return;
402 
403    _find_signal_binding_action(action, params, NULL, NULL, &j);
404 
405    if (j >= 0)
406      {
407         for (i = 0; i < e_widget_ilist_count(cfdata->gui.o_action_list); i++)
408           {
409              if (i > j) break;
410              if (e_widget_ilist_nth_is_header(cfdata->gui.o_action_list, i)) j++;
411           }
412      }
413 
414    if (j >= 0)
415      {
416         if (j == e_widget_ilist_selected_get(cfdata->gui.o_action_list))
417           _update_action_params(cfdata);
418         else
419           e_widget_ilist_selected_set(cfdata->gui.o_action_list, j);
420      }
421    else
422      {
423         e_widget_ilist_unselect(cfdata->gui.o_action_list);
424         eina_stringshare_del(cfdata->locals.action);
425         cfdata->locals.action = eina_stringshare_add("");
426         e_widget_entry_clear(cfdata->gui.o_params);
427      }
428 }
429 
430 static void
_binding_change_cb(void * data)431 _binding_change_cb(void *data)
432 {
433    E_Config_Dialog_Data *cfdata;
434 
435    cfdata = data;
436 
437    _auto_apply_changes(cfdata);
438    if (cfdata->locals.cur) eina_stringshare_del(cfdata->locals.cur);
439    cfdata->locals.cur = NULL;
440 
441    if ((!cfdata->locals.binding) || (!cfdata->locals.binding[0])) return;
442 
443    cfdata->locals.cur = eina_stringshare_ref(cfdata->locals.binding);
444 
445    _update_buttons(cfdata);
446    _update_action_list(cfdata);
447 }
448 
449 
450 static int
_basic_apply_data(E_Config_Dialog * cfd EINA_UNUSED,E_Config_Dialog_Data * cfdata)451 _basic_apply_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
452 {
453    Eina_List *l;
454    E_Config_Binding_Signal *bi, *bi2;
455 
456    _auto_apply_changes(cfdata);
457    E_FREE_LIST(e_bindings->signal_bindings, _signal_binding_free);
458    EINA_LIST_FOREACH(cfdata->binding.signal, l, bi2)
459      {
460         bi = _signal_binding_copy(bi2);
461         e_bindings->signal_bindings = eina_list_append(e_bindings->signal_bindings, bi);
462      }
463    e_bindings_signal_reset();
464 
465    e_config_save_queue();
466 
467    return 1;
468 }
469 
470 static void
_update_signal_binding_list(E_Config_Dialog_Data * cfdata)471 _update_signal_binding_list(E_Config_Dialog_Data *cfdata)
472 {
473    int i = 0;
474    char b2[64];
475    Eina_List *l;
476    const char *source = NULL;
477    E_Config_Binding_Signal *bi;
478 
479    evas_event_freeze(evas_object_evas_get(cfdata->gui.o_binding_list));
480    edje_freeze();
481    e_widget_ilist_freeze(cfdata->gui.o_binding_list);
482 
483    e_widget_ilist_clear(cfdata->gui.o_binding_list);
484    e_widget_ilist_go(cfdata->gui.o_binding_list);
485 
486    if (cfdata->binding.signal)
487      cfdata->binding.signal = eina_list_sort(cfdata->binding.signal, 0, (Eina_Compare_Cb)_signal_binding_sort_cb);
488 
489    EINA_LIST_FOREACH(cfdata->binding.signal, l, bi)
490      {
491         if (source != bi->source)
492           e_widget_ilist_header_append(cfdata->gui.o_binding_list, NULL, bi->source);
493 
494         snprintf(b2, sizeof(b2), "s%d", i);
495         e_widget_ilist_append(cfdata->gui.o_binding_list, NULL, bi->signal, _binding_change_cb, cfdata, b2);
496         i++;
497         source = bi->source;
498      }
499    e_widget_ilist_go(cfdata->gui.o_binding_list);
500 
501    e_widget_ilist_thaw(cfdata->gui.o_binding_list);
502    edje_thaw();
503    evas_event_thaw(evas_object_evas_get(cfdata->gui.o_binding_list));
504 
505    if (eina_list_count(cfdata->binding.signal))
506      e_widget_disabled_set(cfdata->gui.o_del_all, 0);
507    else
508      e_widget_disabled_set(cfdata->gui.o_del_all, 1);
509 }
510 
511 static void
_fill_actions_list(E_Config_Dialog_Data * cfdata)512 _fill_actions_list(E_Config_Dialog_Data *cfdata)
513 {
514    char buf[1024];
515    Eina_List *l, *l2;
516    E_Action_Group *actg;
517    E_Action_Description *actd;
518    int g, a;
519 
520    evas_event_freeze(evas_object_evas_get(cfdata->gui.o_action_list));
521    edje_freeze();
522    e_widget_ilist_freeze(cfdata->gui.o_action_list);
523 
524    e_widget_ilist_clear(cfdata->gui.o_action_list);
525    for (l = e_action_groups_get(), g = 0; l; l = l->next, g++)
526      {
527         actg = l->data;
528 
529         if (!actg->acts) continue;
530 
531         e_widget_ilist_header_append(cfdata->gui.o_action_list, NULL, _(actg->act_grp));
532 
533         for (l2 = actg->acts, a = 0; l2; l2 = l2->next, a++)
534           {
535              actd = l2->data;
536 
537              snprintf(buf, sizeof(buf), "%d %d", g, a);
538              e_widget_ilist_append(cfdata->gui.o_action_list, NULL, _(actd->act_name),
539                                    _action_change_cb, cfdata, buf);
540           }
541      }
542    e_widget_ilist_go(cfdata->gui.o_action_list);
543    e_widget_ilist_thaw(cfdata->gui.o_action_list);
544    edje_thaw();
545    evas_event_thaw(evas_object_evas_get(cfdata->gui.o_action_list));
546 }
547 
548 static void
_signal_add_cb_ok(void * data,E_Dialog * dia)549 _signal_add_cb_ok(void *data, E_Dialog *dia)
550 {
551    E_Config_Dialog_Data *cfdata = data;
552    E_Config_Binding_Signal *bi;
553    Eina_List *l;
554    const char *sig, *src;
555 
556 
557    sig = eina_stringshare_add(cfdata->locals.dia_signal);
558    src = eina_stringshare_add(cfdata->locals.dia_source);
559    if ((!sig) || (!src) || (!sig[0]) || (!src[0]))
560      {
561         e_util_dialog_show(_("Signal Binding Error"), _("Signal and Source must NOT be blank!"));
562         e_object_del(E_OBJECT(dia));
563         return;
564      }
565    EINA_LIST_FOREACH(cfdata->binding.signal, l, bi)
566      {
567         if ((sig == bi->signal) && (src == bi->source))
568           {
569              eina_stringshare_del(sig);
570              eina_stringshare_del(src);
571              e_util_dialog_show(_("Signal Binding Error"),
572                                 _("The signal and source that you entered are already used by<ps/>"
573                                   "<hilight>%s</hilight> action.<ps/>"),
574                                 bi->action ?: _("Unknown"));
575              e_object_del(E_OBJECT(dia));
576              return;
577           }
578      }
579 
580    bi = E_NEW(E_Config_Binding_Signal, 1);
581    bi->context = 2;
582    bi->any_mod = 1;
583    bi->signal = sig;
584    bi->source = src;
585    cfdata->binding.signal = eina_list_append(cfdata->binding.signal, bi);
586    _update_signal_binding_list(cfdata);
587 
588    e_object_del(E_OBJECT(dia));
589 }
590 
591 static void
_signal_add_cb_cancel(void * data EINA_UNUSED,E_Dialog * dia)592 _signal_add_cb_cancel(void *data EINA_UNUSED, E_Dialog *dia)
593 {
594    e_object_del(E_OBJECT(dia));
595 }
596 
597 static void
_signal_add_del(void * data)598 _signal_add_del(void *data)
599 {
600    E_Dialog *dia = data;
601    E_Config_Dialog_Data *cfdata;
602 
603    if (!dia->data) return;
604    cfdata = dia->data;
605    cfdata->locals.dia = NULL;
606    E_FREE(cfdata->locals.dia_signal);
607    E_FREE(cfdata->locals.dia_source);
608 }
609 
610 static void
_signal_add_show(E_Config_Dialog_Data * cfdata)611 _signal_add_show(E_Config_Dialog_Data *cfdata)
612 {
613    Evas_Object *o, *obg, *ol, *entry;
614    Evas *evas;
615    int w, h;
616 
617    if (cfdata->locals.dia) return;
618 
619    cfdata->locals.dia = e_dialog_new(cfdata->cfd->dia->win, "E", "_signalbind_new_dialog");
620    e_dialog_resizable_set(cfdata->locals.dia, 1);
621    e_dialog_title_set(cfdata->locals.dia, _("Add Signal Binding"));
622    e_dialog_icon_set(cfdata->locals.dia, "enlightenment/signals", 48);
623    e_dialog_button_add(cfdata->locals.dia, _("OK"), NULL, _signal_add_cb_ok, cfdata);
624    e_dialog_button_add(cfdata->locals.dia, _("Cancel"), NULL, _signal_add_cb_cancel, cfdata);
625    e_object_del_attach_func_set(E_OBJECT(cfdata->locals.dia), _signal_add_del);
626    cfdata->locals.dia->data = cfdata;
627    elm_win_center(cfdata->locals.dia->win, 1, 1);
628 
629    evas = evas_object_evas_get(cfdata->locals.dia->win);
630    obg = e_widget_list_add(evas, 1, 0);
631 
632    ol = e_widget_framelist_add(evas, _("Source:"), 0);
633    entry = o = e_widget_entry_add(cfdata->locals.dia->win, &cfdata->locals.dia_source, NULL, NULL, NULL);
634    e_widget_framelist_object_append(ol, o);
635    e_widget_list_object_append(obg, ol, 1, 0, 0.5);
636 
637    ol = e_widget_framelist_add(evas, _("Signal:"), 0);
638    o = e_widget_entry_add(cfdata->locals.dia->win, &cfdata->locals.dia_signal, NULL, NULL, NULL);
639    e_widget_framelist_object_append(ol, o);
640    e_widget_list_object_append(obg, ol, 1, 0, 0.5);
641 
642    e_widget_size_min_get(obg, &w, &h);
643    e_dialog_content_set(cfdata->locals.dia, obg, MAX(w, 200), MAX(h, 100));
644 
645    e_dialog_show(cfdata->locals.dia);
646    e_widget_focus_set(entry, 1);
647 }
648 
649 static void
_add_signal_binding_cb(void * data,void * data2 EINA_UNUSED)650 _add_signal_binding_cb(void *data, void *data2 EINA_UNUSED)
651 {
652    E_Config_Dialog_Data *cfdata = data;
653 
654    _auto_apply_changes(cfdata);
655    _signal_add_show(cfdata);
656 }
657 
658 static void
_delete_signal_binding_cb(void * data,void * data2 EINA_UNUSED)659 _delete_signal_binding_cb(void *data, void *data2 EINA_UNUSED)
660 {
661    Eina_List *l = NULL;
662    int sel, n;
663    E_Config_Dialog_Data *cfdata;
664 
665    cfdata = data;
666 
667    sel = e_widget_ilist_selected_get(cfdata->gui.o_binding_list);
668    if (cfdata->locals.binding[0] == 's')
669      {
670         if (sscanf(cfdata->locals.binding, "s%d", &n) != 1)
671           return;
672 
673         l = eina_list_nth_list(cfdata->binding.signal, n);
674 
675         if (l)
676           {
677              _signal_binding_free(eina_list_data_get(l));
678              cfdata->binding.signal = eina_list_remove_list(cfdata->binding.signal, l);
679           }
680      }
681 
682    _update_signal_binding_list(cfdata);
683 
684    if (sel >= e_widget_ilist_count(cfdata->gui.o_binding_list))
685      sel = e_widget_ilist_count(cfdata->gui.o_binding_list) - 1;
686 
687    eina_stringshare_del(cfdata->locals.cur);
688    cfdata->locals.cur = NULL;
689 
690    e_widget_ilist_selected_set(cfdata->gui.o_binding_list, sel);
691    if (sel < 0)
692      {
693         e_widget_ilist_unselect(cfdata->gui.o_action_list);
694         e_widget_entry_clear(cfdata->gui.o_params);
695         e_widget_disabled_set(cfdata->gui.o_params, 1);
696         _update_buttons(cfdata);
697      }
698 }
699 
700 
701 static void
_delete_all_signal_binding_cb(void * data,void * data2 EINA_UNUSED)702 _delete_all_signal_binding_cb(void *data, void *data2 EINA_UNUSED)
703 {
704    E_Config_Binding_Signal *bi;
705    E_Config_Dialog_Data *cfdata;
706 
707    cfdata = data;
708 
709    EINA_LIST_FREE(cfdata->binding.signal, bi)
710      _signal_binding_free(bi);
711 
712    eina_stringshare_del(cfdata->locals.cur);
713    cfdata->locals.cur = NULL;
714 
715    e_widget_ilist_clear(cfdata->gui.o_binding_list);
716    e_widget_ilist_go(cfdata->gui.o_binding_list);
717    e_widget_ilist_unselect(cfdata->gui.o_action_list);
718    e_widget_entry_clear(cfdata->gui.o_params);
719    e_widget_disabled_set(cfdata->gui.o_params, 1);
720 
721    _update_buttons(cfdata);
722 }
723 
724 
725 static void
_restore_signal_binding_defaults_cb(void * data,void * data2 EINA_UNUSED)726 _restore_signal_binding_defaults_cb(void *data, void *data2 EINA_UNUSED)
727 {
728    E_Config_Bindings *ecb;
729    Eina_Stringshare *prof;
730    E_Config_Dialog_Data *cfdata = data;
731 
732    ecb = e_config_domain_system_load("e_bindings", e_config_descriptor_find("E_Config_Bindings"));
733    if (!ecb)
734      {
735         const char *type;
736 
737         prof = eina_stringshare_ref(e_config_profile_get());
738         switch (e_config->config_type)
739           {
740            case E_CONFIG_PROFILE_TYPE_DESKTOP:
741              type = "standard";
742              break;
743            case E_CONFIG_PROFILE_TYPE_MOBILE:
744              type = "mobile";
745              break;
746            //case E_CONFIG_PROFILE_TYPE_TABLET: FIXME - not used
747            default:
748              type = "default";
749              break;
750           }
751         e_config_profile_set(type);
752         ecb = e_config_domain_system_load("e_bindings", e_config_descriptor_find("E_Config_Bindings"));
753         e_config_profile_set(prof);
754         eina_stringshare_del(prof);
755      }
756    if (!ecb) return;
757    E_FREE_LIST(cfdata->binding.signal, e_config_binding_signal_free);
758    cfdata->binding.signal = ecb->signal_bindings, ecb->signal_bindings = NULL;
759    e_config_bindings_free(ecb);
760 
761    eina_stringshare_del(cfdata->locals.cur);
762    cfdata->locals.cur = NULL;
763 
764    _update_signal_binding_list(cfdata);
765    _update_buttons(cfdata);
766 
767    e_widget_ilist_unselect(cfdata->gui.o_action_list);
768    e_widget_entry_clear(cfdata->gui.o_params);
769    e_widget_disabled_set(cfdata->gui.o_params, 1);
770 }
771 
772 static Evas_Object *
_basic_create_widgets(E_Config_Dialog * cfd,Evas * evas,E_Config_Dialog_Data * cfdata)773 _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
774 {
775    Evas_Object *o, *ol, *ot, *of, *ob;
776 
777    cfdata->evas = evas;
778    o = e_widget_list_add(evas, 0, 0);
779    ol = e_widget_list_add(evas, 0, 1);
780 
781    of = e_widget_frametable_add(evas, _("Signal Bindings"), 0);
782    ob = e_widget_ilist_add(evas, 32, 32, &(cfdata->locals.binding));
783    cfdata->gui.o_binding_list = ob;
784    e_widget_size_min_set(ob, 200, 160);
785    e_widget_frametable_object_append(of, ob, 0, 0, 2, 1, 1, 1, 1, 1);
786    ob = e_widget_button_add(evas, _("Add"), "list-add", _add_signal_binding_cb, cfdata, NULL);
787    cfdata->gui.o_add = ob;
788    e_widget_frametable_object_append(of, ob, 0, 1, 1, 2, 1, 0, 1, 0);
789    ob = e_widget_button_add(evas, _("Delete"), "list-remove", _delete_signal_binding_cb, cfdata, NULL);
790    cfdata->gui.o_del = ob;
791    e_widget_disabled_set(ob, 1);
792    e_widget_frametable_object_append(of, ob, 1, 1, 1, 1, 1, 0, 1, 0);
793    ob = e_widget_button_add(evas, _("Delete All"), "edit-clear", _delete_all_signal_binding_cb, cfdata, NULL);
794    cfdata->gui.o_del_all = ob;
795    e_widget_disabled_set(ob, 1);
796    e_widget_frametable_object_append(of, ob, 1, 2, 1, 1, 1, 0, 1, 0);
797    ob = e_widget_button_add(evas, _("Restore Default Bindings"), "enlightenment", _restore_signal_binding_defaults_cb, cfdata, NULL);
798    e_widget_frametable_object_append(of, ob, 0, 3, 2, 1, 1, 0, 1, 0);
799    e_widget_list_object_append(ol, of, 1, 1, 0.5);
800 
801    ot = e_widget_table_add(e_win_evas_win_get(evas), 0);
802    of = e_widget_framelist_add(evas, _("Action"), 0);
803    ob = e_widget_ilist_add(evas, 24, 24, &(cfdata->locals.action));
804    cfdata->gui.o_action_list = ob;
805    e_widget_size_min_set(ob, 200, 240);
806    e_widget_framelist_object_append(of, ob);
807    e_widget_table_object_append(ot, of, 0, 0, 1, 1, 1, 1, 1, 1);
808 
809    of = e_widget_framelist_add(evas, _("Action Params"), 0);
810    ob = e_widget_entry_add(cfd->dia->win, &(cfdata->locals.params), NULL, NULL, NULL);
811    cfdata->gui.o_params = ob;
812    e_widget_disabled_set(ob, 1);
813    e_widget_framelist_object_append(of, ob);
814    e_widget_table_object_append(ot, of, 0, 3, 1, 1, 1, 1, 1, 0);
815    e_widget_list_object_append(ol, ot, 1, 1, 0.5);
816 
817    e_widget_list_object_append(o, ol, 1, 1, 0.5);
818 
819    _update_signal_binding_list(cfdata);
820    _fill_actions_list(cfdata);
821 
822    e_dialog_resizable_set(cfd->dia, 1);
823    return o;
824 }
825 
826 
827 E_Config_Dialog *
e_int_config_signalbindings(Evas_Object * parent EINA_UNUSED,const char * params)828 e_int_config_signalbindings(Evas_Object *parent EINA_UNUSED, const char *params)
829 {
830    E_Config_Dialog *cfd;
831    E_Config_Dialog_View *v;
832 
833    if (e_config_dialog_find("E", "keyboard_and_mouse/signal_bindings")) return NULL;
834    v = E_NEW(E_Config_Dialog_View, 1);
835 
836    v->create_cfdata = _create_data;
837    v->free_cfdata = _free_data;
838    v->basic.apply_cfdata = _basic_apply_data;
839    v->basic.create_widgets = _basic_create_widgets;
840    v->override_auto_apply = 1;
841 
842    cfd = e_config_dialog_new(NULL, _("Signal Bindings Settings"), "E",
843                              "keyboard_and_mouse/signal_bindings",
844                              "enlightenment/signals", 0, v, NULL);
845    if ((params) && (params[0]))
846      {
847         cfd->cfdata->params = eina_stringshare_add(params);
848 //        _add_signal_binding_cb(cfd->cfdata, NULL);
849      }
850 
851    return cfd;
852 }
853