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 "GlGalleryApp.h"
24 #include "GlRadioCustomItem.h"
25 #include "GlResourceManager.h"
26 #include "GlSettingMainForm.h"
27 #include "GlSettingPresentationModel.h"
28 #include "GlSettingToggleCustomItem.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Content;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::System;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 SettingMainForm::SettingMainForm(void)
43 , __pPresentationModel(null)
46 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
49 SettingMainForm::~SettingMainForm(void)
54 delete[] pGroupItemCount;
56 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
60 SettingMainForm::Initialize(void)
63 result r = Form::Construct(IDL_FORM_SETTING_MAIN);
64 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
70 SettingMainForm::OnInitializing(void)
73 __pPresentationModel = SettingPresentationModel::GetInstance();
75 InitializeSettingValues();
77 Header* pHeader = GetHeader();
79 pHeader->SetStyle(HEADER_STYLE_TITLE);
80 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
82 __pList = static_cast<GroupedListView*>(GetControl(L"IDC_SETTING_LIST"));
86 __pList->SetItemProvider(*this);
87 __pList->AddGroupedListViewItemEventListener(*this);
90 Footer* pFooter = GetFooter();
93 AppLogDebug("setting back button");
94 pFooter->SetBackButtonEnabled(true);
97 SetFormBackEventListener(this);
98 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
104 SettingMainForm::OnTerminating(void)
106 AppLogDebug("ENTER");
107 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
113 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
115 AppLogDebug("ENTER");
116 SceneManager* pSceneManager = SceneManager::GetInstance();
117 AppAssert(pSceneManager);
126 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
130 SettingMainForm::OnFormBackRequested(Form& source)
132 AppLogDebug("ENTER");
134 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
137 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
139 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
144 SceneManager* pSceneManager = SceneManager::GetInstance();
145 pSceneManager->GoBackward(BackwardSceneTransition());
149 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
153 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
154 const SceneId& currentSceneId, IList* pArgs)
156 AppLogDebug("ENTER");
157 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
161 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
162 const SceneId& nextSceneId)
164 AppLogDebug("ENTER");
165 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
169 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
171 int effectiveIndex = 0;
174 effectiveIndex = effectiveIndex + itemIndex;
176 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
178 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
179 if (settingInfo[effectiveIndex].isOpen == false)
181 settingInfo[effectiveIndex].isOpen = true;
182 settingInfo[effectiveIndex].childCount = 0;
183 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
185 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
187 settingInfo[effectiveIndex].childCount++;
194 listView.UpdateList();
198 settingInfo[effectiveIndex].isOpen = false;
199 listView.UpdateList();
202 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
205 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
207 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
212 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
214 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
216 if (parentIndex + iter + 1 != effectiveIndex)
218 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
219 settingInfo[parentIndex + iter + 1].isSelected = false;
223 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
224 settingInfo[effectiveIndex].isSelected = true;
230 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
232 if (settingInfo[effectiveIndex].isSelected == true)
234 settingInfo[effectiveIndex].isSelected = false;
238 settingInfo[effectiveIndex].isSelected = true;
242 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
246 switch (effectiveIndex)
248 case SETTING_INTERVAL_2:
251 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
253 listView.UpdateList();
257 case SETTING_INTERVAL_3:
260 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
261 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
262 listView.UpdateList();
266 case SETTING_INTERVAL_5:
269 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
270 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
271 listView.UpdateList();
275 case SETTING_INTERVAL_10:
278 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
279 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
280 listView.UpdateList();
284 case SETTING_INTERVAL_20:
287 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
288 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
289 listView.UpdateList();
293 case SETTING_TRANSITION_PAGE:
296 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
297 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
298 listView.UpdateList();
302 case SETTING_TRANSITION_DISSOLVE:
305 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
306 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
309 AppLogDebug(" Passed") ;
312 listView.UpdateList();
316 case SETTING_TRANSITION_ZOOM:
319 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
320 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
321 listView.UpdateList();
327 int repeatValue = 0 ;
329 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
330 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
332 if (repeatValue == 0)
341 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
342 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
346 case SETTING_SHUFFLE:
348 int shuffleValue = 0;
350 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
351 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
353 if (shuffleValue == 0)
362 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
363 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
373 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
375 GroupItem* pItem = new (std::nothrow) GroupItem();
380 result r = pItem->Construct(Dimension(itemWidth, 46));
391 text = ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW");
398 pItem->SetElement(text, null);
400 AppLogDebug("background color set result %s", GetErrorMessage(r));
402 pItem->SetTextColor(CUSTOM_COLOR_SETTINGS_GROUPTITLE);
407 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
409 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
412 result r = E_SUCCESS;
413 int effectiveIndex = 0;
414 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
415 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
416 const Color ITEM_BACKGROUND_COLOR_HIGHLIGHTED = CUSTOM_BACKGROUND_COLOR_LISTVIEW_PRESSED_HIGHLIGHTED;
418 effectiveIndex = effectiveIndex + itemIndex;
419 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
421 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
423 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
424 r = pItem->Construct(itemWidth, 112);
432 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
433 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
437 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
440 pItem->SetText(settingInfo[effectiveIndex].titleText);
445 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
447 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
448 r = pItem->Construct(itemWidth);
455 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
456 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
458 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
459 pItem->SetSubText(settingInfo[effectiveIndex].subText);
460 if (settingInfo[effectiveIndex].isOpen)
462 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
466 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
479 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
481 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
484 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
486 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
490 if (settingInfo[parentIndex].isOpen == false)
492 r = pItem->Construct(itemWidth, 0);
493 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
498 pItem->Construct(itemWidth, 112);
501 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
502 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
504 pItem->SetText(settingInfo[effectiveIndex].titleText);
505 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
507 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
519 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
526 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
533 SettingMainForm::GetGroupCount(void)
541 SettingMainForm::GetItemCount(int groupIndex)
543 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
544 return pGroupItemCount[groupIndex];
548 SettingMainForm::InitializeSettingValues(void)
550 pGroupItemCount = new (std::nothrow) int[1];
551 pGroupItemCount[0] = 13;
553 int transitionValue = 0;
555 int shuffletValue = 0;
556 String selectedInterval;
557 String selectedTransition;
559 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
561 settingInfo[iter].isSelected = false;
564 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
573 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
574 settingInfo[SETTING_INTERVAL_2].isSelected = true;
580 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
581 settingInfo[SETTING_INTERVAL_3].isSelected = true;
587 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
588 settingInfo[SETTING_INTERVAL_5].isSelected = true;
594 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
595 settingInfo[SETTING_INTERVAL_10].isSelected = true;
601 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
602 settingInfo[SETTING_INTERVAL_20].isSelected = true;
611 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
612 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
616 switch (transitionValue)
620 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
621 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
627 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
628 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
634 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
635 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
644 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
645 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval ;
646 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
648 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
649 settingInfo[SETTING_INTERVAL_2].subText = L"";
650 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
652 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
653 settingInfo[SETTING_INTERVAL_3].subText = L"";
654 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
656 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
657 settingInfo[SETTING_INTERVAL_5].subText = L"";
658 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
660 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
661 settingInfo[SETTING_INTERVAL_10].subText = L"";
662 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
664 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
665 settingInfo[SETTING_INTERVAL_20].subText = L"";
666 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
668 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
670 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
671 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
673 if (repeatValue == 0)
675 settingInfo[SETTING_REPEAT].isSelected = false ;
679 settingInfo[SETTING_REPEAT].isSelected = true ;
682 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
683 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
685 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
686 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
688 if (shuffletValue == 0)
690 settingInfo[SETTING_SHUFFLE].isSelected = false ;
694 settingInfo[SETTING_SHUFFLE].isSelected = true ;
697 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
698 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
699 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
701 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
702 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
703 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
705 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
706 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
707 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
709 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
710 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
711 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
714 SettingMainForm::SettingItemInfo::SettingItemInfo(void)