git mv include/def.h include/common_defs.h
[profile/tv/apps/native/settings.git] / src / main.cpp
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
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 <ui-gadget.h>
18 #include "common_defs.h"
19 #include <AppCommon.h>
20 #include "settingviewmgr.h"
21 #include "utils.h"
22 #include "json_marco.h"
23 #include "settings_provider.h"
24
25 #include <vconf.h>
26
27 #define PARAM_SETTINGS_ITEM "settings-item"
28 #define MAIN_CATALOG "maincatalog"
29
30
31 SET_TAG("org.tizen.settings-tv-ref");
32
33 Evas_Object *_add_win(const char *name)
34 {
35         Evas_Object *win;
36
37         win = elm_win_add(NULL, name, ELM_WIN_BASIC);
38         if (!win) {
39                 _ERR("failed to create window!");
40                 return NULL;
41         }
42
43         elm_win_title_set(win, name);
44         elm_win_alpha_set(win, EINA_TRUE);
45
46         elm_win_focus_highlight_enabled_set(win, EINA_TRUE);
47         elm_win_focus_highlight_style_set(win, DEFAULT_FOCUS_INVISIBLE);
48
49         evas_object_show(win);
50
51         return win;
52 }
53
54 class CApp : public CBaseApp {
55
56         struct _appdata {
57                 Evas_Object *win;
58                 CSettingMgr *mgr;
59                 const char *name;
60                 char *item;
61                 unsigned int app_control;
62         } ad;
63 protected:
64
65         virtual bool OnCreate(void)
66         {
67                 Evas_Object *win;
68                 int r;
69
70                 elm_theme_overlay_add(NULL, EDJ_THEME);
71
72                 win = _add_win(ad.name);
73                 if (!win)
74                         return false;
75
76                 r = UG_INIT_EFL(win, UG_OPT_INDICATOR_ENABLE);
77                 if (r == -1) {
78                         _ERR("ug init efl failed.");
79                         evas_object_del(win);
80                         return false;
81                 }
82
83                 r = provider_init();
84                 if (r != 0) {
85                         _ERR("Fail to init provider module");
86                         evas_object_del(win);
87                         return false;
88                 }
89
90                 ad.win = win;
91                 ad.item = NULL;
92                 ad.app_control = 0;
93
94                 /* Set Default value by vconf */
95
96                 /* Proxy */
97                 if(vconf_set_int(VCONF_PROXY_METHOD, 0)) _DBG("Fail to set vconf");
98                 if(vconf_set_str(VCONF_PROXY_IP, "0.0.0.0")) _DBG("Fail to set vconf");
99                 if(vconf_set_str(VCONF_PROXY_URL, "")) _DBG("Fail to set vconf");
100
101                 /* Network */
102                 if(vconf_set_str(WIRED_DNS_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
103                 if(vconf_set_str(WIRED_GATEWAY_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
104                 if(vconf_set_str(WIRED_IP_LAST_MODE, "Obtain automatically")) _DBG("Fail to set vconf");
105                 if(vconf_set_str(WIRED_DNS_LAST_MODE, "Obtain automatically")) _DBG("Fail to set vconf");
106                 if(vconf_set_str(WIRED_IP_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
107                 if(vconf_set_str(WIRED_SUBMASK_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
108
109                 if(vconf_set_str(WIRELESS_DNS_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
110                 if(vconf_set_str(WIRELESS_GATEWAY_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
111                 if(vconf_set_str(WIRELESS_IP_LAST_MODE, "Obtain automatically")) _DBG("Fail to set vconf");
112                 if(vconf_set_str(WIRELESS_DNS_LAST_MODE, "Obtain automatically")) _DBG("Fail to set vconf");
113                 if(vconf_set_str(WIRELESS_IP_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
114                 if(vconf_set_str(WIRELESS_SUBMASK_KEY, "0.0.0.0")) _DBG("Fail to set vconf");
115
116                 /* Time */
117                 if(vconf_set_int(KEY_SYSTEM_CLOCK_MODE, 0)) _DBG("Fail to set vconf");
118                 if(vconf_set_int(KEY_SLEEPTIMER, 0)) _DBG("Fail to set vconf");
119                 if(vconf_set_int(KEY_SLEEPTIMER_TIMERID, 0)) _DBG("Fail to set vconf");
120                 if(vconf_set_str(KEY_WAKEUP_TIMER_SETUP, "OFF")) _DBG("Fail to set vconf");
121
122                 if(vconf_set_int(VCONF_KEY_24HOUR_MODE, 0)) _DBG("Fail to set vconf");
123                 if(vconf_set_str(KEY_CHANGE_PASSCODE, "0000")) _DBG("Fail to set vconf");
124                 if(vconf_set_int(KEY_SUBTITLE_LANGUAGE, 0)) _DBG("Fail to set vconf");
125
126                 /* Broadcasting */
127                 if(vconf_set_bool(KEY_CHANNEL_LOCK, false)) _DBG("Fail to set vconf");
128
129                 /* Lang and Region */
130                 if(vconf_set_str(KEY_SYSTEM_LANGUAGE, "en_US.UTF-8")) _DBG("Fail to set vconf");
131                 if(vconf_set_str(KEY_SYSTEM_COUNTRY, "en_US.UTF-8")) _DBG("Fail to set vconf");
132
133                 return true;
134         }
135
136         virtual void OnTerminate(void)
137         {
138                 CSettingMgr::Finalize();
139                 ad.mgr = NULL;
140
141                 provider_fini();
142
143                 if (ad.win)
144                         evas_object_del(ad.win);
145
146                 if(ad.item)
147                         free(ad.item);
148         }
149         virtual void OnAppControl(app_control_h app_control)
150         {
151                 _DBG("  ******************* OnAppControl *********************");
152                 CSettingMgr *mgr;
153                 int r;
154                 char *param;
155                 unsigned int relaunch, refresh;
156
157                 param = NULL;
158
159                 if (ad.app_control) {
160                         app_control_get_extra_data(app_control, PARAM_SETTINGS_ITEM, &param);
161                         if ((!param && !ad.item) ||
162                                         (param && ad.item &&
163                                          !strcmp(ad.item, param))) {
164                                 refresh = 1;
165                                 relaunch = 0;
166                         } else {
167                                 refresh = 0;
168                                 relaunch = 1;
169                         }
170
171                         if (relaunch) {
172                                 CSettingMgr::Finalize();
173                         } else {
174                                 if (refresh)
175                                 {
176                                         if (!ad.mgr)
177                                                 return;
178
179                                         ad.mgr->ViewRefresh();
180                                 }
181                         }
182                 }
183
184                 if (!CSettingMgr::Initialize(ad.win))
185                         app_efl_exit();
186                 mgr = CSettingMgr::GetInstance();
187
188                 r = app_control_get_extra_data(app_control, PARAM_SETTINGS_ITEM, &param);
189                 if (r == APP_CONTROL_ERROR_NONE && param) {
190                         if (!mgr->LaunchItem(param)) {
191                                 _ERR("the item is not exist.");
192                                 app_efl_exit();
193                         }
194                 } else {
195                         mgr->ViewPush(MAIN_CATALOG, NULL);
196                 }
197
198                 ad.mgr = mgr;
199                 ad.app_control = 1;
200
201                 free(ad.item);
202                 ad.item = param;
203         }
204
205 public:
206
207         virtual int Run(int argc, char **argv) {
208                 memset(&ad, 0x00, sizeof(_appdata));
209                 ad.name = PACKAGE;
210
211                 return CBaseApp::Run(argc, argv);
212         }
213 };
214
215 int main(int argc, char **argv)
216 {
217         CApp app;
218         app.Run(argc, argv);
219
220         return 0;
221 }
222