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