1 #include "e.h"
2
3 struct _E_Config_Dialog_Data
4 {
5 Eina_List *desks;
6 Ecore_Event_Handler *desk_change_handler;
7
8 struct
9 {
10 Evas_Object *list, *add, *del;
11 } obj;
12 };
13
14 /* local function prototypes */
15 static void *_create_data(E_Config_Dialog *cfd);
16 static void _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
17 static Evas_Object *_basic_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata);
18 static Eina_Bool _desks_update(void *data, int ev_type EINA_UNUSED, void *ev EINA_UNUSED);
19 static int _cb_desks_sort(const void *data1, const void *data2);
20 static void _fill_apps_list(E_Config_Dialog_Data *cfdata, Evas_Object *il);
21 static void _btn_cb_add(void *data, void *data2);
22 static void _btn_cb_del(void *data, void *data2);
23 static void _widget_list_selection_changed(void *data, Evas_Object *obj EINA_UNUSED);
24
25 E_Config_Dialog *
e_int_config_apps_personal(Evas_Object * parent EINA_UNUSED,const char * params EINA_UNUSED)26 e_int_config_apps_personal(Evas_Object *parent EINA_UNUSED, const char *params EINA_UNUSED)
27 {
28 E_Config_Dialog *cfd;
29 E_Config_Dialog_View *v;
30
31 if (e_config_dialog_find("E", "applications/personal_applications"))
32 return NULL;
33
34 v = E_NEW(E_Config_Dialog_View, 1);
35 v->create_cfdata = _create_data;
36 v->free_cfdata = _free_data;
37 v->basic.create_widgets = _basic_create;
38
39 cfd = e_config_dialog_new(NULL, _("Personal Application Launchers"),
40 "E", "applications/personal_applications",
41 "preferences-applications-personal", 0, v, NULL);
42 return cfd;
43 }
44
45 /* local function prototypes */
46 static void *
_create_data(E_Config_Dialog * cfd EINA_UNUSED)47 _create_data(E_Config_Dialog *cfd EINA_UNUSED)
48 {
49 E_Config_Dialog_Data *cfdata;
50
51 cfdata = E_NEW(E_Config_Dialog_Data, 1);
52 cfdata->desk_change_handler = ecore_event_handler_add
53 (EFREET_EVENT_DESKTOP_CACHE_UPDATE, _desks_update, cfdata);
54
55 return cfdata;
56 }
57
58 static void
_free_data(E_Config_Dialog * cfd EINA_UNUSED,E_Config_Dialog_Data * cfdata)59 _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
60 {
61 Efreet_Desktop *desk;
62
63 EINA_LIST_FREE(cfdata->desks, desk)
64 efreet_desktop_free(desk);
65 if (cfdata->desk_change_handler)
66 ecore_event_handler_del(cfdata->desk_change_handler);
67 E_FREE(cfdata);
68 }
69
70 static Evas_Object *
_basic_create(E_Config_Dialog * cfd,Evas * evas,E_Config_Dialog_Data * cfdata)71 _basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
72 {
73 Evas_Object *of, *li, *ob;
74 Evas_Coord mw, mh;
75
76 e_dialog_resizable_set(cfd->dia, 1);
77
78 of = e_widget_table_add(e_win_evas_win_get(evas), 0);
79
80 ob = evas_object_rectangle_add(evas);
81 evas_object_color_set(ob, 0, 0, 0, 0);
82 evas_object_pass_events_set(ob, EINA_TRUE);
83 mw = 260 * e_scale; mh = 200 * e_scale;
84 evas_object_size_hint_min_set(ob, mw, mh);
85 e_widget_table_object_append(of, ob, 0, 1, 2, 1, 1, 1, 1, 1);
86
87 li = e_widget_ilist_add(evas, 24, 24, NULL);
88 cfdata->obj.list = li;
89 e_widget_ilist_multi_select_set(li, EINA_TRUE);
90 e_widget_size_min_get(li, &mw, &mh);
91 e_widget_size_min_set(li, mw, mh);
92 e_widget_on_change_hook_set(li, _widget_list_selection_changed, cfdata);
93 e_widget_table_object_append(of, li, 0, 1, 2, 1, 1, 1, 1, 1);
94
95 _fill_apps_list(cfdata, cfdata->obj.list);
96 e_widget_ilist_go(li);
97
98 ob = e_widget_button_add(evas, _("Add"), "list-add", _btn_cb_add, cfdata, NULL);
99 cfdata->obj.add = ob;
100 e_widget_table_object_append(of, ob, 0, 2, 1, 1, 1, 1, 1, 0);
101
102 ob = e_widget_button_add(evas, _("Remove"), "list-remove", _btn_cb_del, cfdata, NULL);
103 cfdata->obj.del = ob;
104 e_widget_disabled_set(ob, 1);
105 e_widget_table_object_append(of, ob, 1, 2, 1, 1, 1, 1, 1, 0);
106
107 elm_win_center(cfd->dia->win, 1, 1);
108 return of;
109 }
110
111 static Eina_Bool
_desks_update(void * data,int ev_type EINA_UNUSED,void * ev EINA_UNUSED)112 _desks_update(void *data, int ev_type EINA_UNUSED, void *ev EINA_UNUSED)
113 {
114 E_Config_Dialog_Data *cfdata = data;
115 Efreet_Desktop *desk;
116
117 EINA_LIST_FREE(cfdata->desks, desk)
118 efreet_desktop_free(desk);
119 _fill_apps_list(cfdata, cfdata->obj.list);
120 return ECORE_CALLBACK_PASS_ON;
121 }
122
123 static int
_cb_desks_sort(const void * data1,const void * data2)124 _cb_desks_sort(const void *data1, const void *data2)
125 {
126 const Efreet_Desktop *d1, *d2;
127
128 if (!(d1 = data1)) return 1;
129 if (!d1->name) return 1;
130 if (!(d2 = data2)) return -1;
131 if (!d2->name) return -1;
132 return strcmp(d1->name, d2->name);
133 }
134
135 static void
_fill_apps_list(E_Config_Dialog_Data * cfdata,Evas_Object * il)136 _fill_apps_list(E_Config_Dialog_Data *cfdata, Evas_Object *il)
137 {
138 Eina_List *desks = NULL, *l;
139 Efreet_Desktop *desk = NULL;
140 Evas *evas;
141 const char *desktop_dir = e_user_desktop_dir_get();
142 int n = 0;
143
144 if (!desktop_dir) return;
145
146 n = strlen(desktop_dir);
147
148 if (!cfdata->desks)
149 {
150 desks = efreet_util_desktop_name_glob_list("*");
151 EINA_LIST_FREE(desks, desk)
152 {
153 if (desk->no_display)
154 {
155 efreet_desktop_free(desk);
156 continue;
157 }
158 if (!strncmp(desk->orig_path, desktop_dir, n))
159 cfdata->desks = eina_list_append(cfdata->desks, desk);
160 else
161 efreet_desktop_free(desk);
162 }
163 cfdata->desks = eina_list_sort(cfdata->desks, -1, _cb_desks_sort);
164 }
165
166 evas = evas_object_evas_get(il);
167 evas_event_freeze(evas);
168 edje_freeze();
169 e_widget_ilist_freeze(il);
170 e_widget_ilist_clear(il);
171
172 EINA_LIST_FOREACH(cfdata->desks, l, desk)
173 {
174 Evas_Object *icon = e_util_desktop_icon_add(desk, 24, evas);
175
176 e_widget_ilist_append(il, icon, desk->name,
177 NULL, desk->orig_path,
178 desk->orig_path);
179 }
180
181 e_widget_ilist_go(il);
182 e_widget_ilist_thaw(il);
183 edje_thaw();
184 evas_event_thaw(evas);
185 }
186
187 static void
_btn_cb_add(void * data EINA_UNUSED,void * data2 EINA_UNUSED)188 _btn_cb_add(void *data EINA_UNUSED, void *data2 EINA_UNUSED)
189 {
190 e_desktop_edit(NULL);
191 }
192
193 static void
_btn_cb_del(void * data,void * data2 EINA_UNUSED)194 _btn_cb_del(void *data, void *data2 EINA_UNUSED)
195 {
196 E_Config_Dialog_Data *cfdata = data;
197 const Eina_List *l;
198 const E_Ilist_Item *it;
199 int x = -1;
200
201 EINA_LIST_FOREACH(e_widget_ilist_items_get(cfdata->obj.list), l, it)
202 {
203 const char *file;
204
205 x++;
206 if (!it->selected) continue;
207 file = e_widget_ilist_item_data_get(it);
208 if (!file) break;
209 ecore_file_unlink(file);
210 e_widget_ilist_remove_num(cfdata->obj.list, x);
211 }
212 e_int_menus_cache_clear();
213 }
214
215 static void
_widget_list_selection_changed(void * data,Evas_Object * obj EINA_UNUSED)216 _widget_list_selection_changed(void *data, Evas_Object *obj EINA_UNUSED)
217 {
218 E_Config_Dialog_Data *cfdata = data;
219
220 e_widget_disabled_set(cfdata->obj.del, !e_widget_ilist_selected_count_get(cfdata->obj.list));
221 }
222
223