Base code / protex done / 64bit build check done
[profile/tv/apps/native/filebrowser.git] / src / views / BaseView / Popup.cpp
1 /*
2 * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #include <Elementary.h>
18 #include <Eina.h>
19 #include <Ecore.h>
20 #include <utilX.h>
21 #include <aul.h>
22 #include "i18n.h"
23
24 #include "AppCommon.h"
25 #include "define.h"
26 #include "common.h"
27 #include "dbg.h"
28 #include "Popup.h"
29
30 #define MAX_POPUP_TIME 10 /* seconds */
31 #define POPUP_ICON_SIZE 48
32
33 struct SPopup {
34         Evas_Object *popup;
35         Elm_Transit *transit;
36 };
37
38 bool CPopup::Create(Evas_Object* base)
39 {
40         ASSERT(base);
41
42         if (m)
43                 return false;
44
45         m = new SPopup;
46         if (!m)
47                 return false;
48
49         Evas_Object *popup, *label, *icon;
50         double scale;
51         char buf[MAX_LENGTH];
52
53         popup = elm_popup_add(base);
54         if (!popup)
55                 return NULL;
56
57         elm_object_style_set(popup, FBR_STYLE_LOADING_POPUP);
58         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_TOP_RIGHT);
59         elm_popup_timeout_set(popup, MAX_POPUP_TIME);
60         evas_object_show(popup);
61
62         label = elm_label_add(popup);
63         if (!label)
64                 goto error;
65
66         elm_object_style_set(label, FBR_STYLE_LOADING_LABEL);
67         elm_object_text_set(label, _(FBR_TEXT_LOADING));
68         elm_object_content_set(popup, label);
69         scale = elm_config_scale_get();
70
71         icon = elm_icon_add(popup);
72         if (!icon)
73                 goto error;
74
75         snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR, FBR_IMAGE_LOADING);
76         elm_image_file_set(icon, buf, NULL);
77         elm_image_animated_set(icon, EINA_TRUE);
78         elm_image_animated_play_set(icon, EINA_TRUE);
79         evas_object_size_hint_min_set(icon, POPUP_ICON_SIZE * scale,
80                 POPUP_ICON_SIZE * scale);
81         elm_object_part_content_set(popup, FBR_POPUP_SWALLOW_ICON, icon);
82
83         m->transit = elm_transit_add();
84         if (!m->transit)
85                 goto error;
86
87         elm_transit_object_add(m->transit, icon);
88         elm_transit_effect_rotation_add(m->transit, 0, 360);
89         elm_transit_duration_set(m->transit, 1);
90         elm_transit_repeat_times_set(m->transit, 5);
91         elm_transit_objects_final_state_keep_set(m->transit, EINA_TRUE);
92         elm_transit_go(m->transit);
93
94         return true;
95
96 error:
97         evas_object_del(popup);
98
99         return false;
100 }
101
102 void CPopup::Destroy(void)
103 {
104         if (!m)
105                 return;
106
107         if (m->transit) {
108                 elm_transit_del(m->transit);
109         }
110         evas_object_del(m->popup);
111
112         delete m;
113         m = NULL;
114 }