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);
148 if(__pAppControlList)
149 __pAppControlList->RemoveAll(true);
150 delete __pAppControlList;
154 SharePopup::Initialize(void)
156 Button* pCancelButton = null;
158 Popup::Construct(L"IDL_SHARE_POPUP");
159 SetName(L"CommonPopup");
161 __pShareList = new(std::nothrow) ArrayList();
162 __pShareList->Construct();
164 __pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW"));
170 __pList->SetItemProvider(*this);
171 __pList->AddListViewItemEventListener(*this);
172 // __pList->SetTextOfEmptyList(L"No Sharing Options");//hardcoded string
174 pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON1", true));
177 pCancelButton->AddActionEventListener(*this);
178 pCancelButton->SetActionId(IDA_CANCEL_BUTTON);
181 __pTimer = new(std::nothrow) Timer();
182 __pTimer->Construct(*this);
183 SetPropagatedKeyEventListener(this);
188 SharePopup::OnTerminating(void)
190 result r = E_SUCCESS;
195 SharePopup::OnTimerExpired(Timer& timer)
197 Popup::SetShowState(false);
202 SharePopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
206 case IDA_CANCEL_BUTTON:
208 Popup::SetShowState(false);
219 SharePopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
225 SharePopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
231 if(__appControlOngoing == false)
233 __appControlOngoing = true;
235 StartMessageAppControl();
238 __pTimer = new(std::nothrow) Timer();
239 __pTimer->Construct(*this);
241 __pTimer->Start(2500);
247 if(__appControlOngoing == false)
249 __appControlOngoing = true;
251 StartEmailAppControl();
254 __pTimer = new(std::nothrow) Timer();
255 __pTimer->Construct(*this);
257 __pTimer->Start(2500);
263 if(__appControlOngoing == false)
265 __appControlOngoing = true;
266 //share via third party app
267 StartAppControl(index);
270 __pTimer = new(std::nothrow) Timer();
271 __pTimer->Construct(*this);
273 __pTimer->Start(2500);
277 Frame* pCurrentFrame = null;
278 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
280 if (pCurrentFrame != null)
282 pCurrentFrame->SetEnabled(false);
287 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
293 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
298 Tizen::Ui::Controls::ListItemBase*
299 SharePopup::CreateItem(int index, int itemWidth)
301 AppLog("SharePopup::CreateItem index %d",index);
302 result r = E_FAILURE;
303 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
305 int elementHeight = 50;
306 int listItemHeight = 75;
308 CustomItem* pItem = new(std::nothrow) CustomItem();
309 r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemHeight), style);
312 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
323 AppLogDebug("SharePopUp CreateItem 0");
324 // IDS_SHARE_VIA_MESSAGE
325 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING, CommonUtil::GetString(L"IDS_BR_OPT_MESSAGES"), true);
330 AppLogDebug("SharePopUp CreateItem 1");
331 // IDS_SHARE_VIA_EMAIL
332 pItem->AddElement(Rectangle(45, 0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_EMAIL_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SENDURLVIA_EMAIL"), true);
336 if(__pAppControlList)
338 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(index -2));
339 AppLog("SharePopup::CreateItem appcontrol count %d",__pAppControlList->GetCount());
341 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING+index, pControl->GetAppName(), true);
349 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
355 SharePopup::GetItemCount(void)
357 String* pStrId = new String(L"http://tizen.org/appcontrol/operation/share_text");
358 __pAppControlList = AppManager::FindAppControlsN(pStrId,null,null,null);
359 if(__pAppControlList == null)
363 int count = __pAppControlList->GetCount();
364 AppLog("SharePopup::GetItemCount appcontrol count %d",count);
366 for(int pos = 0; pos < count; pos++)
368 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(pos));
369 if(pControl->GetAppName().Equals(L"Messages",false) == true || pControl->GetAppName().Equals(L"Email",false) == true )
371 __pAppControlList->RemoveAt(pos,true);
378 AppLog("removeCount %d",removeCount);
379 return count+removeCount;
384 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
386 result r = E_FAILURE;
388 if (__pShareList != NULL)
390 r = __pShareList->Add(*pShareInfo);
395 void SharePopup::RemoveAllShareInfo()
397 __pShareList->RemoveAll();
404 SharePopup::StartAppControl(int index)
407 ShareInfo* pShareInfo = null;
408 result r = E_FAILURE;
409 bool imageAttachment = false;
411 extraData.Construct();
413 if (__pShareList != null)
415 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
416 if (pShareInfo != null)
418 String testURL = pShareInfo->GetPageURL();
419 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
425 if (pShareInfo != null)
427 textVal.Append(pShareInfo->GetPageTitle());
428 textVal.Append(L" <");
429 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
430 textVal.Append(pShareInfo->GetPageURL().GetPointer());
431 textVal.Append(L">");
435 String textKey = L"http://tizen.org/appcontrol/data/text";
437 //String attachKey = L"attachments";
438 String attachKey = L"http://tizen.org/appcontrol/data/path";
440 if (pShareInfo != null)
442 imageAttachment = pShareInfo->GetImageAttached();
445 attachVal = pShareInfo->GetImagePath();
446 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
454 ArrayList* pDataList = null;
455 pDataList = new (std::nothrow) ArrayList();
456 pDataList->Construct();
457 pDataList->Add(&attachVal);
460 extraData.Add(&textKey, &textVal);
462 if(attachVal.GetLength() > 0)
464 extraData.Add(&attachKey, pDataList);
467 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(index - 2));
470 r = pControl->Start(null, null, &extraData, this);
478 SharePopup::StartEmailAppControl(void)
481 ShareInfo* pShareInfo = null;
482 result r = E_FAILURE;
483 bool imageAttachment = false;
485 extraData.Construct();
487 if (__pShareList != null)
489 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
490 if (pShareInfo != null)
492 String testURL = pShareInfo->GetPageURL();
493 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
499 if (pShareInfo != null)
501 textVal.Append(pShareInfo->GetPageTitle());
502 textVal.Append(L" <");
503 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
504 textVal.Append(pShareInfo->GetPageURL().GetPointer());
505 textVal.Append(L">");
508 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
509 String subjectVal = L"";
510 String textKey = L"http://tizen.org/appcontrol/data/text";
512 String toKey = L"http://tizen.org/appcontrol/data/to";
514 String ccKey = L"http://tizen.org/appcontrol/data/cc";
516 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
518 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
519 String resultVal = "true";
522 //String attachKey = L"attachments";
523 String attachKey = L"http://tizen.org/appcontrol/data/path";
525 if (pShareInfo != null)
527 imageAttachment = pShareInfo->GetImageAttached();
530 attachVal = pShareInfo->GetImagePath();
531 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
539 ArrayList* pDataList = null;
540 pDataList = new (std::nothrow) ArrayList();
541 pDataList->Construct();
542 pDataList->Add(&attachVal);
544 extraData.Add(&subjectKey, &subjectVal);
545 extraData.Add(&textKey, &textVal);
546 extraData.Add(&toKey, &toVal);
547 extraData.Add(&ccKey, &ccVal);
548 extraData.Add(&bccKey, &bccVal);
549 extraData.Add(&resultKey, &resultVal);
550 if(attachVal.GetLength() > 0)
552 extraData.Add(&attachKey, pDataList);
555 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
558 r = pAc->Start(null, null, &extraData, this);
566 SharePopup::StartMessageAppControl(void)
569 ShareInfo* pShareInfo = null;
570 result r = E_FAILURE;
571 bool imageAttachment = false;
573 extraData.Construct();
575 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
577 String textKey = L"http://tizen.org/appcontrol/data/text";
579 String attachKey = L"http://tizen.org/appcontrol/data/path";
581 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
582 String resultVal = "true";
583 ArrayList* pDataList = null;
585 if (__pShareList != null)
587 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
588 if (pShareInfo != null)
590 String testURL = pShareInfo->GetPageURL();
591 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
595 if (pShareInfo != null)
597 textVal.Append(pShareInfo->GetPageTitle());
598 if(pShareInfo->GetPageTitle().GetLength() > 0)
600 textVal.Append(L" <");
604 textVal.Append(L"<");
606 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
607 textVal.Append(pShareInfo->GetPageURL().GetPointer());
608 textVal.Append(L">");
610 if (pShareInfo != null)
612 imageAttachment = pShareInfo->GetImageAttached();
617 attachVal = pShareInfo->GetImagePath();
619 pDataList = new (std::nothrow) ArrayList();
620 pDataList->Construct();
621 pDataList->Add(&attachVal);
630 extraData.Add(&typeKey, &typeVal);
634 // type is MMMS, attach the image
635 extraData.Add(&attachKey, pDataList);
639 // type is SMS , attach the text
640 extraData.Add(&textKey, &textVal);
642 extraData.Add(&resultKey, &resultVal);
643 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
646 r = pAc->Start(null, null, &extraData, this);
657 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
659 AppLog("InternetApp::OnForeground called");
663 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
665 AppLog("SharePopup::OnAppControlCompleteResponseReceived");
667 ShareInfo* pShareInfo = null;
668 result r = E_FAILURE;
675 if (__pShareList != null)
677 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
681 bool imageAttachment = false;
682 if (pShareInfo != null)
684 imageAttachment = pShareInfo->GetImageAttached();
687 attachVal = pShareInfo->GetImagePath();
688 AppLog("SharePopup:: imagePath is %S",attachVal.GetPointer());
689 r = File::Remove(attachVal);
692 AppLog("removed success");
696 AppLog("removed failure");
699 __pShareList->RemoveAll(true);
701 Popup::SetShowState(false);
703 Frame* pCurrentFrame = null;
704 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
706 if (pCurrentFrame != null)
708 pCurrentFrame->SetEnabled(true);
710 __appControlOngoing = false;
714 SharePopup::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
716 AppLog("ConfirmationPopup::OnKeyReleased %d",keyEventInfo.GetKeyCode());
717 if(keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
719 if(GetShowState() == true)