1 #include "e_mod_gadman.h"
2 
3 struct _E_Config_Dialog_Data
4 {
5    Evas_Object *o_avail;
6    Evas_Object *o_config;
7    Evas_Object *o_fm; //Filemanager Object
8    Evas_Object *o_sf; //Filemanager Scrollframe
9    Evas_Object *o_btn; //Filemanager updir button
10    E_Color     *color; //Custom Color
11    int          bg_type; //Type of background
12    int          anim_bg; //Anim the background
13    int          anim_gad; //Anim the gadgets
14    int          fmdir; //Filemanager dir (personal or system)
15    Eina_List *waiting;
16    E_Config_Dialog *cfd;
17 };
18 
19 static const char *gadman_layer_names[] =
20 {
21    N_("Background"),
22    N_("Overlay (Action Toggle)"),
23    NULL
24 };
25 
26 /* Local protos */
27 static void        *_create_data(E_Config_Dialog *cfd);
28 static void         _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
29 static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
30 static int          _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
31 static void         _avail_list_cb_change(void *data);
32 static void         _cb_fm_radio_change(void *data, Evas_Object *obj);
33 static void         _cb_color_changed(void *data, Evas_Object *o);
34 static void         _cb_fm_change(void *data, Evas_Object *obj, void *event_info);
35 static void         _cb_fm_sel_change(void *data, Evas_Object *obj, void *event_info);
36 static void         _cb_button_up(void *data1, void *data2);
37 
38 static int
_basic_check_changed(E_Config_Dialog * cfd EINA_UNUSED,E_Config_Dialog_Data * cfdata)39 _basic_check_changed(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
40 {
41    Eina_List *sel;
42 
43 #define CHECK(X, Y) \
44    if (Man->conf->X != cfdata->Y) return 1
45    CHECK(bg_type, bg_type);
46    CHECK(color_r, color->r);
47    CHECK(color_g, color->g);
48    CHECK(color_b, color->b);
49    CHECK(anim_bg, anim_bg);
50    CHECK(anim_gad, anim_gad);
51 #undef CHECK
52 
53    sel = e_fm2_selected_list_get(cfdata->o_fm);
54    if ((!sel) && (!Man->conf->custom_bg)) return 0;
55    eina_list_free(sel);
56    return 1;
57 }
58 
59 E_Config_Dialog *
_config_gadman_module(Evas_Object * parent EINA_UNUSED,const char * params EINA_UNUSED)60 _config_gadman_module(Evas_Object *parent EINA_UNUSED, const char *params EINA_UNUSED)
61 {
62    E_Config_Dialog *cfd;
63    E_Config_Dialog_View *v;
64    char buf[4096];
65 
66    /* check if config dialog exists ... */
67    if (e_config_dialog_find("E", "extensions/gadman"))
68      return NULL;
69 
70    /* ... else create it */
71    v = E_NEW(E_Config_Dialog_View, 1);
72    v->create_cfdata = _create_data;
73    v->free_cfdata = _free_data;
74    v->basic.create_widgets = _basic_create_widgets;
75    v->basic.apply_cfdata = _basic_apply_data;
76    v->basic.check_changed = _basic_check_changed;
77 
78    snprintf(buf, sizeof(buf), "%s/e-module-gadman.edj", Man->module->dir);
79    cfd = e_config_dialog_new(NULL, _("Desktop Gadgets"),
80                              "E", "extensions/gadman",
81                              buf, 0, v, Man);
82 
83    Man->config_dialog = cfd;
84    return Man->config_dialog;
85 }
86 
87 static void *
_create_data(E_Config_Dialog * cfd)88 _create_data(E_Config_Dialog *cfd)
89 {
90    E_Config_Dialog_Data *cfdata;
91 
92    cfdata = E_NEW(E_Config_Dialog_Data, 1);
93    cfdata->cfd = cfd;
94    cfdata->bg_type = Man->conf->bg_type;
95    if (Man->conf->custom_bg)
96      {
97         if (!strstr(Man->conf->custom_bg, e_user_homedir_get()))
98           cfdata->fmdir = 1;
99      }
100 
101    cfdata->color = E_NEW(E_Color, 1);
102    cfdata->color->r = Man->conf->color_r;
103    cfdata->color->g = Man->conf->color_g;
104    cfdata->color->b = Man->conf->color_b;
105    cfdata->color->a = Man->conf->color_a;
106    cfdata->anim_bg = Man->conf->anim_bg;
107    cfdata->anim_gad = Man->conf->anim_gad;
108 
109    e_color_update_rgb(cfdata->color);
110 
111    return cfdata;
112 }
113 
114 static void
_free_data(E_Config_Dialog * cfd EINA_UNUSED,E_Config_Dialog_Data * cfdata)115 _free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
116 {
117    Man->config_dialog = NULL;
118    E_FREE(cfdata->color);
119    E_FREE(cfdata);
120 }
121 
122 static void
_cb_config_del(void * data)123 _cb_config_del(void *data)
124 {
125    int layer;
126    Eina_List *l;
127    E_Gadcon *gc;
128    Eina_Bool del = EINA_TRUE;
129 
130    for (layer = 0; layer < GADMAN_LAYER_COUNT; layer++)
131      EINA_LIST_FOREACH(Man->gadcons[layer], l, gc)
132        if (gc->config_dialog)
133          {
134             del = EINA_FALSE;
135             break;
136          }
137    Man->waiting = eina_list_remove(Man->waiting, data);
138    if (del && Man->add) ecore_event_handler_del(Man->add);
139 }
140 
141 static void
_cb_config(void * data,void * data2 EINA_UNUSED)142 _cb_config(void *data, void *data2 EINA_UNUSED)
143 {
144    int x;
145    E_Config_Dialog_Data *cfdata = data;
146    Eina_List *l;
147    E_Gadcon *gc;
148 
149    x = e_widget_ilist_selected_get(cfdata->o_avail);
150    if (x < 0) return;
151 
152    EINA_LIST_FOREACH(Man->gadcons[x], l, gc)
153      {
154         if (gc->zone != e_win_client_get(cfdata->cfd->dia->win)->zone) continue;
155         if (gc->config_dialog) return;
156         e_int_gadcon_config_hook(gc, _("Desktop Gadgets"), E_GADCON_SITE_DESKTOP);
157         if (!Man->add)
158           Man->add = ecore_event_handler_add(E_EVENT_GADCON_CLIENT_ADD, (Ecore_Event_Handler_Cb)gadman_gadget_add_handler, NULL);
159         Man->waiting = eina_list_append(Man->waiting, gc);
160         e_object_data_set(E_OBJECT(gc->config_dialog), cfdata);
161         e_object_del_attach_func_set(E_OBJECT(gc->config_dialog), _cb_config_del);
162         break;
163      }
164 }
165 
166 static Evas_Object *
_basic_create_widgets(E_Config_Dialog * cfd EINA_UNUSED,Evas * evas,E_Config_Dialog_Data * cfdata)167 _basic_create_widgets(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata)
168 {
169    Evas_Object *o, *ol, *ob, *ow, *ft, *of, *otb;
170    E_Radio_Group *rg;
171    Evas_Coord mw, mh;
172    E_Fm2_Config fmc;
173    char path[PATH_MAX];
174    int layer;
175 
176    otb = e_widget_toolbook_add(evas, 48 * e_scale, 48 * e_scale);
177    o = e_widget_list_add(evas, 0, 0);
178 
179    of = e_widget_framelist_add(evas, _("Available Layers"), 0);
180 
181    //o_avail  List of available layers
182    ol = e_widget_ilist_add(evas, 24, 24, NULL);
183    cfdata->o_avail = ol;
184    for (layer = 0; layer < GADMAN_LAYER_COUNT; layer++)
185      e_widget_ilist_append(ol, NULL, _(gadman_layer_names[layer]), _avail_list_cb_change, cfdata, NULL);
186    e_widget_framelist_object_append(of, ol);
187 
188    //o_config  Button to configure a layer
189    ob = e_widget_button_add(evas, _("Configure Layer"), NULL, _cb_config, cfdata, NULL);
190    e_widget_disabled_set(ob, 1);
191    cfdata->o_config = ob;
192    evas_object_size_hint_min_get(ob, &mw, &mh);
193    e_widget_framelist_object_append_full(of, ob,
194                                          1, 1, /* fill */
195                                          1, 0, /* expand */
196                                          0.5, 0.5, /* align */
197                                          mw, mh, /* min */
198                                          99999, 99999 /* max */
199                                          );
200 
201    e_widget_list_object_append(o, of, 1, 1, 0.5);
202 
203    e_widget_toolbook_page_append(otb, NULL, _("Layers"), o, 1, 1, 1, 1, 0.5, 0.0);
204    /////////////////////////////////////////////////////////////////////
205    ft = e_widget_table_add(e_win_evas_win_get(evas), 0);
206 
207    //Background mode
208    of = e_widget_frametable_add(evas, _("Mode"), 0);
209    rg = e_widget_radio_group_new(&(cfdata->bg_type));
210    ow = e_widget_radio_add(evas, _("Theme Defined"), BG_STD, rg);
211    //~ evas_object_smart_callback_add(ow, "changed", _cb_method_change, cfdata);
212    e_widget_frametable_object_append(of, ow, 0, 0, 1, 1, 1, 0, 1, 0);
213    ow = e_widget_radio_add(evas, _("Custom Image"), BG_CUSTOM, rg);
214    //~ evas_object_smart_callback_add(cfdata->o_custom, "changed",
215    //~ _cb_method_change, cfdata);
216    e_widget_frametable_object_append(of, ow, 0, 1, 1, 1, 1, 0, 1, 0);
217    ow = e_widget_radio_add(evas, _("Custom Color"), BG_COLOR, rg);
218    //~ evas_object_smart_callback_add(cfdata->o_custom, "changed",
219    //~ _cb_method_change, cfdata);
220    e_widget_frametable_object_append(of, ow, 0, 2, 1, 1, 1, 0, 1, 0);
221    ow = e_widget_radio_add(evas, _("Transparent"), BG_TRANS, rg);
222    //~ evas_object_smart_callback_add(cfdata->o_custom, "changed",
223    //~ _cb_method_change, cfdata);
224    e_widget_frametable_object_append(of, ow, 0, 3, 1, 1, 1, 0, 1, 0);
225    e_widget_table_object_append(ft, of, 0, 0, 1, 1, 1, 1, 1, 1);
226 
227    //Animations
228    of = e_widget_frametable_add(evas, _("Animations"), 0);
229    ow = e_widget_check_add(evas, _("Background"), &(cfdata->anim_bg));
230    e_widget_frametable_object_append(of, ow, 0, 0, 1, 1, 1, 0, 1, 0);
231 
232    ow = e_widget_check_add(evas, _("Gadgets"), &(cfdata->anim_gad));
233    e_widget_frametable_object_append(of, ow, 0, 1, 1, 1, 1, 0, 1, 0);
234 
235    e_widget_table_object_append(ft, of, 0, 1, 1, 1, 1, 1, 1, 1);
236 
237    //Custom Color
238    of = e_widget_framelist_add(evas, _("Custom Color"), 0);
239    ow = e_widget_color_well_add(evas, cfdata->color, 1);
240    e_widget_framelist_object_append(of, ow);
241    e_widget_on_change_hook_set(ow, _cb_color_changed, cfdata);
242    e_widget_table_object_append(ft, of, 0, 2, 1, 1, 1, 1, 1, 1);
243 
244    //Background filemanager chooser
245    of = e_widget_frametable_add(evas, _("Custom Image"), 0);
246    rg = e_widget_radio_group_new(&(cfdata->fmdir));
247 
248    ow = e_widget_radio_add(evas, _("Personal"), 0, rg);
249    e_widget_on_change_hook_set(ow, _cb_fm_radio_change, cfdata);
250    e_widget_frametable_object_append(of, ow, 0, 0, 1, 1, 1, 1, 0, 0);
251 
252    ow = e_widget_radio_add(evas, _("System"), 1, rg);
253    e_widget_on_change_hook_set(ow, _cb_fm_radio_change, cfdata);
254    e_widget_frametable_object_append(of, ow, 1, 0, 1, 1, 1, 1, 0, 0);
255 
256    cfdata->o_btn = e_widget_button_add(evas, _("Go up a Directory"),
257                                        "widgets/up_dir", _cb_button_up,
258                                        cfdata, NULL);
259    e_widget_frametable_object_append(of, cfdata->o_btn, 0, 1, 2, 1, 1, 1, 1, 0);
260 
261    if (cfdata->fmdir == 1)
262      e_prefix_data_concat_static(path, "data/backgrounds");
263    else
264      e_user_dir_concat_static(path, "backgrounds");
265 
266    ow = e_fm2_add(evas);
267    cfdata->o_fm = ow;
268    memset(&fmc, 0, sizeof(E_Fm2_Config));
269    fmc.view.mode = E_FM2_VIEW_MODE_LIST;
270    fmc.view.open_dirs_in_place = 1;
271    fmc.view.selector = 1;
272    fmc.view.single_click = 0;
273    fmc.view.no_subdir_jump = 0;
274    fmc.icon.list.w = 36;
275    fmc.icon.list.h = 36;
276    fmc.icon.fixed.w = 1;
277    fmc.icon.fixed.h = 1;
278    fmc.icon.extension.show = 0;
279    fmc.icon.key_hint = NULL;
280    fmc.list.sort.no_case = 1;
281    fmc.list.sort.dirs.first = 0;
282    fmc.list.sort.dirs.last = 1;
283    fmc.selection.single = 1;
284    fmc.selection.windows_modifiers = 0;
285    e_fm2_config_set(ow, &fmc);
286    e_fm2_icon_menu_flags_set(ow, E_FM2_MENU_NO_SHOW_HIDDEN);
287    e_fm2_path_set(ow, path, "/");
288 
289    evas_object_smart_callback_add(ow, "selection_change",
290                                   _cb_fm_sel_change, cfdata);
291    evas_object_smart_callback_add(ow, "changed", _cb_fm_change, cfdata);
292 
293    cfdata->o_sf = e_widget_scrollframe_pan_add(evas, ow, e_fm2_pan_set,
294                                                e_fm2_pan_get,
295                                                e_fm2_pan_max_get,
296                                                e_fm2_pan_child_size_get);
297    e_widget_size_min_set(cfdata->o_sf, 150, 250);
298    e_widget_frametable_object_append(of, cfdata->o_sf, 0, 2, 2, 1, 1, 1, 1, 1);
299    e_widget_table_object_append(ft, of, 2, 0, 1, 3, 1, 1, 1, 1);
300 
301 
302    e_widget_toolbook_page_append(otb, NULL, _("Background Options"), ft, 0, 0, 0, 0, 0.5, 0.0);
303    e_widget_toolbook_page_show(otb, 0);
304 
305    return otb;
306 }
307 
308 static int
_basic_apply_data(E_Config_Dialog * cfd EINA_UNUSED,E_Config_Dialog_Data * cfdata)309 _basic_apply_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
310 {
311    Eina_List *sel;
312    const char *p = NULL;
313    E_Fm2_Icon_Info *ic;
314    char path[PATH_MAX];
315 
316    Man->conf->bg_type = cfdata->bg_type;
317    Man->conf->color_r = cfdata->color->r;
318    Man->conf->color_g = cfdata->color->g;
319    Man->conf->color_b = cfdata->color->b;
320    Man->conf->color_a = 255;
321    Man->conf->anim_bg = cfdata->anim_bg;
322    Man->conf->anim_gad = cfdata->anim_gad;
323 
324    p = e_fm2_real_path_get(cfdata->o_fm);
325    sel = e_fm2_selected_list_get(cfdata->o_fm);
326    if (sel && p)
327      {
328         ic = sel->data;
329         if (ic->file)
330           {
331              snprintf(path, sizeof(path), "%s/%s", p, ic->file);
332              eina_stringshare_replace(&Man->conf->custom_bg, path);
333           }
334         eina_list_free(sel);
335      }
336 
337    gadman_gadget_edit_end(NULL, NULL, NULL, NULL);
338    e_config_save_queue();
339    gadman_update_bg();
340 
341    return 1;
342 }
343 
344 //Basic Callbacks
345 static void
_avail_list_cb_change(void * data)346 _avail_list_cb_change(void *data)
347 {
348    E_Config_Dialog_Data *cfdata;
349 
350    if (!(cfdata = data)) return;
351    e_widget_disabled_set(cfdata->o_config, 0);
352 }
353 
354 //Advanced Callbacks
355 static void
_cb_color_changed(void * data,Evas_Object * o EINA_UNUSED)356 _cb_color_changed(void *data, Evas_Object *o EINA_UNUSED)
357 {
358    E_Config_Dialog_Data *cfdata;
359    cfdata = data;
360    if (!cfdata) return;
361    e_color_update_rgb(cfdata->color);
362 }
363 
364 static void
_cb_fm_radio_change(void * data,Evas_Object * obj EINA_UNUSED)365 _cb_fm_radio_change(void *data, Evas_Object *obj EINA_UNUSED)
366 {
367    E_Config_Dialog_Data *cfdata;
368    char path[PATH_MAX];
369 
370    cfdata = data;
371    if (!cfdata->o_fm) return;
372    if (cfdata->fmdir == 0)
373      e_user_dir_concat_static(path, "backgrounds");
374    else
375      e_prefix_data_concat_static(path, "data/backgrounds");
376    e_fm2_path_set(cfdata->o_fm, path, "/");
377 }
378 
379 static void
_cb_fm_change(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)380 _cb_fm_change(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
381 {
382    E_Config_Dialog_Data *cfdata;
383    const char *p;
384    char path[PATH_MAX];
385    size_t len;
386 
387    cfdata = data;
388    if (!Man->conf->custom_bg) return;
389    if (!cfdata->o_fm) return;
390 
391    p = e_fm2_real_path_get(cfdata->o_fm);
392    if (!p) return;
393 
394    if (strncmp(p, Man->conf->custom_bg, strlen(p))) return;
395 
396    len = e_user_dir_concat_static(path, "backgrounds");
397    if (!strncmp(Man->conf->custom_bg, path, len))
398      p = Man->conf->custom_bg + len + 1;
399    else
400      {
401         len = e_prefix_data_concat_static(path, "data/backgrounds");
402         if (!strncmp(Man->conf->custom_bg, path, len))
403           p = Man->conf->custom_bg + len + 1;
404         else
405           p = Man->conf->custom_bg;
406      }
407 
408    e_fm2_select_set(cfdata->o_fm, p, 1);
409    e_fm2_file_show(cfdata->o_fm, p);
410 }
411 
412 static void
_cb_fm_sel_change(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)413 _cb_fm_sel_change(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
414 {
415    E_Config_Dialog_Data *cfdata;
416 
417    cfdata = data;
418    e_widget_change(cfdata->o_sf);
419 }
420 
421 static void
_cb_button_up(void * data1,void * data2 EINA_UNUSED)422 _cb_button_up(void *data1, void *data2 EINA_UNUSED)
423 {
424    E_Config_Dialog_Data *cfdata;
425 
426    cfdata = data1;
427    if (!cfdata->o_fm) return;
428 
429    e_fm2_parent_go(cfdata->o_fm);
430    e_widget_scrollframe_child_pos_set(cfdata->o_sf, 0, 0);
431 }
432