summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-25 15:23:52 -0300
committerGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-25 16:29:38 -0300
commit2edf0d244bf94afdac08850a5fc5f9e6bd2bbbc1 (patch)
tree244a3d40ffed49dacacd5bb495128ebfc143ae71
parentc533f68b0b960623f85a32ac7992f80c0c380847 (diff)
elm_prefs: Possibility to connect a prefs 'page:item' to a property; Included example.
-rw-r--r--src/examples/Makefile.am3
-rw-r--r--src/examples/prefs_example_04.c80
-rw-r--r--src/examples/prefs_example_04.epc49
-rw-r--r--src/lib/elm_prefs.c47
-rw-r--r--src/lib/elm_prefs.eo11
-rw-r--r--src/lib/elm_prefs.h1
-rw-r--r--src/lib/elm_widget_prefs.h1
7 files changed, 183 insertions, 9 deletions
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 31494a745..5a55dbaab 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -114,6 +114,7 @@ photocam_example_01.c \
114prefs_example_01.c \ 114prefs_example_01.c \
115prefs_example_02.c \ 115prefs_example_02.c \
116prefs_example_03.c \ 116prefs_example_03.c \
117prefs_example_04.c \
117popup_example_01.c \ 118popup_example_01.c \
118popup_example_02.c \ 119popup_example_02.c \
119popup_example_03.c \ 120popup_example_03.c \
@@ -171,6 +172,7 @@ files_DATA += \
171 prefs_example_02.epb \ 172 prefs_example_02.epb \
172 prefs_example_03.epb \ 173 prefs_example_03.epb \
173 prefs_example_03.edj \ 174 prefs_example_03.edj \
175 prefs_example_04.epb \
174 theme_example.edj \ 176 theme_example.edj \
175 layout_example.edj\ 177 layout_example.edj\
176 codegen_example.edj \ 178 codegen_example.edj \
@@ -268,6 +270,7 @@ photocam_example_01 \
268prefs_example_01 \ 270prefs_example_01 \
269prefs_example_02 \ 271prefs_example_02 \
270prefs_example_03 \ 272prefs_example_03 \
273prefs_example_04 \
271popup_example_01 \ 274popup_example_01 \
272popup_example_02 \ 275popup_example_02 \
273popup_example_03 \ 276popup_example_03 \
diff --git a/src/examples/prefs_example_04.c b/src/examples/prefs_example_04.c
new file mode 100644
index 000000000..d64d50f16
--- /dev/null
+++ b/src/examples/prefs_example_04.c
@@ -0,0 +1,80 @@
1//Compile with:
2//gcc -o prefs_example_04 prefs_example_04.c -g `pkg-config --cflags --libs elementary`
3
4#include <Elementary.h>
5#include <Emodel.h>
6#include <Eio.h>
7#include <eio_model.eo.h>
8
9static void
10_page_saved_cb(void *data, Evas_Object *obj, void *event_info)
11{
12 const char *page = event_info;
13
14 printf("page %s was saved!\n", page);
15}
16
17static void
18_page_loaded_cb(void *data, Evas_Object *obj, void *event_info)
19{
20 const char *page = event_info;
21
22 printf("page %s was loaded!\n", page);
23}
24
25static void
26_item_changed_cb(void *data, Evas_Object *obj, void *event_info)
27{
28 const char *item = event_info;
29
30 printf("item %s was changed!\n", item);
31}
32
33static Eina_Bool
34_filter_cb(void *data EINA_UNUSED,
35 Eio_File *handler EINA_UNUSED,
36 const Eina_File_Direct_Info *info)
37{
38 if (info->type == EINA_FILE_DIR &&
39 info->path[info->name_start] != '.')
40 return EINA_TRUE;
41
42 return EINA_FALSE;
43}
44
45EAPI_MAIN int
46elm_main(int argc, char **argv)
47{
48 Evas_Object *win, *prefs, *notify, *label;
49
50 win = elm_win_util_standard_add("prefs", "Prefs Example 04");
51 elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
52 elm_win_autodel_set(win, EINA_TRUE);
53
54 prefs = elm_prefs_add(win);
55 evas_object_size_hint_weight_set(prefs, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
56 elm_win_resize_object_add(win, prefs);
57 evas_object_show(prefs);
58
59 evas_object_smart_callback_add(prefs, "page,saved", _page_saved_cb, NULL);
60 evas_object_smart_callback_add(prefs, "page,loaded", _page_loaded_cb, NULL);
61 evas_object_smart_callback_add(prefs, "item,changed", _item_changed_cb, win);
62
63 Emodel *model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set("."));
64 eo_do(model, eio_model_children_filter_set(_filter_cb, NULL));
65 eo_do(model, emodel_load());
66
67 elm_prefs_file_set(prefs, "prefs_example_04.epb", NULL);
68 eo_do(prefs, elm_obj_prefs_property_connect("filename", "main:filename"),
69 elm_obj_prefs_model_set(model));
70
71 evas_object_resize(win, 320, 320);
72 evas_object_show(win);
73
74 elm_run();
75
76 eo_unref(model);
77
78 return 0;
79}
80ELM_MAIN()
diff --git a/src/examples/prefs_example_04.epc b/src/examples/prefs_example_04.epc
new file mode 100644
index 000000000..30e1a2ef4
--- /dev/null
+++ b/src/examples/prefs_example_04.epc
@@ -0,0 +1,49 @@
1collection
2{
3 page
4 {
5 name: "main";
6 version: 1;
7 title: "Preferences Widget";
8 subtitle: "Example 01";
9 widget: "elm/vertical_box";
10
11 items {
12
13 item {
14 name: "label";
15 type: LABEL;
16 label: "Filename";
17 }
18
19 item {
20 name: "text";
21 type: TEXT;
22 editable: 1;
23
24 text {
25 placeholder: "test.txt";
26 default: "test.txt";
27 deny: "/";
28 }
29 }
30
31 item {
32 name: "sep";
33 type: SEPARATOR;
34 }
35
36 item {
37 name: "save";
38 type: SAVE;
39 label: "Save";
40 }
41
42 item {
43 name: "reset";
44 type: RESET;
45 label: "Reset";
46 }
47 }
48 }
49}
diff --git a/src/lib/elm_prefs.c b/src/lib/elm_prefs.c
index be091d339..55c04f3db 100644
--- a/src/lib/elm_prefs.c
+++ b/src/lib/elm_prefs.c
@@ -525,6 +525,7 @@ _elm_prefs_evas_object_smart_del(Eo *obj, Elm_Prefs_Data *sd)
525 _root_node_free(sd); 525 _root_node_free(sd);
526 } 526 }
527 527
528 eina_hash_free(sd->prop_con);
528 if (sd->prefs_data) elm_prefs_data_unref(sd->prefs_data); 529 if (sd->prefs_data) elm_prefs_data_unref(sd->prefs_data);
529 if (sd->model) eo_unref(sd->model); 530 if (sd->model) eo_unref(sd->model);
530 531
@@ -575,13 +576,14 @@ elm_prefs_add(Evas_Object *parent)
575} 576}
576 577
577EOLIAN static void 578EOLIAN static void
578_elm_prefs_eo_base_constructor(Eo *obj, Elm_Prefs_Data *_pd EINA_UNUSED) 579_elm_prefs_eo_base_constructor(Eo *obj, Elm_Prefs_Data *pd)
579{ 580{
580 eo_do_super(obj, MY_CLASS, eo_constructor()); 581 eo_do_super(obj, MY_CLASS, eo_constructor());
581 eo_do(obj, 582 eo_do(obj,
582 evas_obj_type_set(MY_CLASS_NAME_LEGACY), 583 evas_obj_type_set(MY_CLASS_NAME_LEGACY),
583 evas_obj_smart_callbacks_descriptions_set(_elm_prefs_smart_callbacks), 584 evas_obj_smart_callbacks_descriptions_set(_elm_prefs_smart_callbacks),
584 elm_interface_atspi_accessible_role_set(ELM_ATSPI_ROLE_REDUNDANT_OBJECT)); 585 elm_interface_atspi_accessible_role_set(ELM_ATSPI_ROLE_REDUNDANT_OBJECT));
586 pd->prop_con = eina_hash_string_superfast_new(free);
585} 587}
586 588
587static Eina_Bool 589static Eina_Bool
@@ -1239,8 +1241,11 @@ _elm_prefs_data_set(Eo *obj, Elm_Prefs_Data *sd, Elm_Prefs_Data *prefs_data)
1239{ 1241{
1240 if (!sd->root) return EINA_FALSE; 1242 if (!sd->root) return EINA_FALSE;
1241 1243
1242 Eina_Bool ret = eo_do_ret(obj, ret, elm_obj_prefs_model_set(NULL)); 1244 if (sd->model)
1243 if (!ret) return EINA_FALSE; 1245 {
1246 Eina_Bool ret = eo_do_ret(obj, ret, elm_obj_prefs_model_set(NULL));
1247 if (!ret) return EINA_FALSE;
1248 }
1244 1249
1245 if (prefs_data && !_elm_prefs_data_cbs_add(obj, prefs_data)) 1250 if (prefs_data && !_elm_prefs_data_cbs_add(obj, prefs_data))
1246 return EINA_FALSE; 1251 return EINA_FALSE;
@@ -1287,8 +1292,11 @@ _elm_prefs_model_set(Eo *obj, Elm_Prefs_Data *sd, Emodel *model)
1287{ 1292{
1288 if (!sd->root) return EINA_FALSE; 1293 if (!sd->root) return EINA_FALSE;
1289 1294
1290 Eina_Bool ret = eo_do_ret(obj, ret, elm_obj_prefs_data_set(NULL)); 1295 if (sd->prefs_data)
1291 if (!ret) return EINA_FALSE; 1296 {
1297 Eina_Bool ret = eo_do_ret(obj, ret, elm_obj_prefs_data_set(NULL));
1298 if (!ret) return EINA_FALSE;
1299 }
1292 1300
1293 if (model && !_elm_prefs_model_cbs_add(obj, model)) 1301 if (model && !_elm_prefs_model_cbs_add(obj, model))
1294 return EINA_FALSE; 1302 return EINA_FALSE;
@@ -1991,14 +1999,18 @@ elm_prefs_file_get(const Eo *obj, const char **file, const char **page)
1991static Eina_Bool 1999static Eina_Bool
1992_elm_prefs_value_get(Elm_Prefs_Data *sd, const char *key, Eina_Value *value) 2000_elm_prefs_value_get(Elm_Prefs_Data *sd, const char *key, Eina_Value *value)
1993{ 2001{
2002 const char *property = eina_hash_find(sd->prop_con, key);
2003 if (!property)
2004 property = key;
2005
1994 if (sd->prefs_data) 2006 if (sd->prefs_data)
1995 return elm_prefs_data_value_get(sd->prefs_data, key, NULL, value); 2007 return elm_prefs_data_value_get(sd->prefs_data, property, NULL, value);
1996 2008
1997 if (sd->model) 2009 if (sd->model)
1998 { 2010 {
1999 Emodel_Load_Status status; 2011 Emodel_Load_Status status;
2000 const Eina_Value *prop_value; 2012 const Eina_Value *prop_value;
2001 eo_do(sd->model, status = emodel_property_get(key, &prop_value)); 2013 eo_do(sd->model, status = emodel_property_get(property, &prop_value));
2002 if (EMODEL_LOAD_STATUS_ERROR == status) 2014 if (EMODEL_LOAD_STATUS_ERROR == status)
2003 return EINA_FALSE; 2015 return EINA_FALSE;
2004 2016
@@ -2014,17 +2026,21 @@ _elm_prefs_value_set(Elm_Prefs_Data *sd,
2014 const Elm_Prefs_Item_Type type, 2026 const Elm_Prefs_Item_Type type,
2015 const Eina_Value *value) 2027 const Eina_Value *value)
2016{ 2028{
2029 const char *property = eina_hash_find(sd->prop_con, key);
2030 if (!property)
2031 property = key;
2032
2017 sd->changing_from_ui = EINA_TRUE; 2033 sd->changing_from_ui = EINA_TRUE;
2018 2034
2019 Eina_Bool result = EINA_FALSE; 2035 Eina_Bool result = EINA_FALSE;
2020 if (sd->prefs_data) 2036 if (sd->prefs_data)
2021 result = elm_prefs_data_value_set(sd->prefs_data, key, type, value); 2037 result = elm_prefs_data_value_set(sd->prefs_data, property, type, value);
2022 else 2038 else
2023 if (sd->model) 2039 if (sd->model)
2024 { 2040 {
2025 // TODO: Convert the value 2041 // TODO: Convert the value
2026 Emodel_Load_Status status; 2042 Emodel_Load_Status status;
2027 eo_do(sd->model, status = emodel_property_set(key, value)); 2043 eo_do(sd->model, status = emodel_property_set(property, value));
2028 result = EMODEL_LOAD_STATUS_ERROR != status; 2044 result = EMODEL_LOAD_STATUS_ERROR != status;
2029 // TODO: The property changed event could be delayed for Emodel 2045 // TODO: The property changed event could be delayed for Emodel
2030 } 2046 }
@@ -2033,4 +2049,17 @@ _elm_prefs_value_set(Elm_Prefs_Data *sd,
2033 return result; 2049 return result;
2034} 2050}
2035 2051
2052static void
2053_elm_prefs_property_connect(Eo *obj EINA_UNUSED,
2054 Elm_Prefs_Data *sd,
2055 const char *property,
2056 const char *part)
2057{
2058 EINA_SAFETY_ON_NULL_RETURN(sd);
2059 EINA_SAFETY_ON_NULL_RETURN(property);
2060 EINA_SAFETY_ON_NULL_RETURN(part);
2061
2062 free(eina_hash_set(sd->prop_con, part, strdup(property)));
2063}
2064
2036#include "elm_prefs.eo.c" 2065#include "elm_prefs.eo.c"
diff --git a/src/lib/elm_prefs.eo b/src/lib/elm_prefs.eo
index 8036fab08..27a53e63a 100644
--- a/src/lib/elm_prefs.eo
+++ b/src/lib/elm_prefs.eo
@@ -138,6 +138,17 @@ class Elm_Prefs (Elm_Widget, Efl.File) {
138 } 138 }
139 } 139 }
140 methods { 140 methods {
141 property_connect {
142 /*@ Connect property
143 *
144 * @def elm_prefs_property_connect
145 * @since 1.13
146 */
147 params {
148 @in const(char)* property; /*@ Property name */
149 @in const(char)* part; /*@ Prefs page:item layout part */
150 }
151 }
141 reset { 152 reset {
142 /*@ 153 /*@
143 Reset the values of a given prefs widget to a previous state. 154 Reset the values of a given prefs widget to a previous state.
diff --git a/src/lib/elm_prefs.h b/src/lib/elm_prefs.h
index 466065850..a43f73f41 100644
--- a/src/lib/elm_prefs.h
+++ b/src/lib/elm_prefs.h
@@ -71,6 +71,7 @@
71 * @li @ref prefs_example_01 71 * @li @ref prefs_example_01
72 * @li @ref prefs_example_02 72 * @li @ref prefs_example_02
73 * @li @ref prefs_example_03 73 * @li @ref prefs_example_03
74 * @li @ref prefs_example_04
74 */ 75 */
75 76
76#include "elm_prefs_common.h" 77#include "elm_prefs_common.h"
diff --git a/src/lib/elm_widget_prefs.h b/src/lib/elm_widget_prefs.h
index d384c229a..d902b3143 100644
--- a/src/lib/elm_widget_prefs.h
+++ b/src/lib/elm_widget_prefs.h
@@ -75,6 +75,7 @@ struct _Elm_Prefs_Data
75{ 75{
76 Elm_Prefs_Page_Node *root; 76 Elm_Prefs_Page_Node *root;
77 77
78 Eina_Hash *prop_con;
78 Elm_Prefs_Data *prefs_data; 79 Elm_Prefs_Data *prefs_data;
79 Emodel *model; 80 Emodel *model;
80 const char *file; 81 const char *file;