tizen 2.4 release
[framework/uifw/elementary.git] / src / examples / prefs_example_02.c
1 //Compile with:
2 //gcc -o prefs_example_02 prefs_example_02.c -g `pkg-config --cflags --libs elementary`
3
4 #include <Elementary.h>
5
6 static Eina_Bool visible = EINA_TRUE;
7 static Eina_Bool editable = EINA_TRUE;
8 static Eina_Bool disabled = EINA_FALSE;
9
10 //testing ui reflection on prefs data changes
11 static Eina_Bool
12 _elm_prefs_items_change(void *data)
13 {
14    Evas_Object *prefs, *notify = data;
15    Elm_Prefs_Data *prefs_data;
16    Elm_Prefs_Item_Type type;
17    Eina_Value value;
18
19    prefs = evas_object_data_get(notify, "prefs");
20    prefs_data = evas_object_data_get(notify, "prefs_data");
21
22    visible = !visible;
23    elm_prefs_item_visible_set(prefs, "main:floatsp", visible);
24
25    disabled = !disabled;
26    elm_prefs_item_disabled_set(prefs, "main:checkb", disabled);
27
28    editable = !editable;
29    elm_prefs_item_editable_set(prefs, "main:text", editable);
30    if (elm_prefs_data_value_get(prefs_data, "main:text", &type, &value))
31      {
32         eina_value_set(&value, editable ? "This is a editable text entry" :
33                        "This is a non-editable text entry");
34         elm_prefs_data_value_set(prefs_data, "main:text", type, &value);
35      }
36
37    evas_object_show(notify);
38
39    return ECORE_CALLBACK_RENEW;
40 }
41
42 static void
43 _action_cb(void *data, Evas_Object *obj, void *event_info)
44 {
45    Evas_Object *notify = data;
46    Elm_Prefs_Data *prefs_data;
47    Elm_Prefs_Item_Type type;
48    Eina_Value value;
49
50    prefs_data = evas_object_data_get(notify, "prefs_data");
51
52    if (elm_prefs_data_value_get(prefs_data, "main:text", &type, &value))
53      {
54         eina_value_set(&value, "Action!");
55         elm_prefs_data_value_set(prefs_data, "main:text", type, &value);
56      }
57 }
58
59 EAPI_MAIN int
60 elm_main(int argc, char **argv)
61 {
62    Evas_Object *win, *prefs, *notify, *label;
63    Elm_Prefs_Data *prefs_data;
64
65    win = elm_win_util_standard_add("prefs", "Prefs Example 02");
66    elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
67    elm_win_autodel_set(win, EINA_TRUE);
68
69    prefs = elm_prefs_add(win);
70    evas_object_size_hint_weight_set(prefs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
71    elm_win_resize_object_add(win, prefs);
72    evas_object_show(prefs);
73
74    elm_prefs_autosave_set(prefs, EINA_TRUE);
75
76    prefs_data = elm_prefs_data_new("./prefs_example_02.cfg", NULL,
77                                    EET_FILE_MODE_READ_WRITE);
78
79    elm_prefs_file_set(prefs, "prefs_example_02.epb", NULL);
80    elm_prefs_data_set(prefs, prefs_data);
81
82    label = elm_label_add(win);
83    elm_object_text_set(label, "Editable, Visible and Disable! Just Saying...");
84    evas_object_size_hint_weight_set(label, 0.0, 0.0);
85    evas_object_size_hint_align_set(label, 0.5, 0.5);
86
87    notify = elm_notify_add(win);
88    elm_notify_align_set(notify, 0.5, 1);
89    elm_notify_timeout_set(notify, 2);
90    elm_object_content_set(notify, label);
91    evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
92    evas_object_show(notify);
93
94    evas_object_data_set(notify, "prefs", prefs);
95    evas_object_data_set(notify, "prefs_data", prefs_data);
96
97    evas_object_smart_callback_add(prefs, "action", _action_cb, notify);
98
99    evas_object_resize(win, 320, 320);
100    evas_object_show(win);
101
102    ecore_timer_add(5.0, _elm_prefs_items_change, notify);
103
104    elm_run();
105
106    elm_prefs_data_unref(prefs_data);
107
108    return 0;
109 }
110 ELM_MAIN()