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 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
109 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
111 AppLogDebug("ENTER");
112 SceneManager* pSceneManager = SceneManager::GetInstance();
113 AppAssert(pSceneManager);
122 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
126 SettingMainForm::OnFormBackRequested(Form& source)
128 AppLogDebug("ENTER");
130 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
133 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
135 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
140 SceneManager* pSceneManager = SceneManager::GetInstance();
141 if (__contentUpdated)
143 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
147 pSceneManager->GoBackward(BackwardSceneTransition());
152 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
156 SettingMainForm::OnContentUpdated(void)
158 AppLogDebug("ENTER");
159 __contentUpdated = true;
160 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
164 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
165 const SceneId& currentSceneId, IList* pArgs)
167 AppLogDebug("ENTER");
168 FileListPresentationModel::GetInstance()->AddContentEventListener(this);
169 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
173 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
174 const SceneId& nextSceneId)
176 AppLogDebug("ENTER");
177 FileListPresentationModel::GetInstance()->RemoveContentEventListener(this);
178 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
182 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
184 int effectiveIndex = 0;
187 effectiveIndex = effectiveIndex + itemIndex;
189 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
191 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
192 if (settingInfo[effectiveIndex].isOpen == false)
194 settingInfo[effectiveIndex].isOpen = true;
195 settingInfo[effectiveIndex].childCount = 0;
196 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
198 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
200 settingInfo[effectiveIndex].childCount++;
207 listView.UpdateList();
211 settingInfo[effectiveIndex].isOpen = false;
212 listView.UpdateList();
215 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
218 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
220 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
225 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
227 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
229 if (parentIndex + iter + 1 != effectiveIndex)
231 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
232 settingInfo[parentIndex + iter + 1].isSelected = false;
236 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
237 settingInfo[effectiveIndex].isSelected = true;
243 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
245 if (settingInfo[effectiveIndex].isSelected == true)
247 settingInfo[effectiveIndex].isSelected = false;
251 settingInfo[effectiveIndex].isSelected = true;
255 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
259 switch (effectiveIndex)
261 case SETTING_INTERVAL_2:
264 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
266 listView.UpdateList();
270 case SETTING_INTERVAL_3:
273 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
274 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
275 listView.UpdateList();
279 case SETTING_INTERVAL_5:
282 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
283 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
284 listView.UpdateList();
288 case SETTING_INTERVAL_10:
291 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
292 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
293 listView.UpdateList();
297 case SETTING_INTERVAL_20:
300 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
301 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
302 listView.UpdateList();
306 case SETTING_TRANSITION_PAGE:
309 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
310 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
311 listView.UpdateList();
315 case SETTING_TRANSITION_DISSOLVE:
318 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
319 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
322 AppLogDebug(" Passed") ;
325 listView.UpdateList();
329 case SETTING_TRANSITION_ZOOM:
332 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
333 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
334 listView.UpdateList();
340 int repeatValue = 0 ;
342 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
343 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
345 if (repeatValue == 0)
354 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
355 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
359 case SETTING_SHUFFLE:
361 int shuffleValue = 0;
363 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
364 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
366 if (shuffleValue == 0)
375 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
376 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
386 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
388 GroupItem* pItem = new (std::nothrow) GroupItem();
393 result r = pItem->Construct(Dimension(itemWidth, 46));
404 text = ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW");
411 pItem->SetElement(text, null);
413 AppLogDebug("background color set result %s", GetErrorMessage(r));
415 pItem->SetTextColor(CUSTOM_COLOR_SETTINGS_GROUPTITLE);
420 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
422 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
425 result r = E_SUCCESS;
426 int effectiveIndex = 0;
427 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
428 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
429 const Color ITEM_BACKGROUND_COLOR_HIGHLIGHTED = CUSTOM_BACKGROUND_COLOR_LISTVIEW_PRESSED_HIGHLIGHTED;
431 effectiveIndex = effectiveIndex + itemIndex;
432 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
437 int defaultHeight = 112 ;
438 int defaultFontSize = 44 ;
440 SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
441 AppLog("the font value is %S",fontSizeStr.GetPointer());
443 if(fontSizeStr == "medium")
446 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
448 else if(fontSizeStr == "huge")
451 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
453 else if(fontSizeStr == "giant")
456 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
458 else if(fontSizeStr == "small")
461 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
463 else if(fontSizeStr == "large")
466 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
474 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
476 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
477 r = pItem->Construct(itemWidth, itemHeight);
485 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
486 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
490 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
493 pItem->SetText(settingInfo[effectiveIndex].titleText);
494 pItem->Make(fontSize);
498 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
500 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
501 r = pItem->Construct(itemWidth,itemHeight);
508 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
509 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
511 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
512 pItem->SetSubText(settingInfo[effectiveIndex].subText);
513 if (settingInfo[effectiveIndex].isOpen)
515 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
519 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
522 r = pItem->Make(fontSize,itemHeight);
532 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
534 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
537 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
539 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
543 if (settingInfo[parentIndex].isOpen == false)
545 r = pItem->Construct(itemWidth, 0);
546 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
551 pItem->Construct(itemWidth, itemHeight);
554 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
555 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
557 pItem->SetText(settingInfo[effectiveIndex].titleText);
558 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
560 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
561 pItem->Make(fontSize);
572 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
579 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
586 SettingMainForm::GetGroupCount(void)
594 SettingMainForm::GetItemCount(int groupIndex)
596 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
597 return pGroupItemCount[groupIndex];
601 SettingMainForm::InitializeSettingValues(void)
603 pGroupItemCount = new (std::nothrow) int[1];
604 pGroupItemCount[0] = 13;
606 int transitionValue = 0;
608 int shuffletValue = 0;
609 String selectedInterval;
610 String selectedTransition;
612 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
614 settingInfo[iter].isSelected = false;
617 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
626 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
627 settingInfo[SETTING_INTERVAL_2].isSelected = true;
633 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
634 settingInfo[SETTING_INTERVAL_3].isSelected = true;
640 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
641 settingInfo[SETTING_INTERVAL_5].isSelected = true;
647 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
648 settingInfo[SETTING_INTERVAL_10].isSelected = true;
654 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
655 settingInfo[SETTING_INTERVAL_20].isSelected = true;
664 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
665 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
669 switch (transitionValue)
673 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
674 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
680 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
681 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
687 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
688 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
697 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
698 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval ;
699 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
701 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
702 settingInfo[SETTING_INTERVAL_2].subText = L"";
703 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
705 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
706 settingInfo[SETTING_INTERVAL_3].subText = L"";
707 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
709 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
710 settingInfo[SETTING_INTERVAL_5].subText = L"";
711 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
713 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
714 settingInfo[SETTING_INTERVAL_10].subText = L"";
715 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
717 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
718 settingInfo[SETTING_INTERVAL_20].subText = L"";
719 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
721 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
723 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
724 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
726 if (repeatValue == 0)
728 settingInfo[SETTING_REPEAT].isSelected = false ;
732 settingInfo[SETTING_REPEAT].isSelected = true ;
735 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
736 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
738 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
739 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
741 if (shuffletValue == 0)
743 settingInfo[SETTING_SHUFFLE].isSelected = false ;
747 settingInfo[SETTING_SHUFFLE].isSelected = true ;
750 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
751 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
752 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
754 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
755 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
756 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
758 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
759 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
760 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
762 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
763 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
764 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
767 SettingMainForm::SettingItemInfo::SettingItemInfo(void)
776 SettingMainForm::OnSettingChanged(String& key)
778 AppLogDebug("ENTER");
779 if (key == L"http://tizen.org/setting/font.size")
781 __pList->UpdateList();
783 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));