From 6437ea875a2b394515f987b257c582ce66cc866a Mon Sep 17 00:00:00 2001 From: codewarrior Date: Sat, 14 Jan 2006 21:05:44 +0000 Subject: [PATCH] - patch from mista (Efm) - allow eap image w/h to be changable. SVN revision: 19808 --- src/bin/e_apps.c | 36 ++++-- src/bin/e_apps.h | 3 + src/bin/e_eap_editor.c | 8 ++ src/bin/e_fileman_file.c | 282 ++++++++++++++++++++++------------------------ src/bin/e_fileman_file.h | 7 +- src/bin/e_fileman_icon.c | 49 +++----- src/bin/e_fileman_smart.c | 6 +- 7 files changed, 197 insertions(+), 194 deletions(-) diff --git a/src/bin/e_apps.c b/src/bin/e_apps.c index dc99b1c..c3c09b9 100644 --- a/src/bin/e_apps.c +++ b/src/bin/e_apps.c @@ -72,6 +72,9 @@ static char *_e_apps_path_all = NULL; static char *_e_apps_path_trash = NULL; static Evas_List *_e_apps_start_pending = NULL; +#define EAP_MIN_WIDTH 8 +#define EAP_MIN_HEIGHT 8 + #define EAP_EDC_TMPL \ "images {\n" \ " image: \"%s\" COMP;\n" \ @@ -234,6 +237,8 @@ e_app_new(const char *path, int scan_subdirs) /* no image for now */ a->image = NULL; + a->width = 0; + a->height = 0; /* record the path */ a->path = evas_stringshare_add(path); @@ -289,6 +294,13 @@ e_app_empty_new(const char *path) return a; } +EAPI void +e_app_image_size_set(E_App *a, int w, int h) +{ + a->width = w; + a->height = h; +} + EAPI int e_app_is_parent(E_App *parent, E_App *app) { @@ -1022,10 +1034,6 @@ e_app_fields_fill(E_App *a, const char *path) eet_close(ef); } -/* - * We also need to fix startup-notify and wait-exit as they currently - * dont save too. - */ EAPI void e_app_fields_save(E_App *a) { @@ -1119,16 +1127,20 @@ e_app_fields_save(E_App *a) iw = 0; ih = 0; evas_object_image_size_get(im, &iw, &ih); alpha = evas_object_image_alpha_get(im); + if(a->width <= EAP_MIN_WIDTH) + a->width = EAP_MIN_WIDTH; + if(a->height <= EAP_MIN_HEIGHT) + a->height = EAP_MIN_HEIGHT; if ((iw > 0) && (ih > 0)) { /* we need to change the sizes */ - ecore_evas_resize(buf, 48, 48); - evas_object_image_fill_set(im, 0, 0, 48, 48); - evas_object_resize(im, 48, 48); + ecore_evas_resize(buf, a->width, a->height); + evas_object_image_fill_set(im, 0, 0, a->width, a->height); + evas_object_resize(im, a->height, a->width); evas_object_move(im, 0, 0); evas_object_show(im); data = ecore_evas_buffer_pixels_get(buf); - eet_data_image_write(ef, "images/0", (void *)data, 48, 48, alpha, 1, 0, 0); + eet_data_image_write(ef, "images/0", (void *)data, a->width, a->height, alpha, 1, 0, 0); } } @@ -1320,7 +1332,13 @@ _e_app_new_save(E_App *a) else ipart[0] = '\0'; if (a->image) - fprintf(out, EAP_EDC_TMPL, a->image, "48", "48", a->image); + { + if(a->width <= 0) + a->width = EAP_MIN_WIDTH; + if(a->height <= 0) + a->height = EAP_MIN_HEIGHT; + fprintf(out, EAP_EDC_TMPL, a->image, a->width, a->height, a->image); + } else fprintf(out, EAP_EDC_TMPL_EMPTY); fclose(out); diff --git a/src/bin/e_apps.h b/src/bin/e_apps.h index 3a38d03..afb562e 100644 --- a/src/bin/e_apps.h +++ b/src/bin/e_apps.h @@ -63,6 +63,8 @@ struct _E_App unsigned char deleted : 1; /* this app's file is deleted from disk */ char *image; /* used when we're saving a image into the eap */ + int width; /* used for saving eap's image width in edje */ + int height; /* used for saving eap's image height in edje */ }; struct _E_App_Instance @@ -79,6 +81,7 @@ EAPI int e_app_shutdown (void); EAPI E_App *e_app_new (const char *path, int scan_subdirs); EAPI E_App *e_app_empty_new (const char *path); +EAPI void e_app_image_size_set (E_App *a, int w, int h); EAPI int e_app_is_parent (E_App *parent, E_App *app); EAPI int e_app_equals (E_App *app1, E_App *app2); EAPI void e_app_subdir_scan (E_App *a, int scan_subdirs); diff --git a/src/bin/e_eap_editor.c b/src/bin/e_eap_editor.c index bf40a13..295c7c5 100644 --- a/src/bin/e_eap_editor.c +++ b/src/bin/e_eap_editor.c @@ -161,6 +161,10 @@ _e_eap_edit_basic_apply_data(E_Config_Dialog *cfd, void *data) eap->startup_notify = cfdata->startup_notify; eap->wait_exit = cfdata->wait_exit; + /* FIXME: hardcoded until the eap editor provides fields to change it */ + eap->width = 128; + eap->height = 128; + e_app_fields_save(eap); return 1; @@ -213,6 +217,10 @@ _e_eap_edit_advanced_apply_data(E_Config_Dialog *cfd, void *data) if (cfdata->wrole) eap->win_role = evas_stringshare_add(cfdata->wrole); if (cfdata->iclass) eap->icon_class = evas_stringshare_add(cfdata->iclass); if (cfdata->path) eap->path = evas_stringshare_add(cfdata->path); + + /* FIXME: hardcoded until the eap editor provides fields to change it */ + eap->width = 128; + eap->height = 128; e_app_fields_save(eap); return 1; diff --git a/src/bin/e_fileman_file.c b/src/bin/e_fileman_file.c index 2047ee3..c1c8ccb 100644 --- a/src/bin/e_fileman_file.c +++ b/src/bin/e_fileman_file.c @@ -74,13 +74,17 @@ e_fm_file_new(const char *filename) if(!file->mime) { - ext = strrchr(file->name, '.'); - if (ext) - { - file->mime = ext; - } - else - file->mime = "unknown"; + ext = strrchr(file->name, '.'); + if (ext) + { + char *ext2; + ext = strdup(ext); + ext2 = ext; + for (; *ext2; ext2++) *ext2 = tolower(*ext2); + file->mime = ext; + } + else + file->mime = "unknown"; } D(("e_fm_file_new: %s\n", filename)); return file; @@ -105,17 +109,17 @@ e_fm_file_rename(E_Fm_File *file, const char *name) if (ecore_file_mv(file->path, path)) { - free(file->path); - file->path = strdup(path); - free(file->name); - file->name = strdup(name); - D(("e_fm_file_rename: ok (%p) (%s)\n", file, name)); - return 1; + free(file->path); + file->path = strdup(path); + free(file->name); + file->name = strdup(name); + D(("e_fm_file_rename: ok (%p) (%s)\n", file, name)); + return 1; } else { - D(("e_fm_file_rename: fail (%p) (%s)\n", file, name)); - return 0; + D(("e_fm_file_rename: fail (%p) (%s)\n", file, name)); + return 0; } } @@ -124,17 +128,17 @@ e_fm_file_delete(E_Fm_File *file) { if (ecore_file_recursive_rm(file->path)) { - free(file->path); - file->path = NULL; - free(file->name); - file->name = NULL; - D(("e_fm_file_delete: ok (%p) (%s)\n", file, file->name)); - return 1; + free(file->path); + file->path = NULL; + free(file->name); + file->name = NULL; + D(("e_fm_file_delete: ok (%p) (%s)\n", file, file->name)); + return 1; } else { - D(("e_fm_file_delete: fail (%p) (%s)\n", file, file->name)); - return 0; + D(("e_fm_file_delete: fail (%p) (%s)\n", file, file->name)); + return 0; } } @@ -145,20 +149,36 @@ e_fm_file_copy(E_Fm_File *file, const char *name) if (ecore_file_cp(file->path, name)) { - free(file->path); - file->path = strdup(name); - free(file->name); - file->name = strdup(ecore_file_get_file(name)); - D(("e_fm_file_copy: ok (%p) (%s)\n", file, name)); - return 1; + free(file->path); + file->path = strdup(name); + free(file->name); + file->name = strdup(ecore_file_get_file(name)); + D(("e_fm_file_copy: ok (%p) (%s)\n", file, name)); + return 1; } else { - D(("e_fm_file_copy: fail (%p) (%s)\n", file, name)); - return 0; + D(("e_fm_file_copy: fail (%p) (%s)\n", file, name)); + return 0; } } +int +e_fm_file_is_regular(E_Fm_File *file) /* TODO: find better name */ +{ + return ((file->type == E_FM_FILE_TYPE_FILE) + || (file->type == E_FM_FILE_TYPE_SYMLINK)); +} + +EAPI int +e_fm_file_has_mime(E_Fm_File *file, char* mime) +{ + if (!file->mime) return 0; + + D(("e_fm_file_has_mime: (%p) : %s\n", file,file->mime)); + return (!strcasecmp(file->mime, mime)); +} + EAPI int e_fm_file_can_preview(E_Fm_File *file) { @@ -167,11 +187,11 @@ e_fm_file_can_preview(E_Fm_File *file) D(("e_fm_file_can_preview: (%s) (%p)\n", file->name, file)); for (i = 0; file->preview_funcs[i]; i++) { - E_Fm_File_Preview_Function func; + E_Fm_File_Preview_Function func; - func = file->preview_funcs[i]; - if (func(file)) - return 1; + func = file->preview_funcs[i]; + if (func(file)) + return 1; } return 0; } @@ -183,31 +203,22 @@ e_fm_file_is_image(E_Fm_File *file) * If it isn't supported by evas, we can't show it in the * canvas. */ - char *ext; - - if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; - - ext = strrchr(file->name, '.'); - if (!ext) return 0; - - D(("e_fm_file_is_image: (%p)\n", file)); - return (!strcasecmp(ext, ".jpg")) || (!strcasecmp(ext, ".png")) || - (!strcasecmp(ext, ".jpeg")); + + //D(("e_fm_file_is_image: (%p)\n", file)); + + return e_fm_file_is_regular(file) + &&(e_fm_file_has_mime(file,".jpg") + || e_fm_file_has_mime(file,".jpeg") + || e_fm_file_has_mime(file,".png")); } EAPI int e_fm_file_is_etheme(E_Fm_File *file) { int val; - char *ext; Evas_List *groups, *l; - if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; - - ext = strrchr(file->name, '.'); - if (!ext) return 0; - - if (strcasecmp(ext, ".edj")) + if (!e_fm_file_is_regular(file) || !e_fm_file_has_mime(file,".edj")) return 0; val = 0; @@ -216,13 +227,13 @@ e_fm_file_is_etheme(E_Fm_File *file) return 0; for (l = groups; l; l = l->next) - { - if (!strcmp(l->data, "widgets/border/default/border")) - { - val = 1; - break; - } - } + { + if (!strcmp(l->data, "widgets/border/default/border")) + { + val = 1; + break; + } + } edje_file_collection_list_free(groups); return val; } @@ -231,30 +242,24 @@ EAPI int e_fm_file_is_ebg(E_Fm_File *file) { int val; - char *ext; Evas_List *groups, *l; - if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; - - ext = strrchr(file->name, '.'); - if (!ext) return 0; - - if (strcasecmp(ext, ".edj")) + if (!e_fm_file_is_regular(file) || !e_fm_file_has_mime(file,".edj")) return 0; - + val = 0; groups = edje_file_collection_list(file->path); if (!groups) return 0; for (l = groups; l; l = l->next) - { - if (!strcmp(l->data, "desktop/background")) - { - val = 1; - break; - } - } + { + if (!strcmp(l->data, "desktop/background")) + { + val = 1; + break; + } + } edje_file_collection_list_free(groups); return val; } @@ -262,23 +267,18 @@ e_fm_file_is_ebg(E_Fm_File *file) EAPI int e_fm_file_is_eap(E_Fm_File *file) { - char *ext; - E_App *app; - - if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0; - ext = strrchr(file->name, '.'); - if (!ext) return 0; + E_App *app; - if (strcasecmp(ext, ".eap")) + if (!e_fm_file_is_regular(file) || !e_fm_file_has_mime(file,".eap")) return 0; - + app = e_app_new(file->path, 0); if (!app) - { - e_object_unref(E_OBJECT(app)); - return 0; - } + { + e_object_unref(E_OBJECT(app)); + return 0; + } e_object_unref(E_OBJECT(app)); return 1; } @@ -286,23 +286,17 @@ e_fm_file_is_eap(E_Fm_File *file) EAPI int e_fm_file_can_exec(E_Fm_File *file) { - char *ext; - - ext = strrchr(file->name, '.'); - if (ext) - { - if (!strcasecmp(ext, ".eap")) - { - D(("e_fm_file_can_exec: true (%p) (%s)\n", file, file->name)); - return 1; - } - } + if (e_fm_file_has_mime(file,".eap")) + { + D(("e_fm_file_can_exec: true (%p) (%s)\n", file, file->name)); + return 1; + } if (ecore_file_can_exec(file->path)) - { - D(("e_fm_file_can_exec: true (%p) (%s)\n", file, file->name)); - return 1; - } + { + D(("e_fm_file_can_exec: true (%p) (%s)\n", file, file->name)); + return 1; + } D(("e_fm_file_can_exec: false (%p) (%s)\n", file, file->name)); return 0; @@ -312,40 +306,35 @@ EAPI int e_fm_file_exec(E_Fm_File *file) { Ecore_Exe *exe; - char *ext; - ext = strrchr(file->name, '.'); - if (ext) - { - if (!strcasecmp(ext, ".eap")) - { - E_App *e_app; - Ecore_Exe *exe; + if(e_fm_file_has_mime(file,".eap")) + { + E_App *e_app; + Ecore_Exe *exe; - e_app = e_app_new(file->path, 0); + e_app = e_app_new(file->path, 0); - if (!e_app) return 0; + if (!e_app) return 0; - exe = ecore_exe_run(e_app->exe, NULL); - if (exe) ecore_exe_free(exe); - e_object_unref(E_OBJECT(e_app)); - D(("e_fm_file_exec: eap (%p) (%s)\n", file, file->name)); - return 1; - } - } + exe = ecore_exe_run(e_app->exe, NULL); + if (exe) ecore_exe_free(exe); + e_object_unref(E_OBJECT(e_app)); + D(("e_fm_file_exec: eap (%p) (%s)\n", file, file->name)); + return 1; + } exe = ecore_exe_run(file->path, NULL); if (!exe) - { - e_error_dialog_show(_("Run Error"), - _("Enlightenment was unable to fork a child process:\n" - "\n" - "%s\n" - "\n"), - file->path); - D(("e_fm_file_exec: fail (%p) (%s)\n", file, file->name)); - return 0; - } + { + e_error_dialog_show(_("Run Error"), + _("Enlightenment was unable to fork a child process:\n" + "\n" + "%s\n" + "\n"), + file->path); + D(("e_fm_file_exec: fail (%p) (%s)\n", file, file->name)); + return 0; + } /* E/app is the correct tag if the data is en E_App! ecore_exe_tag_set(exe, "E/app"); */ @@ -371,15 +360,12 @@ e_fm_file_assoc_exec(E_Fm_File *file) if (!assoc_apps) return 0; for (l = assoc_apps; l; l = l->next) - { - char *ext; - - assoc = l->data; - ext = strrchr(file->path, '.'); - if ((ext) && (!strcasecmp(ext, assoc->mime))) - break; - assoc = NULL; - } + { + assoc = l->data; + if (e_fm_file_has_mime(file,assoc->mime)) + break; + assoc = NULL; + } if (!assoc) return 0; @@ -387,16 +373,16 @@ e_fm_file_assoc_exec(E_Fm_File *file) exe = ecore_exe_run(app, NULL); if (!exe) - { - e_error_dialog_show(_("Run Error"), - _("Enlightenment was unable to fork a child process:\n" - "\n" - "%s\n" - "\n"), - app); - D(("e_fm_assoc_exec: fail (%s)\n", app)); - return 0; - } + { + e_error_dialog_show(_("Run Error"), + _("Enlightenment was unable to fork a child process:\n" + "\n" + "%s\n" + "\n"), + app); + D(("e_fm_assoc_exec: fail (%s)\n", app)); + return 0; + } /* * ecore_exe_tag_set(exe, "E/app"); */ @@ -435,7 +421,7 @@ _e_fm_file_free(E_Fm_File *file) free(file->preview_funcs); if (file->path) free(file->path); if (file->name) free(file->name); - ///??? if (file->mime) free(file->mime); + ///??? if (file->mime) free(file->mime); free(file); } diff --git a/src/bin/e_fileman_file.h b/src/bin/e_fileman_file.h index c30ec93..fd6f0c7 100644 --- a/src/bin/e_fileman_file.h +++ b/src/bin/e_fileman_file.h @@ -37,7 +37,7 @@ struct _E_Fm_File char *path; /* full name with path */ char *name; /* file name without parent directories */ - char *mime; /* mimetype (just the extension) */ + char *mime; /* mimetype (just the extension, beginning with dot) */ dev_t device; /* ID of device containing file */ ino_t inode; /* inode number */ @@ -67,8 +67,9 @@ EAPI int e_fm_file_can_exec (E_Fm_File *file); EAPI int e_fm_file_exec (E_Fm_File *file); EAPI int e_fm_file_assoc_set (E_Fm_File *file, const char *assoc); EAPI int e_fm_file_assoc_exec (E_Fm_File *file); -EAPI int e_fm_file_exec_with (E_Fm_File *file, char* exec_with); - +EAPI int e_fm_file_exec_with (E_Fm_File *file, char* exec_with); +EAPI int e_fm_file_has_mime (E_Fm_File *file, char* mime); +EAPI int e_fm_file_is_regular (E_Fm_File *file); #endif #endif diff --git a/src/bin/e_fileman_icon.c b/src/bin/e_fileman_icon.c index 698eac3..1ccdb21 100644 --- a/src/bin/e_fileman_icon.c +++ b/src/bin/e_fileman_icon.c @@ -496,32 +496,22 @@ _e_fm_icon_smart_clip_unset(Evas_Object *obj) static void _e_fm_icon_icon_mime_get(E_Smart_Data *sd) { - sd->image_object = edje_object_add(sd->evas); - if (sd->file->type == E_FM_FILE_TYPE_DIRECTORY) - e_theme_edje_object_set(sd->image_object, "base/theme/fileman", - "icons/fileman/folder"); - else - { - char *ext; - - ext = strrchr(sd->file->name, '.'); - if (ext) - { - char part[PATH_MAX]; - char *ext2; - - ext = strdup(ext); - ext2 = ext; - for (; *ext2; ext2++) *ext2 = tolower(*ext2); - - snprintf(part, PATH_MAX, "icons/fileman/%s", (ext + 1)); - if (!e_theme_edje_object_set(sd->image_object, "base/theme/fileman", part)) + char part[PATH_MAX]; + + sd->image_object = edje_object_add(sd->evas); + + // since a mime is set with every creation of an E_Fm_File its existence isnĀ“t checked here + if(sd->file->type == E_FM_FILE_TYPE_DIRECTORY) + e_theme_edje_object_set(sd->image_object, "base/theme/fileman", "icons/fileman/folder"); + + else if(e_fm_file_has_mime(sd->file,"unknown")) + e_theme_edje_object_set(sd->image_object, "base/theme/fileman", "icons/fileman/file"); + else + { + snprintf(part, PATH_MAX, "icons/fileman/%s", (sd->file->mime + 1)); + if (!e_theme_edje_object_set(sd->image_object, "base/theme/fileman", part)) e_theme_edje_object_set(sd->image_object, "base/theme/fileman", "icons/fileman/file"); - free(ext); - } - else - e_theme_edje_object_set(sd->image_object, "base/theme/fileman", "icons/fileman/file"); - } + } evas_object_show(sd->image_object); edje_extern_object_min_size_set(sd->image_object, sd->iw, sd->ih); edje_extern_object_max_size_set(sd->image_object, sd->iw, sd->ih); @@ -529,19 +519,16 @@ _e_fm_icon_icon_mime_get(E_Smart_Data *sd) sd->image_object); } + + void _e_fm_icon_thumb_generate_cb(Evas_Object *obj, void *data) { E_Smart_Data *sd; - char *ext; sd = data; - ext = strrchr(sd->file->name, '.'); - if ((ext) && (strcasecmp(ext, ".eap"))) - ext = NULL; - - if ((ext) || (ecore_file_exists(sd->thumb_path))) + if (e_fm_file_has_mime(sd->file,".eap") || (ecore_file_exists(sd->thumb_path))) { Evas_Coord icon_w, icon_h; diff --git a/src/bin/e_fileman_smart.c b/src/bin/e_fileman_smart.c index 80d9c45..57f1c8d 100644 --- a/src/bin/e_fileman_smart.c +++ b/src/bin/e_fileman_smart.c @@ -1211,7 +1211,7 @@ _e_fm_icon_prop_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, void *dat e_widget_frametable_object_append(o, e_widget_label_add(evas, text), 0, 2, 1, 1, 1, 1, 1, 1); - snprintf(text, 512, "%s", "An Image"); + snprintf(text, 512, "%s", icon->file->mime); e_widget_frametable_object_append(o, e_widget_label_add(evas, text), 1, 2, 1, 1, 1, 1, 1, 1); @@ -2120,7 +2120,7 @@ _e_fm_icon_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info if(icon->sd->win) icon->sd->drag.start = 0; - if (!strcmp(icon->file->name, ".")) return; + if (!strcmp(icon->file->name, ".")) return; /* this case cant happen!? */ if (!strcmp(icon->file->name, "..")) { @@ -2215,7 +2215,7 @@ _e_fm_icon_mouse_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info for (l = icon->sd->conf.main->apps; l; l = l->next) { assoc = l->data; - if (strcmp(icon->file->mime, assoc->mime) == 0) + if (e_fm_file_has_mime(icon->file, assoc->mime)) { mi = e_menu_item_new(mo); -- 2.7.4