devilhorns pushed a commit to branch master.

http://git.enlightenment.org/apps/express.git/commit/?id=928de66e3906c61ccce8ecc7181635b4093e839b

commit 928de66e3906c61ccce8ecc7181635b4093e839b
Author: Chris Michael <cp.mich...@samsung.com>
Date:   Tue Oct 27 11:05:30 2015 -0400

    express: Fix crash when adding channel groups
    
    This fixes an issue when having channels from more than one network
    would crash when adding channel groups to the treeview
    
    @fix
    
    Signed-off-by: Chris Michael <cp.mich...@samsung.com>
---
 src/bin/channel.c | 32 +++++++------------
 src/bin/channel.h |  4 +--
 src/bin/window.c  | 94 +++++++++++++++++++++++++++++++++----------------------
 3 files changed, 69 insertions(+), 61 deletions(-)

diff --git a/src/bin/channel.c b/src/bin/channel.c
index c6f57a6..af58d6e 100644
--- a/src/bin/channel.c
+++ b/src/bin/channel.c
@@ -45,7 +45,6 @@ struct _Channel
         Evas_Object *o_frame;
         Evas_Object *o_box;
         Evas_Object *o_list;
-        Elm_Object_Item *group;
         Elm_Genlist_Item_Class *itc, *gitc;
      } treeview;
 
@@ -1447,37 +1446,28 @@ _channel_treeview_clear(Channel *chl)
    elm_genlist_clear(chl->treeview.o_list);
 }
 
-void 
+Elm_Object_Item *
 _channel_treeview_group_add(Channel *chl, const char *group)
 {
    Elm_Object_Item *it;
 
-   it = elm_genlist_item_append(chl->treeview.o_list, chl->treeview.gitc, 
-                                group, NULL, ELM_GENLIST_ITEM_GROUP,
-                                NULL, NULL);
-   elm_genlist_item_expanded_set(it, EINA_FALSE);
+   it =
+     elm_genlist_item_append(chl->treeview.o_list, chl->treeview.gitc,
+                             group, NULL, ELM_GENLIST_ITEM_GROUP, NULL, NULL);
+   elm_genlist_item_expanded_set(it, EINA_TRUE);
    elm_genlist_item_select_mode_set(it, ELM_OBJECT_SELECT_MODE_DISPLAY_ONLY);
 
-   if (chl->net)
-     {
-        const char *netname;
-
-        if ((netname = express_network_name_get(chl->net)))
-          {
-             if (!strcmp(netname, group))
-               chl->treeview.group = it;
-          }
-     }
+   return it;
 }
 
 void 
-_channel_treeview_group_item_add(Channel *pchl, Channel *chl)
+_channel_treeview_group_item_add(Channel *pchl, Channel *chl, Elm_Object_Item 
*group)
 {
    Elm_Object_Item *it;
 
    it = 
-     elm_genlist_item_append(pchl->treeview.o_list, pchl->treeview.itc, 
-                             chl, pchl->treeview.group, ELM_GENLIST_ITEM_NONE, 
+     elm_genlist_item_append(pchl->treeview.o_list, pchl->treeview.itc,
+                             chl, group, ELM_GENLIST_ITEM_NONE,
                              _cb_treeview_selected, NULL);
 
    if (chl->active)
@@ -1490,8 +1480,8 @@ _channel_treeview_item_add(Channel *pchl, Channel *chl)
    Elm_Object_Item *it;
 
    it = 
-     elm_genlist_item_append(pchl->treeview.o_list, pchl->treeview.itc, 
-                             chl, NULL, ELM_GENLIST_ITEM_NONE, 
+     elm_genlist_item_append(pchl->treeview.o_list, pchl->treeview.itc,
+                             chl, NULL, ELM_GENLIST_ITEM_NONE,
                              _cb_treeview_selected, NULL);
 
    if (chl->active)
diff --git a/src/bin/channel.h b/src/bin/channel.h
index a07d6cc..7171bf8 100644
--- a/src/bin/channel.h
+++ b/src/bin/channel.h
@@ -64,8 +64,8 @@ void _channel_tabspacer_create(Channel *chl, double v1, 
double v2);
 void _channel_tabspacer_destroy(Channel *chl);
 
 void _channel_treeview_clear(Channel *chl);
-void _channel_treeview_group_add(Channel *chl, const char *group);
-void _channel_treeview_group_item_add(Channel *pchl, Channel *chl);
+Elm_Object_Item *_channel_treeview_group_add(Channel *chl, const char *group);
+void _channel_treeview_group_item_add(Channel *pchl, Channel *chl, 
Elm_Object_Item *group);
 void _channel_treeview_item_add(Channel *pchl, Channel *chl);
 
 Eina_Bool _channel_user_find(Channel *chl, const char *user);
diff --git a/src/bin/window.c b/src/bin/window.c
index 95451c9..6404a46 100644
--- a/src/bin/window.c
+++ b/src/bin/window.c
@@ -7,6 +7,12 @@
 #include "options.h"
 #include "callbacks.h"
 
+typedef struct _Group
+{
+   char *name;
+   Eina_List *channels;
+} Group;
+
 struct _Window
 {
    Evas *evas;
@@ -337,12 +343,6 @@ _window_new(void)
    return win;
 }
 
-static int 
-_cb_groups_sort(const void *d1, const void *d2)
-{
-   return strcasecmp(d1, d2);
-}
-
 /* external functions */
 Eina_Bool 
 _window_create(void)
@@ -1054,59 +1054,77 @@ _window_tabcount_update(void)
      }
 }
 
+static void
+_cb_groups_free(void *data)
+{
+   Group *group;
+
+   group = data;
+   free(group->name);
+   free(group);
+}
+
 void 
 _window_treeview_update(void)
 {
-   Eina_List *l, *groups = NULL;
-   Eina_List *ll, *channels = NULL;
-   Channel *chl;
-   const char *name;
+   Eina_List *l, *ll;
+   Channel *chl, *lchl;
+   Eina_Hash *groups;
+   Group *group;
+   Eina_Iterator *itr;
+   void *data = NULL;
+
+   groups = eina_hash_string_superfast_new(_cb_groups_free);
+
+   EINA_LIST_FOREACH(_win->channels, l, chl)
+     _channel_treeview_clear(chl);
 
-   channels = eina_list_clone(_win->channels);
+   lchl = _window_channel_find("Status");
+
+   /* add Status to each channel */
+   EINA_LIST_FOREACH(_win->channels, l, chl)
+     _channel_treeview_item_add(chl, lchl);
 
    EINA_LIST_FOREACH(_win->channels, l, chl)
      {
         Express_Network *net;
 
-        _channel_treeview_clear(chl);
-
-        if ((net = _channel_network_get(chl)))
+        net = _channel_network_get(chl);
+        if (net)
           {
+             const char *name;
+
              name = express_network_name_get(net);
+             group = eina_hash_find(groups, name);
+             if (!group)
+               {
+                  group = calloc(1, sizeof(Group));
+                  group->name = strdup(name);
+
+                  eina_hash_add(groups, name, group);
+               }
 
-             if (!eina_list_data_find(groups, name))
-               groups = eina_list_append(groups, name);
+             if (!eina_list_data_find(group->channels, chl))
+               group->channels = eina_list_append(group->channels, chl);
           }
      }
 
-   groups = eina_list_sort(groups, eina_list_count(groups), _cb_groups_sort);
-
-   EINA_LIST_FREE(groups, name)
+   itr = eina_hash_iterator_data_new(groups);
+   while (eina_iterator_next(itr, &data))
      {
+        group = (Group *)data;
+
         EINA_LIST_FOREACH(_win->channels, l, chl)
           {
-             Channel *lchl;
-
-             EINA_LIST_FOREACH(channels, ll, lchl)
-               {
-                  if (!_channel_network_get(lchl))
-                    _channel_treeview_item_add(chl, lchl);
-               }
+             Elm_Object_Item *it;
 
-             _channel_treeview_group_add(chl, name);
+             it = _channel_treeview_group_add(chl, strdup(group->name));
 
-             EINA_LIST_FOREACH(channels, ll, lchl)
-               {
-                  Express_Network *net;
-
-                  if ((net = _channel_network_get(lchl)))
-                    {
-                       if (!strcmp(name, express_network_name_get(net)))
-                         _channel_treeview_group_item_add(chl, lchl);
-                    }
-               }
+             EINA_LIST_FOREACH(group->channels, ll, lchl)
+               _channel_treeview_group_item_add(chl, lchl, it);
           }
      }
+   eina_iterator_free(itr);
 
-   eina_list_free(channels);
+   eina_hash_free(groups);
 }

-- 


Reply via email to