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 __contentUpdated = false;
182 __pPresentationModel->DeleteRegistry();
183 FileListPresentationModel::GetInstance()->RemoveContentEventListener(this);
184 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
188 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
190 int effectiveIndex = 0;
193 effectiveIndex = effectiveIndex + itemIndex;
195 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
197 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
198 if (settingInfo[effectiveIndex].isOpen == false)
200 settingInfo[effectiveIndex].isOpen = true;
201 settingInfo[effectiveIndex].childCount = 0;
202 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
204 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
206 ++settingInfo[effectiveIndex].childCount;
213 listView.UpdateList();
217 settingInfo[effectiveIndex].isOpen = false;
218 listView.UpdateList();
221 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
224 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
226 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
231 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
233 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
235 if (parentIndex + iter + 1 != effectiveIndex)
237 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
238 settingInfo[parentIndex + iter + 1].isSelected = false;
242 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
243 settingInfo[effectiveIndex].isSelected = true;
249 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
251 if (settingInfo[effectiveIndex].isSelected == true)
253 settingInfo[effectiveIndex].isSelected = false;
257 settingInfo[effectiveIndex].isSelected = true;
261 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
265 switch (effectiveIndex)
267 case SETTING_INTERVAL_2:
270 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
272 listView.UpdateList();
276 case SETTING_INTERVAL_3:
279 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
280 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
281 listView.UpdateList();
285 case SETTING_INTERVAL_5:
288 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
289 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
290 listView.UpdateList();
294 case SETTING_INTERVAL_10:
297 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
298 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
299 listView.UpdateList();
303 case SETTING_INTERVAL_20:
306 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
307 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
308 listView.UpdateList();
312 case SETTING_TRANSITION_PAGE:
315 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
316 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
317 listView.UpdateList();
321 case SETTING_TRANSITION_DISSOLVE:
324 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
325 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
328 AppLogDebug(" Passed");
331 listView.UpdateList();
335 case SETTING_TRANSITION_ZOOM:
338 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
339 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
340 listView.UpdateList();
348 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
349 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
351 if (repeatValue == 0)
360 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
361 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
365 case SETTING_SHUFFLE:
367 int shuffleValue = 0;
369 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
370 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
372 if (shuffleValue == 0)
381 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
382 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
392 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
394 GroupItem* pItem = new (std::nothrow) GroupItem();
399 result r = pItem->Construct(Dimension(itemWidth, 46));
410 text = ResourceManager::GetString(L"IDS_MEDIABR_OPT_SLIDESHOW");
417 pItem->SetElement(text, null);
419 AppLogDebug("background color set result %s", GetErrorMessage(r));
421 pItem->SetTextColor(CUSTOM_COLOR_SETTINGS_GROUPTITLE);
426 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
428 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
431 result r = E_SUCCESS;
432 int effectiveIndex = 0;
433 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
434 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
435 const Color ITEM_BACKGROUND_COLOR_HIGHLIGHTED = CUSTOM_BACKGROUND_COLOR_LISTVIEW_PRESSED_HIGHLIGHTED;
437 effectiveIndex = effectiveIndex + itemIndex;
438 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
443 int defaultHeight = 112;
444 int defaultFontSize = 44;
446 SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
447 AppLog("the font value is %S",fontSizeStr.GetPointer());
449 if(fontSizeStr == "medium")
452 itemHeight = defaultHeight + (fontSize - defaultFontSize);
454 else if(fontSizeStr == "huge")
457 itemHeight = defaultHeight + (fontSize - defaultFontSize);
459 else if(fontSizeStr == "giant")
462 itemHeight = defaultHeight + (fontSize - defaultFontSize);
464 else if(fontSizeStr == "small")
467 itemHeight = defaultHeight + (fontSize - defaultFontSize);
469 else if(fontSizeStr == "large")
472 itemHeight = defaultHeight + (fontSize - defaultFontSize);
477 itemHeight = defaultHeight;
481 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
483 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
484 r = pItem->Construct(itemWidth, itemHeight);
492 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
493 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
497 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
500 pItem->SetText(settingInfo[effectiveIndex].titleText);
501 pItem->Make(fontSize);
505 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
507 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
508 r = pItem->Construct(itemWidth,itemHeight);
515 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
516 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
518 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
519 pItem->SetSubText(settingInfo[effectiveIndex].subText);
520 if (settingInfo[effectiveIndex].isOpen)
522 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
526 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
529 r = pItem->Make(fontSize,itemHeight);
539 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
541 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
544 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
546 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
550 if (settingInfo[parentIndex].isOpen == false)
552 r = pItem->Construct(itemWidth, 0);
553 __pList->SetItemEnabled(groupIndex, itemIndex,false);
554 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
559 pItem->Construct(itemWidth, itemHeight);
560 __pList->SetItemEnabled(groupIndex, itemIndex, true);
563 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
564 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
566 pItem->SetText(settingInfo[effectiveIndex].titleText);
567 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
569 __pList->SetItemChecked(groupIndex,itemIndex,settingInfo[effectiveIndex].isSelected);
570 pItem->Make(fontSize);
581 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
588 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
595 SettingMainForm::GetGroupCount(void)
603 SettingMainForm::GetItemCount(int groupIndex)
605 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
606 return pGroupItemCount[groupIndex];
610 SettingMainForm::InitializeSettingValues(void)
612 pGroupItemCount = new (std::nothrow) int[1];
613 pGroupItemCount[0] = 12;
615 int transitionValue = 0;
617 int shuffletValue = 0;
618 String selectedInterval;
619 String selectedTransition;
621 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
623 settingInfo[iter].isSelected = false;
626 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
635 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
636 settingInfo[SETTING_INTERVAL_2].isSelected = true;
642 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
643 settingInfo[SETTING_INTERVAL_3].isSelected = true;
649 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
650 settingInfo[SETTING_INTERVAL_5].isSelected = true;
656 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
657 settingInfo[SETTING_INTERVAL_10].isSelected = true;
663 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
664 settingInfo[SETTING_INTERVAL_20].isSelected = true;
673 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
674 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
678 switch (transitionValue)
682 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
683 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
689 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
690 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
696 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
697 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
706 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
707 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval;
708 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
710 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
711 settingInfo[SETTING_INTERVAL_2].subText = L"";
712 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
714 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
715 settingInfo[SETTING_INTERVAL_3].subText = L"";
716 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
718 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
719 settingInfo[SETTING_INTERVAL_5].subText = L"";
720 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
722 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
723 settingInfo[SETTING_INTERVAL_10].subText = L"";
724 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
726 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
727 settingInfo[SETTING_INTERVAL_20].subText = L"";
728 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
730 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
732 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
733 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
735 if (repeatValue == 0)
737 settingInfo[SETTING_REPEAT].isSelected = false;
741 settingInfo[SETTING_REPEAT].isSelected = true;
744 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
745 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
747 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
748 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
750 if (shuffletValue == 0)
752 settingInfo[SETTING_SHUFFLE].isSelected = false;
756 settingInfo[SETTING_SHUFFLE].isSelected = true;
759 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
760 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
761 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
763 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
764 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
765 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
767 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
768 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
769 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
771 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
772 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
773 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
776 SettingMainForm::SettingItemInfo::SettingItemInfo(void)
785 SettingMainForm::OnSettingChanged(String& key)
787 AppLogDebug("ENTER");
788 if (key == L"http://tizen.org/setting/font.size")
790 __pList->UpdateList();
792 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));