dbg.h file is removed.
[profile/tv/apps/native/source.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 <AppCommon.h>
18 #include "def.h"
19 #include "source_mgr.h"
20 #include "allsource_view.h"
21 #include "menu_view.h"
22
23
24 SET_TAG("source-list");
25
26 static Evas_Object *_add_win(const char *name)
27 {
28         Evas_Object *win;
29
30         win = elm_win_util_standard_add(name, NULL);
31         if (!win) {
32                 _ERR("failed to create window!");
33                 return NULL;
34         }
35
36         elm_win_title_set(win, name);
37         elm_win_focus_highlight_style_set(win, "invisible");
38         elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
39
40         evas_object_show(win);
41
42         return win;
43 }
44
45
46 static Evas_Object *_add_bg(Evas_Object *win)
47 {
48         Evas_Object *bg;
49
50         if (!win)
51                 return NULL;
52
53         bg = elm_layout_add(win);
54         if (!bg)
55                 return NULL;
56
57         elm_layout_file_set(bg, EDJ_FILE, GRP_BG);
58
59         evas_object_size_hint_weight_set(bg,
60                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61
62         elm_win_resize_object_add(win, bg);
63         evas_object_show(bg);
64
65         return bg;
66 }
67
68
69
70 class CApp : public CBaseApp {
71 private:
72         Evas_Object *m_win;
73         Evas_Object *m_bg;
74
75         CAllSourceView *pAllSourceView;
76         CMenuView      *pMenuView;
77
78 public:
79         CApp() : m_win(0) {}
80         virtual ~CApp() {}
81
82         virtual bool OnCreate(void)
83         {
84                 if (m_win)
85                         return false;
86
87                 elm_theme_overlay_add(NULL, EDJ_THEME);
88
89                 m_win = _add_win(PACKAGE);
90                 if (!m_win)
91                         return false;
92
93                 if (!CViewMgr::Initialize(m_win, NULL)) {
94                         evas_object_del(m_win);
95                         m_win = NULL;
96                         return false;
97                 }
98
99                 pAllSourceView = new CAllSourceView(ALLSOURCE_VIEW);
100                 pMenuView = new CMenuView(MENU_VIEW);
101
102                 CViewMgr::GetInstance()->AddView(pAllSourceView);
103                 CViewMgr::GetInstance()->AddView(pMenuView);
104
105                 m_bg = _add_bg(m_win);
106
107                 return true;
108         }
109
110         virtual void OnTerminate(void)
111         {
112                 if (!m_win)
113                         return;
114
115                 CViewMgr::Finalize();
116
117                 delete pAllSourceView;
118                 delete pMenuView;
119
120                 evas_object_del(m_bg);
121                 evas_object_del(m_win);
122                 m_win = NULL;
123         }
124
125         virtual void OnAppControl(app_control_h app_control)
126         {
127                 if (!m_win)
128                         return;
129
130                 enum launch_mode lmode;
131                 char *mode;
132                 int ret;
133
134                 mode = NULL;
135                 lmode = SRC_PLUGGED;
136
137                 ret = app_control_get_extra_data(app_control, "mode", &mode);
138                 if (ret == APP_CONTROL_ERROR_NONE) {
139                         if (!strcmp(mode, "plugged"))
140                                 lmode = SRC_PLUGGED;
141                         else if (!strcmp(mode, "nearby"))
142                                 lmode = SRC_NEARBY;
143
144                         free(mode);
145                 }
146
147                 if (!CViewMgr::GetInstance()->PushView(ALLSOURCE_VIEW, (void *)lmode)) {
148                         _ERR("push view error.");
149                         app_efl_exit();
150                 }
151         }
152
153         virtual int Run(int argc, char **argv)
154         {
155                 m_win = NULL;
156                 return CBaseApp::Run(argc, argv);
157         }
158 };
159
160 int main(int argc, char **argv)
161 {
162         CApp app;
163
164         app.Run(argc, argv);
165
166         return 0;
167 }