efl_ui/layout: validate theme api version in theme_apply
authorMike Blumenkrantz <zmike@samsung.com>
Tue, 24 Sep 2019 20:59:39 +0000 (16:59 -0400)
committerJongmin Lee <jm105.lee@samsung.com>
Tue, 24 Sep 2019 21:50:43 +0000 (06:50 +0900)
Summary:
this throws error and warning messages if the theme api version does
not match the current efl version, and it will cause unit tests to fail
when the theme version is not updated

ref T8231

Depends on D10093

Reviewers: cedric

Reviewed By: cedric

Subscribers: cedric, #reviewers, #committers

Tags: #efl_widgets

Maniphest Tasks: T8231

Differential Revision: https://phab.enlightenment.org/D10081

src/lib/elementary/efl_ui_layout.c
src/lib/elementary/elm_widget_layout.h

index 590b107..2cd86ef 100644 (file)
@@ -575,12 +575,13 @@ _efl_ui_layout_base_efl_ui_widget_disabled_set(Eo *obj, Efl_Ui_Layout_Data *_pd
 }
 
 static Eina_Error
-_efl_ui_layout_theme_internal(Eo *obj, Efl_Ui_Layout_Data *sd)
+_efl_ui_layout_theme_internal(Eo *obj, Efl_Ui_Layout_Data *sd, Elm_Widget_Smart_Data **widget_data)
 {
    Eina_Error ret = EFL_UI_THEME_APPLY_ERROR_GENERIC;
 
    ELM_WIDGET_DATA_GET_OR_RETURN(obj, wd, EFL_UI_THEME_APPLY_ERROR_GENERIC);
 
+   *widget_data = wd;
    /* function already prints error messages, if any */
    if (!sd->file_set)
      {
@@ -604,11 +605,14 @@ EOLIAN static Eina_Error
 _efl_ui_layout_base_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Layout_Data *sd)
 {
    Eina_Error theme_apply_ret, theme_apply_internal_ret;
+   Elm_Widget_Smart_Data *wd;
+   char buf[64];
+   static unsigned int version = 0;
 
    theme_apply_ret = efl_ui_widget_theme_apply(efl_super(obj, MY_CLASS));
    if (theme_apply_ret == EFL_UI_THEME_APPLY_ERROR_GENERIC) return EFL_UI_THEME_APPLY_ERROR_GENERIC;
 
-   theme_apply_internal_ret = _efl_ui_layout_theme_internal(obj, sd);
+   theme_apply_internal_ret = _efl_ui_layout_theme_internal(obj, sd, &wd);
    if (theme_apply_internal_ret == EFL_UI_THEME_APPLY_ERROR_GENERIC)
      return EFL_UI_THEME_APPLY_ERROR_GENERIC;
 
@@ -620,6 +624,38 @@ _efl_ui_layout_base_efl_ui_widget_theme_apply(Eo *obj, Efl_Ui_Layout_Data *sd)
    efl_gfx_hint_size_restricted_min_set(obj, EINA_SIZE2D(0, 0));
    if (elm_widget_is_legacy(obj))
      efl_gfx_hint_size_min_set(obj, EINA_SIZE2D(0, 0));
+   else
+     {
+        const char *version = edje_object_data_get(wd->resize_obj, "version");
+        if (!version)
+          ERR("Widget(%p) with type '%s' is not providing a version in its theme!", obj,
+              efl_class_name_get(efl_class_get(obj)));
+        errno = 0;
+        sd->version = strtoul(version, NULL, 10);
+        if (errno)
+          {
+             ERR("Widget(%p) with type '%s' is not providing a valid version in its theme!", obj,
+                 efl_class_name_get(efl_class_get(obj)));
+             sd->version = 0;
+          }
+     }
+   if (!version)
+     {
+        snprintf(buf, sizeof(buf), "%d%d", EFL_VERSION_MAJOR, EFL_VERSION_MINOR);
+        errno = 0;
+        version = strtoul(buf, NULL, 10);
+        if (errno)
+          {
+             ERR("something broke in theme parsing, this system is probably busted");
+             version = 0;
+          }
+     }
+   if (version && (!_running_in_tree))
+     {
+        if (sd->version < version)
+          WRN("Widget(%p) with type '%s' is providing a potentially old version in its theme: found %u, should be %u", obj,
+              efl_class_name_get(efl_class_get(obj)), sd->version, version);
+     }
 
    return EFL_UI_THEME_APPLY_ERROR_NONE;
 }
index 593f770..c5dc65c 100644 (file)
@@ -64,6 +64,7 @@ typedef struct _Efl_Ui_Layout_Data
    } connect;
 
    unsigned int          finger_size_multiplier_x, finger_size_multiplier_y; /**< multipliers for finger_size during group_calc */
+   unsigned int          version; /**< version number specified in the widget's theme */
 
    Eina_Bool             frozen; /**< Layout freeze state */
    Eina_Bool             can_access : 1; /**< This is true when all text(including textblock) parts can be accessible by accessibility. */