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