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)
47 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
50 SettingMainForm::~SettingMainForm(void)
55 delete[] pGroupItemCount;
57 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
61 SettingMainForm::Initialize(void)
64 result r = Form::Construct(IDL_FORM_SETTING_MAIN);
65 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
71 SettingMainForm::OnInitializing(void)
74 __pPresentationModel = SettingPresentationModel::GetInstance();
76 InitializeSettingValues();
78 Header* pHeader = GetHeader();
80 pHeader->SetStyle(HEADER_STYLE_TITLE);
81 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
83 __pList = static_cast<GroupedListView*>(GetControl(L"IDC_SETTING_LIST"));
87 __pList->SetItemProvider(*this);
88 __pList->AddGroupedListViewItemEventListener(*this);
91 Footer* pFooter = GetFooter();
94 AppLogDebug("setting back button");
95 pFooter->SetBackButtonEnabled(true);
98 SetFormBackEventListener(this);
99 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
105 SettingMainForm::OnTerminating(void)
107 AppLogDebug("ENTER");
108 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
114 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
116 AppLogDebug("ENTER");
117 SceneManager* pSceneManager = SceneManager::GetInstance();
118 AppAssert(pSceneManager);
127 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
131 SettingMainForm::OnFormBackRequested(Form& source)
133 AppLogDebug("ENTER");
135 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
138 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
140 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
145 SceneManager* pSceneManager = SceneManager::GetInstance();
146 if (__contentUpdated)
148 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
152 pSceneManager->GoBackward(BackwardSceneTransition());
157 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
161 SettingMainForm::OnContentUpdated(void)
163 AppLogDebug("ENTER");
164 __contentUpdated = true;
165 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
169 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
170 const SceneId& currentSceneId, IList* pArgs)
172 AppLogDebug("ENTER");
173 FileListPresentationModel::GetInstance()->AddContentEventListener(this);
174 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
178 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
179 const SceneId& nextSceneId)
181 AppLogDebug("ENTER");
182 FileListPresentationModel::GetInstance()->RemoveContentEventListener(this);
183 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
187 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
189 int effectiveIndex = 0;
192 effectiveIndex = effectiveIndex + itemIndex;
194 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
196 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
197 if (settingInfo[effectiveIndex].isOpen == false)
199 settingInfo[effectiveIndex].isOpen = true;
200 settingInfo[effectiveIndex].childCount = 0;
201 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
203 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
205 settingInfo[effectiveIndex].childCount++;
212 listView.UpdateList();
216 settingInfo[effectiveIndex].isOpen = false;
217 listView.UpdateList();
220 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
223 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
225 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
230 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
232 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
234 if (parentIndex + iter + 1 != effectiveIndex)
236 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
237 settingInfo[parentIndex + iter + 1].isSelected = false;
241 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
242 settingInfo[effectiveIndex].isSelected = true;
248 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
250 if (settingInfo[effectiveIndex].isSelected == true)
252 settingInfo[effectiveIndex].isSelected = false;
256 settingInfo[effectiveIndex].isSelected = true;
260 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
264 switch (effectiveIndex)
266 case SETTING_INTERVAL_2:
269 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
271 listView.UpdateList();
275 case SETTING_INTERVAL_3:
278 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
279 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
280 listView.UpdateList();
284 case SETTING_INTERVAL_5:
287 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
288 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
289 listView.UpdateList();
293 case SETTING_INTERVAL_10:
296 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
297 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
298 listView.UpdateList();
302 case SETTING_INTERVAL_20:
305 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
306 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
307 listView.UpdateList();
311 case SETTING_TRANSITION_PAGE:
314 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
315 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
316 listView.UpdateList();
320 case SETTING_TRANSITION_DISSOLVE:
323 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
324 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
327 AppLogDebug(" Passed") ;
330 listView.UpdateList();
334 case SETTING_TRANSITION_ZOOM:
337 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
338 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
339 listView.UpdateList();
345 int repeatValue = 0 ;
347 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
348 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
350 if (repeatValue == 0)
359 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
360 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
364 case SETTING_SHUFFLE:
366 int shuffleValue = 0;
368 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
369 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
371 if (shuffleValue == 0)
380 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
381 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
391 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
393 GroupItem* pItem = new (std::nothrow) GroupItem();
398 result r = pItem->Construct(Dimension(itemWidth, 46));
409 text = ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW");
416 pItem->SetElement(text, null);
418 AppLogDebug("background color set result %s", GetErrorMessage(r));
420 pItem->SetTextColor(CUSTOM_COLOR_SETTINGS_GROUPTITLE);
425 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
427 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
430 result r = E_SUCCESS;
431 int effectiveIndex = 0;
432 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
433 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
434 const Color ITEM_BACKGROUND_COLOR_HIGHLIGHTED = CUSTOM_BACKGROUND_COLOR_LISTVIEW_PRESSED_HIGHLIGHTED;
436 effectiveIndex = effectiveIndex + itemIndex;
437 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
439 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
441 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
442 r = pItem->Construct(itemWidth, 112);
450 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
451 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
455 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
458 pItem->SetText(settingInfo[effectiveIndex].titleText);
463 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
465 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
466 r = pItem->Construct(itemWidth);
473 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
474 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
476 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
477 pItem->SetSubText(settingInfo[effectiveIndex].subText);
478 if (settingInfo[effectiveIndex].isOpen)
480 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
484 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
497 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
499 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
502 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
504 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
508 if (settingInfo[parentIndex].isOpen == false)
510 r = pItem->Construct(itemWidth, 0);
511 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
516 pItem->Construct(itemWidth, 112);
519 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
520 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
522 pItem->SetText(settingInfo[effectiveIndex].titleText);
523 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
525 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
537 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
544 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
551 SettingMainForm::GetGroupCount(void)
559 SettingMainForm::GetItemCount(int groupIndex)
561 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
562 return pGroupItemCount[groupIndex];
566 SettingMainForm::InitializeSettingValues(void)
568 pGroupItemCount = new (std::nothrow) int[1];
569 pGroupItemCount[0] = 13;
571 int transitionValue = 0;
573 int shuffletValue = 0;
574 String selectedInterval;
575 String selectedTransition;
577 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
579 settingInfo[iter].isSelected = false;
582 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
591 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
592 settingInfo[SETTING_INTERVAL_2].isSelected = true;
598 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
599 settingInfo[SETTING_INTERVAL_3].isSelected = true;
605 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
606 settingInfo[SETTING_INTERVAL_5].isSelected = true;
612 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
613 settingInfo[SETTING_INTERVAL_10].isSelected = true;
619 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
620 settingInfo[SETTING_INTERVAL_20].isSelected = true;
629 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
630 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
634 switch (transitionValue)
638 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
639 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
645 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
646 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
652 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
653 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
662 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
663 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval ;
664 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
666 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
667 settingInfo[SETTING_INTERVAL_2].subText = L"";
668 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
670 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
671 settingInfo[SETTING_INTERVAL_3].subText = L"";
672 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
674 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
675 settingInfo[SETTING_INTERVAL_5].subText = L"";
676 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
678 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
679 settingInfo[SETTING_INTERVAL_10].subText = L"";
680 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
682 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
683 settingInfo[SETTING_INTERVAL_20].subText = L"";
684 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
686 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
688 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
689 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
691 if (repeatValue == 0)
693 settingInfo[SETTING_REPEAT].isSelected = false ;
697 settingInfo[SETTING_REPEAT].isSelected = true ;
700 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
701 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
703 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
704 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
706 if (shuffletValue == 0)
708 settingInfo[SETTING_SHUFFLE].isSelected = false ;
712 settingInfo[SETTING_SHUFFLE].isSelected = true ;
715 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
716 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
717 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
719 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
720 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
721 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
723 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
724 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
725 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
727 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
728 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
729 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
732 SettingMainForm::SettingItemInfo::SettingItemInfo(void)