<commit_before>#include "e.h"

static void        *_create_data    (E_Config_Dialog *cfd);
static void         _fill_data      (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void         _free_data      (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create   (E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int          _basic_apply    (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void         _cb_icon_sel    (void *data, void *data2);
static Evas_Object *_get_icon       (void *data);
static void         _cb_type        (void *data, Evas_Object *obj, void *event_info);
static void         _cb_fsel_sel    (void *data, Evas_Object *obj);
static void         _cb_fsel_ok     (void *data, E_Dialog *dia);
static void         _cb_fsel_cancel (void *data, E_Dialog *dia);
static void         _cb_file_change (void *data);

typedef enum _Icon_Type Icon_Type;
enum _Icon_Type 
{
     THUMB,
     THEME,
     EDJ
};

struct _E_Config_Dialog_Data 
{
   char *mime;
   char *icon;
   int type;

   char *file;
   struct 
     {
	Evas_Object *icon, *fsel_wid;
	E_Dialog *fsel;
     } gui;
};

#define IFDUP(src, dst) if (src) dst = strdup(src); else dst = NULL;
#define IFFREE(src) if (src) free(src); src = NULL;

EAPI E_Config_Dialog *
e_int_config_mime_edit(E_Config_Mime_Icon *mime) 
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   E_Container *con;
   
   if (e_config_dialog_find("E", "_config_mime_edit_dialog")) return NULL;

   con = e_container_current_get(e_manager_current_get());
   
   v = E_NEW(E_Config_Dialog_View, 1);
   v->create_cfdata = _create_data;
   v->free_cfdata = _free_data;
   v->basic.create_widgets = _basic_create;
   v->basic.apply_cfdata = _basic_apply;
   
   cfd = e_config_dialog_new(con, _("Mime Settings"), "E", 
			     "_config_mime_edit_dialog", "enlightenment/e", 
			     0, v, mime);
   return cfd;
}

static void *
_create_data(E_Config_Dialog *cfd) 
{
   E_Config_Dialog_Data *cfdata;
   
   cfdata = E_NEW(E_Config_Dialog_Data, 1);
   _fill_data(cfd, cfdata);
   return cfdata;
}

static void
_fill_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
   E_Config_Mime_Icon *mime;
   char *p;
   
   if (!cfd->data) return;

   mime = cfd->data;
   if (!mime) return;
   IFDUP(mime->mime, cfdata->mime);
   IFDUP(mime->icon, cfdata->icon);
   if (!cfdata->icon) 
     {
	cfdata->type = THUMB;
	return;
     }
   
   if (!strcmp(cfdata->icon, "THUMB")) 
     cfdata->type = THUMB;
   else
     {
	p = strrchr(cfdata->icon, '.');
	if ((p) && (!strcmp(p, ".edj"))) 
	  cfdata->type = EDJ;
	else
	  cfdata->type = THEME;
     }
}

static void
_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
   if (cfdata->gui.fsel) e_object_del(E_OBJECT(cfdata->gui.fsel));
   IFFREE(cfdata->file);
   IFFREE(cfdata->mime);
   IFFREE(cfdata->icon);
   E_FREE(cfdata);
}

static Evas_Object *
_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) 
{
   Evas_Object *o, *of;
   Evas_Object *ob, *oi, *icon;
   E_Radio_Group *rg;
   
   o = e_widget_list_add(evas, 0, 0);

   of = e_widget_frametable_add(evas, _("Basic Info"), 0);
   ob = e_widget_label_add(evas, _("Mime:"));
   e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 1, 1, 1);
   ob = e_widget_entry_add(evas, &(cfdata->mime));
   e_widget_entry_readonly_set(ob, 1);
   e_widget_min_size_set(ob, 100, 1);
   e_widget_frametable_object_append(of, ob, 1, 0, 1, 1, 1, 1, 1, 1);
   e_widget_list_object_append(o, of, 1, 1, 0.5);
   
   of = e_widget_frametable_add(evas, _("Icon"), 0);
   rg = e_widget_radio_group_new(&cfdata->type);
   ob = e_widget_radio_add(evas, _("Use Generated Thumbnail"), THUMB, rg);
   evas_object_smart_callback_add(ob, "changed", _cb_type, cfdata);
   e_widget_frametable_object_append(of, ob, 0, 0, 3, 1, 1, 1, 1, 1);
   ob = e_widget_radio_add(evas, _("Use Theme Icon"), THEME, rg);
   evas_object_smart_callback_add(ob, "changed", _cb_type, cfdata);
   e_widget_frametable_object_append(of, ob, 0, 1, 3, 1, 1, 1, 1, 1);
   ob = e_widget_radio_add(evas, _("Use Edje File"), EDJ, rg);
   evas_object_smart_callback_add(ob, "changed", _cb_type, cfdata);
   e_widget_frametable_object_append(of, ob, 0, 2, 3, 1, 1, 1, 1, 1);
   e_widget_disabled_set(ob, 1);
   
   oi = e_widget_button_add(evas, "", NULL, _cb_icon_sel, cfdata, cfd);
   cfdata->gui.icon = oi;
   if (cfdata->icon) 
     {
	icon = _get_icon(cfdata);
	if (icon)
	  e_widget_button_icon_set(oi, icon);
     }
   
   e_widget_min_size_set(oi, 48, 48);
   e_widget_frametable_object_append(of, oi, 1, 3, 1, 1, 1, 1, 1, 1);
   e_widget_list_object_append(o, of, 1, 1, 0.5);
      
   return o;
}

static int
_basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
   E_Config_Mime_Icon *mime;
   char buf[4096];
   
   mime = cfd->data;
   if (!mime) return 0;
   
   if (mime->mime)
     evas_stringshare_del(mime->mime);
   mime->mime = evas_stringshare_add(cfdata->mime);
   
   if (mime->icon)
     evas_stringshare_del(mime->icon);
   
   switch (cfdata->type) 
     {
      case THUMB:
	mime->icon = evas_stringshare_add("THUMB");
	break;
      case THEME:
      case EDJ:
	snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", cfdata->mime);
	mime->icon = evas_stringshare_add(buf);
	break;
     }
   e_config_save_queue();
   return 1;
}

static void 
_cb_icon_sel(void *data, void *data2) 
{
   E_Config_Dialog_Data *cfdata;
   E_Config_Dialog *cfd;
   E_Dialog *dia;
   Evas_Object *o;
   Evas_Coord w, h;
   
   cfdata = data;
   if (!cfdata) return;
   if (cfdata->gui.fsel) return;

   cfd = data2;
   if (!cfd) return;
   
   dia = e_dialog_new(cfd->con, "E", "_mime_icon_select_dialog");
   if (!dia) return;
   e_dialog_title_set(dia, _("Select an Icon"));<commit_msg>Fix saving of mime types, they actually save properly now...but why does fm2 not honor it? ie: I set image/png to not be thumbnailed, yet they still thumb...hmm.<commit_after>#include "e.h"

static void        *_create_data    (E_Config_Dialog *cfd);
static void         _fill_data      (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void         _free_data      (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create   (E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static int          _basic_apply    (E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static void         _cb_icon_sel    (void *data, void *data2);
static Evas_Object *_get_icon       (void *data);
static void         _cb_type        (void *data, Evas_Object *obj, void *event_info);
static void         _cb_fsel_sel    (void *data, Evas_Object *obj);
static void         _cb_fsel_ok     (void *data, E_Dialog *dia);
static void         _cb_fsel_cancel (void *data, E_Dialog *dia);
static void         _cb_file_change (void *data);

typedef enum _Icon_Type Icon_Type;
enum _Icon_Type 
{
     THUMB,
     THEME,
     EDJ
};

struct _E_Config_Dialog_Data 
{
   char *mime;
   char *icon;
   int type;

   char *file;
   struct 
     {
	Evas_Object *icon, *fsel_wid;
	E_Dialog *fsel;
     } gui;
};

#define IFDUP(src, dst) if (src) dst = strdup(src); else dst = NULL;
#define IFFREE(src) if (src) free(src); src = NULL;

EAPI E_Config_Dialog *
e_int_config_mime_edit(E_Config_Mime_Icon *mime) 
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   E_Container *con;
   
   if (e_config_dialog_find("E", "_config_mime_edit_dialog")) return NULL;

   con = e_container_current_get(e_manager_current_get());
   
   v = E_NEW(E_Config_Dialog_View, 1);
   v->create_cfdata = _create_data;
   v->free_cfdata = _free_data;
   v->basic.create_widgets = _basic_create;
   v->basic.apply_cfdata = _basic_apply;
   
   cfd = e_config_dialog_new(con, _("Mime Settings"), "E", 
			     "_config_mime_edit_dialog", "enlightenment/e", 
			     0, v, mime);
   return cfd;
}

static void *
_create_data(E_Config_Dialog *cfd) 
{
   E_Config_Dialog_Data *cfdata;
   
   cfdata = E_NEW(E_Config_Dialog_Data, 1);
   _fill_data(cfd, cfdata);
   return cfdata;
}

static void
_fill_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
   E_Config_Mime_Icon *mime;
   char *p;
   
   if (!cfd->data) return;

   mime = cfd->data;
   if (!mime) return;
   IFDUP(mime->mime, cfdata->mime);
   IFDUP(mime->icon, cfdata->icon);
   if (!cfdata->icon) 
     {
	cfdata->type = THUMB;
	return;
     }
   
   if (!strcmp(cfdata->icon, "THUMB")) 
     cfdata->type = THUMB;
   else
     {
	p = strrchr(cfdata->icon, '.');
	if ((p) && (!strcmp(p, ".edj"))) 
	  cfdata->type = EDJ;
	else
	  cfdata->type = THEME;
     }
}

static void
_free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
   if (cfdata->gui.fsel) e_object_del(E_OBJECT(cfdata->gui.fsel));
   IFFREE(cfdata->file);
   IFFREE(cfdata->mime);
   IFFREE(cfdata->icon);
   E_FREE(cfdata);
}

static Evas_Object *
_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata) 
{
   Evas_Object *o, *of;
   Evas_Object *ob, *oi, *icon;
   E_Radio_Group *rg;
   
   o = e_widget_list_add(evas, 0, 0);

   of = e_widget_frametable_add(evas, _("Basic Info"), 0);
   ob = e_widget_label_add(evas, _("Mime:"));
   e_widget_frametable_object_append(of, ob, 0, 0, 1, 1, 1, 1, 1, 1);
   ob = e_widget_entry_add(evas, &(cfdata->mime));
   e_widget_entry_readonly_set(ob, 1);
   e_widget_min_size_set(ob, 100, 1);
   e_widget_frametable_object_append(of, ob, 1, 0, 1, 1, 1, 1, 1, 1);
   e_widget_list_object_append(o, of, 1, 1, 0.5);
   
   of = e_widget_frametable_add(evas, _("Icon"), 0);
   rg = e_widget_radio_group_new(&cfdata->type);
   ob = e_widget_radio_add(evas, _("Use Generated Thumbnail"), 0, rg);
   evas_object_smart_callback_add(ob, "changed", _cb_type, cfdata);
   e_widget_frametable_object_append(of, ob, 0, 0, 3, 1, 1, 1, 1, 1);
   ob = e_widget_radio_add(evas, _("Use Theme Icon"), 1, rg);
   evas_object_smart_callback_add(ob, "changed", _cb_type, cfdata);
   e_widget_frametable_object_append(of, ob, 0, 1, 3, 1, 1, 1, 1, 1);
   ob = e_widget_radio_add(evas, _("Use Edje File"), 2, rg);
   evas_object_smart_callback_add(ob, "changed", _cb_type, cfdata);
   e_widget_frametable_object_append(of, ob, 0, 2, 3, 1, 1, 1, 1, 1);
   e_widget_disabled_set(ob, 1);
   
   oi = e_widget_button_add(evas, "", NULL, _cb_icon_sel, cfdata, cfd);
   cfdata->gui.icon = oi;
   if (cfdata->icon) 
     {
	icon = _get_icon(cfdata);
	if (icon)
	  e_widget_button_icon_set(oi, icon);
     }
   
   e_widget_min_size_set(oi, 48, 48);
   e_widget_frametable_object_append(of, oi, 1, 3, 1, 1, 1, 1, 1, 1);
   e_widget_list_object_append(o, of, 1, 1, 0.5);
      
   return o;
}

static int
_basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata) 
{
   E_Config_Mime_Icon *mime;
   Evas_List *l;
   char buf[4096];
   
   for (l = e_config->mime_icons; l; l = l->next) 
     {
	mime = l->data;
	if (!mime) continue;
	if (strcmp(mime->mime, cfdata->mime)) continue;
	if (mime->mime)
	  evas_stringshare_del(mime->mime);
	mime->mime = evas_stringshare_add(cfdata->mime);
	if (mime->icon)
	  evas_stringshare_del(mime->icon);
	switch (cfdata->type) 
	  {
	   case THUMB:
	     mime->icon = evas_stringshare_add("THUMB");
	     break;
	   case THEME:
	     snprintf(buf, sizeof(buf), "e/icons/fileman/mime/%s", cfdata->mime);
	     mime->icon = evas_stringshare_add(buf);
	     break;
	   case EDJ:
	     break;
	  }
	break;
     }
   e_config_save_queue();
   return 1;
}

static void 
_cb_icon_sel(void *data, void *data2) 
{
   E_Config_Dialog_Data *cfdata;
   E_Config_Dialog *cfd;
   E_Dialog *dia;
   Evas_Object *o;
   Evas_Coord w, h;
   
   cfdata = data;
   if (!cfdata) return;
   if (cfdata->gui.fsel) return;

   cfd = data2;
   if (!cfd) return;
   
   dia = e_dialog_new(cfd->con, "E", "_mime_icon_select_dialog");
   if (!dia) return;
   e_dialog_title_set(dia, _("Select an Icon"));
{'fraction_non_alphanumeric': 0.13413917569042222, 'fraction_numerical': 0.014018299336858893, 'mean_word_length': 3.6448343079922028, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 85, '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': '797580', 'n_tokens_mistral': 5198, 'n_tokens_neox': 4884, 'n_words': 1023}