Move assoc to e_fileman_file

SVN revision: 17823
This commit is contained in:
sebastid 2005-10-23 15:18:47 +00:00 committed by sebastid
parent 12e9497d94
commit 38679d522c
7 changed files with 647 additions and 692 deletions

View File

@ -9,10 +9,40 @@
# define D(x) ((void) 0)
#endif
typedef struct _E_Fm_Assoc_App E_Fm_Assoc_App;
struct _E_Fm_Assoc_App
{
char *mime;
char *app;
};
/* local subsystem functions */
static void _e_fm_file_free(E_Fm_File *file);
/* TODO Make init and shutdown func that populates the assoc */
static E_Config_DD *assoc_app_edd;
static Evas_List *assoc_apps;
#if 0
{
E_Fm_Assoc_App *assoc;
assoc = E_NEW(E_Fm_Assoc_App, 1);
assoc->mime = (char*)E_NEW(char *, 5);
snprintf(assoc->mime, 5, "%s", ".jpg");
assoc->app = (char*)E_NEW(char *, 7);
snprintf(assoc->app, 7, "gqview");
sd->conf.main->apps = evas_list_append(sd->conf.main->apps, assoc);
assoc = E_NEW(E_Fm_Assoc_App, 1);
assoc->mime = (char*)E_NEW(char *, 5);
snprintf(assoc->mime, 5, "%s", ".png");
assoc->app = (char*)E_NEW(char *, 7);
snprintf(assoc->app, 7, "gqview");
sd->conf.main->apps = evas_list_append(sd->conf.main->apps, assoc);
}
#endif
/* externally accessible functions */
E_Fm_File *
e_fm_file_new(const char *filename)
@ -58,7 +88,7 @@ e_fm_file_new(const char *filename)
file->preview_funcs[1] = e_fm_file_is_etheme;
file->preview_funcs[2] = e_fm_file_is_ebg;
file->preview_funcs[3] = e_fm_file_is_eap;
D(("e_fm_file_new: %s\n", filename));
return file;
@ -119,7 +149,7 @@ int
e_fm_file_copy(E_Fm_File *file, const char *name)
{
if ((!name) || (!name[0])) return 0;
if (ecore_file_cp(file->path, name))
{
free(file->path);
@ -140,15 +170,15 @@ int
e_fm_file_can_preview(E_Fm_File *file)
{
int i;
D(("e_fm_file_can_preview: (%s) (%p)\n", file->name, file));
for (i = 0; i < sizeof(file->preview_funcs); i++)
{
E_Fm_File_Preview_Function func;
func = file->preview_funcs[i];
if(func(file))
return 1;
}
{
E_Fm_File_Preview_Function func;
func = file->preview_funcs[i];
if (func(file))
return 1;
}
return 0;
}
@ -160,15 +190,15 @@ e_fm_file_is_image(E_Fm_File *file)
* canvas.
*/
char *ext;
if ((file->type != E_FM_FILE_TYPE_FILE) && (file->type != E_FM_FILE_TYPE_SYMLINK)) return 0;
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"));
return (!strcasecmp(ext, ".jpg")) || (!strcasecmp(ext, ".png")) ||
(!strcasecmp(ext, ".jpeg"));
}
int
@ -177,26 +207,28 @@ 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;
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 (strcasecmp(ext, ".edj"))
return 0;
val = 0;
groups = edje_file_collection_list(file->path);
if(!groups)
if (!groups)
return 0;
for (l = groups; l; l = l->next)
if(!strcmp(l->data, "widgets/border/default/border"))
{
val = 1;
break;
}
for (l = groups; l; l = l->next)
{
if (!strcmp(l->data, "widgets/border/default/border"))
{
val = 1;
break;
}
}
edje_file_collection_list_free(groups);
return val;
}
@ -207,28 +239,30 @@ 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;
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 (strcasecmp(ext, ".edj"))
return 0;
val = 0;
groups = edje_file_collection_list(file->path);
if(!groups)
if (!groups)
return 0;
for (l = groups; l; l = l->next)
if(!strcmp(l->data, "desktop/background"))
{
val = 1;
break;
}
for (l = groups; l; l = l->next)
{
if (!strcmp(l->data, "desktop/background"))
{
val = 1;
break;
}
}
edje_file_collection_list_free(groups);
return val;
return val;
}
int
@ -236,47 +270,46 @@ 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;
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, ".eap"))
if (strcasecmp(ext, ".eap"))
return 0;
app = e_app_new(file->path, 0);
if(!app)
{
e_object_unref(E_OBJECT(app));
return 0;
}
if (!app)
{
e_object_unref(E_OBJECT(app));
return 0;
}
e_object_unref(E_OBJECT(app));
return 1;
return 1;
}
int
e_fm_file_can_exec(E_Fm_File *file)
{
char *ext;
char *fullname;
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(ecore_file_can_exec(file->path))
{
D(("e_fm_file_can_exec: true (%p) (%s)\n", file, file->name));
return 1;
}
if (ext)
{
if (!strcasecmp(ext, ".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: false (%p) (%s)\n", file, file->name));
return 0;
}
@ -286,28 +319,27 @@ 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;
e_app = e_app_new(file->path, NULL);
if(!e_app) return;
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;
}
}
if (ext)
{
if (!strcasecmp(ext, ".eap"))
{
E_App *e_app;
Ecore_Exe *exe;
e_app = e_app_new(file->path, 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(file->path, NULL);
if (!exe)
{
@ -327,11 +359,60 @@ e_fm_file_exec(E_Fm_File *file)
return 1;
}
int
e_fm_file_assoc_set(E_Fm_File *file, const char *assoc)
{
/* TODO */
return 1;
}
int
e_fm_file_assoc_exec(E_Fm_File *file)
{
char app[PATH_MAX * 2];
Evas_List *l;
E_Fm_Assoc_App *assoc;
Ecore_Exe *exe;
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;
}
if (!assoc) return 0;
snprintf(app, PATH_MAX * 2, "%s %s", assoc->app, file->path);
exe = ecore_exe_run(app, NULL);
if (!exe)
{
e_error_dialog_show(_("Run Error"),
_("Enlightenment was unable 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");
*/
D(("e_fm_assoc_exec: ok (%s)\n", app));
return 1;
}
/* local subsystem functions */
static void
_e_fm_file_free(E_Fm_File *file)
{
D(("_e_fm_file_free: (%p) (%s)\n", file, file->name));
D(("_e_fm_file_free: (%p) (%s)\n", file, file->name));
free(file->preview_funcs);
if (file->path) free(file->path);
if (file->name) free(file->name);

View File

@ -62,6 +62,7 @@ EAPI int e_fm_file_is_image (E_Fm_File *file);
EAPI int e_fm_file_is_etheme (E_Fm_File *file);
EAPI int e_fm_file_is_ebg (E_Fm_File *file);
EAPI int e_fm_file_is_eap (E_Fm_File *file);
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);

View File

@ -57,9 +57,6 @@ static Evas_List *event_handlers = NULL;
int
e_fm_icon_init(void)
{
char *homedir;
char path[PATH_MAX];
event_handlers = evas_list_append(event_handlers,
ecore_event_handler_add(ECORE_EVENT_EXE_EXIT,
_e_fm_icon_thumb_cb_exe_exit,
@ -439,17 +436,17 @@ _e_fm_icon_icon_mime_get(E_Smart_Data *sd)
{
char part[PATH_MAX];
char *ext2;
ext = strdup(ext);
ext2 = ext;
for(;*ext2;ext2++)
*ext2 = (unsigned char)tolower((unsigned char)*ext2);
for (; *ext2; ext2++)
*ext2 = tolower(*ext2);
snprintf(part, PATH_MAX, "fileman/icons/%s", (ext + 1));
if(!e_theme_edje_object_set(sd->image_object, "base/theme/fileman", part))
if (!e_theme_edje_object_set(sd->image_object, "base/theme/fileman", part))
e_theme_edje_object_set(sd->image_object, "base/theme/fileman", "fileman/icons/file");
free(ext);
}
else
@ -494,12 +491,11 @@ _e_fm_icon_thumb_cb_exe_exit(void *data, int type, void *event)
sd = thumb_files->data;
thumb_files = evas_list_remove_list(thumb_files, thumb_files);
ext = strrchr(sd->file->name, ".");
if(ext)
if(strcasecmp(ext, ".eap"))
ext = NULL;
ext = strrchr(sd->file->name, '.');
if ((ext) && (strcasecmp(ext, ".eap")))
ext = NULL;
if (ecore_file_exists(sd->thumb_path) || ext)
if ((ext) || (ecore_file_exists(sd->thumb_path)))
{
if (sd->image_object) evas_object_del(sd->image_object);
sd->image_object = e_thumb_evas_object_get(sd->file->path,

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,6 @@
typedef struct _E_Event_Fm_Reconfigure E_Event_Fm_Reconfigure;
typedef struct _E_Event_Fm_Directory_Change E_Event_Fm_Directory_Change;
typedef struct _E_Fm_Assoc_App E_Fm_Assoc_App;
#else
#ifndef E_FM_SMART_H
@ -23,12 +22,6 @@ struct _E_Event_Fm_Directory_Change
Evas_Coord w, h;
};
struct _E_Fm_Assoc_App
{
char *mime;
char *app;
};
EAPI int e_fm_init(void);
EAPI int e_fm_shutdown(void);
EAPI Evas_Object *e_fm_add(Evas *evas);

View File

@ -22,13 +22,13 @@ e_thumb_init(void)
homedir = e_user_homedir_get();
if (homedir)
{
snprintf(path, sizeof(path), "%s/.e/e/fileman/thumbnails", homedir);
if (!ecore_file_exists(path))
ecore_file_mkpath(path);
thumb_path = strdup(path);
free(homedir);
}
{
snprintf(path, sizeof(path), "%s/.e/e/fileman/thumbnails", homedir);
if (!ecore_file_exists(path))
ecore_file_mkpath(path);
thumb_path = strdup(path);
free(homedir);
}
else return 0;
return 1;
@ -42,10 +42,10 @@ e_thumb_shutdown(void)
}
/* return dir where thumbs are saved */
char *
const char *
e_thumb_dir_get(void)
{
return strdup(thumb_path);
return thumb_path;
}
/* return hashed path of thumb */
@ -56,7 +56,7 @@ e_thumb_file_get(char *file)
char thumb[PATH_MAX];
id = _e_thumb_file_id(file);
if(!id) { return NULL; }
if (!id) return NULL;
snprintf(thumb, sizeof(thumb), "%s/%s", thumb_path, id);
free(id);
return strdup(thumb);
@ -68,19 +68,17 @@ e_thumb_exists(char *file)
{
char *thumb;
char *ext;
ext = strrchr(file, '.');
if(ext)
if(!strcasecmp(ext, ".eap"))
return 1;
if ((ext) && (!strcasecmp(ext, ".eap")))
return 1;
thumb = e_thumb_file_get(file);
if(ecore_file_exists(thumb))
{
free(thumb);
return 1;
}
if (ecore_file_exists(thumb))
{
free(thumb);
return 1;
}
return 0;
}
@ -98,22 +96,22 @@ _e_thumb_image_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh,
evas_object_image_size_get(*im, &iw, &ih);
*alpha = evas_object_image_alpha_get(*im);
if ((iw > 0) && (ih > 0))
{
*ww = w;
*hh = (w * ih) / iw;
if (*hh > h)
{
*hh = h;
*ww = (h * iw) / ih;
}
ecore_evas_resize(*buf, *ww, *hh);
evas_object_image_fill_set(*im, 0, 0, *ww, *hh);
evas_object_resize(*im, *ww, *hh);
evas_object_move(*im, 0, 0);
evas_object_show(*im);
return ecore_evas_buffer_pixels_get(*buf);
}
{
*ww = w;
*hh = (w * ih) / iw;
if (*hh > h)
{
*hh = h;
*ww = (h * iw) / ih;
}
ecore_evas_resize(*buf, *ww, *hh);
evas_object_image_fill_set(*im, 0, 0, *ww, *hh);
evas_object_resize(*im, *ww, *hh);
evas_object_move(*im, 0, 0);
evas_object_show(*im);
return ecore_evas_buffer_pixels_get(*buf);
}
return NULL;
}
@ -137,7 +135,6 @@ _e_thumb_ebg_create(char *file, Evas_Coord w, Evas_Coord h, int *ww, int *hh, in
wallpaper = edje_object_add(evasbuf);
edje_object_file_set(wallpaper, file, "desktop/background");
/* wallpaper */
@ -242,29 +239,23 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord h)
int alpha;
ext = strrchr(file, '.');
if(ext)
{
if(!strcasecmp(ext, ".eap"))
return 1;
}
if ((ext) && (!strcasecmp(ext, ".eap")))
return 1;
thumbpath = e_thumb_file_get(file);
if (!thumbpath)
{
free(thumbpath);
return -1;
}
return -1;
if(ext)
{
if(!strcasecmp(ext, ".edj"))
{
/* for now, this function does both the bg and theme previews */
data = _e_thumb_etheme_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
}
else
data = _e_thumb_image_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
}
if (ext)
{
if(!strcasecmp(ext, ".edj"))
{
/* for now, this function does both the bg and theme previews */
data = _e_thumb_etheme_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
}
else
data = _e_thumb_image_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
}
else
data = _e_thumb_image_create(file, w, h, &ww, &hh, &alpha, &im, &buf);
@ -279,7 +270,7 @@ e_thumb_create(char *file, Evas_Coord w, Evas_Coord h)
return -1;
}
free(thumbpath);
eet_write(ef, "/thumbnail/orig_path", file, strlen(file), 1);
if ((size = eet_data_image_write(ef, "/thumbnail/data",
(void *)data, ww, hh, alpha,
@ -314,31 +305,31 @@ e_thumb_evas_object_get(char *file, Evas *evas, Evas_Coord width, Evas_Coord hei
/* eap thumbnailer */
ext = strrchr(file, '.');
if(ext)
{
if(!strcasecmp(ext, ".eap"))
{
E_App *app;
if (ext)
{
if (!strcasecmp(ext, ".eap"))
{
E_App *app;
D(("e_thumb_evas_object_get: eap found\n"));
app = e_app_new(file, 0);
D(("e_thumb_evas_object_get: eap loaded\n"));
if(!app)
{
D(("e_thumb_evas_object_get: invalid eap\n"));
DEF_THUMB_RETURN;
}
else
{
D(("e_thumb_evas_object_get: creating eap thumb\n"));
im = edje_object_add(evas);
edje_object_file_set(im, file, "icon");
e_object_unref(E_OBJECT(app));
D(("e_thumb_evas_object_get: returning eap thumb\n"));
return im;
}
}
}
D(("e_thumb_evas_object_get: eap found\n"));
app = e_app_new(file, 0);
D(("e_thumb_evas_object_get: eap loaded\n"));
if (!app)
{
D(("e_thumb_evas_object_get: invalid eap\n"));
DEF_THUMB_RETURN;
}
else
{
D(("e_thumb_evas_object_get: creating eap thumb\n"));
im = edje_object_add(evas);
edje_object_file_set(im, file, "icon");
e_object_unref(E_OBJECT(app));
D(("e_thumb_evas_object_get: returning eap thumb\n"));
return im;
}
}
}
/* saved thumb */
/* TODO: add ability to fetch thumbs from freedesktop dirs */
@ -398,7 +389,7 @@ _e_thumb_file_id(char *file)
{
unsigned int t, tt;
int j;
t = id[i];
j = 32;
while (j > 0)

View File

@ -10,7 +10,7 @@
EAPI int e_thumb_init(void);
EAPI int e_thumb_shutdown(void);
EAPI char *e_thumb_dir_get(void);
EAPI const char *e_thumb_dir_get(void);
EAPI char *e_thumb_file_get(char *file);
EAPI int e_thumb_exists(char *file);
EAPI int e_thumb_create(char *file, Evas_Coord w, Evas_Coord h);