update for beta release
[framework/uifw/e17.git] / src / modules / conf_display / e_int_config_desks.c
1 #include "e.h"
2
3 /* PROTOTYPES - same all the time */
4 static void *_create_data(E_Config_Dialog *cfd);
5 static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
6 static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
7 static int _basic_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
8 static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
9 static void _cb_slider_change(void *data, Evas_Object *obj);
10 static void _cb_disable_flip_anim(void *data, Evas_Object *obj);
11
12 /* Actual config data we will be playing with whil the dialog is active */
13 struct _E_Config_Dialog_Data
14 {
15    /*- BASIC -*/
16    int x;
17    int y;
18    int edge_flip_dragging;
19    int flip_wrap;
20    int flip_mode;
21    int flip_interp;
22    double flip_speed;
23
24    /*- GUI -*/
25    Evas_Object *preview;
26    Eina_List *flip_anim_list;
27 };
28
29 /* a nice easy setup function that does the dirty work */
30 E_Config_Dialog *
31 e_int_config_desks(E_Container *con, const char *params __UNUSED__)
32 {
33    E_Config_Dialog *cfd;
34    E_Config_Dialog_View *v;
35    
36    if (e_config_dialog_find("E", "screen/virtual_desktops")) return NULL;
37    v = E_NEW(E_Config_Dialog_View, 1);
38    
39    /* methods */
40    v->create_cfdata = _create_data;
41    v->free_cfdata = _free_data;
42    v->basic.apply_cfdata = _basic_apply_data;
43    v->basic.create_widgets = _basic_create_widgets;
44    v->basic.check_changed = _basic_check_changed;
45    v->advanced.apply_cfdata = NULL;
46    v->advanced.create_widgets = NULL;
47    v->advanced.check_changed = NULL;
48    /* create config diaolg for NULL object/data */
49    cfd = e_config_dialog_new(con, _("Virtual Desktops Settings"),
50                              "E", "screen/virtual_desktops",
51                              "preferences-desktop", 0, v, NULL);
52    return cfd;
53 }
54
55 /**--CREATE--**/
56 static void
57 _fill_data(E_Config_Dialog_Data *cfdata)
58 {
59    cfdata->x = e_config->zone_desks_x_count;
60    cfdata->y = e_config->zone_desks_y_count;
61    cfdata->edge_flip_dragging = e_config->edge_flip_dragging;
62    cfdata->flip_wrap = e_config->desk_flip_wrap;
63    cfdata->flip_mode = e_config->desk_flip_animate_mode;
64    cfdata->flip_interp = e_config->desk_flip_animate_interpolation;
65    cfdata->flip_speed = e_config->desk_flip_animate_time;
66 }
67
68 static void *
69 _create_data(E_Config_Dialog *cfd __UNUSED__)
70 {
71    E_Config_Dialog_Data *cfdata;
72
73    cfdata = E_NEW(E_Config_Dialog_Data, 1);
74    _fill_data(cfdata);
75    return cfdata;
76 }
77
78 static void
79 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
80 {
81    eina_list_free(cfdata->flip_anim_list);
82    E_FREE(cfdata);
83 }
84
85 /**--APPLY--**/
86
87 static int
88 _basic_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
89 {
90    /* Actually take our cfdata settings and apply them in real life */
91    const Eina_List *l, *ll, *lll;
92    E_Manager *man;
93    E_Container *con;
94    E_Zone *zone;
95
96    EINA_LIST_FOREACH(e_manager_list(), l, man)
97      EINA_LIST_FOREACH(man->containers, ll, con)
98        EINA_LIST_FOREACH(con->zones, lll, zone)
99          e_zone_desk_count_set(zone, cfdata->x, cfdata->y);
100
101    e_config->desk_flip_animate_mode = cfdata->flip_mode;
102    e_config->desk_flip_animate_interpolation = cfdata->flip_interp;
103    e_config->desk_flip_animate_time = cfdata->flip_speed;
104    
105    e_config->edge_flip_dragging = cfdata->edge_flip_dragging;
106    e_config->desk_flip_wrap = cfdata->flip_wrap;
107
108    e_config_save_queue();
109    return 1; /* Apply was OK */
110 }
111
112 static int
113 _basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
114 {
115    const Eina_List *l, *ll, *lll;
116    E_Manager *man;
117    E_Container *con;
118    E_Zone *zone;
119
120    EINA_LIST_FOREACH(e_manager_list(), l, man)
121      EINA_LIST_FOREACH(man->containers, ll, con)
122        EINA_LIST_FOREACH(con->zones, lll, zone)
123          {
124             int x, y;
125
126             e_zone_desk_count_get(zone, &x, &y);
127             if ((x != cfdata->x) || (y != cfdata->y))
128               return 1;
129          }
130
131    return ((e_config->desk_flip_animate_mode != cfdata->flip_mode) ||
132            (e_config->desk_flip_animate_interpolation != cfdata->flip_interp) ||
133            (e_config->desk_flip_animate_time != cfdata->flip_speed) ||
134            (e_config->edge_flip_dragging != cfdata->edge_flip_dragging) ||
135            (e_config->desk_flip_wrap != cfdata->flip_wrap));
136 }
137
138 /**--GUI--**/
139 static Evas_Object *
140 _basic_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata)
141 {
142    /* generate the core widget layout for a basic dialog */
143    Evas_Object *o, *ob, *of, *otb;
144    E_Radio_Group *rg;
145
146    otb = e_widget_toolbook_add(evas, (48 * e_scale), (48 * e_scale));
147    
148    o = e_widget_list_add(evas, 0, 0);
149
150    of = e_widget_frametable_add(evas, _("Number of Desktops"), 0);
151    e_widget_frametable_content_align_set(of, 0.5, 0.0);
152
153    ob = e_widget_deskpreview_add(evas, cfdata->x, cfdata->y);
154    e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 1, 1, 1);
155    cfdata->preview = ob;
156
157    ob = e_widget_slider_add(evas, 0, 0, _("%1.0f"), 1.0, 12.0, 1.0, 0, NULL, 
158                             &(cfdata->y), 150);
159    e_widget_on_change_hook_set(ob, _cb_slider_change, cfdata);
160    e_widget_frametable_object_append(of, ob, 1, 0, 1, 1, 1, 1, 0, 1);
161
162    ob = e_widget_slider_add(evas, 1, 0, _("%1.0f"), 1.0, 12.0, 1.0, 0, NULL, 
163                             &(cfdata->x), 200);
164    e_widget_on_change_hook_set(ob, _cb_slider_change, cfdata);
165    e_widget_frametable_object_append(of, ob, 0, 1, 1, 1, 1, 1, 1, 0);
166
167    e_widget_list_object_append(o, of, 1, 1, 0.5);
168
169    of = e_widget_framelist_add(evas, _("Desktop Flip"), 0);
170    ob = e_widget_check_add(evas, _("Flip when dragging objects to the screen edge"), 
171                            &(cfdata->edge_flip_dragging));
172    e_widget_framelist_object_append(of, ob);
173    ob = e_widget_check_add(evas, _("Wrap desktops around when flipping"), 
174                            &(cfdata->flip_wrap));
175    e_widget_framelist_object_append(of, ob);
176
177    e_widget_list_object_append(o, of, 1, 0, 0.5);
178    
179    e_widget_toolbook_page_append(otb, NULL, _("Desktops"), o, 1, 1, 1, 1, 
180                                  0.5, 0.0);
181
182    o = e_widget_list_add(evas, 0, 0);
183    rg = e_widget_radio_group_new(&(cfdata->flip_mode));
184    ob = e_widget_radio_add(evas, _("Off"), 0, rg);
185    e_widget_on_change_hook_set(ob, _cb_disable_flip_anim, cfdata);
186    e_widget_list_object_append(o, ob, 1, 0, 0.5);
187    ob = e_widget_radio_add(evas, _("Pane"), 1, rg);
188    e_widget_on_change_hook_set(ob, _cb_disable_flip_anim, cfdata);
189    e_widget_list_object_append(o, ob, 1, 0, 0.5);
190    ob = e_widget_radio_add(evas, _("Zoom"), 2, rg);
191    e_widget_on_change_hook_set(ob, _cb_disable_flip_anim, cfdata);
192    e_widget_list_object_append(o, ob, 1, 0, 0.5);
193    
194    ob = e_widget_label_add(evas, _("Animation speed"));
195    cfdata->flip_anim_list = eina_list_append(cfdata->flip_anim_list, ob);
196    e_widget_list_object_append(o, ob, 1, 0, 0.5);
197    ob = e_widget_slider_add(evas, 1, 0, _("%1.1f sec"), 0, 5, 0.05, 0, 
198                             &(cfdata->flip_speed), NULL, 150);
199    e_widget_disabled_set(ob, !cfdata->flip_mode);
200    cfdata->flip_anim_list = eina_list_append(cfdata->flip_anim_list, ob);
201    e_widget_list_object_append(o, ob, 1, 0, 0.5);
202    e_widget_toolbook_page_append(otb, NULL, _("Flip Animation"), o, 
203                                  1, 0, 1, 0, 0.5, 0.0);
204
205    e_widget_toolbook_page_show(otb, 0);
206
207    return otb;
208 }
209
210 static void
211 _cb_slider_change(void *data, Evas_Object *obj __UNUSED__)
212 {
213    E_Config_Dialog_Data *cfdata = data;
214
215    e_widget_deskpreview_num_desks_set(cfdata->preview, cfdata->x, cfdata->y);
216 }
217
218 static void
219 _cb_disable_flip_anim(void *data, Evas_Object *obj __UNUSED__)
220 {
221    E_Config_Dialog_Data *cfdata = (E_Config_Dialog_Data*) data;
222    Eina_List *list = cfdata->flip_anim_list;
223    Eina_List *l;
224    Evas_Object *o;
225
226    EINA_LIST_FOREACH(list, l, o)
227      e_widget_disabled_set(o, !cfdata->flip_mode);
228 }