Fix build error
[profile/tv/apps/native/filebrowser.git] / src / main.cpp
1 /*
2
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 <cstring>
18
19 #include <AppCommon.h>
20 #include "define.h"
21 #include "FbBaseView.h"
22 #include "FbContextView.h"
23
24 #define PARAM_SOURCE "source"
25 #define FBR_WIN_TITLE "File Browser"
26
27 SET_TAG((char*)PACKAGE);
28
29 Evas_Object *_add_win(const char *name)
30 {
31         Evas_Object *win;
32
33         //win = elm_win_add(NULL, name, ELM_WIN_BASIC);
34         win = elm_win_util_standard_add(name, NULL);
35         if (!win)
36                 return NULL;
37
38         elm_win_title_set(win, FBR_WIN_TITLE);
39         elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
40         elm_win_focus_highlight_style_set(win, FBR_STYLE_WIN_FOCUS);
41         elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
42         evas_object_show(win);
43
44         return win;
45 }
46
47 class CApp : public CBaseApp {
48
49         struct _appdata {
50                 const char   *name;
51                 Evas_Object  *win;
52                 char         *source;
53         }   ad;
54
55         CFbBaseView  *pFbBaseView;
56         CContextView *pContextView;
57 protected:
58
59         virtual bool OnCreate(void)
60         {
61                 Evas_Object *win;
62
63                 elm_theme_overlay_add(NULL, THEMEFILE);
64
65                 win = _add_win(ad.name);
66                 if (!win)
67                         return false;
68
69                 ad.win = win;
70                 
71                 elm_win_activate(ad.win);
72                 CViewMgr::Initialize(ad.win,NULL);
73                 CViewMgr* viewmgr = NULL;
74
75                 CSortMgr::Initialize();
76
77                 viewmgr = CViewMgr::GetInstance();
78                 if(!viewmgr) {
79                         _ERR("Fail to get viewmgr instance");
80                         CViewMgr::Finalize();
81                         return false;
82                 }
83
84                 pFbBaseView = new CFbBaseView(FBR_BASE_VIEW);
85                 if(!viewmgr->AddView(pFbBaseView))
86                 {
87                         _ERR("Fail to add pFbBaseView");
88                         CViewMgr::Finalize();
89                         return false;
90                 }
91
92                 pContextView = new CContextView(FBR_CONTEXT_VIEW);
93                 if(!viewmgr->AddView(pContextView))
94                 {
95                         _ERR("Fail to add pContextView");
96                         CViewMgr::Finalize();
97                         return false;
98                 }
99
100                 return true;
101         }
102
103         virtual void OnTerminate(void)
104         {
105                 CViewMgr::Finalize();
106
107                 if (ad.win)
108                         evas_object_del(ad.win);
109
110                 free(ad.source);
111         }
112
113         virtual void OnAppControl(app_control_h app_control)
114         {
115                 _DBG("  ******************* OnAppControl *********************");
116                 char *source;
117                 int r;
118                 
119                 r = app_control_get_extra_data(app_control, PARAM_SOURCE, &source);
120                 if (r != APP_CONTROL_ERROR_NONE)
121                         source = NULL;
122
123                 if (source) {
124                         ad.source = strdup(source);
125                         free(source);
126                 }
127                 else
128                 {
129                         ad.source = strdup("all");
130                 }
131         }
132
133         virtual void OnResume(void)
134         {
135                 _DBG("  ******************* OnService *********************");
136                 CViewMgr* viewmgr = NULL;
137
138                 viewmgr = CViewMgr::GetInstance();
139                 if(!viewmgr) {
140                         _ERR("Fail to get viewmgr instance");
141                         ASSERT(0);
142                         return ;
143                 }
144
145                 if (!viewmgr->PushView(FBR_BASE_VIEW, ad.source)) {
146                         _ERR("Fail to push view");
147                         ASSERT(0);
148                         return ;
149                 }
150         }
151
152 public:
153
154         virtual int Run(int argc, char **argv) {
155                 memset(&ad, 0x00, sizeof(_appdata));
156                 ad.name = PACKAGE;
157
158                 return CBaseApp::Run(argc, argv);
159         }
160 };
161
162 int main(int argc, char **argv)
163 {
164         CApp app;
165         app.Run(argc, argv);
166
167         return 0;
168 }