4 #include "xcnphandler.h"
5 #include "clipdrawer.h"
7 #define DELETE_ICON_PATH "/usr/share/icon/cbhm/05_delete.png"
8 #define IM "/opt/media/Images and videos/My photo clips/"
9 static const char *g_images_path[] = {
21 #define GRID_ITEM_SIZE 100
23 static int g_clipdrawer_mode = 0;
24 // gic should live at gengrid callback functions
25 Elm_Gengrid_Item_Class gic;
27 typedef struct tag_gridimgitem
29 Elm_Gengrid_Item *item;
34 static int toggle_clipdrawer_mode()
36 g_clipdrawer_mode = !g_clipdrawer_mode;
37 return g_clipdrawer_mode;
40 static int get_clipdrawer_mode()
42 return g_clipdrawer_mode;
45 static void _list_longpress(void *data, Evas_Object *obj, void *event_info)
47 struct appdata *ad = data;
49 clipdrawer_change_mode(ad);
52 static void _list_click_paste(void *data, Evas_Object *obj, void *event_info)
54 struct appdata *ad = data;
55 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
59 elm_list_item_selected_set(it, 0);
65 cpdata = elm_list_item_label_get(it);
68 cplen = strlen(cpdata);
69 p = malloc(cplen + 1);
70 snprintf(p, cplen+1, "%s", cpdata);
71 elm_selection_set(1, obj, /*ELM_SEL_FORMAT_TEXT*/1, p);
72 // elm_selection_set(1, obj, /*ELM_SEL_FORMAT_MARKUP*/2, p);
74 // clipdrawer_lower_view(ad);
77 static void _list_del_response_cb(void *data, Evas_Object *obj, void *event_info)
79 Elm_List_Item *it = (Elm_List_Item *)data;
82 if((int)event_info == ELM_POPUP_RESPONSE_OK)
83 elm_list_item_del(it);
86 static void _list_click_delete(void *data, Evas_Object *obj, void *event_info)
88 struct appdata *ad = data;
89 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
93 elm_list_item_selected_set(it, 0);
95 Evas_Object *popup = elm_popup_add(ad->win_main);
96 elm_popup_timeout_set(popup, 3);
97 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
98 elm_popup_desc_set(popup, "Are you sure delete this?");
99 elm_popup_buttons_add(popup, 2,
100 "Yes", ELM_POPUP_RESPONSE_OK,
101 "No", ELM_POPUP_RESPONSE_CANCEL,
103 evas_object_smart_callback_add(popup, "response", _list_del_response_cb, it);
104 evas_object_show(popup);
106 // char *slabel = NULL;
107 // slabel = elm_list_item_label_get(it);
110 int clipdrawer_update_contents(void *data)
112 struct appdata *ad = data;
115 // if delete mode, then back to normal mode
116 if (get_clipdrawer_mode())
117 clipdrawer_change_mode(ad);
119 elm_list_clear(ad->txtlist);
120 for (i = 0; i < HISTORY_QUEUE_MAX_TXT_ITEMS; i++)
122 pos = get_current_history_position()+i;
123 if (pos > HISTORY_QUEUE_MAX_TXT_ITEMS-1)
124 pos = pos-HISTORY_QUEUE_MAX_TXT_ITEMS;
125 if (get_item_contents_by_pos(pos) != NULL && strlen(get_item_contents_by_pos(pos)) > 0)
127 elm_list_item_append(ad->txtlist, get_item_contents_by_pos(pos), NULL, NULL, NULL, ad);
130 elm_list_go(ad->txtlist);
132 /* FIXME : sometimes when list update, screen isn't updated */
137 const char* clipdrawer_get_plain_string_from_escaped(char *escstr)
139 /* TODO : is it should be here? besides, remove dependency for entry */
140 /* NOTE : return string should be freed */
141 return elm_entry_markup_to_utf8(escstr);
144 Evas_Object* _grid_icon_get(const void *data, Evas_Object *obj, const char *part)
146 int delete_mode = get_clipdrawer_mode();
147 gridimgitem_t *ti = (gridimgitem_t *)data;
148 if (!strcmp(part, "elm.swallow.icon"))
150 Evas_Object *icon = elm_icon_add(obj);
151 elm_icon_file_set(icon, ti->path, NULL);
152 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
153 evas_object_show(icon);
156 else if (!strcmp(part, "elm.swallow.end") && delete_mode)
158 ti->delbtn = elm_check_add(obj);
159 elm_object_style_set(ti->delbtn, "extended/imagegrid");
160 elm_check_state_set(ti->delbtn, 1);
161 evas_object_show(ti->delbtn);
168 static void _grid_longpress(void *data, Evas_Object *obj, void *event_info)
170 struct appdata *ad = data;
171 clipdrawer_change_mode(ad);
175 static void _grid_click_paste(void *data, Evas_Object *obj, void *event_info)
177 struct appdata *ad = data;
180 Elm_Gengrid_Item *sgobj = NULL;
181 sgobj = elm_gengrid_selected_item_get(ad->imggrid);
182 gridimgitem_t *ti = NULL;
183 ti = elm_gengrid_item_data_get(sgobj);
187 DTRACE("ERR: cbhm can't get the selected image\n");
190 len = strlen(ti->path);
191 p = malloc(len + 10);
192 snprintf(p,len+10, "file:///%s", ti->path);
194 elm_selection_set(/*secondary*/1,obj,/*ELM_SEL_FORMAT_IMAGE*/4,p);
196 // clipdrawer_lower_view(ad);
198 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
201 static void _grid_del_response_cb(void *data, Evas_Object *obj, void *event_info)
203 Elm_Gengrid_Item *it = (Elm_Gengrid_Item *)data;
204 evas_object_del(obj);
206 if((int)event_info == ELM_POPUP_RESPONSE_OK)
207 elm_gengrid_item_del(it);
210 static void _grid_click_delete(void *data, Evas_Object *obj, void *event_info)
212 struct appdata *ad = data;
213 Elm_Gengrid_Item *sgobj = NULL;
214 sgobj = elm_gengrid_selected_item_get(ad->imggrid);
215 gridimgitem_t *ti = NULL;
216 ti = elm_gengrid_item_data_get(sgobj);
220 DTRACE("ERR: cbhm can't get the clicked del image\n");
224 Evas_Object *popup = elm_popup_add(ad->win_main);
225 elm_popup_timeout_set(popup, 3);
226 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227 elm_popup_desc_set(popup, "Are you sure delete this?");
228 elm_popup_buttons_add(popup, 2,
229 "Yes", ELM_POPUP_RESPONSE_OK,
230 "No", ELM_POPUP_RESPONSE_CANCEL,
232 evas_object_smart_callback_add(popup, "response", _grid_del_response_cb, sgobj);
233 evas_object_show(popup);
236 void _grid_del(const void *data, Evas_Object *obj)
238 gridimgitem_t *ti = (gridimgitem_t *)data;
239 eina_stringshare_del(ti->path);
243 int clipdrawer_refresh_imghistory_item(void *data, int delete_mode)
245 struct appdata *ad = data;
246 Eina_List *oldlist = NULL;
248 Elm_Gengrid_Item *lgrid;
249 gridimgitem_t *lgitem;
253 oldlist = elm_gengrid_items_get(ad->imggrid);
254 elm_layout_content_unset(ad->ly_main, "imagehistory/list");
255 ngg = elm_gengrid_add(ad->win_main);
256 elm_layout_content_set(ad->ly_main, "imagehistory/list", ngg);
259 elm_gengrid_item_size_set(ad->imggrid, GRID_ITEM_SIZE, GRID_ITEM_SIZE+3);
260 elm_gengrid_align_set(ad->imggrid, 0.0, 0.0);
261 elm_gengrid_horizontal_set(ad->imggrid, EINA_TRUE);
262 elm_gengrid_bounce_set(ad->imggrid, EINA_TRUE, EINA_FALSE);
263 elm_gengrid_multi_select_set(ad->imggrid, EINA_FALSE);
265 evas_object_smart_callback_add(ad->imggrid, "selected", _grid_click_delete, ad);
267 evas_object_smart_callback_add(ad->imggrid, "selected", _grid_click_paste, ad);
268 evas_object_smart_callback_add(ad->imggrid, "longpressed", _grid_longpress, ad);
269 evas_object_size_hint_weight_set(ad->imggrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
271 gic.item_style = "default_grid";
272 gic.func.label_get = NULL;
273 gic.func.icon_get = _grid_icon_get;
274 gic.func.state_get = NULL;
275 gic.func.del = _grid_del;
277 EINA_LIST_REVERSE_FOREACH(oldlist, l, lgrid)
279 lgitem = elm_gengrid_item_data_get(lgrid);
280 clipdrawer_add_image_item(lgitem->path);
283 evas_object_show (ad->imggrid);
285 elm_gengrid_clear(oldgg);
286 evas_object_hide(oldgg);
287 evas_object_del(oldgg);
292 int clipdrawer_refresh_txthistory_item(void *data, int delete_mode)
294 struct appdata *ad = data;
295 Eina_List *oldlist = NULL;
297 Elm_List_Item *litem;
299 Evas_Object *ntl = NULL;
300 // Evas_Object *ci = NULL;
302 oldlist = elm_list_items_get(ad->txtlist);
303 elm_layout_content_unset(ad->ly_main, "texthistory/list");
304 ntl = elm_list_add(ad->win_main);
305 elm_layout_content_set(ad->ly_main, "texthistory/list", ntl);
306 elm_object_style_set(ntl, "extended/historylist");
308 EINA_LIST_FOREACH(oldlist, l, litem)
310 ltext = elm_list_item_label_get(litem);
313 Evas_Object *ci = elm_icon_add(ad->win_main);
314 elm_icon_file_set(ci, DELETE_ICON_PATH, NULL);
315 evas_object_size_hint_min_set(ci, 33 * elm_scale_get(), 33 * elm_scale_get());
316 // evas_object_size_hint_aspect_set(ci, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
317 evas_object_show(ci);
318 elm_list_item_append(ntl, ltext, NULL, ci, NULL, ad);
322 elm_list_item_append(ntl, ltext, NULL, NULL, NULL, ad);
326 elm_list_clear(ad->txtlist);
327 evas_object_hide(ad->txtlist);
328 evas_object_del(ad->txtlist);
331 evas_object_size_hint_weight_set(ad->txtlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
333 evas_object_smart_callback_add(ad->txtlist, "selected", _list_click_delete, ad);
335 evas_object_smart_callback_add(ad->txtlist, "selected", _list_click_paste, ad);
336 evas_object_smart_callback_add(ad->txtlist, "longpressed", _list_longpress, ad);
338 elm_list_go(ad->txtlist);
343 int clipdrawer_change_mode(void *data)
345 struct appdata *ad = data;
347 toggle_clipdrawer_mode();
349 DTRACE("clipdrawer delete mode = %d\n", get_clipdrawer_mode());
351 clipdrawer_refresh_imghistory_item(ad, get_clipdrawer_mode());
352 clipdrawer_refresh_txthistory_item(ad, get_clipdrawer_mode());
357 // FIXME: how to remove calling g_get_main_appdata()?
358 // it's mainly used at 'clipdrawer_add_image_item'
359 int clipdrawer_add_image_item(char *imagepath)
361 struct appdata *ad = g_get_main_appdata();
362 gridimgitem_t *newgenimg = NULL;
363 char* filepath = NULL;
364 Eina_List *igl = NULL;
365 unsigned int igl_counter = 0;
367 // if delete mode, then back to normal mode
368 if (get_clipdrawer_mode())
369 clipdrawer_change_mode(ad);
371 if (!check_regular_file(imagepath))
373 DTRACE("Error : it isn't normal file = %s\n", imagepath);
377 igl = elm_gengrid_items_get(ad->imggrid);
378 igl_counter = eina_list_count(igl);
379 if (igl_counter >= HISTORY_QUEUE_MAX_IMG_ITEMS)
381 elm_gengrid_item_del(eina_list_data_get(eina_list_last(igl)));
384 newgenimg = malloc(sizeof(gridimgitem_t));
385 newgenimg->path = eina_stringshare_add(imagepath);
386 newgenimg->item = elm_gengrid_item_prepend(ad->imggrid, &gic, newgenimg, NULL, NULL);
392 clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
394 struct appdata *ad = data;
396 #define EDJE_CLOSE_PART_PREFIX "closebutton/"
397 if (!strncmp(source, EDJE_CLOSE_PART_PREFIX, strlen(EDJE_CLOSE_PART_PREFIX)))
399 clipdrawer_lower_view(ad);
403 int clipdrawer_init(void *data)
405 struct appdata *ad = data;
408 // for elm_check, elm_list
409 elm_theme_extension_add(NULL, APP_EDJ_FILE);
411 cdy = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
412 cdw = (1.0*CLIPDRAWER_POS_Y/SCREEN_HEIGHT)*ad->root_h;
414 evas_object_resize(ad->win_main, ad->root_w, (int)cdy);
415 evas_object_move(ad->win_main, CLIPDRAWER_POS_X, (int)cdw);
416 evas_object_resize(ad->ly_main, ad->root_w, (int)cdy);
417 evas_object_move(ad->ly_main, CLIPDRAWER_POS_X, (int)cdw);
419 edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main), "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
422 ad->imggrid = elm_gengrid_add(ad->win_main);
423 elm_layout_content_set(ad->ly_main, "imagehistory/list", ad->imggrid);
424 elm_gengrid_item_size_set(ad->imggrid, GRID_ITEM_SIZE, GRID_ITEM_SIZE+3);
425 elm_gengrid_align_set(ad->imggrid, 0.0, 0.0);
426 elm_gengrid_horizontal_set(ad->imggrid, EINA_TRUE);
427 elm_gengrid_bounce_set(ad->imggrid, EINA_TRUE, EINA_FALSE);
428 elm_gengrid_multi_select_set(ad->imggrid, EINA_FALSE);
429 evas_object_smart_callback_add(ad->imggrid, "selected", _grid_click_paste, ad);
430 evas_object_smart_callback_add(ad->imggrid, "longpressed", _grid_longpress, ad);
431 evas_object_size_hint_weight_set(ad->imggrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
433 elm_gengrid_clear(ad->imggrid);
435 gic.item_style = "default_grid";
436 gic.func.label_get = NULL;
437 gic.func.icon_get = _grid_icon_get;
438 gic.func.state_get = NULL;
439 gic.func.del = _grid_del;
442 gridimgitem_t *newgenimg;
444 for (i = 0; i < N_IMAGES; i++)
446 clipdrawer_add_image_item(g_images_path[i]);
449 evas_object_show (ad->imggrid);
451 // for debugging, calc image history pos
453 Evas_Coord x, y, w, h;
454 Evas_Coord vx, vy, vw, vh;
456 edje_object_part_geometry_get(elm_layout_edje_get(ad->ly_main),"imagehistory/list",&x,&y,&w,&h);
457 evas_object_geometry_get (ad->imggrid, &vx,&vy,&vw,&vh);
458 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
459 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
462 ad->txtlist = elm_list_add(ad->win_main);
463 elm_layout_content_set(ad->ly_main, "texthistory/list", ad->txtlist);
464 elm_object_style_set(ad->txtlist, "extended/historylist");
465 evas_object_size_hint_weight_set(ad->txtlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
466 evas_object_smart_callback_add(ad->txtlist, "selected", _list_click_paste, ad);
467 evas_object_smart_callback_add(ad->txtlist, "longpressed", _list_longpress, ad);
468 elm_list_item_append(ad->txtlist, "default", NULL, NULL, NULL, ad);
470 elm_list_go(ad->txtlist);
472 if (get_item_counts() != 0)
473 clipdrawer_update_contents(ad);
478 int clipdrawer_create_view(void *data)
480 struct appdata *ad = data;
485 // at starting, showing app view
486 //clipdrawer_activate_view(ad);
491 void clipdrawer_activate_view(void *data)
493 struct appdata *ad = data;
497 evas_object_show(ad->win_main);
498 elm_win_activate(ad->win_main);
502 void clipdrawer_lower_view(void *data)
504 struct appdata *ad = data;
508 evas_object_hide(ad->win_main);
509 elm_win_lower(ad->win_main);
511 // if delete mode, then back to normal mode
512 if (get_clipdrawer_mode())
513 clipdrawer_change_mode(ad);