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();
75 SettingInfo::AddSettingEventListener(*this);
77 InitializeSettingValues();
79 Header* pHeader = GetHeader();
81 pHeader->SetStyle(HEADER_STYLE_TITLE);
82 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_GALLERY"));
84 __pList = static_cast<GroupedListView*>(GetControl(L"IDC_SETTING_LIST"));
88 __pList->SetItemProvider(*this);
89 __pList->AddGroupedListViewItemEventListener(*this);
92 Footer* pFooter = GetFooter();
95 AppLogDebug("setting back button");
96 pFooter->SetBackButtonEnabled(true);
99 SetFormBackEventListener(this);
100 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
106 SettingMainForm::OnTerminating(void)
108 AppLogDebug("ENTER");
109 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
115 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
117 AppLogDebug("ENTER");
118 SceneManager* pSceneManager = SceneManager::GetInstance();
119 AppAssert(pSceneManager);
128 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
132 SettingMainForm::OnFormBackRequested(Form& source)
134 AppLogDebug("ENTER");
136 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
139 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
141 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
146 SceneManager* pSceneManager = SceneManager::GetInstance();
147 if (__contentUpdated)
149 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
153 pSceneManager->GoBackward(BackwardSceneTransition());
158 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
162 SettingMainForm::OnContentUpdated(void)
164 AppLogDebug("ENTER");
165 __contentUpdated = true;
166 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
170 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
171 const SceneId& currentSceneId, IList* pArgs)
173 AppLogDebug("ENTER");
174 FileListPresentationModel::GetInstance()->AddContentEventListener(this);
175 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
179 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
180 const SceneId& nextSceneId)
182 AppLogDebug("ENTER");
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();
346 int repeatValue = 0 ;
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_BUTTON_SLIDE_SHOW");
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);
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 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
557 pItem->Construct(itemWidth, itemHeight);
560 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
561 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
563 pItem->SetText(settingInfo[effectiveIndex].titleText);
564 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
566 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
567 pItem->Make(fontSize);
578 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
585 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
592 SettingMainForm::GetGroupCount(void)
600 SettingMainForm::GetItemCount(int groupIndex)
602 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
603 return pGroupItemCount[groupIndex];
607 SettingMainForm::InitializeSettingValues(void)
609 pGroupItemCount = new (std::nothrow) int[1];
610 pGroupItemCount[0] = 13;
612 int transitionValue = 0;
614 int shuffletValue = 0;
615 String selectedInterval;
616 String selectedTransition;
618 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
620 settingInfo[iter].isSelected = false;
623 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
632 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
633 settingInfo[SETTING_INTERVAL_2].isSelected = true;
639 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
640 settingInfo[SETTING_INTERVAL_3].isSelected = true;
646 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
647 settingInfo[SETTING_INTERVAL_5].isSelected = true;
653 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
654 settingInfo[SETTING_INTERVAL_10].isSelected = true;
660 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
661 settingInfo[SETTING_INTERVAL_20].isSelected = true;
670 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
671 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
675 switch (transitionValue)
679 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
680 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
686 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
687 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
693 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
694 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
703 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
704 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval ;
705 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
707 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
708 settingInfo[SETTING_INTERVAL_2].subText = L"";
709 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
711 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
712 settingInfo[SETTING_INTERVAL_3].subText = L"";
713 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
715 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
716 settingInfo[SETTING_INTERVAL_5].subText = L"";
717 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
719 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
720 settingInfo[SETTING_INTERVAL_10].subText = L"";
721 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
723 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
724 settingInfo[SETTING_INTERVAL_20].subText = L"";
725 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
727 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
729 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
730 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
732 if (repeatValue == 0)
734 settingInfo[SETTING_REPEAT].isSelected = false ;
738 settingInfo[SETTING_REPEAT].isSelected = true ;
741 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
742 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
744 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
745 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
747 if (shuffletValue == 0)
749 settingInfo[SETTING_SHUFFLE].isSelected = false ;
753 settingInfo[SETTING_SHUFFLE].isSelected = true ;
756 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
757 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
758 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
760 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
761 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
762 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
764 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
765 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
766 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
768 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
769 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
770 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
773 SettingMainForm::SettingItemInfo::SettingItemInfo(void)
782 SettingMainForm::OnSettingChanged(String& key)
784 AppLogDebug("ENTER");
785 if (key == L"http://tizen.org/setting/font.size")
787 __pList->UpdateList();
789 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));