<commit_before>/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

/* FIXME:
 * 
 * basic -
 * + show file 
 * + show size
 * + show modified date
 * + show mimetype
 * + show permissions (others read, others write)
 * + show preview
 * + show owner
 * + show icon
 * * show symlink/fifo/socket/etc. status
 * * show broken link status
 * + change icon for mime type
 * * change icon for just this file
 * + change permissions (others read, others write)
 * 
 * advanced (extra) -
 * * show access date
 * * show change date
 * * show comment
 * * show generic
 * * show mount status
 * * show setuid bit
 * * show link destination (if symlink or link)
 * * show group
 * * change link destination
 * * change app to open THIS file with (or dir)
 * 
 */

/* PROTOTYPES - same all the time */

static void *_create_data(E_Config_Dialog *cfd);
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
#if 0
static int _advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
#endif

static void _cb_icon_sel(void *data, void *data2);
static void _cb_type(void *data, Evas_Object *obj, void *event_info);
static void _cb_preview_update(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);

/* Actual config data we will be playing with whil the dialog is active */
struct _E_Config_Dialog_Data
{
   E_Fm2_Icon *ic;
   E_Fm2_Icon_Info *fi;
   struct {
      Evas_Object *icon_wid;
      Evas_Object *preview;
      Evas_Object *preview_table;
      Evas_Object *fsel_wid;
      E_Dialog *fsel;
   } gui;
   /*- BASIC -*/
   char *file;
   char *size;
   char *mod_date;
   char *mime;
   char *owner;
   char *link;
   char *plink;
   int owner_read;
   int owner_write;
   int others_read;
   int others_write;
   int picon_type;
   int picon_mime;
   int picon_changed;
   int icon_type;
   int icon_mime;
   char *icon;
   /*- ADVANCED -*/
};

/* a nice easy setup function that does the dirty work */
EAPI E_Config_Dialog *
e_fm_prop_file(E_Container *con, E_Fm2_Icon *ic)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   
   v = E_NEW(E_Config_Dialog_View, 1);
   
   /* methods */
   v->create_cfdata           = _create_data;
   v->free_cfdata             = _free_data;
   v->basic.apply_cfdata      = _basic_apply_data;
   v->basic.create_widgets    = _basic_create_widgets;
#if 0   
   v->advanced.apply_cfdata   = _advanced_apply_data;
   v->advanced.create_widgets = _advanced_create_widgets;
#endif   
   /* create config diaolg for NULL object/data */
   cfd = e_config_dialog_new(con,
			     _("File Properties"),
			     "E", "_fm_prop",
			     "enlightenment/file_properties", 0, v, ic);
   return cfd;
}

/**--CREATE--**/
static void
_fill_data(E_Config_Dialog_Data *cfdata, E_Fm2_Icon *ic)
{
   struct passwd *pw;
   
   cfdata->ic = ic;
   cfdata->fi = e_fm2_icon_file_info_get(ic);
   if (cfdata->fi->file) cfdata->file = strdup(cfdata->fi->file);
   cfdata->size = e_util_size_string_get(cfdata->fi->statinfo.st_size);
   cfdata->mod_date = e_util_file_time_get(cfdata->fi->statinfo.st_mtime);
   if (cfdata->fi->mime) cfdata->mime = strdup(cfdata->fi->mime);
   pw = getpwuid(cfdata->fi->statinfo.st_uid);
   if (pw) cfdata->owner = strdup(pw->pw_name);
   if (cfdata->fi->link) cfdata->link = strdup(cfdata->fi->link);
   if (cfdata->fi->link) cfdata->plink = strdup(cfdata->fi->link);
   if (cfdata->fi->statinfo.st_mode & S_IRUSR) cfdata->owner_read = 1;
   if (cfdata->fi->statinfo.st_mode & S_IWUSR) cfdata->owner_write = 1;
   if (cfdata->fi->statinfo.st_mode & S_IROTH) cfdata->others_read = 1;
   if (cfdata->fi->statinfo.st_mode & S_IWOTH) cfdata->others_write = 1;
}

static void *
_create_data(E_Config_Dialog *cfd)
{
   /* Create cfdata - cfdata is a temporary block of config data that this
    * dialog will be dealing with while configuring. it will be applied to
    * the running systems/config in the apply methods
    */
   E_Config_Dialog_Data *cfdata;
   
   cfdata = E_NEW(E_Config_Dialog_Data, 1);
   _fill_data(cfdata, cfd->data);
   return cfdata;
}

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));
   E_FREE(cfdata->file);
   E_FREE(cfdata->size);
   E_FREE(cfdata->mod_date);
   E_FREE(cfdata->mime);
   E_FREE(cfdata->owner);
   E_FREE(cfdata->link);
   E_FREE(cfdata->plink);
   E_FREE(cfdata->icon);
   free(cfdata);
}

/**--APPLY--**/
static int
_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
   char buf[4096];
   int fperm = 0;
   
   snprintf(buf, sizeof(buf), "%s/%s", 
	    e_fm2_real_path_get(cfdata->fi->fm), cfdata->fi->file);
   if (((cfdata->fi->statinfo.st_mode & S_IRUSR) && (cfdata->owner_read)) ||
       ((!cfdata->fi->statinfo.st_mode & S_IRUSR) && (!cfdata->owner_read)))
     fperm = 1;
   if (((cfdata->fi->statinfo.st_mode & S_IWUSR) && (cfdata->owner_write)) ||
       ((!cfdata->fi->statinfo.st_mode & S_IWUSR) && (!cfdata->owner_write)))
     fperm = 1;
   if (((cfdata->fi->statinfo.st_mode & S_IROTH) && (cfdata->others_read)) ||
       ((!cfdata->fi->statinfo.st_mode & S_IROTH) && (!cfdata->others_read)))
     fperm = 1;
   if (((cfdata->fi->statinfo.st_mode & S_IWOTH) && (cfdata->others_write)) ||
       ((!cfdata->fi->statinfo.st_mode & S_IWOTH) && (!cfdata->others_write)))
     fperm = 1;
   if (fperm)
     {
	mode_t pmode;
	
	pmode = cfdata->fi->statinfo.st_mode;
	if (cfdata->owner_read) cfdata->fi->statinfo.st_mode |= S_IRUSR;
	else cfdata->fi->statinfo.st_mode &= ~S_IRUSR;
	if (cfdata->owner_write) cfdata->fi->statinfo.st_mode |= S_IWUSR;<commit_msg>Fix warning by adding parentheses<commit_after>/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "e.h"

/* FIXME:
 * 
 * basic -
 * + show file 
 * + show size
 * + show modified date
 * + show mimetype
 * + show permissions (others read, others write)
 * + show preview
 * + show owner
 * + show icon
 * * show symlink/fifo/socket/etc. status
 * * show broken link status
 * + change icon for mime type
 * * change icon for just this file
 * + change permissions (others read, others write)
 * 
 * advanced (extra) -
 * * show access date
 * * show change date
 * * show comment
 * * show generic
 * * show mount status
 * * show setuid bit
 * * show link destination (if symlink or link)
 * * show group
 * * change link destination
 * * change app to open THIS file with (or dir)
 * 
 */

/* PROTOTYPES - same all the time */

static void *_create_data(E_Config_Dialog *cfd);
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int _basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
#if 0
static int _advanced_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static Evas_Object *_advanced_create_widgets(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
#endif

static void _cb_icon_sel(void *data, void *data2);
static void _cb_type(void *data, Evas_Object *obj, void *event_info);
static void _cb_preview_update(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);

/* Actual config data we will be playing with whil the dialog is active */
struct _E_Config_Dialog_Data
{
   E_Fm2_Icon *ic;
   E_Fm2_Icon_Info *fi;
   struct {
      Evas_Object *icon_wid;
      Evas_Object *preview;
      Evas_Object *preview_table;
      Evas_Object *fsel_wid;
      E_Dialog *fsel;
   } gui;
   /*- BASIC -*/
   char *file;
   char *size;
   char *mod_date;
   char *mime;
   char *owner;
   char *link;
   char *plink;
   int owner_read;
   int owner_write;
   int others_read;
   int others_write;
   int picon_type;
   int picon_mime;
   int picon_changed;
   int icon_type;
   int icon_mime;
   char *icon;
   /*- ADVANCED -*/
};

/* a nice easy setup function that does the dirty work */
EAPI E_Config_Dialog *
e_fm_prop_file(E_Container *con, E_Fm2_Icon *ic)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;
   
   v = E_NEW(E_Config_Dialog_View, 1);
   
   /* methods */
   v->create_cfdata           = _create_data;
   v->free_cfdata             = _free_data;
   v->basic.apply_cfdata      = _basic_apply_data;
   v->basic.create_widgets    = _basic_create_widgets;
#if 0   
   v->advanced.apply_cfdata   = _advanced_apply_data;
   v->advanced.create_widgets = _advanced_create_widgets;
#endif   
   /* create config diaolg for NULL object/data */
   cfd = e_config_dialog_new(con,
			     _("File Properties"),
			     "E", "_fm_prop",
			     "enlightenment/file_properties", 0, v, ic);
   return cfd;
}

/**--CREATE--**/
static void
_fill_data(E_Config_Dialog_Data *cfdata, E_Fm2_Icon *ic)
{
   struct passwd *pw;
   
   cfdata->ic = ic;
   cfdata->fi = e_fm2_icon_file_info_get(ic);
   if (cfdata->fi->file) cfdata->file = strdup(cfdata->fi->file);
   cfdata->size = e_util_size_string_get(cfdata->fi->statinfo.st_size);
   cfdata->mod_date = e_util_file_time_get(cfdata->fi->statinfo.st_mtime);
   if (cfdata->fi->mime) cfdata->mime = strdup(cfdata->fi->mime);
   pw = getpwuid(cfdata->fi->statinfo.st_uid);
   if (pw) cfdata->owner = strdup(pw->pw_name);
   if (cfdata->fi->link) cfdata->link = strdup(cfdata->fi->link);
   if (cfdata->fi->link) cfdata->plink = strdup(cfdata->fi->link);
   if (cfdata->fi->statinfo.st_mode & S_IRUSR) cfdata->owner_read = 1;
   if (cfdata->fi->statinfo.st_mode & S_IWUSR) cfdata->owner_write = 1;
   if (cfdata->fi->statinfo.st_mode & S_IROTH) cfdata->others_read = 1;
   if (cfdata->fi->statinfo.st_mode & S_IWOTH) cfdata->others_write = 1;
}

static void *
_create_data(E_Config_Dialog *cfd)
{
   /* Create cfdata - cfdata is a temporary block of config data that this
    * dialog will be dealing with while configuring. it will be applied to
    * the running systems/config in the apply methods
    */
   E_Config_Dialog_Data *cfdata;
   
   cfdata = E_NEW(E_Config_Dialog_Data, 1);
   _fill_data(cfdata, cfd->data);
   return cfdata;
}

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));
   E_FREE(cfdata->file);
   E_FREE(cfdata->size);
   E_FREE(cfdata->mod_date);
   E_FREE(cfdata->mime);
   E_FREE(cfdata->owner);
   E_FREE(cfdata->link);
   E_FREE(cfdata->plink);
   E_FREE(cfdata->icon);
   free(cfdata);
}

/**--APPLY--**/
static int
_basic_apply_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata)
{
   char buf[4096];
   int fperm = 0;
   
   snprintf(buf, sizeof(buf), "%s/%s", 
	    e_fm2_real_path_get(cfdata->fi->fm), cfdata->fi->file);
   if (((cfdata->fi->statinfo.st_mode & S_IRUSR) && (cfdata->owner_read)) ||
       ((!(cfdata->fi->statinfo.st_mode & S_IRUSR)) && (!cfdata->owner_read)))
     fperm = 1;
   if (((cfdata->fi->statinfo.st_mode & S_IWUSR) && (cfdata->owner_write)) ||
       ((!(cfdata->fi->statinfo.st_mode & S_IWUSR)) && (!cfdata->owner_write)))
     fperm = 1;
   if (((cfdata->fi->statinfo.st_mode & S_IROTH) && (cfdata->others_read)) ||
       ((!(cfdata->fi->statinfo.st_mode & S_IROTH)) && (!cfdata->others_read)))
     fperm = 1;
   if (((cfdata->fi->statinfo.st_mode & S_IWOTH) && (cfdata->others_write)) ||
       ((!(cfdata->fi->statinfo.st_mode & S_IWOTH)) && (!cfdata->others_write)))
     fperm = 1;
   if (fperm)
     {
	mode_t pmode;
	
	pmode = cfdata->fi->statinfo.st_mode;
	if (cfdata->owner_read) cfdata->fi->statinfo.st_mode |= S_IRUSR;
	else cfdata->fi->statinfo.st_mode &= ~S_IRUSR;
	if (cfdata->owner_write) cfdata->fi->statinfo.st_mode |= S_IWUSR;
{'fraction_non_alphanumeric': 0.14056619211258387, 'fraction_numerical': 0.005400098183603338, 'mean_word_length': 3.772745021475986, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 203, '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': '4968897', 'n_tokens_mistral': 4809, 'n_tokens_neox': 4677, 'n_words': 987}