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