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 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 SetFormBackEventListener(this);
92 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
98 SettingMainForm::OnTerminating(void)
100 AppLogDebug("ENTER");
101 SettingInfo::RemoveSettingEventListener(*this);
102 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
108 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
110 AppLogDebug("ENTER");
111 SceneManager* pSceneManager = SceneManager::GetInstance();
112 AppAssert(pSceneManager);
121 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
125 SettingMainForm::OnFormBackRequested(Form& source)
127 AppLogDebug("ENTER");
129 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
132 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
134 if (pApp->GetFrameActivated() == true)
136 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
142 SceneManager* pSceneManager = SceneManager::GetInstance();
143 if (__contentUpdated)
145 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
149 pSceneManager->GoBackward(BackwardSceneTransition());
154 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
158 SettingMainForm::OnContentUpdated(void)
160 AppLogDebug("ENTER");
161 __contentUpdated = true;
162 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
166 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
167 const SceneId& currentSceneId, IList* pArgs)
169 AppLogDebug("ENTER");
170 FileListPresentationModel::GetInstance()->AddContentEventListener(this);
171 __pPresentationModel->CreateDefaultRegistry();
172 InitializeSettingValues();
173 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
177 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
178 const SceneId& nextSceneId)
180 AppLogDebug("ENTER");
181 __pPresentationModel->DeleteRegistry();
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();
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_OPT_SLIDESHOW");
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);
442 int defaultHeight = 112;
443 int defaultFontSize = 44;
445 SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
446 AppLog("the font value is %S",fontSizeStr.GetPointer());
448 if(fontSizeStr == "medium")
451 itemHeight = defaultHeight + (fontSize - defaultFontSize);
453 else if(fontSizeStr == "huge")
456 itemHeight = defaultHeight + (fontSize - defaultFontSize);
458 else if(fontSizeStr == "giant")
461 itemHeight = defaultHeight + (fontSize - defaultFontSize);
463 else if(fontSizeStr == "small")
466 itemHeight = defaultHeight + (fontSize - defaultFontSize);
468 else if(fontSizeStr == "large")
471 itemHeight = defaultHeight + (fontSize - defaultFontSize);
476 itemHeight = defaultHeight;
480 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
482 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
483 r = pItem->Construct(itemWidth, itemHeight);
491 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
492 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
496 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
499 pItem->SetText(settingInfo[effectiveIndex].titleText);
500 pItem->Make(fontSize);
504 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
506 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
507 r = pItem->Construct(itemWidth,itemHeight);
514 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
515 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
517 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
518 pItem->SetSubText(settingInfo[effectiveIndex].subText);
519 if (settingInfo[effectiveIndex].isOpen)
521 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
525 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
528 r = pItem->Make(fontSize,itemHeight);
538 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
540 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
543 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
545 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
549 if (settingInfo[parentIndex].isOpen == false)
551 r = pItem->Construct(itemWidth, 0);
552 __pList->SetItemEnabled(groupIndex, itemIndex,false);
553 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
558 pItem->Construct(itemWidth, itemHeight);
559 __pList->SetItemEnabled(groupIndex, itemIndex, true);
562 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
563 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
565 pItem->SetText(settingInfo[effectiveIndex].titleText);
566 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
568 __pList->SetItemChecked(groupIndex,itemIndex,settingInfo[effectiveIndex].isSelected);
569 pItem->Make(fontSize);
580 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
587 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
594 SettingMainForm::GetGroupCount(void)
602 SettingMainForm::GetItemCount(int groupIndex)
604 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
605 return pGroupItemCount[groupIndex];
609 SettingMainForm::InitializeSettingValues(void)
611 pGroupItemCount = new (std::nothrow) int[1];
612 pGroupItemCount[0] = 12;
614 int transitionValue = 0;
616 int shuffletValue = 0;
617 String selectedInterval;
618 String selectedTransition;
620 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
622 settingInfo[iter].isSelected = false;
625 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
634 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
635 settingInfo[SETTING_INTERVAL_2].isSelected = true;
641 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
642 settingInfo[SETTING_INTERVAL_3].isSelected = true;
648 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
649 settingInfo[SETTING_INTERVAL_5].isSelected = true;
655 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
656 settingInfo[SETTING_INTERVAL_10].isSelected = true;
662 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
663 settingInfo[SETTING_INTERVAL_20].isSelected = true;
672 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
673 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
677 switch (transitionValue)
681 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
682 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
688 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
689 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
695 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
696 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
705 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
706 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval;
707 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
709 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
710 settingInfo[SETTING_INTERVAL_2].subText = L"";
711 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
713 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
714 settingInfo[SETTING_INTERVAL_3].subText = L"";
715 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
717 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
718 settingInfo[SETTING_INTERVAL_5].subText = L"";
719 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
721 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
722 settingInfo[SETTING_INTERVAL_10].subText = L"";
723 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
725 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
726 settingInfo[SETTING_INTERVAL_20].subText = L"";
727 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
729 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
731 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
732 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
734 if (repeatValue == 0)
736 settingInfo[SETTING_REPEAT].isSelected = false;
740 settingInfo[SETTING_REPEAT].isSelected = true;
743 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
744 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
746 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
747 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
749 if (shuffletValue == 0)
751 settingInfo[SETTING_SHUFFLE].isSelected = false;
755 settingInfo[SETTING_SHUFFLE].isSelected = true;
758 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
759 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
760 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
762 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
763 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
764 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
766 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
767 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
768 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
770 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
771 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
772 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
775 SettingMainForm::SettingItemInfo::SettingItemInfo(void)
784 SettingMainForm::OnSettingChanged(String& key)
786 AppLogDebug("ENTER");
787 if (key == L"http://tizen.org/setting/font.size")
789 __pList->UpdateList();
791 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));