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 Footer* pFooter = GetFooter();
96 AppLogDebug("setting back button");
97 pFooter->SetBackButtonEnabled(true);
100 SetFormBackEventListener(this);
101 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
107 SettingMainForm::OnTerminating(void)
109 AppLogDebug("ENTER");
110 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
116 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
118 AppLogDebug("ENTER");
119 SceneManager* pSceneManager = SceneManager::GetInstance();
120 AppAssert(pSceneManager);
129 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
133 SettingMainForm::OnFormBackRequested(Form& source)
135 AppLogDebug("ENTER");
137 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
140 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
142 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
147 SceneManager* pSceneManager = SceneManager::GetInstance();
148 if (__contentUpdated)
150 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
154 pSceneManager->GoBackward(BackwardSceneTransition());
159 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
163 SettingMainForm::OnContentUpdated(void)
165 AppLogDebug("ENTER");
166 __contentUpdated = true;
167 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
171 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
172 const SceneId& currentSceneId, IList* pArgs)
174 AppLogDebug("ENTER");
175 FileListPresentationModel::GetInstance()->AddContentEventListener(this);
176 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
180 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
181 const SceneId& nextSceneId)
183 AppLogDebug("ENTER");
184 FileListPresentationModel::GetInstance()->RemoveContentEventListener(this);
185 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
189 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
191 int effectiveIndex = 0;
194 effectiveIndex = effectiveIndex + itemIndex;
196 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
198 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
199 if (settingInfo[effectiveIndex].isOpen == false)
201 settingInfo[effectiveIndex].isOpen = true;
202 settingInfo[effectiveIndex].childCount = 0;
203 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
205 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
207 settingInfo[effectiveIndex].childCount++;
214 listView.UpdateList();
218 settingInfo[effectiveIndex].isOpen = false;
219 listView.UpdateList();
222 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
225 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
227 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
232 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
234 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
236 if (parentIndex + iter + 1 != effectiveIndex)
238 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
239 settingInfo[parentIndex + iter + 1].isSelected = false;
243 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
244 settingInfo[effectiveIndex].isSelected = true;
250 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
252 if (settingInfo[effectiveIndex].isSelected == true)
254 settingInfo[effectiveIndex].isSelected = false;
258 settingInfo[effectiveIndex].isSelected = true;
262 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
266 switch (effectiveIndex)
268 case SETTING_INTERVAL_2:
271 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
273 listView.UpdateList();
277 case SETTING_INTERVAL_3:
280 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
281 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
282 listView.UpdateList();
286 case SETTING_INTERVAL_5:
289 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
290 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
291 listView.UpdateList();
295 case SETTING_INTERVAL_10:
298 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
299 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
300 listView.UpdateList();
304 case SETTING_INTERVAL_20:
307 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
308 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
309 listView.UpdateList();
313 case SETTING_TRANSITION_PAGE:
316 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
317 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
318 listView.UpdateList();
322 case SETTING_TRANSITION_DISSOLVE:
325 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
326 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
329 AppLogDebug(" Passed") ;
332 listView.UpdateList();
336 case SETTING_TRANSITION_ZOOM:
339 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
340 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
341 listView.UpdateList();
347 int repeatValue = 0 ;
349 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
350 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
352 if (repeatValue == 0)
361 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
362 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
366 case SETTING_SHUFFLE:
368 int shuffleValue = 0;
370 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
371 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
373 if (shuffleValue == 0)
382 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
383 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
393 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
395 GroupItem* pItem = new (std::nothrow) GroupItem();
400 result r = pItem->Construct(Dimension(itemWidth, 46));
411 text = ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW");
418 pItem->SetElement(text, null);
420 AppLogDebug("background color set result %s", GetErrorMessage(r));
422 pItem->SetTextColor(CUSTOM_COLOR_SETTINGS_GROUPTITLE);
427 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
429 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
432 result r = E_SUCCESS;
433 int effectiveIndex = 0;
434 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
435 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
436 const Color ITEM_BACKGROUND_COLOR_HIGHLIGHTED = CUSTOM_BACKGROUND_COLOR_LISTVIEW_PRESSED_HIGHLIGHTED;
438 effectiveIndex = effectiveIndex + itemIndex;
439 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
444 int defaultHeight = 112 ;
445 int defaultFontSize = 44 ;
447 SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
448 AppLog("the font value is %S",fontSizeStr.GetPointer());
450 if(fontSizeStr == "medium")
453 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
455 else if(fontSizeStr == "huge")
458 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
460 else if(fontSizeStr == "giant")
463 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
465 else if(fontSizeStr == "small")
468 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
470 else if(fontSizeStr == "large")
473 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
481 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
483 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
484 r = pItem->Construct(itemWidth, itemHeight);
492 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
493 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
497 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
500 pItem->SetText(settingInfo[effectiveIndex].titleText);
501 pItem->Make(fontSize);
505 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
507 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
508 r = pItem->Construct(itemWidth,itemHeight);
515 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
516 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
518 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
519 pItem->SetSubText(settingInfo[effectiveIndex].subText);
520 if (settingInfo[effectiveIndex].isOpen)
522 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
526 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
529 r = pItem->Make(fontSize,itemHeight);
539 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
541 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
544 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
546 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
550 if (settingInfo[parentIndex].isOpen == false)
552 r = pItem->Construct(itemWidth, 0);
553 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
558 pItem->Construct(itemWidth, itemHeight);
561 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
562 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
564 pItem->SetText(settingInfo[effectiveIndex].titleText);
565 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
567 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
568 pItem->Make(fontSize);
579 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
586 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
593 SettingMainForm::GetGroupCount(void)
601 SettingMainForm::GetItemCount(int groupIndex)
603 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
604 return pGroupItemCount[groupIndex];
608 SettingMainForm::InitializeSettingValues(void)
610 pGroupItemCount = new (std::nothrow) int[1];
611 pGroupItemCount[0] = 13;
613 int transitionValue = 0;
615 int shuffletValue = 0;
616 String selectedInterval;
617 String selectedTransition;
619 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
621 settingInfo[iter].isSelected = false;
624 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
633 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
634 settingInfo[SETTING_INTERVAL_2].isSelected = true;
640 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
641 settingInfo[SETTING_INTERVAL_3].isSelected = true;
647 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
648 settingInfo[SETTING_INTERVAL_5].isSelected = true;
654 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
655 settingInfo[SETTING_INTERVAL_10].isSelected = true;
661 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
662 settingInfo[SETTING_INTERVAL_20].isSelected = true;
671 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
672 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
676 switch (transitionValue)
680 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
681 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
687 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
688 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
694 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
695 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
704 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
705 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval ;
706 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
708 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
709 settingInfo[SETTING_INTERVAL_2].subText = L"";
710 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
712 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
713 settingInfo[SETTING_INTERVAL_3].subText = L"";
714 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
716 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
717 settingInfo[SETTING_INTERVAL_5].subText = L"";
718 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
720 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
721 settingInfo[SETTING_INTERVAL_10].subText = L"";
722 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
724 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
725 settingInfo[SETTING_INTERVAL_20].subText = L"";
726 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
728 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
730 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
731 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
733 if (repeatValue == 0)
735 settingInfo[SETTING_REPEAT].isSelected = false ;
739 settingInfo[SETTING_REPEAT].isSelected = true ;
742 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
743 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
745 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
746 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
748 if (shuffletValue == 0)
750 settingInfo[SETTING_SHUFFLE].isSelected = false ;
754 settingInfo[SETTING_SHUFFLE].isSelected = true ;
757 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
758 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
759 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
761 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
762 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
763 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
765 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
766 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
767 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
769 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
770 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
771 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
774 SettingMainForm::SettingItemInfo::SettingItemInfo(void)
783 SettingMainForm::OnSettingChanged(String& key)
785 AppLogDebug("ENTER");
786 if (key == L"http://tizen.org/setting/font.size")
788 __pList->UpdateList();
790 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));