3 /* TODO: Check cache update */
5 struct _E_Config_Dialog_Data
7 Efreet_Desktop *desktop;
8 int type; /* desktop type */
10 char *name; /* app name (e.g. Firefox) */
11 char *generic_name; /* generic app name (e.g. Web Browser) */
12 char *comment; /* a longer description */
13 char *exec; /* command to execute */
14 char *try_exec; /* executable to test for an apps existence */
15 char *url; /* url to open */
17 char *startup_wm_class; /* window class */
18 char *categories; /* list of category names that app is in */
19 char *mimes; /* list of mimes this app can handle */
20 char *icon; /* absolute path to file or icon name */
26 E_Desktop_Edit *editor;
28 char *orig_path; /* informational only */
29 Evas_Object *orig_path_entry; /* to set when info changes */
30 Evas_Object *icon_entry; /* to set when icon changes */
32 /* speed up check_changed tests */
33 Eina_Bool changed_categories;
34 Eina_Bool changed_mimes;
35 Eina_Bool edited_categories;
36 Eina_Bool edited_mimes;
39 /* local subsystem functions */
41 static int _e_desktop_edit_view_create(E_Desktop_Edit *editor, E_Comp *c);
42 static void _e_desktop_edit_free(E_Desktop_Edit *editor);
43 static void *_e_desktop_edit_create_data(E_Config_Dialog *cfd);
44 static void _e_desktop_edit_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *data);
45 static int _e_desktop_edit_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *data);
46 static int _e_desktop_edit_basic_check_changed(E_Config_Dialog *cfd, E_Config_Dialog_Data *data);
47 static Evas_Object *_e_desktop_edit_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *data);
48 static void _e_desktop_editor_cb_icon_select(void *data1, void *data2);
49 static void _e_desktop_edit_cb_icon_select_destroy(void *obj);
50 static void _e_desktop_edit_cb_icon_select_ok(void *data, E_Dialog *dia);
51 static void _e_desktop_edit_cb_icon_select_cancel(void *data, E_Dialog *dia);
52 static void _e_desktop_editor_icon_update(E_Config_Dialog_Data *cfdata);
53 static void _e_desktop_editor_cb_exec_select(void *data1, void *data2);
54 static void _e_desktop_edit_cb_exec_select_destroy(void *obj);
55 static void _e_desktop_edit_cb_exec_select_ok(void *data, E_Dialog *dia);
56 static void _e_desktop_edit_cb_exec_select_cancel(void *data, E_Dialog *dia);
57 static void _e_desktop_editor_exec_update(E_Config_Dialog_Data *cfdata);
58 static void _e_desktop_edit_select_cb(void *data, Evas_Object *obj);
59 static void _e_desktop_editor_icon_entry_changed(void *data, Evas_Object *obj);
61 #define IFDUP(src, dst) if (src) dst = strdup(src); else \
66 _e_util_icon_save(Ecore_X_Icon *icon, const char *filename)
73 ee = ecore_evas_buffer_new(icon->width, icon->height);
75 evas = ecore_evas_get(ee);
76 evas_image_cache_set(evas, 0);
77 evas_font_cache_set(evas, 0);
79 im = evas_object_image_add(evas);
85 evas_object_move(im, 0, 0);
86 evas_object_resize(im, icon->width, icon->height);
87 evas_object_image_size_set(im, icon->width, icon->height);
88 evas_object_image_data_copy_set(im, icon->data);
89 evas_object_image_alpha_set(im, 1);
91 ret = evas_object_image_save(im, filename, NULL, NULL);
96 /* externally accessible functions */
99 e_desktop_client_create(E_Client *ec)
101 Efreet_Desktop *desktop = NULL;
102 const char *desktop_dir, *icon_dir;
103 const char *bname, *bclass, *btitle;
106 bname = ec->icccm.name;
107 if ((bname) && (bname[0] == 0)) bname = NULL;
108 bclass = ec->icccm.class;
109 if ((bclass) && (bclass[0] == 0)) bclass = NULL;
110 btitle = e_client_util_name_get(ec);
112 desktop_dir = e_user_desktop_dir_get();
114 if ((!desktop_dir) || (!e_util_dir_check(desktop_dir))) return NULL;
116 icon_dir = e_user_icon_dir_get();
117 if ((!icon_dir) || (!e_util_dir_check(icon_dir))) return NULL;
121 snprintf(path, sizeof(path), "%s/%s.desktop", desktop_dir, bname);
122 desktop = efreet_desktop_empty_new(path);
128 for (i = 1; i < 65536; i++)
130 snprintf(path, sizeof(path), "%s/_new_app-%i.desktop",
132 if (!ecore_file_exists(path))
134 desktop = efreet_desktop_empty_new(path);
140 snprintf(path, sizeof(path), "%s/_rename_me-%i.desktop",
141 desktop_dir, (int)ecore_time_get());
142 desktop = efreet_desktop_empty_new(NULL);
151 if (bclass) desktop->name = strdup(bclass);
153 desktop->name = strdup(bname);
155 desktop->name = strdup(btitle);
157 if (btitle) desktop->comment = strdup(btitle);
159 if (bclass) desktop->startup_wm_class = strdup(bclass);
160 if (ec->icccm.command.argc > 0)
161 // FIXME this should concat the entire argv array together
162 desktop->exec = strdup(ec->icccm.command.argv[0]);
164 desktop->exec = strdup(bname);
167 // if (ec->netwm.startup_id > 0) desktop->startup_notify = 1;
171 * - Find the icon with the best size
172 * - Should use mkstemp
176 snprintf(file, sizeof(file), "%s-%.6f.png", bname ?: "", ecore_time_get());
177 snprintf(path, sizeof(path), "%s/%s", icon_dir, file);
178 if (_e_util_icon_save(&(ec->netwm.icons[0]), path))
179 desktop->icon = strdup(file);
181 fprintf(stderr, "Could not save file from ARGB: %s\n", path);
186 EAPI E_Desktop_Edit *
187 e_desktop_border_edit(E_Comp *c, E_Client *ec)
189 E_Desktop_Edit *editor;
192 editor = E_OBJECT_ALLOC(E_Desktop_Edit, E_DESKTOP_EDIT_TYPE, _e_desktop_edit_free);
193 if (!editor) return NULL;
195 editor->desktop = ec->desktop;
197 /* the border does not yet have a desktop entry. add one and pre-populate
198 it with values from the border */
199 if (!editor->desktop)
201 editor->desktop = e_desktop_client_create(ec);
202 if ((editor->desktop) && (editor->desktop->icon))
203 editor->tmp_image_path = strdup(editor->desktop->icon);
208 if ((!bname) && (!bclass))
210 e_util_dialog_show(_("Incomplete Window Properties"),
211 _("The window you are creating an icon for<br>"
212 "does not contain window name and class<br>"
213 "properties. Without these, you will have to<br>"
214 "use the window title instead. This will only<br>"
215 "work if the window title is the same at<br>"
216 "the time the window starts up, and does not<br>"
220 if (!_e_desktop_edit_view_create(editor, c))
222 e_object_del(E_OBJECT(editor));
226 e_config_dialog_changed_set(editor->cfd, new_desktop);
231 EAPI E_Desktop_Edit *
232 e_desktop_edit(E_Comp *c, Efreet_Desktop *desktop)
234 E_Desktop_Edit *editor;
236 editor = E_OBJECT_ALLOC(E_Desktop_Edit, E_DESKTOP_EDIT_TYPE, _e_desktop_edit_free);
237 if (!editor) return NULL;
238 if (desktop) editor->desktop = desktop;
239 if (!_e_desktop_edit_view_create(editor, c))
241 e_object_del(E_OBJECT(editor));
248 _e_desktop_edit_view_create(E_Desktop_Edit *editor, E_Comp *c EINA_UNUSED)
250 E_Config_Dialog_View *v;
252 v = E_NEW(E_Config_Dialog_View, 1);
256 v->create_cfdata = _e_desktop_edit_create_data;
257 v->free_cfdata = _e_desktop_edit_free_data;
258 v->basic.apply_cfdata = _e_desktop_edit_basic_apply_data;
259 v->basic.create_widgets = _e_desktop_edit_basic_create_widgets;
260 v->basic.check_changed = _e_desktop_edit_basic_check_changed;
263 e_config_dialog_new(NULL, _("Desktop Entry Editor"), "E",
264 "applications/new_application",
265 "preferences-applications", 0, v, editor);
276 /* local subsystem functions */
278 _e_desktop_edit_free(E_Desktop_Edit *editor)
281 E_OBJECT_CHECK(editor);
282 E_OBJECT_TYPE_CHECK(editor, E_DESKTOP_EDIT_TYPE);
284 E_FREE(editor->tmp_image_path);
289 * Populates the config dialog's data from the .desktop file passed in
292 _e_desktop_edit_create_data(E_Config_Dialog *cfd)
294 E_Config_Dialog_Data *cfdata;
295 Efreet_Desktop *desktop = NULL;
298 cfdata = E_NEW(E_Config_Dialog_Data, 1);
299 if (!cfdata) return NULL;
300 e_win_no_reopen_set(cfd->dia->win, 1);
301 cfdata->editor = cfd->data;
304 * If we can't write to the file on it's current location,
305 * we always save to the user's applications dir.
306 * If the file is already there, then edit it directly. Otherwise, create
307 * a new empty desktop entry there.
309 * cfdata->editor->desktop is the the desktop passed in
310 * cfdata->desktop is the desktop to save
311 * desktop is the desktop to load
314 if (cfdata->editor->desktop)
319 if (ecore_file_can_write(cfdata->editor->desktop->orig_path))
320 cfdata->desktop = efreet_desktop_uncached_new(cfdata->editor->desktop->orig_path);
323 snprintf(dir, sizeof(dir), "%s/applications", efreet_data_home_get());
324 if (!strncmp(dir, cfdata->editor->desktop->orig_path, strlen(dir)))
325 cfdata->desktop = efreet_desktop_uncached_new(cfdata->editor->desktop->orig_path);
328 /* file not in user's dir, so create new desktop that points there */
329 if (!ecore_file_exists(dir)) ecore_file_mkdir(dir);
330 file = ecore_file_file_get(cfdata->editor->desktop->orig_path);
331 snprintf(path, sizeof(path), "%s/%s", dir, file);
333 * if a file already exists in the user dir with this name, we
334 * fetch the pointer to it, so the caches stay consistent (this
335 * probably will never return non null, since the ui shouldn't
336 * provide a means to edit a file in a system dir when one
337 * exists in the user's
339 cfdata->desktop = efreet_desktop_uncached_new(path);
342 desktop = cfdata->editor->desktop;
345 if (!cfdata->desktop)
346 cfdata->desktop = efreet_desktop_empty_new(path);
348 if (!desktop) desktop = cfdata->desktop;
350 IFDUP(desktop->name, cfdata->name);
351 IFDUP(desktop->generic_name, cfdata->generic_name);
352 IFDUP(desktop->comment, cfdata->comment);
353 IFDUP(desktop->exec, cfdata->exec);
354 IFDUP(desktop->try_exec, cfdata->try_exec);
355 IFDUP(desktop->url, cfdata->url);
356 IFDUP(desktop->startup_wm_class, cfdata->startup_wm_class);
357 IFDUP(desktop->orig_path, cfdata->orig_path);
359 if (desktop->categories)
360 cfdata->categories = efreet_desktop_string_list_join(desktop->categories);
361 if (desktop->mime_types)
362 cfdata->mimes = efreet_desktop_string_list_join(desktop->mime_types);
364 IFDUP(desktop->icon, cfdata->icon);
366 cfdata->startup_notify = desktop->startup_notify;
367 cfdata->terminal = desktop->terminal;
368 cfdata->show_in_menus = !desktop->no_display;
370 if (cfdata->exec && *cfdata->exec)
372 else if (cfdata->url && *cfdata->url)
379 * Frees the config dialog data
382 _e_desktop_edit_free_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
384 if (cfdata->editor->tmp_image_path)
386 if ((!cfdata->desktop) || (!cfdata->editor->saved) ||
387 (!cfdata->desktop->icon) ||
388 (strcmp(cfdata->editor->tmp_image_path, cfdata->desktop->icon)))
390 ecore_file_unlink(cfdata->editor->tmp_image_path);
393 if (cfdata->desktop) efreet_desktop_free(cfdata->desktop);
395 E_FREE(cfdata->name);
396 E_FREE(cfdata->generic_name);
397 E_FREE(cfdata->comment);
398 E_FREE(cfdata->exec);
399 E_FREE(cfdata->try_exec);
401 E_FREE(cfdata->startup_wm_class);
402 E_FREE(cfdata->categories);
403 E_FREE(cfdata->icon);
404 E_FREE(cfdata->mimes);
405 E_FREE(cfdata->orig_path);
407 if (cfdata->editor->icon_fsel_dia)
408 e_object_del(E_OBJECT(cfdata->editor->icon_fsel_dia));
410 e_object_del(E_OBJECT(cfdata->editor));
415 _e_desktop_edit_user_local_desktop_filename_generate(E_Config_Dialog_Data *cfdata, char *path)
422 if ((cfdata->name) && (cfdata->name[0]))
424 else if ((cfdata->desktop) && (cfdata->desktop->name) &&
425 (cfdata->desktop->name[0]))
432 const char *s = name;
433 for (i = 0; i < sizeof(buf) - 1 && s[i]; i++)
443 eina_strlcpy(buf, "unnamed_desktop", sizeof(buf));
445 i = snprintf(path, PATH_MAX, "%s/applications/%s.desktop",
446 efreet_data_home_get(), buf);
452 prefix = i - (sizeof(".desktop") - 1);
454 for (i = 0; ecore_file_exists(path); i++)
455 snprintf(path + prefix, PATH_MAX - prefix, "-%u.desktop", i);
459 _e_desktop_edit_update_orig_path(E_Config_Dialog_Data *cfdata)
461 const char *orig_path;
464 if ((cfdata->desktop->orig_path) && (cfdata->desktop->orig_path[0]))
465 orig_path = cfdata->desktop->orig_path;
468 _e_desktop_edit_user_local_desktop_filename_generate(cfdata, path);
469 orig_path = cfdata->orig_path = strdup(path);
472 if (cfdata->orig_path_entry)
473 e_widget_entry_text_set(cfdata->orig_path_entry, orig_path);
477 * Apply the basic config dialog
480 _e_desktop_edit_basic_apply_data(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
482 E_FREE(cfdata->desktop->name);
483 IFDUP(cfdata->name, cfdata->desktop->name);
484 E_FREE(cfdata->desktop->comment);
485 IFDUP(cfdata->comment, cfdata->desktop->comment);
487 switch (cfdata->type)
490 E_FREE(cfdata->desktop->url);
491 IFDUP(cfdata->url, cfdata->desktop->url);
495 E_FREE(cfdata->desktop->exec);
496 IFDUP(cfdata->exec, cfdata->desktop->exec);
497 E_FREE(cfdata->desktop->try_exec);
498 IFDUP(cfdata->try_exec, cfdata->desktop->try_exec);
502 E_FREE(cfdata->desktop->generic_name);
503 IFDUP(cfdata->generic_name, cfdata->desktop->generic_name);
504 E_FREE(cfdata->desktop->startup_wm_class);
505 IFDUP(cfdata->startup_wm_class, cfdata->desktop->startup_wm_class);
508 E_FREE_LIST(cfdata->desktop->categories, eina_stringshare_del);
509 if (cfdata->categories)
510 cfdata->desktop->categories = efreet_desktop_string_list_parse(cfdata->categories);
512 E_FREE_LIST(cfdata->desktop->mime_types, eina_stringshare_del);
514 cfdata->desktop->mime_types = efreet_desktop_string_list_parse(cfdata->mimes);
516 E_FREE(cfdata->desktop->icon);
517 IFDUP(cfdata->icon, cfdata->desktop->icon);
519 cfdata->desktop->startup_notify = cfdata->startup_notify;
520 cfdata->desktop->terminal = cfdata->terminal;
521 cfdata->desktop->no_display = !cfdata->show_in_menus;
523 if (cfdata->desktop->orig_path && cfdata->desktop->orig_path[0])
524 cfdata->editor->saved = efreet_desktop_save(cfdata->desktop);
527 _e_desktop_edit_update_orig_path(cfdata);
528 cfdata->editor->saved = efreet_desktop_save_as
529 (cfdata->desktop, cfdata->orig_path);
535 _e_desktop_edit_basic_check_changed(E_Config_Dialog *cfd __UNUSED__, E_Config_Dialog_Data *cfdata)
539 if ((cfdata->startup_notify != cfdata->desktop->startup_notify) ||
540 (cfdata->terminal != cfdata->desktop->terminal) ||
541 (cfdata->show_in_menus != !cfdata->desktop->no_display))
548 if (cfdata->desktop->k) \
549 __k = cfdata->desktop->k; \
550 else if ((cfdata->editor) && (cfdata->editor->desktop)) \
551 __k = cfdata->editor->desktop->k; \
554 if ((cfdata->k && !__k) || (!cfdata->k && __k) || \
555 (cfdata->k && __k && strcmp(cfdata->k, __k) != 0)) \
566 CHECK(startup_wm_class);
572 if (cfdata->edited_categories)
575 Eina_List *lst = NULL, *old_lst;
577 cfdata->edited_categories = EINA_FALSE;
578 cfdata->changed_categories = EINA_FALSE;
580 if (cfdata->desktop->categories)
581 old_lst = cfdata->desktop->categories;
582 else if ((cfdata->editor) && (cfdata->editor->desktop))
583 old_lst = cfdata->editor->desktop->categories;
587 if (cfdata->categories)
588 lst = efreet_desktop_string_list_parse(cfdata->categories);
589 if (eina_list_count(lst) != eina_list_count(old_lst))
590 cfdata->changed_categories = EINA_TRUE;
592 EINA_LIST_FREE(lst, str)
594 if (!cfdata->changed_categories)
598 Eina_Bool found = EINA_FALSE;
599 EINA_LIST_FOREACH(old_lst, n, old)
601 if (strcmp(str, old) == 0)
608 cfdata->changed_categories = EINA_TRUE;
610 eina_stringshare_del(str);
613 ret |= cfdata->changed_categories;
617 if (cfdata->edited_mimes)
620 Eina_List *lst = NULL, *old_lst;
622 cfdata->edited_mimes = EINA_FALSE;
623 cfdata->changed_mimes = EINA_FALSE;
625 if (cfdata->desktop->mime_types)
626 old_lst = cfdata->desktop->mime_types;
627 else if ((cfdata->editor) && (cfdata->editor->desktop))
628 old_lst = cfdata->editor->desktop->mime_types;
633 lst = efreet_desktop_string_list_parse(cfdata->mimes);
634 if (eina_list_count(lst) != eina_list_count(old_lst))
635 cfdata->changed_mimes = EINA_TRUE;
637 EINA_LIST_FREE(lst, str)
639 if (!cfdata->changed_mimes)
643 Eina_Bool found = EINA_FALSE;
644 EINA_LIST_FOREACH(old_lst, n, old)
646 if (strcmp(str, old) == 0)
653 cfdata->changed_mimes = EINA_TRUE;
655 eina_stringshare_del(str);
658 ret |= cfdata->changed_mimes;
665 _e_desktop_editor_name_changed(void *data, Evas_Object *obj __UNUSED__)
667 E_Config_Dialog_Data *cfdata = data;
668 _e_desktop_edit_update_orig_path(cfdata);
672 _e_desktop_editor_categories_changed(void *data, Evas_Object *obj __UNUSED__)
674 E_Config_Dialog_Data *cfdata = data;
675 cfdata->edited_categories = EINA_TRUE;
679 _e_desktop_editor_icon_entry_changed(void *data, Evas_Object *obj __UNUSED__)
681 E_Config_Dialog_Data *cfdata = data;
682 _e_desktop_editor_icon_update(cfdata);
686 _e_desktop_editor_mimes_changed(void *data, Evas_Object *obj __UNUSED__)
688 E_Config_Dialog_Data *cfdata = data;
689 cfdata->edited_mimes = EINA_TRUE;
693 _e_desktop_edit_basic_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata)
695 E_Desktop_Edit *editor = cfdata->editor;
697 Evas_Object *otb, *ol, *o, *ot;
702 otb = e_widget_toolbook_add(evas, 48 * e_scale, 48 * e_scale);
704 ot = e_widget_table_add(evas, 0);
706 o = e_widget_label_add(evas, _("Name"));
707 e_widget_table_object_append(ot, o, 0, 0, 1, 1, 1, 1, 0, 0);
709 o = e_widget_entry_add(evas, &(cfdata->name), NULL, NULL, NULL);
710 e_widget_size_min_get(o, &mw, &mh);
711 if (mw < 220) mw = 220;
712 e_widget_size_min_set(o, mw, mh);
713 if ((!cfdata->desktop->orig_path) || (!cfdata->desktop->orig_path[0]))
714 e_widget_on_change_hook_set(o, _e_desktop_editor_name_changed, cfdata);
715 e_widget_table_object_append(ot, o, 1, 0, 1, 1, 1, 1, 1, 0);
717 o = e_widget_label_add(evas, _("Comment"));
718 e_widget_table_object_append(ot, o, 0, 1, 1, 1, 1, 1, 0, 0);
720 o = e_widget_entry_add(evas, &(cfdata->comment), NULL, NULL, NULL);
721 e_widget_table_object_append(ot, o, 1, 1, 1, 1, 1, 1, 1, 0);
723 rg = e_widget_radio_group_new(&(cfdata->type));
725 // desktop type: application
727 o = e_widget_radio_add(evas, _("Application"), 0, rg);
728 e_widget_table_object_append(ot, o, 0, 2, 1, 1, 1, 1, 0, 0);
730 editor->entry_widget_exec = e_widget_entry_add
731 (evas, &(cfdata->exec), NULL, NULL, NULL);
732 e_widget_table_object_append(ot, editor->entry_widget_exec, 1, 2, 1, 1, 1, 1, 1, 0);
734 o = e_widget_button_add
735 (evas, "...", NULL, _e_desktop_editor_cb_exec_select, cfdata, editor);
736 e_widget_table_object_append(ot, o, 2, 2, 1, 1, 0, 0, 0, 0);
739 o = e_widget_radio_add(evas, _("URL"), 1, rg);
740 e_widget_table_object_append(ot, o, 0, 3, 1, 1, 1, 1, 0, 0);
742 editor->entry_widget_url = e_widget_entry_add
743 (evas, &(cfdata->url), NULL, NULL, NULL);
744 e_widget_table_object_append(ot, editor->entry_widget_url, 1, 3, 1, 1, 1, 1, 1, 0);
745 // FIXME: add url selection dialog (file:/etc/..)
747 e_widget_toolbook_page_append
748 (otb, NULL, _("Basic"), ot, 1, 0, 1, 0, 0.5, 0.0);
750 /* e_widget_size_min_get(ol, &mw, &mh); */
752 ot = e_widget_table_add(evas, 0);
754 editor->img_widget = e_widget_button_add
755 (evas, "", NULL, _e_desktop_editor_cb_icon_select, cfdata, editor);
756 _e_desktop_editor_icon_update(cfdata);
757 e_widget_size_min_set(editor->img_widget, 192, 192);
759 e_widget_table_object_append(ot, editor->img_widget, 0, 0, 2, 1, 1, 1, 0, 0);
761 o = e_widget_label_add(evas, _("Icon"));
762 e_widget_table_object_append(ot, o, 0, 1, 1, 1, 1, 1, 0, 0);
764 o = e_widget_entry_add(evas, &(cfdata->icon), NULL, NULL, NULL);
765 cfdata->icon_entry = o;
766 e_widget_on_change_hook_set(o, _e_desktop_editor_icon_entry_changed, cfdata);
767 e_widget_table_object_append(ot, o, 1, 1, 1, 1, 1, 1, 1, 0);
769 e_widget_toolbook_page_append
770 (otb, NULL, _("Icon"), ot, 0, 0, 0, 0, 0.5, 0.5);
772 ot = e_widget_table_add(evas, 0);
774 o = e_widget_label_add(evas, _("Generic Name"));
775 e_widget_table_object_append(ot, o, 0, 0, 1, 1, 1, 1, 0, 0);
777 o = e_widget_entry_add(evas, &(cfdata->generic_name), NULL, NULL, NULL);
778 e_widget_table_object_append(ot, o, 1, 0, 1, 1, 1, 1, 1, 0);
780 o = e_widget_label_add(evas, _("Window Class"));
781 e_widget_table_object_append(ot, o, 0, 1, 1, 1, 1, 1, 0, 0);
783 o = e_widget_entry_add(evas, &(cfdata->startup_wm_class), NULL, NULL, NULL);
784 e_widget_table_object_append(ot, o, 1, 1, 1, 1, 1, 1, 1, 0);
786 o = e_widget_label_add(evas, _("Categories"));
787 e_widget_table_object_append(ot, o, 0, 2, 1, 1, 1, 1, 0, 0);
789 o = e_widget_entry_add(evas, &(cfdata->categories), NULL, NULL, NULL);
790 e_widget_on_change_hook_set(o, _e_desktop_editor_categories_changed, cfdata);
791 e_widget_table_object_append(ot, o, 1, 2, 1, 1, 1, 1, 1, 0);
793 o = e_widget_label_add(evas, _("Mime Types"));
794 e_widget_table_object_append(ot, o, 0, 3, 1, 1, 1, 1, 0, 0);
796 o = e_widget_entry_add(evas, &(cfdata->mimes), NULL, NULL, NULL);
797 e_widget_on_change_hook_set(o, _e_desktop_editor_mimes_changed, cfdata);
798 e_widget_table_object_append(ot, o, 1, 3, 1, 1, 1, 1, 1, 0);
800 o = e_widget_label_add(evas, _("Desktop file"));
801 e_widget_table_object_append(ot, o, 0, 4, 1, 1, 1, 1, 0, 0);
803 o = e_widget_entry_add(evas, NULL, NULL, NULL, NULL);
804 e_widget_table_object_append(ot, o, 1, 4, 1, 1, 1, 1, 1, 0);
805 e_widget_entry_readonly_set(o, 1);
806 cfdata->orig_path_entry = o;
807 _e_desktop_edit_update_orig_path(cfdata);
809 e_widget_toolbook_page_append
810 (otb, NULL, _("General"), ot, 1, 0, 1, 0, 0.5, 0.0);
812 ol = e_widget_list_add(evas, 0, 0);
813 o = e_widget_check_add(evas, _("Startup Notify"), &(cfdata->startup_notify));
814 e_widget_list_object_append(ol, o, 1, 0, 0.0);
815 o = e_widget_check_add(evas, _("Run in Terminal"), &(cfdata->terminal));
816 e_widget_list_object_append(ol, o, 1, 0, 0.0);
817 o = e_widget_check_add(evas, _("Show in Menus"), &(cfdata->show_in_menus));
818 e_widget_list_object_append(ol, o, 1, 0, 0.0);
819 e_widget_toolbook_page_append
820 (otb, NULL, _("Options"), ol, 1, 0, 1, 0, 0.5, 0.0);
822 e_widget_toolbook_page_show(otb, 0);
824 e_util_win_auto_resize_fill(cfd->dia->win);
825 elm_win_center(cfd->dia->win, 1, 1);
831 _e_desktop_editor_cb_icon_select(void *data1, void *data2)
833 E_Config_Dialog_Data *cfdata;
837 E_Desktop_Edit *editor;
839 const char *icon_path = NULL;
840 char buf[PATH_MAX + 32];
845 if (editor->icon_fsel_dia) return;
847 dia = e_dialog_new(NULL, "E", "_eap_icon_select_dialog");
849 e_object_del_attach_func_set(E_OBJECT(dia),
850 _e_desktop_edit_cb_icon_select_destroy);
851 snprintf(buf, sizeof(buf), _("Select an Icon for '%s'"), ecore_file_file_get(cfdata->orig_path));
852 e_dialog_title_set(dia, buf);
855 /* absolute path to icon */
856 /* XXX change this to a generic icon selector (that can do either
857 * files from a dir, or icons in the current theme */
860 if (ecore_file_exists(cfdata->icon))
861 icon_path = cfdata->icon;
863 icon_path = efreet_icon_path_find(e_config->icon_theme, cfdata->icon, 64);
866 path = ecore_file_dir_get(icon_path);
871 o = e_widget_fsel_add(evas_object_evas_get(dia->win), "/", path, NULL, NULL,
872 _e_desktop_edit_select_cb, cfdata,
878 o = e_widget_fsel_add(evas_object_evas_get(dia->win), "~/", "/", NULL, NULL,
879 _e_desktop_edit_select_cb, cfdata,
884 editor->icon_fsel = o;
885 e_widget_size_min_get(o, &mw, &mh);
886 e_dialog_content_set(dia, o, mw, mh);
888 /* buttons at the bottom */
889 e_dialog_button_add(dia, _("OK"), NULL,
890 _e_desktop_edit_cb_icon_select_ok, cfdata);
891 e_dialog_button_add(dia, _("Cancel"), NULL,
892 _e_desktop_edit_cb_icon_select_cancel, cfdata);
893 elm_win_center(dia->win, 1, 1);
895 editor->icon_fsel_dia = dia;
899 _e_desktop_editor_cb_exec_select(void *data1, void *data2)
901 E_Config_Dialog_Data *cfdata;
905 E_Desktop_Edit *editor;
911 if (editor->exec_fsel_dia) return;
913 dia = e_dialog_new(NULL, "E", "_eap_exec_select_dialog");
915 e_object_del_attach_func_set(E_OBJECT(dia),
916 _e_desktop_edit_cb_exec_select_destroy);
917 e_dialog_title_set(dia, _("Select an Executable"));
920 /* absolute path to exe */
923 path = ecore_file_dir_get(cfdata->exec);
924 if (path && !ecore_file_exists(path))
933 o = e_widget_fsel_add(evas_object_evas_get(dia->win), "/", path, NULL, NULL,
934 _e_desktop_edit_select_cb, cfdata,
941 o = e_widget_fsel_add(evas_object_evas_get(dia->win), "~/", "/", NULL, NULL,
942 _e_desktop_edit_select_cb, cfdata,
947 editor->exec_fsel = o;
948 e_widget_size_min_get(o, &mw, &mh);
949 e_dialog_content_set(dia, o, mw, mh);
951 /* buttons at the bottom */
952 e_dialog_button_add(dia, _("OK"), NULL,
953 _e_desktop_edit_cb_exec_select_ok, cfdata);
954 e_dialog_button_add(dia, _("Cancel"), NULL,
955 _e_desktop_edit_cb_exec_select_cancel, cfdata);
956 elm_win_center(dia->win, 1, 1);
958 editor->exec_fsel_dia = dia;
962 _e_desktop_edit_select_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__)
967 _e_desktop_edit_cb_icon_select_destroy(void *obj)
970 E_Config_Dialog_Data *cfdata = dia->data;
972 /* extra unref isn't needed - there is no extra ref() anywhere i saw */
973 /* e_object_unref(E_OBJECT(dia));*/
974 _e_desktop_edit_cb_icon_select_cancel(cfdata, NULL);
978 _e_desktop_edit_cb_icon_select_ok(void *data, E_Dialog *dia)
980 E_Config_Dialog_Data *cfdata;
983 const char *icon_dir;
986 file = e_widget_fsel_selection_path_get(cfdata->editor->icon_fsel);
987 dir = ecore_file_dir_get(file);
989 E_FREE(cfdata->icon);
991 /* TODO: Check for theme icon */
992 icon_dir = e_user_icon_dir_get();
993 if ((icon_dir) && (e_util_dir_check(icon_dir)) && (!e_util_strcmp(dir, icon_dir)))
995 cfdata->icon = strdup(ecore_file_file_get(file));
999 Eina_List *xdg_dirs, *l;
1002 xdg_dirs = efreet_data_dirs_get();
1004 EINA_LIST_FOREACH(xdg_dirs, l, icon_dir)
1006 snprintf(buf, sizeof(buf), "%s/icons", icon_dir);
1007 if (!ecore_file_is_dir(buf)) continue;
1008 if (!e_util_strcmp(dir, buf))
1010 cfdata->icon = strdup(ecore_file_file_get(file));
1017 IFDUP(file, cfdata->icon);
1023 p = strrchr(cfdata->icon, '.');
1026 /* TODO: Check if known extension */
1031 e_widget_entry_text_set(cfdata->icon_entry, cfdata->icon);
1033 _e_desktop_edit_cb_icon_select_cancel(data, dia);
1037 _e_desktop_edit_cb_icon_select_cancel(void *data, E_Dialog *dia)
1039 E_Config_Dialog_Data *cfdata;
1042 if (dia) e_util_defer_object_del(E_OBJECT(dia));
1043 cfdata->editor->icon_fsel_dia = NULL;
1044 _e_desktop_editor_icon_update(cfdata);
1048 _e_desktop_editor_icon_update(E_Config_Dialog_Data *cfdata)
1052 if (!cfdata->editor->img_widget) return;
1053 o = e_util_icon_theme_icon_add(cfdata->icon, 128, cfdata->editor->evas);
1055 /* NB this takes care of freeing any previous icon object */
1056 e_widget_button_icon_set(cfdata->editor->img_widget, o);
1057 e_widget_change(cfdata->editor->img_widget);
1061 _e_desktop_edit_cb_exec_select_destroy(void *obj)
1063 E_Dialog *dia = obj;
1064 E_Config_Dialog_Data *cfdata = dia->data;
1066 /* guess it should work like _e_desktop_edit_cb_icon_select_destroy */
1067 /* e_object_unref(E_OBJECT(dia)); */
1068 _e_desktop_edit_cb_exec_select_cancel(cfdata, NULL);
1072 _e_desktop_edit_cb_exec_select_ok(void *data, E_Dialog *dia)
1074 E_Config_Dialog_Data *cfdata;
1078 file = e_widget_fsel_selection_path_get(cfdata->editor->exec_fsel);
1080 E_FREE(cfdata->exec);
1081 cfdata->exec = eina_str_escape(file);
1082 E_FREE(cfdata->try_exec);
1083 IFDUP(cfdata->exec, cfdata->try_exec);
1085 _e_desktop_edit_cb_exec_select_cancel(data, dia);
1089 _e_desktop_edit_cb_exec_select_cancel(void *data, E_Dialog *dia)
1091 E_Config_Dialog_Data *cfdata;
1094 if (dia) e_util_defer_object_del(E_OBJECT(dia));
1095 cfdata->editor->exec_fsel_dia = NULL;
1096 _e_desktop_editor_exec_update(cfdata);
1100 _e_desktop_editor_exec_update(E_Config_Dialog_Data *cfdata)
1102 if (!cfdata->editor->entry_widget_exec) return;
1103 e_widget_entry_text_set(cfdata->editor->entry_widget_exec, cfdata->exec);