diff --git a/src/bin/edi_debugpanel.c b/src/bin/edi_debugpanel.c index 1361c64..54914f8 100644 --- a/src/bin/edi_debugpanel.c +++ b/src/bin/edi_debugpanel.c @@ -295,7 +295,7 @@ void edi_debugpanel_start(const char *name) return; } - mime = efreet_mime_type_get(_edi_project_config->launch.path); + mime = edi_mime_type_get(_edi_project_config->launch.path); if (mime && !strcmp(mime, "application/x-shellscript")) snprintf(debug->cmd, sizeof(debug->cmd), LIBTOOL_COMMAND " --mode execute %s %s", debug->tool->exec, _edi_project_config->launch.path); else if (debug->tool->arguments) diff --git a/src/bin/edi_filepanel.c b/src/bin/edi_filepanel.c index 7d188b5..e822873 100644 --- a/src/bin/edi_filepanel.c +++ b/src/bin/edi_filepanel.c @@ -68,7 +68,7 @@ _get_provider_from_hashset(const char *filename) const char *mime = eina_hash_find(mime_entries, filename); if ( !mime ) { - mime = efreet_mime_type_get(filename); + mime = edi_mime_type_get(filename); if (mime) eina_hash_add(mime_entries, filename, strdup(mime)); diff --git a/src/bin/edi_main.c b/src/bin/edi_main.c index 8ffb285..6788203 100644 --- a/src/bin/edi_main.c +++ b/src/bin/edi_main.c @@ -1801,7 +1801,7 @@ elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED) { const char *mime; - mime = efreet_mime_type_get(project_path); + mime = edi_mime_type_get(project_path); if (!edi_content_provider_for_mime_get(mime)) { fprintf(stderr, _("Could not open file of unsupported mime type (%s)\n"), mime); diff --git a/src/bin/edi_scm_ui.c b/src/bin/edi_scm_ui.c index 9f74a34..258e8db 100644 --- a/src/bin/edi_scm_ui.c +++ b/src/bin/edi_scm_ui.c @@ -235,7 +235,7 @@ _content_get(void *data, Evas_Object *obj, const char *source) status = (Edi_Scm_Status *) data; - mime = efreet_mime_type_get(status->fullpath); + mime = edi_mime_type_get(status->fullpath); if (mime) icon_file = efreet_mime_type_icon_get(mime, elm_config_icon_theme_get(), 32); diff --git a/src/bin/edi_searchpanel.c b/src/bin/edi_searchpanel.c index cbcd5c0..19feb8d 100644 --- a/src/bin/edi_searchpanel.c +++ b/src/bin/edi_searchpanel.c @@ -407,7 +407,7 @@ _edi_searchpanel_search_project_file(const char *path, const char *search_term, // If the file looks big, check if it is a text file first. if (eina_file_size_get(f) > 1 * 1024 * 1024 && - strncmp(efreet_mime_type_get(path), "text/", 5)) + strncmp(edi_mime_type_get(path), "text/", 5)) { eina_file_close(f); return ; diff --git a/src/bin/mainview/edi_mainview.c b/src/bin/mainview/edi_mainview.c index 67a65f7..39cd61a 100644 --- a/src/bin/mainview/edi_mainview.c +++ b/src/bin/mainview/edi_mainview.c @@ -257,7 +257,7 @@ _edi_mainview_win_stat_done(void *data, Eio_File *handler EINA_UNUSED, const Ein if (!S_ISREG(stat->mode)) return; - mime = efreet_mime_type_get(options->path); + mime = edi_mime_type_get(options->path); provider = edi_content_provider_for_mime_get(mime); if (!provider) { diff --git a/src/bin/mainview/edi_mainview_panel.c b/src/bin/mainview/edi_mainview_panel.c index c4ae9f6..629f7ee 100644 --- a/src/bin/mainview/edi_mainview_panel.c +++ b/src/bin/mainview/edi_mainview_panel.c @@ -912,7 +912,7 @@ _edi_mainview_panel_tab_stat_done(void *data, Eio_File *handler EINA_UNUSED, con if (!S_ISREG(stat->mode)) return; - mime = efreet_mime_type_get(options->path); + mime = edi_mime_type_get(options->path); provider = edi_content_provider_for_mime_get(mime); if (!provider) { diff --git a/src/lib/.edi_mime.c.swp b/src/lib/.edi_mime.c.swp new file mode 100644 index 0000000..da3048f Binary files /dev/null and b/src/lib/.edi_mime.c.swp differ diff --git a/src/lib/Edi.h b/src/lib/Edi.h index eaf9d82..9d42fd3 100644 --- a/src/lib/Edi.h +++ b/src/lib/Edi.h @@ -39,6 +39,7 @@ extern "C" { #include #include #include +#include /** * @file diff --git a/src/lib/edi_mime.c b/src/lib/edi_mime.c new file mode 100644 index 0000000..9808bf5 --- /dev/null +++ b/src/lib/edi_mime.c @@ -0,0 +1,63 @@ +#ifdef HAVE_CONFIG +# include "config.h" +#endif + +#include +#include +#include + +#include "Edi.h" +#include "edi_mime.h" + +#include "edi_private.h" + +EAPI const char * +edi_mime_type_get(const char *path) +{ + Eina_File *f; + const char *mime; + char *map; + unsigned long long len; + Eina_Bool likely_text = EINA_TRUE; + + f = eina_file_open(path, EINA_FALSE); + if (!f) return efreet_mime_type_get(path); + + map = eina_file_map_all(f, EINA_FILE_POPULATE); + if (!map) + { + eina_file_close(f); + return efreet_mime_type_get(path); + } + + len = eina_file_size_get(f); + if (!len) + { + eina_file_map_free(f, map); + eina_file_close(f); + return "text/plain"; + } + + if (len > 2048) len = 2048; + + for (int i = 0; i < (int) len; i++) + { + if (map[i] == '\0') + { + likely_text = EINA_FALSE; + break; + } + } + + eina_file_map_free(f, map); + eina_file_close(f); + + mime = efreet_mime_type_get(path); + if ((strncmp(mime, "text/", 5)) && likely_text) + { + return "text/plain"; + } + + return mime; +} + diff --git a/src/lib/edi_mime.h b/src/lib/edi_mime.h new file mode 100644 index 0000000..805705e --- /dev/null +++ b/src/lib/edi_mime.h @@ -0,0 +1,31 @@ +#ifndef EDI_MIME_H_ +# define EDI_MIME_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @file + * @brief These routines are used for Edi mime handling + */ + +/** + * Return the mime type of a file + * + * @param path The path of the file to return the mime type of. + * + * @return A pointer to the mime type as a const character string. + * + */ +EAPI const char *edi_mime_type_get(const char *path); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* EDI_MIME_H_ */ diff --git a/src/lib/meson.build b/src/lib/meson.build index 9d948cd..dcd2600 100644 --- a/src/lib/meson.build +++ b/src/lib/meson.build @@ -15,6 +15,8 @@ src = files([ 'edi_create.h', 'edi_exe.c', 'edi_exe.h', + 'edi_mime.c', + 'edi_mime.h', 'edi_path.c', 'edi_path.h', 'edi_process.c',