Tizen 2.1 base
[apps/osp/Internet.git] / src / IntSettingForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://floralicense.org/license/
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 //!Internet SettingForm class
18 /*@file:        IntSettingForm.cpp
19  *@brief:       The SettingForm
20  */
21
22 #include <FApp.h>
23 #include <FGraphics.h>
24 #include <FUi.h>
25
26 #include "IntCommonLib.h"
27 #include "IntConfirmationPopup.h"
28 #include "IntDefaultCustomItem.h"
29 #include "IntDropDownCustomItem.h"
30 #include "IntHistoryPresentationModel.h"
31 #include "IntMultipleWindowPresentationModel.h"
32 #include "IntNotificationPanel.h"
33 #include "IntRadioCustomItem.h"
34 #include "IntSceneRegister.h"
35 #include "IntSettingForm.h"
36 #include "IntSettingPresentationModel.h"
37 #include "IntSettingToggleCustomItem.h"
38
39
40 using namespace Tizen::App;
41 using namespace Tizen::Base;
42 using namespace Tizen::Base::Collection;
43 using namespace Tizen::Graphics;
44 using namespace Tizen::Ui;
45 using namespace Tizen::Ui::Controls;
46 using namespace Tizen::Ui::Scenes;
47
48 //static const int IDA_CONFIRMATION_NO = 1000;
49 //static const int IDA_CONFIRMATION_YES = 1001;
50
51 static const wchar_t* IDB_EDIT_BACKGROUND = L"EditBackground.png";
52
53 SettingForm::SettingForm(void)
54 : __fontValue(0),__pResetPopup(null),__pWindowInfo(null) , __pConfirmationPopup(null)
55 {
56         __currentURL = L"";
57         __pList = null;
58         InitializeSettingValues();
59 }
60
61 SettingForm::~SettingForm(void)
62 {
63         if (pGroupItemCount)
64         {
65                 delete[] pGroupItemCount;
66                 pGroupItemCount = null;
67         }
68 }
69
70 void
71 SettingForm::InitializeSettingValues(void)
72 {
73         AppLog("SettingForm::InitializeSettingValues homepage %ls",SettingPresentationModel::GetInstance()->GetHomepage().GetPointer());
74         groupCount = 5;
75         pGroupItemCount = new(std::nothrow) int[5];
76         pGroupItemCount[0] = 5;  //Homepage
77         pGroupItemCount[1] = 6;  //Page content settings
78         pGroupItemCount[2] = 5;  //Private and Security
79         pGroupItemCount[3] = 4;  //Search
80         pGroupItemCount[4] = 1;  //Website settings and Reset
81
82         for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; iter++)
83         {
84                 settingInfo[iter].isSelected = false;
85         }
86
87         AppLogDebug("image display %d", (int) SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled());
88         settingInfo[SETTING_HOMEPAGE_TITLE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_HOMEPAGE");
89         settingInfo[SETTING_HOMEPAGE_TITLE].subText = SettingPresentationModel::GetInstance()->GetHomepage();
90         settingInfo[SETTING_HOMEPAGE_TITLE].itemType = ITEM_TYPE_DROPDOWN;
91
92         settingInfo[SETTING_CURRENT_PAGE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_CURRENT_PAGE");
93         settingInfo[SETTING_CURRENT_PAGE].subText = L"";
94         settingInfo[SETTING_CURRENT_PAGE].itemType = ITEM_TYPE_RADIO;
95
96         settingInfo[SETTING_BLANK_PAGE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_BLANK_PAGE");
97         settingInfo[SETTING_BLANK_PAGE].subText = L"";
98         settingInfo[SETTING_BLANK_PAGE].itemType = ITEM_TYPE_RADIO;
99         if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_BLANK_PAGE")) == 0)
100         {
101                 settingInfo[SETTING_BLANK_PAGE].isSelected = true;
102         }
103
104         settingInfo[SETTING_MOST_VISITED_SITE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_MOST_VISITED_SITES");
105         settingInfo[SETTING_MOST_VISITED_SITE].subText = L"";
106         settingInfo[SETTING_MOST_VISITED_SITE].itemType = ITEM_TYPE_RADIO;
107         if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
108         {
109                 settingInfo[SETTING_MOST_VISITED_SITE].isSelected = true;
110         }
111         WindowInfo* pWindowInfo = null;
112         String curUrl = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
113         AppLog("SettingForm::OnSceneActivatedN check1");
114
115         settingInfo[SETTING_FAVORITE_URL].titleText = L"http://www.tizen.org";
116         if (SettingPresentationModel::GetInstance()->GetFavoriteUrl().CompareTo(L"") == 0)
117         {
118                 SettingPresentationModel::GetInstance()->SetFavoriteValue(L"http://www.tizen.org");
119         }
120         settingInfo[SETTING_FAVORITE_URL].subText = L"";
121         settingInfo[SETTING_FAVORITE_URL].itemType = ITEM_TYPE_RADIO;
122
123         if (SettingPresentationModel::GetInstance()->GetHomepage().CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE")) == 0)
124         {
125                 settingInfo[SETTING_FAVORITE_URL].isSelected = true;
126         }
127
128         settingInfo[SETTING_DEFAULT_VIEW_TITLE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_DEFAULT_VIEW");
129         settingInfo[SETTING_DEFAULT_VIEW_TITLE].subText = SettingPresentationModel::GetInstance()->GetDefaultView();
130         settingInfo[SETTING_DEFAULT_VIEW_TITLE].itemType = ITEM_TYPE_DROPDOWN;
131
132         settingInfo[SETTING_FIT_TO_WIDTH].titleText = CommonUtil::GetString(L"IDS_BR_BODY_FIT_TO_WIDTH");
133         settingInfo[SETTING_FIT_TO_WIDTH].subText = L"";
134         settingInfo[SETTING_FIT_TO_WIDTH].itemType = ITEM_TYPE_RADIO;
135         settingInfo[SETTING_FIT_TO_WIDTH].isSelected = !(String::Compare(settingInfo[SETTING_FIT_TO_WIDTH].titleText, settingInfo[SETTING_DEFAULT_VIEW_TITLE].subText));
136
137         settingInfo[SETTING_READABLE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_READABLE");
138         settingInfo[SETTING_READABLE].subText = L"";
139         settingInfo[SETTING_READABLE].itemType = ITEM_TYPE_RADIO;
140         settingInfo[SETTING_READABLE].isSelected = !(String::Compare(settingInfo[SETTING_READABLE].titleText, settingInfo[SETTING_DEFAULT_VIEW_TITLE].subText));
141
142         settingInfo[SETTING_RUN_JAVASCRIPT].titleText = CommonUtil::GetString(L"IDS_BR_BODY_RUN_JAVASCRIPT");
143         settingInfo[SETTING_RUN_JAVASCRIPT].subText = L"";
144         settingInfo[SETTING_RUN_JAVASCRIPT].itemType = ITEM_TYPE_TOGGLE;
145         settingInfo[SETTING_RUN_JAVASCRIPT].isSelected = SettingPresentationModel::GetInstance()->IsRunJavascriptEnabled();
146
147         settingInfo[SETTING_DISPLAY_IMAGES].titleText = CommonUtil::GetString(L"IDS_BR_BODY_DISPLAY_IMAGES");
148         settingInfo[SETTING_DISPLAY_IMAGES].subText = L"";
149         settingInfo[SETTING_DISPLAY_IMAGES].itemType = ITEM_TYPE_TOGGLE;
150         settingInfo[SETTING_DISPLAY_IMAGES].isSelected = SettingPresentationModel::GetInstance()->IsDisplayImagesEnabled();
151
152         settingInfo[SETTING_BLOCK_POPUP].titleText = CommonUtil::GetString(L"IDS_BR_BODY_BLOCK_POP_UPS_ABB");
153         settingInfo[SETTING_BLOCK_POPUP].subText = L"";
154         settingInfo[SETTING_BLOCK_POPUP].itemType = ITEM_TYPE_TOGGLE;
155         settingInfo[SETTING_BLOCK_POPUP].isSelected = !SettingPresentationModel::GetInstance()->IsBlockPopUp();
156
157         settingInfo[SETTING_CLEAR_CACHE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_CLEAR_CACHE");
158         settingInfo[SETTING_CLEAR_CACHE].subText = L"";
159         settingInfo[SETTING_CLEAR_CACHE].itemType = ITEM_TYPE_NORMAL;
160
161         settingInfo[SETTING_CLEAR_HISTORY].titleText = CommonUtil::GetString(L"IDS_BR_BODY_CLEAR_HISTORY");
162         settingInfo[SETTING_CLEAR_HISTORY].subText = L"";
163         settingInfo[SETTING_CLEAR_HISTORY].itemType = ITEM_TYPE_NORMAL;
164
165         settingInfo[SETTING_SHOW_SECURITY_WARNINGS].titleText = CommonUtil::GetString(L"IDS_BR_BODY_SHOW_SECURITY_WARNINGS");
166         settingInfo[SETTING_SHOW_SECURITY_WARNINGS].subText = L"";
167         settingInfo[SETTING_SHOW_SECURITY_WARNINGS].itemType = ITEM_TYPE_TOGGLE;
168         settingInfo[SETTING_SHOW_SECURITY_WARNINGS].isSelected = SettingPresentationModel::GetInstance()->IsSecurityWarningsEnabled();
169
170         settingInfo[SETTING_ACCEPT_COOKIES].titleText = CommonUtil::GetString(L"IDS_BR_BODY_ACCEPT_COOKIES");
171         settingInfo[SETTING_ACCEPT_COOKIES].subText = L"";
172         settingInfo[SETTING_ACCEPT_COOKIES].itemType = ITEM_TYPE_TOGGLE;
173         settingInfo[SETTING_ACCEPT_COOKIES].isSelected = SettingPresentationModel::GetInstance()->IsCookiesEnabled();
174
175         settingInfo[SETTING_CLEAR_COOKIE_DATA].titleText = CommonUtil::GetString(L"IDS_BR_BODY_CLEAR_ALL_COOKIE_DATA");
176         settingInfo[SETTING_CLEAR_COOKIE_DATA].subText = CommonUtil::GetString(L"IDS_BR_HEADER_COOKIES");
177         settingInfo[SETTING_CLEAR_COOKIE_DATA].itemType = ITEM_TYPE_NORMAL;
178
179         settingInfo[SETTING_SEARCH_ENGINE_TITLE].titleText = CommonUtil::GetString(L"IDS_BR_BODY_SEARCH_ENGINE");
180         settingInfo[SETTING_SEARCH_ENGINE_TITLE].subText = SettingPresentationModel::GetInstance()->GetSearchEngine();
181         settingInfo[SETTING_SEARCH_ENGINE_TITLE].itemType = ITEM_TYPE_DROPDOWN;
182
183         settingInfo[SETTING_SEARCH_ENGINE_YAHOO].titleText = CommonUtil::GetString(L"IDS_BR_BODY_YAHOO");
184         settingInfo[SETTING_SEARCH_ENGINE_YAHOO].subText = L"";
185         settingInfo[SETTING_SEARCH_ENGINE_YAHOO].itemType = ITEM_TYPE_RADIO;
186         settingInfo[SETTING_SEARCH_ENGINE_YAHOO].isSelected = !(String::Compare(settingInfo[SETTING_SEARCH_ENGINE_YAHOO].titleText, settingInfo[SETTING_SEARCH_ENGINE_TITLE].subText));
187
188         settingInfo[SETTING_SEARCH_ENGINE_NAVER].titleText = CommonUtil::GetString(L"IDS_BR_BODY_NAVER");
189         settingInfo[SETTING_SEARCH_ENGINE_NAVER].subText = L"";
190         settingInfo[SETTING_SEARCH_ENGINE_NAVER].itemType = ITEM_TYPE_RADIO;
191         settingInfo[SETTING_SEARCH_ENGINE_NAVER].isSelected = !(String::Compare(settingInfo[SETTING_SEARCH_ENGINE_NAVER].titleText, settingInfo[SETTING_SEARCH_ENGINE_TITLE].subText));
192
193         settingInfo[SETTING_SEARCH_ENGINE_GOOGLE].titleText = CommonUtil::GetString(L"IDS_COM_BODY_GOOGLE");
194         settingInfo[SETTING_SEARCH_ENGINE_GOOGLE].subText = L"";
195         settingInfo[SETTING_SEARCH_ENGINE_GOOGLE].itemType = ITEM_TYPE_RADIO;
196         settingInfo[SETTING_SEARCH_ENGINE_GOOGLE].isSelected = !(String::Compare(settingInfo[SETTING_SEARCH_ENGINE_GOOGLE].titleText, settingInfo[SETTING_SEARCH_ENGINE_TITLE].subText));
197
198         settingInfo[SETTING_RESET_TO_DEFAULT].titleText = CommonUtil::GetString(L"IDS_BR_BODY_RESET_TO_DEFAULT");
199         settingInfo[SETTING_RESET_TO_DEFAULT].subText = L"";
200         settingInfo[SETTING_RESET_TO_DEFAULT].itemType = ITEM_TYPE_NORMAL;
201 }
202
203 bool
204 SettingForm::Initialize(void)
205 {
206         result r = E_FAILURE;
207
208         r = Construct(L"IDL_SETTING_FORM");
209         if (IsFailed(r))
210         {
211                 return false;
212         }
213         return true;
214 }
215
216 result
217 SettingForm::OnInitializing(void)
218 {
219         result r = E_FAILURE;
220         Footer* pFooter = NULL;
221         SceneManager* pSceneManager = NULL;
222
223         __pList = static_cast< GroupedListView* >(GetControl(L"IDC_SETTING_LIST"));
224         if ( __pList != NULL )
225         {
226
227                 r = __pList->SetItemProvider(*this);
228                 TryCatch(!IsFailed(r),,"setItemProvider failed with error %s",GetErrorMessage(r));
229                 __pList->AddGroupedListViewItemEventListener(*this);
230         }
231
232         pFooter = GetFooter();
233         if (pFooter)
234         {
235                 AppLogDebug("setting back button");
236                 pFooter->SetBackButtonEnabled(true);
237                 SetFormBackEventListener(this);
238         }
239         pSceneManager = SceneManager::GetInstance();
240         if (pSceneManager != null)
241         {
242                 r = pSceneManager->AddSceneEventListener(IDSCN_SETTINGS, *this);
243                 TryCatch(!IsFailed(r),,"AddSceneEventListener failed with error %s",GetErrorMessage(r));
244         }
245         AddOrientationEventListener(*this);
246
247         CATCH:
248         return r;
249 }
250
251 void
252 SettingForm::OnGroupedListViewContextItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListContextItemStatus status)
253 {
254
255 }
256
257 void
258 SettingForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
259 {
260         int effectiveIndex = 0;
261         SettingPresentationModel* pSettingMgr = SettingPresentationModel::GetInstance();
262
263         if (pSettingMgr == null)
264                 return;
265
266         for (int i = 0; i < groupIndex; i++)
267                 effectiveIndex = effectiveIndex + pGroupItemCount[i];
268         effectiveIndex = effectiveIndex + itemIndex;
269
270         if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
271         {
272                 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
273                 if (settingInfo[effectiveIndex].isOpen == false)
274                 {
275                         settingInfo[effectiveIndex].isOpen = true;
276                         settingInfo[effectiveIndex].childCount = 0;
277                         for (int iter = effectiveIndex + 1; iter < SETTING_MAX; iter++)
278                         {
279                                 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
280                                         settingInfo[effectiveIndex].childCount++;
281                                 else
282                                         break;
283                         }
284                         listView.UpdateList();
285                 }
286                 else
287                 {
288                         settingInfo[effectiveIndex].isOpen = false;
289                         listView.UpdateList();
290                 }
291         }
292         else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
293         {
294                 int parentIndex = 0;
295                 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
296                 {
297                         if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
298                                 break;
299                 }
300                 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
301
302                 for (int iter = 0; iter < settingInfo[parentIndex].childCount; iter++)
303                 {
304                         if (parentIndex + iter + 1 != effectiveIndex)
305                         {
306                                 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
307                                 settingInfo[parentIndex + iter + 1].isSelected = false;
308                         }
309                         else
310                         {
311                                 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
312                                 settingInfo[effectiveIndex].isSelected = true;
313                         }
314                         if (effectiveIndex == SETTING_CURRENT_PAGE)
315                         {
316                                 settingInfo[SETTING_CURRENT_PAGE].isSelected = false;
317                                 settingInfo[SETTING_FAVORITE_URL].isSelected = true;
318                         }
319                         //listView.RefreshList(groupIndex, itemIndex - (effectiveIndex - parentIndex) + iter + 1, LIST_REFRESH_TYPE_ITEM_MODIFY);
320                 }
321 //              listView.UpdateList();
322                 //listView.ScrollToItem(groupIndex, itemIndex, LIST_SCROLL_ITEM_ALIGNMENT_TOP);
323                 Invalidate(true);
324         }
325         else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
326         {
327                 if (settingInfo[effectiveIndex].isSelected == true)
328                 {
329                         settingInfo[effectiveIndex].isSelected = false;
330                 }
331                 else
332                 {
333                         settingInfo[effectiveIndex].isSelected = true;
334                 }
335 //              listView.RefreshList(groupIndex, itemIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
336                 if(__pList != null)
337                 {
338                         __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
339                 }
340         }
341
342         switch (effectiveIndex)
343         {
344         case SETTING_CURRENT_PAGE:
345                 //SettingPresentationModel::GetInstance()->SetHomepage(settingInfo[SETTING_FAVORITE_URL].titleText);
346                 AppLog("setting current page currentURL is =%ls",__currentURL.GetPointer());
347                 if (__currentURL.CompareTo(L"") != 0)
348                 {
349                         AppLog("setting current page currentURL is =%ls",__currentURL.GetPointer());
350                         SettingPresentationModel::GetInstance()->SetHomepage(CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"));
351                         SettingPresentationModel::GetInstance()->SetFavoriteValue(__currentURL);
352                         settingInfo[SETTING_FAVORITE_URL].titleText = __currentURL;
353 //                      listView.RefreshList(groupIndex, effectiveIndex, LIST_REFRESH_TYPE_ITEM_MODIFY);
354                         listView.UpdateList();
355                 }
356                 break;
357         case SETTING_BLANK_PAGE:
358                 //SettingPresentationModel::GetInstance()->SetHomepage(settingInfo[SETTING_BLANK_PAGE].titleText);
359                 SettingPresentationModel::GetInstance()->SetHomepage(CommonUtil::GetString(L"IDS_BR_BODY_BLANK_PAGE"));
360                 AppLog("GetHomepage() %ls",SettingPresentationModel::GetInstance()->GetHomepage().GetPointer());
361                 listView.UpdateList();
362
363                 break;
364         case SETTING_MOST_VISITED_SITE:
365                 SettingPresentationModel::GetInstance()->SetHomepage(settingInfo[SETTING_MOST_VISITED_SITE].titleText);
366                 listView.UpdateList();
367                 break;
368
369         case SETTING_FAVORITE_URL:
370                 //SettingPresentationModel::GetInstance()->SetHomepage(settingInfo[SETTING_FAVORITE_URL].titleText);
371                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EDIT_HOMEPAGE_VIEW, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
372                 break;
373
374         case SETTING_FIT_TO_WIDTH:
375                 SettingPresentationModel::GetInstance()->SetDefaultView(settingInfo[SETTING_FIT_TO_WIDTH].titleText);
376                 listView.UpdateList();
377                 break;
378
379         case SETTING_READABLE:
380                 SettingPresentationModel::GetInstance()->SetDefaultView(settingInfo[SETTING_READABLE].titleText);
381                 listView.UpdateList();
382                 break;
383
384         case SETTING_RUN_JAVASCRIPT:
385                 SettingPresentationModel::GetInstance()->SetRunJavascriptEnabled(settingInfo[SETTING_RUN_JAVASCRIPT].isSelected);
386                 break;
387
388         case SETTING_DISPLAY_IMAGES:
389                 SettingPresentationModel::GetInstance()->SetDisplayImagesEnabled(settingInfo[SETTING_DISPLAY_IMAGES].isSelected);
390                 break;
391
392         case SETTING_BLOCK_POPUP:
393                 SettingPresentationModel::GetInstance()->SetBlockPopUp(!settingInfo[SETTING_BLOCK_POPUP].isSelected);
394                 break;
395
396         case SETTING_CLEAR_CACHE:
397                 ClearCache();
398                 break;
399
400         case SETTING_CLEAR_HISTORY:
401                 ClearHistory();
402                 break;
403
404         case SETTING_SHOW_SECURITY_WARNINGS:
405                 SettingPresentationModel::GetInstance()->SetSecurityWarningsEnabled(settingInfo[SETTING_SHOW_SECURITY_WARNINGS].isSelected);
406                 break;
407
408         case SETTING_ACCEPT_COOKIES:
409                 SettingPresentationModel::GetInstance()->SetCookiesEnabled(settingInfo[SETTING_ACCEPT_COOKIES].isSelected);
410                 break;
411
412         case SETTING_CLEAR_COOKIE_DATA:
413                 ClearCookie();
414                 break;
415
416         case SETTING_SEARCH_ENGINE_YAHOO:
417                 SettingPresentationModel::GetInstance()->SetSearchEngine(settingInfo[SETTING_SEARCH_ENGINE_YAHOO].titleText);
418                 listView.UpdateList();
419                 break;
420
421         case SETTING_SEARCH_ENGINE_NAVER:
422                 SettingPresentationModel::GetInstance()->SetSearchEngine(settingInfo[SETTING_SEARCH_ENGINE_NAVER].titleText);
423                 listView.UpdateList();
424                 break;
425
426         case SETTING_SEARCH_ENGINE_GOOGLE:
427                 SettingPresentationModel::GetInstance()->SetSearchEngine(settingInfo[SETTING_SEARCH_ENGINE_GOOGLE].titleText);
428                 listView.UpdateList();
429                 break;
430
431         case SETTING_RESET_TO_DEFAULT:
432                 //OpenResetPopup();
433                 ResetToDefault();
434                 break;
435
436         default:
437                 break;
438         }
439 }
440
441 void
442 SettingForm::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex, SweepDirection direction)
443 {
444
445 }
446
447 GroupItem*
448 SettingForm::CreateGroupItem(int groupIndex, int itemWidth)
449 {
450         result r = E_FAILURE;
451         String text(L"");
452         GroupItem* pItem = null;
453         const Color ITEM_TEXT_COLOR = CUSTOM_COLOR_SETTINGS_GROUPTITLE;
454
455         pItem = new(std::nothrow) GroupItem();
456         if (pItem == null)
457         {
458                 return null;
459         }
460         r = pItem->Construct(Dimension(itemWidth, 46));
461         if (IsFailed(r))
462         {
463                 delete pItem;
464                 return null;
465         }
466
467         switch (groupIndex)
468         {
469         case 0:
470                 text = CommonUtil::GetString(L"IDS_BR_BODY_HOMEPAGE"); // IDS_HOMEPAGE
471                 settingInfo[SETTING_HOMEPAGE_TITLE].subText = SettingPresentationModel::GetInstance()->GetHomepage();
472                 break;
473
474         case 1:
475                 text = CommonUtil::GetString(L"IDS_BR_MBODY_PAGE_CONTENT_SETTINGS"); // IDS_BR_MBODY_PAGE_CONTENT_SETTINGS
476                 break;
477
478         case 2:
479                 text = CommonUtil::GetString(L"IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB");  // IDS_BR_BODY_PRIVACY_AND_SECURITY_ABB
480                 break;
481
482         case 3:
483                 text = CommonUtil::GetString(L"IDS_BR_BODY_SEARCH");    // IDS_BR_BODY_SEARCH
484                 break;
485
486         case 4:
487                 text = L"";
488                 break;
489
490         default:
491                 break;
492         }
493
494         pItem->SetElement(text, null);
495
496         AppLogDebug("background color set result %s", GetErrorMessage(r));
497
498         pItem->SetTextColor(ITEM_TEXT_COLOR);
499         return pItem;
500 }
501
502 ListItemBase*
503 SettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
504 {
505         AppLog("SettingForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex, itemWidth);
506
507         result r = E_SUCCESS;
508         int effectiveIndex = 0;
509         const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
510         const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
511
512         for (int i = 0; i < groupIndex; i++)
513                 effectiveIndex = effectiveIndex + pGroupItemCount[i];
514         effectiveIndex = effectiveIndex + itemIndex;
515         AppLogDebug("SettingForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
516
517         if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
518         {
519                 SettingToggleCustomItem* pItem = new(std::nothrow) SettingToggleCustomItem();
520                 r = pItem->Construct(itemWidth, 112);
521                 if (IsFailed(r))
522                 {
523                         delete pItem;
524                         return null;
525                 }
526 /*
527                 Bitmap* pNormalBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG9,itemWidth,112);
528                 Bitmap* pPressedBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG_PRESS9,itemWidth,112);
529
530                 if (pNormalBackgroundBitmap != NULL)
531                 {
532                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL,pNormalBackgroundBitmap);
533                         delete pNormalBackgroundBitmap;
534                 }
535
536                 if (pPressedBackgroundBitmap != NULL)
537                 {
538                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_PRESSED,pPressedBackgroundBitmap);
539                         delete pPressedBackgroundBitmap;
540                 }*/
541
542                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL,ITEM_BACKGROUND_COLOR);
543                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED,ITEM_BACKGROUND_COLOR);
544                 if(__pList != null)
545                 {
546                         __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
547                 }
548
549                 pItem->SetText(settingInfo[effectiveIndex].titleText);
550
551                 //if (pBitmap != null)
552                 //      pItem->AddElement(Rectangle(0, 0, 10, 112), IDA_LIST_LEFT_SIDE_MARGIN, *pBitmap, null);
553
554                 pItem->Make();
555 //              if (__pList)
556 //              {
557 //                      __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
558 //                      AppLog("asdasda %s %d,%d-> %d",GetErrorMessage(r),groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
559 //              }
560                 return pItem;
561
562         }
563         else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
564         {
565                 DropDownCustomItem* pItem = new(std::nothrow) DropDownCustomItem();
566                 r = pItem->Construct(itemWidth);
567                 if (IsFailed(r))
568                 {
569                         delete pItem;
570                         return null;
571                 }
572
573 /*              Bitmap* pNormalBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG9,itemWidth,128);
574                 Bitmap* pPressedBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG_PRESS9,itemWidth,112);
575
576                 if (pNormalBackgroundBitmap != NULL)
577                 {
578                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL,pNormalBackgroundBitmap);
579                         delete pNormalBackgroundBitmap;
580                 }
581
582                 if (pPressedBackgroundBitmap != NULL)
583                 {
584                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_PRESSED,pPressedBackgroundBitmap);
585                         delete pPressedBackgroundBitmap;
586                 }*/
587
588                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL,ITEM_BACKGROUND_COLOR);
589                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED,ITEM_BACKGROUND_COLOR);
590
591                 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
592                 pItem->SetSubText(settingInfo[effectiveIndex].subText);
593                 if (settingInfo[effectiveIndex].isOpen)
594                 {
595                         pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
596                 }
597                 else
598                 {
599                         pItem->SetCurState(DROP_DOWN__ITEM_STATE_CLOSED);
600                 }
601                 r = pItem->Make();
602                 //      if (pBitmap != null)
603                 //              pItem->AddElement(Rectangle(0, 0, 10, 128), IDA_LIST_LEFT_SIDE_MARGIN_DROPDOWN, *pBitmap, null);
604
605                 if (IsFailed(r))
606                 {
607                         delete pItem;
608                         return null;
609                 }
610
611                 return pItem;
612         }
613         else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
614         {
615
616
617                 RadioCustomItem* pItem = new(std::nothrow) RadioCustomItem();
618                 int parentIndex = 0;
619                 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
620                 {
621                         if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
622                                 break;
623                 }
624                 if (settingInfo[parentIndex].isOpen == false || (__isCurrentPageDisable == true && groupIndex == 0 && itemIndex == 1))
625                 {
626                         r = pItem->Construct(itemWidth, 0);
627                         AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
628                         return pItem;
629                 }
630                 else
631                 {
632                         pItem->Construct(itemWidth, 112);
633                 }
634 /*
635                 Bitmap* pNormalBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG9,itemWidth,112);
636                 Bitmap* pPressedBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG_PRESS9,itemWidth,112);
637
638                 if (pNormalBackgroundBitmap != NULL)
639                 {
640                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL,pNormalBackgroundBitmap);
641                         delete pNormalBackgroundBitmap;
642                 }
643
644                 if (pPressedBackgroundBitmap != NULL)
645                 {
646                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_PRESSED,pPressedBackgroundBitmap);
647                         delete pPressedBackgroundBitmap;
648                 }*/
649
650                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL,ITEM_RADIO_ITEM_BACKGROUND_COLOR);
651                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED,ITEM_RADIO_ITEM_BACKGROUND_COLOR);
652
653
654                 pItem->SetText(settingInfo[effectiveIndex].titleText);
655                 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
656
657                 //if (pBitmap != null)
658                 //      pItem->AddElement(Rectangle(0, 0, 10, 112), IDA_LIST_LEFT_SIDE_MARGIN, *pBitmap, null);
659
660                 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
661                 pItem->Make();
662
663                 return pItem;
664         }
665         else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_NORMAL)
666         {
667                 DefaultCustomItem* pItem = new(std::nothrow) DefaultCustomItem();
668
669                 r = pItem->Construct(itemWidth, 112);
670                 if (IsFailed(r))
671                 {
672                         delete pItem;
673                         return null;
674                 }
675
676 /*
677                 Bitmap* pNormalBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG9,itemWidth,112);
678                 Bitmap* pPressedBackgroundBitmap = CommonUtil::GetNinepatchedBitmapN(IDB_LIST_GROUP_BG_PRESS9,itemWidth,112);
679
680                 if (pNormalBackgroundBitmap != NULL)
681                 {
682                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_NORMAL,pNormalBackgroundBitmap);
683                         delete pNormalBackgroundBitmap;
684                 }
685
686                 if (pPressedBackgroundBitmap != NULL)
687                 {
688                         pItem->SetBackgroundBitmap(LIST_ITEM_DRAWING_STATUS_PRESSED,pPressedBackgroundBitmap);
689                         delete pPressedBackgroundBitmap;
690                 }*/
691
692                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL,ITEM_BACKGROUND_COLOR);
693                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED,ITEM_BACKGROUND_COLOR);
694
695                 pItem->SetText(settingInfo[effectiveIndex].titleText);
696
697                 //if (pBitmap != null)
698                 //      pItem->AddElement(Rectangle(0, 0, 10, 112), IDA_LIST_LEFT_SIDE_MARGIN, *pBitmap, null);
699
700                 r = pItem->Make();
701                 if (IsFailed(r))
702                 {
703                         delete pItem;
704                         return null;
705                 }
706                 return pItem;
707         }
708         else
709         {
710                 return null;
711         }
712 }
713
714 bool
715 SettingForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
716 {
717         delete pItem;
718         pItem = null;
719         return true;
720 }
721
722 bool
723 SettingForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
724 {
725         delete pItem;
726         pItem = null;
727         return true;
728 }
729
730 int
731 SettingForm::GetGroupCount(void)
732 {
733         return groupCount;
734 }
735
736 int
737 SettingForm::GetItemCount(int groupIndex)
738 {
739         AppLog(" SettingForm::GetItemCount --> groupIndex : %d,", groupIndex);
740         return pGroupItemCount[groupIndex];
741 }
742
743 void
744 SettingForm::OnFormBackRequested(Form& source)
745 {
746         String* pSelectedScene = NULL;
747         Object* value = NULL;
748         MultipleWindowPresentationModel::GetInstance()->GetValue(SELECTED_SCENE_ID, &value);
749         pSelectedScene = (String*) value;
750         if (pSelectedScene)
751         {
752                 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(*pSelectedScene, SCENE_TRANSITION_ANIMATION_TYPE_NONE));
753 //              delete pSelectedScene;
754 //              pSelectedScene = null;
755         }
756 }
757
758 void
759 SettingForm::OnActionPerformed(const Control& source, int actionId)
760 {
761         switch (actionId)
762         {
763         case IDA_BUTTON_NO:
764                 if(__pConfirmationPopup)
765                 {
766                         __pConfirmationPopup->SetShowState(false);
767                         __pConfirmationPopup->Show();
768                         delete __pConfirmationPopup;
769                         __pConfirmationPopup = null;
770                 }
771                 break;
772
773         case IDA_BUTTON_YES:
774                 if(__pConfirmationPopup)
775                 {
776                         String message = L"";
777                         __pConfirmationPopup->SetShowState(false);
778                         __pConfirmationPopup->Show();
779                         if (__pConfirmationPopup->GetMessage() == CommonUtil::GetString(L"IDS_BR_POP_EMPTY_COOKIE_POPUP_BNO"))
780                         {
781                                 message = CommonUtil::GetString(L"IDS_BR_POP_DELETED");
782                                 SettingPresentationModel::GetInstance()->ClearCookie();
783                         }
784                         else if (__pConfirmationPopup->GetMessage() == CommonUtil::GetString(L"IDS_BR_POP_DELETE_LOCALLY_CACHED_CONTENT_AND_DATABASES_Q"))
785                         {
786                                 message = CommonUtil::GetString(L"IDS_BR_POP_DELETED");
787                                 SettingPresentationModel::GetInstance()->ClearCache();
788                         }
789                         else if (__pConfirmationPopup->GetMessage() == CommonUtil::GetString(L"IDS_BR_BODY_DELETE_BROWSER_HISTORY_Q"))
790                         {
791                                 message = CommonUtil::GetString(L"IDS_BR_POP_DELETED");
792                                 HistoryPresentationModel::GetInstance()->ClearHistory();
793                         }
794                         else if (__pConfirmationPopup->GetMessage() == CommonUtil::GetString(L"IDS_BR_POP_RESET_ALL_SETTINGS_TO_DEFAULT_Q"))
795                         {
796                                 message = CommonUtil::GetString(L"IDS_BR_SK_DONE");
797                                 SettingPresentationModel::GetInstance()->ResetRegistry();
798                                 InitializeSettingValues();
799                                 if(__pList != null)
800                                 {
801                                         __pList->UpdateList();
802                                 }
803                         }
804                         delete __pConfirmationPopup;
805                         __pConfirmationPopup = null;
806
807                         NotificationPanel* pNotification = new (std::nothrow) NotificationPanel(*this);
808                         pNotification->SetText(message);
809                         pNotification->SetPositionDiff(0);
810                         pNotification->ShowNotification();
811                 }
812                 break;
813
814         default:
815                 break;
816         }
817 }
818
819 void
820 SettingForm::OnOrientationChanged(const Control& source, OrientationStatus orientationStatus)
821 {
822         Rectangle rect = GetClientAreaBounds();
823         if(__pList == null)
824         {
825                 return;
826         }
827         __pList->SetBounds(rect);
828         __pList->UpdateList();
829 }
830
831 SettingForm::SettingItemInfo::SettingItemInfo(void)
832 {
833         titleText = L"";
834         subText = L"";
835         childCount = 0;
836         isOpen = false;
837         isSelected = false ;
838 }
839 void
840 SettingForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
841 {
842         WindowInfo* pWindowInfo = null;
843         String curUrl = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
844
845         pWindowInfo = MultipleWindowPresentationModel::GetInstance()->GetActiveWindowInfo();
846
847         if (previousSceneId == IDSCN_EDIT_HOMEPAGE_VIEW)
848         {
849                 if (pArgs != null)
850                 {
851                         String* pValue = NULL;
852                         pValue = dynamic_cast<String*>(pArgs->GetAt(0));
853                         if( pValue != NULL )
854                         {
855                                 if (pValue->CompareTo(L"Done") == 0)
856                                 {
857                                         SettingPresentationModel::GetInstance()->SetHomepage(CommonUtil::GetString(L"IDS_BR_BODY_USER_HOMEPAGE"));
858                                 }
859                                 else if (pValue->CompareTo(L"Cancel") == 0)
860                                 {
861                                         String homePage = SettingPresentationModel::GetInstance()->GetHomepage();
862                                         if (homePage.CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_MOST_VISITED_SITES")) == 0)
863                                         {
864                                                 settingInfo[SETTING_MOST_VISITED_SITE].isSelected = true;
865                                                 settingInfo[SETTING_BLANK_PAGE].isSelected = false;
866                                                 settingInfo[SETTING_CURRENT_PAGE].isSelected = false;
867                                                 settingInfo[SETTING_FAVORITE_URL].isSelected = false;
868
869                                         }
870                                         else if (homePage.CompareTo(CommonUtil::GetString(L"IDS_BR_BODY_BLANK_PAGE")) == 0)
871                                         {
872                                                 settingInfo[SETTING_MOST_VISITED_SITE].isSelected = false;
873                                                 settingInfo[SETTING_BLANK_PAGE].isSelected = true;
874                                                 settingInfo[SETTING_CURRENT_PAGE].isSelected = false;
875                                                 settingInfo[SETTING_FAVORITE_URL].isSelected = false;
876                                         }
877                                 }
878                         }
879                 }
880         }
881
882         if (pWindowInfo != null)
883         {
884                 __currentURL.Clear();
885                 __currentURL.Append(pWindowInfo->pageUrl);
886                 AppLog("current url is %ls",__currentURL.GetPointer());
887
888                 if (SettingPresentationModel::GetInstance()->GetFavoriteUrl().CompareTo(L"") == 0)
889                 {
890                         if (pWindowInfo->pageUrl.CompareTo(L"") == 0)
891                         {
892                                 //settingInfo[SETTING_FAVORITE_URL].titleText = CommonUtil::GetString(L"IDS_SET_HOMEPAGE");
893                                 settingInfo[SETTING_FAVORITE_URL].titleText = L"http://www.tizen.org";
894                         }
895                         else
896                         {
897                                 settingInfo[SETTING_FAVORITE_URL].titleText = pWindowInfo->pageUrl;
898                         }
899                 }
900                 else
901                 {
902                         settingInfo[SETTING_FAVORITE_URL].titleText = SettingPresentationModel::GetInstance()->GetFavoriteUrl();
903                 }
904         }
905
906         if (__pList != null)
907         {
908                 __pList->UpdateList();
909                 if (pWindowInfo && pWindowInfo->pageUrl.CompareTo(L"") == 0)
910                 {
911                         __isCurrentPageDisable = true;
912                         AppLog("set item enabled is false");
913                         __pList->SetItemEnabled(0, 1, false);
914                 }
915                 else
916                 {
917                         __isCurrentPageDisable = false;
918                         AppLog("set item enabled is true");
919                         __pList->SetItemEnabled(0, 1, true);
920                 }
921                 for(int grpindex = 0; grpindex < groupCount; grpindex++)
922                 {
923                         for(int index = 0; index < *(pGroupItemCount+groupCount); index++)
924                         {
925                                 int effectiveIndex = 0;
926                                 for (int i = 0; i < grpindex; i++)
927                                                 effectiveIndex = effectiveIndex + pGroupItemCount[i];
928                                         effectiveIndex = effectiveIndex + index;
929
930                                         if(effectiveIndex >= SETTING_MAX)
931                                         {
932                                                 continue;
933                                         }
934                                 if(settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE || settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO )
935                                 {
936                                         __pList->SetItemChecked(grpindex, index, settingInfo[effectiveIndex].isSelected);
937                                 }
938                         }
939                 }
940         }
941         return;
942 }
943
944 void
945 SettingForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
946 {
947         return;
948 }
949
950 void
951 SettingForm::ClearHistory(void)
952 {
953         String message = CommonUtil::GetString(L"IDS_BR_BODY_DELETE_BROWSER_HISTORY_Q");
954         __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
955         __pConfirmationPopup->Initialize();
956         __pConfirmationPopup->RemoveActionListener(*this);
957         __pConfirmationPopup->AddActionListener(*this);
958         __pConfirmationPopup->setMessage(message);
959         __pConfirmationPopup->Show();
960 }
961
962 void
963 SettingForm::ClearCache(void)
964 {
965         String message = CommonUtil::GetString(L"IDS_BR_POP_DELETE_LOCALLY_CACHED_CONTENT_AND_DATABASES_Q");
966         __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
967         __pConfirmationPopup->Initialize();
968         __pConfirmationPopup->RemoveActionListener(*this);
969         __pConfirmationPopup->AddActionListener(*this);
970         __pConfirmationPopup->setMessage(message);
971         __pConfirmationPopup->Show();
972 }
973
974 void
975 SettingForm::ClearCookie(void)
976 {
977         String message = CommonUtil::GetString(L"IDS_BR_POP_EMPTY_COOKIE_POPUP_BNO");
978         __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
979         __pConfirmationPopup->Initialize();
980         __pConfirmationPopup->RemoveActionListener(*this);
981         __pConfirmationPopup->AddActionListener(*this);
982         __pConfirmationPopup->setMessage(message);
983         __pConfirmationPopup->Show();
984 }
985
986 void
987 SettingForm::ResetToDefault()
988 {
989         String message = CommonUtil::GetString(L"IDS_BR_POP_RESET_ALL_SETTINGS_TO_DEFAULT_Q");
990         __pConfirmationPopup = new(std::nothrow) ConfirmationPopup();
991         __pConfirmationPopup->Initialize();
992         __pConfirmationPopup->RemoveActionListener(*this);
993         __pConfirmationPopup->AddActionListener(*this);
994         __pConfirmationPopup->setMessage(message);
995         __pConfirmationPopup->Show();
996 }