<commit_before>#include "elm_file_display_priv.h"

typedef struct
{
   Evas_Object *filepreview;
   Evas_Object *size, *size_name;
   Evas_Object *mtime, *mtime_name;
   Evas_Object *user, *user_name;
   Evas_Object *group, *group_name;
   Evas_Object *ctime, *ctime_name;
   Evas_Object *mtype, *mtype_name;
} Filepreview;
 #if 0
static const char*
_preview_read_file(Efm_File *file)
{
   FILE *f;
   char buf[PATH_MAX];
   const char *esc;

   f = fopen(file->path, "r");

   fread(buf, sizeof(char), sizeof(buf), f);

   ERR("WE GOT: %s", buf);

   esc = evas_textblock_escape_string_get(buf);
   if (esc)
     return esc;
   else
     return strdup(buf);
}
#endif
void
filepreview_file_set(Evas_Object *w, Efm_File *file)
{
  Filepreview *f;
  Evas_Object *o;
  char buf[PATH_MAX];
  const char *path;
  const char *mime_type;
  Efm_File_Stat *st;

  //char[] bytes = {"B", "KB", "MB", "GB", "TB", "PM", "EM", NULL}
  f = evas_object_data_get(w, "__ctx");
  path = efm_file_path_get(file);
  mime_type = efm_file_mimetype_get(file);

  if (!f) return;

  //TODO make a nice thumbnail :)
  //- text thumbnail
  //- image file thumbnail
  //- just the mime type icon
  if (f->filepreview)
    {
       elm_object_part_content_unset(w, "thumb");
       evas_object_del(f->filepreview);
    }
#if 0
  if (!strncmp("text/", file->mime_type, 5))
    {
       Evas_Object *tx;

       const char *content;
       //text preview
       o = elm_layout_add(w);
       if (!elm_layout_theme_set(o, "file_display", "file_text_preview", "default"))
         {
            CRI("Failed to set theme file\n");
         }

       tx = elm_entry_add(o);
       elm_entry_editable_set(tx, EINA_TRUE);
       content = _preview_read_file(file);
       snprintf(buf, sizeof(buf), "<font_size=30><color=BLACK>%s", content);
       elm_entry_entry_set(tx, buf);
       elm_object_part_content_set(o, "content", tx);
       free((char*)content);
    }
  else
    #endif
    if (evas_object_image_extension_can_load_fast_get(path))
    {
       //make a thumb
       o = elm_thumb_add(w);
       eo_do(o, efl_file_set(path, NULL));
    }
  else
    {
       const char *theme;
       const char *ic;
       const char *mime_type;

       //display the mime_type icon
       o = elm_icon_add(w);
       mime_type = efm_file_mimetype_get(file);

       eo_do(ELM_FILE_ICON_CLASS, theme = elm_obj_file_icon_util_icon_theme_get());

       ic = efreet_mime_type_icon_get(mime_type, theme, 256);
       eo_do(o, efl_file_set(ic, NULL));
    }

  evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
  evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

  f->filepreview = o;
  elm_object_part_content_set(w, "thumb", o);
  evas_object_show(o);

  st = efm_file_stat_get(file);

  {
    char *nicestr;

    eo_do(EMOUS_CLASS, nicestr = emous_util_size_convert(EINA_TRUE, st->size));
    elm_object_text_set(f->size, nicestr);
    free(nicestr);<commit_msg>elm_file_display: use cache in preview<commit_after>#include "elm_file_display_priv.h"

typedef struct
{
   Evas_Object *filepreview;
   Evas_Object *size, *size_name;
   Evas_Object *mtime, *mtime_name;
   Evas_Object *user, *user_name;
   Evas_Object *group, *group_name;
   Evas_Object *ctime, *ctime_name;
   Evas_Object *mtype, *mtype_name;
} Filepreview;
 #if 0
static const char*
_preview_read_file(Efm_File *file)
{
   FILE *f;
   char buf[PATH_MAX];
   const char *esc;

   f = fopen(file->path, "r");

   fread(buf, sizeof(char), sizeof(buf), f);

   ERR("WE GOT: %s", buf);

   esc = evas_textblock_escape_string_get(buf);
   if (esc)
     return esc;
   else
     return strdup(buf);
}
#endif
void
filepreview_file_set(Evas_Object *w, Efm_File *file)
{
  Filepreview *f;
  Evas_Object *o;
  char buf[PATH_MAX];
  const char *path;
  const char *mime_type;
  Efm_File_Stat *st;

  //char[] bytes = {"B", "KB", "MB", "GB", "TB", "PM", "EM", NULL}
  f = evas_object_data_get(w, "__ctx");
  path = efm_file_path_get(file);
  mime_type = efm_file_mimetype_get(file);

  if (!f) return;

  //TODO make a nice thumbnail :)
  //- text thumbnail
  //- image file thumbnail
  //- just the mime type icon
  if (f->filepreview)
    {
       elm_object_part_content_unset(w, "thumb");
       evas_object_del(f->filepreview);
    }
#if 0
  if (!strncmp("text/", file->mime_type, 5))
    {
       Evas_Object *tx;

       const char *content;
       //text preview
       o = elm_layout_add(w);
       if (!elm_layout_theme_set(o, "file_display", "file_text_preview", "default"))
         {
            CRI("Failed to set theme file\n");
         }

       tx = elm_entry_add(o);
       elm_entry_editable_set(tx, EINA_TRUE);
       content = _preview_read_file(file);
       snprintf(buf, sizeof(buf), "<font_size=30><color=BLACK>%s", content);
       elm_entry_entry_set(tx, buf);
       elm_object_part_content_set(o, "content", tx);
       free((char*)content);
    }
  else
    #endif
    if (evas_object_image_extension_can_load_fast_get(path))
    {
       //make a thumb
       o = elm_thumb_add(w);
       eo_do(o, efl_file_set(path, NULL));
    }
  else
    {
       const char *ic;
       const char *mime_type;

       //display the mime_type icon
       o = elm_icon_add(w);
       elm_icon_order_lookup_set(o, ELM_ICON_LOOKUP_FDO);
       if (efm_file_is_type(file, EFM_FILE_TYPE_DIRECTORY))
         ic = "folder";
       else
         {
            mime_type = efm_file_mimetype_get(file);
            eo_do(cache, ic = elm_file_mimetype_cache_mimetype_get(mime_type));
         }

       eo_do(o, elm_obj_icon_standard_set(ic));
    }

  evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
  evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);

  f->filepreview = o;
  elm_object_part_content_set(w, "thumb", o);
  evas_object_show(o);

  st = efm_file_stat_get(file);

  {
    char *nicestr;

    eo_do(EMOUS_CLASS, nicestr = emous_util_size_convert(EINA_TRUE, st->size));
    elm_object_text_set(f->size, nicestr);
    free(nicestr);
{'fraction_non_alphanumeric': 0.12838730998017184, 'fraction_numerical': 0.0021480502313284866, 'mean_word_length': 3.2626760563380284, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '511165', 'n_tokens_mistral': 2455, 'n_tokens_neox': 2379, 'n_words': 449}