2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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 MpSettingForm.cpp
19 * @brief This is the implementation file for SettingForm class.
25 #include <FUiScenes.h>
26 #include "MpAllListPresentationModel.h"
27 #include "MpNowPlayContentPanel.h"
28 #include "MpSceneRegister.h"
29 #include "MpSettingForm.h"
30 #include "MpSettingPresentationModel.h"
33 using namespace Tizen::App;
34 using namespace Tizen::Base;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
40 static const int SETTING_ITEM_HEIGHT = 112;
42 static const int ID_MAIN_DEFAULT_PLAYLIST_ITEM = 1;
43 static const int ID_SUB_MOST_PLAYED_ITEM = 0;
44 static const int ID_SUB_RECENTLY_PLAYED_ITEM = 1;
45 static const int ID_SUB_RECENTLY_ADD_ITEM = 2;
47 static const int ID_MAIN_AUTO_OFF_ITEM = 0;
48 static const int ID_SUB_ZERO_ITEM = 0;
49 static const int ID_SUB_FIFTEEN_ITEM = 1;
50 static const int ID_SUB_THIRTY_ITEM = 2;
51 static const int ID_SUB_ONE_HOUR_ITEM = 3;
52 static const int ID_SUB_ONE_HOUR_THIRTY_ITEM = 4;
53 static const int ID_SUB_TWO_HOURS_ITEM = 5;
55 static const int ID_MAIN_DEFAULT_PLAYLIST_ITEM_COUNT = 3;
56 static const int ID_MAIN_AUTO_OFF_ITEM_COUNT = 6;
58 SettingForm::SettingForm(void)
59 : __pSettingPresentationModel(null)
60 , __pSettingTableView(null)
66 SettingForm::~SettingForm(void)
73 SettingForm::Initialize(void)
76 Construct(IDL_SETTING_FORM);
81 SettingForm::OnInitializing(void)
86 Footer* pFooter = null;
87 pFooter = GetFooter();
88 pFooter->AddActionEventListener(*this);
89 SetFormBackEventListener(this);
91 __pSettingTableView = static_cast<GroupedTableView*>(GetControl(IDC_GROUPEDTABLEVIEW_CONTENT_LIST));
92 __pSettingTableView->SetItemProvider(this);
93 __pSettingTableView->AddGroupedTableViewItemEventListener(*this);
95 __pSettingPresentationModel = SettingPresentationModel::GetInstance();
96 __pSettingPresentationModel->InitializeSettingValue();
97 __pPresentationModel = AllListPresentationModel::GetInstance();
98 __pSettingTableView->UpdateTableView();
99 __pSettingTableView->CollapseAllGroup();
100 // for (int itemIndex = 0; itemIndex < ID_MAIN_DEFAULT_PLAYLIST_ITEM_COUNT; itemIndex++)
102 // __pSettingTableView->SetItemChecked(0, itemIndex, __pSettingPresentationModel->IsTabEnable(itemIndex));
104 __pSettingTableView->SetItemChecked(ID_MAIN_AUTO_OFF_ITEM, __pSettingPresentationModel->GetAutoOffTime(), true);
112 SettingForm::OnTerminating(void)
114 AppLogDebug("ENTER");
115 result r = E_SUCCESS;
117 /*Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
118 Form* pForm = static_cast<Form*>(pFrame->GetControl(CONTENT_FORM_REQUSEST_ID));
121 AppLogDebug("AForm");
122 pForm->SendUserEvent(0, null);
124 // __pSettingPresentationModel->DestroySettingPresentationModel();
131 SettingForm::GetGroupCount(void)
133 AppLogDebug("ENTER");
139 SettingForm::GetItemCount(int groupIndex)
141 AppLogDebug("ENTER");
146 case ID_MAIN_DEFAULT_PLAYLIST_ITEM:
148 itemCount = ID_MAIN_DEFAULT_PLAYLIST_ITEM_COUNT;
152 case ID_MAIN_AUTO_OFF_ITEM:
154 itemCount = ID_MAIN_AUTO_OFF_ITEM_COUNT;
165 Tizen::Ui::Controls::TableViewGroupItem*
166 SettingForm::CreateGroupItem(int groupIndex, int itemWidth)
168 AppLogDebug("ENTER %d", groupIndex);
169 RelativeLayout layout;
172 TableViewGroupItem* pItem = new (std::nothrow) TableViewGroupItem();
173 pItem->Construct(layout, Dimension(itemWidth, SETTING_ITEM_HEIGHT));
174 Panel* pGroupTableViewItem = new (std::nothrow) Panel();
177 case ID_MAIN_DEFAULT_PLAYLIST_ITEM:
179 if (IsFailed(pGroupTableViewItem->Construct(IDL_SETTING_PLAYLIST_SET_ITEM_PANEL)))
181 AppLogDebug("Construct(IDL_SETTING_PLAYLIST_SET_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
182 delete pGroupTableViewItem;
189 case ID_MAIN_AUTO_OFF_ITEM:
191 if (IsFailed(pGroupTableViewItem->Construct(IDL_SETTING_OFF_SET_ITEM_PANEL)))
193 AppLogDebug("Construct(IDL_SETTING_PLAYLIST_SET_ITEM_PANEL) failed(%s)", GetErrorMessage(GetLastResult()));
194 delete pGroupTableViewItem;
198 Label* pSubText = static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_SUB_TEXT));
199 pSubText->SetText(GetAutoOffString());
207 pItem->AddControl(*pGroupTableViewItem);
208 pItem->SetIndividualSelectionEnabled(pGroupTableViewItem, true);
209 CommonUtil::SetLayoutFitToContainer(*pItem, *pGroupTableViewItem);
216 SettingForm::DeleteGroupItem(int groupIndex, TableViewGroupItem* pItem)
218 AppLogDebug("ENTER");
224 Tizen::Ui::Controls::TableViewItem*
225 SettingForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
227 AppLogDebug("ENTER");
228 RelativeLayout layout;
231 TableViewItem* pItem = new (std::nothrow) TableViewItem();
232 Panel* pGroupTableViewItem = new (std::nothrow) Panel();
234 result r = pGroupTableViewItem->Construct(IDL_GROUPEDTABLEVIEW_ITEM_PANEL);
235 TryCatch(r == E_SUCCESS, delete pItem, "pGroupTableViewItem->Construct(%s)", GetErrorMessage(r));
237 if (groupIndex == ID_MAIN_DEFAULT_PLAYLIST_ITEM)
239 r = pItem->Construct(layout, Tizen::Graphics::Dimension(W_CLIENT_AREA, SETTING_ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_MARK);
240 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
242 Label* pMainText = static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_MAIN_TEXT));
246 case ID_SUB_MOST_PLAYED_ITEM:
248 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_MOST_PLAYED"));
252 case ID_SUB_RECENTLY_PLAYED_ITEM:
254 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_PLAYLIST_RECENTLY_PLAYED"));
258 case ID_SUB_RECENTLY_ADD_ITEM:
260 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_RECENTLY_ADDED"));
270 r = pItem->Construct(layout, Tizen::Graphics::Dimension(W_CLIENT_AREA, SETTING_ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_RADIO);
271 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
273 Label* pMainText = static_cast<Label*>(pGroupTableViewItem->GetControl(IDC_LABEL_MAIN_TEXT));
277 case ID_SUB_ZERO_ITEM:
279 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_NOT_USED"));
283 case ID_SUB_FIFTEEN_ITEM:
285 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_OPT_AFTER_15_MIN_ABB"));
289 case ID_SUB_THIRTY_ITEM:
291 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_30_MIN"));
295 case ID_SUB_ONE_HOUR_ITEM:
297 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_1_HOUR"));
301 case ID_SUB_ONE_HOUR_THIRTY_ITEM:
303 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_POP_AFTER_1_HOUR_30_MIN"));
307 case ID_SUB_TWO_HOURS_ITEM:
309 pMainText->SetText(ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_2_HOURS"));
318 pItem->AddControl(*pGroupTableViewItem);
319 pItem->SetIndividualSelectionEnabled(pGroupTableViewItem, true);
320 CommonUtil::SetLayoutFitToContainer(*pItem, *pGroupTableViewItem);
326 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
327 delete pGroupTableViewItem;
332 SettingForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
334 AppLogDebug("ENTER");
339 SettingForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
341 AppLogDebug("ENTER");
342 if (groupIndex == ID_MAIN_AUTO_OFF_ITEM)
344 Label* pLabelSubtext = static_cast<Label*>(pItem->GetControl(IDC_LABEL_SUB_TEXT, true));
345 pLabelSubtext->SetText(GetAutoOffString());
346 pLabelSubtext->Invalidate(false);
348 __pSettingTableView->Invalidate(true);
353 SettingForm::GetDefaultItemHeight(void)
355 AppLogDebug("ENTER");
357 return SETTING_ITEM_HEIGHT;
361 SettingForm::GetDefaultGroupItemHeight(void)
363 AppLogDebug("ENTER");
365 return SETTING_ITEM_HEIGHT;
369 SettingForm::DeleteItem(int groupIndex, int itemIndex, TableViewItem* pItem)
371 AppLogDebug("ENTER");
378 SettingForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
380 AppLogDebug("ENTER");
381 if (tableView.IsGroupExpanded(groupIndex) == true)
383 Label* pLabel = static_cast<Label*>(pItem->GetControl(IDC_LABEL_EX, true));
384 Bitmap* pBitmap = ResourceManager::GetBitmapN(L"00_button_expand_closed.png");
385 pLabel->SetBackgroundBitmap(*pBitmap);
386 pLabel->Invalidate(false);
389 if (groupIndex == ID_MAIN_AUTO_OFF_ITEM)
391 Label* pLabelSubtext = static_cast<Label*>(pItem->GetControl(IDC_LABEL_SUB_TEXT, true));
392 pLabelSubtext->SetText(GetAutoOffString());
393 pLabelSubtext->Invalidate(false);
396 AppLogDebug("CollapseGroup %d",groupIndex);
397 tableView.CollapseGroup(groupIndex);
401 Label* pLabel = static_cast<Label*>(pItem->GetControl(IDC_LABEL_EX, true));
402 Bitmap* pBitmap = ResourceManager::GetBitmapN(L"00_button_expand_opened.png");
403 pLabel->SetBackgroundBitmap(*pBitmap);
404 pLabel->Invalidate(false);
407 AppLogDebug("ExpandGroup %d",groupIndex);
408 tableView.ExpandGroup(groupIndex);
414 SettingForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
416 AppLogDebug("ENTER");
417 bool isChecked = false;
420 case ID_MAIN_DEFAULT_PLAYLIST_ITEM:
422 if (status == TABLE_VIEW_ITEM_STATUS_CHECKED)
426 __pSettingPresentationModel->SetTabEnable(itemIndex, isChecked);
427 Frame* pFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
428 Form* pForm = static_cast<Form*>(pFrame->GetControl(CONTENT_FORM_REQUSEST_ID));
431 AppLogDebug("AForm");
432 pForm->SendUserEvent(0, null);
437 case ID_MAIN_AUTO_OFF_ITEM:
439 for (int i = 0; i < __pSettingTableView->GetItemCountAt(ID_MAIN_AUTO_OFF_ITEM); i++)
443 AppLogDebug("true : %d", i);
444 __pSettingTableView->SetItemChecked(groupIndex, i, true);
448 AppLogDebug("false : %d", i);
449 __pSettingTableView->SetItemChecked(groupIndex, i, false);
452 __pPresentationModel->StartAutoOffTimer(__pSettingPresentationModel->SetAutoOffTime(itemIndex));
453 tableView.RefreshItem(groupIndex, -1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
464 SettingForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView& tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
466 AppLogDebug("ENTER");
471 SettingForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
473 AppLogDebug("ENTER");
478 SettingForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
480 AppLogDebug("ENTER");
481 SceneManager* pSceneManager = SceneManager::GetInstance();
482 AppAssert(pSceneManager);
483 result r = pSceneManager->GoBackward(BackwardSceneTransition());
486 __pSettingPresentationModel->DestroySettingPresentationModel();
487 UiApp* pApp = UiApp::GetInstance();
494 SettingForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
495 const Tizen::Ui::Scenes::SceneId& currentSceneId,
496 Tizen::Base::Collection::IList* pArgs)
498 AppLogDebug("ENTER");
499 SceneManager* pSceneManager = SceneManager::GetInstance();
500 AppAssert(pSceneManager);
502 CommonUtil::SetSimpleTitleStyle(*GetHeader(), ResourceManager::GetString(L"IDS_MUSIC_BODY_MUSIC_SETTINGS"));
506 pArgs->RemoveAll(true);
513 SettingForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
514 const Tizen::Ui::Scenes::SceneId& nextSceneId)
516 AppLogDebug("ENTER");
521 SettingForm::GetAutoOffString(void)
523 AppLogDebug("ENTER");
524 switch (__pSettingPresentationModel->GetAutoOffTime())
526 case ID_SUB_ZERO_ITEM:
528 return ResourceManager::GetString(L"IDS_MUSIC_BODY_NOT_USED");
532 case ID_SUB_FIFTEEN_ITEM:
534 return ResourceManager::GetString(L"IDS_MUSIC_OPT_AFTER_15_MIN_ABB");
538 case ID_SUB_THIRTY_ITEM:
540 return ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_30_MIN");
544 case ID_SUB_ONE_HOUR_ITEM:
546 return ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_1_HOUR");
550 case ID_SUB_ONE_HOUR_THIRTY_ITEM:
552 return ResourceManager::GetString(L"IDS_MUSIC_POP_AFTER_1_HOUR_30_MIN");
556 case ID_SUB_TWO_HOURS_ITEM:
558 return ResourceManager::GetString(L"IDS_MUSIC_BODY_AFTER_2_HOURS");
567 return ResourceManager::GetString(L"IDS_MUSIC_BODY_NOT_USED");