diff --git a/src/bin/e_eap_editor.c b/src/bin/e_eap_editor.c index 77a095193..8d3254f93 100644 --- a/src/bin/e_eap_editor.c +++ b/src/bin/e_eap_editor.c @@ -22,14 +22,12 @@ struct _E_Config_Dialog_Data int terminal; int show_in_menus; - int new_desktop; - int saved; /* whether desktop has been saved or not */ - E_Desktop_Edit *editor; }; /* local subsystem functions */ +static int _e_desktop_edit_view_create(E_Desktop_Edit *editor, E_Container *con); static void _e_desktop_edit_free(E_Desktop_Edit *editor); static void *_e_desktop_edit_create_data(E_Config_Dialog *cfd); static void _e_desktop_edit_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *data); @@ -51,26 +49,128 @@ static void _e_desktop_editor_icon_update(E_Config_Dialog_Data *cfdata /* externally accessible functions */ EAPI E_Desktop_Edit * -e_desktop_edit_show(E_Container *con, Efreet_Desktop *desktop) +e_desktop_border_edit(E_Container *con, E_Border *bd) +{ + E_Desktop_Edit *editor; + const char *bname, *bclass; + char path[PATH_MAX]; + + if (!con) return NULL; + editor = E_OBJECT_ALLOC(E_Desktop_Edit, E_DESKTOP_EDIT_TYPE, _e_desktop_edit_free); + if (!editor) return NULL; + if (bd->desktop) + editor->desktop = bd->desktop; + + bname = bd->client.icccm.name; + if ((bname) && (bname[0] == 0)) bname = NULL; + bclass = bd->client.icccm.class; + if ((bclass) && (bclass[0] == 0)) bclass = NULL; + + /* the border does not yet have a desktop entry. add one and pre-populate + it with values from the border */ + if (!editor->desktop) + { + const char *desktop_dir, *icon_dir; + + desktop_dir = e_user_desktop_dir_get(); + + if (!desktop_dir || !e_util_dir_check(desktop_dir)) return; + + icon_dir = e_user_icon_dir_get(); + if (!icon_dir || !e_util_dir_check(icon_dir)) return; + + if (bname) + { + snprintf(path, sizeof(path), "%s/%s.desktop", desktop_dir, bname); + editor->desktop = efreet_desktop_empty_new(path); + } + else + editor->desktop = efreet_desktop_empty_new(NULL); + + if (!editor->desktop) + { + //XXX out of memory? + return; + } + if (bclass) editor->desktop->name = strdup(bclass); + if (bclass) editor->desktop->startup_wm_class = strdup(bclass); + if (bd->client.icccm.command.argc > 0) + // FIXME this should concat the entire argv array together + editor->desktop->exec = strdup(bd->client.icccm.command.argv[0]); + else if (bname) + editor->desktop->exec = strdup(bname); + + if (bd->client.netwm.startup_id > 0) + editor->desktop->startup_notify = 1; + if (bd->client.netwm.icons) + { + /* FIXME + * - Find the icon with the best size + * - Should use mkstemp + */ + const char *tmp; + + snprintf(path, sizeof(path), "%s/%s-%.6f.png", icon_dir, bname, ecore_time_get()); + if (e_util_icon_save(&(bd->client.netwm.icons[0]), path)) + { + editor->tmp_image_path = strdup(path); + editor->desktop->icon = strdup(path); + } + else + fprintf(stderr, "Could not save file from ARGB: %s\n", path); + } + } + +#if 0 + if ((!bname) && (!bclass)) + { + e_util_dialog_show(_("Incomplete Window Properties"), + _("The window you are creating an icon for
" + "does not contain window name and class
" + "properties, so the needed properties for
" + "the icon so that it will be used for this
" + "window cannot be guessed. You will need to
" + "use the window title instead. This will only
" + "work if the window title is the same at
" + "the time the window starts up, and does not
" + "change.")); + } +#endif + if (!_e_desktop_edit_view_create(editor, con)) + { + e_object_del(E_OBJECT(editor)); + editor = NULL; + } + return editor; +} + +EAPI E_Desktop_Edit * +e_desktop_edit(E_Container *con, Efreet_Desktop *desktop) { - E_Config_Dialog_View *v; E_Desktop_Edit *editor; if (!con) return NULL; - editor = E_OBJECT_ALLOC(E_Desktop_Edit, E_DESKTOP_EDIT_TYPE, _e_desktop_edit_free); if (!editor) return NULL; - v = E_NEW(E_Config_Dialog_View, 1); - if (!v) - { - e_object_del(E_OBJECT(editor)); - return NULL; - } - - editor->img = NULL; if (desktop) editor->desktop = desktop; + if (!_e_desktop_edit_view_create(editor, con)) + { + e_object_del(E_OBJECT(editor)); + editor = NULL; + } + return editor; +} + +static int +_e_desktop_edit_view_create(E_Desktop_Edit *editor, E_Container *con) +{ + E_Config_Dialog_View *v; + v = E_NEW(E_Config_Dialog_View, 1); + if (!v) + return 0; + /* view methods */ v->create_cfdata = _e_desktop_edit_create_data; v->free_cfdata = _e_desktop_edit_free_data; @@ -84,7 +184,7 @@ e_desktop_edit_show(E_Container *con, Efreet_Desktop *desktop) "E", "_desktop_editor_dialog", "enlightenment/desktop_editor", 0, v, editor); - return editor; + return 1; } /* local subsystem functions */ @@ -95,6 +195,8 @@ _e_desktop_edit_free(E_Desktop_Edit *editor) E_OBJECT_CHECK(editor); E_OBJECT_TYPE_CHECK(editor, E_EAP_EDIT_TYPE); + IFFREE(editor->tmp_image_path); + E_FREE(editor); } @@ -108,8 +210,6 @@ _e_desktop_edit_create_data(E_Config_Dialog *cfd) Efreet_Desktop *desktop = NULL; char path[PATH_MAX]; - printf("create data\n"); - cfdata = E_NEW(E_Config_Dialog_Data, 1); if (!cfdata) return NULL; cfdata->editor = cfd->data; @@ -153,7 +253,7 @@ _e_desktop_edit_create_data(E_Config_Dialog *cfd) if (!cfdata->desktop) { cfdata->desktop = efreet_desktop_empty_new(path); - cfdata->new_desktop = 1; + cfdata->editor->new_desktop = 1; } if (!desktop) desktop = cfdata->desktop; @@ -184,8 +284,19 @@ _e_desktop_edit_create_data(E_Config_Dialog *cfd) static void _e_desktop_edit_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) { - if (cfdata->desktop && cfdata->new_desktop && !cfdata->saved) - efreet_desktop_free(cfdata->desktop); + if (cfdata->desktop && cfdata->editor->new_desktop && !cfdata->editor->saved) + efreet_desktop_free(cfdata->desktop); + + if (cfdata->editor->tmp_image_path) + { + if (!cfdata->desktop || !cfdata->editor->saved || + !cfdata->desktop->icon || + strcmp(cfdata->editor->tmp_image_path, cfdata->desktop->icon)) + { + ecore_file_unlink(cfdata->editor->tmp_image_path); + } + } + IFFREE(cfdata->name); IFFREE(cfdata->generic_name); @@ -236,7 +347,7 @@ _e_desktop_edit_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfd cfdata->desktop->no_display = !cfdata->show_in_menus; if (cfdata->desktop->orig_path && cfdata->desktop->orig_path[0]) - cfdata->saved = efreet_desktop_save(cfdata->desktop); + cfdata->editor->saved = efreet_desktop_save(cfdata->desktop); else { /* find a suitable name to save the desktop as */ @@ -272,7 +383,7 @@ _e_desktop_edit_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfd i++; } - cfdata->saved = efreet_desktop_save_as(cfdata->desktop, path); + cfdata->editor->saved = efreet_desktop_save_as(cfdata->desktop, path); } return 1; } @@ -477,7 +588,6 @@ _e_desktop_edit_cb_icon_select_ok(void *data, E_Dialog *dia) cfdata = data; file = e_widget_fsel_selection_path_get(cfdata->editor->fsel); - printf("selected file: %s\n", file); IFFREE(cfdata->icon); IFDUP(file, cfdata->icon); diff --git a/src/bin/e_eap_editor.h b/src/bin/e_eap_editor.h index 6c23c18e0..91ee13a14 100644 --- a/src/bin/e_eap_editor.h +++ b/src/bin/e_eap_editor.h @@ -23,12 +23,17 @@ struct _E_Desktop_Edit Evas_Object *img_widget; Evas_Object *fsel; E_Dialog *fsel_dia; - int img_set; + //int img_set; + + char *tmp_image_path; + int new_desktop; + int saved; /* whether desktop has been saved or not */ E_Config_Dialog *cfd; }; -EAPI E_Desktop_Edit *e_desktop_edit_show(E_Container *con, Efreet_Desktop *desktop); +EAPI E_Desktop_Edit *e_desktop_border_edit(E_Container *con, E_Border *bd); +EAPI E_Desktop_Edit *e_desktop_edit(E_Container *con, Efreet_Desktop *desktop); #endif #endif diff --git a/src/bin/e_int_border_menu.c b/src/bin/e_int_border_menu.c index ab0152014..2fd1e53b6 100644 --- a/src/bin/e_int_border_menu.c +++ b/src/bin/e_int_border_menu.c @@ -252,18 +252,18 @@ e_int_border_menu_show(E_Border *bd, Evas_Coord x, Evas_Coord y, int key, Ecore_ "e/widgets/border/default/skip_winlist"); } -#if 0 +#if 1 if (!bd->internal) { mi = e_menu_item_new(m); e_menu_item_separator_set(mi, 1); - if (bd->app) + if (bd->desktop) { mi = e_menu_item_new(m); e_menu_item_label_set(mi, _("Edit Icon")); e_menu_item_callback_set(mi, _e_border_menu_cb_icon_edit, bd); - e_app_icon_add_to_menu_item(bd->app, mi); + e_util_desktop_menu_item_icon_add(bd->desktop, "16x16", mi); } else if (bd->client.icccm.class) /* icons with no class useless to borders */ { @@ -531,94 +531,14 @@ _e_border_menu_cb_shade(void *data, E_Menu *m, E_Menu_Item *mi) } } -#if 0 static void _e_border_menu_cb_icon_edit(void *data, E_Menu *m, E_Menu_Item *mi) { - E_App *a; E_Border *bd; - char *bname = NULL, *bclass = NULL; - char path[4096]; bd = data; - a = bd->app; - - bname = bd->client.icccm.name; - if ((bname) && (bname[0] == 0)) bname = NULL; - bclass = bd->client.icccm.class; - if ((bclass) && (bclass[0] == 0)) bclass = NULL; - - if (!a) - { - if (bname) - { - const char *homedir; - - homedir = e_user_homedir_get(); - snprintf(path, sizeof(path), "%s/.e/e/applications/all/%s.desktop", - homedir, bname); - a = e_app_empty_new(path); - } - else - a = e_app_empty_new(NULL); - - if (a) - { - if (bname) a->win_name = evas_stringshare_add(bname); - if (bclass) a->win_class = evas_stringshare_add(bclass); - if (bd->client.icccm.window_role) - a->win_role = evas_stringshare_add(bd->client.icccm.window_role); - if (bclass) a->icon_class = evas_stringshare_add(bclass); - if (bclass) a->name = evas_stringshare_add(bclass); - if (bname) a->exe = evas_stringshare_add(bname); - if (bd->client.netwm.startup_id > 0) - a->startup_notify = 1; - if (bd->client.netwm.icons) - { - /* FIXME - * - Find the icon with the best size - * - Should use mkstemp - */ - const char *tmp; - - tmp = getenv("TMPDIR"); - if (!tmp) tmp = getenv("TMP"); - if (!tmp) tmp = "/tmp"; - snprintf(path, sizeof(path), "%s/%s-%.6f.png", tmp, bname, ecore_time_get()); - if (e_util_icon_save(&(bd->client.netwm.icons[0]), path)) - { - a->image = evas_stringshare_add(path); - a->width = bd->client.netwm.icons[0].width; - a->height = bd->client.netwm.icons[0].height; - a->tmpfile = 1; - } - else - fprintf(stderr, "Could not save file from ARGB: %s\n", path); - } - bd->app = a; - e_object_ref(E_OBJECT(bd->app)); - } - } - if (!a) return; - if (a->orig) - e_eap_edit_show(m->zone->container, a->orig); - else - e_eap_edit_show(m->zone->container, a); - if ((!bname) && (!bclass)) - { - e_util_dialog_show(_("Incomplete Window Properties"), - _("The window you are creating an icon for
" - "does not contain window name and class
" - "properties, so the needed properties for
" - "the icon so that it will be used for this
" - "window cannot be guessed. You will need to
" - "use the window title instead. This will only
" - "work if the window title is the same at
" - "the time the window starts up, and does not
" - "change.")); - } + e_desktop_border_edit(m->zone->container, bd); } -#endif static void _e_border_menu_cb_prop(void *data, E_Menu *m, E_Menu_Item *mi) diff --git a/src/bin/e_user.c b/src/bin/e_user.c index 32cfad3f4..12d9d751a 100644 --- a/src/bin/e_user.c +++ b/src/bin/e_user.c @@ -3,6 +3,8 @@ */ #include "e.h" +static int _e_user_dir_check(const char *dir); + /* externally accessible functions */ EAPI const char * e_user_homedir_get(void) @@ -20,3 +22,35 @@ e_user_homedir_get(void) } return homedir; } + +/** + * Return the directory where user .desktop files should be stored. + * If the directory does not exist, it will be created. If it cannot be + * created, a dialog will be displayed an NULL will be returned + */ +EAPI const char * +e_user_desktop_dir_get(void) +{ + static char dir[PATH_MAX] = ""; + if (!dir[0]) + snprintf(dir, sizeof(dir), "%s/applications", efreet_data_home_get()); + + return dir; +} + +/** + * Return the directory where user .icon files should be stored. + * If the directory does not exist, it will be created. If it cannot be + * created, a dialog will be displayed an NULL will be returned + */ +EAPI const char * +e_user_icon_dir_get(void) +{ + static char dir[PATH_MAX] = ""; + if (!dir[0]) + snprintf(dir, sizeof(dir), "%s/icons", efreet_data_home_get()); + + return dir; +} + + diff --git a/src/bin/e_user.h b/src/bin/e_user.h index d65eb2944..4d2ae217a 100644 --- a/src/bin/e_user.h +++ b/src/bin/e_user.h @@ -7,6 +7,8 @@ #define E_USER_H EAPI const char *e_user_homedir_get(void); +EAPI const char *e_user_desktop_dir_get(void); +EAPI const char *e_user_icon_dir_get(void); #endif #endif diff --git a/src/bin/e_utils.c b/src/bin/e_utils.c index f185e5ecf..ede288cae 100644 --- a/src/bin/e_utils.c +++ b/src/bin/e_utils.c @@ -884,6 +884,28 @@ e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, const char *size, E_M } } +int +e_util_dir_check(const char *dir) +{ + if (!ecore_file_exists(dir)) + { + if (!ecore_file_mkdir(dir)) + { + e_util_dialog_show("Error creating the directory: %s. Check that you have correct permissions set.", dir); + return 0; + } + } + else + { + if (!ecore_file_is_dir(dir)) + { + e_util_dialog_show("Error creating the directory: %s. A file of that name already exists.", dir); + return 0; + } + } + return 1; +} + /* local subsystem functions */ static void _e_util_container_fake_mouse_up_cb(void *data) @@ -906,3 +928,4 @@ _e_util_wakeup_cb(void *data) return 0; } + diff --git a/src/bin/e_utils.h b/src/bin/e_utils.h index 39a3149a3..101080c78 100644 --- a/src/bin/e_utils.h +++ b/src/bin/e_utils.h @@ -51,6 +51,7 @@ EAPI Evas_Object *e_util_icon_add(const char *path, Evas *evas); EAPI Evas_Object *e_util_desktop_icon_add(Efreet_Desktop *desktop, const char *size, Evas *evas); EAPI Evas_Object *e_util_icon_theme_icon_add(const char *icon_name, const char *size, Evas *evas); EAPI void e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, const char *size, E_Menu_Item *mi); +int e_util_dir_check(const char *dir); #endif #endif