1 #include "e.h"
2 #include "e_mod_main.h"
3
4 typedef struct _Import Import;
5
6 struct _Import
7 {
8 E_Config_Dialog *parent;
9 E_Config_Dialog_Data *cfdata;
10
11 Evas_Object *bg_obj;
12 Evas_Object *box_obj;
13 Evas_Object *content_obj;
14 Evas_Object *event_obj;
15 Evas_Object *fsel_obj;
16
17 Evas_Object *ok_obj;
18 Evas_Object *cancel_obj;
19
20 Evas_Object *win;
21 };
22
23 struct _E_Config_Dialog_Data
24 {
25 char *file;
26 };
27
28 static void _theme_import_cb_delete(void *data, Evas *e, Evas_Object *obj, void *event_info);
29 static void _theme_import_cb_wid_focus(void *data, Evas_Object *obj);
30 static void _theme_import_cb_selected(void *data, Evas_Object *obj);
31 static void _theme_import_cb_changed(void *data, Evas_Object *obj);
32 static void _theme_import_cb_ok(void *data, void *data2);
33 static void _theme_import_cb_close(void *data, void *data2);
34 static void _theme_import_cb_key_down(void *data, Evas *e, Evas_Object *obj, void *event);
35
36 Evas_Object *
e_int_config_theme_import(E_Config_Dialog * parent)37 e_int_config_theme_import(E_Config_Dialog *parent)
38 {
39 Evas *evas;
40 Evas_Object *win;
41 Evas_Object *o, *ofm;
42 Import *import;
43 E_Config_Dialog_Data *cfdata;
44 Evas_Modifier_Mask mask;
45 Evas_Coord w, h;
46 Eina_Bool kg;
47
48 import = E_NEW(Import, 1);
49 if (!import) return NULL;
50
51 win = elm_win_add(parent->parent, "E", ELM_WIN_DIALOG_BASIC);
52 if (!win)
53 {
54 E_FREE(import);
55 return NULL;
56 }
57
58 evas = evas_object_evas_get(win);
59
60 cfdata = E_NEW(E_Config_Dialog_Data, 1);
61 import->cfdata = cfdata;
62 import->win = win;
63 import->parent = parent;
64
65 elm_win_title_set(win, _("Select a Theme..."));
66 evas_object_event_callback_add(win, EVAS_CALLBACK_DEL, _theme_import_cb_delete, NULL);
67 ecore_evas_name_class_set(ecore_evas_ecore_evas_get(evas_object_evas_get(win)), "E", "_theme_import_dialog");
68
69 o = elm_layout_add(win);
70 E_EXPAND(o);
71 E_FILL(o);
72 import->bg_obj = o;
73 e_theme_edje_object_set(o, "base/theme/dialog", "e/widgets/dialog/main");
74 elm_win_resize_object_add(win, o);
75 evas_object_show(o);
76
77 o = e_widget_list_add(evas, 1, 1);
78 e_widget_on_focus_hook_set(o, _theme_import_cb_wid_focus, import);
79 import->box_obj = o;
80 elm_object_part_content_set(import->bg_obj, "e.swallow.buttons", o);
81
82 o = evas_object_rectangle_add(evas);
83 import->event_obj = o;
84 mask = 0;
85 kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0);
86 if (!kg)
87 fprintf(stderr, "ERROR: Unable to redirect \"Tab\" key events to object %p.\n", o);
88 mask = evas_key_modifier_mask_get(evas, "Shift");
89 kg = evas_object_key_grab(o, "Tab", mask, ~mask, 0);
90 if (!kg)
91 fprintf(stderr, "ERROR: unable to redirect \"Tab\" key events to object %p.\n", o);
92 mask = 0;
93 kg = evas_object_key_grab(o, "Return", mask, ~mask, 0);
94 if (!kg)
95 fprintf(stderr, "ERROR: unable to redirect \"Return\" key events to object %p.\n", o);
96 mask = 0;
97 kg = evas_object_key_grab(o, "KP_Enter", mask, ~mask, 0);
98 if (!kg)
99 fprintf(stderr, "ERROR: unable to redirect \"KP_Enter\" key events to object %p.\n", o);
100 evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN,
101 _theme_import_cb_key_down, import);
102
103 o = e_widget_list_add(evas, 0, 0);
104 import->content_obj = o;
105
106 ofm = e_widget_fsel_add(evas, e_user_homedir_get(), "/",
107 NULL, NULL,
108 _theme_import_cb_selected, import,
109 _theme_import_cb_changed, import, 1);
110 import->fsel_obj = ofm;
111 e_widget_list_object_append(o, ofm, 1, 1, 0.5);
112
113 e_widget_size_min_get(o, &w, &h);
114 evas_object_size_hint_min_set(o, w, h);
115 elm_object_part_content_set(import->bg_obj, "e.swallow.content", o);
116 evas_object_show(o);
117
118 import->ok_obj = e_widget_button_add(evas, _("OK"), NULL,
119 _theme_import_cb_ok, win, cfdata);
120 e_widget_list_object_append(import->box_obj, import->ok_obj, 1, 0, 0.5);
121
122 import->cancel_obj = e_widget_button_add(evas, _("Cancel"), NULL,
123 _theme_import_cb_close,
124 win, cfdata);
125 e_widget_list_object_append(import->box_obj, import->cancel_obj, 1, 0, 0.5);
126
127 e_widget_disabled_set(import->ok_obj, 1);
128
129 elm_win_center(win, 1, 1);
130
131 o = import->box_obj;
132 e_widget_size_min_get(o, &w, &h);
133 evas_object_size_hint_min_set(o, w, h);
134 elm_object_part_content_set(import->bg_obj, "e.swallow.buttons", o);
135
136 evas_object_show(win);
137 e_win_client_icon_set(win, "preferences-desktop-theme");
138
139 evas_object_data_set(win, "import_win", import);
140
141 return win;
142 }
143
144 static void
_theme_import_cb_delete(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj,void * event_info EINA_UNUSED)145 _theme_import_cb_delete(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_info EINA_UNUSED)
146 {
147 Import *import;
148
149 import = evas_object_data_del(obj, "import_win");
150 if (!import) return;
151
152 evas_object_del(import->win);
153 e_int_config_theme_import_done(import->parent);
154
155 E_FREE(import->cfdata->file);
156 E_FREE(import->cfdata);
157 E_FREE(import);
158 return;
159 }
160
161 static void
_theme_import_cb_wid_focus(void * data,Evas_Object * obj)162 _theme_import_cb_wid_focus(void *data, Evas_Object *obj)
163 {
164 Import *import;
165
166 import = data;
167 if (obj == import->content_obj)
168 e_widget_focused_object_clear(import->box_obj);
169 else if (import->content_obj)
170 e_widget_focused_object_clear(import->content_obj);
171 }
172
173 static void
_theme_import_cb_selected(void * data,Evas_Object * obj EINA_UNUSED)174 _theme_import_cb_selected(void *data, Evas_Object *obj EINA_UNUSED)
175 {
176 Import *import;
177
178 import = data;
179 _theme_import_cb_ok(import->win, NULL);
180 }
181
182 static void
_theme_import_cb_changed(void * data,Evas_Object * obj EINA_UNUSED)183 _theme_import_cb_changed(void *data, Evas_Object *obj EINA_UNUSED)
184 {
185 Import *import;
186 const char *path;
187 const char *file;
188
189 import = data;
190 if (!import) return;
191 if (!import->fsel_obj) return;
192
193 path = e_widget_fsel_selection_path_get(import->fsel_obj);
194 E_FREE(import->cfdata->file);
195 if (path)
196 import->cfdata->file = strdup(path);
197
198 if (import->cfdata->file)
199 {
200 char *strip;
201
202 file = ecore_file_file_get(import->cfdata->file);
203 strip = ecore_file_strip_ext(file);
204 if (!strip)
205 {
206 E_FREE(import->cfdata->file);
207 e_widget_disabled_set(import->ok_obj, 1);
208 return;
209 }
210 free(strip);
211 if (!e_util_glob_case_match(file, "*.edj"))
212 {
213 E_FREE(import->cfdata->file);
214 e_widget_disabled_set(import->ok_obj, 1);
215 return;
216 }
217 e_widget_disabled_set(import->ok_obj, 0);
218 }
219 else
220 e_widget_disabled_set(import->ok_obj, 1);
221 }
222
223 static void
_theme_import_cb_ok(void * data,void * data2 EINA_UNUSED)224 _theme_import_cb_ok(void *data, void *data2 EINA_UNUSED)
225 {
226 Import *import;
227 Evas_Object *win;
228 const char *path;
229 const char *file;
230 char buf[PATH_MAX];
231
232 win = data;
233 import = evas_object_data_get(win, "import_win");
234 if (!import) return;
235
236 path = e_widget_fsel_selection_path_get(import->fsel_obj);
237 E_FREE(import->cfdata->file);
238 if (path)
239 import->cfdata->file = strdup(path);
240
241 if (import->cfdata->file)
242 {
243 char *strip;
244
245 file = ecore_file_file_get(import->cfdata->file);
246 snprintf(buf, sizeof(buf), "%s/%s", elm_theme_user_dir_get(), file);
247
248 if (ecore_file_exists(buf))
249 ecore_file_unlink(buf);
250
251 strip = ecore_file_strip_ext(file);
252 if (!strip)
253 return;
254 free(strip);
255
256 if (!e_util_glob_case_match(file, "*.edj"))
257 return;
258
259 if (!edje_file_group_exists(import->cfdata->file,
260 "e/widgets/border/default/border"))
261 {
262 e_util_dialog_show(_("Theme Import Error"),
263 _("Enlightenment was unable to import "
264 "the theme.<ps/><ps/>Are you sure this "
265 "is really a valid theme?"));
266 }
267 else
268 {
269 if (!ecore_file_cp(import->cfdata->file, buf))
270 {
271 e_util_dialog_show(_("Theme Import Error"),
272 _("Enlightenment was unable to import "
273 "the theme<ps/>due to a copy error."));
274 }
275 else
276 e_int_config_theme_update(import->parent, buf);
277 }
278 }
279
280 evas_object_del(import->win);
281 }
282
283 static void
_theme_import_cb_close(void * data,void * data2 EINA_UNUSED)284 _theme_import_cb_close(void *data, void *data2 EINA_UNUSED)
285 {
286 evas_object_del(data);
287 }
288
289 static void
_theme_import_cb_key_down(void * data,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event)290 _theme_import_cb_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
291 {
292 Evas_Event_Key_Down *ev;
293 Import *import;
294
295 ev = event;
296 import = data;
297 if ((!e_widget_fsel_typebuf_visible_get(import->fsel_obj)) && (!strcmp(ev->key, "Tab")))
298 {
299 if (evas_key_modifier_is_set(evas_key_modifier_get(evas_object_evas_get(import->win)), "Shift"))
300 {
301 if (e_widget_focus_get(import->box_obj))
302 {
303 if (!e_widget_focus_jump(import->box_obj, 0))
304 {
305 e_widget_focus_set(import->content_obj, 0);
306 if (!e_widget_focus_get(import->content_obj))
307 e_widget_focus_set(import->box_obj, 0);
308 }
309 }
310 else
311 {
312 if (!e_widget_focus_jump(import->content_obj, 0))
313 e_widget_focus_set(import->box_obj, 0);
314 }
315 }
316 else
317 {
318 if (e_widget_focus_get(import->box_obj))
319 {
320 if (!e_widget_focus_jump(import->box_obj, 1))
321 {
322 e_widget_focus_set(import->content_obj, 1);
323 if (!e_widget_focus_get(import->content_obj))
324 e_widget_focus_set(import->box_obj, 1);
325 }
326 }
327 else
328 {
329 if (!e_widget_focus_jump(import->content_obj, 1))
330 e_widget_focus_set(import->box_obj, 1);
331 }
332 }
333 }
334 else if (((!strcmp(ev->key, "Return")) ||
335 (!strcmp(ev->key, "KP_Enter")) ||
336 (!strcmp(ev->key, "space"))))
337 {
338 Evas_Object *o = NULL;
339
340 if ((import->content_obj) && (e_widget_focus_get(import->content_obj)))
341 o = e_widget_focused_object_get(import->content_obj);
342 else
343 o = e_widget_focused_object_get(import->box_obj);
344 if (o) e_widget_activate(o);
345 }
346 }
347
348