1 #include "luncher.h"
2
3 static void
_config_close(void * data EINA_UNUSED,Evas * e EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)4 _config_close(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
5 {
6 luncher_config->list = NULL;
7 luncher_config->slist = NULL;
8 evas_object_del(luncher_config->config_dialog);
9 luncher_config->config_dialog = NULL;
10 e_config_save_queue();
11 }
12
13 static void
_config_show_general(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)14 _config_show_general(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
15 {
16 evas_object_hide(luncher_config->contents);
17 evas_object_show(luncher_config->general);
18 }
19
20 static void
_config_show_contents(void * data EINA_UNUSED,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)21 _config_show_contents(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
22 {
23 evas_object_hide(luncher_config->general);
24 evas_object_show(luncher_config->contents);
25 }
26
27 static void
_type_changed(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)28 _type_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
29 {
30 Instance *inst = data;
31 int value = elm_radio_value_get(obj);
32
33 switch (value)
34 {
35 case 0:
36 inst->cfg->type = E_LUNCHER_MODULE_FULL;
37 break;
38 case 1:
39 inst->cfg->type = E_LUNCHER_MODULE_LAUNCH_ONLY;
40 break;
41 case 2:
42 inst->cfg->type = E_LUNCHER_MODULE_TASKS_ONLY;
43 break;
44 default:
45 inst->cfg->type = E_LUNCHER_MODULE_FULL;
46 }
47
48 e_config_save_queue();
49 bar_config_updated(inst);
50 }
51
52 static void
_check_changed(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)53 _check_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
54 {
55 Instance *inst = data;
56
57 inst->cfg->hide_tooltips = elm_check_state_get(obj);
58
59 e_config_save_queue();
60 bar_config_updated(inst);
61 }
62
63 static void
_config_source_changed(void * data,Evas_Object * obj EINA_UNUSED,void * event_info EINA_UNUSED)64 _config_source_changed(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
65 {
66 Instance *inst = data;
67 const char *dir = elm_object_item_text_get(elm_list_selected_item_get(luncher_config->list));
68
69 if (eina_streq(inst->cfg->dir, dir))
70 return;
71 if (inst->cfg->dir) eina_stringshare_del(inst->cfg->dir);
72 inst->cfg->dir = NULL;
73 inst->cfg->dir = eina_stringshare_ref(dir);
74 bar_reorder(inst);
75 }
76
77 static void
_config_populate_order_list(Evas_Object * list,Instance * inst)78 _config_populate_order_list(Evas_Object *list, Instance *inst)
79 {
80 Eina_List *dirs;
81 char buf[4096], *file;
82 size_t len;
83 Elm_Object_Item *it;
84
85 elm_list_clear(list);
86
87 len = e_user_dir_concat_static(buf, "applications/bar");
88 if (len + 2 >= sizeof(buf)) return;
89 dirs = ecore_file_ls(buf);
90
91 buf[len] = '/';
92 len++;
93
94 EINA_LIST_FREE(dirs, file)
95 {
96 if (file[0] == '.') continue;
97 if (eina_strlcpy(buf + len, file, sizeof(buf) - len) >= sizeof(buf) - len)
98 continue;
99 if (ecore_file_is_dir(buf))
100 {
101 it = elm_list_item_append(list, file, NULL, NULL, _config_source_changed, inst);
102 if ((inst->cfg->dir) && (eina_streq(inst->cfg->dir, file)))
103 elm_list_item_selected_set(it, EINA_TRUE);
104 }
105 free(file);
106 }
107 elm_list_go(list);
108 }
109
110 static void
_config_source_cancel(void * data)111 _config_source_cancel(void *data)
112 {
113 Instance *inst = data;
114
115 config_luncher(e_zone_current_get(), inst, luncher_config->bar);
116 }
117
118 static void
_config_source_added(void * data,char * text)119 _config_source_added(void *data, char *text)
120 {
121 Instance *inst = data;
122 char buf[4096];
123 char tmp[4096] = {0};
124 FILE *f;
125 size_t len;
126
127 len = e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", text);
128 if (len + sizeof("/.order") >= sizeof(buf)) return;
129 while (!ecore_file_exists(buf))
130 {
131 ecore_file_mkdir(buf);
132 memcpy(buf + len, "/.order", sizeof("/.order"));
133 e_user_dir_concat_static(tmp, "applications/bar/default/.order");
134 if (ecore_file_cp(tmp, buf)) break;
135 f = fopen(buf, "w");
136 if (!f) break;
137 /* Populate this .order file with some defaults */
138 snprintf(tmp, sizeof(tmp),
139 "terminology.desktop\n"
140 "sylpheed.desktop\n"
141 "firefox.desktop\n"
142 "openoffice.desktop\n"
143 "xchat.desktop\n"
144 "gimp.desktop\n");
145 fwrite(tmp, sizeof(char), strlen(tmp), f);
146 fclose(f);
147 break;
148 }
149 config_luncher(e_zone_current_get(), inst, luncher_config->bar);
150 }
151
152 static void
_config_source_deleted(void * data)153 _config_source_deleted(void *data)
154 {
155 char buf[4096];
156 Instance *inst = data;
157
158 if (e_user_dir_snprintf(buf, sizeof(buf), "applications/bar/%s", inst->cfg->dir) >= sizeof(buf))
159 return;
160 if (ecore_file_is_dir(buf))
161 ecore_file_recursive_rm(buf);
162 e_object_del(E_OBJECT(inst->order));
163 config_luncher(e_zone_current_get(), inst, luncher_config->bar);
164 }
165
166 static void
_config_source_add(void * data,Evas_Object * obj EINA_UNUSED,void * event_data EINA_UNUSED)167 _config_source_add(void *data, Evas_Object *obj EINA_UNUSED, void *event_data EINA_UNUSED)
168 {
169 Instance *inst = data;
170
171 evas_object_del(luncher_config->config_dialog);
172 e_entry_dialog_show(_("Create new Luncher source"), "enlightenment",
173 _("Enter a name for this new source:"), "", NULL, NULL,
174 _config_source_added, _config_source_cancel, inst);
175 }
176
177 static void
_config_source_del(void * data,Evas_Object * obj EINA_UNUSED,void * event_data EINA_UNUSED)178 _config_source_del(void *data, Evas_Object *obj EINA_UNUSED, void *event_data EINA_UNUSED)
179 {
180 Instance *inst = data;
181 char buf[4096];
182
183 evas_object_del(luncher_config->config_dialog);
184 snprintf(buf, sizeof(buf), _("You requested to delete \"%s\".<ps/><ps/>"
185 "Are you sure you want to delete this bar source?"),
186 inst->cfg->dir);
187 e_confirm_dialog_show(_("Are you sure you want to delete this bar source?"),
188 "application-exit", buf, _("Delete"), _("Keep"),
189 _config_source_deleted, _config_source_cancel, inst, inst,
190 NULL, NULL);
191 }
192
193 static void
_config_contents(void * data,Evas_Object * obj,void * event_data EINA_UNUSED)194 _config_contents(void *data, Evas_Object *obj, void *event_data EINA_UNUSED)
195 {
196 Instance *inst = data;
197 Evas_Object *popup = evas_object_data_get(obj, "popup");
198
199 if (e_configure_registry_exists("applications/ibar_applications"))
200 {
201 char path[4096];
202 e_user_dir_snprintf(path, sizeof(path), "applications/bar/%s/.order",
203 inst->cfg->dir);
204 e_configure_registry_call("internal/ibar_other", NULL, path);
205 evas_object_del(popup);
206 }
207
208 }
209
210 static void
_config_create_icon(void * data,Evas_Object * obj,void * event_data EINA_UNUSED)211 _config_create_icon(void *data, Evas_Object *obj, void *event_data EINA_UNUSED)
212 {
213 Instance *inst = data;
214 Evas_Object *popup = evas_object_data_get(obj, "popup");
215
216 if (e_configure_registry_exists("applications/new_application"))
217 {
218 char path[4096];
219 e_user_dir_snprintf(path, sizeof(path), "applications/bar/%s/.order",
220 inst->cfg->dir);
221 e_configure_registry_call("applications/new_application", NULL, path);
222 evas_object_del(popup);
223 }
224 }
225
226 static void
_icon_theme_file_set(Evas_Object * img,const char * icon)227 _icon_theme_file_set(Evas_Object *img, const char *icon)
228 {
229 const char *path = NULL, *k = NULL;
230 char buf[4096];
231 int len = 0;
232
233 if (!icon)
234 path = NULL;
235 else if (strncmp(icon, "/", 1) && !ecore_file_exists(icon))
236 {
237 path = efreet_icon_path_find(e_config->icon_theme, icon, 48);
238 if (!path)
239 {
240 if (e_util_strcmp(e_config->icon_theme, "hicolor"))
241 path = efreet_icon_path_find("hicolor", icon, 48);
242 }
243 }
244 else if (ecore_file_exists(icon))
245 {
246 path = icon;
247 }
248 if (!path && icon)
249 {
250 snprintf(buf, sizeof(buf), "e/icons/%s", icon);
251 if (eina_list_count(e_theme_collection_items_find("base/theme/icons", buf)))
252 {
253 path = e_theme_edje_file_get("base/theme/icons", buf);
254 k = buf;
255 }
256 else
257 {
258 path = e_theme_edje_file_get("base/theme/icons", "e/icons/unknown");
259 k = "e/icons/unknown";
260 }
261 }
262 else if (!path && !icon)
263 {
264 path = e_theme_edje_file_get("base/theme/icons", "e/icons/unknown");
265 k = "e/icons/unknown";
266 }
267 if (path && icon)
268 {
269 len = strlen(icon);
270 if ((len > 4) && (!strcasecmp(icon + len - 4, ".edj")))
271 k = "icon";
272 }
273 elm_image_file_set(img, path, k);
274 }
275
276 static void
_update_preview_size(void * data,Evas_Object * obj,void * event_info EINA_UNUSED)277 _update_preview_size(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
278 {
279 Instance *inst = data;
280 int value = elm_slider_value_get(obj);
281
282 inst->cfg->preview_size = value;
283 e_config_save_queue();
284 }
285
286 EINTERN Evas_Object *
config_luncher(E_Zone * zone,Instance * inst,Eina_Bool bar)287 config_luncher(E_Zone *zone, Instance *inst, Eina_Bool bar)
288 {
289 Evas_Object *popup, *tb, *lbl, *fr, *box, *list, *mlist;
290 Evas_Object *butbox, *sep, *hbox, *img, *but, *o, *group;
291 Evas_Object *slider, *check;
292 Elm_Object_Item *it;
293
294 luncher_config->bar = bar;
295
296 popup = elm_popup_add(e_comp->elm);
297 E_EXPAND(popup);
298 elm_popup_allow_events_set(popup, 1);
299 elm_popup_scrollable_set(popup, 1);
300
301 tb = elm_table_add(popup);
302 E_EXPAND(tb);
303 evas_object_size_hint_align_set(tb, EVAS_HINT_FILL, EVAS_HINT_FILL);
304 evas_object_show(tb);
305 elm_object_content_set(popup, tb);
306
307 lbl = elm_label_add(tb);
308 evas_object_size_hint_weight_set(lbl, EVAS_HINT_EXPAND, 0.0);
309 evas_object_size_hint_align_set(lbl, EVAS_HINT_FILL, EVAS_HINT_FILL);
310 elm_object_style_set(lbl, "marker");
311 evas_object_show(lbl);
312 elm_object_text_set(lbl, _("Luncher Configuration"));
313 elm_table_pack(tb, lbl, 0, 0, 2, 1);
314
315 mlist = elm_list_add(tb);
316 E_ALIGN(mlist, 0, EVAS_HINT_FILL);
317 E_WEIGHT(mlist, 0, EVAS_HINT_EXPAND);
318 elm_table_pack(tb, mlist, 0, 1, 1, 1);
319 elm_list_select_mode_set(mlist, ELM_OBJECT_SELECT_MODE_ALWAYS);
320 elm_scroller_content_min_limit(mlist, 1, 1);
321 it = elm_list_item_append(mlist, _("General"), NULL, NULL,
322 _config_show_general, inst);
323 elm_list_item_selected_set(it, 1);
324 it = elm_list_item_append(mlist, _("Contents"), NULL, NULL,
325 _config_show_contents, inst);
326 elm_list_go(mlist);
327 evas_object_show(mlist);
328
329 fr = elm_frame_add(tb);
330 elm_object_text_set(fr, _("General"));
331 E_EXPAND(fr);
332 evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
333 elm_table_pack(tb, fr, 1, 1, 1, 1);
334 evas_object_show(fr);
335 luncher_config->general = fr;
336
337 box = elm_box_add(fr);
338 elm_box_horizontal_set(box, EINA_FALSE);
339 E_EXPAND(box);
340 evas_object_show(box);
341
342 lbl = elm_label_add(box);
343 elm_object_text_set(lbl, _("Luncher Type:"));
344 E_ALIGN(lbl, 0.5, 0.5);
345 E_WEIGHT(lbl, EVAS_HINT_EXPAND, 0);
346 elm_box_pack_end(box, lbl);
347 evas_object_show(lbl);
348
349 o = elm_radio_add(box);
350 elm_radio_state_value_set(o, 0);
351 E_ALIGN(o, 0.0, 0.0);
352 E_WEIGHT(o, EVAS_HINT_EXPAND, 0);
353 elm_object_text_set(o, _("Launcher and Taskbar"));
354 elm_box_pack_end(box, o);
355 evas_object_smart_callback_add(o, "changed", _type_changed, inst);
356 evas_object_show(o);
357 group = o;
358
359 o = elm_radio_add(box);
360 elm_radio_state_value_set(o, 1);
361 elm_radio_group_add(o, group);
362 E_ALIGN(o, 0.0, 0.0);
363 E_WEIGHT(o, EVAS_HINT_EXPAND, 0);
364 elm_object_text_set(o, _("Launcher Only"));
365 elm_box_pack_end(box, o);
366 evas_object_smart_callback_add(o, "changed", _type_changed, inst);
367 evas_object_show(o);
368
369 o = elm_radio_add(box);
370 elm_radio_state_value_set(o, 2);
371 elm_radio_group_add(o, group);
372 E_ALIGN(o, 0.0, 0.0);
373 E_WEIGHT(o, EVAS_HINT_EXPAND, 0);
374 elm_object_text_set(o, _("Taskbar Only"));
375 elm_box_pack_end(box, o);
376 evas_object_smart_callback_add(o, "changed", _type_changed, inst);
377 evas_object_show(o);
378
379 switch(inst->cfg->type)
380 {
381 case E_LUNCHER_MODULE_FULL:
382 elm_radio_value_set(group, 0);
383 break;
384 case E_LUNCHER_MODULE_LAUNCH_ONLY:
385 elm_radio_value_set(group, 1);
386 break;
387 case E_LUNCHER_MODULE_TASKS_ONLY:
388 elm_radio_value_set(group, 2);
389 break;
390 default:
391 elm_radio_value_set(group, 0);
392 }
393
394 o = elm_separator_add(box);
395 elm_separator_horizontal_set(o, EINA_TRUE);
396 E_EXPAND(o);
397 E_FILL(o);
398 elm_box_pack_end(box, o);
399 evas_object_show(o);
400
401 lbl = elm_label_add(box);
402 elm_object_text_set(lbl, _("Tooltips:"));
403 E_ALIGN(lbl, 0.5, 0.5);
404 E_WEIGHT(lbl, EVAS_HINT_EXPAND, 0);
405 elm_box_pack_end(box, lbl);
406 evas_object_show(lbl);
407
408 check = elm_check_add(box);
409 elm_object_text_set(check, _("Hide tooltips"));
410 elm_check_state_set(check, inst->cfg->hide_tooltips);
411 E_ALIGN(check, 0.0, 0.0);
412 E_WEIGHT(check, EVAS_HINT_EXPAND, 0);
413 evas_object_smart_callback_add(check, "changed", _check_changed, inst);
414 elm_box_pack_end(box, check);
415 evas_object_show(check);
416
417 o = elm_separator_add(box);
418 elm_separator_horizontal_set(o, EINA_TRUE);
419 E_EXPAND(o);
420 E_FILL(o);
421 elm_box_pack_end(box, o);
422 evas_object_show(o);
423
424 lbl = elm_label_add(box);
425 elm_object_text_set(lbl, _("Preview Size:"));
426 E_ALIGN(lbl, 0.5, 0.5);
427 E_WEIGHT(lbl, EVAS_HINT_EXPAND, 0);
428 elm_box_pack_end(box, lbl);
429 evas_object_show(lbl);
430
431 slider = elm_slider_add(box);
432 elm_slider_unit_format_set(slider, "%1.0f");
433 elm_slider_indicator_format_set(slider, "%1.0f");
434 elm_slider_min_max_set(slider, 1, 256);
435 elm_slider_value_set(slider, inst->cfg->preview_size);
436 elm_slider_step_set(slider, 1 / 256.0);
437 elm_slider_span_size_set(slider, 256);
438 E_ALIGN(slider, 0.0, 0.0);
439 E_WEIGHT(slider, EVAS_HINT_EXPAND, 0);
440 evas_object_smart_callback_add(slider, "delay,changed", _update_preview_size, inst);
441 elm_box_pack_end(box, slider);
442 evas_object_show(slider);
443
444 elm_object_content_set(fr, box);
445
446 fr = elm_frame_add(tb);
447 elm_object_text_set(fr, _("Contents"));
448 E_EXPAND(fr);
449 evas_object_size_hint_align_set(fr, EVAS_HINT_FILL, EVAS_HINT_FILL);
450 elm_table_pack(tb, fr, 1, 1, 1, 1);
451 evas_object_show(fr);
452 luncher_config->contents = fr;
453
454 box = elm_box_add(fr);
455 elm_box_horizontal_set(box, EINA_FALSE);
456 E_EXPAND(box);
457 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
458 evas_object_show(box);
459
460 hbox = elm_box_add(box);
461 elm_box_horizontal_set(hbox, EINA_TRUE);
462 elm_box_homogeneous_set(hbox, EINA_FALSE);
463 evas_object_size_hint_expand_set(hbox, 0.0, EVAS_HINT_EXPAND);
464 evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
465 elm_box_pack_end(box, hbox);
466 evas_object_show(hbox);
467
468 list = elm_list_add(hbox);
469 E_ALIGN(list, EVAS_HINT_FILL, EVAS_HINT_FILL);
470 E_WEIGHT(list, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
471 elm_box_pack_end(hbox, list);
472 elm_list_select_mode_set(list, ELM_OBJECT_SELECT_MODE_ALWAYS);
473 elm_scroller_content_min_limit(list, 1, 1);
474 evas_object_show(list);
475 luncher_config->list = list;
476 _config_populate_order_list(list, inst);
477
478 butbox = elm_box_add(hbox);
479 elm_box_horizontal_set(butbox, EINA_FALSE);
480 E_EXPAND(butbox);
481 evas_object_size_hint_align_set(butbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
482 elm_box_pack_end(hbox, butbox);
483 evas_object_show(butbox);
484
485 sep = elm_separator_add(box);
486 elm_separator_horizontal_set(sep, EINA_TRUE);
487 elm_box_pack_end(box, sep);
488 evas_object_show(sep);
489
490 img = elm_icon_add(butbox);
491 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
492 _icon_theme_file_set(img, "list-add");
493 evas_object_show(img);
494
495 but = elm_button_add(butbox);
496 elm_object_part_content_set(but, "icon", img);
497 elm_object_text_set(but, _("Add"));
498 E_EXPAND(but);
499 evas_object_size_hint_align_set(but, EVAS_HINT_FILL, EVAS_HINT_FILL);
500 evas_object_data_set(but, "popup", popup);
501 evas_object_smart_callback_add(but, "clicked", _config_source_add, inst);
502 elm_box_pack_end(butbox, but);
503 evas_object_show(but);
504
505 img = elm_icon_add(butbox);
506 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
507 _icon_theme_file_set(img, "list-remove");
508 evas_object_show(img);
509
510 but = elm_button_add(butbox);
511 elm_object_part_content_set(but, "icon", img);
512 elm_object_text_set(but, _("Delete"));
513 E_EXPAND(but);
514 evas_object_size_hint_align_set(but, EVAS_HINT_FILL, EVAS_HINT_FILL);
515 evas_object_data_set(but, "popup", popup);
516 evas_object_smart_callback_add(but, "clicked", _config_source_del, inst);
517 elm_box_pack_end(butbox, but);
518 evas_object_show(but);
519
520 hbox = elm_box_add(box);
521 elm_box_horizontal_set(hbox, EINA_TRUE);
522 elm_box_homogeneous_set(hbox, EINA_TRUE);
523 E_EXPAND(box);
524 evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
525 elm_box_pack_end(box, hbox);
526 evas_object_show(hbox);
527
528 img = elm_icon_add(hbox);
529 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
530 _icon_theme_file_set(img, "document-new");
531 evas_object_show(img);
532
533 but = elm_button_add(hbox);
534 elm_object_part_content_set(but, "icon", img);
535 elm_object_text_set(but, _("Create New Icon"));
536 E_EXPAND(but);
537 evas_object_size_hint_align_set(but, EVAS_HINT_FILL, EVAS_HINT_FILL);
538 evas_object_data_set(but, "popup", popup);
539 evas_object_smart_callback_add(but, "clicked", _config_create_icon, inst);
540 elm_box_pack_end(hbox, but);
541 evas_object_show(but);
542
543 img = elm_icon_add(hbox);
544 evas_object_size_hint_aspect_set(img, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
545 _icon_theme_file_set(img, "list-add");
546 evas_object_show(img);
547
548 but = elm_button_add(hbox);
549 elm_object_part_content_set(but, "icon", img);
550 elm_object_text_set(but, _("Contents"));
551 E_EXPAND(but);
552 evas_object_size_hint_align_set(but, EVAS_HINT_FILL, EVAS_HINT_FILL);
553 evas_object_data_set(but, "popup", popup);
554 evas_object_smart_callback_add(but, "clicked", _config_contents, inst);
555 elm_box_pack_end(hbox, but);
556 evas_object_show(but);
557
558 elm_object_content_set(fr, box);
559
560 _config_show_general(NULL, NULL, NULL);
561
562 popup = e_comp_object_util_add(popup, E_COMP_OBJECT_TYPE_NONE);
563 evas_object_layer_set(popup, E_LAYER_POPUP);
564 evas_object_resize(popup, zone->w / 4, zone->h / 3);
565 e_comp_object_util_center_on_zone(popup, zone);
566 evas_object_show(popup);
567 e_comp_object_util_autoclose(popup, NULL, e_comp_object_util_autoclose_on_escape, NULL);
568 evas_object_event_callback_add(popup, EVAS_CALLBACK_DEL, _config_close, NULL);
569
570 return luncher_config->config_dialog = popup;
571 }
572
573