This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch master
in repository efm2.

View the commit online.

commit aee281bc32e5fe82c284a0e4b90821a40a7a15d9
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
AuthorDate: Sat Dec 2 16:00:12 2023 +0000

    detail view - allow detail items to update not just create
---
 src/efm/efm_structs.h |   1 +
 src/efm/efm_util.c    | 347 +++++++++++++++++++++++++++++++++-----------------
 2 files changed, 228 insertions(+), 120 deletions(-)

diff --git a/src/efm/efm_structs.h b/src/efm/efm_structs.h
index 777725b..bd398fa 100644
--- a/src/efm/efm_structs.h
+++ b/src/efm/efm_structs.h
@@ -150,6 +150,7 @@ struct _Icon
   Evas_Object   *o_entry;
   Evas_Object   *o_list_detail_swallow[6];
   Evas_Object   *o_list_detail_swallow2[6];
+  Evas_Object   *o_list_detail_swallow3[6];
   Smart_Data    *sd;
   Cmd           *cmd;
   Block         *block;
diff --git a/src/efm/efm_util.c b/src/efm/efm_util.c
index 13a73fd..b6a1dc6 100644
--- a/src/efm/efm_util.c
+++ b/src/efm/efm_util.c
@@ -1187,15 +1187,23 @@ _icon_detail_size_display(unsigned long long size, char unit[8])
   return (int)size; // int is fine as we reduced the value to unit size
 }
 
+static void
+_icon_detail_text_set(Icon *icon, int col, const char *detail)
+{
+  char buf[128];
+
+  snprintf(buf, sizeof(buf), "e.text.detail%i", col + 1);
+  edje_object_part_text_set(icon->o_base, buf, detail);
+}
+
 static Evas_Object *
 _icon_detail_rectangle_add(Icon *icon, Smart_Data *sd, Evas *e, int col,
                            const char *detail)
 {
   Evas_Object *o;
-  char buf[128];
+  char         buf[128];
 
-  snprintf(buf, sizeof(buf), "e.text.detail%i", col + 1);
-  if (detail) edje_object_part_text_set(icon->o_base, buf, detail);
+  _icon_detail_text_set(icon, col, detail);
   icon->o_list_detail_swallow[col] = o = evas_object_rectangle_add(e);
   evas_object_pass_events_set(o, EINA_TRUE);
   evas_object_color_set(o, 0, 0, 0, 0);
@@ -1369,22 +1377,13 @@ _cb_icon_detail_slider_mouse_down(void *data, Evas *e EINA_UNUSED,
   if (ev->button == 1) evas_object_raise(icon->o_base);
 }
 
-static Evas_Object *
-_icon_detail_icon_add(Evas_Object *base, const char *icon, const char *dir)
+static void
+_icon_detail_icon_set(Evas_Object *o, const char *icon, const char *dir)
 {
-  Evas_Object *o;
-
   if (!strncmp(icon, "std:", 4))
-    {
-      o = elm_icon_add(base);
-      evas_object_pass_events_set(o, EINA_TRUE);
-      elm_icon_standard_set(o, icon + 4);
-    }
+    elm_icon_standard_set(o, icon + 4);
   else
     {
-      o = efm_icon_add(base);
-      efm_icon_keep_aspect_set(o, EINA_TRUE);
-      evas_object_pass_events_set(o, EINA_TRUE);
       if (icon[0] == '/') efm_icon_file_set(o, icon);
       else
         {
@@ -1396,6 +1395,24 @@ _icon_detail_icon_add(Evas_Object *base, const char *icon, const char *dir)
           eina_strbuf_free(strbuf);
         }
     }
+}
+
+static Evas_Object *
+_icon_detail_icon_add(Evas_Object *base, const char *icon)
+{
+  Evas_Object *o;
+
+  if (!strncmp(icon, "std:", 4))
+    {
+      o = elm_icon_add(base);
+      evas_object_pass_events_set(o, EINA_TRUE);
+    }
+  else
+    {
+      o = efm_icon_add(base);
+      efm_icon_keep_aspect_set(o, EINA_TRUE);
+      evas_object_pass_events_set(o, EINA_TRUE);
+    }
   return o;
 }
 
@@ -1416,45 +1433,61 @@ _icon_detail_elm_object_prepare(Evas_Object *o, int col)
   evas_object_propagate_events_set(o, EINA_FALSE);
 }
 
+static void
+_icon_detail_size_update(Evas_Object *o, const char *detail)
+{
+  char               buf[128];
+  char             **plist;
+  unsigned long long size, size_max;
+  double             sz;
+
+  plist = eina_str_split(detail, "/", 2);
+  if (!plist) return;
+  if (!(plist[0] && plist[1])) goto done;
+  size = atoll(plist[0]);
+  size_max = atoll(plist[1]);
+  if (size_max <= 0) size_max = 1;
+  sz = (double)size / (double)size_max;
+  // counteract _size_message doins a sqrt for show
+  sz = sz * sz;
+  _size_message(o, sz);
+
+  size = _icon_detail_size_display(size, buf);
+  edje_object_part_text_set(o, "e.text.unit", buf);
+  snprintf(buf, sizeof(buf), "%i", (int)size);
+  edje_object_part_text_set(o, "e.text.label", buf);
+
+done:
+  free(*plist);
+  free(plist);
+}
+
 static void
 _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
                  const char *theme_edj_file, int col, const char *detail,
                  const char *format)
-{
+{ // can call this for add AND update - working on update now
   Evas_Object *o, *o2;
-  char buf[128];
-
+  
   if (!detail) detail = "";
   if (!strcmp(format, "text")) // format: just the string as-is
-    _icon_detail_rectangle_add(icon, sd, e, col, detail);
+    {
+      if (!icon->o_list_detail_swallow[col])
+        _icon_detail_rectangle_add(icon, sd, e, col, detail);
+      else
+        _icon_detail_text_set(icon, col, detail);
+    }
   else if (!strcmp(format, "size"))
     { // format: "13/28" = value/max_value
-      char             **plist;
-      unsigned long long size, size_max;
-      double             sz;
-
-      plist = eina_str_split(detail, "/", 2);
-      if (plist[0] && plist[1])
-        {
-          size     = atoll(plist[0]);
-          size_max = atoll(plist[1]);
-
-          o  = _icon_detail_grid_add(icon, sd, col);
-          o  = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
-                                              "e/fileman/default/filesize");
-          sz = (double)size / (double)size_max;
-          // counteract _size_message doins a sqrt for show
-          sz = sz * sz;
-          if (size_max > 0) _size_message(o, sz);
-          else _size_message(o, 0.0);
-
-          size = _icon_detail_size_display(size, buf);
-          edje_object_part_text_set(o, "e.text.unit", buf);
-          snprintf(buf, sizeof(buf), "%i", (int)size);
-          edje_object_part_text_set(o, "e.text.label", buf);
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
+                                             "e/fileman/default/filesize");
+          icon->o_list_detail_swallow3[col] = o;
         }
-      free(*plist);
-      free(plist);
+      o = icon->o_list_detail_swallow3[col];
+      _icon_detail_size_update(o, detail);
     }
   else if (!strcmp(format, "timestamp"))
     { // format: "1284924" = time_in_seconds_since_epoch
@@ -1462,9 +1495,14 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
       struct tm *info;
 
       info = localtime(&tmpt);
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
-                                         "e/fileman/default/filedate");
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
+                                             "e/fileman/default/filedate");
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
       _icon_detail_edje_text_set_free(o, "e.text.year",
                                       eina_strftime("%y", info));
       _icon_detail_edje_text_set_free(o, "e.text.month",
@@ -1476,9 +1514,14 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
     }
   else if (!strcmp(format, "checkview"))
     { // format: "true"/"yes"/"1" or "false"/"no"/"0"
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
-                                         "e/fileman/default/check");
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
+                                             "e/fileman/default/check");
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
       if (_icon_detail_bool_parse(detail))
         edje_object_signal_emit(o, "e,state,on", "e");
       else edje_object_signal_emit(o, "e,state,off", "e");
@@ -1487,12 +1530,17 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
     { // format: "33/100" or "noval,41/50" = value / maxvalue optional noval
       int val = 0, max = 100;
 
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = elm_progressbar_add(o);
-      _icon_detail_elm_object_prepare(o, col);
-      elm_progressbar_horizontal_set(o, EINA_TRUE);
-      elm_progressbar_span_size_set(o, 1);
-      elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = elm_progressbar_add(o);
+          _icon_detail_elm_object_prepare(o, col);
+          elm_progressbar_horizontal_set(o, EINA_TRUE);
+          elm_progressbar_span_size_set(o, 1);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
       if (sscanf(detail, "%i/%i", &val, &max) == 2)
         {
           if (max < 1) max = 0;
@@ -1503,6 +1551,7 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
                                                    NULL);
           if (max < 1) max = 0;
         }
+      if (val < 0) val = 0;
       elm_progressbar_value_set(o, (double)val / (double)max);
       evas_object_show(o);
     }
@@ -1511,42 +1560,69 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
       Edje_Message_String msg;
 
       msg.str = (char *)detail;
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
-                                         "e/fileman/default/circle");
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = _icon_detail_grid_sub_edje_add(icon, e, theme_edj_file, col,
+                                             "e/fileman/default/circle");
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
       edje_object_message_send(o, EDJE_MESSAGE_STRING, 1, &msg);
       edje_object_message_signal_process(o);
     }
   else if (!strcmp(format, "icon"))
     { // format: std:clock or /path/x.png or path/x.gif or x.gif
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = _icon_detail_icon_add(o, detail, sd->config.path);
-      elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
-      evas_object_show(o);
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = _icon_detail_icon_add(o, detail);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+          evas_object_show(o);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
+      _icon_detail_icon_set(o, detail, sd->config.path);
     }
   else if (!strcmp(format, "check"))
     { // format: "true"/"yes"/"1" or "false"/"no"/"0"
-      o = _icon_detail_grid_add(icon, sd, col);
-      // use table to pack check into to force centering and put it in the grid
-      o2 = elm_table_add(o);
-      elm_grid_pack(icon->o_list_detail_swallow[col], o2, 0, 0, 1, 1);
-      o = elm_check_add(o);
-      _icon_detail_elm_object_prepare(o, col);
-      elm_table_pack(o2, o, 0, 0, 1, 1);
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          // use table to pack check into to force centering and put it in
+          // the grid
+          o2 = elm_table_add(o);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o2, 0, 0, 1, 1);
+          o = elm_check_add(o);
+          _icon_detail_elm_object_prepare(o, col);
+          elm_table_pack(o2, o, 0, 0, 1, 1);
+          evas_object_smart_callback_add(o, "changed",
+                                         _cb_icon_detail_check_changed,
+                                         icon);
+          evas_object_show(o2);
+          evas_object_show(o);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
       elm_check_state_set(o, _icon_detail_bool_parse(detail));
-      evas_object_smart_callback_add(o, "changed",
-                                     _cb_icon_detail_check_changed, icon);
-      evas_object_show(o2);
-      evas_object_show(o);
     }
   else if (!strcmp(format, "button"))
     { // format: "Label" or "Label!icon" = icon above
       char *label, *sep;
 
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = elm_button_add(o);
-      _icon_detail_elm_object_prepare(o, col);
-      elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = elm_button_add(o);
+          _icon_detail_elm_object_prepare(o, col);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+          evas_object_smart_callback_add(o, "clicked",
+                                         _cb_icon_detail_button_clicked,
+                                         icon);
+          evas_object_show(o);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o     = icon->o_list_detail_swallow3[col];
       label = strdup(detail);
       if (label)
         {
@@ -1554,39 +1630,52 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
           if (sep)
             {
               *sep++ = 0;
-              o2 = _icon_detail_icon_add(o, sep, sd->config.path);
+              o2     = elm_object_part_content_get(o, "icon");
+              if (!o2) o2 = _icon_detail_icon_add(o, sep);
+              _icon_detail_icon_set(o2, sep, sd->config.path);
               elm_object_part_content_set(o, "icon", o2);
               evas_object_show(o2);
             }
           elm_object_text_set(o, label);
-          evas_object_smart_callback_add(o, "clicked",
-                                         _cb_icon_detail_button_clicked,
-                                         icon);
           free(label);
         }
-      evas_object_show(o);
     }
   else if (!strcmp(format, "segmentsel"))
     { // format: "Opt1,*Opt2" or "*Opt!icon,Opt2" = icon above, *= SELECTED
-      char **plist, **p, *sep, *label;
+      char           **plist, **p, *sep, *label;
       Elm_Object_Item *it;
-      Eina_Bool sel;
-      int n;
+      Eina_Bool        sel;
+      int              n;
 
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = elm_segment_control_add(o);
-      _icon_detail_elm_object_prepare(o, col);
-      elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = elm_segment_control_add(o);
+          _icon_detail_elm_object_prepare(o, col);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+          evas_object_smart_callback_add(o, "changed",
+                                         _cb_icon_detail_segment_changed,
+                                         icon);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
+      n = elm_segment_control_item_count_get(o);
+      while (n > 0)
+        { // delete all existing items - brute force re-fill
+          elm_segment_control_item_del_at(o, 0);
+          n--;
+        }
       plist = eina_str_split(detail, ",", -1);
       for (p = plist, n = 0; *p != NULL; p++, n++)
         {
           sel = EINA_FALSE;
-          o2 = NULL;
+          o2  = NULL;
           sep = strchr(*p, '!');
           if (sep)
             {
               *sep++ = 0;
-              o2 = _icon_detail_icon_add(o, sep, sd->config.path);
+              o2     = _icon_detail_icon_add(o, sep);
+              _icon_detail_icon_set(o2, sep, sd->config.path);
             }
           label = *p;
           if (**p == '*')
@@ -1600,9 +1689,6 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
           if (sel) elm_segment_control_item_selected_set(it, EINA_TRUE);
           if (o2) evas_object_show(o2);
         }
-      evas_object_smart_callback_add(o, "changed",
-                                     _cb_icon_detail_segment_changed,
-                                     icon);
       free(*plist);
       free(plist);
       evas_object_show(o);
@@ -1616,12 +1702,22 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
       char buf[PATH_MAX];
       int n;
 
-      o = _icon_detail_grid_add(icon, sd, col);
-      o = elm_hoversel_add(o);
-      elm_hoversel_auto_update_set(o, EINA_TRUE);
-      elm_hoversel_hover_parent_set(o, sd->o_scroller);
-      _icon_detail_elm_object_prepare(o, col);
-      elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = elm_hoversel_add(o);
+          elm_hoversel_auto_update_set(o, EINA_TRUE);
+          elm_hoversel_hover_parent_set(o, sd->o_scroller);
+          _icon_detail_elm_object_prepare(o, col);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+          evas_object_smart_callback_add(o, "selected",
+                                         _cb_icon_detail_popdown_changed,
+                                         icon);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
+      // brute force - clean hoversel if it is updated
+      elm_hoversel_clear(o);
       plist = eina_str_split(detail, ",", -1);
       for (p = plist, n = 0; *p != NULL; p++, n++)
         {
@@ -1665,9 +1761,6 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
           elm_object_item_data_set(it, (void *)(unsigned long)n);
           if (sel) elm_object_text_set(o, label);
         }
-      evas_object_smart_callback_add(o, "selected",
-                                     _cb_icon_detail_popdown_changed,
-                                     icon);
       free(*plist);
       free(plist);
       evas_object_show(o);
@@ -1677,6 +1770,22 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
       char               **plist;
       unsigned long long   min, max, val, val2;
 
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = elm_slider_add(o);
+          evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
+                                         _cb_icon_detail_slider_mouse_down,
+                                         icon);
+          _icon_detail_elm_object_prepare(o, col);
+          evas_object_smart_callback_add(o, "changed",
+                                         _cb_icon_detail_slider_changed,
+                                         icon);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+          evas_object_show(o);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o     = icon->o_list_detail_swallow3[col];
       plist = eina_str_split(detail, "/", 4);
       if (plist[0] && plist[1] && plist[2])
         {
@@ -1684,12 +1793,6 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
           max = atoll(plist[1]);
           val = atoll(plist[2]);
 
-          o = _icon_detail_grid_add(icon, sd, col);
-          o = elm_slider_add(o);
-          evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_DOWN,
-                                         _cb_icon_detail_slider_mouse_down,
-                                         icon);
-          _icon_detail_elm_object_prepare(o, col);
           elm_slider_min_max_set(o, min, max);
           elm_slider_unit_format_set(o, "%1.0f");
           if (plist[3])
@@ -1698,12 +1801,11 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
               elm_slider_range_enabled_set(o, EINA_TRUE);
               elm_slider_range_set(o, val, val2);
             }
-          else elm_slider_value_set(o, val);
-
-          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
-          evas_object_smart_callback_add(o, "changed",
-                                         _cb_icon_detail_slider_changed, icon);
-          evas_object_show(o);
+          else
+            {
+              elm_slider_range_enabled_set(o, EINA_FALSE);
+              elm_slider_value_set(o, val);
+            }
         }
       free(*plist);
       free(plist);
@@ -1716,8 +1818,16 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
       char **plist2, **p2, **plist, **p, *cc;
       int    min, max, num, *vals, start;
 
+      if (!icon->o_list_detail_swallow[col])
+        { // only add if not there
+          o = _icon_detail_grid_add(icon, sd, col);
+          o = efm_graph_add(o);
+          elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
+          evas_object_show(o);
+          icon->o_list_detail_swallow3[col] = o;
+        }
+      o = icon->o_list_detail_swallow3[col];
       plist2 = eina_str_split(detail, "|", -1);
-      o = _icon_detail_grid_add(icon, sd, col);
       for (p2 = plist2; *p2; p2++)
         {
           plist = eina_str_split(*p2, ",", -1);
@@ -1742,11 +1852,8 @@ _icon_detail_add(Icon *icon, Smart_Data *sd, Evas *e,
                           if (num >= 0) vals[num] = atoi(*p);
                           num++;
                         }
-                      o = efm_graph_add(o);
                       if (cc) efm_graph_colorspec_set(o, cc);
                       efm_graph_values_set(o, num, vals, min, max);
-                      elm_grid_pack(icon->o_list_detail_swallow[col], o, 0, 0, 1, 1);
-                      evas_object_show(o);
                       free(vals);
                     }
                 }

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to