95703aaecb95ca8f7174d1a1b758006974511112
[platform/upstream/enlightenment.git] / src / modules / conf_display / e_int_config_desk.c
1 #include "e.h"
2
3 static void        *_create_data(E_Config_Dialog *cfd);
4 static void         _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
5 static int          _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
6 static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
7 static void         _cb_config(void *data, void *data2);
8 static Eina_Bool    _cb_bg_change(void *data, int type, void *event);
9
10 struct _E_Config_Dialog_Data
11 {
12    int                  man_num;
13    int                  zone_num;
14    int                  desk_x;
15    int                  desk_y;
16    Eina_Stringshare  *bg;
17    char                *name;
18    char                *profile;
19    Evas_Object         *preview;
20    Ecore_Event_Handler *hdl;
21 };
22
23 E_Config_Dialog *
24 e_int_config_desk(Evas_Object *parent EINA_UNUSED, const char *params)
25 {
26    E_Config_Dialog *cfd;
27    E_Config_Dialog_View *v;
28    E_Config_Dialog_Data *cfdata;
29    int man_num, zone_num, dx, dy;
30
31    if (!params) return NULL;
32    man_num = zone_num = dx = dy = -1;
33    if (sscanf(params, "%i %i %i %i", &man_num, &zone_num, &dx, &dy) != 4)
34      return NULL;
35
36    if (e_config_dialog_find("E", "internal/desk")) return NULL;
37
38    v = E_NEW(E_Config_Dialog_View, 1);
39
40    cfdata = E_NEW(E_Config_Dialog_Data, 1);
41    cfdata->man_num = man_num;
42    cfdata->zone_num = zone_num;
43    cfdata->desk_x = dx;
44    cfdata->desk_y = dy;
45
46    v->create_cfdata = _create_data;
47    v->free_cfdata = _free_data;
48    v->basic.apply_cfdata = _basic_apply;
49    v->basic.create_widgets = _basic_create;
50    v->override_auto_apply = 1;
51
52    cfd = e_config_dialog_new(NULL, _("Desk Settings"), "E", "internal/desk",
53                              "preferences-desktop", 0, v, cfdata);
54    return cfd;
55 }
56
57 static void
58 _fill_data(E_Config_Dialog_Data *cfdata)
59 {
60    Eina_List *l;
61    char name[40];
62    int ok = 0;
63    E_Config_Desktop_Window_Profile *prof;
64    cfdata->bg = e_bg_file_get(cfdata->man_num, cfdata->zone_num, cfdata->desk_x, cfdata->desk_y);
65
66    for (l = e_config->desktop_names; l; l = l->next)
67      {
68         E_Config_Desktop_Name *dn;
69
70         dn = l->data;
71         if (!dn) continue;
72         if (dn->manager != cfdata->man_num) continue;
73         if (dn->zone != cfdata->zone_num) continue;
74         if ((dn->desk_x != cfdata->desk_x) || (dn->desk_y != cfdata->desk_y))
75           continue;
76
77         if (dn->name)
78           cfdata->name = strdup(dn->name);
79         ok = 1;
80         break;
81      }
82    if (!ok)
83      {
84         snprintf(name, sizeof(name), _(e_config->desktop_default_name), cfdata->desk_x, cfdata->desk_y);
85         cfdata->name = strdup(name);
86      }
87    ok = 0;
88    EINA_LIST_FOREACH(e_config->desktop_window_profiles, l, prof)
89      {
90         if (!((prof->manager == cfdata->man_num) &&
91               (prof->zone == cfdata->zone_num) &&
92               (prof->desk_x == cfdata->desk_x) &&
93               (prof->desk_y == cfdata->desk_y)))
94           continue;
95
96         if (prof->profile)
97           cfdata->profile = strdup(prof->profile);
98         ok = 1;
99         break;
100      }
101
102    if (!ok)
103      cfdata->profile = strdup(e_config->desktop_default_window_profile);
104 }
105
106 static void *
107 _create_data(E_Config_Dialog *cfd)
108 {
109    E_Config_Dialog_Data *cfdata;
110
111    cfdata = cfd->data;
112    if (!cfdata) return NULL;
113    _fill_data(cfdata);
114    return cfdata;
115 }
116
117 static void
118 _free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
119 {
120    if (cfdata->hdl)
121      ecore_event_handler_del(cfdata->hdl);
122    eina_stringshare_del(cfdata->bg);
123    E_FREE(cfdata->name);
124    E_FREE(cfdata->profile);
125    E_FREE(cfdata);
126 }
127
128 static int
129 _basic_apply(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
130 {
131    char name[40];
132
133    if ((!cfdata->name) || (!cfdata->name[0]))
134      {
135         snprintf(name, sizeof(name), _(e_config->desktop_default_name),
136                  cfdata->desk_x, cfdata->desk_y);
137         free(cfdata->name);
138         cfdata->name = strdup(name);
139      }
140
141    if (!cfdata->profile[0])
142      cfdata->profile = strdup(e_config->desktop_default_window_profile);
143    e_desk_name_del(cfdata->man_num, cfdata->zone_num,
144                    cfdata->desk_x, cfdata->desk_y);
145    e_desk_name_add(cfdata->man_num, cfdata->zone_num,
146                    cfdata->desk_x, cfdata->desk_y, cfdata->name);
147    e_desk_name_update();
148
149    e_desk_window_profile_del(cfdata->man_num, cfdata->zone_num,
150                              cfdata->desk_x, cfdata->desk_y);
151    e_desk_window_profile_add(cfdata->man_num, cfdata->zone_num,
152                              cfdata->desk_x, cfdata->desk_y, cfdata->profile);
153    e_desk_window_profile_update();
154    e_bg_del(cfdata->man_num, cfdata->zone_num, cfdata->desk_x, cfdata->desk_y);
155    e_bg_add(cfdata->man_num, cfdata->zone_num,
156             cfdata->desk_x, cfdata->desk_y, cfdata->bg);
157    e_bg_update();
158
159    e_config_save_queue();
160    return 1;
161 }
162
163 static Evas_Object *
164 _basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata)
165 {
166    Evas_Object *o, *of, *ol, *ob;
167    E_Zone *zone;
168
169    zone = e_zone_current_get(e_comp_get(cfd->dia->win));
170
171    o = e_widget_list_add(evas, 0, 0);
172
173    ol = e_widget_list_add(evas, 0, 1);
174    ob = e_widget_label_add(evas, _("Name"));
175    e_widget_list_object_append(ol, ob, 1, 0, 0.5);
176    ob = e_widget_entry_add(evas, &(cfdata->name), NULL, NULL, NULL);
177    e_widget_list_object_append(ol, ob, 1, 1, 0.5);
178    e_widget_list_object_append(o, ol, 1, 1, 0.5);
179    of = e_widget_frametable_add(evas, _("Desktop Window Profile"), 0);
180    ob = e_widget_label_add(evas, _("Profile name"));
181    e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 1, 0, 0);
182    ob = e_widget_entry_add(evas, &(cfdata->profile), NULL, NULL, NULL);
183    e_widget_disabled_set(ob, !(e_config->use_desktop_window_profile));
184    e_widget_frametable_object_append(of, ob, 1, 0, 2, 1, 1, 1, 1, 0);
185    e_widget_list_object_append(o, of, 1, 1, 0.5);
186    of = e_widget_frametable_add(evas, _("Wallpaper"), 0);
187    ob = e_widget_preview_add(evas, 240, (240 * zone->h) / zone->w);
188    cfdata->preview = ob;
189    if (cfdata->bg)
190      e_widget_preview_edje_set(ob, cfdata->bg, "e/desktop/background");
191    e_widget_frametable_object_append(of, ob, 0, 0, 3, 1, 1, 1, 1, 0);
192    ob = e_widget_button_add(evas, _("Set"), "configure",
193                             _cb_config, cfdata, NULL);
194    e_widget_frametable_object_append(of, ob, 1, 1, 1, 1, 1, 1, 1, 0);
195    e_widget_list_object_append(o, of, 1, 1, 0.5);
196
197    if (cfdata->hdl)
198      ecore_event_handler_del(cfdata->hdl);
199    cfdata->hdl = ecore_event_handler_add(E_EVENT_BG_UPDATE, _cb_bg_change, cfdata);
200
201    return o;
202 }
203
204 static void
205 _cb_config(void *data, void *data2 __UNUSED__)
206 {
207    E_Config_Dialog_Data *cfdata;
208    char buf[256];
209
210    cfdata = data;
211    if (!cfdata) return;
212    snprintf(buf, sizeof(buf), "%i %i %i %i",
213             cfdata->man_num, cfdata->zone_num, cfdata->desk_x, cfdata->desk_y);
214    e_configure_registry_call("internal/wallpaper_desk", NULL, buf);
215 }
216
217 static Eina_Bool
218 _cb_bg_change(void *data, int type, void *event)
219 {
220    E_Event_Bg_Update *ev;
221    E_Config_Dialog_Data *cfdata;
222    const char *file;
223
224    if (type != E_EVENT_BG_UPDATE) return ECORE_CALLBACK_PASS_ON;
225
226    cfdata = data;
227    ev = event;
228    if (ev->manager != cfdata->man_num) return ECORE_CALLBACK_PASS_ON;
229    if (ev->zone != cfdata->zone_num) return ECORE_CALLBACK_PASS_ON;
230    if (ev->desk_x != cfdata->desk_x) return ECORE_CALLBACK_PASS_ON;
231    if (ev->desk_y != cfdata->desk_y) return ECORE_CALLBACK_PASS_ON;
232
233    file = e_bg_file_get(cfdata->man_num, cfdata->zone_num,
234                         cfdata->desk_x, cfdata->desk_y);
235    eina_stringshare_replace(&cfdata->bg, file);
236    e_widget_preview_edje_set(cfdata->preview, cfdata->bg,
237                              "e/desktop/background");
238
239    return ECORE_CALLBACK_PASS_ON;
240 }
241