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 MpSetAsPopup.cpp
19 * @brief This is the implementation file for SetAsPopup class.
23 #include <FSclAddressbook.h>
24 #include <FSclAddressbookManager.h>
25 #include <FSclContact.h>
26 #include <FSysSettingInfo.h>
27 #include "MpMusicPlayerApp.h"
28 #include "MpResourceManager.h"
29 #include "MpSetAsPopup.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Social;
38 using namespace Tizen::System;
39 using namespace Tizen::Ui;
40 using namespace Tizen::Ui::Controls;
41 using namespace Tizen::Ui::Scenes;
45 SET_AS_CALL_RINGTONE = 0,
46 SET_AS_CALLER_RINGTONE,
50 SetAsPopup::SetAsPopup(void)
51 : __pSetAsItemTableView(null)
52 , __pCancelButton(null)
59 SetAsPopup::~SetAsPopup(void)
66 SetAsPopup::Initialize(Tizen::Ui::Control* pControl)
70 r = Construct(IDL_SET_AS_POPUP);
71 TryCatch(r == E_SUCCESS, r = E_OUT_OF_MEMORY, "Unable to construct popup.\n");
72 SetTitleText(ResourceManager::GetString("IDS_COM_SK_SET_AS"));
73 AddTouchEventListener(*this);
74 SetPropagatedKeyEventListener(this);
75 __pSetAsItemTableView = static_cast<TableView*>(GetControl(IDC_TABLEVIEW));
76 TryCatch(__pSetAsItemTableView != null, r = E_OUT_OF_MEMORY, "Unable to construct table view.\n");
77 __pSetAsItemTableView->AddTableViewItemEventListener(*this);
78 __pSetAsItemTableView->SetItemProvider(this);
80 __pCancelButton = static_cast<Button*>(GetControl(IDC_CANCEL_BUTTON));
81 TryCatch(__pCancelButton != null, r = E_OUT_OF_MEMORY, "Unable to construct cancel button.\n");
82 __pCancelButton->SetActionId(IDA_BUTTON_CANCEL);
83 __pCancelButton->AddActionEventListener(*this);
85 __pControl = pControl;
91 //AppLogException("[%ls]", GetErrorMessage(r));
92 if (__pCancelButton != null)
94 delete __pCancelButton;
95 __pCancelButton = null;
97 if ( __pSetAsItemTableView != null)
99 delete __pSetAsItemTableView;
100 __pSetAsItemTableView = null;
106 SetAsPopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
108 AppLogDebug("ENTER");
109 if (actionId == IDA_BUTTON_CANCEL)
118 SetAsPopup::OnTouchDoublePressed(const Tizen::Ui::Control& source,
119 const Tizen::Graphics::Point& currentPosition,
120 const Tizen::Ui::TouchEventInfo& touchInfo)
122 AppLogDebug("ENTER");
127 SetAsPopup::OnTouchLongPressed(const Tizen::Ui::Control& source,
128 const Tizen::Graphics::Point& currentPosition,
129 const Tizen::Ui::TouchEventInfo& touchInfo)
131 AppLogDebug("ENTER");
136 SetAsPopup::OnTouchFocusIn(const Tizen::Ui::Control& source,
137 const Tizen::Graphics::Point& currentPosition,
138 const Tizen::Ui::TouchEventInfo& touchInfo)
140 AppLogDebug("ENTER");
145 SetAsPopup::OnTouchFocusOut(const Tizen::Ui::Control& source,
146 const Tizen::Graphics::Point& currentPosition,
147 const Tizen::Ui::TouchEventInfo& touchInfo)
149 AppLogDebug("ENTER");
154 SetAsPopup::OnTouchMoved(const Tizen::Ui::Control& source,
155 const Tizen::Graphics::Point& currentPosition,
156 const Tizen::Ui::TouchEventInfo& touchInfo)
158 AppLogDebug("ENTER");
163 SetAsPopup::OnTouchPressed(const Tizen::Ui::Control& source,
164 const Tizen::Graphics::Point& currentPosition,
165 const Tizen::Ui::TouchEventInfo& touchInfo)
167 AppLogDebug("ENTER");
169 && (currentPosition.x < 0
170 || currentPosition.y < 0
171 || this->GetBounds().width
172 || this->GetBounds().height))
174 // SetShowState(false);
181 SetAsPopup::OnTouchReleased(const Tizen::Ui::Control& source,
182 const Tizen::Graphics::Point& currentPosition,
183 const Tizen::Ui::TouchEventInfo& touchInfo)
185 AppLogDebug("ENTER");
190 SetAsPopup::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
192 AppLogDebug("ENTER");
193 if (KEY_BACK == keyEventInfo.GetKeyCode() || KEY_ESC == keyEventInfo.GetKeyCode())
202 SetAsPopup::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
204 AppLogDebug("ENTER");
205 if (KEY_BACK == keyEventInfo.GetKeyCode() || KEY_ESC == keyEventInfo.GetKeyCode())
218 SetAsPopup::GetItemCount(void)
220 AppLogDebug("ENTER");
225 Tizen::Ui::Controls::TableViewItem*
226 SetAsPopup::CreateItem(const int itemIndex, int itemWidth)
228 AppLogDebug("ENTER");
229 RelativeLayout layout;
232 TableViewItem* pItem = new (std::nothrow) TableViewItem();
234 result r = pItem->Construct(Dimension(itemWidth, ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_NORMAL);
235 TryCatch(r == E_SUCCESS, delete pItem, "pItem->Construct(%s)", GetErrorMessage(r));
237 if (itemIndex < SET_AS_END)
239 String labelName = L"";
242 case SET_AS_CALL_RINGTONE:
244 labelName = ResourceManager::GetString(L"IDS_MUSIC_OPT_CALL_RINGTONE");
248 case SET_AS_CALLER_RINGTONE:
250 labelName = ResourceManager::GetString(L"IDS_MUSIC_OPT_SETAS_CALLER_RINGTONE");
258 r = CreateTableViewItem(*pItem, labelName);
259 TryCatch(r == E_SUCCESS, delete pItem, "CreateTableViewItem failed(%s)", GetErrorMessage(r));
266 AppLogDebug("EXIT(%ls)", GetErrorMessage(GetLastResult()));
271 SetAsPopup::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
273 AppLogDebug("ENTER");
279 SetAsPopup::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
281 AppLogDebug("ENTER");
286 SetAsPopup::GetDefaultItemHeight(void)
288 AppLogDebug("ENTER");
294 SetAsPopup::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
296 Tizen::Ui::Controls::TableViewItem* pItem,
297 Tizen::Ui::Controls::TableViewItemStatus status)
299 AppLogDebug("ENTER");
300 result r = E_FAILURE;
303 result r = Tizen::System::SettingInfo::SetValue(CALL_RINGTONE_KEY, *__pCurrentContentPath);
309 MessageBox messageBox;
310 messageBox.Construct(L"", ResourceManager::GetString(L"IDS_COM_POP_SUCCESS"),
314 messageBox.ShowAndWait(modalResult);
319 AppControl* pAppControl = AppManager::FindAppControlN(PROVIDER_ID_CONTACT, OPERATION_ID_SOCIAL_PICK);
320 if (pAppControl == null)
325 HashMap* pDataList = new (std::nothrow) HashMap(SingleObjectDeleter);
326 pDataList->Construct();
327 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SELECTION_MODE), new (std::nothrow) String(APPCONTROL_OPTION_SINGLE));
328 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_ITEM_TYPE), new (std::nothrow) String(APPCONTROL_OPTION_PERSON));
329 pDataList->Add(new (std::nothrow) String(APPCONTROL_KEY_SOCIAL_RESULT_TYPE), new (std::nothrow) String(APPCONTROL_OPTION_ITEM_ID));
331 // Tizen::Base::Collection::ArrayList* pData = new (std::nothrow) Tizen::Base::Collection::ArrayList();
332 // pData->Construct();
333 // pData->Add(*(new (std::nothrow) String(SELECTION_MODE)));
334 // pData->Add(*(new (std::nothrow) String(RETURN_TYPE)));
336 r = pAppControl->Start(null, null, pDataList, this);
339 Frame* pFrame = MusicPlayerApp::GetInstance()->GetFrameAt(0);
341 pFrame->SetEnabled(false);
345 AppLogDebug("AppControl Start fail");
350 pDataList->RemoveAll(true);
359 SetAsPopup::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView,
361 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
364 AppLogDebug("ENTER");
369 SetAsPopup::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
373 AppLogDebug("ENTER");
378 SetAsPopup::CreateTableViewItem(Tizen::Ui::Container& parent,
379 Tizen::Base::String& labelName)
381 AppLogDebug("ENTER");
382 result r = E_SUCCESS;
384 Label* pStrLabel = new (std::nothrow) Label();
385 if (pStrLabel == null)
387 return E_INIT_FAILED;
390 r = pStrLabel->Construct(Rectangle(0, 0, POPUP_ITEM_WIDTH, ITEM_HEIGHT), L"");
393 return E_INIT_FAILED;
396 pStrLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
397 pStrLabel->SetTextConfig(32, LABEL_TEXT_STYLE_NORMAL);
398 pStrLabel->SetText(labelName);
400 parent.AddControl(pStrLabel);
407 SetAsPopup::OnAppControlCompleteResponseReceived(const AppId& appId,
408 const String& operationId, AppCtrlResult appControlResult,
409 const IMap* pExtraData)
411 AppLogDebug("ENTER");
412 if (pExtraData == null)
418 AppLogDebug("%ls, %ls", appId.GetPointer(), operationId.GetPointer());
419 if (appId.Equals(String(PROVIDER_ID_CONTACT))/* && operationId.Equals(String(OPERATION_ID_PICK))*/)
421 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
426 ArrayList* pArrayListValue = null;
427 String* pResultString = null;
428 result r = E_SUCCESS;
429 if (pExtraData != null)
431 IMapEnumerator* pEnum = pExtraData->GetMapEnumeratorN();
432 while (pEnum->MoveNext() == E_SUCCESS)
434 pKey = static_cast<String*>(pEnum->GetKey());
435 if (pKey->Equals(APPCONTROL_KEY_SOCIAL_ITEM_ID, true))
437 pArrayListValue = static_cast<ArrayList*>(pEnum->GetValue());
442 if (pArrayListValue != null && pArrayListValue->GetCount() > 0)
444 for (int iCount = 0; iCount < pArrayListValue->GetCount(); iCount++)
446 pResultString = static_cast<String*>(pArrayListValue->GetAt(iCount));
447 AppLogDebug("extraData : %ls:%ls total contacts %d", pKey->GetPointer(), pResultString->GetPointer(),pArrayListValue->GetCount());
448 Integer::Parse(*pResultString, contactId);
449 pResultString->Clear();
452 AppLogDebug("pKey is invaild");
456 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
457 Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
459 Contact* pContact = pAddressbook->GetContactN(contactId);
460 pContact->SetValue(CONTACT_PROPERTY_ID_RINGTONE, *__pCurrentContentPath);
461 r = pAddressbook->UpdateContact(*pContact);
474 AppLogDebug("pExtraData is null");
480 SceneManager* pSceneManager = SceneManager::GetInstance();
481 if (pSceneManager != null)
483 pSceneManager->GetCurrentScene()->GetForm()->SendUserEvent(ID_SHOW_SUCCESS_MESSAGE,null);
493 SetAsPopup::SetCurrentContentPath(Tizen::Base::String* contentPath)
495 AppLogDebug("ENTER");
496 __pCurrentContentPath = contentPath;