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 187
16 #define GRID_ITEM_SINGLE_H 151
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 // gic should live at gengrid callback functions
23 Elm_Gengrid_Item_Class gic;
25 typedef struct tag_griditem
28 Elm_Gengrid_Item *item;
29 const char *ipathdata;
30 Eina_Strbuf *istrdata;
36 int clipdrawer_update_contents(void *data)
38 struct appdata *ad = data;
42 for (i = 0; i < HISTORY_QUEUE_MAX_ITEMS; i++)
44 pos = get_current_history_position() - i;
46 pos = pos+HISTORY_QUEUE_MAX_ITEMS;
48 if (get_item_contents_by_pos(pos) != NULL && strlen(get_item_contents_by_pos(pos)) > 0)
50 unesc = clipdrawer_get_plain_string_from_escaped(get_item_contents_by_pos(pos));
51 unesc = unesc ? unesc : "";
52 elm_list_item_append(ad->txtlist, unesc, NULL, NULL, NULL, ad);
57 /* FIXME : sometimes when list update, screen isn't updated */
62 const char* clipdrawer_get_plain_string_from_escaped(char *escstr)
64 /* TODO : is it should be here? besides, remove dependency for entry */
65 /* NOTE : return string should be freed */
66 return elm_entry_markup_to_utf8(escstr);
69 static void _grid_del_response_cb(void *data, Evas_Object *obj, void *event_info)
71 Elm_Gengrid_Item *it = (Elm_Gengrid_Item *)data;
74 if((int)event_info == ELM_POPUP_RESPONSE_OK)
75 elm_gengrid_item_del(it);
78 static void _grid_click_delete(void *data, Evas_Object *obj, void *event_info)
80 struct appdata *ad = data;
84 _grid_item_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
86 struct appdata *ad = g_get_main_appdata();
88 Elm_Gengrid_Item *sgobj = NULL;
89 sgobj = elm_gengrid_selected_item_get(ad->hig);
90 griditem_t *ti = NULL;
91 ti = elm_gengrid_item_data_get(sgobj);
93 #define EDJE_DELBTN_PART_PREFIX "delbtn"
94 if (strncmp(source, EDJE_DELBTN_PART_PREFIX, strlen(EDJE_DELBTN_PART_PREFIX)))
98 DTRACE("ERR: cbhm can't get the selected image\n");
102 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
104 if (ti->itype == GI_TEXT)
106 char *p = strdup(eina_strbuf_string_get(ti->istrdata));
108 elm_selection_set(1, obj, /*ELM_SEL_FORMAT_TEXT*/1, p);
110 else //if (ti->itype == GI_IMAGE)
112 if (!clipdrawer_paste_textonly_get(ad))
114 int len = strlen(ti->ipathdata);
115 char *p = malloc(len + 10);
116 snprintf(p,len+10, "file:///%s", ti->ipathdata);
118 elm_selection_set(/*secondary*/1,obj,/*ELM_SEL_FORMAT_IMAGE*/4,p);
122 DTRACE("ERR: cbhm image paste mode is false\n");
131 DTRACE("ERR: cbhm can't get the selected item\n");
135 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
137 Evas_Object *popup = elm_popup_add(ad->win_main);
138 elm_popup_timeout_set(popup, 5);
139 evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
140 elm_popup_desc_set(popup, "Are you sure delete this?");
141 elm_popup_buttons_add(popup, 2,
142 "Yes", ELM_POPUP_RESPONSE_OK,
143 "No", ELM_POPUP_RESPONSE_CANCEL,
145 evas_object_smart_callback_add(popup, "response", _grid_del_response_cb, sgobj);
146 evas_object_show(popup);
149 Evas_Object* _grid_icon_get(const void *data, Evas_Object *obj, const char *part)
151 griditem_t *ti = (griditem_t *)data;
153 if (!strcmp(part, "elm.swallow.icon"))
155 if (ti->itype == GI_TEXT)
157 Evas_Object *layout = elm_layout_add (obj);
158 elm_layout_theme_set(layout, "gengrid", "widestyle", "horizontal_layout");
159 edje_object_signal_callback_add(elm_layout_edje_get(layout),
160 "mouse,up,1", "*", _grid_item_ly_clicked, data);
161 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
162 evas_object_resize(rect, GRID_ITEM_W, GRID_ITEM_H);
163 evas_object_color_set(rect, 242, 233, 183, 255);
164 evas_object_show(rect);
165 elm_layout_content_set(layout, "elm.swallow.icon", rect);
167 // FIXME: add string length check
168 Evas_Object *ientry = elm_scrolled_entry_add(obj);
169 evas_object_size_hint_weight_set(ientry, 0, 0);
170 Eina_Strbuf *strent = NULL;
171 char *strdata = eina_strbuf_string_get(ti->istrdata);
172 int i, skipflag, strcnt;
174 strent = eina_strbuf_new();
177 for (i = 0; i < eina_strbuf_length_get(ti->istrdata); i++)
195 eina_strbuf_append_n(strent, strdata, i);
196 // eina_strbuf_append(strent, strdata);
197 eina_strbuf_replace_all(strent, " absize=240x180 ", " absize=52x39 ");
199 eina_strbuf_append(strent, "...");
201 elm_scrolled_entry_entry_set(ientry, eina_strbuf_string_get(strent));
202 elm_scrolled_entry_editable_set(ientry, EINA_FALSE);
203 elm_scrolled_entry_context_menu_disabled_set(ientry, EINA_TRUE);
204 evas_object_show(ientry);
205 elm_layout_content_set(layout, "elm.swallow.inner", ientry);
207 eina_strbuf_free(strent);
211 else// if (ti->itype == GI_IMAGE)
213 Evas_Object *layout = elm_layout_add (obj);
214 elm_layout_theme_set(layout, "gengrid", "widestyle", "horizontal_layout");
215 edje_object_signal_callback_add(elm_layout_edje_get(layout),
216 "mouse,up,1", "*", _grid_item_ly_clicked, data);
219 sicon = evas_object_image_add(evas_object_evas_get(obj));
220 evas_object_image_load_size_set(sicon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
221 evas_object_image_file_set(sicon, ti->ipathdata, NULL);
222 evas_object_image_fill_set(sicon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
223 evas_object_resize(sicon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
224 elm_layout_content_set(layout, "elm.swallow.icon", sicon);
226 struct appdata *ad = g_get_main_appdata();
228 if (!clipdrawer_paste_textonly_get(ad))
230 edje_object_signal_emit(elm_layout_edje_get(layout), "elm,state,hide,delbtn", "elm");
231 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(obj));
232 evas_object_color_set(rect, 0, 0, 0, 200);
233 evas_object_show(rect);
234 elm_layout_content_set(layout, "elm.swallow.cover", rect);
237 ti->ilayout = layout;
241 Evas_Object *icon = elm_icon_add(obj);
242 elm_icon_file_set(icon, ti->ipathdata, NULL);
243 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
244 evas_object_show(icon);
254 my_ee = ecore_evas_buffer_new(GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
255 my_e = ecore_evas_get(my_ee);
257 bgrect = evas_object_rectangle_add(my_e);
258 evas_object_color_set(bgrect, 255, 255, 255, 255);
259 evas_object_resize(bgrect, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
260 evas_object_move(bgrect, 0, 0);
261 evas_object_show(bgrect);
263 #define BORDER_SIZE 1
264 fgimg = evas_object_image_add(my_e);
265 evas_object_image_load_size_set(fgimg, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
266 evas_object_image_file_set(fgimg, ti->ipathdata, NULL);
267 evas_object_image_fill_set(fgimg, 0, 0, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
268 evas_object_image_filled_set(fgimg, 1);
270 evas_object_image_size_get(fgimg, &x, &y);
271 //fprintf(stderr, "## img x = %d, y = %d\n", x, y);
272 evas_object_resize(fgimg, GRID_ITEM_SINGLE_W-BORDER_SIZE*2, GRID_ITEM_SINGLE_H-BORDER_SIZE*2);
273 evas_object_move(fgimg, BORDER_SIZE, BORDER_SIZE);
274 evas_object_show(fgimg);
276 icon = evas_object_image_add(evas_object_evas_get(obj));
278 evas_object_image_data_set(icon, NULL);
279 evas_object_image_size_set(icon, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
280 evas_object_image_fill_set(icon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
281 evas_object_image_filled_set(icon, EINA_TRUE);
282 evas_object_image_data_copy_set(icon, (int *)ecore_evas_buffer_pixels_get(my_ee));
283 evas_object_image_data_update_add(icon, 0, 0, GRID_ITEM_SINGLE_W, GRID_ITEM_SINGLE_H);
285 evas_object_del(bgrect);
286 evas_object_del(fgimg);
287 ecore_evas_free(my_ee);
296 else if (!strcmp(part, "elm.swallow.end"))
298 ti->delbtn = elm_check_add(obj);
299 elm_object_style_set(ti->delbtn, "extended/itemcheck");
300 //evas_object_propagate_events_set(ti->delbtn, 0);
301 elm_check_state_set(ti->delbtn, tcm);
302 evas_object_smart_callback_add(ti->delbtn, "changed", _grid_item_check_changed, data);
303 evas_object_show(ti->delbtn);
311 static void _grid_longpress(void *data, Evas_Object *obj, void *event_info)
313 struct appdata *ad = data;
314 clipdrawer_change_mode(ad);
317 static void _grid_click_paste(void *data, Evas_Object *obj, void *event_info)
319 struct appdata *ad = data;
320 Elm_Gengrid_Item *sgobj = NULL;
321 sgobj = elm_gengrid_selected_item_get(ad->hig);
322 griditem_t *ti = NULL;
323 ti = elm_gengrid_item_data_get(sgobj);
325 fprintf(stderr, "## grid_click_paste = 0x%x\n", event_info);
328 void _grid_del(const void *data, Evas_Object *obj)
330 griditem_t *ti = (griditem_t *)data;
331 if (ti->itype == GI_TEXT)
332 eina_strbuf_free(ti->istrdata);
334 eina_stringshare_del(ti->ipathdata);
338 // FIXME: how to remove calling g_get_main_appdata()?
339 // it's mainly used at 'clipdrawer_image_item'
340 int clipdrawer_add_item(char *idata, int type)
342 struct appdata *ad = g_get_main_appdata();
343 griditem_t *newgi = NULL;
345 newgi = malloc(sizeof(griditem_t));
348 fprintf(stderr, "## add - %d : %s\n", newgi->itype, idata);
351 newgi->istrdata = eina_strbuf_new();
352 eina_strbuf_append(newgi->istrdata, idata);
354 else //if (type == GI_IMAGE)
356 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
357 griditem_t *ti = NULL;
359 if (!check_regular_file(idata))
361 DTRACE("Error : it isn't normal file = %s\n", idata);
367 ti = elm_gengrid_item_data_get(item);
368 if ((ti->itype == type) && !strcmp(ti->ipathdata, idata))
370 DTRACE("Error : duplicated file path = %s\n", idata);
373 item = elm_gengrid_item_next_get(item);
376 newgi->ipathdata = eina_stringshare_add(idata);
379 if (ad->hicount >= HISTORY_QUEUE_MAX_ITEMS)
382 // FIXME: add routine that is removing its elements
383 elm_gengrid_item_del(elm_gengrid_last_item_get(ad->hig));
387 newgi->item = elm_gengrid_item_prepend(ad->hig, &gic, newgi, NULL, NULL);
393 clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
395 struct appdata *ad = data;
397 #define EDJE_CLOSE_PART_PREFIX "background/close"
398 if (!strncmp(source, EDJE_CLOSE_PART_PREFIX, strlen(EDJE_CLOSE_PART_PREFIX)))
400 clipdrawer_lower_view(ad);
404 int clipdrawer_init(void *data)
406 struct appdata *ad = data;
410 ad->pastetextonly = EINA_TRUE;
413 elm_theme_extension_add(NULL, APP_EDJ_FILE);
415 cdy = (1.0*CLIPDRAWER_HEIGHT/SCREEN_HEIGHT)*ad->root_h;
416 cdw = (1.0*CLIPDRAWER_POS_Y/SCREEN_HEIGHT)*ad->root_h;
418 evas_object_resize(ad->win_main, ad->root_w, (int)cdy);
419 evas_object_move(ad->win_main, CLIPDRAWER_POS_X, (int)cdw);
420 evas_object_resize(ad->ly_main, ad->root_w, (int)cdy);
421 evas_object_move(ad->ly_main, CLIPDRAWER_POS_X, (int)cdw);
423 edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main),
424 "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
427 ad->hig = elm_gengrid_add(ad->win_main);
428 elm_layout_content_set(ad->ly_main, "historyitems", ad->hig);
429 elm_gengrid_item_size_set(ad->hig, GRID_ITEM_W+2, GRID_ITEM_H);
430 elm_gengrid_align_set(ad->hig, 0.5, 0.5);
431 elm_gengrid_horizontal_set(ad->hig, EINA_TRUE);
432 elm_gengrid_bounce_set(ad->hig, EINA_TRUE, EINA_FALSE);
433 elm_gengrid_multi_select_set(ad->hig, EINA_FALSE);
434 evas_object_smart_callback_add(ad->hig, "selected", _grid_click_paste, ad);
435 // evas_object_smart_callback_add(ad->hig, "longpressed", _grid_longpress, ad);
436 evas_object_size_hint_weight_set(ad->hig, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
438 elm_gengrid_clear(ad->hig);
440 gic.item_style = "default_grid";
441 gic.func.label_get = NULL;
442 gic.func.icon_get = _grid_icon_get;
443 gic.func.state_get = NULL;
444 gic.func.del = _grid_del;
449 for (i = 0; i < N_IMAGES; i++)
451 clipdrawer_add_item(g_images_path[0], GI_IMAGE);
454 clipdrawer_add_item("clipboard history", GI_TEXT);
456 evas_object_show (ad->hig);
458 // for debugging, calc history pos
460 Evas_Coord x, y, w, h;
461 Evas_Coord vx, vy, vw, vh;
463 edje_object_part_geometry_get(elm_layout_edje_get(ad->ly_main),"imagehistory/list",&x,&y,&w,&h);
464 evas_object_geometry_get (ad->hig, &vx,&vy,&vw,&vh);
465 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
466 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
469 // if (get_item_counts() != 0)
470 // clipdrawer_update_contents(ad);
475 int clipdrawer_create_view(void *data)
477 struct appdata *ad = data;
482 // at starting, showing app view
483 // clipdrawer_activate_view(ad);
488 void clipdrawer_activate_view(void *data)
490 struct appdata *ad = data;
494 set_transient_for(ad);
495 evas_object_show(ad->win_main);
496 elm_win_activate(ad->win_main);
500 void clipdrawer_lower_view(void *data)
502 struct appdata *ad = data;
506 unset_transient_for(ad);
507 evas_object_hide(ad->win_main);
508 elm_win_lower(ad->win_main);
512 void _change_gengrid_paste_textonly_mode(void *data)
514 struct appdata *ad = data;
516 fprintf(stderr, "## _change_gengrid_paste_textonly_mode = %d\n", clipdrawer_paste_textonly_get(ad));
518 Elm_Gengrid_Item *item;
519 griditem_t *ti = NULL;
521 if (clipdrawer_paste_textonly_get(ad))
522 { // textonly paste mode
523 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
527 ti = elm_gengrid_item_data_get(item);
528 if ((ti->itype == GI_IMAGE) && (ti->ilayout))
530 fprintf(stderr, "## sig to hide delbtn\n");
532 edje_object_signal_emit(elm_layout_edje_get(ti->ilayout), "elm,state,hide,delbtn", "elm");
533 Evas_Object *rect = evas_object_rectangle_add(evas_object_evas_get(ad->hig));
534 evas_object_color_set(rect, 0, 0, 0, 200);
535 evas_object_show(rect);
536 elm_layout_content_set(ti->ilayout, "elm.swallow.cover", rect);
538 item = elm_gengrid_item_next_get(item);
542 { // text+image paste mode
543 Elm_Gengrid_Item *item = elm_gengrid_first_item_get(ad->hig);
547 ti = elm_gengrid_item_data_get(item);
548 fprintf(stderr, "## itype = %d\n", ti->itype);
549 fprintf(stderr, "## ilayout = 0x%x\n", ti->ilayout);
550 if ((ti->itype == GI_IMAGE) && (ti->ilayout))
552 fprintf(stderr, "## sig to show delbtn\n");
554 edje_object_signal_emit(elm_layout_edje_get(ti->ilayout), "elm,state,show,delbtn", "elm");
555 Evas_Object *rect = elm_layout_content_unset(ti->ilayout, "elm.swallow.cover");
556 evas_object_hide(rect);
557 evas_object_del(rect);
559 item = elm_gengrid_item_next_get(item);
564 void clipdrawer_paste_textonly_set(void *data, Eina_Bool textonly)
566 struct appdata *ad = data;
567 textonly = !!textonly;
568 if (ad->pastetextonly != textonly)
569 ad->pastetextonly = textonly;
570 DTRACE("paste textonly mode = %d\n", textonly);
572 _change_gengrid_paste_textonly_mode(ad);
575 Eina_Bool clipdrawer_paste_textonly_get(void *data)
577 struct appdata *ad = data;
578 return ad->pastetextonly;