summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-25 17:30:56 -0300
committerGuilherme Lepsch <lepsch@expertisesolutions.com.br>2015-03-25 17:30:56 -0300
commit69d51703775dc554d782f55bfe26d70b4b7c4107 (patch)
treeb3646cac22e3a8a9b92a555ece14547f2dfaedf1
parent2edf0d244bf94afdac08850a5fc5f9e6bd2bbbc1 (diff)
elm_prefs: Listen to Emodel events.
-rw-r--r--src/examples/prefs_example_04.c4
-rw-r--r--src/examples/prefs_example_04.epc4
-rw-r--r--src/lib/elm_prefs.c87
3 files changed, 60 insertions, 35 deletions
diff --git a/src/examples/prefs_example_04.c b/src/examples/prefs_example_04.c
index d64d50f16..a5ab3f513 100644
--- a/src/examples/prefs_example_04.c
+++ b/src/examples/prefs_example_04.c
@@ -60,12 +60,12 @@ elm_main(int argc, char **argv)
60 evas_object_smart_callback_add(prefs, "page,loaded", _page_loaded_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); 61 evas_object_smart_callback_add(prefs, "item,changed", _item_changed_cb, win);
62 62
63 Emodel *model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set(".")); 63 Emodel *model = eo_add(EIO_MODEL_CLASS, NULL, eio_model_path_set("test"));
64 eo_do(model, eio_model_children_filter_set(_filter_cb, NULL)); 64 eo_do(model, eio_model_children_filter_set(_filter_cb, NULL));
65 eo_do(model, emodel_load()); 65 eo_do(model, emodel_load());
66 66
67 elm_prefs_file_set(prefs, "prefs_example_04.epb", NULL); 67 elm_prefs_file_set(prefs, "prefs_example_04.epb", NULL);
68 eo_do(prefs, elm_obj_prefs_property_connect("filename", "main:filename"), 68 eo_do(prefs, elm_obj_prefs_property_connect("path", "main:text"),
69 elm_obj_prefs_model_set(model)); 69 elm_obj_prefs_model_set(model));
70 70
71 evas_object_resize(win, 320, 320); 71 evas_object_resize(win, 320, 320);
diff --git a/src/examples/prefs_example_04.epc b/src/examples/prefs_example_04.epc
index 30e1a2ef4..881861904 100644
--- a/src/examples/prefs_example_04.epc
+++ b/src/examples/prefs_example_04.epc
@@ -22,8 +22,8 @@ collection
22 editable: 1; 22 editable: 1;
23 23
24 text { 24 text {
25 placeholder: "test.txt"; 25 placeholder: "test";
26 default: "test.txt"; 26 default: "test";
27 deny: "/"; 27 deny: "/";
28 } 28 }
29 } 29 }
diff --git a/src/lib/elm_prefs.c b/src/lib/elm_prefs.c
index 55c04f3db..6b3baefb9 100644
--- a/src/lib/elm_prefs.c
+++ b/src/lib/elm_prefs.c
@@ -47,6 +47,8 @@ static Eina_Bool _prefs_item_widget_value_from_self(Elm_Prefs_Item_Node *, Eina_
47static Eina_Bool _elm_prefs_value_get(Elm_Prefs_Data *, const char *, Eina_Value *); 47static Eina_Bool _elm_prefs_value_get(Elm_Prefs_Data *, const char *, Eina_Value *);
48static Eina_Bool _elm_prefs_value_set(Elm_Prefs_Data *, const char *, const Elm_Prefs_Item_Type, const Eina_Value *); 48static Eina_Bool _elm_prefs_value_set(Elm_Prefs_Data *, const char *, const Elm_Prefs_Item_Type, const Eina_Value *);
49static Eina_Bool _elm_prefs_item_changed(Eo *, Elm_Prefs_Data *, const char *); 49static Eina_Bool _elm_prefs_item_changed(Eo *, Elm_Prefs_Data *, const char *);
50static void _elm_prefs_values_get_user(Elm_Prefs_Data *, Elm_Prefs_Page_Node *);
51static void _elm_prefs_values_fetch(Eo *, Elm_Prefs_Data *, bool);
50 52
51EOLIAN static void 53EOLIAN static void
52_elm_prefs_evas_object_smart_add(Eo *obj, Elm_Prefs_Data *_pd EINA_UNUSED) 54_elm_prefs_evas_object_smart_add(Eo *obj, Elm_Prefs_Data *_pd EINA_UNUSED)
@@ -397,6 +399,8 @@ _elm_prefs_properties_changed(Eo *obj,
397 Elm_Prefs_Data *sd, 399 Elm_Prefs_Data *sd,
398 const Eina_Array *properties) 400 const Eina_Array *properties)
399{ 401{
402 if (!properties) return EINA_FALSE;
403
400 bool changed = EINA_FALSE; 404 bool changed = EINA_FALSE;
401 405
402 size_t i; 406 size_t i;
@@ -430,6 +434,23 @@ _model_property_changed_cb(void *data,
430 return EO_CALLBACK_CONTINUE; 434 return EO_CALLBACK_CONTINUE;
431} 435}
432 436
437static Eina_Bool
438_model_load_status_change_cb(void *data,
439 Eo *model EINA_UNUSED,
440 const Eo_Event_Description *desc EINA_UNUSED,
441 void *event_info)
442{
443 const Emodel_Load *load = (Emodel_Load*)event_info;
444 Eo *obj = (Eo*)data;
445 ELM_PREFS_DATA_GET(obj, sd);
446
447 bool reset_values = !(load->status & EMODEL_LOAD_STATUS_LOADED_PROPERTIES);
448 _elm_prefs_values_fetch(obj, sd, reset_values);
449
450 return EO_CALLBACK_CONTINUE;
451}
452
453
433static void 454static void
434_prefs_data_autosaved_cb(void *cb_data, 455_prefs_data_autosaved_cb(void *cb_data,
435 Elm_Prefs_Data_Event_Type type EINA_UNUSED, 456 Elm_Prefs_Data_Event_Type type EINA_UNUSED,
@@ -490,6 +511,8 @@ _elm_prefs_model_cbs_add(Eo *obj, Emodel *model)
490{ 511{
491 eo_do(model, eo_event_callback_add(EMODEL_EVENT_PROPERTIES_CHANGED, 512 eo_do(model, eo_event_callback_add(EMODEL_EVENT_PROPERTIES_CHANGED,
492 _model_property_changed_cb, obj)); 513 _model_property_changed_cb, obj));
514 eo_do(model, eo_event_callback_add(EMODEL_EVENT_LOAD_STATUS,
515 _model_load_status_change_cb, obj));
493 return EINA_TRUE; 516 return EINA_TRUE;
494} 517}
495 518
@@ -502,6 +525,8 @@ _elm_prefs_model_cbs_del(Eo *obj)
502 525
503 eo_do(sd->model, eo_event_callback_del(EMODEL_EVENT_PROPERTIES_CHANGED, 526 eo_do(sd->model, eo_event_callback_del(EMODEL_EVENT_PROPERTIES_CHANGED,
504 _model_property_changed_cb, obj)); 527 _model_property_changed_cb, obj));
528 eo_do(sd->model, eo_event_callback_del(EMODEL_EVENT_LOAD_STATUS,
529 _model_load_status_change_cb, obj));
505} 530}
506 531
507EOLIAN static void 532EOLIAN static void
@@ -1259,24 +1284,14 @@ _elm_prefs_data_set(Eo *obj, Elm_Prefs_Data *sd, Elm_Prefs_Data *prefs_data)
1259 1284
1260 sd->prefs_data = prefs_data; 1285 sd->prefs_data = prefs_data;
1261 1286
1262 if (!sd->prefs_data) 1287 bool reset_values = true;
1288 if (sd->prefs_data)
1263 { 1289 {
1264 INF("resetting prefs to default values"); 1290 elm_prefs_data_ref(sd->prefs_data);
1265 _elm_prefs_values_get_default(sd->root, EINA_FALSE); 1291 reset_values = false;
1266
1267 goto end;
1268 } 1292 }
1269 1293
1270 elm_prefs_data_ref(sd->prefs_data); 1294 _elm_prefs_values_fetch(obj, sd, reset_values);
1271
1272 sd->values_fetching = EINA_TRUE;
1273 _elm_prefs_values_get_user(sd, sd->root);
1274 sd->values_fetching = EINA_FALSE;
1275
1276end:
1277 evas_object_smart_callback_call
1278 (obj, SIG_PAGE_CHANGED, (char *)sd->root->name);
1279
1280 return EINA_TRUE; 1295 return EINA_TRUE;
1281} 1296}
1282 1297
@@ -1309,24 +1324,16 @@ _elm_prefs_model_set(Eo *obj, Elm_Prefs_Data *sd, Emodel *model)
1309 1324
1310 sd->model = model; 1325 sd->model = model;
1311 1326
1312 if (!sd->model) 1327 bool reset_values = true;
1328 if (sd->model)
1313 { 1329 {
1314 INF("resetting prefs to default values"); 1330 eo_ref(sd->model);
1315 _elm_prefs_values_get_default(sd->root, EINA_FALSE); 1331 Emodel_Load_Status status;
1316 1332 eo_do(sd->model, status = emodel_load_status_get());
1317 goto end; 1333 reset_values = !(status & EMODEL_LOAD_STATUS_LOADED_PROPERTIES);
1318 } 1334 }
1319 1335
1320 eo_ref(sd->model); 1336 _elm_prefs_values_fetch(obj, sd, reset_values);
1321
1322 sd->values_fetching = EINA_TRUE;
1323 _elm_prefs_values_get_user(sd, sd->root);
1324 sd->values_fetching = EINA_FALSE;
1325
1326end:
1327 evas_object_smart_callback_call
1328 (obj, SIG_PAGE_CHANGED, (char *)sd->root->name);
1329
1330 return EINA_TRUE; 1337 return EINA_TRUE;
1331} 1338}
1332 1339
@@ -2011,7 +2018,7 @@ _elm_prefs_value_get(Elm_Prefs_Data *sd, const char *key, Eina_Value *value)
2011 Emodel_Load_Status status; 2018 Emodel_Load_Status status;
2012 const Eina_Value *prop_value; 2019 const Eina_Value *prop_value;
2013 eo_do(sd->model, status = emodel_property_get(property, &prop_value)); 2020 eo_do(sd->model, status = emodel_property_get(property, &prop_value));
2014 if (EMODEL_LOAD_STATUS_ERROR == status) 2021 if (EMODEL_LOAD_STATUS_ERROR == status || !prop_value)
2015 return EINA_FALSE; 2022 return EINA_FALSE;
2016 2023
2017 return eina_value_copy(prop_value, value); 2024 return eina_value_copy(prop_value, value);
@@ -2062,4 +2069,22 @@ _elm_prefs_property_connect(Eo *obj EINA_UNUSED,
2062 free(eina_hash_set(sd->prop_con, part, strdup(property))); 2069 free(eina_hash_set(sd->prop_con, part, strdup(property)));
2063} 2070}
2064 2071
2072static void
2073_elm_prefs_values_fetch(Eo *obj, Elm_Prefs_Data *sd, bool reset_values)
2074{
2075 if (reset_values)
2076 {
2077 INF("resetting prefs to default values");
2078 _elm_prefs_values_get_default(sd->root, EINA_FALSE);
2079 }
2080 else
2081 {
2082 sd->values_fetching = EINA_TRUE;
2083 _elm_prefs_values_get_user(sd, sd->root);
2084 sd->values_fetching = EINA_FALSE;
2085 }
2086 evas_object_smart_callback_call
2087 (obj, SIG_PAGE_CHANGED, (char *)sd->root->name);
2088}
2089
2065#include "elm_prefs.eo.c" 2090#include "elm_prefs.eo.c"