update for beta release
[framework/uifw/e17.git] / src / modules / conf_applications / e_int_config_apps.c
1 #include "e.h"
2
3 typedef struct _E_Config_Data
4 {
5    const char *title, *icon, *dialog, *filename;
6    Eina_Bool show_autostart;
7 } E_Config_Data;
8
9 typedef struct _E_Config_App_List
10 {
11    E_Config_Dialog_Data *cfdata;
12    Evas_Object *o_list, *o_add, *o_del, *o_desc;
13    Eina_List *desks;
14 } E_Config_App_List;
15
16 struct _E_Config_Dialog_Data
17 {
18    E_Config_Data *data;
19    Evas_Object *o_list, *o_up, *o_down, *o_del;
20    Eina_List *apps;
21    Ecore_Timer *fill_delay;
22    E_Config_App_List apps_user;
23    E_Config_App_List apps_xdg; /* xdg autostart apps */
24 };
25
26 /* local function prototypes */
27 static E_Config_Dialog *_create_dialog(E_Container *con, E_Config_Data *data);
28 static void *_create_data(E_Config_Dialog *cfd);
29 static void _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
30 static Evas_Object *_basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata);
31 static int _basic_apply(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
32 static Eina_List *_load_menu(const char *path);
33 static Eina_List *_load_order(const char *path);
34 static int _save_menu(E_Config_Dialog_Data *cfdata);
35 static int _save_order(E_Config_Dialog_Data *cfdata);
36 static void _fill_apps_list(E_Config_App_List *apps);
37 static void _fill_xdg_list(E_Config_App_List *apps);
38 static void _fill_order_list(E_Config_Dialog_Data *cfdata);
39 static void _cb_apps_list_selected(void *data);
40 static void _cb_order_list_selected(void *data);
41 static int _cb_desks_sort(const void *data1, const void *data2);
42 static int _cb_desks_name(const void *data1, const void *data2);
43 static int _cb_desks_sort(const void *data1, const void *data2);
44 static void _cb_add(void *data, void *data2 __UNUSED__);
45 static void _cb_del(void *data, void *data2 __UNUSED__);
46 static void _cb_up(void *data, void *data2 __UNUSED__);
47 static void _cb_down(void *data, void *data2 __UNUSED__);
48 static void _cb_order_del(void *data, void *data2 __UNUSED__);
49 static Eina_Bool _cb_fill_delay(void *data);
50 static void _list_items_state_set(E_Config_App_List *apps);
51
52 E_Config_Dialog *
53 e_int_config_apps_add(E_Container *con, const char *params __UNUSED__)
54 {
55    E_Desktop_Edit *ed;
56
57    if (!(ed = e_desktop_edit(con, NULL))) return NULL;
58    return ed->cfd;
59 }
60
61 E_Config_Dialog *
62 e_int_config_apps_favs(E_Container *con, const char *params __UNUSED__)
63 {
64    E_Config_Data *data;
65    char buff[PATH_MAX];
66
67    e_user_dir_concat_static(buff, "applications/menu/favorite.menu");
68    data = E_NEW(E_Config_Data, 1);
69    data->title = eina_stringshare_add(_("Favorite Applications"));
70    data->dialog = eina_stringshare_add("menus/favorites_menu");
71    data->icon = eina_stringshare_add("user-bookmarks");
72    data->filename = eina_stringshare_add(buff);
73    return _create_dialog(con, data);
74 }
75
76 E_Config_Dialog *
77 e_int_config_apps_ibar(E_Container *con, const char *params __UNUSED__)
78 {
79    E_Config_Data *data;
80    char buff[PATH_MAX];
81
82    e_user_dir_concat_static(buff, "applications/bar/default/.order");
83    data = E_NEW(E_Config_Data, 1);
84    data->title = eina_stringshare_add(_("IBar Applications"));
85    data->dialog = eina_stringshare_add("applications/ibar_applications");
86    data->icon = eina_stringshare_add("preferences-applications-ibar");
87    data->filename = eina_stringshare_add(buff);
88    return _create_dialog(con, data);
89 }
90
91 E_Config_Dialog *
92 e_int_config_apps_ibar_other(E_Container *con, const char *path)
93 {
94    E_Config_Data *data;
95
96    if (!path) return NULL;
97    data = E_NEW(E_Config_Data, 1);
98    data->title = eina_stringshare_add(_("IBar Applications"));
99    data->dialog = eina_stringshare_add("internal/ibar_other");
100    data->icon = eina_stringshare_add("preferences-applications-ibar");
101    data->filename = eina_stringshare_add(path);
102    return _create_dialog(con, data);
103 }
104
105 E_Config_Dialog *
106 e_int_config_apps_startup(E_Container *con, const char *params __UNUSED__)
107 {
108    E_Config_Data *data;
109    char buff[PATH_MAX];
110
111    e_user_dir_concat_static(buff, "applications/startup/.order");
112    data = E_NEW(E_Config_Data, 1);
113    data->title = eina_stringshare_add(_("Startup Applications"));
114    data->dialog = eina_stringshare_add("applications/startup_applications");
115    data->icon = eina_stringshare_add("preferences-applications-startup");
116    data->filename = eina_stringshare_add(buff);
117    data->show_autostart = EINA_TRUE;
118    return _create_dialog(con, data);
119 }
120
121 E_Config_Dialog *
122 e_int_config_apps_restart(E_Container *con, const char *params __UNUSED__)
123 {
124    E_Config_Data *data;
125    char buff[PATH_MAX];
126
127    e_user_dir_concat_static(buff, "applications/restart/.order");
128    data = E_NEW(E_Config_Data, 1);
129    data->title = eina_stringshare_add(_("Restart Applications"));
130    data->dialog = eina_stringshare_add("applications/restart_applications");
131    data->icon = eina_stringshare_add("preferences-applications-restart");
132    data->filename = eina_stringshare_add(buff);
133    return _create_dialog(con, data);
134 }
135
136 /* local function prototypes */
137 static E_Config_Dialog *
138 _create_dialog(E_Container *con, E_Config_Data *data)
139 {
140    E_Config_Dialog *cfd;
141    E_Config_Dialog_View *v;
142
143    if (e_config_dialog_find("E", data->dialog))
144      {
145         if (data->title) eina_stringshare_del(data->title);
146         if (data->dialog) eina_stringshare_del(data->dialog);
147         if (data->icon) eina_stringshare_del(data->icon);
148         if (data->filename) eina_stringshare_del(data->filename);
149         E_FREE(data);
150         return NULL;
151      }
152
153    v = E_NEW(E_Config_Dialog_View, 1);
154    v->create_cfdata = _create_data;
155    v->free_cfdata = _free_data;
156    v->basic.create_widgets = _basic_create;
157    v->basic.apply_cfdata = _basic_apply;
158
159    cfd = e_config_dialog_new(con, data->title, "E", data->dialog,
160                              data->icon, 0, v, data);
161    return cfd;
162 }
163
164 static void *
165 _create_data(E_Config_Dialog *cfd)
166 {
167    E_Config_Dialog_Data *cfdata;
168    E_Config_Data *data;
169    const char *ext;
170
171    if (!(data = cfd->data)) return NULL;
172    if (!data->filename) return NULL;
173    if (!(ext = strrchr(data->filename, '.'))) return NULL;
174
175    cfdata = E_NEW(E_Config_Dialog_Data, 1);
176    cfdata->data = data;
177    cfdata->apps_xdg.cfdata = cfdata;
178    cfdata->apps_user.cfdata = cfdata;
179    if (!strcmp(ext, ".menu"))
180      cfdata->apps = _load_menu(data->filename);
181    else if (!strcmp(ext, ".order"))
182      cfdata->apps = _load_order(data->filename);
183
184    return cfdata;
185 }
186
187 static void
188 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
189 {
190    E_Config_Data *data;
191    Efreet_Desktop *desk;
192
193    if (cfdata->fill_delay) ecore_timer_del(cfdata->fill_delay);
194
195    if ((data = cfdata->data))
196      {
197         if (data->title) eina_stringshare_del(data->title);
198         if (data->dialog) eina_stringshare_del(data->dialog);
199         if (data->icon) eina_stringshare_del(data->icon);
200         if (data->filename) eina_stringshare_del(data->filename);
201         E_FREE(data);
202      }
203    EINA_LIST_FREE(cfdata->apps, desk)
204      efreet_desktop_free(desk);
205    EINA_LIST_FREE(cfdata->apps_user.desks, desk)
206      efreet_desktop_free(desk);
207    EINA_LIST_FREE(cfdata->apps_xdg.desks, desk)
208      efreet_desktop_free(desk);
209    E_FREE(cfdata);
210 }
211
212 static Evas_Object *
213 _basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata)
214 {
215    Evas_Object *otb, *ot;
216    int mw;
217
218    otb = e_widget_toolbook_add(evas, 24, 24);
219
220    if (cfdata->data->show_autostart)
221      {
222         /* XDG autostart page */
223         ot = e_widget_table_add(evas, EINA_FALSE);
224         cfdata->apps_xdg.o_list = e_widget_ilist_add(evas, 24, 24, NULL);
225         e_widget_ilist_multi_select_set(cfdata->apps_xdg.o_list, EINA_TRUE);
226         e_widget_size_min_get(cfdata->apps_xdg.o_list, &mw, NULL);
227         if (mw < (200 * e_scale)) mw = (200 * e_scale);
228         e_widget_size_min_set(cfdata->apps_xdg.o_list, mw, (75 * e_scale));
229         e_widget_table_object_append(ot, cfdata->apps_xdg.o_list, 0, 0, 2, 1, 1, 1, 1, 1);
230
231         cfdata->apps_xdg.o_desc = e_widget_textblock_add(evas);
232         e_widget_size_min_set(cfdata->apps_xdg.o_desc, 100, (45 * e_scale));
233         e_widget_table_object_append(ot, cfdata->apps_xdg.o_desc, 0, 1, 2, 1, 1, 1, 0, 0);
234
235         cfdata->apps_xdg.o_add = e_widget_button_add(evas, _("Add"), "list-add",
236                                                      _cb_add, &cfdata->apps_xdg, NULL);
237         e_widget_disabled_set(cfdata->apps_xdg.o_add, EINA_TRUE);
238         e_widget_table_object_append(ot, cfdata->apps_xdg.o_add, 0, 2, 1, 1, 1, 1, 1, 0);
239         cfdata->apps_xdg.o_del = e_widget_button_add(evas, _("Remove"), "list-remove",
240                                                      _cb_del, &cfdata->apps_xdg, NULL);
241         e_widget_disabled_set(cfdata->apps_xdg.o_del, EINA_TRUE);
242         e_widget_table_object_append(ot, cfdata->apps_xdg.o_del, 1, 2, 1, 1, 1, 1, 1, 0);
243
244         e_widget_toolbook_page_append(otb, NULL, _("System"), ot,
245                                       1, 1, 1, 1, 0.5, 0.0);
246      }
247
248    /* Selection page */
249    ot = e_widget_table_add(evas, EINA_FALSE);
250    cfdata->apps_user.o_list = e_widget_ilist_add(evas, 24, 24, NULL);
251    e_widget_ilist_multi_select_set(cfdata->apps_user.o_list, EINA_TRUE);
252    e_widget_size_min_get(cfdata->apps_user.o_list, &mw, NULL);
253    if (mw < (200 * e_scale)) mw = (200 * e_scale);
254    e_widget_size_min_set(cfdata->apps_user.o_list, mw, (75 * e_scale));
255    e_widget_table_object_append(ot, cfdata->apps_user.o_list, 0, 0, 2, 1, 1, 1, 1, 1);
256    cfdata->apps_user.o_add = e_widget_button_add(evas, _("Add"), "list-add",
257                                                  _cb_add, &cfdata->apps_user, NULL);
258    e_widget_disabled_set(cfdata->apps_user.o_add, EINA_TRUE);
259    e_widget_table_object_append(ot, cfdata->apps_user.o_add, 0, 1, 1, 1, 1, 1, 1, 0);
260    cfdata->apps_user.o_del = e_widget_button_add(evas, _("Remove"), "list-remove",
261                                                  _cb_del, &cfdata->apps_user, NULL);
262    e_widget_disabled_set(cfdata->apps_user.o_del, EINA_TRUE);
263    e_widget_table_object_append(ot, cfdata->apps_user.o_del, 1, 1, 1, 1, 1, 1, 1, 0);
264    e_widget_toolbook_page_append(otb, NULL, _("Applications"), ot,
265                                  1, 1, 1, 1, 0.5, 0.0);
266
267    /* Order page */
268    ot = e_widget_table_add(evas, EINA_FALSE);
269    cfdata->o_list = e_widget_ilist_add(evas, 24, 24, NULL);
270    _fill_order_list(cfdata);
271    e_widget_table_object_append(ot, cfdata->o_list, 0, 0, 3, 1, 1, 1, 1, 1);
272    cfdata->o_up = e_widget_button_add(evas, _("Up"), "go-up",
273                                       _cb_up, cfdata, NULL);
274    e_widget_disabled_set(cfdata->o_up, EINA_TRUE);
275    e_widget_table_object_append(ot, cfdata->o_up, 0, 1, 1, 1, 1, 1, 1, 0);
276    cfdata->o_down = e_widget_button_add(evas, _("Down"), "go-down",
277                                         _cb_down, cfdata, NULL);
278    e_widget_disabled_set(cfdata->o_down, EINA_TRUE);
279    e_widget_table_object_append(ot, cfdata->o_down, 1, 1, 1, 1, 1, 1, 1, 0);
280    cfdata->o_del = e_widget_button_add(evas, _("Remove"), "list-remove",
281                                         _cb_order_del, cfdata, NULL);
282    e_widget_disabled_set(cfdata->o_del, EINA_TRUE);
283    e_widget_table_object_append(ot, cfdata->o_del, 2, 1, 1, 1, 1, 1, 1, 0);
284    e_widget_toolbook_page_append(otb, NULL, _("Order"), ot,
285                                  1, 1, 1, 1, 0.5, 0.0);
286
287    e_widget_toolbook_page_show(otb, 0);
288
289    if (cfdata->fill_delay) ecore_timer_del(cfdata->fill_delay);
290    cfdata->fill_delay = ecore_timer_add(0.2, _cb_fill_delay, cfdata);
291
292    e_dialog_resizable_set(cfd->dia, 1);
293    e_win_centered_set(cfd->dia->win, 1);
294    return otb;
295 }
296
297 static int
298 _basic_apply(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
299 {
300    const char *ext;
301
302    if ((!cfdata->data) || (!cfdata->data->filename)) return 0;
303    if (!(ext = strrchr(cfdata->data->filename, '.'))) return 0;
304    if (!strcmp(ext, ".menu"))
305      return _save_menu(cfdata);
306    else if (!strcmp(ext, ".order"))
307      return _save_order(cfdata);
308    return 1;
309 }
310
311 static Eina_List *
312 _load_menu(const char *path)
313 {
314    Efreet_Menu *menu, *entry;
315    Eina_List *apps = NULL, *l;
316
317    menu = efreet_menu_parse(path);
318    if ((!menu) || (!menu->entries)) return NULL;
319    EINA_LIST_FOREACH(menu->entries, l, entry)
320      {
321         if (entry->type != EFREET_MENU_ENTRY_DESKTOP) continue;
322         efreet_desktop_ref(entry->desktop);
323         apps = eina_list_append(apps, entry->desktop);
324      }
325    efreet_menu_free(menu);
326    return apps;
327 }
328
329 static Eina_List *
330 _load_order(const char *path)
331 {
332    E_Order *order = NULL;
333    Eina_List *apps = NULL, *l;
334    Efreet_Desktop *desk;
335
336    if (!path) return NULL;
337    if (!(order = e_order_new(path))) return NULL;
338    EINA_LIST_FOREACH(order->desktops, l, desk)
339      {
340         efreet_desktop_ref(desk);
341         apps = eina_list_append(apps, desk);
342      }
343    e_object_del(E_OBJECT(order));
344    return apps;
345 }
346
347 static int
348 _save_menu(E_Config_Dialog_Data *cfdata)
349 {
350    Eina_List *l;
351    Efreet_Menu *menu = NULL;
352    Efreet_Desktop *desk;
353    int ret;
354
355    menu = efreet_menu_new("Favorites");
356    EINA_LIST_FOREACH(cfdata->apps, l, desk)
357      {
358         if (!desk) continue;
359         efreet_menu_desktop_insert(menu, desk, -1);
360      }
361    ret = efreet_menu_save(menu, cfdata->data->filename);
362    efreet_menu_free(menu);
363    return ret;
364 }
365
366 static int
367 _save_order(E_Config_Dialog_Data *cfdata)
368 {
369    Eina_List *l;
370    E_Order *order = NULL;
371    Efreet_Desktop *desk;
372
373    if (!(order = e_order_new(cfdata->data->filename))) return 0;
374    e_order_clear(order);
375    EINA_LIST_FOREACH(cfdata->apps, l, desk)
376      {
377         if (!desk) continue;
378         e_order_append(order, desk);
379      }
380    e_object_del(E_OBJECT(order));
381    return 1;
382 }
383
384 static void
385 _list_items_state_set(E_Config_App_List *apps)
386 {
387    Evas *evas;
388    Eina_List *l;
389    Efreet_Desktop *desk;
390
391    if (!apps->o_list)
392      return;
393
394    evas = evas_object_evas_get(apps->o_list);
395    evas_event_freeze(evas);
396    edje_freeze();
397    e_widget_ilist_freeze(apps->o_list);
398    e_widget_ilist_clear(apps->o_list);
399
400    EINA_LIST_FOREACH(apps->desks, l, desk)
401      {
402         Evas_Object *icon = NULL, *end = NULL;
403
404         end = edje_object_add(evas);
405         if (!e_theme_edje_object_set(end, "base/theme/widgets",
406                                      "e/widgets/ilist/toggle_end"))
407           {
408              evas_object_del(end);
409              end = NULL;
410           }
411
412         if (!end) break;
413
414         if (eina_list_search_unsorted(apps->cfdata->apps, _cb_desks_sort, desk))
415           {
416              edje_object_signal_emit(end, "e,state,checked", "e");
417           }
418         else
419           {
420             edje_object_signal_emit(end, "e,state,unchecked", "e");
421           }
422
423         icon = e_util_desktop_icon_add(desk, 24, evas);
424         e_widget_ilist_append_full(apps->o_list, icon, end, desk->name,
425                                    _cb_apps_list_selected, apps, NULL);
426      }
427
428    e_widget_ilist_go(apps->o_list);
429    e_widget_ilist_thaw(apps->o_list);
430    edje_thaw();
431    evas_event_thaw(evas);
432 }
433
434 static void
435 _fill_apps_list(E_Config_App_List *apps)
436 {
437    Eina_List *desks = NULL;
438    Efreet_Desktop *desk = NULL;
439
440    desks = efreet_util_desktop_name_glob_list("*");
441    EINA_LIST_FREE(desks, desk)
442      {
443         Eina_List *ll;
444
445         if (desk->no_display)
446           {
447              efreet_desktop_free(desk);
448              continue;
449           }
450         ll = eina_list_search_unsorted_list(apps->desks, _cb_desks_sort, desk);
451         if (ll)
452           {
453              Efreet_Desktop *old;
454
455              old = eina_list_data_get(ll);
456              /*
457               * This fixes when we have several .desktop with the same name,
458               * and the only difference is that some of them are for specific
459               * desktops.
460               */
461              if ((old->only_show_in) && (!desk->only_show_in))
462                {
463                   efreet_desktop_free(old);
464                   eina_list_data_set(ll, desk);
465                }
466              else
467                efreet_desktop_free(desk);
468           }
469         else
470           apps->desks = eina_list_append(apps->desks, desk);
471      }
472    apps->desks = eina_list_sort(apps->desks, -1, _cb_desks_sort);
473
474    _list_items_state_set(apps);
475 }
476
477 static void
478 _fill_xdg_list(E_Config_App_List *apps)
479 {
480    Eina_List *files;
481    Efreet_Desktop *desk = NULL;
482    const char *path = "/etc/xdg/autostart";
483    char *file, *ext;
484    char buf[4096];
485
486    files = ecore_file_ls(path);
487    EINA_LIST_FREE(files, file)
488      {
489         Eina_List *ll;
490
491         if ((file[0] == '.') || !(ext = strrchr(file, '.')) || (strcmp(ext, ".desktop")))
492           {
493              free(file);
494              continue;
495           }
496         snprintf(buf, sizeof(buf), "%s/%s", path, file);
497         free(file);
498
499         desk = efreet_desktop_new(buf);
500         if (!desk)
501           continue;
502
503         ll = eina_list_search_unsorted_list(apps->desks, _cb_desks_sort, desk);
504         if (ll)
505           {
506              Efreet_Desktop *old;
507
508              old = eina_list_data_get(ll);
509              /*
510               * This fixes when we have several .desktop with the same name,
511               * and the only difference is that some of them are for specific
512               * desktops.
513               */
514              if ((old->only_show_in) && (!desk->only_show_in))
515                {
516                   efreet_desktop_free(old);
517                   eina_list_data_set(ll, desk);
518                }
519              else
520                efreet_desktop_free(desk);
521           }
522         else
523           apps->desks = eina_list_append(apps->desks, desk);
524      }
525
526    apps->desks = eina_list_sort(apps->desks, -1, _cb_desks_sort);
527
528    _list_items_state_set(apps);
529 }
530
531 static void
532 _fill_order_list(E_Config_Dialog_Data *cfdata)
533 {
534    Eina_List *l = NULL;
535    Efreet_Desktop *desk = NULL;
536    Evas *evas;
537
538    evas = evas_object_evas_get(cfdata->o_list);
539    evas_event_freeze(evas);
540    edje_freeze();
541    e_widget_ilist_freeze(cfdata->o_list);
542    e_widget_ilist_clear(cfdata->o_list);
543
544    EINA_LIST_FOREACH(cfdata->apps, l, desk)
545      {
546         Evas_Object *icon = NULL;
547
548         icon = e_util_desktop_icon_add(desk, 24, evas);
549         e_widget_ilist_append(cfdata->o_list, icon, desk->name,
550                               _cb_order_list_selected, cfdata, NULL);
551      }
552
553    e_widget_ilist_go(cfdata->o_list);
554    e_widget_ilist_thaw(cfdata->o_list);
555    edje_thaw();
556    evas_event_thaw(evas);
557 }
558
559 static void
560 _cb_apps_list_selected(void *data)
561 {
562    E_Config_App_List *apps;
563    const E_Ilist_Item *it;
564    Eina_List *l;
565    unsigned int enabled = 0, disabled = 0;
566
567    if (!(apps = data)) return;
568    EINA_LIST_FOREACH(e_widget_ilist_items_get(apps->o_list), l, it)
569      {
570         if ((!it->selected) || (it->header)) continue;
571         if (eina_list_search_unsorted(apps->cfdata->apps, _cb_desks_name, it->label))
572           enabled++;
573         else
574           disabled++;
575      }
576
577    if (apps->o_desc)
578      {
579         Efreet_Desktop *desk;
580         int sel;
581
582         sel = e_widget_ilist_selected_get(apps->o_list);
583         desk = eina_list_nth(apps->desks, sel);
584         if (desk)
585           e_widget_textblock_markup_set(apps->o_desc, desk->comment);
586      }
587
588    e_widget_disabled_set(apps->o_add, !disabled);
589    e_widget_disabled_set(apps->o_del, !enabled);
590 }
591
592 static void
593 _cb_order_list_selected(void *data)
594 {
595    E_Config_Dialog_Data *cfdata;
596    int sel, count;
597
598    if (!(cfdata = data)) return;
599    sel = e_widget_ilist_selected_get(cfdata->o_list);
600    count = eina_list_count(cfdata->apps);
601    e_widget_disabled_set(cfdata->o_up, (sel == 0));
602    e_widget_disabled_set(cfdata->o_down, !(sel < (count - 1)));
603    e_widget_disabled_set(cfdata->o_del, EINA_FALSE);
604 }
605
606 static int
607 _cb_desks_name(const void *data1, const void *data2)
608 {
609    const Efreet_Desktop *d1;
610    const char *d2;
611
612    if (!(d1 = data1)) return 1;
613    if (!d1->name) return 1;
614    if (!(d2 = data2)) return -1;
615    return strcmp(d1->name, d2);
616 }
617
618 static int
619 _cb_desks_sort(const void *data1, const void *data2)
620 {
621    const Efreet_Desktop *d1, *d2;
622
623    if (!(d1 = data1)) return 1;
624    if (!d1->name) return 1;
625    if (!(d2 = data2)) return -1;
626    if (!d2->name) return -1;
627    return strcmp(d1->name, d2->name);
628 }
629
630 static void
631 _cb_add(void *data, void *data2 __UNUSED__)
632 {
633    E_Config_App_List *apps;
634    const E_Ilist_Item *it;
635    Eina_List *l;
636
637    if (!(apps = data)) return;
638    EINA_LIST_FOREACH(e_widget_ilist_items_get(apps->o_list), l, it)
639      {
640         Efreet_Desktop *desk;
641
642         if ((!it->selected) || (it->header)) continue;
643         if (!(desk = eina_list_search_unsorted(apps->desks, _cb_desks_name, it->label))) continue;
644         if (!eina_list_search_unsorted(apps->cfdata->apps, _cb_desks_sort, desk))
645           {
646              Evas_Object *end;
647
648              end = e_widget_ilist_item_end_get(it);
649              if (end) edje_object_signal_emit(end, "e,state,checked", "e");
650              efreet_desktop_ref(desk);
651              apps->cfdata->apps = eina_list_append(apps->cfdata->apps, desk);
652           }
653      }
654    e_widget_ilist_unselect(apps->o_list);
655    e_widget_disabled_set(apps->o_add, EINA_TRUE);
656    e_widget_disabled_set(apps->o_del, EINA_TRUE);
657    _fill_order_list(apps->cfdata);
658 }
659
660 static void
661 _cb_del(void *data, void *data2 __UNUSED__)
662 {
663    E_Config_App_List *apps;
664    const E_Ilist_Item *it;
665    Eina_List *l;
666
667    if (!(apps = data)) return;
668    EINA_LIST_FOREACH(e_widget_ilist_items_get(apps->o_list), l, it)
669      {
670         Efreet_Desktop *desk;
671
672         if ((!it->selected) || (it->header)) continue;
673         if ((desk = eina_list_search_unsorted(apps->cfdata->apps, _cb_desks_name, it->label)))
674           {
675              Evas_Object *end;
676
677              end = e_widget_ilist_item_end_get(it);
678              if (end) edje_object_signal_emit(end, "e,state,unchecked", "e");
679              apps->cfdata->apps = eina_list_remove(apps->cfdata->apps, desk);
680              efreet_desktop_unref(desk);
681           }
682      }
683
684    e_widget_ilist_unselect(apps->o_list);
685    e_widget_disabled_set(apps->o_add, EINA_TRUE);
686    e_widget_disabled_set(apps->o_del, EINA_TRUE);
687    _fill_order_list(apps->cfdata);
688 }
689
690 static void
691 _cb_order_del(void *data, void *data2 __UNUSED__)
692 {
693    E_Config_Dialog_Data *cfdata;
694    const E_Ilist_Item *it;
695    Eina_List *l;
696
697    if (!(cfdata = data)) return;
698    EINA_LIST_FOREACH(e_widget_ilist_items_get(cfdata->o_list), l, it)
699      {
700         Efreet_Desktop *desk;
701
702         if ((!it->selected) || (it->header)) continue;
703
704         if ((desk = eina_list_search_unsorted(cfdata->apps, _cb_desks_name, it->label)))
705           {
706              cfdata->apps = eina_list_remove(cfdata->apps, desk);
707              efreet_desktop_unref(desk);
708           }
709      }
710
711    _list_items_state_set(&(cfdata->apps_xdg));
712    _list_items_state_set(&(cfdata->apps_user));
713
714    e_widget_ilist_unselect(cfdata->o_list);
715    e_widget_disabled_set(cfdata->o_del, EINA_TRUE);
716    _fill_order_list(cfdata);
717 }
718
719 static void
720 _cb_up(void *data, void *data2 __UNUSED__)
721 {
722    E_Config_Dialog_Data *cfdata;
723    Eina_List *l;
724    Evas *evas;
725    const char *lbl;
726    int sel;
727
728    if (!(cfdata = data)) return;
729    evas = evas_object_evas_get(cfdata->o_list);
730    evas_event_freeze(evas);
731    edje_freeze();
732    e_widget_ilist_freeze(cfdata->o_list);
733
734    sel = e_widget_ilist_selected_get(cfdata->o_list);
735    lbl = e_widget_ilist_selected_label_get(cfdata->o_list);
736    if ((l = eina_list_search_unsorted_list(cfdata->apps, _cb_desks_name, lbl)))
737      {
738         Efreet_Desktop *desk;
739         Evas_Object *icon = NULL;
740
741         desk = eina_list_data_get(l);
742         if (l->prev)
743           {
744              Eina_List *ll;
745
746              ll = l->prev;
747              cfdata->apps = eina_list_remove_list(cfdata->apps, l);
748              cfdata->apps = eina_list_prepend_relative_list(cfdata->apps, desk, ll);
749
750              e_widget_ilist_remove_num(cfdata->o_list, sel);
751              e_widget_ilist_go(cfdata->o_list);
752              icon = e_util_desktop_icon_add(desk, 24, evas);
753              e_widget_ilist_prepend_relative(cfdata->o_list, icon, desk->name,
754                                              _cb_order_list_selected, cfdata,
755                                              NULL, (sel - 1));
756              e_widget_ilist_selected_set(cfdata->o_list, (sel - 1));
757           }
758      }
759
760    e_widget_ilist_go(cfdata->o_list);
761    e_widget_ilist_thaw(cfdata->o_list);
762    edje_thaw();
763    evas_event_thaw(evas);
764 }
765
766 static void
767 _cb_down(void *data, void *data2 __UNUSED__)
768 {
769    E_Config_Dialog_Data *cfdata;
770    Eina_List *l;
771    Evas *evas;
772    const char *lbl;
773    int sel;
774
775    if (!(cfdata = data)) return;
776    evas = evas_object_evas_get(cfdata->o_list);
777    evas_event_freeze(evas);
778    edje_freeze();
779    e_widget_ilist_freeze(cfdata->o_list);
780
781    sel = e_widget_ilist_selected_get(cfdata->o_list);
782    lbl = e_widget_ilist_selected_label_get(cfdata->o_list);
783    if ((l = eina_list_search_unsorted_list(cfdata->apps, _cb_desks_name, lbl)))
784      {
785         Efreet_Desktop *desk;
786         Evas_Object *icon = NULL;
787
788         desk = eina_list_data_get(l);
789         if (l->next)
790           {
791              Eina_List *ll;
792
793              ll = l->next;
794              cfdata->apps = eina_list_remove_list(cfdata->apps, l);
795              cfdata->apps = eina_list_append_relative_list(cfdata->apps, desk, ll);
796
797              e_widget_ilist_remove_num(cfdata->o_list, sel);
798              e_widget_ilist_go(cfdata->o_list);
799              icon = e_util_desktop_icon_add(desk, 24, evas);
800              e_widget_ilist_append_relative(cfdata->o_list, icon, desk->name,
801                                             _cb_order_list_selected, cfdata,
802                                             NULL, sel);
803              e_widget_ilist_selected_set(cfdata->o_list, (sel + 1));
804           }
805      }
806
807    e_widget_ilist_go(cfdata->o_list);
808    e_widget_ilist_thaw(cfdata->o_list);
809    edje_thaw();
810    evas_event_thaw(evas);
811 }
812
813 static Eina_Bool
814 _cb_fill_delay(void *data)
815 {
816    E_Config_Dialog_Data *cfdata;
817    int mw;
818
819    if (!(cfdata = data)) return ECORE_CALLBACK_CANCEL;
820    _fill_apps_list(&cfdata->apps_user);
821    e_widget_size_min_get(cfdata->apps_user.o_list, &mw, NULL);
822    if (mw < (200 * e_scale)) mw = (200 * e_scale);
823    e_widget_size_min_set(cfdata->apps_user.o_list, mw, (175 * e_scale));
824
825    if (cfdata->data->show_autostart)
826      {
827         _fill_xdg_list(&cfdata->apps_xdg);
828         e_widget_size_min_get(cfdata->apps_xdg.o_list, &mw, NULL);
829         if (mw < (200 * e_scale)) mw = (200 * e_scale);
830         e_widget_size_min_set(cfdata->apps_xdg.o_list, mw, (175 * e_scale));
831      }
832
833    cfdata->fill_delay = NULL;
834    return ECORE_CALLBACK_CANCEL;
835 }