1 /* NOTE : Before testing elm_store,
2 email data files should exist in your local storage.
3 And you can just get example files in enlightenment website.
4 Use wget to obtain it. It almost 50 Megabytes.
5 http://www.enlightenment.org/~raster/store.tar.gz
8 #include <Elementary.h>
11 # include "elementary_config.h"
13 #ifndef ELM_LIB_QUICKLAUNCH
15 typedef struct _My_Item My_Item;
19 char *from, *subject, *date, *head_content;
22 // callbacks just to see user interacting with genlist
24 _st_selected(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
26 printf("selected: %p\n", event_info);
30 _st_double_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
32 printf("double clicked: %p\n", event_info);
36 _st_longpress(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
38 printf("longpress %p\n", event_info);
41 // store callbacks to handle loading/parsing/freeing of store items from src
42 static Elm_Genlist_Item_Class itc1 =
44 "message", { NULL, NULL, NULL, NULL}
47 static const Elm_Store_Item_Mapping it1_mapping[] =
50 ELM_STORE_ITEM_MAPPING_LABEL,
51 "elm.title.1", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, from),
56 ELM_STORE_ITEM_MAPPING_LABEL,
57 "elm.title.2", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, subject),
62 ELM_STORE_ITEM_MAPPING_LABEL,
63 "elm.text", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, head_content),
68 ELM_STORE_ITEM_MAPPING_ICON,
69 "elm.swallow.icon", 0,
72 ELM_ICON_LOOKUP_THEME_FDO,
73 EINA_TRUE, EINA_FALSE,
75 EINA_FALSE, EINA_FALSE,
78 ELM_STORE_ITEM_MAPPING_CUSTOM,
83 ELM_STORE_ITEM_MAPPING_END
87 ////// **** WARNING ***********************************************************
88 //// * This function runs inside a thread outside efl mainloop. Be careful! *
89 // ************************************************************************
91 _st_store_list(void *data __UNUSED__, Elm_Store_Item_Info *item_info)
93 Elm_Store_Item_Info_Filesystem *info = (Elm_Store_Item_Info_Filesystem *)item_info;
97 // create a sort id based on the filename itself assuming it is a numeric
98 // value like the id number in mh mail folders which is what this test
99 // uses as a data source
100 char *file = strrchr(info->path, '/');
102 else file = info->path;
104 sort_id[0] = ((id >> 30) & 0x3f) + 32;
105 sort_id[1] = ((id >> 24) & 0x3f) + 32;
106 sort_id[2] = ((id >> 18) & 0x3f) + 32;
107 sort_id[3] = ((id >> 12) & 0x3f) + 32;
108 sort_id[4] = ((id >> 6) & 0x3f) + 32;
109 sort_id[5] = ((id >> 0) & 0x3f) + 32;
111 info->base.sort_id = strdup(sort_id);
112 // choose the item genlist item class to use (only item style should be
113 // provided by the app, store will fill everything else in, so it also
114 // has to be writable
115 info->base.item_class = &itc1; // based on item info - return the item class wanted (only style field used - rest reset to internal funcs store sets up to get label/icon etc)
116 info->base.mapping = it1_mapping;
117 info->base.data = NULL; // if we can already parse and load all of item here and want to - set this
118 return EINA_TRUE; // return true to include this, false not to
120 // ************************************************************************
121 //// * End of separate thread function. *
122 ////// ************************************************************************
124 ////// **** WARNING ***********************************************************
125 //// * This function runs inside a thread outside efl mainloop. Be careful! *
126 // ************************************************************************
128 _st_store_fetch(void *data __UNUSED__, Elm_Store_Item *sti)
130 const char *path = elm_store_item_filesystem_path_get(sti);
134 Eina_Bool have_content = EINA_FALSE;
135 char *content = NULL, *content_pos = NULL, *content_end = NULL;
137 // if we already have my item data - skip
138 if (elm_store_item_data_get(sti)) return;
139 // open the mail file and parse it
140 f = fopen(path, "rb");
143 // alloc my item in memory that holds data to show in the list
144 myit = calloc(1, sizeof(My_Item));
150 while (fgets(buf, sizeof(buf), f))
154 if (!isblank(buf[0]))
156 // get key: From:, Subject: etc.
157 if (!strncmp(buf, "From:", 5))
160 while ((*p) && (isblank(*p))) p++;
169 else if (!strncmp(buf, "Subject:", 8))
172 while ((*p) && (isblank(*p))) p++;
181 else if (!strncmp(buf, "Date:", 5))
184 while ((*p) && (isblank(*p))) p++;
193 else if (buf[0] == '\n') // begin of content
194 have_content = EINA_TRUE;
199 // get first 320 bytes of content/body
202 content = calloc(1, 320);
203 content_pos = content;
204 content_end = content + 319;
206 strncat(content_pos, buf, content_end - content_pos - 1);
207 content_pos = content + strlen(content);
211 myit->head_content = elm_entry_utf8_to_markup(content);
213 elm_store_item_data_set(sti, myit);
215 // ************************************************************************
216 //// * End of separate thread function. *
217 ////// ************************************************************************
220 _st_store_unfetch(void *data __UNUSED__, Elm_Store_Item *sti)
222 My_Item *myit = elm_store_item_data_get(sti);
224 if (myit->from) free(myit->from);
225 if (myit->subject) free(myit->subject);
226 if (myit->date) free(myit->date);
227 if (myit->head_content) free(myit->head_content);
229 elm_store_item_data_set(sti, NULL);
233 test_store(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
235 Evas_Object *win, *bg, *gl, *bx;
239 win = elm_win_add(NULL, "store", ELM_WIN_BASIC);
240 elm_win_title_set(win, "Store");
241 elm_win_autodel_set(win, EINA_TRUE);
243 bg = elm_bg_add(win);
244 elm_win_resize_object_add(win, bg);
245 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
246 evas_object_show(bg);
248 bx = elm_box_add(win);
249 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
250 elm_win_resize_object_add(win, bx);
251 evas_object_show(bx);
253 gl = elm_genlist_add(win);
254 elm_genlist_height_for_width_mode_set(gl, EINA_TRUE);
255 evas_object_smart_callback_add(gl, "selected", _st_selected, NULL);
256 evas_object_smart_callback_add(gl, "clicked,double", _st_double_clicked, NULL);
257 evas_object_smart_callback_add(gl, "longpressed", _st_longpress, NULL);
258 evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
259 evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
260 elm_box_pack_end(bx, gl);
261 evas_object_show(gl);
263 st = elm_store_filesystem_new();
264 elm_store_list_func_set(st, _st_store_list, NULL);
265 elm_store_fetch_func_set(st, _st_store_fetch, NULL);
266 //elm_store_fetch_thread_set(st, EINA_FALSE);
267 elm_store_unfetch_func_set(st, _st_store_unfetch, NULL);
268 elm_store_sorted_set(st, EINA_TRUE);
269 elm_store_target_genlist_set(st, gl);
270 elm_store_filesystem_directory_set(st, "./store");
272 evas_object_resize(win, 480, 800);
273 evas_object_show(win);