4 #include "xcnphandler.h"
5 #include "clipdrawer.h"
7 #define IM "/mnt/ums/Images/Photo/"
8 static const char *g_images_path[] = {
18 // FIXME: how to remove main_ad?
19 // it's mainly used at 'clipdrawer_add_image_item'
20 struct appdata *g_main_ad = NULL;
22 // gic should live at gengrid callback functions
23 Elm_Gengrid_Item_Class gic;
25 typedef struct tag_gridimgitem
27 Elm_Gengrid_Item *item;
31 static void _list_click( void *data, Evas_Object *obj, void *event_info )
33 struct appdata *ad = data;
34 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
38 elm_list_item_selected_set(it, 0);
44 cpdata = elm_list_item_label_get(it);
47 cplen = strlen(cpdata);
48 p = malloc(cplen + 1);
49 snprintf(p, cplen+1, "%s", cpdata);
50 elm_selection_set(1, obj, /*ELM_SEL_FORMAT_TEXT*/1, p);
51 // elm_selection_set(1, obj, /*ELM_SEL_FORMAT_MARKUP*/2, p);
53 clipdrawer_lower_view(ad);
56 int clipdrawer_update_contents(void *data)
58 struct appdata *ad = data;
61 elm_list_clear(ad->txtlist);
62 for (i = 0; i < HISTORY_QUEUE_NUMBER; i++)
64 pos = get_current_history_position()+i;
65 if (pos > HISTORY_QUEUE_NUMBER-1)
66 pos = pos-HISTORY_QUEUE_NUMBER;
67 if (get_item_contents_by_pos(pos) != NULL && strlen(get_item_contents_by_pos(pos)) > 0)
69 elm_list_item_append(ad->txtlist, get_item_contents_by_pos(pos), NULL, NULL, NULL, ad);
72 elm_list_go(ad->txtlist);
74 /* FIXME : sometimes when list update, screen isn't updated */
79 const char* clipdrawer_get_plain_string_from_escaped(char *escstr)
81 /* TODO : is it should be here? besides, remove dependency for entry */
82 /* NOTE : return string should be freed */
83 return elm_entry_markup_to_utf8(escstr);
86 Evas_Object* grid_icon_get(const void *data, Evas_Object *obj, const char *part)
88 gridimgitem_t *ti = (gridimgitem_t *)data;
89 if (!strcmp(part, "elm.swallow.icon"))
91 Evas_Object *icon = elm_icon_add(obj);
92 elm_icon_file_set(icon, ti->path, NULL);
93 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
94 evas_object_show(icon);
100 static void grid_selected(void *data, Evas_Object *obj, void *event_info)
102 struct appdata *ad = data;
105 Elm_Gengrid_Item *sgobj = NULL;
106 sgobj = elm_gengrid_selected_item_get(ad->imggrid);
107 gridimgitem_t *ti = NULL;
108 ti = elm_gengrid_item_data_get(sgobj);
112 DTRACE("ERR: cbhm can't get the selected image\n");
115 len = strlen(ti->path);
116 p = malloc(len + 10);
117 snprintf(p,len+10, "file:///%s", ti->path);
119 fprintf(stderr, "## sel path = %s_\n", p);
121 elm_selection_set(/*secondary*/1,obj,/*ELM_SEL_FORMAT_IMAGE*/4,p);
123 clipdrawer_lower_view(ad);
125 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
128 void grid_del(const void *data, Evas_Object *obj)
130 gridimgitem_t *ti = (gridimgitem_t *)data;
131 eina_stringshare_del(ti->path);
135 // FIXME: how to remove main_ad?
136 // it's mainly used at 'clipdrawer_add_image_item'
137 int clipdrawer_add_image_item(char *imagepath)
139 // struct appdata *ad = data;
140 gridimgitem_t *newgenimg = NULL;
141 char* filepath = NULL;
142 filepath = &imagepath[7]; // skip 'file://'
144 fprintf(stderr, "## image_path = %s_\n", filepath);
145 newgenimg = malloc(sizeof(gridimgitem_t));
146 newgenimg->path = eina_stringshare_add(filepath);
147 newgenimg->item = elm_gengrid_item_append(g_main_ad->imggrid, &gic, newgenimg, NULL, NULL);
153 clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
155 struct appdata *ad = data;
157 #define EDJE_CLOSE_PART_PREFIX "closebutton/"
158 if (!strncmp(source, EDJE_CLOSE_PART_PREFIX, strlen(EDJE_CLOSE_PART_PREFIX)))
160 clipdrawer_lower_view(ad);
164 int clipdrawer_init(void *data)
166 struct appdata *ad = data;
169 evas_object_resize(ad->win_main, CLIPDRAWER_WIDTH, CLIPDRAWER_HEIGHT);
170 evas_object_move(ad->win_main, CLIPDRAWER_POS_X, CLIPDRAWER_POS_Y);
171 evas_object_resize(ad->ly_main, CLIPDRAWER_WIDTH, CLIPDRAWER_HEIGHT);
172 evas_object_move(ad->ly_main, CLIPDRAWER_POS_X, CLIPDRAWER_POS_Y);
174 edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main), "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
177 ad->imggrid = elm_gengrid_add(ad->win_main);
178 elm_layout_content_set(ad->ly_main, "imagehistory/list", ad->imggrid);
179 elm_gengrid_item_size_set(ad->imggrid, 100, 100+3);
180 elm_gengrid_align_set(ad->imggrid, 0.5, 0.0);
181 elm_gengrid_horizontal_set(ad->imggrid, EINA_TRUE);
182 elm_gengrid_bounce_set(ad->imggrid, EINA_TRUE, EINA_FALSE);
183 elm_gengrid_multi_select_set(ad->imggrid, EINA_FALSE);
184 evas_object_smart_callback_add(ad->imggrid, "selected", grid_selected, ad);
185 evas_object_size_hint_weight_set(ad->imggrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
188 elm_gengrid_clear(ad->imggrid);
190 gic.item_style = "default_grid";
191 gic.func.label_get = NULL;
192 gic.func.icon_get = grid_icon_get;
193 gic.func.state_get = NULL;
194 gic.func.del = grid_del;
197 gridimgitem_t *newgenimg;
199 for (i = 0; i < N_IMAGES; i++)
201 newgenimg = malloc(sizeof(gridimgitem_t));
202 newgenimg->path = eina_stringshare_add(g_images_path[i]);
203 newgenimg->item = elm_gengrid_item_append(ad->imggrid, &gic, newgenimg, NULL, NULL);
204 // evas_object_data_set(newgenimg->item, "URI", g_images_path[i]);
207 evas_object_show (ad->imggrid);
209 // for debugging, calc image history pos
211 Evas_Coord x, y, w, h;
212 Evas_Coord vx, vy, vw, vh;
214 edje_object_part_geometry_get(elm_layout_edje_get(ad->ly_main),"imagehistory/list",&x,&y,&w,&h);
215 evas_object_geometry_get (ad->imggrid, &vx,&vy,&vw,&vh);
216 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
217 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
220 ad->txtlist = elm_list_add(ad->win_main);
221 elm_layout_content_set(ad->ly_main, "texthistory/list", ad->txtlist);
222 elm_list_horizontal_mode_set(ad->txtlist, ELM_LIST_COMPRESS);
223 evas_object_smart_callback_add(ad->txtlist, "selected", _list_click, ad);
224 elm_list_item_append(ad->txtlist, "default", NULL, NULL, NULL, ad);
226 elm_list_go(ad->txtlist);
228 if (get_item_counts() != 0)
229 clipdrawer_update_contents(ad);
234 int clipdrawer_create_view(void *data)
236 struct appdata *ad = data;
241 // at starting, showing app view
242 //clipdrawer_activate_view(ad);
247 void clipdrawer_activate_view(void *data)
249 struct appdata *ad = data;
253 evas_object_show(ad->win_main);
254 elm_win_activate(ad->win_main);
258 void clipdrawer_lower_view(void *data)
260 struct appdata *ad = data;
264 evas_object_hide(ad->win_main);
265 elm_win_lower(ad->win_main);