summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2016-06-17 16:40:49 -0300
committerVitor Sousa <vitorsousasilva@gmail.com>2016-06-17 16:40:49 -0300
commit434421021d3dfd808ff8f76a4279b1e476376376 (patch)
tree6137a60b29299aec1ad389945a194c556cd75289
parentd7c45e41d4a911b160d2c24c13f243d0c7de25a3 (diff)
elementary: Fix fileselector directory monitoring events
@fix
-rw-r--r--src/lib/elementary/elc_fileselector.c58
-rw-r--r--src/lib/elementary/elm_widget_fileselector.h1
2 files changed, 42 insertions, 17 deletions
diff --git a/src/lib/elementary/elc_fileselector.c b/src/lib/elementary/elc_fileselector.c
index 4c510b88ea..d3053a7dc6 100644
--- a/src/lib/elementary/elc_fileselector.c
+++ b/src/lib/elementary/elc_fileselector.c
@@ -74,12 +74,27 @@ _model_free_eo_cb(void *data)
74} 74}
75 75
76static void 76static void
77_monitoring_start(Elm_Fileselector *fs, Elm_Fileselector_Data *sd, Efl_Model *model)
78{
79 sd->monitoring = EINA_TRUE;
80 eo_event_callback_add(model, EFL_MODEL_EVENT_CHILD_ADDED, _resource_created, fs);
81 eo_event_callback_add(model, EFL_MODEL_EVENT_CHILD_REMOVED, _resource_deleted, fs);
82}
83
84static void
85_monitoring_stop(Elm_Fileselector *fs, Elm_Fileselector_Data *sd, Efl_Model *model)
86{
87 sd->monitoring = EINA_FALSE;
88 eo_event_callback_del(model, EFL_MODEL_EVENT_CHILD_ADDED, _resource_created, fs);
89 eo_event_callback_del(model, EFL_MODEL_EVENT_CHILD_REMOVED, _resource_deleted, fs);
90}
91
92static void
77_elm_fileselector_replace_model(Elm_Fileselector *fs, Elm_Fileselector_Data *sd, Efl_Model *model, const char *path) 93_elm_fileselector_replace_model(Elm_Fileselector *fs, Elm_Fileselector_Data *sd, Efl_Model *model, const char *path)
78{ 94{
79 if (sd->model) 95 if (sd->model)
80 { 96 {
81 eo_event_callback_del(sd->model, EFL_MODEL_EVENT_CHILD_ADDED, _resource_created, fs); 97 _monitoring_stop(fs, sd, sd->model);
82 eo_event_callback_del(sd->model, EFL_MODEL_EVENT_CHILD_REMOVED, _resource_deleted, fs);
83 eo_unref(sd->model); 98 eo_unref(sd->model);
84 } 99 }
85 100
@@ -87,8 +102,7 @@ _elm_fileselector_replace_model(Elm_Fileselector *fs, Elm_Fileselector_Data *sd,
87 { 102 {
88 sd->model = model ? eo_ref(model) : NULL; 103 sd->model = model ? eo_ref(model) : NULL;
89 eina_stringshare_replace(&sd->path, path); 104 eina_stringshare_replace(&sd->path, path);
90 eo_event_callback_add(sd->model, EFL_MODEL_EVENT_CHILD_ADDED, _resource_created, fs); 105 _monitoring_start(fs, sd, sd->model);
91 eo_event_callback_add(sd->model, EFL_MODEL_EVENT_CHILD_REMOVED, _resource_deleted, fs);
92 /* TODO: sub directory should be monitored for expand mode */ 106 /* TODO: sub directory should be monitored for expand mode */
93 } 107 }
94 else 108 else
@@ -902,6 +916,9 @@ _populate(Evas_Object *obj,
902 sd->current_populate_lreq = NULL; 916 sd->current_populate_lreq = NULL;
903 } 917 }
904 918
919 if (sd->model)
920 _monitoring_stop(obj, sd, sd->model);
921
905 lreq = calloc(1, sizeof (Listing_Request)); 922 lreq = calloc(1, sizeof (Listing_Request));
906 if (!lreq) return; 923 if (!lreq) return;
907 924
@@ -1660,6 +1677,9 @@ _resource_created_then(void *data, void *values)
1660 1677
1661 ELM_FILESELECTOR_DATA_GET(obj, sd); 1678 ELM_FILESELECTOR_DATA_GET(obj, sd);
1662 1679
1680 if (!sd || !sd->monitoring || sd->model != it_data->parent_model)
1681 goto cancel;
1682
1663 if (!_iterator_next_value_get(value_itt, &path) || 1683 if (!_iterator_next_value_get(value_itt, &path) ||
1664 !_iterator_next_value_get(value_itt, &filename) || 1684 !_iterator_next_value_get(value_itt, &filename) ||
1665 !path || !filename || 1685 !path || !filename ||
@@ -1669,25 +1689,17 @@ _resource_created_then(void *data, void *values)
1669 !_iterator_next_value_get(value_itt, &mime_type)) 1689 !_iterator_next_value_get(value_itt, &mime_type))
1670 { 1690 {
1671 ERR("missing Efl.Model data"); 1691 ERR("missing Efl.Model data");
1672 eo_unref(it_data->model); 1692 goto cancel;
1673 free(it_data);
1674 goto end;
1675 } 1693 }
1676 1694
1677 if (!_filter_child(sd, path, filename, dir, mime_type)) 1695 if (!_filter_child(sd, path, filename, dir, mime_type))
1678 { 1696 goto cancel;
1679 eo_unref(it_data->model);
1680 free(it_data);
1681 goto end;
1682 }
1683 1697
1684 it_data->path = eina_stringshare_add(path); 1698 it_data->path = eina_stringshare_add(path);
1685 it_data->filename = eina_stringshare_add(filename); 1699 it_data->filename = eina_stringshare_add(filename);
1686 it_data->size = size; 1700 it_data->size = size;
1687 it_data->mtime = mtime; 1701 it_data->mtime = mtime;
1688 it_data->mime_type = eina_stringshare_add(mime_type); 1702 it_data->mime_type = eina_stringshare_add(mime_type);
1689 it_data->parent_model = eo_ref(sd->model);
1690 it_data->parent_path = eina_stringshare_add(sd->path);
1691 it_data->is_dir = dir; 1703 it_data->is_dir = dir;
1692 1704
1693 if (dir) 1705 if (dir)
@@ -1710,8 +1722,15 @@ _resource_created_then(void *data, void *values)
1710 it_data, 1722 it_data,
1711 _file_grid_cmp, NULL, NULL); 1723 _file_grid_cmp, NULL, NULL);
1712 1724
1713end:
1714 eo_unref(obj); 1725 eo_unref(obj);
1726 return;
1727
1728cancel:
1729 eo_unref(obj);
1730 eo_unref(it_data->model);
1731 eo_unref(it_data->parent_model);
1732 eina_stringshare_add(it_data->parent_path);
1733 free(it_data);
1715} 1734}
1716 1735
1717static Eina_Bool 1736static Eina_Bool
@@ -1726,7 +1745,7 @@ _resource_created(void *data, const Eo_Event *event)
1726 1745
1727 ELM_FILESELECTOR_DATA_GET(fs, sd); 1746 ELM_FILESELECTOR_DATA_GET(fs, sd);
1728 1747
1729 if (sd->model != event->object) 1748 if (!sd || !sd->monitoring || sd->model != event->object)
1730 return ECORE_CALLBACK_PASS_ON; 1749 return ECORE_CALLBACK_PASS_ON;
1731 1750
1732 it_data = calloc(1, sizeof(Elm_Fileselector_Item_Data)); 1751 it_data = calloc(1, sizeof(Elm_Fileselector_Item_Data));
@@ -1735,6 +1754,8 @@ _resource_created(void *data, const Eo_Event *event)
1735 1754
1736 it_data->model = eo_ref(child); 1755 it_data->model = eo_ref(child);
1737 it_data->user_data = eo_ref(fs); 1756 it_data->user_data = eo_ref(fs);
1757 it_data->parent_model = eo_ref(sd->model);
1758 it_data->parent_path = eina_stringshare_add(sd->path);
1738 1759
1739 promises[0] = efl_model_property_get(child, "path"); 1760 promises[0] = efl_model_property_get(child, "path");
1740 promises[1] = efl_model_property_get(child, "filename"); 1761 promises[1] = efl_model_property_get(child, "filename");
@@ -1762,7 +1783,7 @@ _resource_deleted(void *data, const Eo_Event *event)
1762 1783
1763 ELM_FILESELECTOR_DATA_GET(obj, sd); 1784 ELM_FILESELECTOR_DATA_GET(obj, sd);
1764 1785
1765 if (sd->model != event->object) 1786 if (!sd || !sd->monitoring || sd->model != event->object)
1766 return ECORE_CALLBACK_PASS_ON; 1787 return ECORE_CALLBACK_PASS_ON;
1767 1788
1768 if (sd->mode == ELM_FILESELECTOR_LIST) 1789 if (sd->mode == ELM_FILESELECTOR_LIST)
@@ -1990,6 +2011,9 @@ _elm_fileselector_efl_canvas_group_group_del(Eo *obj, Elm_Fileselector_Data *sd)
1990 sd->current_populate_lreq->valid = EINA_FALSE; 2011 sd->current_populate_lreq->valid = EINA_FALSE;
1991 sd->current_populate_lreq = NULL; 2012 sd->current_populate_lreq = NULL;
1992 2013
2014 if (sd->model)
2015 _monitoring_stop(obj, sd, sd->model);
2016
1993 EINA_LIST_FREE(sd->filter_list, filter) 2017 EINA_LIST_FREE(sd->filter_list, filter)
1994 { 2018 {
1995 eina_stringshare_del(filter->filter_name); 2019 eina_stringshare_del(filter->filter_name);
diff --git a/src/lib/elementary/elm_widget_fileselector.h b/src/lib/elementary/elm_widget_fileselector.h
index c352887af8..aa167ca7af 100644
--- a/src/lib/elementary/elm_widget_fileselector.h
+++ b/src/lib/elementary/elm_widget_fileselector.h
@@ -76,6 +76,7 @@ struct _Elm_Fileselector_Data
76 Eina_Bool expand : 1; 76 Eina_Bool expand : 1;
77 Eina_Bool double_tap_navigation : 1; 77 Eina_Bool double_tap_navigation : 1;
78 Eina_Bool multi : 1; 78 Eina_Bool multi : 1;
79 Eina_Bool monitoring : 1;
79 80
80 /* this flag is only for multi selection. 81 /* this flag is only for multi selection.
81 * If this flag is set to @c EINA_TRUE, it means directory is selected 82 * If this flag is set to @c EINA_TRUE, it means directory is selected