Remove key defs
[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 <aul.h>
21 #include "i18n.h"
22
23 #include "AppCommon.h"
24 #include "define.h"
25 #include "common.h"
26 #include "dbg.h"
27 #include "Popup.h"
28
29 #define MAX_POPUP_TIME 10 /* seconds */
30 #define POPUP_ICON_SIZE 48
31
32 struct SPopup {
33         Evas_Object *popup;
34         Elm_Transit *transit;
35 };
36
37 bool CPopup::Create(Evas_Object* base)
38 {
39         ASSERT(base);
40
41         if (m)
42                 return false;
43
44         m = new SPopup;
45         if (!m)
46                 return false;
47
48         Evas_Object *popup, *label, *icon;
49         double scale;
50         char buf[MAX_LENGTH];
51
52         popup = elm_popup_add(base);
53         if (!popup)
54                 return NULL;
55
56         elm_object_style_set(popup, FBR_STYLE_LOADING_POPUP);
57         elm_popup_orient_set(popup, ELM_POPUP_ORIENT_TOP_RIGHT);
58         elm_popup_timeout_set(popup, MAX_POPUP_TIME);
59         evas_object_show(popup);
60
61         label = elm_label_add(popup);
62         if (!label)
63                 goto error;
64
65         elm_object_style_set(label, FBR_STYLE_LOADING_LABEL);
66         elm_object_text_set(label, _(FBR_TEXT_LOADING));
67         elm_object_content_set(popup, label);
68         scale = elm_config_scale_get();
69
70         icon = elm_icon_add(popup);
71         if (!icon)
72                 goto error;
73
74         snprintf(buf, sizeof(buf), "%s/%s", IMAGEDIR, FBR_IMAGE_LOADING);
75         elm_image_file_set(icon, buf, NULL);
76         elm_image_animated_set(icon, EINA_TRUE);
77         elm_image_animated_play_set(icon, EINA_TRUE);
78         evas_object_size_hint_min_set(icon, POPUP_ICON_SIZE * scale,
79                 POPUP_ICON_SIZE * scale);
80         elm_object_part_content_set(popup, FBR_POPUP_SWALLOW_ICON, icon);
81
82         m->transit = elm_transit_add();
83         if (!m->transit)
84                 goto error;
85
86         elm_transit_object_add(m->transit, icon);
87         elm_transit_effect_rotation_add(m->transit, 0, 360);
88         elm_transit_duration_set(m->transit, 1);
89         elm_transit_repeat_times_set(m->transit, 5);
90         elm_transit_objects_final_state_keep_set(m->transit, EINA_TRUE);
91         elm_transit_go(m->transit);
92
93         return true;
94
95 error:
96         evas_object_del(popup);
97
98         return false;
99 }
100
101 void CPopup::Destroy(void)
102 {
103         if (!m)
104                 return;
105
106         if (m->transit) {
107                 elm_transit_del(m->transit);
108         }
109         evas_object_del(m->popup);
110
111         delete m;
112         m = NULL;
113 }