3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.1 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://floralicense.org/license/
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
20 *@file: IntSharePopup.cpp
21 *@brief: Share Popup for sharing bookmark via message, email etc
24 #include <FAppUiApp.h>
29 #include "IntCommonLib.h"
30 #include "IntSharePopup.h"
32 using namespace Tizen::App;
33 using namespace Tizen::Io;
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Base::Runtime;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
43 const int SharePopup::IDA_CANCEL_BUTTON = 101;
44 const int SharePopup::ID_FORMAT_MESSAGE_STRING = 500;
45 const int SharePopup::ID_FORMAT_EMAIL_STRING = 501;
46 const int SharePopup::ID_FORMAT_FACEBOOK_STRING = 502;
47 const int SharePopup::ID_FORMAT_TWITTER_STRING = 503;
49 ShareInfo:: ShareInfo(void)
51 isImageAttached = false;
54 ShareInfo:: ~ShareInfo(void)
59 ShareInfo::SetPageTitle(Tizen::Base::String aPageTitle)
62 __pageTitle.Append(aPageTitle);
66 ShareInfo::SetPageUrl(Tizen::Base::String aPageURL)
69 __pageURL.Append(aPageURL);
73 ShareInfo::GetPageTitle(void)
79 ShareInfo::GetPageURL(void)
85 ShareInfo::SetImageAttached(bool imageAttached)
87 isImageAttached = imageAttached;
91 ShareInfo::GetImageAttached()
93 return isImageAttached;
97 ShareInfo::SetImagePath(Tizen::Base::String aImagePath)
100 __imagePath.Append(aImagePath);
104 ShareInfo::GetImagePath(void)
109 SharePopup::SharePopup(void)
110 :__pList(null),__pShareList(null)
112 __appControlOngoing = false;
116 SharePopup::~SharePopup(void)
118 ShareInfo* pShareInfo = null;
119 result r = E_FAILURE;
121 if (__pShareList != null)
123 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
127 bool imageAttachment = false;
128 if (pShareInfo != null)
130 imageAttachment = pShareInfo->GetImageAttached();
133 attachVal = pShareInfo->GetImagePath();
134 AppLog("SharePopup:: imagePath is %S",attachVal.GetPointer());
135 r = File::Remove(attachVal);
138 AppLog("removed success");
142 AppLog("removed failure");
145 __pShareList->RemoveAll(true);
151 SharePopup::Initialize(void)
153 Button* pCancelButton = null;
155 Popup::Construct(L"IDL_SHARE_POPUP");
156 SetName(L"CommonPopup");
158 __pShareList = new(std::nothrow) ArrayList();
159 __pShareList->Construct();
161 __pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW"));
167 __pList->SetItemProvider(*this);
168 __pList->AddListViewItemEventListener(*this);
170 pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON1", true));
173 pCancelButton->AddActionEventListener(*this);
174 pCancelButton->SetActionId(IDA_CANCEL_BUTTON);
177 __pTimer = new(std::nothrow) Timer();
178 __pTimer->Construct(*this);
179 SetPropagatedKeyEventListener(this);
184 SharePopup::OnTerminating(void)
186 result r = E_SUCCESS;
191 SharePopup::OnTimerExpired(Timer& timer)
193 Popup::SetShowState(false);
198 SharePopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
202 case IDA_CANCEL_BUTTON:
204 Popup::SetShowState(false);
215 SharePopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
221 SharePopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
227 if(__appControlOngoing == false)
229 __appControlOngoing = true;
231 StartMessageAppControl();
234 __pTimer = new(std::nothrow) Timer();
235 __pTimer->Construct(*this);
237 __pTimer->Start(2500);
243 if(__appControlOngoing == false)
245 __appControlOngoing = true;
247 StartEmailAppControl();
250 __pTimer = new(std::nothrow) Timer();
251 __pTimer->Construct(*this);
253 __pTimer->Start(2500);
261 Frame* pCurrentFrame = null;
262 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
264 if (pCurrentFrame != null)
265 { pCurrentFrame->SetEnabled(false); }
269 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
275 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
280 Tizen::Ui::Controls::ListItemBase*
281 SharePopup::CreateItem(int index, int itemWidth)
283 result r = E_FAILURE;
284 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
286 int elementHeight = 50;
287 int listItemHeight = 75;
289 CustomItem* pItem = new(std::nothrow) CustomItem();
290 r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemHeight), style);
293 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
302 AppLogDebug("SharePopUp CreateItem 0");
303 // IDS_SHARE_VIA_MESSAGE
304 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING, CommonUtil::GetString(L"IDS_BR_OPT_MESSAGES"), true);
309 AppLogDebug("SharePopUp CreateItem 1");
310 // IDS_SHARE_VIA_EMAIL
311 pItem->AddElement(Rectangle(45, 0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_EMAIL_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SENDURLVIA_EMAIL"), true);
321 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
327 SharePopup::GetItemCount(void)
333 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
335 result r = E_FAILURE;
337 if (__pShareList != NULL)
339 r = __pShareList->Add(*pShareInfo);
344 void SharePopup::RemoveAllShareInfo()
346 __pShareList->RemoveAll();
350 SharePopup::StartEmailAppControl(void)
353 ShareInfo* pShareInfo = null;
354 result r = E_FAILURE;
355 bool imageAttachment = false;
357 extraData.Construct();
359 if (__pShareList != null)
361 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
362 if (pShareInfo != null)
364 String testURL = pShareInfo->GetPageURL();
365 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
371 if (pShareInfo != null)
373 textVal.Append(pShareInfo->GetPageTitle());
374 textVal.Append(L" <");
375 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
376 textVal.Append(pShareInfo->GetPageURL().GetPointer());
377 textVal.Append(L">");
380 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
381 String subjectVal = L"";
382 String textKey = L"http://tizen.org/appcontrol/data/text";
384 String toKey = L"http://tizen.org/appcontrol/data/to";
386 String ccKey = L"http://tizen.org/appcontrol/data/cc";
388 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
390 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
391 String resultVal = "true";
394 //String attachKey = L"attachments";
395 String attachKey = L"http://tizen.org/appcontrol/data/path";
397 if (pShareInfo != null)
399 imageAttachment = pShareInfo->GetImageAttached();
402 attachVal = pShareInfo->GetImagePath();
403 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
411 ArrayList* pDataList = null;
412 pDataList = new (std::nothrow) ArrayList();
413 pDataList->Construct();
414 pDataList->Add(&attachVal);
416 extraData.Add(&subjectKey, &subjectVal);
417 extraData.Add(&textKey, &textVal);
418 extraData.Add(&toKey, &toVal);
419 extraData.Add(&ccKey, &ccVal);
420 extraData.Add(&bccKey, &bccVal);
421 extraData.Add(&resultKey, &resultVal);
422 if(attachVal.GetLength() > 0)
424 extraData.Add(&attachKey, pDataList);
427 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
430 r = pAc->Start(null, null, &extraData, this);
438 SharePopup::StartMessageAppControl(void)
441 ShareInfo* pShareInfo = null;
442 result r = E_FAILURE;
443 bool imageAttachment = false;
445 extraData.Construct();
447 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
449 String textKey = L"http://tizen.org/appcontrol/data/text";
451 String attachKey = L"http://tizen.org/appcontrol/data/path";
453 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
454 String resultVal = "true";
455 ArrayList* pDataList = null;
457 if (__pShareList != null)
459 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
460 if (pShareInfo != null)
462 String testURL = pShareInfo->GetPageURL();
463 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
467 if (pShareInfo != null)
469 textVal.Append(pShareInfo->GetPageTitle());
470 if(pShareInfo->GetPageTitle().GetLength() > 0)
472 textVal.Append(L" <");
476 textVal.Append(L"<");
478 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
479 textVal.Append(pShareInfo->GetPageURL().GetPointer());
480 textVal.Append(L">");
482 if (pShareInfo != null)
484 imageAttachment = pShareInfo->GetImageAttached();
489 attachVal = pShareInfo->GetImagePath();
491 pDataList = new (std::nothrow) ArrayList();
492 pDataList->Construct();
493 pDataList->Add(&attachVal);
502 extraData.Add(&typeKey, &typeVal);
506 // type is MMMS, attach the image
507 extraData.Add(&attachKey, pDataList);
511 // type is SMS , attach the text
512 extraData.Add(&textKey, &textVal);
514 extraData.Add(&resultKey, &resultVal);
515 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
518 r = pAc->Start(null, null, &extraData, this);
529 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
531 AppLog("InternetApp::OnForeground called");
535 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
537 AppLog("SharePopup::OnAppControlCompleteResponseReceived");
539 ShareInfo* pShareInfo = null;
540 result r = E_FAILURE;
547 if (__pShareList != null)
549 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
553 bool imageAttachment = false;
554 if (pShareInfo != null)
556 imageAttachment = pShareInfo->GetImageAttached();
559 attachVal = pShareInfo->GetImagePath();
560 AppLog("SharePopup:: imagePath is %S",attachVal.GetPointer());
561 r = File::Remove(attachVal);
564 AppLog("removed success");
568 AppLog("removed failure");
571 __pShareList->RemoveAll(true);
573 Popup::SetShowState(false);
575 Frame* pCurrentFrame = null;
576 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
578 if (pCurrentFrame != null)
579 { pCurrentFrame->SetEnabled(true); }
580 __appControlOngoing = false;
584 SharePopup::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
586 AppLog("ConfirmationPopup::OnKeyReleased %d",keyEventInfo.GetKeyCode());
587 if(keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
589 if(GetShowState() == true)