movie/music: update play info when there is no recent item
[profile/tv/apps/native/air_mediahub.git] / src / main.c
1 /*
2  * Copyright (c) 2015 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 <app.h>
18 #include <Elementary.h>
19 #include <efl_util.h>
20 #include <app_debug.h>
21 #include <app_define.h>
22 #include <viewmgr.h>
23 #include <inputmgr.h>
24
25 #include "define.h"
26 #include "view.h"
27
28 #define MEDIAHUB_WIN_TITLE PACKAGE
29
30 #define APP_ID_FAVORITE "org.tizen.favorite"
31 #define APP_ID_RECENT "org.tizen.home"
32
33 SET_TAG(PACKAGE)
34
35 struct _appdata {
36         const char *name;
37         Evas_Object *win;
38 };
39
40 static Evas_Object *_add_win(const char *name)
41 {
42         Evas_Object *win;
43         int w, h;
44
45         win = elm_win_add(NULL, name, ELM_WIN_BASIC);
46         if (!win)
47                 return NULL;
48
49         elm_win_title_set(win, MEDIAHUB_WIN_TITLE);
50         elm_win_alpha_set(win, EINA_TRUE);
51         elm_win_role_set(win, "video");
52         elm_win_screen_size_get(win, NULL, NULL, &w, &h);
53         evas_object_resize(win, w, h);
54         efl_util_set_window_opaque_state(win, 1);
55
56         evas_object_show(win);
57
58         return win;
59 }
60
61 static bool _create(void *data)
62 {
63         struct _appdata *ad;
64         Evas_Object *win;
65
66         if (!data) {
67                 _ERR("failed to get data");
68                 return false;
69         }
70
71         ad = data;
72
73         elm_app_base_scale_set(APP_BASE_SCALE);
74         elm_theme_overlay_add(NULL, THEMEFILE);
75         elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
76
77         win = _add_win(ad->name);
78         if (!win) {
79                 _ERR("failed to create win object");
80                 return false;
81         }
82
83         if (!viewmgr_create(win)) {
84                 _ERR("failed to initialize viewmgr");
85                 evas_object_del(win);
86                 return false;
87         }
88
89         viewmgr_add_view(view_base_get_vclass(), NULL);
90         viewmgr_add_view(view_detail_get_vclass(), NULL);
91         viewmgr_add_view(view_viewer_get_vclass(), NULL);
92         viewmgr_add_view(view_mplayer_get_vclass(), NULL);
93         viewmgr_add_view(view_action_menu_get_vclass(), NULL);
94         viewmgr_add_view(view_zoom_get_vclass(), NULL);
95
96         elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
97         elm_win_focus_highlight_style_set(win, STYLE_INVISIBLE);
98
99         ad->win = win;
100
101         return true;
102 }
103
104 static void _terminate(void *data)
105 {
106         struct _appdata *ad;
107
108         if (!data) {
109                 _ERR("failed to get data");
110                 return;
111         }
112
113         ad = data;
114
115         viewmgr_remove_view(VIEW_BASE);
116         viewmgr_remove_view(VIEW_DETAIL);
117         viewmgr_remove_view(VIEW_VIEWER);
118         viewmgr_remove_view(VIEW_MPLAYER);
119         viewmgr_remove_view(VIEW_ACTION_MENU);
120         viewmgr_remove_view(VIEW_ZOOM);
121
122         viewmgr_destroy();
123
124         if (ad->win) {
125                 evas_object_del(ad->win);
126                 ad->win = NULL;
127         }
128 }
129
130 static void _app_control(app_control_h app_control, void *data)
131 {
132         struct _appdata *ad;
133         char *media_id;
134         char *caller_id;
135         int r;
136
137         if (!data) {
138                 _ERR("failed to get data");
139                 return;
140         }
141
142         ad = data;
143
144         if (ad->win)
145                 elm_win_activate(ad->win);
146
147         r = app_control_get_caller(app_control, &caller_id);
148         if (r != APP_CONTROL_ERROR_NONE)
149                 caller_id = NULL;
150
151         r = app_control_get_extra_data(app_control, PARAM_MEDIA_ID, &media_id);
152         if (r != APP_CONTROL_ERROR_NONE)
153                 media_id = NULL;
154
155         if (media_id && caller_id) {
156                 if (!strcmp(caller_id, APP_ID_FAVORITE)) {
157                         while (viewmgr_active_view_count() > 0)
158                                 viewmgr_pop_view();
159
160                         viewmgr_update_view(VIEW_BASE,
161                                         UPDATE_FAVORITE, media_id);
162                 } else if (!strcmp(caller_id, APP_ID_RECENT)) {
163                         viewmgr_push_view(VIEW_BASE);
164                         viewmgr_update_view(VIEW_BASE,
165                                         UPDATE_RECENT, media_id);
166                 }
167         } else
168                 viewmgr_push_view(VIEW_BASE);
169
170         free(media_id);
171         free(caller_id);
172 }
173
174 static void _pause(void *data)
175 {
176         inputmgr_enable(EINA_FALSE);
177         viewmgr_pause();
178 }
179
180 static void _resume(void *data)
181 {
182         inputmgr_enable(EINA_TRUE);
183         viewmgr_resume();
184 }
185
186 int main(int argc, char **argv)
187 {
188         struct _appdata ad;
189         ui_app_lifecycle_callback_s cb = {
190                 .create = _create,
191                 .terminate = _terminate,
192                 .app_control = _app_control,
193                 .pause = _pause,
194                 .resume = _resume,
195         };
196
197         memset(&ad, 0x0, sizeof(ad));
198         ad.name = PACKAGE;
199
200         ui_app_main(argc, argv, &cb, &ad);
201
202         return 0;
203 }