summaryrefslogtreecommitdiff
path: root/src/lib/elementary
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-11-06 11:23:21 -0200
committerVitor Sousa <vitorsousa@expertisesolutions.com.br>2018-11-30 16:56:47 -0200
commit0398b8f19c2adcf206ec298ded8ce4dd1681a501 (patch)
tree5c075a6f0875b67a97a214db65f69aa98638b7cf /src/lib/elementary
parentddd263875896c11b7d0875c7357a3322243290d9 (diff)
elementary: rework Efl.Ui.Layout boolean signal-connection to Models
Add new feature to specify signal connection to boolean properties of Models. This also fix some '%v' substitution problems. Parsing EINA_VALUE_TYPE_BOOL as boolean in Efl.Ui.Layout signal updates from Models (instead of EINA_VALUE_TYPE_UCHAR). UCHAR no longer has special handling and falls to the general result of eina_value_to_string() as other types do. Use EINA_VALUE_TYPE_BOOL instead of EINA_VALUE_TYPE_UCHAR to signal selection on click events to the Model. Update examples to make usage of the new property connection feature in order to model selection of items on Views.
Diffstat (limited to 'src/lib/elementary')
-rw-r--r--src/lib/elementary/efl_ui_layout.c57
1 files changed, 44 insertions, 13 deletions
diff --git a/src/lib/elementary/efl_ui_layout.c b/src/lib/elementary/efl_ui_layout.c
index 0b46b4ee34..0e42c88d21 100644
--- a/src/lib/elementary/efl_ui_layout.c
+++ b/src/lib/elementary/efl_ui_layout.c
@@ -1964,7 +1964,9 @@ _efl_ui_layout_view_model_signal_update(Efl_Ui_Layout_Data *pd, const char *sign
1964{ 1964{
1965 Eina_Value *v = NULL; 1965 Eina_Value *v = NULL;
1966 Eina_Strbuf *buf; 1966 Eina_Strbuf *buf;
1967 char *value; 1967 char *value = NULL;
1968 Eina_Bool eval = EINA_FALSE;
1969 Eina_Bool is_bool = EINA_FALSE;
1968 1970
1969 v = efl_model_property_get(pd->connect.model, fetch); 1971 v = efl_model_property_get(pd->connect.model, fetch);
1970 if (!v) return; 1972 if (!v) return;
@@ -1978,26 +1980,55 @@ _efl_ui_layout_view_model_signal_update(Efl_Ui_Layout_Data *pd, const char *sign
1978 return; 1980 return;
1979 } 1981 }
1980 1982
1981 // FIXME: previous implementation would just do that for signal/part == "selected" 1983 is_bool = (eina_value_type_get(v) == EINA_VALUE_TYPE_BOOL);
1982 if (eina_value_type_get(v) == EINA_VALUE_TYPE_UCHAR) 1984 if (is_bool)
1983 {
1984 Eina_Bool bl;
1985
1986 eina_value_bool_get(v, &bl);
1987 if (bl) value = strdup("selected");
1988 else value = strdup("unselected");
1989 }
1990 else
1991 { 1985 {
1992 value = eina_value_to_string(v); 1986 eina_value_bool_get(v, &eval);
1993 } 1987 }
1988 value = eina_value_to_string(v);
1994 1989
1995 buf = eina_strbuf_new(); 1990 buf = eina_strbuf_new();
1996 // FIXME: is it really the form of signal we want to send ? 1991 // FIXME: is it really the form of signal we want to send ?
1997 eina_strbuf_append_printf(buf, "%s%s", signal, value); 1992 const char *ini = signal;
1993 for (;;)
1994 {
1995 const char *last = ini;
1996 ini = strstr(last, "%{");
1997 if (!ini)
1998 {
1999 eina_strbuf_append(buf, last);
2000 break;
2001 }
2002 if (!is_bool)
2003 {
2004 ERR("Using signal connection `%%{;}' with a property that is not boolean. Signal: `%s'; Property: `%s'.", signal, fetch);
2005 goto on_error;
2006 }
2007 eina_strbuf_append_length(buf, last, (size_t)(ini-last));
2008 const char *sep = strchr(ini+2, ';');
2009 if (!sep)
2010 {
2011 ERR("Could not find separator `;'.");
2012 goto on_error;
2013 }
2014 const char *fin = strchr(sep+1, '}');
2015 if (!fin)
2016 {
2017 ERR("Could not find terminator `}'.");
2018 goto on_error;
2019 }
2020 if (eval)
2021 eina_strbuf_append_length(buf, ini+2, (size_t)(sep-(ini+2)));
2022 else
2023 eina_strbuf_append_length(buf, sep+1, (size_t)(fin-(sep+1)));
2024 ini = fin+1;
2025 }
2026 eina_strbuf_replace_all(buf, "%v", value);
2027
1998 elm_layout_signal_emit(pd->obj, eina_strbuf_string_get(buf), 2028 elm_layout_signal_emit(pd->obj, eina_strbuf_string_get(buf),
1999 elm_widget_is_legacy(pd->obj) ? "elm" : "efl"); 2029 elm_widget_is_legacy(pd->obj) ? "elm" : "efl");
2000 2030
2031on_error:
2001 eina_strbuf_free(buf); 2032 eina_strbuf_free(buf);
2002 eina_value_free(v); 2033 eina_value_free(v);
2003 free(value); 2034 free(value);