add image selecting features
[framework/uifw/cbhm.git] / src / clipdrawer.c
1 #include "common.h"
2 #include "clipdrawer.h"
3 #include "cbhm_main.h"
4 #include "storage.h"
5
6 #ifndef _EDJ
7 #define _EDJ(ly) elm_layout_edje_get(ly)
8 #endif
9
10 #define IM      "/mnt/ums/Images/Wallpapers/"
11 static const char *images[] = {
12         IM"TFT_01_480x800.jpg",
13         IM"TFT_02_480x800.jpg",
14         IM"TFT_03_480x800.jpg",
15         IM"TFT_04_480x800.jpg",
16         IM"TFT_05_480x800.jpg",
17         IM"OCTA_01_480x800.jpg",
18         IM"OCTA_02_480x800.jpg",
19         IM"OCTA_03_480x800.jpg",
20         IM"OCTA_04_480x800.jpg",
21         IM"OCTA_05_480x800.jpg",
22 };
23 #define N_IMAGES (10)
24
25 static void
26 _image_click(void *data, Evas_Object *obj, void *event_info)
27 {
28         char *p,*file;
29         int len;
30         file = evas_object_data_get(data, "URI");
31         char *dir = IM;
32         len = strlen(file) + strlen(dir);
33         p = malloc(len + 10);
34         snprintf(p,len+10,"file:///%s/%s",dir,file);
35
36         elm_selection_set(1,data,2,p);
37 }
38
39 static void _list_click( void *data, Evas_Object *obj, void *event_info )
40 {
41     Elm_List_Item *it = (Elm_List_Item *) elm_list_selected_item_get( obj );
42         if (it == NULL)
43                 return;
44
45     elm_list_item_selected_set(it, 0);
46
47         char *p = NULL;
48         char *cpdata = NULL;
49         int clen;
50
51         cpdata = elm_list_item_label_get(it);
52         if (cpdata == NULL)
53                 return;
54         clen = strlen(cpdata);
55         p = malloc(clen + 1);
56         snprintf(p, clen, "%s", cpdata);
57         elm_selection_set(1, obj, /*mark up*/1, p);
58 }
59
60 int clipdrawer_update_contents(void *data)
61 {
62         struct appdata *ad = data;
63         int i, pos;
64
65         elm_list_clear(ad->txtlist);
66         for (i = 0; i < HISTORY_QUEUE_NUMBER; i++)
67         {
68                 pos = get_current_history_position()+i;
69                 if (pos > HISTORY_QUEUE_NUMBER-1)
70                         pos = pos-HISTORY_QUEUE_NUMBER;
71                 if (get_item_contents_by_pos(pos) != NULL)
72                         elm_list_item_append(ad->txtlist, get_item_contents_by_pos(pos), NULL, NULL, NULL, ad);
73         }
74         elm_list_go(ad->txtlist);
75
76         /* FIXME : sometimes when list update, screen isn't updated */
77
78         return 0;
79 }
80
81 static int clipdrawer_init(void *data)
82 {
83         struct appdata *ad = data;
84
85         evas_object_resize(ad->win_main, 480, 400);
86         evas_object_move(ad->win_main, 0, 400);
87         evas_object_resize(ad->ly_main, 480, 400);
88         evas_object_move(ad->ly_main, 0, 400);
89
90         ad->scrl = elm_scroller_add(ad->win_main);
91         edje_object_part_swallow(_EDJ(ad->ly_main), "cbhmdrawer/imglist", ad->scrl);
92         evas_object_size_hint_weight_set(ad->scrl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
93         elm_scroller_bounce_set(ad->scrl, EINA_TRUE, EINA_FALSE);
94         elm_scroller_policy_set(ad->scrl, ELM_SCROLLER_POLICY_AUTO, ELM_SCROLLER_POLICY_OFF);
95         elm_win_resize_object_add(ad->win_main, ad->scrl);
96         evas_object_show(ad->scrl);
97
98         evas_object_resize(ad->scrl,480,95);
99  
100         ad->imgbox = elm_box_add(ad->win_main);
101         elm_box_horizontal_set(ad->imgbox, TRUE);
102         evas_object_size_hint_weight_set(ad->imgbox, EVAS_HINT_EXPAND, 0);
103         evas_object_size_hint_align_set(ad->imgbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
104         elm_scroller_content_set(ad->scrl, ad->imgbox);
105         evas_object_show(ad->imgbox);
106
107         Evas_Object *pt;
108         int i;
109         for (i = 0 ; i < N_IMAGES ; i ++)
110         {
111                 pt = elm_photo_add(ad->win_main);
112                 elm_photo_file_set(pt, images[i]);
113                 evas_object_size_hint_weight_set(pt, EVAS_HINT_EXPAND,
114                                 EVAS_HINT_EXPAND);
115                 evas_object_size_hint_align_set(pt, EVAS_HINT_FILL,
116                                 EVAS_HINT_FILL);
117                 elm_photo_size_set(pt, 145);
118                 elm_box_pack_end(ad->imgbox, pt);
119                 evas_object_show(pt);
120                 evas_object_data_set(pt,"URI",images[i]);
121
122                 evas_object_smart_callback_add(pt, "clicked", _image_click, pt);
123         }
124
125         ad->txtlist = elm_list_add(ad->win_main);
126         elm_layout_content_set(ad->ly_main, "cbhmdrawer/txtlist", ad->txtlist);
127         elm_list_horizontal_mode_set(ad->txtlist, ELM_LIST_COMPRESS);
128         evas_object_smart_callback_add(ad->txtlist, "selected", _list_click, ad);
129         elm_list_item_append(ad->txtlist, "default", NULL, NULL, NULL, ad);
130
131         elm_list_go(ad->txtlist);
132
133         if (get_item_counts() != 0)
134                 clipdrawer_update_contents(ad);
135
136         return 0;
137 }
138
139 int clipdrawer_create_view(void *data)
140 {
141         struct appdata *ad = data;
142
143         clipdrawer_init(ad);
144
145         return 0;
146 }
147
148 void clipdrawer_activate_view(void *data)
149 {
150         struct appdata *ad = data;
151         
152         if (ad->win_main)
153                 elm_win_activate(ad->win_main);
154 }