apply the CBaseApp
[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 <AppCommon.h>
21 #include <BaseApp.h>
22 #include "define.h"
23 #include "view_player.h"
24 #include "i18n.h"
25
26 #define WIN_TITLE "Video Player"
27 #define PARAM_URI "uri"
28 #define PARAM_PLAYLIST_ID "playlist_id"
29
30 struct SAppData {
31         const char *name;
32         Evas_Object *win;
33         viewdata *vdata;
34 };
35
36 class CVideoPlayerApp : public CBaseApp {
37 private:
38         SAppData *m_pApp;
39
40 private:
41         static Evas_Object *sm_AddWin(const char *name);
42
43 public:
44         CVideoPlayerApp(void);
45         virtual ~CVideoPlayerApp(void);
46         virtual bool OnCreate(void);
47         virtual void OnPause(void);
48         virtual void OnResume(void);
49         virtual void OnTerminate(void);
50         virtual void OnService(service_h service);
51         virtual int Run(int argc, char **argv);
52 };
53
54 CVideoPlayerApp::CVideoPlayerApp(void)
55 {
56         m_pApp = new SAppData;
57 }
58
59 CVideoPlayerApp::~CVideoPlayerApp(void)
60 {
61         delete m_pApp;
62         m_pApp = NULL;
63 }
64
65 Evas_Object *CVideoPlayerApp::sm_AddWin(const char *name)
66 {
67         Evas_Object *win;
68         Evas_Object *obj;
69         Evas *evas;
70
71         if (!name)
72                 return NULL;
73
74         win = elm_win_add(NULL, name, ELM_WIN_BASIC);
75         if (!win)
76                 return NULL;
77
78         elm_win_title_set(win, WIN_TITLE);
79
80         evas_object_show(win);
81
82         evas = evas_object_evas_get(win);
83         obj = evas_object_rectangle_add(evas);
84         evas_object_color_set(obj, 0, 0, 0, 0);
85         evas_object_render_op_set(obj, EVAS_RENDER_COPY);
86         elm_win_resize_object_add(win, obj);
87         evas_object_show(obj);
88
89         return win;
90 }
91
92 bool CVideoPlayerApp::OnCreate(void)
93 {
94         ASSERT(m_pApp);
95
96         Evas_Object *win;
97
98         elm_theme_overlay_add(NULL, THEMEFILE);
99         elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
100
101         win = sm_AddWin(m_pApp->name);
102         if (!win) {
103                 _ERR("failed to add window");
104                 return false;
105         }
106
107         elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
108         elm_win_focus_highlight_style_set(win, STYLE_INVISIBLE);
109
110         m_pApp->win = win;
111
112         return true;
113 }
114
115 void CVideoPlayerApp::OnTerminate(void)
116 {
117         ASSERT(m_pApp);
118
119         if (m_pApp->vdata)
120                 view_player_fini(m_pApp->vdata);
121
122         if (m_pApp->win)
123                 evas_object_del(m_pApp->win);
124 }
125
126 void CVideoPlayerApp::OnPause(void)
127 {
128         ASSERT(m_pApp);
129
130         if (!m_pApp->vdata)
131                 return;
132
133         view_player_pause(m_pApp->vdata);
134 }
135
136 void CVideoPlayerApp::OnResume(void)
137 {
138         ASSERT(m_pApp);
139
140         if (!m_pApp->vdata)
141                 return;
142
143         view_player_resume(m_pApp->vdata);
144 }
145
146 void CVideoPlayerApp::OnService(service_h service)
147 {
148         ASSERT(m_pApp);
149
150         viewdata *vdata;
151         char *uri;
152         char *playlist_id;
153         int r;
154
155         r = service_get_extra_data(service, PARAM_URI, &uri);
156         if (r != SERVICE_ERROR_NONE)
157                 uri = NULL;
158
159         r = service_get_extra_data(service, PARAM_PLAYLIST_ID, &playlist_id);
160         if (r != SERVICE_ERROR_NONE)
161                 playlist_id = NULL;
162
163         vdata = view_player_init(m_pApp->win, uri, playlist_id);
164
165         free(uri);
166         free(playlist_id);
167
168         if (!vdata)
169                 elm_exit();
170
171         if (view_player_create(vdata) == -1)
172                 elm_exit();
173
174         m_pApp->vdata = vdata;
175 }
176
177 int CVideoPlayerApp::Run(int argc, char **argv)
178 {
179         ASSERT(m_pApp);
180
181         m_pApp->name = PACKAGE;
182
183         return CBaseApp::Run(argc, argv);
184 }
185
186 int main(int argc, char **argv)
187 {
188         CVideoPlayerApp app;
189
190         app.Run(argc, argv);
191
192         return 0;
193 }