convert c files to cpp
[profile/tv/apps/native/videoplayer.git] / src / main.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 <app.h>
18 #include <Elementary.h>
19 #include <dbg.h>
20 #include "define.h"
21 #include "view_player.h"
22 #include "i18n.h"
23
24 #define PARAM_URI "uri"
25 #define PARAM_PLAYLIST_ID "playlist_id"
26
27 struct _appdata {
28         const char *name;
29         Evas_Object *win;
30
31         struct viewdata *vdata;
32 };
33
34 static Evas_Object *_add_win(const char *name)
35 {
36         Evas_Object *win;
37         Evas_Object *obj;
38         Evas *evas;
39
40         if (!name)
41                 return NULL;
42
43         win = elm_win_add(NULL, name, ELM_WIN_BASIC);
44         if (!win)
45                 return NULL;
46
47         elm_win_title_set(win, "Video player");
48
49         evas_object_show(win);
50
51         evas = evas_object_evas_get(win);
52         obj = evas_object_rectangle_add(evas);
53         evas_object_color_set(obj, 0, 0, 0, 0);
54         evas_object_render_op_set(obj, EVAS_RENDER_COPY);
55         elm_win_resize_object_add(win, obj);
56         evas_object_show(obj);
57
58         return win;
59 }
60
61 static bool _create(void *user_data)
62 {
63         struct _appdata *ad;
64         Evas_Object *win;
65
66         if (!user_data)
67                 return false;
68
69         ad = (_appdata *)user_data;
70
71         elm_theme_overlay_add(NULL, THEMEFILE);
72         elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
73
74         win = _add_win(ad->name);
75         if (!win)
76                 return false;
77
78         ad->win = win;
79
80         elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
81         elm_win_focus_highlight_style_set(win, STYLE_INVISIBLE);
82
83         return true;
84 }
85
86 static void _terminate(void *user_data)
87 {
88         struct _appdata *ad;
89
90         if (!user_data)
91                 return;
92
93         ad = (_appdata *)user_data;
94
95         view_player_fini(ad->vdata);
96 }
97
98 static void _pause(void *user_data)
99 {
100         struct _appdata *ad;
101
102         if (!user_data) {
103                 _ERR("App Data is NULL");
104                 return;
105         }
106
107         ad = (_appdata *)user_data;
108         if (!ad->vdata)
109                 return;
110
111         view_player_pause(ad->vdata);
112 }
113
114 static void _resume(void *user_data)
115 {
116         struct _appdata *ad;
117
118         if (!user_data) {
119                 _ERR("App Data is NULL");
120                 return;
121         }
122
123         ad = (_appdata *)user_data;
124         if (!ad->vdata)
125                 return;
126
127         view_player_resume(ad->vdata);
128 }
129
130 static void _service(service_h service, void *user_data)
131 {
132         struct _appdata *ad;
133         struct viewdata *vdata;
134         char *uri;
135         char *playlist_id;
136         int r;
137
138         if (!user_data)
139                 return;
140
141         ad = (_appdata *)user_data;
142
143         r = service_get_extra_data(service, PARAM_URI, &uri);
144         if (r != SERVICE_ERROR_NONE)
145                 uri = NULL;
146
147         r = service_get_extra_data(service, PARAM_PLAYLIST_ID, &playlist_id);
148         if (r != SERVICE_ERROR_NONE)
149                 playlist_id = NULL;
150
151         vdata = view_player_init(ad->win, uri, playlist_id);
152
153         free(uri);
154         free(playlist_id);
155
156         if (!vdata)
157                 elm_exit();
158
159         if (view_player_create(vdata) == -1)
160                 elm_exit();
161
162         ad->vdata = vdata;
163 }
164
165 int main(int argc, char **argv)
166 {
167         struct _appdata ad;
168         app_event_callback_s cbs = {
169                 .create = _create,
170                 .terminate = _terminate,
171                 .pause = _pause,
172                 .resume = _resume,
173                 .service = _service,
174         };
175
176         memset(&ad, 0x00, sizeof(ad));
177         ad.name = PACKAGE;
178
179         memset(&cbs, 0x00, sizeof(cbs));
180         cbs.create = _create;
181         cbs.terminate = _terminate;
182         cbs.pause = _pause;
183         cbs.resume = _resume;
184         cbs.service = _service;
185
186         i18n_init();
187
188         app_efl_main(&argc, &argv, &cbs, &ad);
189
190         return 0;
191 }