Fix UI issue / Launch issue / Mediadata issue
[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 <string.h>
18 #include <app.h>
19 #include <Elementary.h>
20 #include <Eina.h>
21 #include "dbg.h"
22 #include "define.h"
23 #include "BaseApp.h"
24
25 #include <BaseView.h>
26 #include <ViewMgr.h>
27 #include <CtxPopup.h>
28 #include <InputHandler.h>
29
30 #include "FbBaseView.h"
31 #include <ExtNameInfo.h>
32 #include "FbContextView.h"
33
34 #include <SortMgr.h>
35
36 #define PARAM_SOURCE "source"
37 #define FBR_WIN_TITLE "File Browser"
38
39 Evas_Object *_add_win(const char *name)
40 {
41         Evas_Object *win;
42
43         //win = elm_win_add(NULL, name, ELM_WIN_BASIC);
44         win = elm_win_util_standard_add(name, NULL);
45         if (!win)
46                 return NULL;
47
48         elm_win_title_set(win, FBR_WIN_TITLE);
49         elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
50         elm_win_focus_highlight_style_set(win, FBR_STYLE_WIN_FOCUS);
51         elm_config_focus_move_policy_set(ELM_FOCUS_MOVE_POLICY_CLICK);
52         evas_object_show(win);
53
54         return win;
55 }
56
57 class CApp : public CBaseApp {
58
59         struct _appdata {
60                 const char   *name;
61                 Evas_Object  *win;
62                 char         *source;
63         }   ad;
64
65         CFbBaseView  *pFbBaseView;
66         CContextView *pContextView;
67 protected:
68
69         virtual bool OnCreate(void)
70         {
71                 Evas_Object *win;
72
73                 elm_theme_overlay_add(NULL, THEMEFILE);
74
75                 win = _add_win(ad.name);
76                 if (!win)
77                         return false;
78
79                 ad.win = win;
80                 
81                 return true;
82         }
83
84         virtual void OnTerminate(void)
85         {
86                 CViewMgr::Finalize();
87
88                 if (ad.win)
89                         evas_object_del(ad.win);
90
91                 free(ad.source);
92         }
93
94         virtual void OnService(service_h service)
95         {
96                 char *source;
97                 int r;
98                 CViewMgr* viewmgr = NULL;
99
100                 _DBG("  ******************* OnService *********************");
101                 elm_win_activate(ad.win);
102
103                 r = service_get_extra_data(service, PARAM_SOURCE, &source);
104                 if (r != SERVICE_ERROR_NONE)
105                         source = NULL;
106
107                 if (source) {
108                         ad.source = strdup(source);
109                         free(source);
110                 }
111                 else
112                 {
113                         ad.source = strdup("all");
114                 }
115
116                 CSortMgr::Initialize();
117
118                 CViewMgr::Initialize(ad.win,NULL);
119                 viewmgr = CViewMgr::GetInstance();
120                 if(!viewmgr) {
121                         _ERR("Fail to get viewmgr instance");
122                         goto error;
123                 }
124
125                 pFbBaseView = new CFbBaseView(FBR_BASE_VIEW);
126                 if(!viewmgr->AddView(pFbBaseView))
127                 {
128                         _ERR("Fail to add pFbBaseView");
129                         goto error;
130                 }
131
132                 pContextView = new CContextView(FBR_CONTEXT_VIEW);
133                 if(!viewmgr->AddView(pContextView))
134                 {
135                         _ERR("Fail to add pContextView");
136                         goto error;
137                 }
138
139                 if (!viewmgr->PushView(FBR_BASE_VIEW, ad.source)) {
140                         _ERR("Fail to push view");
141                         goto error;
142                 }
143                 return;
144
145         error:
146                 CViewMgr::Finalize();
147                 elm_exit();
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 }