Migrating source code to RSA from private.
[platform/core/uifw/e17.git] / src / modules / conf_paths / e_int_config_paths.c
1 #include "e.h"
2
3 typedef struct _E_Path_Pair E_Path_Pair;
4 typedef struct _CFPath_Change_Data CFPath_Change_Data;
5
6 static void *_create_data(E_Config_Dialog *cfd);
7 static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
8 static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
9 static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
10
11 static void _ilist_update(Evas_Object *obj, CFPath_Change_Data *old, CFPath_Change_Data *new);
12 static void _ilist_path_cb_change(void *data);
13
14 struct _E_Path_Pair
15 {
16    E_Path     *path;
17    const char *path_description;
18 };
19
20 struct _CFPath_Change_Data
21 {
22    E_Path               *path;
23    Eina_List            *new_user_path;
24    int                   dirty;
25    E_Config_Dialog_Data *cfdata;
26 };
27      
28 struct _E_Config_Dialog_Data
29 {
30    E_Config_Dialog *cfd;
31
32    /* Current data */
33    CFPath_Change_Data *cur_pcd;
34
35    Eina_List        *pcd_list;
36    E_Path_Pair      *paths_available;
37    struct
38      {
39         Evas_Object *path_list;
40         Evas_Object *default_list; /* Read Only */
41         Evas_Object *user_list; /* Editable */
42      } gui;
43 };
44
45 E_Config_Dialog *
46 e_int_config_paths(E_Container *con, const char *params __UNUSED__)
47 {
48    E_Config_Dialog *cfd;
49    E_Config_Dialog_View *v;
50
51    if (e_config_dialog_find("E", "advanced/search_directories")) return NULL;
52    v = E_NEW(E_Config_Dialog_View, 1);
53    
54    v->create_cfdata           = _create_data;
55    v->free_cfdata             = _free_data;
56    v->basic.create_widgets    = _basic_create_widgets;
57    v->basic.apply_cfdata      = _basic_apply_data;
58    
59    cfd = e_config_dialog_new(con, _("Search Path Settings"),
60                              "E", "advanced/search_directories",
61                              "preferences-directories", 0, v, NULL);
62    return cfd;
63 }
64
65 static void
66 _fill_data(E_Config_Dialog_Data *cfdata)
67 {
68    cfdata->paths_available = E_NEW(E_Path_Pair, 10);
69    cfdata->paths_available[0].path =             path_data;
70    cfdata->paths_available[0].path_description = _("Data");
71    cfdata->paths_available[1].path =             path_images;
72    cfdata->paths_available[1].path_description = _("Images");
73    cfdata->paths_available[2].path =             path_fonts;
74    cfdata->paths_available[2].path_description = _("Fonts");
75    cfdata->paths_available[3].path =             path_themes;
76    cfdata->paths_available[3].path_description = _("Themes");
77    cfdata->paths_available[4].path =             path_icons;
78    cfdata->paths_available[4].path_description = _("Icons");
79    cfdata->paths_available[5].path =             path_modules;
80    cfdata->paths_available[5].path_description = _("Modules");
81    cfdata->paths_available[6].path =             path_backgrounds;
82    cfdata->paths_available[6].path_description = _("Backgrounds");
83    cfdata->paths_available[7].path =             path_messages;
84    cfdata->paths_available[7].path_description = _("Messages");
85    cfdata->paths_available[8].path =             NULL;
86    cfdata->paths_available[8].path_description = NULL;
87    return;
88 }
89
90 static void *
91 _create_data(E_Config_Dialog *cfd)
92 {
93    E_Config_Dialog_Data *cfdata;
94
95    cfdata = E_NEW(E_Config_Dialog_Data, 1);
96    cfdata->cfd = cfd;
97    _fill_data(cfdata);
98    return cfdata;
99 }
100
101 static void
102 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
103 {
104    while (cfdata->pcd_list)
105      {
106         CFPath_Change_Data *pcd;
107
108         pcd = cfdata->pcd_list->data;
109         while (pcd->new_user_path)
110           {
111              const char *dir;
112              
113              dir = pcd->new_user_path->data;
114              eina_stringshare_del(dir);
115              pcd->new_user_path = 
116                eina_list_remove_list(pcd->new_user_path, pcd->new_user_path);
117           }
118         free(pcd);
119         cfdata->pcd_list = 
120           eina_list_remove_list(cfdata->pcd_list, cfdata->pcd_list);
121      }
122    free(cfdata->paths_available);
123    E_FREE(cfdata);
124 }
125
126 static int
127 _basic_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
128 {        
129    Eina_List *l;
130    Eina_List *ll;
131    
132    _ilist_update(cfdata->gui.user_list, cfdata->cur_pcd, NULL);
133
134    for (l = cfdata->pcd_list; l; l = l->next)
135      {
136         CFPath_Change_Data *pcd;
137         
138         pcd = l->data;
139         if (pcd->new_user_path)
140           {
141              e_path_user_path_clear(pcd->path);
142              for (ll = pcd->new_user_path; ll; ll = ll->next)
143                {
144                   const char *dir;
145
146                   dir = ll->data;
147                   e_path_user_path_append(pcd->path, dir);
148                }
149           }
150         else if (*(pcd->path->user_dir_list) && pcd->dirty)
151           e_path_user_path_clear(pcd->path);
152      }
153    e_config_save_queue();
154    return 1;
155 }
156
157 static Evas_Object *
158 _basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
159 {
160    Evas_Object *o, *of, *ob;
161    int i;
162
163    o = e_widget_table_add(evas, 0);
164
165    of = e_widget_framelist_add(evas, _("E Paths"), 0);
166    ob = e_widget_ilist_add(evas, 0, 0, NULL);
167    cfdata->gui.path_list = ob;
168    e_widget_size_min_set(ob, 170, 100);
169
170    evas_event_freeze(evas_object_evas_get(cfdata->gui.path_list));
171    edje_freeze();
172    e_widget_ilist_freeze(cfdata->gui.path_list);
173    
174    /* Fill In Ilist */
175    for (i = 0; cfdata->paths_available[i].path; i++)
176      {
177         CFPath_Change_Data *pcd;
178
179         pcd = E_NEW(CFPath_Change_Data, 1);
180         pcd->path = cfdata->paths_available[i].path;
181         pcd->cfdata = cfdata;
182         cfdata->pcd_list = eina_list_append(cfdata->pcd_list, pcd);
183         e_widget_ilist_append(ob, NULL, 
184                               cfdata->paths_available[i].path_description, 
185                               _ilist_path_cb_change, pcd, NULL);
186      }
187
188    e_widget_ilist_go(ob);
189    e_widget_ilist_thaw(cfdata->gui.path_list);
190    edje_thaw();
191    evas_event_thaw(evas_object_evas_get(cfdata->gui.path_list));
192    
193    e_widget_framelist_object_append(of, ob);
194    e_widget_table_object_append(o, of, 0, 0, 1, 1, 1, 1, 1, 1);
195
196    of = e_widget_framelist_add(evas, _("Default Directories"), 0);
197    ob = e_widget_ilist_add(evas, 0, 0, NULL);
198    cfdata->gui.default_list = ob;
199    e_widget_size_min_set(ob, 100, 100);
200    e_widget_framelist_object_append(of, ob);
201    e_widget_table_object_append(o, of, 0, 1, 1, 1, 1, 1, 1, 1);
202
203    of = e_widget_framelist_add(evas, _("User Defined Directories"), 0);
204    ob = e_widget_config_list_add(evas, e_widget_entry_add, 
205                                  _("New Directory"), 2);
206    e_widget_disabled_set(ob, 1);
207    cfdata->gui.user_list = ob;
208    e_widget_framelist_object_append(of, ob);
209    e_widget_table_object_append(o, of, 1, 0, 1, 2, 0, 1, 0, 1);
210    
211    e_dialog_resizable_set(cfd->dia, 1);
212    return o;
213 }
214
215 static void
216 _ilist_path_cb_change(void *data)
217 {
218    CFPath_Change_Data *pcd;
219    Eina_List *default_list;
220    Eina_List *l;
221    
222    pcd = data;
223    default_list = pcd->path->default_dir_list;
224
225    /* Update Default List */
226    evas_event_freeze(evas_object_evas_get(pcd->cfdata->gui.default_list));
227    edje_freeze();
228    e_widget_ilist_freeze(pcd->cfdata->gui.default_list);
229    
230    e_widget_ilist_clear(pcd->cfdata->gui.default_list);
231    for (l = default_list; l; l = l->next)
232      {
233         const char *dir;
234
235         dir = ((E_Path_Dir *)l->data)->dir;
236         e_widget_ilist_append(pcd->cfdata->gui.default_list, 
237                               NULL, dir, NULL, NULL, NULL);
238      }
239    e_widget_ilist_go(pcd->cfdata->gui.default_list);
240
241    e_widget_ilist_thaw(pcd->cfdata->gui.default_list);
242    edje_thaw();
243    evas_event_thaw(evas_object_evas_get(pcd->cfdata->gui.default_list));
244    
245    _ilist_update(pcd->cfdata->gui.user_list,
246                  pcd->cfdata->cur_pcd, /* Path data to save */
247                  pcd); /* New Path to show */
248    
249    pcd->cfdata->cur_pcd = pcd;
250 }
251
252 static void 
253 _ilist_update(Evas_Object *obj, CFPath_Change_Data *old, CFPath_Change_Data *new)
254 {
255    /* Save current data to old path */
256    if (old)
257      {
258         int i;
259         
260         old->dirty = 1;
261         while (old->new_user_path)
262           {
263              const char *dir;
264              
265              dir = old->new_user_path->data;
266              eina_stringshare_del(dir);
267              old->new_user_path = 
268                eina_list_remove_list(old->new_user_path, old->new_user_path);
269           }
270         
271         for (i = 0; i < e_widget_config_list_count(obj); i++)
272           {
273              const char *dir;
274
275              dir = e_widget_config_list_nth_get(obj, i);
276              old->new_user_path = 
277                eina_list_append(old->new_user_path, eina_stringshare_add(dir));
278           }
279      }
280
281    if (!new) return;
282    
283    /* Fill list with selected data */
284    e_widget_disabled_set(obj, 0);
285    e_widget_config_list_clear(obj);
286    
287    if (new->new_user_path)
288      {
289         Eina_List *l;
290         Eina_List *user_path;
291         
292         user_path = new->new_user_path;
293         
294         for (l = user_path; l; l = l->next)
295           {
296              const char *dir;
297              
298              dir = l->data;
299              e_widget_config_list_append(obj, dir);
300           }
301      }
302    else if (*(new->path->user_dir_list) && !new->dirty)
303      {
304         Eina_List *l;
305         Eina_List *user_path;
306         
307         user_path = *(new->path->user_dir_list);
308
309         for (l = user_path; l; l = l->next)
310           {
311              E_Path_Dir *epd;
312              
313              epd = l->data;
314              e_widget_config_list_append(obj, epd->dir);
315           }
316      } 
317 }