4 #include "xcnphandler.h"
5 #include "clipdrawer.h"
7 #define DELETE_ICON_PATH "/usr/share/cbhm/icons/05_delete.png"
8 #define IM "/usr/share/cbhm/icons/"
9 static const char *g_images_path[] = {
10 IM"cbhm_default_img.png",
14 #define GRID_ITEM_SPACE_W 6
15 #define GRID_ITEM_SINGLE_W 185
16 #define GRID_ITEM_SINGLE_H 161
17 #define GRID_ITEM_W (GRID_ITEM_SINGLE_W+(GRID_ITEM_SPACE_W*2))
18 #define GRID_ITEM_H (GRID_ITEM_SINGLE_H)
19 #define GRID_IMAGE_LIMIT_W 91
20 #define GRID_IMAGE_LIMIT_H 113
22 #define ANIM_DURATION 30 // 1 seconds
23 #define ANIM_FLOPS (0.5/30)
25 // gic should live at gengrid callback functions
26 Elm_Gengrid_Item_Class gic;
28 typedef struct tag_griditem
31 Elm_Gengrid_Item *item;
32 const char *ipathdata;
33 Eina_Strbuf *istrdata;
39 int clipdrawer_update_contents(void *data)
41 struct appdata *ad = data;
45 for (i = 0; i < HISTORY_QUEUE_MAX_ITEMS; i++)
47 pos = get_current_history_position() - i;
49 pos = pos+HISTORY_QUEUE_MAX_ITEMS;
51 if (clipdrawer_get_item_data(ad, pos) != NULL && strlen(clipdrawer_get_item_data(ad, pos)) > 0)
53 unesc = clipdrawer_get_plain_string_from_escaped(clipdrawer_get_item_data(ad, pos));
54 unesc = unesc ? unesc : "";
55 elm_list_item_append(ad->txtlist, unesc, NULL, NULL, NULL, ad);
60 /* FIXME : sometimes when list update, screen isn't updated */
65 const char* clipdrawer_get_plain_string_from_escaped(char *escstr)
67 /* TODO : is it should be here? besides, remove dependency for entry */
68 /* NOTE : return string should be freed */
69 return elm_entry_markup_to_utf8(escstr);
72 static void _grid_del_response_cb(void *data, Evas_Object *obj, void *event_info)
74 Elm_Gengrid_Item *it = (Elm_Gengrid_Item *)data;
77 if((int)event_info == ELM_POPUP_RESPONSE_OK)
78 elm_gengrid_item_del(it);
81 static void _grid_click_delete(void *data, Evas_Object *obj, void *event_info)
83 struct appdata *ad = data;
87 _grid_item_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
89 struct appdata *ad = g_get_main_appdata();
91 if (ad->anim_status != STATUS_NONE)
94 Elm_Gengrid_Item *sgobj = NULL;
95 sgobj = elm_gengrid_selected_item_get(ad->hig);
96 griditem_t *ti = NULL;
97 ti = elm_gengrid_item_data_get(sgobj);
99 #define EDJE_DELBTN_PART_PREFIX "delbtn"
100 if (strncmp(source, EDJE_DELBTN_PART_PREFIX, strlen(EDJE_DELBTN_PART_PREFIX)))
104 DTRACE("ERR: cbhm can't get the selected image\n");
108 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
110 if (ti->itype == GI_TEXT)
112 char *p = strdup(eina_strbuf_string_get(ti->istrdata));
114 elm_selection_set(1, obj, /*ELM_SEL_FORMAT_TEXT*/1, p);
116 else //if (ti->itype == GI_IMAGE)
118 if (!clipdrawer_paste_textonly_get(ad))
120 int len = strlen(ti->ipathdata);
121 char *p = malloc(len + 10);
122 snprintf(p,len+10, "file:///%s", ti->ipathdata);
124 elm_selection_set(/*secondary*/1,obj,/*ELM_SEL_FORMAT_IMAGE*/4,p);
128 DTRACE("ERR: cbhm image paste mode is false\n");
137 DTRACE("ERR: cbhm can't get the selected item\n");
141 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
143 Evas_Object *popup = elm_popup_add(ad->win_main);
144 elm_popup_timeout_set(popup, 5);
145 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
146 elm_popup_desc_set(popup, "Are you sure delete this?");
147 elm_popup_buttons_add(popup, 2,
148 "Yes", ELM_POPUP_RESPONSE_OK,
149 "No", ELM_POPUP_RESPONSE_CANCEL,
151 evas_object_smart_callback_add(popup, "response", _grid_del_response_cb, sgobj);
152 evas_object_show(popup);
155 Evas_Object* _grid_icon_get(const void *data, Evas_Object *obj, const char *part)
157 griditem_t *ti = (griditem_t *)data;
159 if (!strcmp(part, "elm.swallow.icon"))
161 if (ti->itype == GI_TEXT)
163 Evas_Object *layout = elm_layout_add (obj);
164 elm_layout_theme_set(layout, "gengrid", "widestyle", "horizontal_layout");
165 edje_object_signal_callback_add(elm_layout_edje_get(layout),
166 "mouse,up,1", "*", _grid_item_ly_clicked, data);
167 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
168 evas_object_resize(rect, GRID_ITEM_W, GRID_ITEM_H);
169 evas_object_color_set(rect, 242, 233, 183, 255);
170 evas_object_show(rect);
171 elm_layout_content_set(layout, "elm.swallow.icon", rect);
173 // FIXME: add string length check
174 Evas_Object *ientry = elm_scrolled_entry_add(obj);
175 evas_object_size_hint_weight_set(ientry, 0, 0);
176 Eina_Strbuf *strent = NULL;
177 char *strdata = eina_strbuf_string_get(ti->istrdata);
178 int i, skipflag, strcnt;
180 strent = eina_strbuf_new();
183 for (i = 0; i < eina_strbuf_length_get(ti->istrdata); i++)
201 eina_strbuf_append_n(strent, strdata, i);
202 // eina_strbuf_append(strent, strdata);
203 eina_strbuf_replace_all(strent, " absize=240x180 ", " absize=52x39 ");
205 eina_strbuf_append(strent, "...");
206 eina_strbuf_prepend(strent, "<font_size=18>");
208 elm_scrolled_entry_entry_set(ientry, eina_strbuf_string_get(strent));
209 elm_scrolled_entry_editable_set(ientry, EINA_FALSE);
210 elm_scrolled_entry_context_menu_disabled_set(ientry, EINA_TRUE);
211 evas_object_show(ientry);
212 elm_layout_content_set(layout, "elm.swallow.inner", ientry);
214 eina_strbuf_free(strent);
218 else// if (ti->itype == GI_IMAGE)
220 Evas_Object *layout = elm_layout_add (obj);
221 elm_layout_theme_set(layout, "gengrid", "widestyle", "horizontal_layout");
222 edje_object_signal_callback_add(elm_layout_edje_get(layout),
223 "mouse,up,1", "*", _grid_item_ly_clicked, data);
226 sicon = evas_object_image_add(evas_object_evas_get(obj));
227 evas_object_image_load_size_set(sicon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
228 evas_object_image_file_set(sicon, ti->ipathdata, NULL);
229 evas_object_image_fill_set(sicon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
230 evas_object_resize(sicon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
231 elm_layout_content_set(layout, "elm.swallow.icon", sicon);
233 struct appdata *ad = g_get_main_appdata();
235 if (!clipdrawer_paste_textonly_get(ad))
237 edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,hide,delbtn", "elm");
238 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
239 evas_object_color_set(rect, 0, 0, 0, 200);
240 evas_object_show(rect);
241 elm_layout_content_set(layout, "elm.swallow.cover", rect);
244 ti->ilayout = layout;
248 Evas_Object *icon = elm_icon_add(obj);
249 elm_icon_file_set(icon, ti->ipathdata, NULL);
250 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
251 evas_object_show(icon);
261 my_ee = ecore_evas_buffer_new(GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
262 my_e = ecore_evas_get(my_ee);
264 bgrect = evas_object_rectangle_add(my_e);
265 evas_object_color_set(bgrect, 255, 255, 255, 255);
266 evas_object_resize(bgrect, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
267 evas_object_move(bgrect, 0, 0);
268 evas_object_show(bgrect);
270 #define BORDER_SIZE 1
271 fgimg = evas_object_image_add(my_e);
272 evas_object_image_load_size_set(fgimg, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
273 evas_object_image_file_set(fgimg, ti->ipathdata, NULL);
274 evas_object_image_fill_set(fgimg, 0, 0, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
275 evas_object_image_filled_set(fgimg, 1);
277 evas_object_image_size_get(fgimg, &x, &y);
278 //fprintf(stderr, "## img x = %d, y = %d\n", x, y);
279 evas_object_resize(fgimg, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
280 evas_object_move(fgimg, BORDER_SIZE, BORDER_SIZE);
281 evas_object_show(fgimg);
283 icon = evas_object_image_add(evas_object_evas_get(obj));
285 evas_object_image_data_set(icon, NULL);
286 evas_object_image_size_set(icon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
287 evas_object_image_fill_set(icon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
288 evas_object_image_filled_set(icon, EINA_TRUE);
289 evas_object_image_data_copy_set(icon, (int *)ecore_evas_buffer_pixels_get(my_ee));
290 evas_object_image_data_update_add(icon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
292 evas_object_del(bgrect);
293 evas_object_del(fgimg);
294 ecore_evas_free(my_ee);
303 else if (!strcmp(part, "elm.swallow.end"))
305 ti->delbtn = elm_check_add(obj);
306 elm_object_style_set(ti->delbtn, "extended/itemcheck");
307 //evas_object_propagate_events_set(ti->delbtn, 0);
308 elm_check_state_set(ti->delbtn, tcm);
309 evas_object_smart_callback_add(ti->delbtn, "changed", _grid_item_check_changed, data);
310 evas_object_show(ti->delbtn);
318 static void _grid_longpress(void *data, Evas_Object *obj, void *event_info)
320 struct appdata *ad = data;
321 clipdrawer_change_mode(ad);
324 static void _grid_click_paste(void *data, Evas_Object *obj, void *event_info)
326 struct appdata *ad = data;
327 if (ad->anim_status != STATUS_NONE)
330 Elm_Gengrid_Item *sgobj = NULL;
331 sgobj = elm_gengrid_selected_item_get(ad->hig);
332 griditem_t *ti = NULL;
333 ti = elm_gengrid_item_data_get(sgobj);
336 void _grid_del(const void *data, Evas_Object *obj)
338 griditem_t *ti = (griditem_t *)data;
339 if (ti->itype == GI_TEXT)
340 eina_strbuf_free(ti->istrdata);
342 eina_stringshare_del(ti->ipathdata);
346 char* clipdrawer_get_item_data(void *data, int pos)
348 struct appdata *ad = data;
349 griditem_t *ti = NULL;
350 griditem_t *newgi = NULL;
353 if (pos < 0 || pos > ad->hicount)
356 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
359 ti = elm_gengrid_item_data_get(item);
364 if (ti->itype == GI_TEXT)
365 return (char*)eina_strbuf_string_get(ti->istrdata);
367 return ti->ipathdata;
370 item = elm_gengrid_item_next_get(item);
376 // FIXME: how to remove calling g_get_main_appdata()?
377 // it's mainly used at 'clipdrawer_image_item'
378 int clipdrawer_add_item(char *idata, int type)
380 struct appdata *ad = g_get_main_appdata();
381 griditem_t *newgi = NULL;
383 newgi = malloc(sizeof(griditem_t));
386 fprintf(stderr, "## add - %d : %s\n", newgi->itype, idata);
389 newgi->istrdata = eina_strbuf_new();
390 eina_strbuf_append(newgi->istrdata, idata);
392 else //if (type == GI_IMAGE)
394 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
395 griditem_t *ti = NULL;
397 if (!check_regular_file(idata))
399 DTRACE("Error : it isn't normal file = %s\n", idata);
405 ti = elm_gengrid_item_data_get(item);
406 if ((ti->itype == type) && !strcmp(ti->ipathdata, idata))
408 DTRACE("Error : duplicated file path = %s\n", idata);
411 item = elm_gengrid_item_next_get(item);
413 newgi->ipathdata = eina_stringshare_add(idata);
416 if (ad->hicount >= HISTORY_QUEUE_MAX_ITEMS)
419 // FIXME: add routine that is removing its elements
420 elm_gengrid_item_del(elm_gengrid_last_item_get(ad->hig));
424 newgi->item = elm_gengrid_item_prepend(ad->hig, &gic, newgi, NULL, NULL);
430 clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
432 struct appdata *ad = data;
434 if (ad->anim_status != STATUS_NONE)
437 #define EDJE_CLOSE_PART_PREFIX "background/close"
438 if (!strncmp(source, EDJE_CLOSE_PART_PREFIX, strlen(EDJE_CLOSE_PART_PREFIX)))
440 clipdrawer_lower_view(ad);
444 int clipdrawer_init(void *data)
446 struct appdata *ad = data;
449 ad->windowshow = EINA_FALSE;
451 ad->pastetextonly = EINA_TRUE;
452 ad->anim_status = STATUS_NONE;
455 elm_theme_extension_add(NULL, APP_EDJ_FILE);
457 cdy = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
458 cdw = (1.0*CLIPDRAWER_POS_Y/SCREEN_HEIGHT)*ad->root_h;
460 evas_object_resize(ad->win_main, ad->root_w, (int)cdy);
461 evas_object_move(ad->win_main, CLIPDRAWER_POS_X, (int)cdw);
462 evas_object_resize(ad->ly_main, ad->root_w, (int)cdy);
463 evas_object_move(ad->ly_main, CLIPDRAWER_POS_X, (int)cdw);
465 edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main),
466 "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
469 ad->hig = elm_gengrid_add(ad->win_main);
470 elm_layout_content_set(ad->ly_main, "historyitems", ad->hig);
471 elm_gengrid_item_size_set(ad->hig, GRID_ITEM_W+2, GRID_ITEM_H);
472 elm_gengrid_align_set(ad->hig, 0.5, 0.5);
473 elm_gengrid_horizontal_set(ad->hig, EINA_TRUE);
474 elm_gengrid_bounce_set(ad->hig, EINA_TRUE, EINA_FALSE);
475 elm_gengrid_multi_select_set(ad->hig, EINA_FALSE);
476 evas_object_smart_callback_add(ad->hig, "selected", _grid_click_paste, ad);
477 // evas_object_smart_callback_add(ad->hig, "longpressed", _grid_longpress, ad);
478 evas_object_size_hint_weight_set(ad->hig, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
480 elm_gengrid_clear(ad->hig);
482 gic.item_style = "default_grid";
483 gic.func.label_get = NULL;
484 gic.func.icon_get = _grid_icon_get;
485 gic.func.state_get = NULL;
486 gic.func.del = _grid_del;
491 for (i = 0; i < N_IMAGES; i++)
493 clipdrawer_add_item(g_images_path[0], GI_IMAGE);
496 clipdrawer_add_item("clipboard history", GI_TEXT);
498 evas_object_show (ad->hig);
500 // for debugging, calc history pos
502 Evas_Coord x, y, w, h;
503 Evas_Coord vx, vy, vw, vh;
505 edje_object_part_geometry_get(elm_layout_edje_get(ad->ly_main),"imagehistory/list",&x,&y,&w,&h);
506 evas_object_geometry_get (ad->hig, &vx,&vy,&vw,&vh);
507 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
508 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
511 // if (get_item_counts() != 0)
512 // clipdrawer_update_contents(ad);
517 int clipdrawer_create_view(void *data)
519 struct appdata *ad = data;
524 // at starting, showing app view
525 clipdrawer_activate_view(ad);
527 // clipdrawer_anim_show_effect(ad);
532 Ecore_Timer *tm_anim;
534 Eina_Bool anim_pos_calc_cb(void *data)
536 struct appdata *ad = data;
538 static int anim_count = 0;
539 int anim_starty, anim_endy, deltay;
542 switch (ad->anim_status)
545 anim_starty = (int)((1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
546 anim_endy = ad->root_h;
547 anim_starty = anim_endy - anim_starty;
550 anim_starty = ad->root_h;
551 anim_endy = (int)((1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h);
552 anim_endy = anim_starty-anim_endy;
558 if (anim_count > ANIM_DURATION)
561 if (ad->anim_status == HIDE_ANIM)
563 evas_object_hide(ad->win_main);
564 elm_win_lower(ad->win_main);
565 unset_transient_for(ad);
567 ad->anim_status = STATUS_NONE;
571 posprop = 1.0*anim_count/ANIM_DURATION;
572 switch (ad->anim_status)
575 deltay = (int)((anim_endy-anim_starty)*posprop);
576 evas_object_move(ad->win_main, 0, anim_starty+deltay);
579 deltay = (int)((anim_starty-anim_endy)*posprop);
580 evas_object_move(ad->win_main, 0, anim_starty-deltay);
590 void clipdrawer_anim_effect(void *data, anim_status_t atype)
592 struct appdata *ad = data;
594 if (ad->anim_status != STATUS_NONE)
596 DTRACE("ERR: another animation is showing\n");
600 ad->anim_status = atype;
601 ecore_timer_add(ANIM_FLOPS, anim_pos_calc_cb, ad);
604 void clipdrawer_activate_view(void *data)
606 struct appdata *ad = data;
610 set_transient_for(ad);
611 evas_object_show(ad->win_main);
612 clipdrawer_anim_effect(ad, SHOW_ANIM);
613 elm_win_activate(ad->win_main);
614 ad->windowshow = EINA_TRUE;
618 void clipdrawer_lower_view(void *data)
620 struct appdata *ad = data;
622 if (ad->win_main && ad->windowshow)
624 clipdrawer_anim_effect(ad, HIDE_ANIM);
625 ad->windowshow = EINA_FALSE;
629 void _change_gengrid_paste_textonly_mode(void *data)
631 struct appdata *ad = data;
633 Elm_Gengrid_Item *item;
634 griditem_t *ti = NULL;
636 if (clipdrawer_paste_textonly_get(ad))
637 { // textonly paste mode
638 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
642 ti = elm_gengrid_item_data_get(item);
643 if ((ti->itype == GI_IMAGE) && (ti->ilayout))
645 edje_object_signal_emit(elm_layout_edje_get(ti->ilayout), "elm,state,hide,delbtn", "elm");
646 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(ad->hig));
647 evas_object_color_set(rect, 0, 0, 0, 200);
648 evas_object_show(rect);
649 elm_layout_content_set(ti->ilayout, "elm.swallow.cover", rect);
651 item = elm_gengrid_item_next_get(item);
655 { // text+image paste mode
656 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
660 ti = elm_gengrid_item_data_get(item);
661 if ((ti->itype == GI_IMAGE) && (ti->ilayout))
663 edje_object_signal_emit(elm_layout_edje_get(ti->ilayout), "elm,state,show,delbtn", "elm");
664 Evas_Object *rect = elm_layout_content_unset(ti->ilayout, "elm.swallow.cover");
665 evas_object_hide(rect);
666 evas_object_del(rect);
668 item = elm_gengrid_item_next_get(item);
673 void clipdrawer_paste_textonly_set(void *data, Eina_Bool textonly)
675 struct appdata *ad = data;
676 textonly = !!textonly;
677 if (ad->pastetextonly != textonly)
678 ad->pastetextonly = textonly;
679 DTRACE("paste textonly mode = %d\n", textonly);
681 _change_gengrid_paste_textonly_mode(ad);
684 Eina_Bool clipdrawer_paste_textonly_get(void *data)
686 struct appdata *ad = data;
687 return ad->pastetextonly;