1 #include "e.h"
2 #include "e_mod_main.h"
3 
4 struct _E_Config_Dialog_Data
5 {
6    Evas_Object *o_list, *o_up;
7    int          fmdir;
8    char        *bg;
9    int          hide_logo;
10 };
11 
12 /* local function prototypes */
13 static void        *_create_data(E_Config_Dialog *cfd);
14 static void         _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
15 static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
16 static void         _cb_dir_changed(void *data, Evas_Object *obj, void *event);
17 static void         _cb_sel_changed(void *data, Evas_Object *obj, void *event);
18 static void         _cb_files_changed(void *data, Evas_Object *obj, void *event);
19 static void         _cb_files_deleted(void *data, Evas_Object *obj, void *event);
20 static void         _cb_radio_changed(void *data, Evas_Object *obj, void *event);
21 static void         _cb_dir_up(void *data1, void *data2);
22 
23 E_Config_Dialog *
e_int_config_desklock_fsel(E_Config_Dialog * parent,Evas_Object * bg)24 e_int_config_desklock_fsel(E_Config_Dialog *parent, Evas_Object *bg)
25 {
26    E_Config_Dialog *cfd;
27    E_Config_Dialog_View *v;
28 
29    v = E_NEW(E_Config_Dialog_View, 1);
30    v->create_cfdata = _create_data;
31    v->free_cfdata = _free_data;
32    v->basic.create_widgets = _basic_create;
33    v->basic_only = 1;
34    v->normal_win = 1;
35 
36    cfd = e_config_dialog_new(parent->dia->win, _("Select a Background..."),
37                              "E", "_desklock_fsel_dialog",
38                              "enlightenment/background", 0, v, bg);
39    cfd->data = parent;
40    e_object_data_set(E_OBJECT(cfd), bg);
41    return cfd;
42 }
43 
44 /* local functions */
45 static void *
_create_data(E_Config_Dialog * cfd)46 _create_data(E_Config_Dialog *cfd)
47 {
48    E_Config_Dialog_Data *cfdata;
49 
50    cfdata = E_NEW(E_Config_Dialog_Data, 1);
51    cfdata->hide_logo = !!evas_object_data_get(cfd->data, "hide_logo");
52 
53    return cfdata;
54 }
55 
56 static void
_free_data(E_Config_Dialog * cfd,E_Config_Dialog_Data * cfdata)57 _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
58 {
59    const char *bg_file = NULL;
60    Eina_Bool hide_logo = cfdata->hide_logo;
61 
62    if (cfdata->bg) bg_file = strdup(cfdata->bg);
63    E_FREE(cfdata->bg);
64    E_FREE(cfdata);
65    e_int_config_desklock_fsel_done(cfd->data, e_object_data_get(E_OBJECT(cfd)), bg_file, hide_logo);
66 }
67 
68 static Evas_Object *
_basic_create(E_Config_Dialog * cfd EINA_UNUSED,Evas * evas,E_Config_Dialog_Data * cfdata)69 _basic_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata)
70 {
71    Evas_Object *o, *ow, *ot, *rt;
72    E_Radio_Group *rg;
73    const char *file = NULL;
74    char path[PATH_MAX];
75    size_t len;
76 
77    /* Content */
78    o = e_widget_list_add(evas, 0, 0);
79 
80    len = e_user_dir_concat_static(path, "backgrounds");
81    e_widget_preview_file_get(cfd->data, &file, NULL);
82    if (file)
83      {
84         cfdata->bg = strdup(file);
85         cfdata->fmdir = strncmp(file, path, len);
86         if (cfdata->fmdir)
87           e_prefix_data_concat_static(path, "data/backgrounds");
88      }
89    else
90      cfdata->bg = NULL;
91 
92    rg = e_widget_radio_group_new(&(cfdata->fmdir));
93    ot = e_widget_table_add(e_win_evas_win_get(evas), 0);
94    rt = e_widget_table_add(e_win_evas_win_get(evas), 1);
95 
96    ow = e_widget_radio_add(evas, _("Personal"), 0, rg);
97    evas_object_smart_callback_add(ow, "changed", _cb_radio_changed, cfdata);
98    e_widget_table_object_append(rt, ow, 0, 0, 1, 1, 1, 1, 0, 0);
99    ow = e_widget_radio_add(evas, _("System"), 1, rg);
100    evas_object_smart_callback_add(ow, "changed", _cb_radio_changed, cfdata);
101    e_widget_table_object_append(rt, ow, 1, 0, 1, 1, 1, 1, 0, 0);
102    e_widget_table_object_append(ot, rt, 0, 0, 1, 1, 0, 0, 0, 0);
103    ow = e_widget_button_add(evas, _("Go up a Directory"), "go-up",
104                             _cb_dir_up, cfdata, NULL);
105    cfdata->o_up = ow;
106    e_widget_table_object_append(ot, ow, 0, 1, 1, 1, 0, 0, 0, 0);
107 
108    cfdata->o_list = e_widget_flist_add(evas);
109    {
110       E_Fm2_Config *cfg;
111       cfg = e_widget_flist_config_get(cfdata->o_list);
112       cfg->view.no_click_rename = 1;
113    }
114    evas_object_smart_callback_add(cfdata->o_list, "dir_changed",
115                                   _cb_dir_changed, cfdata);
116    evas_object_smart_callback_add(cfdata->o_list, "selection_change",
117                                   _cb_sel_changed, cfdata);
118    evas_object_smart_callback_add(cfdata->o_list, "changed",
119                                   _cb_files_changed, cfdata);
120    evas_object_smart_callback_add(cfdata->o_list, "files_deleted",
121                                   _cb_files_deleted, cfdata);
122    e_widget_flist_path_set(cfdata->o_list, path, "/");
123    e_widget_size_min_set(cfdata->o_list, 200, 160);
124    e_widget_table_object_append(ot, cfdata->o_list, 0, 2, 1, 1, 1, 1, 1, 1);
125 
126    e_widget_list_object_append(o, ot, 1, 1, 0.5);
127    ow = e_widget_check_add(evas, _("Hide Logo"), &cfdata->hide_logo);
128    e_widget_list_object_append(o, ow, 1, 1, 0.5);
129 
130    return o;
131 }
132 
133 static void
_cb_dir_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event EINA_UNUSED)134 _cb_dir_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
135 {
136    E_Config_Dialog_Data *cfdata;
137 
138    if (!(cfdata = data)) return;
139    e_widget_disabled_set(cfdata->o_up,
140                          !e_widget_flist_has_parent_get(cfdata->o_list));
141 }
142 
143 static void
_cb_sel_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event EINA_UNUSED)144 _cb_sel_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
145 {
146    E_Config_Dialog_Data *cfdata;
147    Eina_List *sel;
148    E_Fm2_Icon_Info *ici;
149    const char *real_path;
150    char buff[PATH_MAX];
151 
152    if (!(cfdata = data)) return;
153    if (!(sel = e_widget_flist_selected_list_get(cfdata->o_list))) return;
154    ici = sel->data;
155    real_path = e_widget_flist_real_path_get(cfdata->o_list);
156    if (!strcmp(real_path, "/"))
157      snprintf(buff, sizeof(buff), "/%s", ici->file);
158    else
159      snprintf(buff, sizeof(buff), "%s/%s", real_path, ici->file);
160    eina_list_free(sel);
161    if (ecore_file_is_dir(buff)) return;
162    E_FREE(cfdata->bg);
163    cfdata->bg = strdup(buff);
164 }
165 
166 static void
_cb_files_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event EINA_UNUSED)167 _cb_files_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
168 {
169    E_Config_Dialog_Data *cfdata;
170    const char *p = NULL;
171    char buff[PATH_MAX];
172    size_t len;
173 
174    if (!(cfdata = data)) return;
175    if (!cfdata->bg) return;
176    p = e_widget_flist_real_path_get(cfdata->o_list);
177    if (p)
178      {
179         if (strncmp(p, cfdata->bg, strlen(p))) return;
180      }
181    else return;
182 
183    len = e_user_dir_concat_static(buff, "backgrounds");
184    if (!strncmp(cfdata->bg, buff, len))
185      p = cfdata->bg + len + 1;
186    else
187      {
188         len = e_prefix_data_concat_static(buff, "data/backgrounds");
189         if (!strncmp(cfdata->bg, buff, len))
190           p = cfdata->bg + len + 1;
191         else
192           p = cfdata->bg;
193      }
194    e_widget_flist_select_set(cfdata->o_list, p, 1);
195    e_widget_flist_file_show(cfdata->o_list, p);
196 }
197 
198 static void
_cb_files_deleted(void * data,Evas_Object * obj EINA_UNUSED,void * event EINA_UNUSED)199 _cb_files_deleted(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
200 {
201    E_Config_Dialog_Data *cfdata;
202    Eina_List *sel, *all, *n;
203    E_Fm2_Icon_Info *ici, *ic;
204 
205    if (!(cfdata = data)) return;
206    if (!cfdata->bg) return;
207    if (!(all = e_widget_flist_all_list_get(cfdata->o_list))) return;
208    if (!(sel = e_widget_flist_selected_list_get(cfdata->o_list))) return;
209    if (!(ici = sel->data)) return;
210    all = eina_list_data_find_list(all, ici);
211    n = eina_list_next(all);
212    if (!n)
213      {
214         if (!(n = eina_list_prev(all))) return;
215      }
216    if (!(ic = n->data)) return;
217    e_widget_flist_select_set(cfdata->o_list, ic->file, 1);
218    e_widget_flist_file_show(cfdata->o_list, ic->file);
219    eina_list_free(n);
220    evas_object_smart_callback_call(cfdata->o_list, "selection_change", cfdata);
221 }
222 
223 static void
_cb_radio_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event EINA_UNUSED)224 _cb_radio_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
225 {
226    E_Config_Dialog_Data *cfdata;
227    char path[PATH_MAX];
228 
229    if (!(cfdata = data)) return;
230    if (cfdata->fmdir == 1)
231      e_prefix_data_concat_static(path, "data/backgrounds");
232    else
233      e_user_dir_concat_static(path, "backgrounds");
234    e_widget_flist_path_set(cfdata->o_list, path, "/");
235 }
236 
237 static void
_cb_dir_up(void * data1,void * data2 EINA_UNUSED)238 _cb_dir_up(void *data1, void *data2 EINA_UNUSED)
239 {
240    E_Config_Dialog_Data *cfdata;
241 
242    if (!(cfdata = data1)) return;
243    e_widget_flist_parent_go(cfdata->o_list);
244 }
245 
246