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