2 * Copyright 2012 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.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
8 * http://floralicense.org/license/
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.
17 #include "advancedview.h"
23 #include <Elementary.h>
26 #include <dpl/foreach.h>
27 #include <dpl/assert.h>
28 #include <dpl/wrt-dao-ro/WrtDatabase.h>
29 #include <dpl/wrt-dao-ro/vconf_config.h>
30 #include <dpl/wrt-dao-rw/widget_dao.h>
31 #include "exceptionsview.h"
34 namespace WebAppDetailSetting {
37 const char* const ELM_STYLE_CHECKBOX = "checkbox";
38 const char* const ELM_PART_ICON = "elm.icon";
39 const char* const EVAS_SMART_CALLBACK_CHANGED = "changed";
40 const char* const ELM_GENLIST_ITEM_CLASS_STYLE_GROUPINDEX = "groupindex";
41 const char* const ELM_GENLIST_ITEM_CLASS_STYLE_1TEXT = "1text";
42 const char* const ELM_GENLIST_ITEM_CLASS_STYLE_1TEXT_1ICON_6 = "1text.1icon.2";
43 const char* const TEXT_NAVIFRAME_TITLE = "ALLOW LIST";
46 AdvancedView::AdvancedView(Evas_Object *navi, DPL::String appID) :
50 m_groupMenuMap[GROUP_IDX_SECURITY_SETTINGS] = "Security Settings";
51 m_groupMenuMap[GROUP_IDX_DEVELOPER_OPTIONS] = "Developer Options";
53 m_menuMap[SECURITY_SETTINGS_IDX_SECURITY_POPUP_USAGE] =
54 "Show security warnings";
55 m_menuMap[SECURITY_SETTINGS_IDX_GEOLOCATION_USAGE] =
57 m_menuMap[SECURITY_SETTINGS_IDX_WEB_NOTIFICATION_USAGE] =
59 m_menuMap[SECURITY_SETTINGS_IDX_EXCEPTIONS_SETTINGS] =
60 "Exceptions Settings";
61 m_menuMap[DEVELOPER_OPTIONS_IDX_MEMORY_SAVING_MODE] =
65 AdvancedView::~AdvancedView(void)
69 char* AdvancedView::getGroupText(void* data,
74 AdvancedSettingsGroupData* advancedSettingsData =
75 static_cast<AdvancedSettingsGroupData*>(data);
76 return strdup(advancedSettingsData->m_menuText.c_str());
79 void AdvancedView::delGroupData(void* data,
83 AdvancedSettingsGroupData* advancedSettingsData =
84 static_cast<AdvancedSettingsGroupData*>(data);
85 delete advancedSettingsData;
88 char* AdvancedView::getSettingText(void *data,
93 SettingData* settingData = static_cast<SettingData*>(data);
94 return strdup(settingData->m_menuText.c_str());
97 Evas_Object* AdvancedView::getSettingContent(void* data,
102 SettingData* settingData =
103 static_cast<SettingData*>(data);
106 Evas_Object* icon = elm_check_add(obj);
107 elm_check_state_set(icon, EINA_TRUE);
108 elm_object_style_set(icon, ELM_STYLE_CHECKBOX);
109 settingData->m_iconPart = ELM_PART_ICON;
111 evas_object_propagate_events_set(
114 elm_check_state_set(icon, settingData->isEnabled() ? EINA_TRUE : EINA_FALSE);
115 evas_object_smart_callback_add(icon,
116 EVAS_SMART_CALLBACK_CHANGED,
117 settingChangedCallback,
123 void AdvancedView::delSettingData(void* data,
124 Evas_Object* /*obj*/)
127 SettingData* settingData = static_cast<SettingData*>(data);
131 void AdvancedView::settingSelectedCallback(void* data,
136 Elm_Object_Item* item = static_cast<Elm_Object_Item*>(eventInfo);
137 elm_genlist_item_selected_set(item, EINA_FALSE);
139 SettingData* settingData =
140 static_cast<SettingData*>(elm_object_item_data_get(item));
144 elm_object_item_part_content_get(item,
145 settingData->m_iconPart.c_str());
147 bool state = !elm_check_state_get(check);
148 settingData->saveChange(state);
149 elm_check_state_set(check, state);
152 void AdvancedView::settingChangedCallback(void* data,
157 SettingData* settingData =
158 static_cast<SettingData*>(data);
160 settingData->saveChange(elm_check_state_get(obj));
163 char* AdvancedView::getSecurityExceptionsSettingsText(void *data,
168 return strdup("Exceptions Settings");
171 void AdvancedView::securityExceptionsSettingsSelectedCallback(void* data,
176 Elm_Object_Item* item = static_cast<Elm_Object_Item*>(eventInfo);
177 elm_genlist_item_selected_set(item, EINA_FALSE);
180 static_cast<AdvancedView*>(elm_object_item_data_get(item));
182 This->m_exceptionsView.Reset(
183 new ExceptionsView(This->m_naviframe, This->m_appID));
184 if (!This->m_exceptionsView->loadView()) {
185 This->m_exceptionsView.Reset();
189 bool AdvancedView::loadView(void)
193 Evas_Object* genlist = NULL;
194 genlist = elm_genlist_add(m_naviframe);
196 loadSecuritySettingsMenu(genlist);
198 elm_naviframe_item_push(m_naviframe,
199 TEXT_NAVIFRAME_TITLE,
208 void AdvancedView::loadSecuritySettingsMenu(Evas_Object* genlist)
210 for (int index = SECURITY_SETTINGS_IDX_START; index <= SECURITY_SETTINGS_IDX_END; index++) {
211 if (index == SECURITY_SETTINGS_IDX_EXCEPTIONS_SETTINGS) {
212 // create exceptions security settings menu
213 static Elm_Genlist_Item_Class itcSecurityExceptionsSettings = {0,};
214 itcSecurityExceptionsSettings.item_style =
215 ELM_GENLIST_ITEM_CLASS_STYLE_1TEXT;
216 itcSecurityExceptionsSettings.func.text_get = getSecurityExceptionsSettingsText;
217 itcSecurityExceptionsSettings.func.content_get = NULL;
218 itcSecurityExceptionsSettings.func.state_get = NULL;
219 itcSecurityExceptionsSettings.func.del = NULL;
220 elm_genlist_item_append(genlist,
221 &itcSecurityExceptionsSettings,
222 static_cast<void*>(this),
224 ELM_GENLIST_ITEM_NONE,
225 securityExceptionsSettingsSelectedCallback,
230 static Elm_Genlist_Item_Class itcSecuritySettings = {0,};
231 itcSecuritySettings.item_style =
232 ELM_GENLIST_ITEM_CLASS_STYLE_1TEXT_1ICON_6;
233 itcSecuritySettings.func.text_get = getSettingText;
234 itcSecuritySettings.func.content_get = getSettingContent;
235 itcSecuritySettings.func.state_get = NULL;
236 itcSecuritySettings.func.del = delSettingData;
238 elm_genlist_item_append(genlist,
239 &itcSecuritySettings,
242 m_appID, index, m_menuMap[index])),
244 ELM_GENLIST_ITEM_NONE,
245 settingSelectedCallback,
251 void AdvancedView::loadDeveloperOptionsMenu(Evas_Object* genlist)
253 static Elm_Genlist_Item_Class itcDeveloperOptions = {0,};
254 itcDeveloperOptions.item_style =
255 ELM_GENLIST_ITEM_CLASS_STYLE_1TEXT_1ICON_6;
256 itcDeveloperOptions.func.text_get = getSettingText;
257 itcDeveloperOptions.func.content_get = getSettingContent;
258 itcDeveloperOptions.func.state_get = NULL;
259 itcDeveloperOptions.func.del = delSettingData;
261 for (int index = DEVELOPER_OPTIONS_IDX_START; index <= DEVELOPER_OPTIONS_IDX_END; index++) {
262 elm_genlist_item_append(genlist,
263 &itcDeveloperOptions,
266 m_appID, index, m_menuMap[index])),
268 ELM_GENLIST_ITEM_NONE,
269 settingSelectedCallback,
274 SettingData::SettingData(DPL::String appID, int index, std::string menuText) :
275 m_index(static_cast<MenuIndex>(index)),
278 m_dao.Reset(new WrtDB::WidgetDAO(appID));
281 bool SettingData::isEnabled()
283 using namespace WrtDB;
285 if (m_index == SECURITY_SETTINGS_IDX_SECURITY_POPUP_USAGE) {
286 key = VconfConfig::GetVconfKeyPopupUsage(m_dao->getTzAppId());
287 } else if (m_index == SECURITY_SETTINGS_IDX_GEOLOCATION_USAGE) {
288 key = VconfConfig::GetVconfKeyGeolocationUsage(m_dao->getTzAppId());
289 } else if (m_index == SECURITY_SETTINGS_IDX_WEB_NOTIFICATION_USAGE) {
290 key = VconfConfig::GetVconfKeyWebNotificationUsage(
291 m_dao->getTzAppId());
292 } else if (m_index == DEVELOPER_OPTIONS_IDX_MEMORY_SAVING_MODE) {
293 key = VconfConfig::GetVconfKeyMemorySavingMode(m_dao->getTzAppId());
295 Assert("Wrong menu index");
299 vconf_get_int(key.c_str(), &ret);
300 if (static_cast<SettingsType>(ret) == SETTINGS_TYPE_ON) {
302 } else if (static_cast<SettingsType>(ret) == SETTINGS_TYPE_OFF) {
306 Assert("Unsupported value");
307 // For preventing compile warning, even this code isn't necessary.
311 void SettingData::saveChange(bool state)
313 using namespace WrtDB;
314 SettingsType result = state ? SETTINGS_TYPE_ON : SETTINGS_TYPE_OFF;
317 if (m_index == SECURITY_SETTINGS_IDX_SECURITY_POPUP_USAGE) {
318 key = VconfConfig::GetVconfKeyPopupUsage(m_dao->getTzAppId());
319 } else if (m_index == SECURITY_SETTINGS_IDX_GEOLOCATION_USAGE) {
320 key = VconfConfig::GetVconfKeyGeolocationUsage(m_dao->getTzAppId());
321 } else if (m_index == SECURITY_SETTINGS_IDX_WEB_NOTIFICATION_USAGE) {
322 key = VconfConfig::GetVconfKeyWebNotificationUsage(
323 m_dao->getTzAppId());
324 } else if (m_index == DEVELOPER_OPTIONS_IDX_MEMORY_SAVING_MODE) {
325 key = VconfConfig::GetVconfKeyMemorySavingMode(m_dao->getTzAppId());
327 Assert("Wrong menu index");
329 vconf_set_int(key.c_str(), static_cast<int>(result));
332 } /* WebAppDetailSetting */