2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <Elementary.h>
21 #include "mf-tray-item.h"
23 #include "mf-widget.h"
25 #ifdef MYFILE_TRAY_FEATURE
27 #define ICON_NORMAL_SIZE_WIDTH 180.0f
28 #define ICON_NORMAL_SIZE_HEIGHT 180.0f
29 #define CATEGORY_IMAGE "Image"
30 #define CATEGORY_VIDEO "Video"
31 #define CATEGORY_SOUNDS "Sounds"
32 #define CATEGORY_DOC "Document"
33 #define CATEGORY_OTHERS "Others"
35 #define LAYOUT_SWALLOW_BG "swallow.bg"
36 #define LAYOUT_INFO_SHORTCUT_ITEM_ICON "swallow.icon"
37 static const char *STR_ATTRIBUTE_NAME = "name";
38 static const char *STR_ATTRIBUTE_ICON_PRESS = "icon_press";
39 static const char *STR_ATTRIBUTE_ICON = "icon";
41 static void __mf_tray_item_del(void *data, Evas *e, Evas_Object *obj, void *event_info)
43 mf_retm_if(obj == NULL, "Invalid argument: parent is NULL\n");
46 tmp = evas_object_data_get(obj, STR_ATTRIBUTE_NAME);
49 tmp = evas_object_data_get(obj, STR_ATTRIBUTE_ICON_PRESS);
52 mf_debug("_dock_item_del end.\n");
55 int mf_tray_item_type(const char *path)
57 int type = mf_file_attr_get_file_type_by_mime(path);
58 int category = mf_tray_item_category_none;
61 category = mf_tray_item_category_image;
64 category = mf_tray_item_category_video;
68 category = mf_tray_item_category_sounds;
75 category = mf_tray_item_category_document;
78 category = mf_tray_item_category_none;
81 category = mf_tray_item_category_others;
84 mf_debug("path is [%s] category is [%d]", path, category);
88 char *mf_tray_item_get_data(Evas_Object *edje, const char *attribute)
90 return evas_object_data_get(edje, attribute);
93 static void __item_mouse_down_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
95 mf_retm_if(NULL == data, "NULL == data");
96 mf_retm_if(NULL == obj, "NULL == obj");
98 Evas_Object *icon = NULL;
99 Evas_Object *bg = NULL;
100 char *press_icon = NULL;
102 bg = elm_object_part_content_get(obj, LAYOUT_SWALLOW_BG);
103 icon = elm_object_part_content_get(obj, LAYOUT_INFO_SHORTCUT_ITEM_ICON);
104 press_icon = mf_tray_item_get_data(obj, STR_ATTRIBUTE_ICON_PRESS);
107 mf_debug(" set bg icon %s", MF_ICON_CATEGORY_BG_PRESS);
108 elm_image_file_set(bg, MF_ICON_CATEGORY_BG_PRESS, NULL);
111 elm_image_file_set(icon, press_icon, NULL);
116 static void __item_mouse_up_cb(void *data, Evas *evas, Evas_Object *obj, void *event_info)
118 mf_retm_if(NULL == data, "NULL == data");
119 mf_retm_if(NULL == obj, "NULL == obj");
121 struct appdata *ap = (struct appdata *)data;
122 Evas_Object *icon = NULL;
123 Evas_Object *bg = NULL;
124 char *unpress_icon = NULL;
125 const char *name = NULL;
127 bg = elm_object_part_content_get(obj, LAYOUT_SWALLOW_BG);
128 icon = elm_object_part_content_get(obj, LAYOUT_INFO_SHORTCUT_ITEM_ICON);
129 unpress_icon = mf_tray_item_get_data(obj, STR_ATTRIBUTE_ICON);
130 name = mf_tray_item_get_data(obj, STR_ATTRIBUTE_NAME);
133 mf_debug(" set bg icon %s", MF_ICON_CATEGORY_BG);
134 elm_image_file_set(bg, MF_ICON_CATEGORY_BG, NULL);
137 elm_image_file_set(icon, unpress_icon, NULL);
140 int category = mf_tray_item_category_none;
141 if (g_strcmp0(name, CATEGORY_IMAGE) == 0) {
142 category = mf_tray_item_category_image;
143 } else if (g_strcmp0(name, CATEGORY_VIDEO) == 0) {
144 category = mf_tray_item_category_video;
145 } else if (g_strcmp0(name, CATEGORY_SOUNDS) == 0) {
146 category = mf_tray_item_category_sounds;
147 } else if (g_strcmp0(name, CATEGORY_DOC) == 0) {
148 category = mf_tray_item_category_document;
149 } else if (g_strcmp0(name, CATEGORY_OTHERS) == 0) {
150 category = mf_tray_item_category_others;
152 mf_debug("category is [%d]", category);
153 if (category != mf_tray_item_category_none) {
154 ap->mf_Status.view_type = mf_view_root_category;
155 mf_search_bar_category_search(ap, category);
156 Evas_Object *btn = mf_widget_unset_part_content(ap->mf_MainWindow.pNaviBar, NAVI_BOTTOM_BUTTON_1_PART);
159 btn = mf_widget_util_create_button(ap->mf_MainWindow.pNaviBar, NAVI_BUTTON_STYLE, MF_LABEL_EDIT, NULL, mf_callback_edit_cb, ap);
161 elm_object_item_part_content_set(ap->mf_MainWindow.pNaviItem, NAVI_BOTTOM_BUTTON_1_PART, btn);
167 static int __mf_tray_item_register_event(void *data, Evas_Object *obj)
169 mf_retvm_if(NULL == data, EXIT_FAILURE, "NULL == data");
171 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_DOWN, __item_mouse_down_cb, data);
172 //evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_MOVE, _item_mouse_move_cb, app_tray);
173 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOUSE_UP, __item_mouse_up_cb, data);
174 //evas_object_event_callback_add(obj, EVAS_CALLBACK_FOCUS_OUT, _item_focus_out_cb, app_tray);
178 static void __mf_tray_item_data_set(Evas_Object *obj, const char* attribute, const char *data)
180 mf_retm_if(NULL == obj, "NULL == obj");
181 mf_retm_if(NULL == attribute, "NULL == attribute");
182 mf_retm_if(NULL == data, "NULL == data");
184 evas_object_data_set(obj, attribute, data);
188 static char *__mf_tray_item_get_press_icon(const char *name)
190 mf_retvm_if(NULL == name, NULL, "NULL == name");
191 if (g_strcmp0(name, CATEGORY_IMAGE) == 0) {
192 return MF_ICON_CATEGORY_IMAGE_PRESS;
193 } else if (g_strcmp0(name, CATEGORY_VIDEO) == 0) {
194 return MF_ICON_CATEGORY_VIDEO_PRESS;
195 } else if (g_strcmp0(name, CATEGORY_SOUNDS) == 0) {
196 return MF_ICON_CATEGORY_SOUNDS_PRESS;
197 } else if (g_strcmp0(name, CATEGORY_DOC) == 0) {
198 return MF_ICON_CATEGORY_DOCUMENT_PRESS;
199 } else if (g_strcmp0(name, CATEGORY_OTHERS) == 0) {
200 return MF_ICON_CATEGORY_OTHERS_PRESS;
205 Evas_Object *mf_tray_item_create(Evas_Object *parent, const char *icon_file, const char *name)
207 mf_retvm_if(parent == NULL, NULL, "parent is NULL");
208 mf_retvm_if(icon_file == NULL, NULL, "icon_file is NULL");
209 mf_retvm_if(name == NULL, NULL, "name is NULL");
211 Evas_Object *layout = NULL;
214 layout = mf_widget_create_layout(parent, EDJ_NAME, GRP_TRAY_ITEM);
217 bg = evas_object_rectangle_add(evas);
219 evas_object_del(layout);
223 evas_object_color_set(bg, 0, 0, 0, 0);
224 evas_object_resize(bg, ICON_NORMAL_SIZE_WIDTH * elm_config_scale_get(), ICON_NORMAL_SIZE_HEIGHT * elm_config_scale_get());
225 evas_object_size_hint_min_set(bg, ICON_NORMAL_SIZE_WIDTH * elm_config_scale_get(), ICON_NORMAL_SIZE_HEIGHT * elm_config_scale_get());
226 evas_object_size_hint_max_set(bg, ICON_NORMAL_SIZE_WIDTH * elm_config_scale_get(), ICON_NORMAL_SIZE_HEIGHT * elm_config_scale_get());
229 bg = elm_image_add(layout);
230 if (elm_image_file_set(bg, MF_ICON_CATEGORY_BG, NULL) == EINA_FALSE) {
231 mf_error("Icon file is not accessible (%s)\n", MF_ICON_CATEGORY_BG);
235 elm_image_resizable_set(bg, EINA_TRUE, EINA_TRUE);
236 evas_object_show(bg);
237 elm_object_part_content_set(layout, LAYOUT_SWALLOW_BG, bg);
239 Evas_Object *icon = NULL;
241 icon = elm_image_add(layout);
242 if (elm_image_file_set(icon, icon_file, NULL) == EINA_FALSE) {
243 mf_error("Icon file is not accessible (%s)\n", icon_file);
244 evas_object_del(icon);
248 elm_image_resizable_set(icon, EINA_TRUE, EINA_TRUE);
249 evas_object_show(icon);
253 tmp = mf_widget_unset_part_content(layout, LAYOUT_INFO_SHORTCUT_ITEM_ICON);
255 evas_object_del(tmp);
258 elm_object_part_content_set(layout, LAYOUT_INFO_SHORTCUT_ITEM_ICON, icon);
261 __mf_tray_item_data_set(layout, STR_ATTRIBUTE_NAME, name);
262 __mf_tray_item_data_set(layout, STR_ATTRIBUTE_ICON, icon_file);
263 __mf_tray_item_data_set(layout, STR_ATTRIBUTE_ICON_PRESS, __mf_tray_item_get_press_icon(name));
265 //edje_object_part_text_set(_EDJ(layout), LAYOUT_INFO_SHORTCUT_ITEM_NAME, name);
266 evas_object_show(layout);
267 //evas_object_event_callback_add(layout, EVAS_CALLBACK_DEL, __mf_tray_item_del, NULL);
271 Evas_Object *mf_tray_create(Evas_Object *parent, void *data)
273 mf_retvm_if(parent == NULL, NULL, "parent is NULL");
274 mf_retvm_if(data == NULL, NULL, "data is NULL");
276 Evas_Object *tray_box = elm_box_add(parent);
278 elm_box_horizontal_set(tray_box, EINA_TRUE);
279 elm_box_align_set(tray_box, 0.0, 0.0);
280 evas_object_size_hint_weight_set(tray_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
282 Evas_Object *Image = mf_tray_item_create(tray_box, MF_ICON_CATEGORY_IMAGE, CATEGORY_IMAGE);
283 elm_box_pack_end(tray_box, Image);
284 __mf_tray_item_register_event(data, Image);
286 Evas_Object *Video = mf_tray_item_create(tray_box, MF_ICON_CATEGORY_VIDEO, CATEGORY_VIDEO);
287 elm_box_pack_end(tray_box, Video);
288 __mf_tray_item_register_event(data, Video);
290 Evas_Object *Sounds = mf_tray_item_create(tray_box, MF_ICON_CATEGORY_SOUNDS, CATEGORY_SOUNDS);
291 elm_box_pack_end(tray_box, Sounds);
292 __mf_tray_item_register_event(data, Sounds);
294 Evas_Object *Document = mf_tray_item_create(tray_box, MF_ICON_CATEGORY_DOCUMENT, CATEGORY_DOC);
295 elm_box_pack_end(tray_box, Document);
296 __mf_tray_item_register_event(data, Document);
298 Evas_Object *Others = mf_tray_item_create(tray_box, MF_ICON_CATEGORY_OTHERS, CATEGORY_OTHERS);
299 elm_box_pack_end(tray_box, Others);
300 __mf_tray_item_register_event(data, Others);
302 //evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_DOWN, _item_mouse_down_cb, app_tray);
303 //evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_MOVE, _item_mouse_move_cb, app_tray);
305 //evas_object_event_callback_add(icon, EVAS_CALLBACK_MOUSE_UP, _item_mouse_up_cb, app_tray);
306 //evas_object_event_callback_add(icon, EVAS_CALLBACK_FOCUS_OUT, _item_focus_out_cb, app_tray);