Edi_Mime: Use our own variation to detect mime.

Replace efreet_mime_type_get with our own internal
edi_mime_type_get. Due to inacurracies do our own test for
binary file.
This commit is contained in:
Alastair Poole 2019-12-20 18:00:57 +00:00
parent be5868e8d4
commit d45bb357ef
12 changed files with 104 additions and 7 deletions

View File

@ -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)

View File

@ -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));

View File

@ -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);

View File

@ -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);

View File

@ -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 ;

View File

@ -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)
{

View File

@ -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)
{

BIN
src/lib/.edi_mime.c.swp Normal file

Binary file not shown.

View File

@ -39,6 +39,7 @@ extern "C" {
#include <edi_path.h>
#include <edi_exe.h>
#include <edi_scm.h>
#include <edi_mime.h>
/**
* @file

63
src/lib/edi_mime.c Normal file
View File

@ -0,0 +1,63 @@
#ifdef HAVE_CONFIG
# include "config.h"
#endif
#include <Efreet_Mime.h>
#include <Ecore_File.h>
#include <Eina.h>
#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;
}

31
src/lib/edi_mime.h Normal file
View File

@ -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_ */

View File

@ -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',