4 #include "xcnphandler.h"
5 #include "clipdrawer.h"
7 #define IM "/mnt/ums/Images/Photo/"
8 static const char *g_images_path[] = {
20 // gic should live at gengrid callback functions
21 Elm_Gengrid_Item_Class gic;
23 typedef struct tag_gridimgitem
25 Elm_Gengrid_Item *item;
29 static void _list_click( void *data, Evas_Object *obj, void *event_info )
31 struct appdata *ad = data;
32 Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get(obj);
36 elm_list_item_selected_set(it, 0);
42 cpdata = elm_list_item_label_get(it);
45 cplen = strlen(cpdata);
46 p = malloc(cplen + 1);
47 snprintf(p, cplen+1, "%s", cpdata);
48 elm_selection_set(1, obj, /*ELM_SEL_FORMAT_TEXT*/1, p);
49 // elm_selection_set(1, obj, /*ELM_SEL_FORMAT_MARKUP*/2, p);
51 // clipdrawer_lower_view(ad);
54 int clipdrawer_update_contents(void *data)
56 struct appdata *ad = data;
59 elm_list_clear(ad->txtlist);
60 for (i = 0; i < HISTORY_QUEUE_NUMBER; i++)
62 pos = get_current_history_position()+i;
63 if (pos > HISTORY_QUEUE_NUMBER-1)
64 pos = pos-HISTORY_QUEUE_NUMBER;
65 if (get_item_contents_by_pos(pos) != NULL && strlen(get_item_contents_by_pos(pos)) > 0)
67 elm_list_item_append(ad->txtlist, get_item_contents_by_pos(pos), NULL, NULL, NULL, ad);
70 elm_list_go(ad->txtlist);
72 /* FIXME : sometimes when list update, screen isn't updated */
77 const char* clipdrawer_get_plain_string_from_escaped(char *escstr)
79 /* TODO : is it should be here? besides, remove dependency for entry */
80 /* NOTE : return string should be freed */
81 return elm_entry_markup_to_utf8(escstr);
84 Evas_Object* grid_icon_get(const void *data, Evas_Object *obj, const char *part)
86 gridimgitem_t *ti = (gridimgitem_t *)data;
87 if (!strcmp(part, "elm.swallow.icon"))
89 Evas_Object *icon = elm_icon_add(obj);
90 elm_icon_file_set(icon, ti->path, NULL);
91 evas_object_size_hint_aspect_set(icon, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
92 evas_object_show(icon);
98 static void grid_selected(void *data, Evas_Object *obj, void *event_info)
100 struct appdata *ad = data;
103 Elm_Gengrid_Item *sgobj = NULL;
104 sgobj = elm_gengrid_selected_item_get(ad->imggrid);
105 gridimgitem_t *ti = NULL;
106 ti = elm_gengrid_item_data_get(sgobj);
110 DTRACE("ERR: cbhm can't get the selected image\n");
113 len = strlen(ti->path);
114 p = malloc(len + 10);
115 snprintf(p,len+10, "file:///%s", ti->path);
117 elm_selection_set(/*secondary*/1,obj,/*ELM_SEL_FORMAT_IMAGE*/4,p);
119 // clipdrawer_lower_view(ad);
121 elm_gengrid_item_selected_set(sgobj, EINA_FALSE);
124 void grid_del(const void *data, Evas_Object *obj)
126 gridimgitem_t *ti = (gridimgitem_t *)data;
127 eina_stringshare_del(ti->path);
131 // FIXME: how to remove main_ad?
132 // it's mainly used at 'clipdrawer_add_image_item'
133 int clipdrawer_add_image_item(char *imagepath)
135 struct appdata *ad = g_get_main_appdata();
136 gridimgitem_t *newgenimg = NULL;
137 char* filepath = NULL;
138 Eina_List *igl = NULL;
139 unsigned int igl_counter = 0;
140 filepath = &imagepath[7]; // skip 'file://'
142 igl = elm_gengrid_items_get(ad->imggrid);
143 igl_counter = eina_list_count(igl);
144 if (igl_counter >= 10)
146 elm_gengrid_item_del(eina_list_nth(igl, 0));
149 newgenimg = malloc(sizeof(gridimgitem_t));
150 newgenimg->path = eina_stringshare_add(filepath);
151 newgenimg->item = elm_gengrid_item_append(ad->imggrid, &gic, newgenimg, NULL, NULL);
157 clipdrawer_ly_clicked(void *data, Evas_Object *obj, const char *emission, const char *source)
159 struct appdata *ad = data;
161 #define EDJE_CLOSE_PART_PREFIX "closebutton/"
162 if (!strncmp(source, EDJE_CLOSE_PART_PREFIX, strlen(EDJE_CLOSE_PART_PREFIX)))
164 clipdrawer_lower_view(ad);
168 int clipdrawer_init(void *data)
170 struct appdata *ad = data;
172 evas_object_resize(ad->win_main, CLIPDRAWER_WIDTH, CLIPDRAWER_HEIGHT);
173 evas_object_move(ad->win_main, CLIPDRAWER_POS_X, CLIPDRAWER_POS_Y);
174 evas_object_resize(ad->ly_main, CLIPDRAWER_WIDTH, CLIPDRAWER_HEIGHT);
175 evas_object_move(ad->ly_main, CLIPDRAWER_POS_X, CLIPDRAWER_POS_Y);
177 edje_object_signal_callback_add(elm_layout_edje_get(ad->ly_main), "mouse,up,1", "*", clipdrawer_ly_clicked, ad);
180 ad->imggrid = elm_gengrid_add(ad->win_main);
181 elm_layout_content_set(ad->ly_main, "imagehistory/list", ad->imggrid);
182 elm_gengrid_item_size_set(ad->imggrid, 100, 100+3);
183 elm_gengrid_align_set(ad->imggrid, 0.0, 0.0);
184 elm_gengrid_horizontal_set(ad->imggrid, EINA_TRUE);
185 elm_gengrid_bounce_set(ad->imggrid, EINA_TRUE, EINA_FALSE);
186 elm_gengrid_multi_select_set(ad->imggrid, EINA_FALSE);
187 evas_object_smart_callback_add(ad->imggrid, "selected", grid_selected, ad);
188 evas_object_size_hint_weight_set(ad->imggrid, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
190 elm_gengrid_clear(ad->imggrid);
192 gic.item_style = "default_grid";
193 gic.func.label_get = NULL;
194 gic.func.icon_get = grid_icon_get;
195 gic.func.state_get = NULL;
196 gic.func.del = grid_del;
199 gridimgitem_t *newgenimg;
201 for (i = 0; i < N_IMAGES; i++)
203 newgenimg = malloc(sizeof(gridimgitem_t));
204 newgenimg->path = eina_stringshare_add(g_images_path[i]);
205 newgenimg->item = elm_gengrid_item_append(ad->imggrid, &gic, newgenimg, NULL, NULL);
206 // evas_object_data_set(newgenimg->item, "URI", g_images_path[i]);
209 evas_object_show (ad->imggrid);
211 // for debugging, calc image history pos
213 Evas_Coord x, y, w, h;
214 Evas_Coord vx, vy, vw, vh;
216 edje_object_part_geometry_get(elm_layout_edje_get(ad->ly_main),"imagehistory/list",&x,&y,&w,&h);
217 evas_object_geometry_get (ad->imggrid, &vx,&vy,&vw,&vh);
218 fprintf(stderr, "## x = %d, y = %d, w = %d, h = %d\n", x, y, w, h);
219 fprintf(stderr, "## vx = %d, vy = %d, vw = %d, vh = %d\n", vx, vy, vw, vh);
222 ad->txtlist = elm_list_add(ad->win_main);
223 elm_layout_content_set(ad->ly_main, "texthistory/list", ad->txtlist);
224 elm_theme_extension_add(NULL, APP_EDJ_FILE);
225 elm_object_style_set(ad->txtlist, "extended/historylist");
226 evas_object_size_hint_weight_set(ad->txtlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227 evas_object_smart_callback_add(ad->txtlist, "selected", _list_click, ad);
228 elm_list_item_append(ad->txtlist, "default", NULL, NULL, NULL, ad);
230 elm_list_go(ad->txtlist);
232 if (get_item_counts() != 0)
233 clipdrawer_update_contents(ad);
238 int clipdrawer_create_view(void *data)
240 struct appdata *ad = data;
245 // at starting, showing app view
246 //clipdrawer_activate_view(ad);
251 void clipdrawer_activate_view(void *data)
253 struct appdata *ad = data;
257 evas_object_show(ad->win_main);
258 elm_win_activate(ad->win_main);
262 void clipdrawer_lower_view(void *data)
264 struct appdata *ad = data;
268 evas_object_hide(ad->win_main);
269 elm_win_lower(ad->win_main);