summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hollerbach <marcel-hollerbach@t-online.de>2014-12-06 13:37:54 +0100
committerMarcel Hollerbach <marcel-hollerbach@t-online.de>2014-12-06 13:37:54 +0100
commit75279eeb0f4e70b13150f777410d39ff3a26ab08 (patch)
treebc8752eae1a56169e44cda7f687c041a35e0fef9
parentb7707366877610e5b844d624c2bccbaa40b6d15c (diff)
Implemented searching!
The search "algorithmen" is very very poor right now, if there is one with a better one, you are welcome :)
-rw-r--r--src/elm_settingspane.c222
1 files changed, 220 insertions, 2 deletions
diff --git a/src/elm_settingspane.c b/src/elm_settingspane.c
index eb1db8c..c6ae73b 100644
--- a/src/elm_settingspane.c
+++ b/src/elm_settingspane.c
@@ -28,6 +28,14 @@ typedef struct
28 Eina_List *stack; 28 Eina_List *stack;
29 29
30 Elm_Genlist_Item_Class *itcc; // , *itci; 30 Elm_Genlist_Item_Class *itcc; // , *itci;
31
32 struct
33 {
34 Eina_Bool on;
35 Evas_Object *display;
36 Ecore_Thread *run;
37 const char* keyword;
38 } search;
31} Elm_Settingspane_Data; 39} Elm_Settingspane_Data;
32 40
33typedef struct 41typedef struct
@@ -62,9 +70,17 @@ typedef struct _Stack_Item
62 Elm_Object_Item *current; 70 Elm_Object_Item *current;
63} Stack_Item; 71} Stack_Item;
64 72
73typedef struct _Search_Run
74{
75 Eina_List *results;
76 Elm_Settingspane_Data *data;
77 const char *keyword;
78} Search_Run;
79
65static void _item_sel_cb(void *data, Evas_Object *obj, void *event_info); 80static void _item_sel_cb(void *data, Evas_Object *obj, void *event_info);
66static Eina_Bool _item_stack_pop(Elm_Settingspane *pane); 81static Eina_Bool _item_stack_pop(Elm_Settingspane *pane);
67static void _item_stack_remove(Elm_Settingspane_Item *del); 82static void _item_stack_remove(Elm_Settingspane_Item *del);
83static void _search_panel_stop(Evas_Object *w);
68 84
69#define HAS_PANEL(id) (id->panel.content_get) 85#define HAS_PANEL(id) (id->panel.content_get)
70/* Data Keys in the layouts, DK = Data Key */ 86/* Data Keys in the layouts, DK = Data Key */
@@ -87,6 +103,9 @@ static void _item_stack_remove(Elm_Settingspane_Item *del);
87#define DK_MENU_GENLIST "__menu_genlist" 103#define DK_MENU_GENLIST "__menu_genlist"
88#define DK_MENU_ITEM_SHOWN "__showed_item" 104#define DK_MENU_ITEM_SHOWN "__showed_item"
89 105
106#define DK_SEARCH_LABEL "__search_label"
107#define DK_SEARCH_GRID "__search_results"
108
90/* Layout positions */ 109/* Layout positions */
91 110
92#define POS_PANEL_PAD "conf.pad" 111#define POS_PANEL_PAD "conf.pad"
@@ -115,7 +134,6 @@ static void _item_stack_remove(Elm_Settingspane_Item *del);
115#define EMIT_CONTENT_VISIBLE "state,visible", EMITTER 134#define EMIT_CONTENT_VISIBLE "state,visible", EMITTER
116#define EMIT_CONTENT_HIGHLIGHT "state,highlight", EMITTER 135#define EMIT_CONTENT_HIGHLIGHT "state,highlight", EMITTER
117 136
118
119static void 137static void
120conf_menu_back_cb(void *data EINA_UNUSED, Evas_Object *obj, const char *emission EINA_UNUSED, const char *source EINA_UNUSED) 138conf_menu_back_cb(void *data EINA_UNUSED, Evas_Object *obj, const char *emission EINA_UNUSED, const char *source EINA_UNUSED)
121{ 139{
@@ -124,7 +142,11 @@ conf_menu_back_cb(void *data EINA_UNUSED, Evas_Object *obj, const char *emission
124 * FIXME: For menu cb, we need a new stack method here which pop to the next menu entry!!! 142 * FIXME: For menu cb, we need a new stack method here which pop to the next menu entry!!!
125 * 143 *
126 */ 144 */
127 _item_stack_pop(obj); 145 Elm_Settingspane_Data *wd = eo_data_scope_get(obj, ELM_SETTINGSPANE_CLASS);
146 if (wd->search.on)
147 _search_panel_stop(obj);
148 else
149 _item_stack_pop(obj);
128} 150}
129 151
130/* 152/*
@@ -947,6 +969,201 @@ _item_sel_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNU
947 return; 969 return;
948 _item_stack_push_to_item(id->sw, selected); 970 _item_stack_push_to_item(id->sw, selected);
949} 971}
972/*
973 * Seachbar stuff
974 */
975
976static void
977_search_panel_display(Evas_Object *w)
978{
979 Evas_Object *o, *l, *g;
980 Elm_Settingspane_Data *id = eo_data_scope_get(w, ELM_SETTINGSPANE_CLASS);
981
982 o = elm_box_add(w);
983 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
984 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL);
985 id->search.display = o;
986 evas_object_show(o);
987
988 l = elm_label_add(w);
989 evas_object_size_hint_weight_set(l, EVAS_HINT_EXPAND, 0.0);
990 evas_object_size_hint_align_set(l, EVAS_HINT_FILL, EVAS_HINT_FILL);
991 evas_object_data_set(o, DK_SEARCH_LABEL, l);
992 elm_box_pack_end(o, l);
993 evas_object_show(l);
994
995 g = elm_gengrid_add(w);
996 elm_gengrid_item_size_set(g, 150, 150);
997 evas_object_size_hint_weight_set(g, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
998 evas_object_size_hint_align_set(g, EVAS_HINT_FILL, EVAS_HINT_FILL);
999 evas_object_data_set(o, DK_SEARCH_GRID, g);
1000 elm_box_pack_end(o, g);
1001 evas_object_show(g);
1002
1003 _content_layout_display(w, o);
1004 _menu_layout_hide(w);
1005}
1006
1007static void
1008_search_panel_hide(Evas_Object *w)
1009{
1010 Elm_Settingspane_Item *item;
1011
1012 item = _stack_item_current_get(w);
1013 _menu_layout_restore(w);
1014 if (_item_has_panel(item))
1015 _content_layout_content_set(w, item);
1016 else
1017 _content_layout_content_hide(w);
1018}
1019
1020static void
1021_search_panel_stop(Evas_Object *w)
1022{
1023 Elm_Settingspane_Data *wd = eo_data_scope_get(w, ELM_SETTINGSPANE_CLASS);
1024 _search_panel_hide(w);
1025 wd->search.on = EINA_FALSE;
1026 ecore_thread_cancel(wd->search.run);
1027}
1028
1029static char*
1030_search_grid_label_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
1031{
1032 Elm_Settingspane_Item_Data *id = eo_data_scope_get(data, ELM_SETTINGSPANE_ITEM_CLASS);
1033
1034 return strdup(id->name);
1035}
1036
1037
1038static Evas_Object*
1039_search_grid_content_get(void *data, Evas_Object *obj EINA_UNUSED, const char *part EINA_UNUSED)
1040{
1041 Elm_Settingspane_Item_Data *id = eo_data_scope_get(data, ELM_SETTINGSPANE_ITEM_CLASS);
1042 if (!strcmp(part, "elm.swallow.icon"))
1043 return id->icon;
1044 else
1045 return NULL;
1046}
1047
1048static void
1049_search_grid_item_sel(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
1050{
1051 Elm_Settingspane_Item *it = data;
1052 Elm_Settingspane_Item_Data *id = eo_data_scope_get(it, ELM_SETTINGSPANE_ITEM_CLASS);
1053 _search_panel_stop(id->sw);
1054 eo_do(it, elm_obj_settingspane_item_focus());
1055}
1056
1057static void *
1058_search_display_items(void *data)
1059{
1060 Search_Run *sr = data;
1061 Eina_List *node;
1062 Elm_Settingspane_Item *it;
1063 Elm_Gengrid_Item_Class *gic = NULL;
1064 Evas_Object *grid = evas_object_data_get(sr->data->search.display,
1065 DK_SEARCH_GRID);
1066
1067 elm_gengrid_clear(grid);
1068
1069 gic = elm_gengrid_item_class_new();
1070 gic->item_style = "default";
1071 gic->func.text_get = _search_grid_label_get;
1072 gic->func.content_get = _search_grid_content_get;
1073
1074 EINA_LIST_FOREACH(sr->results, node, it)
1075 {
1076 elm_gengrid_item_append(grid, gic, it, _search_grid_item_sel, it);
1077 }
1078
1079 return NULL;
1080}
1081
1082/*
1083 * !!!This code runs in a seperated thread!!!
1084 */
1085static void
1086_search_tree(Elm_Settingspane_Item *it, Eina_List **results, const char *keyword)
1087{
1088 Elm_Settingspane_Item_Data *id = eo_data_scope_get(it, ELM_SETTINGSPANE_ITEM_CLASS);
1089 Eina_List *node;
1090 Elm_Settingspane_Item *item;
1091
1092 if (eina_str_has_prefix(id->name, keyword))
1093 {
1094 *results = eina_list_append(*results, it);
1095 }
1096
1097 EINA_LIST_FOREACH(id->childs, node ,item)
1098 _search_tree(item, results, keyword);
1099}
1100
1101static void
1102_search_cb(void *data, Ecore_Thread *th)
1103{
1104 Search_Run *sr = data;
1105
1106 _search_tree(sr->data->zero, &(sr->results), sr->keyword);
1107
1108 if (ecore_thread_check(th))
1109 return;
1110
1111 ecore_main_loop_thread_safe_call_sync(_search_display_items, sr);
1112}
1113/*
1114 * END OF !!!This code runs in a seperated thread!!!
1115 */
1116
1117static void
1118_search_cb_ended(void *data, Ecore_Thread *th EINA_UNUSED)
1119{
1120 Search_Run *sr = data;
1121
1122 sr->data->search.run = NULL;
1123 free(sr);
1124}
1125
1126
1127static void
1128_search_panel_search_string_update(Evas_Object *w, const char *word)
1129{
1130 char buf[PATH_MAX];
1131 Search_Run *sr;
1132 Elm_Settingspane_Data *wd = eo_data_scope_get(w, ELM_SETTINGSPANE_CLASS);
1133 Evas_Object *l = evas_object_data_get(wd->search.display, DK_SEARCH_LABEL);
1134
1135 sr = calloc(1, sizeof(sr));
1136 sr->keyword = word;
1137 sr->data = wd;
1138
1139 snprintf(buf, sizeof(buf), "Search results for \"%s\": ", word);
1140 elm_object_text_set(l, buf);
1141
1142 if (wd->search.run)
1143 ecore_thread_cancel(wd->search.run);
1144 wd->search.run = ecore_thread_run(_search_cb, _search_cb_ended, NULL, sr);
1145}
1146
1147static void
1148_search_entry_changed(void *data, Evas_Object *obj, void *event_info EINA_UNUSED)
1149{
1150 Evas_Object *w = data;
1151 Elm_Settingspane_Data *id = eo_data_scope_get(data, ELM_SETTINGSPANE_CLASS);
1152 const char *edit;
1153
1154 if (!id->search.on)
1155 {
1156 id->search.on = EINA_TRUE;
1157 _search_panel_display(w);
1158 }
1159
1160 edit = elm_object_text_get(obj);
1161
1162 if (!strcmp(edit, ""))
1163 _search_panel_stop(w);
1164 else
1165 _search_panel_search_string_update(w, edit);
1166}
950 1167
951EOLIAN static void 1168EOLIAN static void
952_elm_settingspane_evas_object_smart_add(Eo *obj, Elm_Settingspane_Data *pd) 1169_elm_settingspane_evas_object_smart_add(Eo *obj, Elm_Settingspane_Data *pd)
@@ -977,6 +1194,7 @@ _elm_settingspane_evas_object_smart_add(Eo *obj, Elm_Settingspane_Data *pd)
977 en = elm_entry_add(obj); 1194 en = elm_entry_add(obj);
978 elm_entry_single_line_set(en, EINA_TRUE); 1195 elm_entry_single_line_set(en, EINA_TRUE);
979 elm_entry_scrollable_set(en, EINA_TRUE); 1196 elm_entry_scrollable_set(en, EINA_TRUE);
1197 evas_object_smart_callback_add(en, "changed", _search_entry_changed, obj);
980 elm_object_part_text_set(en, "guide", "Search"); 1198 elm_object_part_text_set(en, "guide", "Search");
981 elm_object_part_content_set(obj, POS_MAIN_SEARCH, en); 1199 elm_object_part_content_set(obj, POS_MAIN_SEARCH, en);
982 evas_object_show(en); 1200 evas_object_show(en);