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 SettingInfo::RemoveSettingEventListener(*this);
104 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
110 SettingMainForm::OnActionPerformed(const Control& source, int actionId)
112 AppLogDebug("ENTER");
113 SceneManager* pSceneManager = SceneManager::GetInstance();
114 AppAssert(pSceneManager);
123 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
127 SettingMainForm::OnFormBackRequested(Form& source)
129 AppLogDebug("ENTER");
131 GalleryApp* pApp = dynamic_cast<GalleryApp*>(UiApp::GetInstance());
134 if (pApp->GetAppControlOperationId() == APPCONTROL_OPERATION_ID_CONFIGURE)
136 pApp->SendAppControlResult(APP_CTRL_RESULT_TERMINATED, null);
141 SceneManager* pSceneManager = SceneManager::GetInstance();
142 if (__contentUpdated)
144 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_ALBUM_LIST));
148 pSceneManager->GoBackward(BackwardSceneTransition());
153 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
157 SettingMainForm::OnContentUpdated(void)
159 AppLogDebug("ENTER");
160 __contentUpdated = true;
161 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
165 SettingMainForm::OnSceneActivatedN(const SceneId& previousSceneId,
166 const SceneId& currentSceneId, IList* pArgs)
168 AppLogDebug("ENTER");
169 FileListPresentationModel::GetInstance()->AddContentEventListener(this);
170 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
174 SettingMainForm::OnSceneDeactivated(const SceneId& currentSceneId,
175 const SceneId& nextSceneId)
177 AppLogDebug("ENTER");
178 FileListPresentationModel::GetInstance()->RemoveContentEventListener(this);
179 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));
183 SettingMainForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex, int elementId, ListItemStatus status)
185 int effectiveIndex = 0;
188 effectiveIndex = effectiveIndex + itemIndex;
190 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
192 AppLogDebug("refreshing data child count is %d", settingInfo[effectiveIndex].childCount);
193 if (settingInfo[effectiveIndex].isOpen == false)
195 settingInfo[effectiveIndex].isOpen = true;
196 settingInfo[effectiveIndex].childCount = 0;
197 for (int iter = effectiveIndex + 1; iter < SETTING_MAX; ++iter)
199 if (settingInfo[iter].itemType == ITEM_TYPE_RADIO)
201 settingInfo[effectiveIndex].childCount++;
208 listView.UpdateList();
212 settingInfo[effectiveIndex].isOpen = false;
213 listView.UpdateList();
216 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
219 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
221 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
226 settingInfo[parentIndex].subText = settingInfo[effectiveIndex].titleText;
228 for (int iter = 0; iter < settingInfo[parentIndex].childCount; ++iter)
230 if (parentIndex + iter + 1 != effectiveIndex)
232 AppLogDebug("long effectiveIndex %d set to false", itemIndex - (effectiveIndex - parentIndex) + iter + 1);
233 settingInfo[parentIndex + iter + 1].isSelected = false;
237 AppLogDebug("effectiveIndex %d set to true", effectiveIndex);
238 settingInfo[effectiveIndex].isSelected = true;
244 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
246 if (settingInfo[effectiveIndex].isSelected == true)
248 settingInfo[effectiveIndex].isSelected = false;
252 settingInfo[effectiveIndex].isSelected = true;
256 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
260 switch (effectiveIndex)
262 case SETTING_INTERVAL_2:
265 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
267 listView.UpdateList();
271 case SETTING_INTERVAL_3:
274 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
275 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
276 listView.UpdateList();
280 case SETTING_INTERVAL_5:
283 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
284 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
285 listView.UpdateList();
289 case SETTING_INTERVAL_10:
292 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
293 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
294 listView.UpdateList();
298 case SETTING_INTERVAL_20:
301 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
302 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL, inputValue);
303 listView.UpdateList();
307 case SETTING_TRANSITION_PAGE:
310 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
311 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
312 listView.UpdateList();
316 case SETTING_TRANSITION_DISSOLVE:
319 result r = __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
320 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
323 AppLogDebug(" Passed") ;
326 listView.UpdateList();
330 case SETTING_TRANSITION_ZOOM:
333 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
334 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, inputValue);
335 listView.UpdateList();
341 int repeatValue = 0 ;
343 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
344 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
346 if (repeatValue == 0)
355 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
356 ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, inputValue);
360 case SETTING_SHUFFLE:
362 int shuffleValue = 0;
364 __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
365 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffleValue);
367 if (shuffleValue == 0)
376 __pPresentationModel->SetValue(SECTION_NAME_IMAGE_VIEWER,
377 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, inputValue);
387 SettingMainForm::CreateGroupItem(int groupIndex, int itemWidth)
389 GroupItem* pItem = new (std::nothrow) GroupItem();
394 result r = pItem->Construct(Dimension(itemWidth, 46));
405 text = ResourceManager::GetString(L"IDS_MEDIABR_BUTTON_SLIDE_SHOW");
412 pItem->SetElement(text, null);
414 AppLogDebug("background color set result %s", GetErrorMessage(r));
416 pItem->SetTextColor(CUSTOM_COLOR_SETTINGS_GROUPTITLE);
421 SettingMainForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
423 AppLog("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d ", groupIndex, itemIndex,
426 result r = E_SUCCESS;
427 int effectiveIndex = 0;
428 const Color ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_BACKGROUND;
429 const Color ITEM_RADIO_ITEM_BACKGROUND_COLOR = CUSTOM_COLOR_SETTINGS_LISTITEM_RADIO_BACKGROUND;
430 const Color ITEM_BACKGROUND_COLOR_HIGHLIGHTED = CUSTOM_BACKGROUND_COLOR_LISTVIEW_PRESSED_HIGHLIGHTED;
432 effectiveIndex = effectiveIndex + itemIndex;
433 AppLogDebug("SettingMainForm::CreateItem --> groupIndex : %d, itemIndex: %d itemWidth: %d effectiveIndex %d", groupIndex, itemIndex, itemWidth, effectiveIndex);
438 int defaultHeight = 112 ;
439 int defaultFontSize = 44 ;
441 SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
442 AppLog("the font value is %S",fontSizeStr.GetPointer());
444 if(fontSizeStr == "medium")
447 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
449 else if(fontSizeStr == "huge")
452 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
454 else if(fontSizeStr == "giant")
457 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
459 else if(fontSizeStr == "small")
462 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
464 else if(fontSizeStr == "large")
467 itemHeight = defaultHeight + ( fontSize - defaultFontSize);
475 if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_TOGGLE)
477 SettingToggleCustomItem* pItem = new (std::nothrow) SettingToggleCustomItem();
478 r = pItem->Construct(itemWidth, itemHeight);
486 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
487 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
491 __pList->SetItemChecked(groupIndex, itemIndex, settingInfo[effectiveIndex].isSelected);
494 pItem->SetText(settingInfo[effectiveIndex].titleText);
495 pItem->Make(fontSize);
499 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_DROPDOWN)
501 DropDownCustomItem* pItem = new (std::nothrow) DropDownCustomItem();
502 r = pItem->Construct(itemWidth,itemHeight);
509 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_BACKGROUND_COLOR);
510 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
512 pItem->SetMainText(settingInfo[effectiveIndex].titleText);
513 pItem->SetSubText(settingInfo[effectiveIndex].subText);
514 if (settingInfo[effectiveIndex].isOpen)
516 pItem->SetCurState(DROP_DOWN_ITEM_STATE_OPENED);
520 pItem->SetCurState(DROP_DOWN_ITEM_STATE_CLOSED);
523 r = pItem->Make(fontSize,itemHeight);
533 else if (settingInfo[effectiveIndex].itemType == ITEM_TYPE_RADIO)
535 RadioCustomItem* pItem = new (std::nothrow) RadioCustomItem();
538 for (parentIndex = effectiveIndex; parentIndex > SETTING_INVALID; parentIndex--)
540 if (settingInfo[parentIndex].itemType == ITEM_TYPE_DROPDOWN)
544 if (settingInfo[parentIndex].isOpen == false)
546 r = pItem->Construct(itemWidth, 0);
547 AppLogDebug("construct with height 0 %s", GetErrorMessage(r));
552 pItem->Construct(itemWidth, itemHeight);
555 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, ITEM_RADIO_ITEM_BACKGROUND_COLOR);
556 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, ITEM_BACKGROUND_COLOR_HIGHLIGHTED);
558 pItem->SetText(settingInfo[effectiveIndex].titleText);
559 AppLogDebug("effectiveIndex %d SettingInfo[effectiveIndex].isSelected %d", effectiveIndex, settingInfo[effectiveIndex].isSelected);
561 pItem->SetSelected(settingInfo[effectiveIndex].isSelected);
562 pItem->Make(fontSize);
573 SettingMainForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
580 SettingMainForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
587 SettingMainForm::GetGroupCount(void)
595 SettingMainForm::GetItemCount(int groupIndex)
597 AppLog(" SettingMainForm::GetItemCount --> groupIndex : %d,", groupIndex);
598 return pGroupItemCount[groupIndex];
602 SettingMainForm::InitializeSettingValues(void)
604 pGroupItemCount = new (std::nothrow) int[1];
605 pGroupItemCount[0] = 13;
607 int transitionValue = 0;
609 int shuffletValue = 0;
610 String selectedInterval;
611 String selectedTransition;
613 for (int iter = (int) SETTING_INVALID + 1; iter < (int) SETTING_MAX; ++iter)
615 settingInfo[iter].isSelected = false;
618 result r =__pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_INTERVAL,
627 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
628 settingInfo[SETTING_INTERVAL_2].isSelected = true;
634 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
635 settingInfo[SETTING_INTERVAL_3].isSelected = true;
641 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
642 settingInfo[SETTING_INTERVAL_5].isSelected = true;
648 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
649 settingInfo[SETTING_INTERVAL_10].isSelected = true;
655 selectedInterval = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
656 settingInfo[SETTING_INTERVAL_20].isSelected = true;
665 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
666 ENTRY_NAME_IMAGE_VIEWER_SLIDESHOW_TRANSITION_EFFECT, transitionValue);
670 switch (transitionValue)
674 selectedTransition = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
675 settingInfo[SETTING_TRANSITION_PAGE].isSelected = true;
681 selectedTransition = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
682 settingInfo[SETTING_TRANSITION_DISSOLVE].isSelected = true;
688 selectedTransition = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
689 settingInfo[SETTING_TRANSITION_ZOOM].isSelected = true;
698 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SLIDESHOW_INTERVAL");
699 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].subText = selectedInterval ;
700 settingInfo[SETTING_SLIDESHOW_INTERVAL_TITLE].itemType = ITEM_TYPE_DROPDOWN;
702 settingInfo[SETTING_INTERVAL_2].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_2_SECONDS");
703 settingInfo[SETTING_INTERVAL_2].subText = L"";
704 settingInfo[SETTING_INTERVAL_2].itemType = ITEM_TYPE_RADIO;
706 settingInfo[SETTING_INTERVAL_3].titleText = ResourceManager::GetString(L"IDS_MEDIABR_OPT_3_SECONDS");
707 settingInfo[SETTING_INTERVAL_3].subText = L"";
708 settingInfo[SETTING_INTERVAL_3].itemType = ITEM_TYPE_RADIO;
710 settingInfo[SETTING_INTERVAL_5].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_5_SECONDS");
711 settingInfo[SETTING_INTERVAL_5].subText = L"";
712 settingInfo[SETTING_INTERVAL_5].itemType = ITEM_TYPE_RADIO;
714 settingInfo[SETTING_INTERVAL_10].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_10_SECONDS");
715 settingInfo[SETTING_INTERVAL_10].subText = L"";
716 settingInfo[SETTING_INTERVAL_10].itemType = ITEM_TYPE_RADIO;
718 settingInfo[SETTING_INTERVAL_20].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_20_SECONDS");
719 settingInfo[SETTING_INTERVAL_20].subText = L"";
720 settingInfo[SETTING_INTERVAL_20].itemType = ITEM_TYPE_RADIO;
722 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER, ENTRY_NAME_IMAGE_VIEWER_REPEAT_VALUE, repeatValue);
724 settingInfo[SETTING_REPEAT].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_REPEAT");
725 settingInfo[SETTING_REPEAT].itemType = ITEM_TYPE_TOGGLE;
727 if (repeatValue == 0)
729 settingInfo[SETTING_REPEAT].isSelected = false ;
733 settingInfo[SETTING_REPEAT].isSelected = true ;
736 r = __pPresentationModel->GetValue(SECTION_NAME_IMAGE_VIEWER,
737 ENTRY_NAME_IMAGE_VIEWER_SHUFFLE_VALUE, shuffletValue);
739 settingInfo[SETTING_SHUFFLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_SHUFFLE");
740 settingInfo[SETTING_SHUFFLE].itemType = ITEM_TYPE_TOGGLE;
742 if (shuffletValue == 0)
744 settingInfo[SETTING_SHUFFLE].isSelected = false ;
748 settingInfo[SETTING_SHUFFLE].isSelected = true ;
751 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_TRANSITION_EFFECT");
752 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].subText = selectedTransition;
753 settingInfo[SETTING_TRANSITION_EFFECT_TITLE].itemType = ITEM_TYPE_DROPDOWN;
755 settingInfo[SETTING_TRANSITION_PAGE].titleText = ResourceManager::GetString(L"IDS_EBOOK_BODY_PAGE");
756 settingInfo[SETTING_TRANSITION_PAGE].subText = L"";
757 settingInfo[SETTING_TRANSITION_PAGE].itemType = ITEM_TYPE_RADIO;
759 settingInfo[SETTING_TRANSITION_DISSOLVE].titleText = ResourceManager::GetString(L"IDS_MEDIABR_BODY_DISSOLVE");
760 settingInfo[SETTING_TRANSITION_DISSOLVE].subText = L"";
761 settingInfo[SETTING_TRANSITION_DISSOLVE].itemType = ITEM_TYPE_RADIO;
763 settingInfo[SETTING_TRANSITION_ZOOM].titleText = ResourceManager::GetString(L"IDS_IV_OPT_ZOOM");
764 settingInfo[SETTING_TRANSITION_ZOOM].subText = L"";
765 settingInfo[SETTING_TRANSITION_ZOOM].itemType = ITEM_TYPE_RADIO;
768 SettingMainForm::SettingItemInfo::SettingItemInfo(void)
777 SettingMainForm::OnSettingChanged(String& key)
779 AppLogDebug("ENTER");
780 if (key == L"http://tizen.org/setting/font.size")
782 __pList->UpdateList();
784 AppLogDebug("EXIT(%s)", GetErrorMessage(GetLastResult()));