prefs_data_example.c
//Compile with:
//gcc -o prefs_data_example prefs_data_example.c -g `pkg-config --cflags --libs elementary`
#include <Elementary.h>
static void
_item_changed_cb(void *cb_data,
Elm_Prefs_Data_Event_Type type,
Elm_Prefs_Data *data,
void *event_info)
{
Elm_Prefs_Data_Event_Changed *evt = event_info;
Eina_Bool ok;
char *str = eina_value_to_string(evt->value);
printf("item %s had its value changed to %s\n", evt->key, str);
free(str);
ok = elm_prefs_data_event_callback_del(data, type, _item_changed_cb, NULL);
printf("elm_prefs_data_event_callback_del(): %s\n", ok ? "ok" : "fail");
}
int
elm_main(int argc, char **argv)
{
Elm_Prefs_Data *prefs_data;
Eina_Value value;
Eina_Bool ok;
int version;
char *str;
prefs_data = elm_prefs_data_new("./test", NULL, EET_FILE_MODE_READ_WRITE);
printf("elm_prefs_data_new(): %s\n", prefs_data ? "ok" : "fail");
elm_prefs_data_autosave_set(prefs_data, EINA_TRUE);
ok = elm_prefs_data_autosave_get(prefs_data);
printf("elm_prefs_data_autosave_get() returns: %s\n", ok ? "yes" : "no");
eina_value_setup(&value, EINA_VALUE_TYPE_INT);
eina_value_set(&value, 50);
ok = elm_prefs_data_value_set(prefs_data, "position", &value);
printf("elm_prefs_data_value_set(): %s\n", ok ? "ok" : "fail");
str = eina_value_to_string(&value);
printf("value for \'position\' is now %s\n", str);
free(str);
printf("elm_prefs_data_version_get() returns %d\n",
version = elm_prefs_data_version_get(prefs_data));
elm_prefs_data_version_set(prefs_data, ++version);
elm_prefs_data_unref(prefs_data);
prefs_data = elm_prefs_data_new("./test", NULL, EET_FILE_MODE_READ_WRITE);
ok = elm_prefs_data_value_get(prefs_data, "position", &value);
printf("elm_prefs_data_value_get(): %s\n", ok ? "ok" : "fail");
str = eina_value_to_string(&value);
printf("value for \'position\' is %s\n", str);
free(str);
eina_value_set(&value, 3000);
ok = elm_prefs_data_event_callback_add
(prefs_data, ELM_PREFS_DATA_EVENT_ITEM_CHANGED, _item_changed_cb, NULL);
printf("elm_prefs_data_event_callback_add(): %s\n", ok ? "ok" : "fail");
ok = elm_prefs_data_value_set(prefs_data, "position", &value);
printf("elm_prefs_data_value_set(): %s\n", ok ? "ok" : "fail");
str = eina_value_to_string(&value);
printf("value for \'position\' is now %s\n", str);
free(str);
ok = elm_prefs_data_save(prefs_data, NULL, NULL);
printf("elm_prefs_data_save(): %s\n", ok ? "ok" : "fail");
elm_prefs_data_ref(prefs_data);
elm_prefs_data_ref(prefs_data);
printf("elm_prefs_data_version_get() returns %d\n",
version = elm_prefs_data_version_get(prefs_data));
elm_prefs_data_unref(prefs_data);
elm_prefs_data_unref(prefs_data);
elm_prefs_data_unref(prefs_data);
return 0;
}
ELM_MAIN()
EET_FILE_MODE_READ_WRITE
@ EET_FILE_MODE_READ_WRITE
File is for both read and write.
Definition Eet.h:481
EINA_TRUE
#define EINA_TRUE
boolean value TRUE (numerical value 1)
Definition eina_types.h:539
Eina_Bool
unsigned char Eina_Bool
Type to mimic a boolean.
Definition eina_types.h:527
Eina_Value
struct _Eina_Value Eina_Value
Store generic values.
Definition eina_value.h:307
EINA_VALUE_TYPE_INT
EINA_API const Eina_Value_Type * EINA_VALUE_TYPE_INT
manages int type.
Definition eina_value.c:5602
eina_value_to_string
EINA_API char * eina_value_to_string(const Eina_Value *value)
Converts value to string.
Definition eina_value.c:5719
ELM_MAIN
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition elm_general.h:556
elm_prefs_data_ref
Elm_Prefs_Data * elm_prefs_data_ref(Elm_Prefs_Data *prefs_data)
Increment reference count on a given prefs data handle.
Definition elm_prefs_data.c:613
elm_prefs_data_event_callback_add
Eina_Bool elm_prefs_data_event_callback_add(Elm_Prefs_Data *prefs_data, Elm_Prefs_Data_Event_Type type, Elm_Prefs_Data_Event_Cb cb, const void *cb_data)
Register a callback for one of the prefs data events.
Definition elm_prefs_data.c:795
elm_prefs_data_value_get
Eina_Bool elm_prefs_data_value_get(const Elm_Prefs_Data *prefs_data, const char *path, Elm_Prefs_Item_Type *type, Eina_Value *value)
Get one value of a given prefs data handle (by key).
Definition elm_prefs_data.c:748
elm_prefs_data_new
Elm_Prefs_Data * elm_prefs_data_new(const char *data_file, const char *key, Eet_File_Mode mode)
Create a new prefs data handle.
Definition elm_prefs_data.c:329
elm_prefs_data_unref
void elm_prefs_data_unref(Elm_Prefs_Data *prefs_data)
Decrement reference count on a given prefs data handle.
Definition elm_prefs_data.c:649
elm_prefs_data_save
Eina_Bool elm_prefs_data_save(const Elm_Prefs_Data *prefs_data, const char *file, const char *key)
Save, manually, a given elm prefs data handle data back, on the given file and key.
Definition elm_prefs_data.c:894
elm_prefs_data_autosave_set
void elm_prefs_data_autosave_set(Elm_Prefs_Data *prefs_data, Eina_Bool autosave)
Set whether a given elm prefs data handle should save its values back automatically on changes.
Definition elm_prefs_data.c:860
elm_prefs_data_autosave_get
Eina_Bool elm_prefs_data_autosave_get(const Elm_Prefs_Data *prefs_data)
Get whether a given elm prefs data handle is saving its values back automatically on changes.
Definition elm_prefs_data.c:887
elm_prefs_data_value_set
Eina_Bool elm_prefs_data_value_set(Elm_Prefs_Data *prefs_data, const char *path, const Elm_Prefs_Item_Type type, const Eina_Value *value)
Set (or delete) one value of a given prefs data handle.
Definition elm_prefs_data.c:660
elm_prefs_data_version_set
Eina_Bool elm_prefs_data_version_set(Elm_Prefs_Data *prefs_data, unsigned int version)
Set the version field of a given prefs data handle.
Definition elm_prefs_data.c:600
elm_prefs_data_version_get
unsigned int elm_prefs_data_version_get(const Elm_Prefs_Data *prefs_data)
Get the version field of a given prefs data handle.
Definition elm_prefs_data.c:391
Elm_Prefs_Data
struct _Elm_Prefs_Data Elm_Prefs_Data
An Elm Prefs Data handle.
Definition elm_prefs_data.h:89
Elm_Prefs_Data_Event_Type
Elm_Prefs_Data_Event_Type
Types of events a given prefs data handle may issue.
Definition elm_prefs_data.h:76
Elm_Prefs_Data_Event_Changed
struct _Elm_Prefs_Data_Event_Changed Elm_Prefs_Data_Event_Changed
An Elm Prefs ELM_PREFS_DATA_EVENT_ITEM_CHANGED event info data blob.
elm_prefs_data_event_callback_del
Eina_Bool elm_prefs_data_event_callback_del(Elm_Prefs_Data *prefs_data, Elm_Prefs_Data_Event_Type type, Elm_Prefs_Data_Event_Cb cb, const void *cb_data)
Unregister a callback for one of the prefs data events.
Definition elm_prefs_data.c:822
ELM_PREFS_DATA_EVENT_ITEM_CHANGED
@ ELM_PREFS_DATA_EVENT_ITEM_CHANGED
The group of values has been automatically saved (event info is the group's name (key)).
Definition elm_prefs_data.h:78
_Elm_Prefs_Data_Event_Changed::value
const Eina_Value * value
key of the data value which changed
Definition elm_prefs_data.h:107