3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 /*@file: IntSettingsPresentationModel.cpp
20 *@brief: Used to define SettingsManager
24 #include "IntCommonLib.h"
25 #include "IntSettingPresentationModel.h"
27 using namespace Tizen::App;
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Io;
31 using namespace Tizen::Ui::Controls;
32 using namespace Tizen::Web::Controls;
34 SettingPresentationModel* SettingPresentationModel::__pSettingsPresentationModel = null;
36 SettingPresentationModel::SettingPresentationModel(void)
38 __listenerList.Construct();
40 __isPrivateOn = false;
43 SettingPresentationModel::SettingPresentationModel(const SettingPresentationModel& settingModelObj)
48 SettingPresentationModel& SettingPresentationModel::operator=(const SettingPresentationModel& settingModelObj)
53 SettingPresentationModel::~SettingPresentationModel(void)
59 SettingPresentationModel::SetDefaultValues(void)
61 //__homePage = CommonUtil::GetString(L"IDS_EMPTY_PAGE");
62 __homePage = CommonUtil::GetString(L"IDS_BR_BODY_MOST_VISITED_SITES");
63 __defaultViewLevel = CommonUtil::GetString(L"IDS_BR_BODY_FIT_TO_WIDTH"); // IDS_FIT_TO_WIDTH
64 __runJsEnabled = true;
65 __displayImages = true;
69 __rememberFormData = false;
70 __rememberPassword = false;
72 __savePassword = CommonUtil::GetString(L"IDS_BR_BODY_ALWAYS_ASK"); // IDS_ALWAYS_ASK
73 __securityWarnings = true;
74 __searchEngine = CommonUtil::GetString(L"IDS_BR_BODY_YAHOO"); // L"Yahoo";
75 __caseSensitive = false;
79 __setting.SetInputStyle(INPUT_STYLE_OVERLAY);
80 __setting.SetAutoImageLoadEnabled(__displayImages);
81 __setting.SetJavascriptEnabled(__runJsEnabled);
82 __setting.SetJavaScriptPopupEnabled(__blockPopUp);
84 if (__securityWarnings == true)
86 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
90 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
95 SettingPresentationModel::CreateInstance(void)
97 if (__pSettingsPresentationModel == null)
98 __pSettingsPresentationModel = new(std::nothrow) SettingPresentationModel();
99 result r = __pSettingsPresentationModel->Construct();
102 delete __pSettingsPresentationModel;
103 __pSettingsPresentationModel = null;
106 std::atexit(DestroyInstance);
109 SettingPresentationModel*
110 SettingPresentationModel::GetInstance(void)
112 if (__pSettingsPresentationModel == null)
116 return __pSettingsPresentationModel;
120 SettingPresentationModel::DestroyInstance(void)
122 if (__pSettingsPresentationModel)
124 delete __pSettingsPresentationModel;
125 __pSettingsPresentationModel = null;
130 SettingPresentationModel::LoadRegistry(void)
132 AppLog("SettingPresentationModel::LoadRegistry entered");
133 result r = E_FAILURE;
136 for (int settingValueName = REGISTRY_SETTING_HOMEPAGE; settingValueName < MAX_REGISTRY_SETTING; settingValueName++)
138 r = AppRegistry::GetInstance()->Get(__entry[settingValueName], __values[settingValueName]);
139 if (r != E_SUCCESS && r != E_KEY_NOT_FOUND)
141 AppLog("Registry Load failed with result %s settingValueName %d", GetErrorMessage(r),settingValueName);
145 if (__values[REGISTRY_SETTING_HOMEPAGE].CompareTo(L"") != 0)
147 __homePage = __values[REGISTRY_SETTING_HOMEPAGE];
148 AppLog("homepage Loading from registry %ls",__homePage.GetPointer());
150 if (__values[REGISTRY_SETTING_DEFAULT_VIEW].CompareTo(L"") != 0)
152 __defaultViewLevel = __values[REGISTRY_SETTING_DEFAULT_VIEW];
154 if (__values[REGISTRY_SETTING_RUN_JAVASCRIPT].CompareTo(L"") != 0)
156 __runJsEnabled = Boolean::Parse(__values[REGISTRY_SETTING_RUN_JAVASCRIPT], false);
157 AppLogDebug("LoadRegistry __runJsEnabled %d",__runJsEnabled);
159 if (__values[REGISTRY_SETTING_DISPLAY_IMAGES].CompareTo(L"") != 0)
161 __displayImages = Boolean::Parse(__values[REGISTRY_SETTING_DISPLAY_IMAGES], false);
162 AppLogDebug("LoadRegistry __displayImages %d",__displayImages);
164 if (__values[REGISTRY_SETTING_HTML5_VIDEOS].CompareTo(L"") != 0)
166 __html5Videos = Boolean::Parse(__values[REGISTRY_SETTING_HTML5_VIDEOS], false);
167 AppLogDebug("LoadRegistry __html5Videos %d",__html5Videos);
169 if (__values[REGISTRY_SETTING_WORD_WRAPPING].CompareTo(L"") != 0)
171 __wordWrap = Boolean::Parse(__values[REGISTRY_SETTING_WORD_WRAPPING], false);
172 AppLogDebug("LoadRegistry __wordWrap %d",__wordWrap);
174 if (__values[REGISTRY_SETTING_BLOCK_POPUP].CompareTo(L"") != 0)
176 __blockPopUp = Boolean::Parse(__values[REGISTRY_SETTING_BLOCK_POPUP], false);
177 AppLogDebug("LoadRegistry __blockPopUp %d",__blockPopUp);
179 if (__values[REGISTRY_SETTING_ACCEPT_COOKIES].CompareTo(L"") != 0)
181 __cookies = Boolean::Parse(__values[REGISTRY_SETTING_ACCEPT_COOKIES], false);
182 AppLogDebug("LoadRegistry __cookies %d",__cookies);
184 if (__values[REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD].CompareTo(L"") != 0)
186 __savePassword = __values[REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD];
188 if (__values[REGISTRY_SETTING_SHOW_SECURITY_WARNINGS].CompareTo(L"") != 0)
190 __securityWarnings = Boolean::Parse(__values[REGISTRY_SETTING_SHOW_SECURITY_WARNINGS], false);
191 AppLogDebug("LoadRegistry __securityWarnings %d",__securityWarnings);
193 if (__values[REGISTRY_SETTING_SEARCH_ENGINE].CompareTo(L"") != 0)
195 __searchEngine = __values[REGISTRY_SETTING_SEARCH_ENGINE];
197 if (__values[REGISTRY_SETTING_CASE_SENSITIVE].CompareTo(L"") != 0)
199 __caseSensitive = Boolean::Parse(__values[REGISTRY_SETTING_CASE_SENSITIVE], false);
200 AppLogDebug("LoadRegistry __caseSensitive %d",__caseSensitive);
202 if (__values[REGISTRY_SETTING_RUN_READER].CompareTo(L"") != 0)
204 __runReader = Boolean::Parse(__values[REGISTRY_SETTING_RUN_READER], false);
205 AppLogDebug("LoadRegistry __runReader %d",__runReader);
207 if (__values[REGISTRY_SETTING_READER_FONT_SIZE].CompareTo(L"") != 0)
209 Integer::Parse(__values[REGISTRY_SETTING_READER_FONT_SIZE], (int&)__fontSize);
211 if (__values[REGISTRY_SETTING_REMEMBER_FORM_DATA].CompareTo(L"") != 0)
213 __rememberFormData = Boolean::Parse(__values[REGISTRY_SETTING_REMEMBER_FORM_DATA], false);
214 AppLogDebug("LoadRegistry form data %d",__rememberFormData);
216 if (__values[REGISTRY_SETTING_REMEMBER_PASSWORD].CompareTo(L"") != 0)
218 __rememberPassword = Boolean::Parse(__values[REGISTRY_SETTING_REMEMBER_PASSWORD], false);
219 AppLogDebug("LoadRegistry form password %d",__rememberPassword);
222 for (int index = REGISTRY_SETTING_HOMEPAGE; index < MAX_REGISTRY_SETTING; index++)
224 AppLogDebug("registry loaded value :%ls at index %d", __values[index].GetPointer(), index);
226 __setting.SetInputStyle(INPUT_STYLE_OVERLAY);
227 __setting.SetAutoImageLoadEnabled(__displayImages);
228 __setting.SetJavascriptEnabled(__runJsEnabled);
229 __setting.SetJavaScriptPopupEnabled(__blockPopUp);
231 if (__securityWarnings == true)
233 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
237 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
239 __favouriteURL.Clear();
240 __favouriteURL = L"";
241 r = AppRegistry::GetInstance()->Get(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], __favouriteURL);
242 AppLog("__favouriteURL taken from registry is %ls",__favouriteURL.GetPointer());
244 if (r != E_SUCCESS && r != E_KEY_NOT_FOUND)
246 AppLogDebug("Registry Load failed with result %s", GetErrorMessage(r));
254 SettingPresentationModel::ResetRegistry(void)
256 result r = E_FAILURE;
258 AppLogDebug("SettingsManager::ResetRegistry");
259 for (int index = REGISTRY_SETTING_INVALID+1; index < MAX_REGISTRY_SETTING; index++)
261 r = AppRegistry::GetInstance()->Remove(__entry[index]);
262 AppLogDebug("Registry Remove result %s",GetErrorMessage(r));
265 AppRegistry::GetInstance()->Save();
267 for (int index = REGISTRY_SETTING_HOMEPAGE; index < MAX_REGISTRY_SETTING; index++)
269 __values[index] = L"";
273 for (int index = 0; index < __listenerList.GetCount(); index++)
275 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
276 if (pSettingsListener)
277 pSettingsListener->OnSettingsReset();
284 SettingPresentationModel::ClearCache(void)
286 for (int index = 0; index < __listenerList.GetCount(); index++)
288 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
289 if (pSettingsListener)
290 pSettingsListener->OnClearCache();
295 SettingPresentationModel::ClearCookie(void)
297 for (int index = 0; index < __listenerList.GetCount(); index++)
299 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
300 if (pSettingsListener)
301 pSettingsListener->OnClearCookie();
306 SettingPresentationModel::Construct(void)
308 result r = E_FAILURE;
310 for (int index = REGISTRY_SETTING_HOMEPAGE; index < MAX_REGISTRY_SETTING; index++)
312 __values[index] = L"";
315 __entry[REGISTRY_SETTING_HOMEPAGE] = L"homePage";
316 __entry[REGISTRY_SETTING_DEFAULT_VIEW] = L"defaultViewLevel";
317 __entry[REGISTRY_SETTING_RUN_JAVASCRIPT] = L"runJs";
318 __entry[REGISTRY_SETTING_DISPLAY_IMAGES] = L"displayImages";
319 __entry[REGISTRY_SETTING_HTML5_VIDEOS] = L"html5Videos";
320 __entry[REGISTRY_SETTING_WORD_WRAPPING] = L"wordWrap";
321 __entry[REGISTRY_SETTING_BLOCK_POPUP] = L"blockPopUp";
322 __entry[REGISTRY_SETTING_ACCEPT_COOKIES] = L"cookies";
323 __entry[REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD] = L"savePassword";
324 __entry[REGISTRY_SETTING_SHOW_SECURITY_WARNINGS] = L"securityWarnings";
325 __entry[REGISTRY_SETTING_SEARCH_ENGINE] = L"searchEngine";
326 __entry[REGISTRY_SETTING_CASE_SENSITIVE] = L"caseSensitive";
327 __entry[REGISTRY_SETTING_RUN_READER] = L"runReader";
328 __entry[REGISTRY_SETTING_READER_FONT_SIZE] = L"fontSize";
329 __entry[REGISTRY_SETTING_FAVORITE_URL_VALUE] = L"Favourite";
330 __entry[REGISTRY_SETTING_REMEMBER_FORM_DATA] = L"formData";
331 __entry[REGISTRY_SETTING_REMEMBER_PASSWORD] = L"rememberPassword";
338 SettingPresentationModel::SetValue(const int settingValueName, const String& val)
340 result r = E_FAILURE;
342 AppLogDebug("SettingsManager::SetValue settingValueName:%d val %ls", settingValueName, val.GetPointer());
343 if (__values[settingValueName] == L"")
345 AppLogDebug("adding the new (std::nothrow) entry into registry");
346 r = AppRegistry::GetInstance()->Add(__entry[settingValueName], val);
350 AppLogDebug("modifying entry into registry");
351 r = AppRegistry::GetInstance()->Set(__entry[settingValueName], val);
353 TryCatch(!IsFailed(r),,"Adding into registry failed %s",GetErrorMessage(r));
355 r = AppRegistry::GetInstance()->Save();
356 TryCatch(!IsFailed(r),,"Save Failed with error %s",GetErrorMessage(r));
358 for (int index = 0; index < __listenerList.GetCount(); index++)
360 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
361 if (pSettingsListener)
362 pSettingsListener->OnSettingsChange(settingValueName);
365 __values[settingValueName] = val;
373 SettingPresentationModel::SetFavoriteValue(const Tizen::Base::String& val)
375 result r = E_FAILURE;
377 if (__favouriteURL == L"")
378 r = AppRegistry::GetInstance()->Add(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], val);
380 r = AppRegistry::GetInstance()->Set(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], val);
381 TryCatch(!IsFailed(r),,"registry set failed with error %s",GetErrorMessage(r));
382 r = AppRegistry::GetInstance()->Save();
383 TryCatch(!IsFailed(r),,"registry set failed with error %s",GetErrorMessage(r));
384 __favouriteURL.Clear();
385 __favouriteURL.Append(val);
392 SettingPresentationModel::GetFavoriteUrl(void)
394 __favouriteURL.Clear();
395 __favouriteURL = L"";
396 AppRegistry::GetInstance()->Get(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], __favouriteURL);
398 return __favouriteURL;
402 SettingPresentationModel::AddSettingsEventListener(const ISettingChangeEventListener& listener)
404 __listenerList.Add(listener);
408 SettingPresentationModel::RemoveSettingsEventListener(ISettingChangeEventListener& listener)
410 __listenerList.Remove(listener, false);
414 SettingPresentationModel::SetHomepage(const String& homePage)
417 __homePage.Append(homePage);
418 AppLog("SettingPresentationModel::SetHomepage %ls",__homePage.GetPointer());
419 SetValue((int) REGISTRY_SETTING_HOMEPAGE, __homePage);
423 SettingPresentationModel::GetHomepage(void)
429 SettingPresentationModel::SetDefaultView(const String& viewLevel)
431 __defaultViewLevel = viewLevel;
432 //CommonUtil::GetString(L"IDS_FIT_TO_WIDTH")
433 if (__defaultViewLevel.CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
435 __setting.SetAutoFittingEnabled(true);
437 else if (__defaultViewLevel.CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_READABLE")) == 0)
439 __setting.SetAutoFittingEnabled(false);
442 SetValue((int) REGISTRY_SETTING_DEFAULT_VIEW, viewLevel);
446 SettingPresentationModel::GetDefaultView(void)
448 return __defaultViewLevel;
452 SettingPresentationModel::SetRunJavascriptEnabled(bool runJsEnabled)
454 __runJsEnabled = runJsEnabled;
455 SetValue((int) REGISTRY_SETTING_RUN_JAVASCRIPT, Boolean::ToString(runJsEnabled));
456 __setting.SetJavascriptEnabled(runJsEnabled);
460 SettingPresentationModel::IsRunJavascriptEnabled(void)
462 return __runJsEnabled;
466 SettingPresentationModel::SetDisplayImagesEnabled(bool displayImages)
468 __displayImages = displayImages;
469 SetValue((int) REGISTRY_SETTING_DISPLAY_IMAGES, Boolean::ToString(displayImages));
470 __setting.SetAutoImageLoadEnabled(__displayImages);
474 SettingPresentationModel::IsDisplayImagesEnabled(void)
476 return __displayImages;
480 SettingPresentationModel::SetHtml5VideosEnabled(bool html5Videos)
482 __html5Videos = html5Videos;
483 SetValue((int) REGISTRY_SETTING_HTML5_VIDEOS, Boolean::ToString(html5Videos));
487 SettingPresentationModel::IsHtml5VideosEnabled(void)
489 return __html5Videos;
493 SettingPresentationModel::SetWordWrapEnabled(bool wordWrap)
495 __wordWrap = wordWrap;
496 SetValue((int) REGISTRY_SETTING_WORD_WRAPPING, Boolean::ToString(wordWrap));
500 SettingPresentationModel::IsWordWrapEnabled(void)
506 SettingPresentationModel::SetBlockPopUp(bool blockPopUp)
508 __blockPopUp = blockPopUp;
509 SetValue((int) REGISTRY_SETTING_BLOCK_POPUP, Boolean::ToString(blockPopUp));
510 __setting.SetJavaScriptPopupEnabled(__blockPopUp);
514 SettingPresentationModel::IsBlockPopUp(void)
520 SettingPresentationModel::SetCookiesEnabled(bool cookiesEnabled)
522 __cookies = cookiesEnabled;
523 SetValue((int) REGISTRY_SETTING_ACCEPT_COOKIES, Boolean::ToString(cookiesEnabled));
527 SettingPresentationModel::IsCookiesEnabled(void)
533 SettingPresentationModel::SetRememberFormData(bool formData)
535 __rememberFormData = formData;
536 SetValue((int) REGISTRY_SETTING_REMEMBER_FORM_DATA, Boolean::ToString(__rememberFormData));
540 SettingPresentationModel::IsRememberFormData(void)
542 return __rememberFormData;
545 void SettingPresentationModel::SetRememberPassword(bool rememberPassword)
547 __rememberPassword = rememberPassword;
548 SetValue((int) REGISTRY_SETTING_REMEMBER_PASSWORD, Boolean::ToString(__rememberPassword));
551 bool SettingPresentationModel::IsRememberPassword(void)
553 return __rememberPassword;
557 SettingPresentationModel::SetSavePassword(const String& savePassword)
559 __savePassword = savePassword;
560 SetValue((int) REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD, savePassword);
564 SettingPresentationModel::GetSavePassword(void)
566 return __savePassword;
570 SettingPresentationModel::SetSecurityWarningsEnabled(bool securityWarnings)
572 __securityWarnings = securityWarnings;
573 SetValue((int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS, Boolean::ToString(securityWarnings));
574 if (__securityWarnings == true)
576 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
580 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
585 SettingPresentationModel::IsSecurityWarningsEnabled(void)
587 return __securityWarnings;
591 SettingPresentationModel::SetSearchEngine(const String& searchEngine)
593 __searchEngine = searchEngine;
594 SetValue((int) REGISTRY_SETTING_SEARCH_ENGINE, searchEngine);
598 SettingPresentationModel::GetSearchEngine(void)
600 return __searchEngine;
604 SettingPresentationModel::SetCaseSensitiveEnabled(bool caseSensitive)
606 __caseSensitive = caseSensitive;
607 SetValue((int) REGISTRY_SETTING_CASE_SENSITIVE, Boolean::ToString(caseSensitive));
611 SettingPresentationModel::IsCaseSensitiveEnabled(void)
613 return __caseSensitive;
617 SettingPresentationModel::SetRunReaderEnabled(bool runReader)
619 __runReader = runReader;
620 SetValue((int) REGISTRY_SETTING_RUN_READER, Boolean::ToString(runReader));
624 SettingPresentationModel::IsRunReaderEnabled(void)
630 SettingPresentationModel::SetReaderFontSize(int fontSize)
632 __fontSize = fontSize;
633 SetValue((int) REGISTRY_SETTING_READER_FONT_SIZE, Integer::ToString(__fontSize));
637 SettingPresentationModel::GetReaderFontSize(void)
643 SettingPresentationModel::GetSearchUrl(const String& searchText)
645 String searchStr = L"";
646 if (GetSearchEngine().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_YAHOO")) == 0)
648 searchStr.Append(L"http://search.yahoo.com/search?p=");
649 searchStr.Append(searchText);
651 else if (GetSearchEngine().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_NAVER")) == 0)
653 searchStr.Append(L"http://search.naver.com/search.naver?query=");
654 searchStr.Append(searchText);
656 else if (GetSearchEngine().CompareTo(CommonUtil::GetString(L"IDS_COM_BODY_GOOGLE")) == 0)
658 searchStr.Append(L"http://www.google.com/search?q=");
659 searchStr.Append(searchText);
664 Tizen::Web::Controls::WebSetting&
665 SettingPresentationModel::GetWebSettings(void)
671 SettingPresentationModel::SetPrivateOn(bool isPrivateOn)
673 __isPrivateOn = isPrivateOn;
678 SettingPresentationModel::GetPrivateOn(void)
680 return __isPrivateOn;