prefs_example_01.c
//Compile with:
//gcc -o prefs_example_01 prefs_example_01.c -g `pkg-config --cflags --libs elementary`
#include <Elementary.h>
//testing ui reflection on prefs data changes
static Eina_Bool
_elm_prefs_data_change(void *data)
{
Evas_Object *notify = data;
Elm_Prefs_Data *prefs_data;
Elm_Prefs_Item_Type type;
Eina_Value value;
prefs_data = evas_object_data_get(notify, "prefs_data");
if (elm_prefs_data_value_get(prefs_data, "main:universe", &type, &value))
{
eina_value_set(&value, 42);
elm_prefs_data_value_set(prefs_data, "main:universe", type, &value);
}
if (elm_prefs_data_value_get(prefs_data, "main:text", &type, &value))
{
eina_value_set(&value, "This is a text field (:");
elm_prefs_data_value_set(prefs_data, "main:text", type, &value);
}
evas_object_show(notify);
return ECORE_CALLBACK_RENEW;
}
static void
_page_saved_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
const char *page = event_info;
printf("page %s was saved!\n", page);
}
static void
_page_loaded_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
const char *page = event_info;
printf("page %s was loaded!\n", page);
}
static void
_item_changed_cb(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event_info)
{
const char *item = event_info;
printf("item %s was changed!\n", item);
}
EAPI_MAIN int
elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
Evas_Object *win, *prefs, *notify, *label;
Elm_Prefs_Data *prefs_data;
win = elm_win_util_standard_add("prefs", "Prefs Example 01");
elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
elm_win_autodel_set(win, EINA_TRUE);
prefs = elm_prefs_add(win);
evas_object_size_hint_weight_set(prefs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
elm_win_resize_object_add(win, prefs);
evas_object_show(prefs);
evas_object_smart_callback_add(prefs, "page,saved", _page_saved_cb, NULL);
evas_object_smart_callback_add(prefs, "page,loaded", _page_loaded_cb, NULL);
evas_object_smart_callback_add(prefs, "item,changed", _item_changed_cb, win);
elm_prefs_autosave_set(prefs, EINA_TRUE);
prefs_data = elm_prefs_data_new("./prefs_example_01.cfg", NULL,
EET_FILE_MODE_READ_WRITE);
elm_prefs_file_set(prefs, "prefs_example_01.epb", NULL);
elm_prefs_data_set(prefs, prefs_data);
label = elm_label_add(win);
elm_object_text_set(label, "Setting Values Programmatically");
evas_object_size_hint_align_set(label, 0.5, 0.5);
notify = elm_notify_add(win);
elm_notify_align_set(notify, 0.5, 1);
elm_notify_timeout_set(notify, 2);
elm_object_content_set(notify, label);
evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_show(notify);
evas_object_data_set(notify, "prefs_data", prefs_data);
evas_object_resize(win, 320, 320);
evas_object_show(win);
ecore_timer_add(5.0, _elm_prefs_data_change, notify);
elm_run();
elm_prefs_data_unref(prefs_data);
return 0;
}
ELM_MAIN()
EVAS_HINT_EXPAND
#define EVAS_HINT_EXPAND
Use with evas_object_size_hint_weight_set(), evas_object_size_hint_weight_get(), evas_object_size_hin...
Definition: Evas_Common.h:297
ECORE_CALLBACK_RENEW
#define ECORE_CALLBACK_RENEW
Return value to keep a callback.
Definition: Ecore_Common.h:153
ecore_timer_add
Ecore_Timer * ecore_timer_add(double in, Ecore_Task_Cb func, const void *data)
Creates a timer to call the given function in the given period of time.
Definition: ecore_timer.c:189
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_UNUSED
#define EINA_UNUSED
Used to indicate that a function parameter is purposely unused.
Definition: eina_types.h:339
eina_value_set
static Eina_Bool eina_value_set(Eina_Value *value,...)
Sets the generic value.
ELM_MAIN
#define ELM_MAIN()
macro to be used after the elm_main() function
Definition: elm_general.h:556
elm_policy_set
Eina_Bool elm_policy_set(unsigned int policy, int value)
Set a new policy's value (for a given policy group/identifier).
Definition: elm_main.c:1380
elm_run
void elm_run(void)
Run Elementary's main loop.
Definition: elm_main.c:1357
ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
@ ELM_POLICY_QUIT_LAST_WINDOW_CLOSED
quit when the application's last window is closed
Definition: elm_general.h:248
ELM_POLICY_QUIT
@ ELM_POLICY_QUIT
under which circumstances the application should quit automatically.
Definition: elm_general.h:227
elm_label_add
Evas_Object * elm_label_add(Evas_Object *parent)
Add a new label to the parent.
Definition: elm_label.c:421
elm_notify_add
Evas_Object * elm_notify_add(Evas_Object *parent)
Add a new notify to the parent.
Definition: elm_notify.c:478
elm_notify_align_set
void elm_notify_align_set(Elm_Notify *obj, double horizontal, double vertical)
Set the alignment of the notify object.
Definition: elm_notify_eo.legacy.c:3
elm_notify_timeout_set
void elm_notify_timeout_set(Elm_Notify *obj, double timeout)
Set the time interval after which the notify window is going to be hidden.
Definition: elm_notify_eo.legacy.c:27
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_add
Evas_Object * elm_prefs_add(Evas_Object *parent)
Add a new prefs widget.
Definition: elm_prefs.c:478
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_Item_Type
Elm_Prefs_Item_Type
Elm Prefs item types.
Definition: elm_prefs_data.h:51
Elm_Prefs_Data
struct _Elm_Prefs_Data Elm_Prefs_Data
An Elm Prefs Data handle.
Definition: elm_prefs_data.h:89
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_file_set
Eina_Bool elm_prefs_file_set(Eo *obj, const char *file, const char *page)
Set file and page to populate a given prefs widget's interface.
Definition: elm_prefs.c:1794
elm_win_resize_object_add
void elm_win_resize_object_add(Eo *obj, Evas_Object *subobj)
Add subobj as a resize object of window obj.
Definition: efl_ui_win.c:8992
elm_win_autodel_set
void elm_win_autodel_set(Eo *obj, Eina_Bool autodel)
Set the window's autodel state.
Definition: efl_ui_win.c:6189
elm_win_util_standard_add
Evas_Object * elm_win_util_standard_add(const char *name, const char *title)
Adds a window object with standard setup.
Definition: efl_ui_win.c:9576
evas_object_show
EVAS_API void evas_object_show(Evas_Object *eo_obj)
Makes the given Evas object visible.
Definition: evas_object_main.c:1814
evas_object_data_get
EVAS_API void * evas_object_data_get(const Evas_Object *obj, const char *key)
Return an attached data pointer on an Evas object by its given string key.
Definition: evas_data.c:12
evas_object_data_set
EVAS_API void evas_object_data_set(Evas_Object *eo_obj, const char *key, const void *data)
Set an attached data pointer to an object with a given string key.
Definition: evas_data.c:5
evas_object_size_hint_weight_set
EVAS_API void evas_object_size_hint_weight_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's weight.
Definition: evas_object_main.c:2638
Evas_Object
Efl_Canvas_Object Evas_Object
An Evas Object handle.
Definition: Evas_Common.h:185
evas_object_size_hint_align_set
EVAS_API void evas_object_size_hint_align_set(Evas_Object *obj, double x, double y)
Sets the hints for an object's alignment.
Definition: evas_object_main.c:2650
evas_object_resize
EVAS_API void evas_object_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
Changes the size of the given Evas object.
Definition: evas_object_main.c:1236
evas_object_smart_callback_add
EVAS_API void evas_object_smart_callback_add(Evas_Object *eo_obj, const char *event, Evas_Smart_Cb func, const void *data)
Add (register) a callback function to the smart event specified by event on the smart object obj.
Definition: evas_object_smart.c:1040
_Eina_Value
defines the contents of a value
Definition: eina_value.h:662