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
43 static Elm_Genlist_Item_Class itc1 =
45 "message", { NULL, NULL, NULL, NULL}
48 static Elm_Genlist_Item_Class *itc1;
49 >>>>>>> remotes/origin/upstream
51 static const Elm_Store_Item_Mapping it1_mapping[] =
54 ELM_STORE_ITEM_MAPPING_LABEL,
55 "elm.title.1", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, from),
60 ELM_STORE_ITEM_MAPPING_LABEL,
61 "elm.title.2", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, subject),
66 ELM_STORE_ITEM_MAPPING_LABEL,
67 "elm.text", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, head_content),
72 ELM_STORE_ITEM_MAPPING_ICON,
73 "elm.swallow.icon", 0,
76 ELM_ICON_LOOKUP_THEME_FDO,
77 EINA_TRUE, EINA_FALSE,
79 EINA_FALSE, EINA_FALSE,
82 ELM_STORE_ITEM_MAPPING_CUSTOM,
87 ELM_STORE_ITEM_MAPPING_END
91 ////// **** WARNING ***********************************************************
92 //// * This function runs inside a thread outside efl mainloop. Be careful! *
93 // ************************************************************************
95 _st_store_list(void *data __UNUSED__, Elm_Store_Item_Info *item_info)
98 Elm_Store_Item_Info_Filesystem *info = (Elm_Store_Item_Info_Filesystem *)item_info;
102 // create a sort id based on the filename itself assuming it is a numeric
103 // value like the id number in mh mail folders which is what this test
104 // uses as a data source
105 char *file = strrchr(info->path, '/');
107 else file = info->path;
109 sort_id[0] = ((id >> 30) & 0x3f) + 32;
110 sort_id[1] = ((id >> 24) & 0x3f) + 32;
111 sort_id[2] = ((id >> 18) & 0x3f) + 32;
112 sort_id[3] = ((id >> 12) & 0x3f) + 32;
113 sort_id[4] = ((id >> 6) & 0x3f) + 32;
114 sort_id[5] = ((id >> 0) & 0x3f) + 32;
116 info->base.sort_id = strdup(sort_id);
117 // choose the item genlist item class to use (only item style should be
118 // provided by the app, store will fill everything else in, so it also
119 // has to be writable
120 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)
121 info->base.mapping = it1_mapping;
122 info->base.data = NULL; // if we can already parse and load all of item here and want to - set this
123 return EINA_TRUE; // return true to include this, false not to
125 Elm_Store_Item_Info_Filesystem *info = (Elm_Store_Item_Info_Filesystem *)item_info;
129 // create a sort id based on the filename itself assuming it is a numeric
130 // value like the id number in mh mail folders which is what this test
131 // uses as a data source
132 char *file = strrchr(info->path, '/');
134 else file = info->path;
136 sort_id[0] = ((id >> 30) & 0x3f) + 32;
137 sort_id[1] = ((id >> 24) & 0x3f) + 32;
138 sort_id[2] = ((id >> 18) & 0x3f) + 32;
139 sort_id[3] = ((id >> 12) & 0x3f) + 32;
140 sort_id[4] = ((id >> 6) & 0x3f) + 32;
141 sort_id[5] = ((id >> 0) & 0x3f) + 32;
143 info->base.sort_id = strdup(sort_id);
144 // choose the item genlist item class to use (only item style should be
145 // provided by the app, store will fill everything else in, so it also
146 // has to be writable
147 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)
148 info->base.mapping = it1_mapping;
149 info->base.data = NULL; // if we can already parse and load all of item here and want to - set this
150 return EINA_TRUE; // return true to include this, false not to
151 >>>>>>> remotes/origin/upstream
153 // ************************************************************************
154 //// * End of separate thread function. *
155 ////// ************************************************************************
157 ////// **** WARNING ***********************************************************
158 //// * This function runs inside a thread outside efl mainloop. Be careful! *
159 // ************************************************************************
161 _st_store_fetch(void *data __UNUSED__, Elm_Store_Item *sti)
164 const char *path = elm_store_item_filesystem_path_get(sti);
168 Eina_Bool have_content = EINA_FALSE;
169 char *content = NULL, *content_pos = NULL, *content_end = NULL;
171 // if we already have my item data - skip
172 if (elm_store_item_data_get(sti)) return;
173 // open the mail file and parse it
174 f = fopen(path, "rb");
177 // alloc my item in memory that holds data to show in the list
178 myit = calloc(1, sizeof(My_Item));
184 while (fgets(buf, sizeof(buf), f))
188 if (!isblank(buf[0]))
190 // get key: From:, Subject: etc.
191 if (!strncmp(buf, "From:", 5))
194 while ((*p) && (isblank(*p))) p++;
203 else if (!strncmp(buf, "Subject:", 8))
206 while ((*p) && (isblank(*p))) p++;
215 else if (!strncmp(buf, "Date:", 5))
218 while ((*p) && (isblank(*p))) p++;
227 else if (buf[0] == '\n') // begin of content
228 have_content = EINA_TRUE;
233 // get first 320 bytes of content/body
236 content = calloc(1, 320);
237 content_pos = content;
238 content_end = content + 319;
240 strncat(content_pos, buf, content_end - content_pos - 1);
241 content_pos = content + strlen(content);
245 myit->head_content = elm_entry_utf8_to_markup(content);
247 elm_store_item_data_set(sti, myit);
249 const char *path = elm_store_item_filesystem_path_get(sti);
253 Eina_Bool have_content = EINA_FALSE;
254 char *content = NULL, *content_pos = NULL, *content_end = NULL;
256 // if we already have my item data - skip
257 if (elm_store_item_data_get(sti)) return;
258 // open the mail file and parse it
259 f = fopen(path, "rb");
262 // alloc my item in memory that holds data to show in the list
263 myit = calloc(1, sizeof(My_Item));
269 while (fgets(buf, sizeof(buf), f))
273 if (!isblank(buf[0]))
275 // get key: From:, Subject: etc.
276 if (!strncmp(buf, "From:", 5))
279 while ((*p) && (isblank(*p))) p++;
288 else if (!strncmp(buf, "Subject:", 8))
291 while ((*p) && (isblank(*p))) p++;
300 else if (!strncmp(buf, "Date:", 5))
303 while ((*p) && (isblank(*p))) p++;
312 else if (buf[0] == '\n') // begin of content
313 have_content = EINA_TRUE;
318 // get first 320 bytes of content/body
321 content = calloc(1, 320);
322 content_pos = content;
323 content_end = content + 319;
325 strncat(content_pos, buf, content_end - content_pos - 1);
326 content_pos = content + strlen(content);
330 myit->head_content = elm_entry_utf8_to_markup(content);
332 elm_store_item_data_set(sti, myit);
333 >>>>>>> remotes/origin/upstream
335 // ************************************************************************
336 //// * End of separate thread function. *
337 ////// ************************************************************************
340 _st_store_unfetch(void *data __UNUSED__, Elm_Store_Item *sti)
343 My_Item *myit = elm_store_item_data_get(sti);
345 if (myit->from) free(myit->from);
346 if (myit->subject) free(myit->subject);
347 if (myit->date) free(myit->date);
348 if (myit->head_content) free(myit->head_content);
350 elm_store_item_data_set(sti, NULL);
352 My_Item *myit = elm_store_item_data_get(sti);
354 if (myit->from) free(myit->from);
355 if (myit->subject) free(myit->subject);
356 if (myit->date) free(myit->date);
357 if (myit->head_content) free(myit->head_content);
359 >>>>>>> remotes/origin/upstream
363 test_store(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
366 Evas_Object *win, *bg, *gl, *bx;
370 win = elm_win_add(NULL, "store", ELM_WIN_BASIC);
371 elm_win_title_set(win, "Store");
372 elm_win_autodel_set(win, EINA_TRUE);
374 bg = elm_bg_add(win);
375 elm_win_resize_object_add(win, bg);
376 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
377 evas_object_show(bg);
379 bx = elm_box_add(win);
380 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
381 elm_win_resize_object_add(win, bx);
382 evas_object_show(bx);
384 gl = elm_genlist_add(win);
385 elm_genlist_height_for_width_mode_set(gl, EINA_TRUE);
386 evas_object_smart_callback_add(gl, "selected", _st_selected, NULL);
387 evas_object_smart_callback_add(gl, "clicked,double", _st_double_clicked, NULL);
388 evas_object_smart_callback_add(gl, "longpressed", _st_longpress, NULL);
389 evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
390 evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
391 elm_box_pack_end(bx, gl);
392 evas_object_show(gl);
394 st = elm_store_filesystem_new();
395 elm_store_list_func_set(st, _st_store_list, NULL);
396 elm_store_fetch_func_set(st, _st_store_fetch, NULL);
397 //elm_store_fetch_thread_set(st, EINA_FALSE);
398 elm_store_unfetch_func_set(st, _st_store_unfetch, NULL);
399 elm_store_sorted_set(st, EINA_TRUE);
400 elm_store_target_genlist_set(st, gl);
401 elm_store_filesystem_directory_set(st, "./store");
403 evas_object_resize(win, 480, 800);
404 evas_object_show(win);
406 Evas_Object *win, *bg, *gl, *bx;
410 win = elm_win_add(NULL, "store", ELM_WIN_BASIC);
411 elm_win_title_set(win, "Store");
412 elm_win_autodel_set(win, EINA_TRUE);
414 bg = elm_bg_add(win);
415 elm_win_resize_object_add(win, bg);
416 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
417 evas_object_show(bg);
419 bx = elm_box_add(win);
420 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
421 elm_win_resize_object_add(win, bx);
422 evas_object_show(bx);
424 gl = elm_genlist_add(win);
425 elm_genlist_mode_set(gl, ELM_LIST_COMPRESS);
426 evas_object_smart_callback_add(gl, "selected", _st_selected, NULL);
427 evas_object_smart_callback_add(gl, "clicked,double", _st_double_clicked, NULL);
428 evas_object_smart_callback_add(gl, "longpressed", _st_longpress, NULL);
429 evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
430 evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
431 elm_box_pack_end(bx, gl);
432 evas_object_show(gl);
434 itc1 = elm_genlist_item_class_new();
435 itc1->item_style = "message";
437 st = elm_store_filesystem_new();
438 elm_store_list_func_set(st, _st_store_list, NULL);
439 elm_store_fetch_func_set(st, _st_store_fetch, NULL);
440 //elm_store_fetch_thread_set(st, EINA_FALSE);
441 elm_store_unfetch_func_set(st, _st_store_unfetch, NULL);
442 elm_store_sorted_set(st, EINA_TRUE);
443 elm_store_target_genlist_set(st, gl);
444 elm_store_filesystem_directory_set(st, "./store");
446 /* item_class_ref is needed for itc1. some items can be added in callbacks */
447 elm_genlist_item_class_ref(itc1);
448 elm_genlist_item_class_free(itc1);
450 evas_object_resize(win, 480, 800);
451 evas_object_show(win);
452 >>>>>>> remotes/origin/upstream