2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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.
18 * @file GlSettingMainForm.cpp
19 * @brief This is the implementation file for SettingMainForm class.
22 #include "GlDropDownCustomItem.h"
23 #include "GlFileListPresentationModel.h"
24 #include "GlGalleryApp.h"
25 #include "GlRadioCustomItem.h"
26 #include "GlResourceManager.h"
27 #include "GlSettingMainForm.h"
28 #include "GlSettingPresentationModel.h"
29 #include "GlSettingToggleCustomItem.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Content;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::System;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
42 SettingMainForm::SettingMainForm(void)
44 , __pPresentationModel(null)
45 , __contentUpdated(false)
48 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
51 SettingMainForm::~SettingMainForm(void)
56 delete[] pGroupItemCount;
58 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
62 SettingMainForm::Initialize(void)
65 result r = Form::Construct(IDL_FORM_SETTING_MAIN);
66 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
72 SettingMainForm::OnInitializing(void)
75 __pPresentationModel = SettingPresentationModel::GetInstance();
76 SettingInfo::AddSettingEventListener(*this);
78 InitializeSettingValues();
80 Header* pHeader = GetHeader();
82 pHeader->SetStyle(HEADER_STYLE_TITLE);
83 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
85 __pList = static_cast<GroupedListView*>(GetControl(L"IDC_SETTING_LIST"));
89 __pList->SetItemProvider(*this);
90 __pList->AddGroupedListViewItemEventListener(*this);
93 SetFormBackEventListener(this);
94 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
100 SettingMainForm::OnTerminating(void)
102 AppLogDebug("ENTER");
103 SettingInfo::RemoveSettingEventListener(*this);
104 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
110 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
112 AppLogDebug("ENTER");
113 SceneManager* pSceneManager = SceneManager::GetInstance();
114 AppAssert(pSceneManager);
123 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
127 SettingMainForm::OnFormBackRequested(Form& source)
129 AppLogDebug("ENTER");
131 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
134 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
136 if (pApp->GetFrameActivated() == true)
138 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
144 SceneManager* pSceneManager = SceneManager::GetInstance();
145 if (__contentUpdated)
147 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
151 pSceneManager->GoBackward(BackwardSceneTransition());
156 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
160 SettingMainForm::OnContentUpdated(void)
162 AppLogDebug("ENTER");
163 __contentUpdated = true;
164 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
168 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
169 const SceneId& currentSceneId, IList* pArgs)
171 AppLogDebug("ENTER");
172 FileListPresentationModel::GetInstance()->AddContentEventListener(this);
173 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
177 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
178 const SceneId& nextSceneId)
180 AppLogDebug("ENTER");
181 FileListPresentationModel::GetInstance()->RemoveContentEventListener(this);
182 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
186 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
188 int effectiveIndex = 0;
191 effectiveIndex = effectiveIndex + itemIndex;
193 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
195 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
196 if (settingInfo[effectiveIndex].isOpen == false)
198 settingInfo[effectiveIndex].isOpen = true;
199 settingInfo[effectiveIndex].childCount = 0;
200 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
202 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
204 ++settingInfo[effectiveIndex].childCount;
211 listView.UpdateList();
215 settingInfo[effectiveIndex].isOpen = false;
216 listView.UpdateList();
219 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
222 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
224 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
229 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
231 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
233 if (parentIndex + iter + 1 != effectiveIndex)
235 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
236 settingInfo[parentIndex + iter + 1].isSelected = false;
240 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
241 settingInfo[effectiveIndex].isSelected = true;
247 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
249 if (settingInfo[effectiveIndex].isSelected == true)
251 settingInfo[effectiveIndex].isSelected = false;
255 settingInfo[effectiveIndex].isSelected = true;
259 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
263 switch (effectiveIndex)
265 case SETTING_INTERVAL_2:
268 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
270 listView.UpdateList();
274 case SETTING_INTERVAL_3:
277 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
278 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
279 listView.UpdateList();
283 case SETTING_INTERVAL_5:
286 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
287 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
288 listView.UpdateList();
292 case SETTING_INTERVAL_10:
295 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
296 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
297 listView.UpdateList();
301 case SETTING_INTERVAL_20:
304 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
305 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
306 listView.UpdateList();
310 case SETTING_TRANSITION_PAGE:
313 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
314 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
315 listView.UpdateList();
319 case SETTING_TRANSITION_DISSOLVE:
322 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
323 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
326 AppLogDebug(" Passed");
329 listView.UpdateList();
333 case SETTING_TRANSITION_ZOOM:
336 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
337 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
338 listView.UpdateList();
346 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
347 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
349 if (repeatValue == 0)
358 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
359 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
363 case SETTING_SHUFFLE:
365 int shuffleValue = 0;
367 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
368 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
370 if (shuffleValue == 0)
379 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
380 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
390 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
392 GroupItem* pItem = new (std::nothrow) GroupItem();
397 result r = pItem->Construct(Dimension(itemWidth, 46));
408 text = ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW");
415 pItem->SetElement(text, null);
417 AppLogDebug("background color set result %s", GetErrorMessage(r));
419 pItem->SetTextColor(CUSTOM_COLOR_SETTINGS_GROUPTITLE);
424 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
426 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
429 result r = E_SUCCESS;
430 int effectiveIndex = 0;
431 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
432 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
433 const Color ITEM_BACKGROUND_COLOR_HIGHLIGHTED = CUSTOM_BACKGROUND_COLOR_LISTVIEW_PRESSED_HIGHLIGHTED;
435 effectiveIndex = effectiveIndex + itemIndex;
436 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
441 int defaultHeight = 112;
442 int defaultFontSize = 44;
444 SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
445 AppLog("the font value is %S",fontSizeStr.GetPointer());
447 if(fontSizeStr == "medium")
450 itemHeight = defaultHeight + (fontSize - defaultFontSize);
452 else if(fontSizeStr == "huge")
455 itemHeight = defaultHeight + (fontSize - defaultFontSize);
457 else if(fontSizeStr == "giant")
460 itemHeight = defaultHeight + (fontSize - defaultFontSize);
462 else if(fontSizeStr == "small")
465 itemHeight = defaultHeight + (fontSize - defaultFontSize);
467 else if(fontSizeStr == "large")
470 itemHeight = defaultHeight + (fontSize - defaultFontSize);
478 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
480 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
481 r = pItem->Construct(itemWidth, itemHeight);
489 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
490 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
494 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
497 pItem->SetText(settingInfo[effectiveIndex].titleText);
498 pItem->Make(fontSize);
502 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
504 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
505 r = pItem->Construct(itemWidth,itemHeight);
512 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
513 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
515 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
516 pItem->SetSubText(settingInfo[effectiveIndex].subText);
517 if (settingInfo[effectiveIndex].isOpen)
519 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
523 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
526 r = pItem->Make(fontSize,itemHeight);
536 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
538 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
541 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
543 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
547 if (settingInfo[parentIndex].isOpen == false)
549 r = pItem->Construct(itemWidth, 0);
550 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
555 pItem->Construct(itemWidth, itemHeight);
558 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
559 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
561 pItem->SetText(settingInfo[effectiveIndex].titleText);
562 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
564 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
565 pItem->Make(fontSize);
576 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
583 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
590 SettingMainForm::GetGroupCount(void)
598 SettingMainForm::GetItemCount(int groupIndex)
600 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
601 return pGroupItemCount[groupIndex];
605 SettingMainForm::InitializeSettingValues(void)
607 pGroupItemCount = new (std::nothrow) int[1];
608 pGroupItemCount[0] = 13;
610 int transitionValue = 0;
612 int shuffletValue = 0;
613 String selectedInterval;
614 String selectedTransition;
616 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
618 settingInfo[iter].isSelected = false;
621 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
630 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
631 settingInfo[SETTING_INTERVAL_2].isSelected = true;
637 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
638 settingInfo[SETTING_INTERVAL_3].isSelected = true;
644 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
645 settingInfo[SETTING_INTERVAL_5].isSelected = true;
651 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
652 settingInfo[SETTING_INTERVAL_10].isSelected = true;
658 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
659 settingInfo[SETTING_INTERVAL_20].isSelected = true;
668 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
669 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
673 switch (transitionValue)
677 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
678 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
684 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
685 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
691 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
692 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
701 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
702 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval;
703 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
705 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
706 settingInfo[SETTING_INTERVAL_2].subText = L"";
707 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
709 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
710 settingInfo[SETTING_INTERVAL_3].subText = L"";
711 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
713 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
714 settingInfo[SETTING_INTERVAL_5].subText = L"";
715 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
717 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
718 settingInfo[SETTING_INTERVAL_10].subText = L"";
719 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
721 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
722 settingInfo[SETTING_INTERVAL_20].subText = L"";
723 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
725 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
727 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
728 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
730 if (repeatValue == 0)
732 settingInfo[SETTING_REPEAT].isSelected = false;
736 settingInfo[SETTING_REPEAT].isSelected = true;
739 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
740 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
742 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
743 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
745 if (shuffletValue == 0)
747 settingInfo[SETTING_SHUFFLE].isSelected = false;
751 settingInfo[SETTING_SHUFFLE].isSelected = true;
754 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
755 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
756 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
758 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
759 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
760 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
762 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
763 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
764 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
766 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
767 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
768 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
771 SettingMainForm::SettingItemInfo::SettingItemInfo(void)
780 SettingMainForm::OnSettingChanged(String& key)
782 AppLogDebug("ENTER");
783 if (key == L"http://tizen.org/setting/font.size")
785 __pList->UpdateList();
787 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));