2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
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)
44 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
47 SettingMainForm::~SettingMainForm(void)
52 delete[] pGroupItemCount;
54 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
58 SettingMainForm::Initialize(void)
61 result r = Form::Construct(IDL_FORM_SETTING_MAIN);
62 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
68 SettingMainForm::OnInitializing(void)
71 __pPresentationModel = SettingPresentationModel::GetInstance();
73 InitializeSettingValues();
75 Header* pHeader = GetHeader();
77 pHeader->SetStyle(HEADER_STYLE_TITLE);
78 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
80 __pList = static_cast< GroupedListView* >(GetControl(L"IDC_SETTING_LIST"));
84 __pList->SetItemProvider(*this);
85 __pList->AddGroupedListViewItemEventListener(*this);
88 Footer* pFooter = GetFooter();
91 AppLogDebug("setting back button");
92 pFooter->SetBackButtonEnabled(true);
95 SetFormBackEventListener(this);
96 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
102 SettingMainForm::OnTerminating(void)
104 AppLogDebug("ENTER");
105 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
111 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
113 AppLogDebug("ENTER");
114 SceneManager* pSceneManager = SceneManager::GetInstance();
115 AppAssert(pSceneManager);
124 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
128 SettingMainForm::OnFormBackRequested(Form& source)
130 AppLogDebug("ENTER");
132 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
135 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
137 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 pSceneManager->GoBackward(BackwardSceneTransition());
147 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
151 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
152 const SceneId& currentSceneId, IList* pArgs)
154 AppLogDebug("ENTER");
155 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
159 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
160 const SceneId& nextSceneId)
162 AppLogDebug("ENTER");
163 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
167 SettingMainForm::OnGroupedListViewContextItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListContextItemStatus status)
172 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
174 int effectiveIndex = 0;
177 effectiveIndex = effectiveIndex + itemIndex;
179 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
181 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
182 if (settingInfo[effectiveIndex].isOpen == false)
184 settingInfo[effectiveIndex].isOpen = true;
185 settingInfo[effectiveIndex].childCount = 0;
186 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
188 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
190 settingInfo[effectiveIndex].childCount++;
197 listView.UpdateList();
201 settingInfo[effectiveIndex].isOpen = false;
202 listView.UpdateList();
205 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
208 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
210 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
215 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
217 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
219 if (parentIndex + iter + 1 != effectiveIndex)
221 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
222 settingInfo[parentIndex + iter + 1].isSelected = false;
226 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
227 settingInfo[effectiveIndex].isSelected = true;
233 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
235 if (settingInfo[effectiveIndex].isSelected == true)
237 settingInfo[effectiveIndex].isSelected = false;
241 settingInfo[effectiveIndex].isSelected = true;
245 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
249 switch (effectiveIndex)
251 case SETTING_INTERVAL_2:
254 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
256 listView.UpdateList();
259 case SETTING_INTERVAL_3:
262 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
263 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
264 listView.UpdateList();
268 case SETTING_INTERVAL_5:
271 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
272 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
273 listView.UpdateList();
277 case SETTING_INTERVAL_10:
280 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
281 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
282 listView.UpdateList();
286 case SETTING_INTERVAL_20:
289 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
290 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
291 listView.UpdateList();
295 case SETTING_TRANSITION_SLIDE:
298 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
299 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
300 listView.UpdateList();
304 case SETTING_TRANSITION_DISSOLVE:
307 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
308 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
311 AppLogDebug(" Passed") ;
314 listView.UpdateList();
317 case SETTING_TRANSITION_ZOOM:
320 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
321 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
322 listView.UpdateList();
328 int repeatValue = 0 ;
330 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
331 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
333 if (repeatValue == 0)
342 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
343 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
347 case SETTING_SHUFFLE:
349 int shuffleValue = 0;
351 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
352 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
354 if (shuffleValue == 0)
363 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
364 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
373 SettingMainForm::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex,
374 SweepDirection direction)
379 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
381 result r = E_FAILURE;
383 GroupItem* pItem = null;
384 const Color ITEM_TEXT_COLOR = CUSTOM_COLOR_SETTINGS_GROUPTITLE;
386 pItem = new(std::nothrow) GroupItem();
391 r = pItem->Construct(Dimension(itemWidth, 46));
401 text = ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW");
408 pItem->SetElement(text, null);
410 AppLogDebug("background color set result %s", GetErrorMessage(r));
412 pItem->SetTextColor(ITEM_TEXT_COLOR);
417 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
419 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
422 result r = E_SUCCESS;
423 int effectiveIndex = 0;
424 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
425 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
427 effectiveIndex = effectiveIndex + itemIndex;
428 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
430 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
432 SettingToggleCustomItem* pItem = new(std::nothrow) SettingToggleCustomItem();
433 r = pItem->Construct(itemWidth, 112);
441 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL,ITEM_BACKGROUND_COLOR);
442 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED,ITEM_BACKGROUND_COLOR);
446 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
449 pItem->SetText(settingInfo[effectiveIndex].titleText);
454 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
456 DropDownCustomItem* pItem = new(std::nothrow) DropDownCustomItem();
457 r = pItem->Construct(itemWidth);
464 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL,ITEM_BACKGROUND_COLOR);
465 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED,ITEM_BACKGROUND_COLOR);
467 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
468 pItem->SetSubText(settingInfo[effectiveIndex].subText);
469 if (settingInfo[effectiveIndex].isOpen)
471 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
475 pItem->SetCurState(DROP_DOWN__ITEM_STATE_CLOSED);
488 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
490 RadioCustomItem* pItem = new(std::nothrow) RadioCustomItem();
493 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
495 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
499 if (settingInfo[parentIndex].isOpen == false)
501 r = pItem->Construct(itemWidth, 0);
502 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
507 pItem->Construct(itemWidth, 112);
510 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL,ITEM_RADIO_ITEM_BACKGROUND_COLOR);
511 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED,ITEM_RADIO_ITEM_BACKGROUND_COLOR);
513 pItem->SetText(settingInfo[effectiveIndex].titleText);
514 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
516 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
528 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
535 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
542 SettingMainForm::GetGroupCount(void)
550 SettingMainForm::GetItemCount(int groupIndex)
552 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
553 return pGroupItemCount[groupIndex];
557 SettingMainForm::InitializeSettingValues(void)
559 pGroupItemCount = new(std::nothrow) int[1];
560 pGroupItemCount[0] = 13;
562 int transitionValue = 0;
564 int shuffletValue = 0;
565 String selectedInterval;
566 String selectedTransition;
568 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
570 settingInfo[iter].isSelected = false;
573 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
582 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
583 settingInfo[SETTING_INTERVAL_2].isSelected = true;
589 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
590 settingInfo[SETTING_INTERVAL_3].isSelected = true;
596 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
597 settingInfo[SETTING_INTERVAL_5].isSelected = true;
603 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
604 settingInfo[SETTING_INTERVAL_10].isSelected = true;
610 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
611 settingInfo[SETTING_INTERVAL_20].isSelected = true;
620 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
621 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
625 switch (transitionValue)
629 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDE");
630 settingInfo[SETTING_TRANSITION_SLIDE].isSelected = true;
636 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
637 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
643 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
644 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
653 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
654 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval ;
655 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
657 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
658 settingInfo[SETTING_INTERVAL_2].subText = L"";
659 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
661 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
662 settingInfo[SETTING_INTERVAL_3].subText = L"";
663 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
665 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
666 settingInfo[SETTING_INTERVAL_5].subText = L"";
667 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
669 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
670 settingInfo[SETTING_INTERVAL_10].subText = L"";
671 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
673 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
674 settingInfo[SETTING_INTERVAL_20].subText = L"";
675 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
677 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
679 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
680 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
682 if (repeatValue == 0)
684 settingInfo[SETTING_REPEAT].isSelected = false ;
688 settingInfo[SETTING_REPEAT].isSelected = true ;
691 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
692 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
694 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
695 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
697 if ( shuffletValue == 0)
699 settingInfo[SETTING_SHUFFLE].isSelected = false ;
703 settingInfo[SETTING_SHUFFLE].isSelected = true ;
706 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
707 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
708 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
710 settingInfo[SETTING_TRANSITION_SLIDE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDE");
711 settingInfo[SETTING_TRANSITION_SLIDE].subText = L"";
712 settingInfo[SETTING_TRANSITION_SLIDE].itemType = ITEM_TYPE_RADIO;
714 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
715 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
716 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
718 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
719 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
720 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
723 SettingMainForm::SettingItemInfo::SettingItemInfo(void)