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