1 #include <Elementary.h>
4 # include "elementary_config.h"
6 #ifndef ELM_LIB_QUICKLAUNCH
8 typedef struct _My_Item My_Item;
12 char *from, *subject, *date, *head_content;
15 // callbacks just to see user interacting with genlist
17 _st_selected(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
19 printf("selected: %p\n", event_info);
23 _st_double_clicked(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
25 printf("double clicked: %p\n", event_info);
29 _st_longpress(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
31 printf("longpress %p\n", event_info);
34 // store callbacks to handle loading/parsing/freeing of store items from src
35 static Elm_Genlist_Item_Class itc1 =
37 "message", { NULL, NULL, NULL, NULL, NULL }, NULL
40 static const Elm_Store_Item_Mapping it1_mapping[] =
43 ELM_STORE_ITEM_MAPPING_LABEL,
44 "elm.title.1", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, from),
49 ELM_STORE_ITEM_MAPPING_LABEL,
50 "elm.title.2", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, subject),
55 ELM_STORE_ITEM_MAPPING_LABEL,
56 "elm.text", ELM_STORE_ITEM_MAPPING_OFFSET(My_Item, head_content),
61 ELM_STORE_ITEM_MAPPING_ICON,
62 "elm.swallow.icon", 0,
65 ELM_ICON_LOOKUP_THEME_FDO,
66 EINA_TRUE, EINA_FALSE,
68 EINA_FALSE, EINA_FALSE,
71 ELM_STORE_ITEM_MAPPING_CUSTOM,
76 ELM_STORE_ITEM_MAPPING_END
80 ////// **** WARNING ***********************************************************
81 //// * This function runs inside a thread outside efl mainloop. Be careful! *
82 // ************************************************************************
84 _st_store_list(void *data __UNUSED__, Elm_Store_Item_Info *item_info)
86 Elm_Store_Item_Info_Filesystem *info = (Elm_Store_Item_Info_Filesystem *)item_info;
90 // create a sort id based on the filename itself assuming it is a numeric
91 // value like the id number in mh mail folders which is what this test
92 // uses as a data source
93 char *file = strrchr(info->path, '/');
95 else file = info->path;
97 sort_id[0] = ((id >> 30) & 0x3f) + 32;
98 sort_id[1] = ((id >> 24) & 0x3f) + 32;
99 sort_id[2] = ((id >> 18) & 0x3f) + 32;
100 sort_id[3] = ((id >> 12) & 0x3f) + 32;
101 sort_id[4] = ((id >> 6) & 0x3f) + 32;
102 sort_id[5] = ((id >> 0) & 0x3f) + 32;
104 info->base.sort_id = strdup(sort_id);
105 // choose the item genlist item class to use (only item style should be
106 // provided by the app, store will fill everything else in, so it also
107 // has to be writable
108 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)
109 info->base.mapping = it1_mapping;
110 info->base.data = NULL; // if we can already parse and load all of item here and want to - set this
111 return EINA_TRUE; // return true to include this, false not to
113 // ************************************************************************
114 //// * End of separate thread function. *
115 ////// ************************************************************************
117 ////// **** WARNING ***********************************************************
118 //// * This function runs inside a thread outside efl mainloop. Be careful! *
119 // ************************************************************************
121 _st_store_fetch(void *data __UNUSED__, Elm_Store_Item *sti)
123 const char *path = elm_store_item_filesystem_path_get(sti);
127 Eina_Bool have_content = EINA_FALSE;
128 char *content = NULL, *content_pos = NULL, *content_end = NULL;
130 // if we already have my item data - skip
131 if (elm_store_item_data_get(sti)) return;
132 // open the mail file and parse it
133 f = fopen(path, "rb");
136 // alloc my item in memory that holds data to show in the list
137 myit = calloc(1, sizeof(My_Item));
143 while (fgets(buf, sizeof(buf), f))
147 if (!isblank(buf[0]))
149 // get key: From:, Subject: etc.
150 if (!strncmp(buf, "From:", 5))
153 while ((*p) && (isblank(*p))) p++;
162 else if (!strncmp(buf, "Subject:", 8))
165 while ((*p) && (isblank(*p))) p++;
174 else if (!strncmp(buf, "Date:", 5))
177 while ((*p) && (isblank(*p))) p++;
186 else if (buf[0] == '\n') // begin of content
187 have_content = EINA_TRUE;
192 // get first 320 bytes of content/body
195 content = calloc(1, 320);
196 content_pos = content;
197 content_end = content + 319;
199 strncat(content_pos, buf, content_end - content_pos - 1);
200 content_pos = content + strlen(content);
204 myit->head_content = elm_entry_utf8_to_markup(content);
206 elm_store_item_data_set(sti, myit);
208 // ************************************************************************
209 //// * End of separate thread function. *
210 ////// ************************************************************************
213 _st_store_unfetch(void *data __UNUSED__, Elm_Store_Item *sti)
215 My_Item *myit = elm_store_item_data_get(sti);
217 if (myit->from) free(myit->from);
218 if (myit->subject) free(myit->subject);
219 if (myit->date) free(myit->date);
220 if (myit->head_content) free(myit->head_content);
222 elm_store_item_data_set(sti, NULL);
226 test_store(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
228 Evas_Object *win, *bg, *gl, *bx;
232 win = elm_win_add(NULL, "store", ELM_WIN_BASIC);
233 elm_win_title_set(win, "Store");
234 elm_win_autodel_set(win, 1);
236 bg = elm_bg_add(win);
237 elm_win_resize_object_add(win, bg);
238 evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
239 evas_object_show(bg);
241 bx = elm_box_add(win);
242 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
243 elm_win_resize_object_add(win, bx);
244 evas_object_show(bx);
246 gl = elm_genlist_add(win);
247 elm_genlist_height_for_width_mode_set(gl, EINA_TRUE);
248 evas_object_smart_callback_add(gl, "selected", _st_selected, NULL);
249 evas_object_smart_callback_add(gl, "clicked,double", _st_double_clicked, NULL);
250 evas_object_smart_callback_add(gl, "longpressed", _st_longpress, NULL);
251 evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
252 evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
253 elm_box_pack_end(bx, gl);
254 evas_object_show(gl);
256 st = elm_store_filesystem_new();
257 elm_store_list_func_set(st, _st_store_list, NULL);
258 elm_store_fetch_func_set(st, _st_store_fetch, NULL);
259 //elm_store_fetch_thread_set(st, EINA_FALSE);
260 elm_store_unfetch_func_set(st, _st_store_unfetch, NULL);
261 elm_store_sorted_set(st, EINA_TRUE);
262 elm_store_target_genlist_set(st, gl);
263 elm_store_filesystem_directory_set(st, "./store");
265 evas_object_resize(win, 480, 800);
266 evas_object_show(win);