Morten Nilsen's latest patches for ecore_config argb etc

SVN revision: 19655
This commit is contained in:
handyande 2006-01-08 14:57:14 +00:00 committed by handyande
parent 69c939d1a4
commit 7c24ebf4e0
5 changed files with 111 additions and 214 deletions

View File

@ -14,15 +14,17 @@
long int_val;
float flt_val;
int r_val;
int g_val;
int b_val;
char *str_val;
char *rgb_val;
char *thm_val;
void set_defaults (void) {
ecore_config_int_default(INT_VAL_KEY, 0);
ecore_config_float_default(FLT_VAL_KEY, 0.0);
ecore_config_string_default(STR_VAL_KEY, "test1");
ecore_config_argb_default(RGB_VAL_KEY, "#FF000000");
ecore_config_argb_default(RGB_VAL_KEY, 255, 0, 0, 0);
ecore_config_theme_default(THM_VAL_KEY, "default");
}
@ -35,7 +37,7 @@ void get_settings (void) {
int_val = ecore_config_int_get(INT_VAL_KEY);
flt_val = ecore_config_float_get(FLT_VAL_KEY);
str_val = ecore_config_string_get(STR_VAL_KEY);
rgb_val = ecore_config_argbstr_get(RGB_VAL_KEY);
ecore_config_argb_get(RGB_VAL_KEY, NULL, &r_val, &g_val, &b_val);
thm_val = ecore_config_theme_get(THM_VAL_KEY);
}
@ -47,15 +49,11 @@ void change_settings(void) {
} else {
str_val[4] += 1;
}
if('9' == rgb_val[3]) {
rgb_val[3] = '0';
rgb_val[5] = '0';
rgb_val[7] = '0';
} else {
rgb_val[3] += 1;
rgb_val[5] += 1;
rgb_val[7] += 1;
}
r_val = (r_val + 1) % 256;
g_val = (g_val + 1) % 256;
b_val = (b_val + 1) % 256;
if(!strcmp(thm_val, "default")) {
if(thm_val) free(thm_val);
thm_val = strdup("winter");
@ -69,7 +67,7 @@ void save_settings (void) {
ecore_config_int_set(INT_VAL_KEY, int_val);
ecore_config_float_set(FLT_VAL_KEY, flt_val);
ecore_config_string_set(STR_VAL_KEY, str_val);
ecore_config_argb_set(RGB_VAL_KEY, rgb_val);
ecore_config_argb_set(RGB_VAL_KEY, 255, r_val, g_val, b_val);
ecore_config_theme_set(THM_VAL_KEY, thm_val);
ecore_config_save();
}
@ -78,7 +76,7 @@ void dump_settings (void) {
printf(" Int Value: %li\n", int_val);
printf(" Float Value: %f\n", flt_val);
printf(" String Value: %s\n", str_val);
printf(" RGB Value: %s\n", rgb_val);
printf(" RGB Value: %i %i %i\n", r_val, g_val, b_val);
printf(" Theme Value: %s\n", thm_val);
}
@ -92,7 +90,6 @@ int main (int argc, char **argv) {
dump_settings();
save_settings();
if(str_val) free(str_val);
if(rgb_val) free(rgb_val);
if(thm_val) free(thm_val);
ecore_config_shutdown();
return 0;

View File

@ -137,14 +137,10 @@ extern "C"
EAPI Ecore_Config_Prop *ecore_config_get(const char *key);
EAPI const char *ecore_config_type_get(const Ecore_Config_Prop *e);
EAPI int ecore_config_boolean_get(const char *key);
EAPI void *ecore_config_data_get(const char *key);
EAPI char *ecore_config_string_get(const char *key);
EAPI long ecore_config_int_get(const char *key);
EAPI int ecore_config_rgb_get(const char *key, int *r, int *g,
int *b);
EAPI int ecore_config_argb_get(const char *key, int *a, int *r,
int *g, int *b);
EAPI char *ecore_config_rgbstr_get(const char *key);
EAPI char *ecore_config_argbstr_get(const char *key);
EAPI float ecore_config_float_get(const char *key);
EAPI char *ecore_config_theme_get(const char *key);
@ -161,9 +157,8 @@ extern "C"
EAPI int ecore_config_boolean_set(const char *key, int val);
EAPI int ecore_config_string_set(const char *key, char *val);
EAPI int ecore_config_int_set(const char *key, int val);
EAPI char *ecore_config_rgb_to_argb(char *rgb);
EAPI int ecore_config_rgb_set(const char *key, char *val);
EAPI int ecore_config_argb_set(const char *key, char *val);
EAPI int ecore_config_argb_set(const char *key, int a, int r, int g, int b);
EAPI int ecore_config_argbstr_set(const char *key, char *val);
EAPI int ecore_config_float_set(const char *key, float val);
EAPI int ecore_config_theme_set(const char *key, char *val);
EAPI int ecore_config_theme_preview_group_set(const char *key,
@ -183,8 +178,8 @@ extern "C"
EAPI int ecore_config_float_default_bound(const char *key,
float val, float lo,
float hi, float step);
EAPI int ecore_config_rgb_default(const char *key, char *val);
EAPI int ecore_config_argb_default(const char *keym, char *val);
EAPI int ecore_config_argb_default(const char *key, int a, int r, int g, int b);
EAPI int ecore_config_argbstr_default(const char *key, char *val);
EAPI int ecore_config_theme_default(const char *key, char *val);
EAPI int ecore_config_listen(const char *name, const char *key,
@ -290,9 +285,6 @@ extern "C"
char short_opt,
char *long_opt,
char *desc);
EAPI int ecore_config_rgb_create(const char *key, char *val,
char short_opt, char *long_opt,
char *desc);
EAPI int ecore_config_argb_create(const char *key, char *val,
char short_opt, char *long_opt,
char *desc);

View File

@ -27,6 +27,9 @@ int __ecore_config_system_init = 0;
static int _ecore_config_system_init_no_load(void);
static int _ecore_config_system_load(void);
static inline void *__ecore_argb_to_long(int a, int r, int g, int b, long *v);
static inline void *__ecore_argbstr_to_long(char *argb, long *v);
static const char *_ecore_config_type[] =
{ "undefined", "integer", "float", "string", "colour", "theme", "boolean" };
@ -139,22 +142,6 @@ ecore_config_type_get(const Ecore_Config_Prop * e)
return "not found";
}
/**
* Obtains the data pointed to by the specified property.
* @param key The property key.
* @return Data pointer used by the property.
* @ingroup Ecore_Config_Get_Group
*/
EAPI void *
ecore_config_data_get(const char *key)
{
Ecore_Config_Prop *e;
e = ecore_config_get(key);
return (e ? ((e->type == ECORE_CONFIG_STR) ? ((void *)&e->ptr) : ((void *)&e->val))
: NULL);
}
/**
* Returns the specified property as a string.
* @param key The property key.
@ -231,23 +218,6 @@ _ecore_config_float_get(Ecore_Config_Prop *e)
return (e && (e->type == ECORE_CONFIG_FLT)) ? ((float)e->val / ECORE_CONFIG_FLOAT_PRECISION) : 0.0;
}
/**
* Finds the red, green and blue values of a color property.
* @param key The property key.
* @param r A pointer to an integer to store the red value into.
* @param g A pointer to an integer to store the green value into.
* @param b A pointer to an integer to store the blue value into.
* @return @c ECORE_CONFIG_ERR_SUCC on success. @c ECORE_CONFIG_ERR_FAIL
* otherwise.
* @ingroup Ecore_Config_Get_Group
* @deprecated
*/
EAPI int
ecore_config_rgb_get(const char *key, int *r, int *g, int *b)
{
return _ecore_config_argb_get( ecore_config_get(key), NULL, r, g, b);
}
/**
* Finds the alpha, red, green and blue values of a color property.
* @param key The property key.
@ -272,31 +242,13 @@ _ecore_config_argb_get(Ecore_Config_Prop *e, int *a, int *r, int *g, int *b)
{
if(a) *a = (e->val >> 24) & 0xff;
if(r) *r = (e->val >> 16) & 0xff;
if(g) *g = (e->val >> 8) & 0xff;
if(b) *b = e->val & 0xff;
if(g) *g = (e->val >> 8) & 0xff;
if(b) *b = e->val & 0xff;
return ECORE_CONFIG_ERR_SUCC;
}
return ECORE_CONFIG_ERR_FAIL;
}
/**
* Returns a color property as a string of hexadecimal characters.
* @param key The property key.
* @return A string of hexadecimal characters in the format #rrggbb.
* @ingroup Ecore_Config_Get_Group
* @deprecated
*/
EAPI char *
ecore_config_rgbstr_get(const char *key)
{
char *argb, *rgb;
argb = ecore_config_argbstr_get(key);
rgb = argb + 2;
*rgb = '#';
return rgb;
}
/**
* Returns a color property as a string of hexadecimal characters.
* @param key The property key.
@ -492,79 +444,44 @@ ecore_config_type_guess(const char *key, const char *val)
static int
ecore_config_typed_val(Ecore_Config_Prop * e, const void *val, int type)
{
char *l;
long v;
int *i;
float *f;
l = NULL;
v = 0;
if (!e)
return ECORE_CONFIG_ERR_NODATA;
if (!(val))
if (!(val) && type != ECORE_CONFIG_NIL)
e->ptr = NULL;
else
{
if (type == ECORE_CONFIG_INT)
{
i = (int *)val;
e->val = (long)*i;
e->type = ECORE_CONFIG_INT;
}
else if (type == ECORE_CONFIG_BLN )
{
i = (int *)val;
e->val = (long)*i;
e->type = ECORE_CONFIG_BLN;
}
if (type == ECORE_CONFIG_INT || type == ECORE_CONFIG_BLN)
{
e->val = (long) *((int *)val);
e->type = type;
}
else if (type == ECORE_CONFIG_STR || type == ECORE_CONFIG_THM)
{
{
if (!(e->ptr = strdup(val)))
return ECORE_CONFIG_ERR_OOM;
if (e->type == ECORE_CONFIG_NIL)
e->type = type;
}
}
else if (type == ECORE_CONFIG_RGB)
{
if (((char *)val)[0] == '#')
{
if ((v = (long) strtoul(&((char *)val)[1], &l, 16)) < 0)
{
v = 0;
E(0,
"ecore_config_val: key \"%s\" -- hexadecimal value less than zero, bound to zero...\n",
(char *)val);
l = (char *)val;
}
}
else
{
E(0,
"ecore_config_val: key \"%s\" -- value \"%s\" not a valid hexadecimal RGB value?\n",
e->key, (char *)val);
return ECORE_CONFIG_ERR_FAIL;
}
if (*l)
E(0,
"ecore_config_val: key \"%s\" -- value \"%s\" not a valid hexadecimal RGB value?\n",
e->key, (char *)val);
else
{
e->val = v;
e->type = ECORE_CONFIG_RGB;
}
{
e->val = *((long *)val);
e->type = ECORE_CONFIG_RGB;
}
else if (type == ECORE_CONFIG_FLT)
{
f = (float *)val;
e->val = (long)((*f) * ECORE_CONFIG_FLOAT_PRECISION);
e->val = (long) ((*((float *)val)) * ECORE_CONFIG_FLOAT_PRECISION);
e->type = ECORE_CONFIG_FLT;
}
else
{
e->type = ECORE_CONFIG_NIL;
}
ecore_config_bound(e);
e->flags |= ECORE_CONFIG_FLAG_MODIFIED;
e->flags = e->flags & ~ECORE_CONFIG_FLAG_CMDLN;
e->flags &= ~ECORE_CONFIG_FLAG_CMDLN;
return ECORE_CONFIG_ERR_SUCC;
}
return ECORE_CONFIG_ERR_IGNORED;
@ -574,40 +491,39 @@ static int
ecore_config_typed_add(const char *key, const void *val, int type)
{
int error = ECORE_CONFIG_ERR_SUCC;
Ecore_Config_Prop *e;
Ecore_Config_Prop *e = NULL;
Ecore_Config_Bundle *t;
t = __ecore_config_bundle_local;
if (!key)
return ECORE_CONFIG_ERR_NODATA;
if (!(e = malloc(sizeof(Ecore_Config_Prop))))
goto ret;
memset(e, 0, sizeof(Ecore_Config_Prop));
if (!(e->key = strdup(key)))
if (!(e = calloc(1, sizeof(Ecore_Config_Prop))))
{
error = ECORE_CONFIG_ERR_OOM;
goto ret_free_nte;
}
if ((error = ecore_config_typed_val(e, val, type) != ECORE_CONFIG_ERR_SUCC))
goto ret_free_key;
e->next = t ? t->data : NULL;
if (t)
else if (!(e->key = strdup(key)))
{
t->data = e;
error = ECORE_CONFIG_ERR_OOM;
}
else if ((error = ecore_config_typed_val(e, val, type)) == ECORE_CONFIG_ERR_SUCC)
{
if (t)
{
e->next = t->data;
t->data = e;
}
return ECORE_CONFIG_ERR_SUCC;
}
ret_free_key:
free(e->key);
ret_free_nte:
free(e);
ret:
if(e->key)
free(e->key);
if(e)
free(e);
if (error == ECORE_CONFIG_ERR_SUCC)
error = ECORE_CONFIG_ERR_FAIL;
return error;
}
@ -826,35 +742,23 @@ ecore_config_float_set(const char *key, float val)
return ecore_config_typed_set(key, (void *)&val, ECORE_CONFIG_FLT);
}
EAPI char *
ecore_config_rgb_to_argb(char *rgb)
{
char *argb;
argb = malloc(strlen(rgb) + 2);
strncpy(argb, "#ff", 3);
strncat(argb, rgb+1, strlen(rgb - 1));
return argb;
}
/**
* Sets the indicated property to a color value.
* @param key The property key
* @param val Color value in RGB format.
* @param a integer 0..255
* @param r integer 0..255
* @param g integer 0..255
* @param b integer 0..255
*
* @return @c ECORE_CONFIG_ERR_SUCC if the property is set successfully.
* @ingroup Ecore_Config_Set_Group
* @deprecated
*/
EAPI int
ecore_config_rgb_set(const char *key, char *val)
ecore_config_argb_set(const char *key, int a, int r, int g, int b)
{
char *argb;
int ret;
argb = ecore_config_rgb_to_argb(val);
ret = ecore_config_argb_set(key, argb);
free(argb);
return ret;
long v = 0;
return ecore_config_typed_set(key, __ecore_argb_to_long(a,r,g,b, &v), ECORE_CONFIG_RGB);
}
/**
@ -865,9 +769,10 @@ ecore_config_rgb_set(const char *key, char *val)
* @ingroup Ecore_Config_Set_Group
*/
EAPI int
ecore_config_argb_set(const char *key, char *val)
ecore_config_argbstr_set(const char *key, char *val)
{
return ecore_config_typed_set(key, (void *)val, ECORE_CONFIG_RGB);
long v = 0;
return ecore_config_typed_set(key, __ecore_argbstr_to_long(val, &v), ECORE_CONFIG_RGB);
}
/**
@ -1118,21 +1023,19 @@ ecore_config_float_default_bound(const char *key, float val, float low,
* Sets the indicated property to a color value if the property has not yet
* been set.
* @param key The property key.
* @param val Color value in RGB format.
* @param a integer 0..255
* @param r integer 0..255
* @param g integer 0..255
* @param b integer 0..255
* @return @c ECORE_CONFIG_ERR_SUCC if there are no problems.
* @ingroup Ecore_Config_Default_Group
* @deprecated
*/
EAPI int
ecore_config_rgb_default(const char *key, char *val)
ecore_config_argb_default(const char *key, int a, int r, int g, int b)
{
char *argb;
int ret;
argb = ecore_config_rgb_to_argb(val);
ret = ecore_config_argb_default(key, argb);
free(argb);
return ret;
long v = 0;
return ecore_config_typed_default(key, __ecore_argb_to_long(a,r,g,b, &v), ECORE_CONFIG_RGB);
}
/**
@ -1144,9 +1047,10 @@ ecore_config_rgb_default(const char *key, char *val)
* @ingroup Ecore_Config_Default_Group
*/
EAPI int
ecore_config_argb_default(const char *key, char *val)
ecore_config_argbstr_default(const char *key, char *val)
{
return ecore_config_typed_default(key, (void *)val, ECORE_CONFIG_RGB);
long v = 0;
return ecore_config_typed_default(key, __ecore_argbstr_to_long(val, &v), ECORE_CONFIG_RGB);
}
/**
@ -1486,7 +1390,6 @@ ecore_config_init(const char *name)
{
char *path;
Ecore_Config_Prop *list;
Ecore_Config_Bundle *temp;
_ecore_config_system_init_no_load();
__ecore_config_app_name = strdup(name);
@ -1494,12 +1397,11 @@ ecore_config_init(const char *name)
if (!__ecore_config_server_local)
return ECORE_CONFIG_ERR_FAIL;
temp = __ecore_config_bundle_local;
list = __ecore_config_bundle_local->data;
free( __ecore_config_bundle_local );
__ecore_config_bundle_local =
ecore_config_bundle_new(__ecore_config_server_local, "config");
__ecore_config_bundle_local->data = list;
free(temp);
path = ecore_config_theme_default_path_get();
ecore_config_string_default("/e/themes/search_path", path);
@ -1647,3 +1549,33 @@ ecore_config_system_shutdown(void)
return ret;
}
static inline void *
__ecore_argb_to_long(int a, int r, int g, int b, long *v)
{
*v = ((a << 24) & 0xff000000 )
| ((r << 16) & 0xff0000 )
| ((g << 8) & 0xff00 )
| ( b & 0xff );
return (void *)v;
}
static inline void *
__ecore_argbstr_to_long(char *argb, long *v)
{
char *l = NULL;
// convert hexadecimal string #..., #0x..., 0x..., ... to long
if(*argb == '#')
argb++;
*v = (long)strtoul( argb, &l, 16);
if(*l)
{
E(0, "ecore_config_val: value \"%s\" not a valid hexadecimal RGB value?\n", argb);
return NULL;
}
return (void *)v;
}

View File

@ -167,8 +167,10 @@ _ecore_config_db_read(Ecore_Config_DB_File *db, const char *key)
ecore_config_typed_set(key, (void *)&tmp, type);
break;
}
case ECORE_CONFIG_STR:
case ECORE_CONFIG_RGB:
ecore_config_argbstr_set(key, value);
break;
case ECORE_CONFIG_STR:
case ECORE_CONFIG_THM:
ecore_config_typed_set(key, (void *)value, type);
break;

View File

@ -246,32 +246,6 @@ ecore_config_float_create_bound(const char *key, float val, float low,
return ret;
}
/**
* Creates a new color property, if it does not already exist, and sets its
* attributes to those given.
* @param key The property key.
* @param val Default color value of key, as a hexadecimal string.
* @param short_opt Short option used to set the property from command
* line.
* @param long_opt Long option used to set the property from command line.
* @param desc String description of property.
* @return @c ECORE_CONFIG_ERR_SUCC on success.
* @ingroup Ecore_Config_Create_Group
* @deprecated
*/
int
ecore_config_rgb_create(const char *key, char *val, char short_opt,
char *long_opt, char *desc)
{
char *argb;
int ret;
argb = ecore_config_rgb_to_argb(val);
ret = ecore_config_argb_create(key, argb, short_opt, long_opt, desc);
free(argb);
return ret;
}
/**
* Creates a new color property, if it does not already exist, and sets its
* attributes to those given.