Let efreet icon return const

We return a pointer to an internal cache, so no need to do strdup. I we
implement a cache, the pointer will be a return from a mmap'ed file, so
no need to do strdup.

A bit late to do an API break, but must be done.

SVN revision: 54372
This commit is contained in:
Sebastian Dransfeld 2010-11-09 20:15:55 +00:00
parent 2a048b5005
commit 3d1a299e06
11 changed files with 39 additions and 65 deletions

View File

@ -301,10 +301,10 @@ _e_configure_efreet_desktop_update(void)
{
char *s;
char *cfg_cat_name;
char *cfg_cat_icon;
const char *cfg_cat_icon;
char *cfg_cat;
char *cfg_cat_cfg;
char *cfg_icon;
const char *cfg_icon;
char *label;
int cfg_pri;
@ -323,19 +323,14 @@ _e_configure_efreet_desktop_update(void)
if (s) cfg_pri = atoi(s);
cfg_cat_name = eina_hash_find(desktop->x, "X-Enlightenment-Config-Category-Name");
cfg_cat_icon = eina_hash_find(desktop->x, "X-Enlightenment-Config-Category-Icon");
if (cfg_cat_icon)
{
if (cfg_cat_icon[0] == '/')
cfg_cat_icon = strdup(cfg_cat_icon);
else
cfg_cat_icon = efreet_icon_path_find(e_config->icon_theme,
cfg_cat_icon, 64);
}
if ((cfg_cat_icon) && (cfg_cat_icon[0] != '/'))
cfg_cat_icon = efreet_icon_path_find(e_config->icon_theme,
cfg_cat_icon, 64);
}
if (desktop->icon)
{
if (desktop->icon[0] == '/')
cfg_icon = strdup(desktop->icon);
cfg_icon = desktop->icon;
else
cfg_icon = efreet_icon_path_find(e_config->icon_theme,
desktop->icon, 64);
@ -345,7 +340,7 @@ _e_configure_efreet_desktop_update(void)
else label = "???";
if (!cfg_cat_cfg)
{
char *ic;
const char *ic;
snprintf(buf, sizeof(buf), "system/%s", label);
cfg_cat_cfg = buf;
@ -371,8 +366,6 @@ _e_configure_efreet_desktop_update(void)
_e_configure_registry_item_full_add(cfg_cat_cfg, cfg_pri, label,
NULL, cfg_icon,
NULL, NULL, desktop);
if (cfg_icon) free(cfg_icon);
if (cfg_cat_icon) free(cfg_cat_icon);
}
EINA_LIST_FREE(settings_desktops, desktop)
efreet_desktop_free(desktop);

View File

@ -805,7 +805,8 @@ _e_desktop_editor_cb_icon_select(void *data1, void *data2)
Evas_Object *o;
Evas_Coord mw, mh;
E_Desktop_Edit *editor;
char *path = NULL, *icon_path = NULL;
char *path = NULL;
const char *icon_path = NULL;
editor = data2;
cfdata = data1;
@ -825,15 +826,12 @@ _e_desktop_editor_cb_icon_select(void *data1, void *data2)
if (cfdata->icon)
{
if (ecore_file_exists(cfdata->icon))
icon_path = strdup(cfdata->icon);
icon_path = cfdata->icon;
else
icon_path = efreet_icon_path_find(e_config->icon_theme, cfdata->icon, 64);
if (icon_path)
{
path = ecore_file_dir_get(icon_path);
free(icon_path);
}
if (icon_path)
path = ecore_file_dir_get(icon_path);
}
if (path)

View File

@ -2016,7 +2016,7 @@ _e_fm2_icon_mime_size_normalize(const E_Fm2_Icon *ic)
static Evas_Object *
_e_fm2_icon_mime_fdo_get(Evas *evas, const E_Fm2_Icon *ic, const char **type_ret)
{
char *icon;
const char *icon;
unsigned int size;
size = _e_fm2_icon_mime_size_normalize(ic);
@ -2025,7 +2025,6 @@ _e_fm2_icon_mime_fdo_get(Evas *evas, const E_Fm2_Icon *ic, const char **type_ret
{
Evas_Object *o;
o = _e_fm2_icon_explicit_get(evas, ic, icon, type_ret);
free(icon);
return o;
}
return NULL;

View File

@ -153,7 +153,7 @@ EAPI Eina_Bool
e_icon_fdo_icon_set(Evas_Object *obj, const char *icon)
{
E_Smart_Data *sd;
char *path;
const char *path;
if (!icon) return EINA_TRUE;
if (icon[0] == '/') return e_icon_file_set(obj, icon);
@ -173,7 +173,6 @@ e_icon_fdo_icon_set(Evas_Object *obj, const char *icon)
evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
if (sd->preload) evas_object_hide(sd->obj);
evas_object_image_file_set(sd->obj, path, NULL);
free(path);
if (evas_object_image_load_error_get(sd->obj) != EVAS_LOAD_ERROR_NONE)
return EINA_FALSE;
if (sd->preload)
@ -547,7 +546,7 @@ _e_icon_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
sd->h = h;
if (sd->fdo)
{
char *path;
const char *path;
sd->size = MAX(w, h);
path = efreet_icon_path_find(e_config->icon_theme, sd->fdo, sd->size);
@ -556,7 +555,6 @@ _e_icon_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
/* smart code here */
evas_object_image_load_size_set(sd->obj, sd->size, sd->size);
evas_object_image_file_set(sd->obj, path, NULL);
free(path);
if (sd->preload)
{
sd->loading = 1;

View File

@ -372,7 +372,7 @@ e_module_dialog_show(E_Module *m, const char *title, const char *body)
E_Dialog *dia;
E_Border *bd;
char buf[PATH_MAX];
char *icon = NULL;
const char *icon = NULL;
dia = e_dialog_new(e_container_current_get(e_manager_current_get()),
"E", "_module_dialog");
@ -393,9 +393,10 @@ e_module_dialog_show(E_Module *m, const char *title, const char *body)
{
snprintf(buf, sizeof(buf), "%s/%s.edj",
e_module_dir_get(m), desktop->icon);
icon = strdup(buf);
dia->icon_object = e_util_icon_add(buf, e_win_evas_get(dia->win));
}
dia->icon_object = e_util_icon_add(icon, e_win_evas_get(dia->win));
else
dia->icon_object = e_util_icon_add(icon, e_win_evas_get(dia->win));
edje_extern_object_min_size_set(dia->icon_object, 64, 64);
edje_object_part_swallow(dia->bg_object, "e.swallow.icon", dia->icon_object);
evas_object_show(dia->icon_object);
@ -414,7 +415,6 @@ e_module_dialog_show(E_Module *m, const char *title, const char *body)
bd = dia->win->border;
if (!bd) return;
bd->internal_icon = eina_stringshare_add(icon);
free(icon);
}
EAPI void

View File

@ -436,7 +436,7 @@ _e_util_icon_theme_set(Evas_Object *obj, const char *icon)
static int
_e_util_icon_fdo_set(Evas_Object *obj, const char *icon)
{
char *path = NULL;
const char *path = NULL;
unsigned int size;
if ((!icon) || (!icon[0])) return 0;
@ -444,7 +444,6 @@ _e_util_icon_fdo_set(Evas_Object *obj, const char *icon)
path = efreet_icon_path_find(e_config->icon_theme, icon, size);
if (!path) return 0;
e_icon_file_set(obj, path);
E_FREE(path);
return 1;
}
@ -508,7 +507,7 @@ e_util_icon_size_normalize(unsigned int desired)
static int
_e_util_menu_item_fdo_icon_set(E_Menu_Item *mi, const char *icon)
{
char *path = NULL;
const char *path = NULL;
unsigned int size;
if ((!icon) || (!icon[0])) return 0;
@ -516,7 +515,6 @@ _e_util_menu_item_fdo_icon_set(E_Menu_Item *mi, const char *icon)
path = efreet_icon_path_find(e_config->icon_theme, icon, size);
if (!path) return 0;
e_menu_item_icon_file_set(mi, path);
E_FREE(path);
return 1;
}
@ -993,13 +991,12 @@ e_util_icon_theme_icon_add(const char *icon_name, unsigned int size, Evas *evas)
else
{
Evas_Object *obj;
char *path;
const char *path;
path = efreet_icon_path_find(e_config->icon_theme, icon_name, size);
if (path)
{
obj = e_util_icon_add(path, evas);
free(path);
return obj;
}
}
@ -1009,11 +1006,11 @@ e_util_icon_theme_icon_add(const char *icon_name, unsigned int size, Evas *evas)
EAPI void
e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, unsigned int size, E_Menu_Item *mi)
{
char *path = NULL;
const char *path = NULL;
if ((!desktop) || (!desktop->icon)) return;
if (desktop->icon[0] == '/') path = strdup(desktop->icon);
if (desktop->icon[0] == '/') path = desktop->icon;
else path = efreet_icon_path_find(e_config->icon_theme, desktop->icon, size);
if (path)
@ -1030,7 +1027,6 @@ e_util_desktop_menu_item_icon_add(Efreet_Desktop *desktop, unsigned int size, E_
}
else
e_menu_item_icon_file_set(mi, path);
free(path);
}
}

View File

@ -133,13 +133,12 @@ _populate_preview(E_Config_Dialog_Data *cfdata)
for (i = 0; i < sizeof(_icon_previews)/sizeof(_icon_previews[0]); i++)
{
char *path;
const char *path;
if (!(path = efreet_icon_path_find(t, _icon_previews[i], PREVIEW_SIZE)))
continue;
if (e_icon_file_set(cfdata->gui.preview[i], path))
e_icon_fill_inside_set(cfdata->gui.preview[i], EINA_TRUE);
free(path);
}
}
@ -301,7 +300,7 @@ static Evas_Object *
_icon_new(Evas *evas, const char *theme, const char *icon, unsigned int size)
{
Evas_Object *o;
char *path;
const char *path;
if (!(path = efreet_icon_path_find(theme, icon, size))) return NULL;
o = e_icon_add(evas);
@ -313,6 +312,5 @@ _icon_new(Evas *evas, const char *theme, const char *icon, unsigned int size)
o = NULL;
}
free(path);
return o;
}

View File

@ -412,7 +412,7 @@ _evry_icon_theme_set(Evas_Object *obj, const char *icon)
static int
_evry_icon_fdo_set(Evas_Object *obj, const char *icon)
{
char *path = NULL;
const char *path = NULL;
if ((!icon) || (!icon[0])) return 0;
path = efreet_icon_path_find(e_config->icon_theme, icon, 128);
@ -420,7 +420,6 @@ _evry_icon_fdo_set(Evas_Object *obj, const char *icon)
if (!path) return 0;
e_icon_scale_size_set(obj, 128);
e_icon_file_set(obj, path);
E_FREE(path);
return 1;
}
@ -479,7 +478,7 @@ Evas_Object *
evry_icon_mime_get(const char *mime, Evas *e)
{
Evas_Object *o = NULL;
char *icon;
const char *icon;
if (!e_config->icon_theme_overrides)
o = _evry_icon_mime_theme_get(mime, e);
@ -488,10 +487,7 @@ evry_icon_mime_get(const char *mime, Evas *e)
icon = efreet_mime_type_icon_get(mime, e_config->icon_theme, 128);
if (icon)
{
o = e_util_icon_add(icon, e);
free(icon);
}
o = e_util_icon_add(icon, e);
if (o) return o;
return _evry_icon_mime_theme_get(mime, e);

View File

@ -1044,7 +1044,8 @@ _apps_populate(void)
{
// TODO: Needs some efreet love
Efreet_Menu *menu, *entry, *subentry;
char *label, *icon, *plabel;
char *label, *plabel;
const char *icon;
Eina_List *settings_desktops, *system_desktops, *keyboard_desktops;
Eina_List *l, *ll;
@ -1074,7 +1075,8 @@ _apps_populate(void)
Efreet_Desktop *desktop;
if (subentry->type != EFREET_MENU_ENTRY_DESKTOP) continue;
label = icon = NULL;
label = NULL;
icon = NULL;
desktop = subentry->desktop;
if (!desktop) continue;
@ -1085,15 +1087,12 @@ _apps_populate(void)
if ((keyboard_desktops) &&
(eina_list_data_find(keyboard_desktops, desktop))) continue;
if ((desktop) && (desktop->x))
{
icon = eina_hash_find(desktop->x, "X-Application-Screenshot");
if (icon) icon = strdup(icon);
}
if ((desktop) && (desktop->x))
icon = eina_hash_find(desktop->x, "X-Application-Screenshot");
if ((!icon) && (subentry->icon))
{
if (subentry->icon[0] == '/')
icon = strdup(subentry->icon);
icon = subentry->icon;
else
icon = efreet_icon_path_find(e_config->icon_theme,
subentry->icon, 512);
@ -1111,7 +1110,7 @@ _apps_populate(void)
if (!icon) icon = efreet_icon_path_find(e_config->icon_theme,
"hires.jpg", 512);
if (!icon) icon = strdup("DEFAULT");
if (!icon) icon = "DEFAULT";
if (!label) label = strdup("???");
snprintf(buf, sizeof(buf), "%s / %s", plabel, label);
@ -1131,7 +1130,6 @@ _apps_populate(void)
num++;
}
if (label) free(label);
if (icon) free(icon);
}
if (plabel) free(plabel);

View File

@ -210,7 +210,7 @@ wizard_page_show(E_Wizard_Page *pg)
{
if (apps[i].found == 0)
{
char *icon;
const char *icon;
apps[i].found = 1;
icon = efreet_icon_path_find(e_config->icon_theme,
@ -218,7 +218,6 @@ wizard_page_show(E_Wizard_Page *pg)
ck = e_widget_check_icon_add(pg->evas, apps[i].name,
icon, 32 * e_scale, 32 * e_scale,
&(apps[i].found));
if (icon) free(icon);
e_widget_list_object_append(li, ck, 1, 1, 0.0);
evas_object_show(ck);
}

View File

@ -67,7 +67,7 @@ wizard_page_show(E_Wizard_Page *pg __UNUSED__)
for (i = 0, l = desktops; l ; l = l->next, i++)
{
Efreet_Desktop *desk;
char *icon;
const char *icon;
desk = l->data;
icon = NULL;
@ -77,7 +77,6 @@ wizard_page_show(E_Wizard_Page *pg __UNUSED__)
ck = e_widget_check_icon_add(pg->evas, desk->name,
icon, 32 * e_scale, 32 * e_scale,
&(desktops_add[i]));
if (icon) free(icon);
e_widget_list_object_append(li, ck, 1, 1, 0.0);
evas_object_show(ck);
}