nick's patches to use efreet_mime. seem to work fine.

SVN revision: 30856
This commit is contained in:
Carsten Haitzler 2007-07-16 14:33:25 +00:00
parent 99c32d45d0
commit 22d4a7d9b9
4 changed files with 6 additions and 266 deletions

View File

@ -174,6 +174,7 @@ PKG_CHECK_MODULES(E, [
eet
embryo
efreet
efreet-mime
])
# ecore-txt is really only needed by the temperature module,

View File

@ -74,6 +74,7 @@
#include <Eet.h>
#include <Edje.h>
#include <Efreet.h>
#include <Efreet_Mime.h>
#if HAVE___ATTRIBUTE__
#define __UNUSED__ __attribute__((unused))

View File

@ -383,6 +383,7 @@ e_fm2_init(void)
NULL); /* data*/
// _e_fm2_client_spawn();
e_fm2_custom_file_init();
efreet_mime_init();
return 1;
}
@ -394,6 +395,7 @@ e_fm2_shutdown(void)
E_FREE(_e_fm2_meta_path);
e_fm2_custom_file_shutdown();
_e_storage_volume_edd_shutdown();
efreet_mime_shutdown();
return 1;
}
@ -3600,7 +3602,7 @@ _e_fm2_icon_fill(E_Fm2_Icon *ic, E_Fm2_Finfo *finf)
if (S_ISDIR(ic->info.statinfo.st_mode))
{
ic->info.mime = evas_stringshare_add("x-directory/normal");
ic->info.mime = evas_stringshare_add("inode/directory");
}
if (!ic->info.mime)
{

View File

@ -3,21 +3,8 @@
*/
#include "e.h"
typedef struct _E_Mime E_Mime;
struct _E_Mime
{
const char *glob;
const char *mime;
};
/* local subsystem functions */
static Evas_Bool _e_fm_mime_icon_foreach(Evas_Hash *hash, const char *key, void *data, void *fdata);
static void _e_fm_mime_all_free(void);
static void _e_fm_mime_update(void);
static int _e_fm_mime_glob_remove(const char *glob);
static void _e_fm_mime_mime_types_load(char *file);
static void _e_fm_mime_shared_mimeinfo_globs_load(char *file);
static Evas_List *mimes = NULL;
static Evas_Hash *icon_map = NULL;
@ -26,33 +13,7 @@ static Evas_Hash *icon_map = NULL;
EAPI const char *
e_fm_mime_filename_get(const char *fname)
{
Evas_List *l;
E_Mime *mime;
_e_fm_mime_update();
/* case senstive match first */
for (l = mimes; l; l = l->next)
{
mime = l->data;
if (e_util_glob_match(fname, mime->glob))
{
mimes = evas_list_remove_list(mimes, l);
mimes = evas_list_prepend(mimes, mime);
return mime->mime;
}
}
/* case insenstive match second */
for (l = mimes; l; l = l->next)
{
mime = l->data;
if (e_util_glob_case_match(fname, mime->glob))
{
mimes = evas_list_remove_list(mimes, l);
mimes = evas_list_prepend(mimes, mime);
return mime->mime;
}
}
return NULL;
return efreet_mime_globs_type_get(fname);
}
/* returns:
@ -166,228 +127,3 @@ _e_fm_mime_icon_foreach(Evas_Hash *hash, const char *key, void *data, void *fdat
*freelist = evas_list_append(*freelist, data);
return 1;
}
static void
_e_fm_mime_all_free(void)
{
E_Mime *mime;
while (mimes)
{
mime = mimes->data;
mimes = evas_list_remove_list(mimes, mimes);
evas_stringshare_del(mime->glob);
evas_stringshare_del(mime->mime);
free(mime);
}
}
static void
_e_fm_mime_update(void)
{
static double last_t = 0.0, t;
char buf[4096];
const char *homedir;
int reload = 0;
time_t ch_times[6] = {0, 0, 0, 0, 0, 0};
time_t ch;
/* load /etc/mime.types
* load /usr/share/mime/
*
* load ~/.mime.types
* load ~/.local/share/mime/
*/
t = ecore_time_get();
if ((t - last_t) < 1.0) return;
last_t = t;
homedir = e_user_homedir_get();
snprintf(buf, sizeof(buf), "usr/local/etc/mime.types");
ch = ecore_file_mod_time(buf);
if (ch != ch_times[0]) reload = 1;
ch_times[0] = ch;
snprintf(buf, sizeof(buf), "/etc/mime.types");
ch = ecore_file_mod_time(buf);
if (ch != ch_times[1]) reload = 1;
ch_times[1] = ch;
snprintf(buf, sizeof(buf), "/usr/local/share/mime/globs");
ch = ecore_file_mod_time(buf);
if (ch != ch_times[2]) reload = 1;
ch_times[2] = ch;
snprintf(buf, sizeof(buf), "/usr/share/mime/globs");
ch = ecore_file_mod_time(buf);
if (ch != ch_times[3]) reload = 1;
ch_times[3] = ch;
snprintf(buf, sizeof(buf), "%s/.mime.types", homedir);
ch = ecore_file_mod_time(buf);
if (ch != ch_times[4]) reload = 1;
ch_times[4] = ch;
snprintf(buf, sizeof(buf), "%s/.local/share/mime/globs", homedir);
ch = ecore_file_mod_time(buf);
if (ch != ch_times[5]) reload = 1;
ch_times[5] = ch;
if (!reload) return;
_e_fm_mime_all_free();
snprintf(buf, sizeof(buf), "/usr/local/etc/mime.types");
_e_fm_mime_mime_types_load(buf);
snprintf(buf, sizeof(buf), "/etc/mime.types");
_e_fm_mime_mime_types_load(buf);
snprintf(buf, sizeof(buf), "/usr/local/share/mime/globs");
_e_fm_mime_shared_mimeinfo_globs_load(buf);
snprintf(buf, sizeof(buf), "/usr/share/mime/globs");
_e_fm_mime_shared_mimeinfo_globs_load(buf);
snprintf(buf, sizeof(buf), "%s/.mime.types", homedir);
_e_fm_mime_mime_types_load(buf);
snprintf(buf, sizeof(buf), "%s/.local/share/mime/globs", homedir);
_e_fm_mime_shared_mimeinfo_globs_load(buf);
}
static int
_e_fm_mime_glob_remove(const char *glob)
{
Evas_List *l;
E_Mime *mime;
for (l = mimes; l; l = l->next)
{
mime = l->data;
if (!strcmp(glob, mime->glob))
{
mimes = evas_list_remove_list(mimes, l);
evas_stringshare_del(mime->glob);
evas_stringshare_del(mime->mime);
free(mime);
return 1;
}
}
return 0;
}
static void
_e_fm_mime_mime_types_load(char *file)
{
/* format:
# type of encoding.
#
###############################################################################
application/msaccess mdb
application/msword doc dot
application/news-message-id
*/
FILE *f;
char buf[4096], buf2[4096], mimetype[4096], ext[4096], *p, *pp;
E_Mime *mime;
f = fopen(file, "rb");
if (!f) return;
while (fgets(buf, sizeof(buf), f))
{
p = buf;
while (isblank(*p) && (*p != 0) && (*p != '\n')) p++;
if (*p == '#') continue;
if ((*p == '\n') || (*p == 0)) continue;
pp = p;
while (!isblank(*p) && (*p != 0) && (*p != '\n')) p++;
if ((*p == '\n') || (*p == 0)) continue;
strncpy(mimetype, pp, (p - pp));
mimetype[p - pp] = 0;
do
{
while (isblank(*p) && (*p != 0) && (*p != '\n')) p++;
if ((*p == '\n') || (*p == 0)) break;
pp = p;
while (!isblank(*p) && (*p != 0) && (*p != '\n')) p++;
strncpy(ext, pp, (p - pp));
ext[p - pp] = 0;
mime = E_NEW(E_Mime, 1);
if (mime)
{
mime->mime = evas_stringshare_add(mimetype);
snprintf(buf2, sizeof(buf2), "*.%s", ext);
mime->glob = evas_stringshare_add(buf2);
if ((!mime->mime) || (!mime->glob))
{
if (mime->mime) evas_stringshare_del(mime->mime);
if (mime->glob) evas_stringshare_del(mime->glob);
free(mime);
}
else
{
_e_fm_mime_glob_remove(buf2);
mimes = evas_list_append(mimes, mime);
}
}
}
while ((*p != '\n') && (*p != 0));
}
fclose(f);
}
static void
_e_fm_mime_shared_mimeinfo_globs_load(char *file)
{
/* format:
# This file was automatically generated by the
# update-mime-database command. DO NOT EDIT!
text/vnd.wap.wml:*.wml
application/x-7z-compressed:*.7z
application/vnd.corel-draw:*.cdr
text/spreadsheet:*.sylk
*/
FILE *f;
char buf[4096], mimetype[4096], ext[4096], *p, *pp;
E_Mime *mime;
f = fopen(file, "rb");
if (!f) return;
while (fgets(buf, sizeof(buf), f))
{
p = buf;
while (isblank(*p) && (*p != 0) && (*p != '\n')) p++;
if (*p == '#') continue;
if ((*p == '\n') || (*p == 0)) continue;
pp = p;
while ((*p != ':') && (*p != 0) && (*p != '\n')) p++;
if ((*p == '\n') || (*p == 0)) continue;
strncpy(mimetype, pp, (p - pp));
mimetype[p - pp] = 0;
p++;
pp = ext;
while ((*p != 0) && (*p != '\n'))
{
*pp = *p;
pp++;
p++;
}
*pp = 0;
mime = E_NEW(E_Mime, 1);
if (mime)
{
mime->mime = evas_stringshare_add(mimetype);
mime->glob = evas_stringshare_add(ext);
if ((!mime->mime) || (!mime->glob))
{
if (mime->mime) evas_stringshare_del(mime->mime);
if (mime->glob) evas_stringshare_del(mime->glob);
free(mime);
}
else
{
_e_fm_mime_glob_remove(ext);
mimes = evas_list_append(mimes, mime);
}
}
}
fclose(f);
}