f16e814eaad5ac7a375ff1d2f13367ecdf2ceb72
[platform/upstream/enlightenment.git] / src / bin / e_int_shelf_config.c
1 #include "e.h"
2
3 struct _E_Config_Dialog_Data
4 {
5    E_Shelf        *es;
6    E_Config_Shelf *escfg;
7
8    Evas_Object    *o_autohide, *o_desk_list, *o_overlap;
9    Eina_List      *autohide_list, *desk_list;
10
11    int             layer, overlap;
12    int             orient, fit_along;
13    int             size;
14    const char     *style;
15    int             autohide, autohide_show_action;
16    double          hide_timeout, hide_duration;
17    int             desk_show_mode;
18    Eina_List      *handlers;
19 };
20
21 /* local function prototypes */
22 static void        *_create_data(E_Config_Dialog *cfd);
23 static void         _fill_data(E_Config_Dialog_Data *cfdata);
24 static int          _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
25 static void         _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata);
26 static Evas_Object *_basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata);
27 static int          _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
28 static void         _fill_styles(E_Config_Dialog_Data *cfdata, Evas_Object *obj);
29 static void         _cb_autohide_change(void *data, Evas_Object *obj __UNUSED__);
30 static void         _fill_desks(E_Config_Dialog_Data *cfdata);
31
32 EAPI void
33 e_int_shelf_config(E_Shelf *es)
34 {
35    E_Config_Dialog_View *v;
36
37    if (!(v = E_NEW(E_Config_Dialog_View, 1))) return;
38
39    v->create_cfdata = _create_data;
40    v->free_cfdata = _free_data;
41    v->basic.create_widgets = _basic_create;
42    v->basic.apply_cfdata = _basic_apply;
43    v->basic.check_changed = _basic_check_changed;
44
45    es->config_dialog =
46      e_config_dialog_new(NULL, _("Shelf Settings"),
47                          "E", "_shelf_config_dialog",
48                          "preferences-desktop-shelf", 0, v, es);
49    elm_win_center(es->config_dialog->dia->win, 1, 1);
50 }
51
52 /* local functions */
53 static Eina_Bool
54 _shelf_event_add(E_Config_Dialog_Data *cfdata, int type __UNUSED__, E_Event_Shelf *ev)
55 {
56    if (ev->shelf->cfg == cfdata->escfg)
57      cfdata->es = ev->shelf;
58    return ECORE_CALLBACK_RENEW;
59 }
60
61 static Eina_Bool
62 _shelf_event_del(E_Config_Dialog_Data *cfdata, int type __UNUSED__, E_Event_Shelf *ev)
63 {
64    if (ev->shelf == cfdata->es)
65      cfdata->es = NULL;
66    return ECORE_CALLBACK_RENEW;
67 }
68
69 static void *
70 _create_data(E_Config_Dialog *cfd)
71 {
72    E_Config_Dialog_Data *cfdata;
73
74    cfdata = E_NEW(E_Config_Dialog_Data, 1);
75    cfdata->es = cfd->data;
76    cfdata->escfg = cfdata->es->cfg;
77    E_LIST_HANDLER_APPEND(cfdata->handlers, E_EVENT_SHELF_ADD, _shelf_event_add, cfdata);
78    E_LIST_HANDLER_APPEND(cfdata->handlers, E_EVENT_SHELF_DEL, _shelf_event_del, cfdata);
79    _fill_data(cfdata);
80    return cfdata;
81 }
82
83 static void
84 _fill_data(E_Config_Dialog_Data *cfdata)
85 {
86    /* stacking */
87    cfdata->layer = cfdata->escfg->layer;
88    cfdata->overlap = cfdata->escfg->overlap;
89
90    /* position */
91    cfdata->orient = cfdata->escfg->orient;
92    cfdata->fit_along = cfdata->escfg->fit_along;
93
94    /* size */
95    cfdata->size = cfdata->escfg->size;
96
97    /* style */
98    if (cfdata->escfg->style)
99      cfdata->style = eina_stringshare_ref(cfdata->escfg->style);
100    else
101      cfdata->style = eina_stringshare_add("");
102
103    /* autohide */
104    cfdata->autohide = cfdata->escfg->autohide;
105    cfdata->autohide_show_action = cfdata->escfg->autohide_show_action;
106    cfdata->hide_timeout = cfdata->escfg->hide_timeout;
107    cfdata->hide_duration = cfdata->escfg->hide_duration;
108
109    /* desktop */
110    cfdata->desk_show_mode = cfdata->escfg->desk_show_mode;
111    cfdata->desk_list = cfdata->escfg->desk_list;
112 }
113
114 static int
115 _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
116 {
117 #define CHECK(X) if (cfdata->X != cfdata->escfg->X) return 1
118    CHECK(layer);
119    CHECK(overlap);
120    CHECK(orient);
121    CHECK(fit_along);
122    CHECK(size);
123    CHECK(style);
124    CHECK(autohide);
125    CHECK(autohide_show_action);
126    CHECK(desk_show_mode);
127    CHECK(desk_list);
128    if (fabs(cfdata->hide_timeout - cfdata->escfg->hide_timeout) > 0.19) return 1;
129    if (fabs(cfdata->hide_duration - cfdata->escfg->hide_duration) > 0.04) return 1;
130    return 0;
131 }
132
133 static void
134 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
135 {
136    eina_list_free(cfdata->autohide_list);
137
138    eina_stringshare_del(cfdata->style);
139    cfdata->style = NULL;
140
141    E_FREE_LIST(cfdata->handlers, ecore_event_handler_del);
142    cfdata->es->config_dialog = NULL;
143    E_FREE(cfdata);
144 }
145
146 static Evas_Object *
147 _basic_create(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata)
148 {
149    Evas_Object *otb, *ol, *ow;
150    E_Radio_Group *rg;
151
152    otb = e_widget_toolbook_add(evas, 24, 24);
153
154    /* Stacking */
155    ol = e_widget_list_add(evas, 0, 0);
156    rg = e_widget_radio_group_new(&(cfdata->layer));
157    ow = e_widget_radio_add(evas, _("Above Everything"), E_LAYER_CLIENT_ABOVE, rg);
158    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
159    ow = e_widget_radio_add(evas, _("Below Windows"), E_LAYER_CLIENT_DESKTOP, rg);
160    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
161    ow = e_widget_radio_add(evas, _("Below Everything"), E_LAYER_DESKTOP, rg);
162    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
163   e_widget_toolbook_page_append(otb, NULL, _("Stacking"), ol,
164                                  1, 0, 1, 0, 0.5, 0.0);
165
166    /* position */
167    ol = e_widget_table_add(evas, 1);
168    rg = e_widget_radio_group_new(&(cfdata->orient));
169    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-left",
170                                 24, 24, E_GADCON_ORIENT_LEFT, rg);
171    e_widget_table_object_append(ol, ow, 0, 2, 1, 1, 1, 1, 1, 1);
172    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-right",
173                                 24, 24, E_GADCON_ORIENT_RIGHT, rg);
174    e_widget_table_object_append(ol, ow, 2, 2, 1, 1, 1, 1, 1, 1);
175    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-top",
176                                 24, 24, E_GADCON_ORIENT_TOP, rg);
177    e_widget_table_object_append(ol, ow, 1, 0, 1, 1, 1, 1, 1, 1);
178    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-bottom",
179                                 24, 24, E_GADCON_ORIENT_BOTTOM, rg);
180    e_widget_table_object_append(ol, ow, 1, 4, 1, 1, 1, 1, 1, 1);
181    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-top-left",
182                                 24, 24, E_GADCON_ORIENT_CORNER_TL, rg);
183    e_widget_table_object_append(ol, ow, 0, 0, 1, 1, 1, 1, 1, 1);
184    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-top-right",
185                                 24, 24, E_GADCON_ORIENT_CORNER_TR, rg);
186    e_widget_table_object_append(ol, ow, 2, 0, 1, 1, 1, 1, 1, 1);
187    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-bottom-left",
188                                 24, 24, E_GADCON_ORIENT_CORNER_BL, rg);
189    e_widget_table_object_append(ol, ow, 0, 4, 1, 1, 1, 1, 1, 1);
190    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-bottom-right",
191                                 24, 24, E_GADCON_ORIENT_CORNER_BR, rg);
192    e_widget_table_object_append(ol, ow, 2, 4, 1, 1, 1, 1, 1, 1);
193    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-left-top",
194                                 24, 24, E_GADCON_ORIENT_CORNER_LT, rg);
195    e_widget_table_object_append(ol, ow, 0, 1, 1, 1, 1, 1, 1, 1);
196    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-right-top",
197                                 24, 24, E_GADCON_ORIENT_CORNER_RT, rg);
198    e_widget_table_object_append(ol, ow, 2, 1, 1, 1, 1, 1, 1, 1);
199    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-left-bottom",
200                                 24, 24, E_GADCON_ORIENT_CORNER_LB, rg);
201    e_widget_table_object_append(ol, ow, 0, 3, 1, 1, 1, 1, 1, 1);
202    ow = e_widget_radio_icon_add(evas, NULL, "preferences-position-right-bottom",
203                                 24, 24, E_GADCON_ORIENT_CORNER_RB, rg);
204    e_widget_table_object_append(ol, ow, 2, 3, 1, 1, 1, 1, 1, 1);
205    e_widget_toolbook_page_append(otb, NULL, _("Position"), ol,
206                                  1, 0, 1, 0, 0.5, 0.0);
207
208    /* size */
209    ol = e_widget_list_add(evas, 0, 0);
210    ow = e_widget_slider_add(evas, 1, 0, _("%1.0f pixels"), 4, 256, 4, 0,
211                             NULL, &(cfdata->size), 100);
212    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
213    ow = e_widget_check_add(evas, _("Shrink to Content Width"),
214                            &(cfdata->fit_along));
215    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
216    e_widget_toolbook_page_append(otb, NULL, _("Size"), ol,
217                                  1, 0, 1, 0, 0.5, 0.0);
218
219    /* style */
220    ol = e_widget_list_add(evas, 0, 0);
221    ow = e_widget_ilist_add(evas, 60, 20, &(cfdata->style));
222    _fill_styles(cfdata, ow);
223    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
224    e_widget_toolbook_page_append(otb, NULL, _("Style"), ol,
225                                  1, 0, 1, 0, 0.5, 0.0);
226
227    /* autohide */
228    ol = e_widget_list_add(evas, 0, 0);
229    cfdata->o_autohide =
230      e_widget_check_add(evas, _("Auto-hide the shelf"), &(cfdata->autohide));
231    e_widget_on_change_hook_set(cfdata->o_autohide, _cb_autohide_change, cfdata);
232    e_widget_list_object_append(ol, cfdata->o_autohide, 1, 1, 0.5);
233
234    rg = e_widget_radio_group_new(&(cfdata->autohide_show_action));
235    ow = e_widget_radio_add(evas, _("Show on mouse in"), 0, rg);
236    e_widget_disabled_set(ow, !cfdata->autohide);
237    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
238    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
239    ow = e_widget_radio_add(evas, _("Show on mouse click"), 1, rg);
240    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
241    e_widget_disabled_set(ow, !cfdata->autohide);
242    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
243
244    ow = e_widget_label_add(evas, _("Hide timeout"));
245    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
246    e_widget_disabled_set(ow, !cfdata->autohide);
247    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
248    ow = e_widget_slider_add(evas, 1, 0, _("%.1f seconds"), 0.2, 6.0, 0.2, 0,
249                             &(cfdata->hide_timeout), NULL, 100);
250    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
251    e_widget_disabled_set(ow, !cfdata->autohide);
252    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
253
254    ow = e_widget_label_add(evas, _("Hide duration"));
255    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
256    e_widget_disabled_set(ow, !cfdata->autohide);
257    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
258    ow = e_widget_slider_add(evas, 1, 0, _("%.2f seconds"), 0.05, 6.0, 0.05, 0,
259                             &(cfdata->hide_duration), NULL, 100);
260    cfdata->autohide_list = eina_list_append(cfdata->autohide_list, ow);
261    e_widget_disabled_set(ow, !cfdata->autohide);
262    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
263    ow = e_widget_check_add(evas, _("Don't adjust windows when overlapping the shelf"),
264                            &(cfdata->overlap));
265    e_widget_disabled_set(ow, ((!cfdata->autohide) || (!e_config->border_fix_on_shelf_toggle)));
266    cfdata->o_overlap = ow;
267    e_widget_list_object_append(ol, ow, 1, 1, 0.5);
268    e_widget_toolbook_page_append(otb, NULL, _("Auto Hide"), ol,
269                                  1, 0, 1, 0, 0.5, 0.0);
270
271    /* Desktop */
272    ol = e_widget_list_add(evas, 0, 0);
273    rg = e_widget_radio_group_new(&(cfdata->desk_show_mode));
274    ow = e_widget_radio_add(evas, _("Show on all Desktops"), 0, rg);
275    e_widget_list_object_append(ol, ow, 1, 0, 0.5);
276    ow = e_widget_radio_add(evas, _("Show on specified Desktops"), 1, rg);
277    e_widget_list_object_append(ol, ow, 1, 0, 0.5);
278
279    cfdata->o_desk_list = e_widget_ilist_add(evas, 24, 24, NULL);
280    e_widget_ilist_multi_select_set(cfdata->o_desk_list, EINA_TRUE);
281    _fill_desks(cfdata);
282    e_widget_list_object_append(ol, cfdata->o_desk_list, 1, 1, 0.5);
283    e_widget_toolbook_page_append(otb, NULL, _("Desktop"), ol,
284                                  1, 0, 1, 0, 0.5, 0.0);
285
286    e_widget_toolbook_page_show(otb, 0);
287    return otb;
288 }
289
290 static int
291 _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
292 {
293    E_Config_Shelf_Desk *sd;
294    int recreate = 0;
295
296    if (cfdata->escfg->orient != cfdata->orient)
297      {
298         cfdata->escfg->orient = cfdata->orient;
299         recreate = 1;
300      }
301
302    if (cfdata->escfg->fit_along != cfdata->fit_along)
303      {
304         cfdata->escfg->fit_along = cfdata->fit_along;
305         cfdata->es->fit_along = cfdata->fit_along;
306         recreate = 1;
307      }
308
309    if (cfdata->escfg->size != cfdata->size)
310      {
311         cfdata->escfg->size = cfdata->size;
312         cfdata->es->size = cfdata->size;
313         recreate = 1;
314      }
315
316    cfdata->escfg->layer = cfdata->layer;
317    evas_object_layer_set(cfdata->es->comp_object, cfdata->escfg->layer);
318    cfdata->escfg->overlap = cfdata->overlap;
319    e_shelf_autohide_set(cfdata->es, cfdata->autohide + (cfdata->autohide * cfdata->autohide_show_action));
320    cfdata->escfg->autohide_show_action = cfdata->autohide_show_action;
321    cfdata->escfg->hide_timeout = cfdata->hide_timeout;
322    cfdata->escfg->hide_duration = cfdata->hide_duration;
323    cfdata->escfg->desk_show_mode = cfdata->desk_show_mode;
324
325    EINA_LIST_FREE(cfdata->escfg->desk_list, sd)
326      E_FREE(sd);
327    cfdata->escfg->desk_list = NULL;
328
329    if (cfdata->desk_show_mode)
330      {
331         const Eina_List *l;
332         const E_Ilist_Item *it;
333         int idx = -1;
334
335         EINA_LIST_FOREACH(e_widget_ilist_items_get(cfdata->o_desk_list), l, it)
336           {
337              E_Desk *desk;
338
339              idx++;
340              if ((!it) || (!it->selected)) continue;
341              if (!(desk = e_desk_at_pos_get(cfdata->es->zone, idx))) continue;
342              sd = E_NEW(E_Config_Shelf_Desk, 1);
343              sd->x = desk->x;
344              sd->y = desk->y;
345              cfdata->escfg->desk_list =
346                eina_list_append(cfdata->escfg->desk_list, sd);
347           }
348      }
349
350    e_gadcon_unpopulate(cfdata->es->gadcon);
351    if (!cfdata->escfg->style)
352      {
353         cfdata->escfg->style = eina_stringshare_ref(cfdata->style);
354         e_shelf_style_set(cfdata->es, cfdata->style);
355      }
356    else if ((cfdata->escfg->style) &&
357             (cfdata->escfg->style != cfdata->style))
358      {
359         eina_stringshare_replace(&cfdata->escfg->style, cfdata->style);
360         e_shelf_style_set(cfdata->es, cfdata->style);
361      }
362    if (recreate)
363      {
364         E_Zone *zone;
365         E_Config_Shelf *cf_es;
366
367         zone = cfdata->es->zone;
368         cf_es = cfdata->es->cfg;
369         cfdata->es->config_dialog = NULL;
370         e_shelf_hide(cfdata->es);
371         e_object_del(E_OBJECT(cfdata->es));
372
373         cfdata->es = e_shelf_config_new(zone, cf_es);
374         cfdata->es->config_dialog = cfd;
375      }
376    else
377      e_gadcon_populate(cfdata->es->gadcon);
378
379    if (cfdata->escfg->desk_show_mode)
380      {
381         E_Desk *desk;
382         Eina_List *l;
383         int show = 0;
384
385         desk = e_desk_current_get(cfdata->es->zone);
386         EINA_LIST_FOREACH(cfdata->escfg->desk_list, l, sd)
387           {
388              if ((desk->x == sd->x) && (desk->y == sd->y))
389                {
390                   show = 1;
391                   break;
392                }
393           }
394         if (show) e_shelf_show(cfdata->es);
395         else e_shelf_hide(cfdata->es);
396      }
397    else
398      e_shelf_show(cfdata->es);
399
400    if ((cfdata->escfg->autohide) && (!cfdata->es->hidden))
401      e_shelf_toggle(cfdata->es, 0);
402    else if ((!cfdata->escfg->autohide) && (cfdata->es->hidden))
403      e_shelf_toggle(cfdata->es, 1);
404
405    e_zone_useful_geometry_dirty(cfdata->es->zone);
406    e_config_save_queue();
407    cfdata->es->config_dialog = cfd;
408    return 1;
409 }
410
411 static void
412 _fill_styles(E_Config_Dialog_Data *cfdata, Evas_Object *obj)
413 {
414    Evas *evas;
415    Eina_List *l, *styles;
416    char *style;
417    const char *str;
418    int mw, n = 0;
419
420    evas = evas_object_evas_get(obj);
421    evas_event_freeze(evas);
422    edje_freeze();
423    e_widget_ilist_freeze(obj);
424    e_widget_ilist_clear(obj);
425
426    styles = e_theme_shelf_list();
427    EINA_LIST_FOREACH(styles, l, style)
428      {
429         Evas_Object *thumb, *ow;
430         char buff[4096];
431
432         thumb = e_livethumb_add(evas);
433         e_livethumb_vsize_set(thumb, 120, 40);
434         ow = edje_object_add(e_livethumb_evas_get(thumb));
435         snprintf(buff, sizeof(buff), "e/shelf/%s/base", style);
436         e_theme_edje_object_set(ow, "base/theme/shelf", buff);
437         e_livethumb_thumb_set(thumb, ow);
438         e_widget_ilist_append(obj, thumb, style, NULL, NULL, style);
439         if (!strcmp(cfdata->style, style))
440           e_widget_ilist_selected_set(obj, n);
441         n++;
442      }
443
444    e_widget_size_min_get(obj, &mw, NULL);
445    e_widget_size_min_set(obj, mw, 180);
446
447    e_widget_ilist_go(obj);
448    e_widget_ilist_thaw(obj);
449    edje_thaw();
450    evas_event_thaw(evas);
451
452    EINA_LIST_FREE(styles, str)
453      eina_stringshare_del(str);
454 }
455
456 static void
457 _cb_autohide_change(void *data, Evas_Object *obj __UNUSED__)
458 {
459    E_Config_Dialog_Data *cfdata;
460    Eina_List *l;
461    Evas_Object *ow;
462
463    if (!(cfdata = data)) return;
464    EINA_LIST_FOREACH(cfdata->autohide_list, l, ow)
465      e_widget_disabled_set(ow, !cfdata->autohide);
466    
467    e_widget_disabled_set(cfdata->o_overlap, ((!cfdata->autohide) || (!e_config->border_fix_on_shelf_toggle)));
468 }
469
470 static void
471 _fill_desks(E_Config_Dialog_Data *cfdata)
472 {
473    Evas *evas;
474    int mw, x, y;
475    int i = 0;
476
477    evas = evas_object_evas_get(cfdata->o_desk_list);
478    evas_event_freeze(evas);
479    edje_freeze();
480    e_widget_ilist_freeze(cfdata->o_desk_list);
481    e_widget_ilist_clear(cfdata->o_desk_list);
482
483    for (y = 0; y < e_config->zone_desks_y_count; y++)
484      for (x = 0; x < e_config->zone_desks_x_count; x++)
485        {
486           E_Desk *desk;
487           Eina_List *l;
488           E_Config_Shelf_Desk *sd;
489
490           desk = e_desk_at_xy_get(cfdata->es->zone, x, y);
491           e_widget_ilist_append(cfdata->o_desk_list, NULL, desk->name,
492                                 NULL, NULL, NULL);
493           i++;
494
495           EINA_LIST_FOREACH(cfdata->desk_list, l, sd)
496             {
497                if ((sd->x != x) || (sd->y != y)) continue;
498                e_widget_ilist_multi_select(cfdata->o_desk_list, i);
499                break;
500             }
501        }
502
503    e_widget_size_min_get(cfdata->o_desk_list, &mw, NULL);
504    e_widget_size_min_set(cfdata->o_desk_list, mw, 180);
505
506    e_widget_ilist_go(cfdata->o_desk_list);
507    e_widget_ilist_thaw(cfdata->o_desk_list);
508    edje_thaw();
509    evas_event_thaw(evas);
510 }
511