3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (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 = (L"IDS_BR_BODY_MOST_VISITED_SITES");
63 __defaultViewLevel = L"IDS_BR_BODY_FIT_TO_WIDTH"; // IDS_FIT_TO_WIDTH
64 __runJsEnabled = true;
65 __displayImages = true;
69 __rememberFormData = true;
70 __rememberPassword = true;
72 __savePassword = CommonUtil::GetString(L"IDS_BR_BODY_ALWAYS_ASK"); // IDS_ALWAYS_ASK
73 __securityWarnings = true;
74 __searchEngine = L"Yahoo"; //CommonUtil::GetString(L"IDS_BR_BODY_YAHOO");
75 __caseSensitive = false;
79 __setting.SetInputStyle(INPUT_STYLE_OVERLAY);
80 __setting.SetAutoImageLoadEnabled(__displayImages);
81 __setting.SetJavascriptEnabled(__runJsEnabled);
82 __setting.SetJavaScriptPopupEnabled(__blockPopUp);
83 __setting.SetAutoFormDataShowEnabled(__rememberFormData);
84 __setting.SetAutoLoginFormFillEnabled(__rememberPassword);
86 if (__defaultViewLevel.CompareTo((L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
88 __setting.SetAutoFittingEnabled(true);
90 else if (__defaultViewLevel.CompareTo((L"IDS_BR_BODY_READABLE")) == 0)
92 __setting.SetAutoFittingEnabled(false);
94 if (__securityWarnings == true)
96 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
100 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
105 SettingPresentationModel::CreateInstance(void)
107 if (__pSettingsPresentationModel == null)
108 __pSettingsPresentationModel = new(std::nothrow) SettingPresentationModel();
109 result r = __pSettingsPresentationModel->Construct();
112 delete __pSettingsPresentationModel;
113 __pSettingsPresentationModel = null;
116 std::atexit(DestroyInstance);
119 SettingPresentationModel*
120 SettingPresentationModel::GetInstance(void)
122 if (__pSettingsPresentationModel == null)
126 return __pSettingsPresentationModel;
130 SettingPresentationModel::DestroyInstance(void)
132 if (__pSettingsPresentationModel)
134 delete __pSettingsPresentationModel;
135 __pSettingsPresentationModel = null;
140 SettingPresentationModel::LoadRegistry(void)
142 AppLog("SettingPresentationModel::LoadRegistry entered");
143 result r = E_FAILURE;
146 for (int settingValueName = REGISTRY_SETTING_HOMEPAGE; settingValueName < MAX_REGISTRY_SETTING; settingValueName++)
148 r = AppRegistry::GetInstance()->Get(__entry[settingValueName], __values[settingValueName]);
149 if (r != E_SUCCESS && r != E_KEY_NOT_FOUND)
151 AppLog("Registry Load failed with result %s settingValueName %d", GetErrorMessage(r),settingValueName);
155 if (__values[REGISTRY_SETTING_HOMEPAGE].CompareTo(L"") != 0)
157 __homePage = __values[REGISTRY_SETTING_HOMEPAGE];
158 AppLog("homepage Loading from registry %ls",__homePage.GetPointer());
160 if (__values[REGISTRY_SETTING_DEFAULT_VIEW].CompareTo(L"") != 0)
162 __defaultViewLevel = __values[REGISTRY_SETTING_DEFAULT_VIEW];
164 if (__values[REGISTRY_SETTING_RUN_JAVASCRIPT].CompareTo(L"") != 0)
166 __runJsEnabled = Boolean::Parse(__values[REGISTRY_SETTING_RUN_JAVASCRIPT], false);
167 AppLogDebug("LoadRegistry __runJsEnabled %d",__runJsEnabled);
169 if (__values[REGISTRY_SETTING_DISPLAY_IMAGES].CompareTo(L"") != 0)
171 __displayImages = Boolean::Parse(__values[REGISTRY_SETTING_DISPLAY_IMAGES], false);
172 AppLogDebug("LoadRegistry __displayImages %d",__displayImages);
174 if (__values[REGISTRY_SETTING_HTML5_VIDEOS].CompareTo(L"") != 0)
176 __html5Videos = Boolean::Parse(__values[REGISTRY_SETTING_HTML5_VIDEOS], false);
177 AppLogDebug("LoadRegistry __html5Videos %d",__html5Videos);
179 if (__values[REGISTRY_SETTING_WORD_WRAPPING].CompareTo(L"") != 0)
181 __wordWrap = Boolean::Parse(__values[REGISTRY_SETTING_WORD_WRAPPING], false);
182 AppLogDebug("LoadRegistry __wordWrap %d",__wordWrap);
184 if (__values[REGISTRY_SETTING_BLOCK_POPUP].CompareTo(L"") != 0)
186 __blockPopUp = Boolean::Parse(__values[REGISTRY_SETTING_BLOCK_POPUP], false);
187 AppLogDebug("LoadRegistry __blockPopUp %d",__blockPopUp);
189 if (__values[REGISTRY_SETTING_ACCEPT_COOKIES].CompareTo(L"") != 0)
191 __cookies = Boolean::Parse(__values[REGISTRY_SETTING_ACCEPT_COOKIES], false);
192 AppLogDebug("LoadRegistry __cookies %d",__cookies);
194 if (__values[REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD].CompareTo(L"") != 0)
196 __savePassword = __values[REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD];
198 if (__values[REGISTRY_SETTING_SHOW_SECURITY_WARNINGS].CompareTo(L"") != 0)
200 __securityWarnings = Boolean::Parse(__values[REGISTRY_SETTING_SHOW_SECURITY_WARNINGS], false);
201 AppLogDebug("LoadRegistry __securityWarnings %d",__securityWarnings);
203 if (__values[REGISTRY_SETTING_SEARCH_ENGINE].CompareTo(L"") != 0)
205 __searchEngine = __values[REGISTRY_SETTING_SEARCH_ENGINE];
207 if (__values[REGISTRY_SETTING_CASE_SENSITIVE].CompareTo(L"") != 0)
209 __caseSensitive = Boolean::Parse(__values[REGISTRY_SETTING_CASE_SENSITIVE], false);
210 AppLogDebug("LoadRegistry __caseSensitive %d",__caseSensitive);
212 if (__values[REGISTRY_SETTING_RUN_READER].CompareTo(L"") != 0)
214 __runReader = Boolean::Parse(__values[REGISTRY_SETTING_RUN_READER], false);
215 AppLogDebug("LoadRegistry __runReader %d",__runReader);
217 if (__values[REGISTRY_SETTING_READER_FONT_SIZE].CompareTo(L"") != 0)
219 Integer::Parse(__values[REGISTRY_SETTING_READER_FONT_SIZE], (int&)__fontSize);
221 if (__values[REGISTRY_SETTING_REMEMBER_FORM_DATA].CompareTo(L"") != 0)
223 __rememberFormData = Boolean::Parse(__values[REGISTRY_SETTING_REMEMBER_FORM_DATA], false);
224 AppLogDebug("LoadRegistry form data %d",__rememberFormData);
226 if (__values[REGISTRY_SETTING_REMEMBER_PASSWORD].CompareTo(L"") != 0)
228 __rememberPassword = Boolean::Parse(__values[REGISTRY_SETTING_REMEMBER_PASSWORD], false);
229 AppLogDebug("LoadRegistry form password %d",__rememberPassword);
232 for (int index = REGISTRY_SETTING_HOMEPAGE; index < MAX_REGISTRY_SETTING; index++)
234 AppLogDebug("registry loaded value :%ls at index %d", __values[index].GetPointer(), index);
236 __setting.SetInputStyle(INPUT_STYLE_OVERLAY);
237 __setting.SetAutoImageLoadEnabled(__displayImages);
238 __setting.SetJavascriptEnabled(__runJsEnabled);
239 __setting.SetJavaScriptPopupEnabled(__blockPopUp);
240 __setting.SetAutoFormDataShowEnabled(__rememberFormData);
241 __setting.SetAutoLoginFormFillEnabled(__rememberPassword);
243 if (__securityWarnings == true)
245 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
249 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
251 __favouriteURL.Clear();
252 __favouriteURL = L"";
253 r = AppRegistry::GetInstance()->Get(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], __favouriteURL);
254 AppLog("__favouriteURL taken from registry is %ls",__favouriteURL.GetPointer());
256 if (r != E_SUCCESS && r != E_KEY_NOT_FOUND)
258 AppLogDebug("Registry Load failed with result %s", GetErrorMessage(r));
266 SettingPresentationModel::ResetRegistry(void)
268 result r = E_FAILURE;
270 AppLogDebug("SettingsManager::ResetRegistry");
271 for (int index = REGISTRY_SETTING_INVALID+1; index < MAX_REGISTRY_SETTING; index++)
273 r = AppRegistry::GetInstance()->Remove(__entry[index]);
274 AppLogDebug("Registry Remove result %s",GetErrorMessage(r));
277 AppRegistry::GetInstance()->Save();
279 for (int index = REGISTRY_SETTING_HOMEPAGE; index < MAX_REGISTRY_SETTING; index++)
281 __values[index] = L"";
285 for (int index = 0; index < __listenerList.GetCount(); index++)
287 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
288 if (pSettingsListener)
289 pSettingsListener->OnSettingsReset();
296 SettingPresentationModel::ClearCache(void)
298 for (int index = 0; index < __listenerList.GetCount(); index++)
300 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
301 if (pSettingsListener)
302 pSettingsListener->OnClearCache();
307 SettingPresentationModel::ClearCookie(void)
309 for (int index = 0; index < __listenerList.GetCount(); index++)
311 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
312 if (pSettingsListener)
313 pSettingsListener->OnClearCookie();
318 SettingPresentationModel::ClearFormData(void)
320 for (int index = 0; index < __listenerList.GetCount(); index++)
322 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
323 if (pSettingsListener)
324 pSettingsListener->OnClearFormData();
329 SettingPresentationModel::ClearPasswords(void)
331 for (int index = 0; index < __listenerList.GetCount(); index++)
333 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
334 if (pSettingsListener)
335 pSettingsListener->OnClearPasswords();
340 SettingPresentationModel::Construct(void)
342 result r = E_FAILURE;
344 for (int index = REGISTRY_SETTING_HOMEPAGE; index < MAX_REGISTRY_SETTING; index++)
346 __values[index] = L"";
349 __entry[REGISTRY_SETTING_HOMEPAGE] = L"homePage";
350 __entry[REGISTRY_SETTING_DEFAULT_VIEW] = L"defaultViewLevel";
351 __entry[REGISTRY_SETTING_RUN_JAVASCRIPT] = L"runJs";
352 __entry[REGISTRY_SETTING_DISPLAY_IMAGES] = L"displayImages";
353 __entry[REGISTRY_SETTING_HTML5_VIDEOS] = L"html5Videos";
354 __entry[REGISTRY_SETTING_WORD_WRAPPING] = L"wordWrap";
355 __entry[REGISTRY_SETTING_BLOCK_POPUP] = L"blockPopUp";
356 __entry[REGISTRY_SETTING_ACCEPT_COOKIES] = L"cookies";
357 __entry[REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD] = L"savePassword";
358 __entry[REGISTRY_SETTING_SHOW_SECURITY_WARNINGS] = L"securityWarnings";
359 __entry[REGISTRY_SETTING_SEARCH_ENGINE] = L"searchEngine";
360 __entry[REGISTRY_SETTING_CASE_SENSITIVE] = L"caseSensitive";
361 __entry[REGISTRY_SETTING_RUN_READER] = L"runReader";
362 __entry[REGISTRY_SETTING_READER_FONT_SIZE] = L"fontSize";
363 __entry[REGISTRY_SETTING_FAVORITE_URL_VALUE] = L"Favourite";
364 __entry[REGISTRY_SETTING_REMEMBER_FORM_DATA] = L"formData";
365 __entry[REGISTRY_SETTING_REMEMBER_PASSWORD] = L"rememberPassword";
372 SettingPresentationModel::SetValue(const int settingValueName, const String& val)
374 result r = E_FAILURE;
376 AppLogDebug("SettingsManager::SetValue settingValueName:%d val %ls", settingValueName, val.GetPointer());
377 if (__values[settingValueName] == L"")
379 AppLogDebug("adding the new (std::nothrow) entry into registry");
380 r = AppRegistry::GetInstance()->Add(__entry[settingValueName], val);
384 AppLogDebug("modifying entry into registry");
385 r = AppRegistry::GetInstance()->Set(__entry[settingValueName], val);
387 TryCatch(!IsFailed(r),,"Adding into registry failed %s",GetErrorMessage(r));
389 r = AppRegistry::GetInstance()->Save();
390 TryCatch(!IsFailed(r),,"Save Failed with error %s",GetErrorMessage(r));
392 for (int index = 0; index < __listenerList.GetCount(); index++)
394 ISettingChangeEventListener* pSettingsListener = static_cast< ISettingChangeEventListener* >(__listenerList.GetAt(index));
395 if (pSettingsListener)
396 pSettingsListener->OnSettingsChange(settingValueName);
399 __values[settingValueName] = val;
407 SettingPresentationModel::SetFavoriteValue(const Tizen::Base::String& val)
409 result r = E_FAILURE;
411 if (__favouriteURL == L"")
412 r = AppRegistry::GetInstance()->Add(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], val);
414 r = AppRegistry::GetInstance()->Set(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], val);
415 TryCatch(!IsFailed(r),,"registry set failed with error %s",GetErrorMessage(r));
416 r = AppRegistry::GetInstance()->Save();
417 TryCatch(!IsFailed(r),,"registry set failed with error %s",GetErrorMessage(r));
418 __favouriteURL.Clear();
419 __favouriteURL.Append(val);
426 SettingPresentationModel::GetFavoriteUrl(void)
428 __favouriteURL.Clear();
429 __favouriteURL = L"";
430 AppRegistry::GetInstance()->Get(__entry[REGISTRY_SETTING_FAVORITE_URL_VALUE], __favouriteURL);
432 return __favouriteURL;
436 SettingPresentationModel::AddSettingsEventListener(const ISettingChangeEventListener& listener)
438 __listenerList.Add(listener);
442 SettingPresentationModel::RemoveSettingsEventListener(ISettingChangeEventListener& listener)
444 __listenerList.Remove(listener, false);
448 SettingPresentationModel::SetHomepage(const String& homePage)
451 __homePage.Append(homePage);
452 AppLog("SettingPresentationModel::SetHomepage %ls",__homePage.GetPointer());
453 SetValue((int) REGISTRY_SETTING_HOMEPAGE, __homePage);
457 SettingPresentationModel::GetHomepage(void)
463 SettingPresentationModel::SetDefaultView(const String& viewLevel)
465 __defaultViewLevel = viewLevel;
466 //CommonUtil::GetString(L"IDS_FIT_TO_WIDTH")
467 if (__defaultViewLevel.CompareTo((L"IDS_BR_BODY_FIT_TO_WIDTH")) == 0)
469 __setting.SetAutoFittingEnabled(true);
471 else if (__defaultViewLevel.CompareTo((L"IDS_BR_BODY_READABLE")) == 0)
473 __setting.SetAutoFittingEnabled(false);
476 SetValue((int) REGISTRY_SETTING_DEFAULT_VIEW, viewLevel);
480 SettingPresentationModel::GetDefaultView(void)
482 return __defaultViewLevel;
486 SettingPresentationModel::SetRunJavascriptEnabled(bool runJsEnabled)
488 __runJsEnabled = runJsEnabled;
489 SetValue((int) REGISTRY_SETTING_RUN_JAVASCRIPT, Boolean::ToString(runJsEnabled));
490 __setting.SetJavascriptEnabled(runJsEnabled);
494 SettingPresentationModel::IsRunJavascriptEnabled(void)
496 return __runJsEnabled;
500 SettingPresentationModel::SetDisplayImagesEnabled(bool displayImages)
502 __displayImages = displayImages;
503 SetValue((int) REGISTRY_SETTING_DISPLAY_IMAGES, Boolean::ToString(displayImages));
504 __setting.SetAutoImageLoadEnabled(__displayImages);
508 SettingPresentationModel::IsDisplayImagesEnabled(void)
510 return __displayImages;
514 SettingPresentationModel::SetHtml5VideosEnabled(bool html5Videos)
516 __html5Videos = html5Videos;
517 SetValue((int) REGISTRY_SETTING_HTML5_VIDEOS, Boolean::ToString(html5Videos));
521 SettingPresentationModel::IsHtml5VideosEnabled(void)
523 return __html5Videos;
527 SettingPresentationModel::SetWordWrapEnabled(bool wordWrap)
529 __wordWrap = wordWrap;
530 SetValue((int) REGISTRY_SETTING_WORD_WRAPPING, Boolean::ToString(wordWrap));
534 SettingPresentationModel::IsWordWrapEnabled(void)
540 SettingPresentationModel::SetBlockPopUp(bool blockPopUp)
542 __blockPopUp = blockPopUp;
543 SetValue((int) REGISTRY_SETTING_BLOCK_POPUP, Boolean::ToString(blockPopUp));
544 __setting.SetJavaScriptPopupEnabled(__blockPopUp);
548 SettingPresentationModel::IsBlockPopUp(void)
554 SettingPresentationModel::SetCookiesEnabled(bool cookiesEnabled)
556 __cookies = cookiesEnabled;
557 SetValue((int) REGISTRY_SETTING_ACCEPT_COOKIES, Boolean::ToString(cookiesEnabled));
561 SettingPresentationModel::IsCookiesEnabled(void)
567 SettingPresentationModel::SetRememberFormData(bool formData)
569 __rememberFormData = formData;
570 SetValue((int) REGISTRY_SETTING_REMEMBER_FORM_DATA, Boolean::ToString(__rememberFormData));
571 __setting.SetAutoFormDataShowEnabled(__rememberFormData);
575 SettingPresentationModel::IsRememberFormData(void)
577 return __rememberFormData;
580 void SettingPresentationModel::SetRememberPassword(bool rememberPassword)
582 __rememberPassword = rememberPassword;
583 SetValue((int) REGISTRY_SETTING_REMEMBER_PASSWORD, Boolean::ToString(__rememberPassword));
584 __setting.SetAutoLoginFormFillEnabled(__rememberPassword);
587 bool SettingPresentationModel::IsRememberPassword(void)
589 return __rememberPassword;
593 SettingPresentationModel::SetSavePassword(const String& savePassword)
595 __savePassword = savePassword;
596 SetValue((int) REGISTRY_SETTING_AUTOSAVE_ID_PASSWORD, savePassword);
600 SettingPresentationModel::GetSavePassword(void)
602 return __savePassword;
606 SettingPresentationModel::SetSecurityWarningsEnabled(bool securityWarnings)
608 __securityWarnings = securityWarnings;
609 SetValue((int) REGISTRY_SETTING_SHOW_SECURITY_WARNINGS, Boolean::ToString(securityWarnings));
610 if (__securityWarnings == true)
612 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_USER_CONFIRM);
616 __setting.SetCertificateErrorHandlingMode(WEB_CERTIFICATE_ERROR_HANDLING_MODE_CONTINUE);
621 SettingPresentationModel::IsSecurityWarningsEnabled(void)
623 return __securityWarnings;
627 SettingPresentationModel::SetSearchEngine(const String& searchEngine)
629 __searchEngine = searchEngine;
630 SetValue((int) REGISTRY_SETTING_SEARCH_ENGINE, searchEngine);
634 SettingPresentationModel::GetSearchEngine(void)
636 return __searchEngine;
640 SettingPresentationModel::SetCaseSensitiveEnabled(bool caseSensitive)
642 __caseSensitive = caseSensitive;
643 SetValue((int) REGISTRY_SETTING_CASE_SENSITIVE, Boolean::ToString(caseSensitive));
647 SettingPresentationModel::IsCaseSensitiveEnabled(void)
649 return __caseSensitive;
653 SettingPresentationModel::SetRunReaderEnabled(bool runReader)
655 __runReader = runReader;
656 SetValue((int) REGISTRY_SETTING_RUN_READER, Boolean::ToString(runReader));
660 SettingPresentationModel::IsRunReaderEnabled(void)
666 SettingPresentationModel::SetReaderFontSize(int fontSize)
668 __fontSize = fontSize;
669 SetValue((int) REGISTRY_SETTING_READER_FONT_SIZE, Integer::ToString(__fontSize));
673 SettingPresentationModel::GetReaderFontSize(void)
679 SettingPresentationModel::GetSearchUrl(const String& searchText)
681 String searchStr = L"";
682 if (GetSearchEngine().CompareTo(L"Yahoo") == 0)
684 searchStr.Append(L"http://search.yahoo.com/search?p=");
685 searchStr.Append(searchText);
687 else if (GetSearchEngine().CompareTo(L"Naver") == 0)
689 searchStr.Append(L"http://search.naver.com/search.naver?query=");
690 searchStr.Append(searchText);
692 else if (GetSearchEngine().CompareTo(L"Google") == 0)
694 searchStr.Append(L"http://www.google.com/search?q=");
695 searchStr.Append(searchText);
700 Tizen::Web::Controls::WebSetting&
701 SettingPresentationModel::GetWebSettings(void)
707 SettingPresentationModel::SetPrivateOn(bool isPrivateOn)
709 __isPrivateOn = isPrivateOn;
714 SettingPresentationModel::GetPrivateOn(void)
716 return __isPrivateOn;