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);
283 pCurrentFrame->Invalidate(true);
288 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
294 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
299 Tizen::Ui::Controls::ListItemBase*
300 SharePopup::CreateItem(int index, int itemWidth)
302 AppLog("SharePopup::CreateItem index %d",index);
303 result r = E_FAILURE;
304 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
306 int elementHeight = 50;
307 int listItemHeight = 75;
309 CustomItem* pItem = new(std::nothrow) CustomItem();
310 r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemHeight), style);
313 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
324 AppLogDebug("SharePopUp CreateItem 0");
325 // IDS_SHARE_VIA_MESSAGE
326 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING, CommonUtil::GetString(L"IDS_BR_OPT_MESSAGES"), true);
331 AppLogDebug("SharePopUp CreateItem 1");
332 // IDS_SHARE_VIA_EMAIL
333 pItem->AddElement(Rectangle(45, 0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_EMAIL_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SENDURLVIA_EMAIL"), true);
337 if(__pAppControlList)
339 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(index -2));
340 AppLog("SharePopup::CreateItem appcontrol count %d",__pAppControlList->GetCount());
342 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING+index, pControl->GetAppName(), true);
350 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
356 SharePopup::GetItemCount(void)
358 String* pStrId = new String(L"http://tizen.org/appcontrol/operation/share_text");
359 __pAppControlList = AppManager::FindAppControlsN(pStrId,null,null,null);
360 if(__pAppControlList == null)
364 int count = __pAppControlList->GetCount();
365 AppLog("SharePopup::GetItemCount appcontrol count %d",count);
367 for(int pos = 0; pos < count; pos++)
369 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(pos));
370 AppLog("pControl->GetAppName() %ls",pControl->GetAppName().GetPointer());
371 if(pControl->GetAppName().Equals(L"Messages",false) == true || pControl->GetAppName().Equals(L"Email",false) == true )
373 __pAppControlList->RemoveAt(pos,true);
380 AppLog("removeCount %d",removeCount);
381 if(count+removeCount >=2)
382 return count+removeCount;
388 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
390 result r = E_FAILURE;
392 if (__pShareList != NULL)
394 r = __pShareList->Add(*pShareInfo);
399 void SharePopup::RemoveAllShareInfo()
401 __pShareList->RemoveAll();
408 SharePopup::StartAppControl(int index)
411 ShareInfo* pShareInfo = null;
412 result r = E_FAILURE;
413 bool imageAttachment = false;
415 extraData.Construct();
417 if (__pShareList != null)
419 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
420 if (pShareInfo != null)
422 String testURL = pShareInfo->GetPageURL();
423 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
429 if (pShareInfo != null)
431 textVal.Append(pShareInfo->GetPageTitle());
432 textVal.Append(L" <");
433 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
434 textVal.Append(pShareInfo->GetPageURL().GetPointer());
435 textVal.Append(L">");
439 String textKey = L"http://tizen.org/appcontrol/data/text";
441 //String attachKey = L"attachments";
442 String attachKey = L"http://tizen.org/appcontrol/data/path";
444 if (pShareInfo != null)
446 imageAttachment = pShareInfo->GetImageAttached();
449 attachVal = pShareInfo->GetImagePath();
450 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
458 ArrayList* pDataList = null;
459 pDataList = new (std::nothrow) ArrayList();
460 pDataList->Construct();
461 pDataList->Add(&attachVal);
464 extraData.Add(&textKey, &textVal);
466 if(attachVal.GetLength() > 0)
468 extraData.Add(&attachKey, pDataList);
471 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(index - 2));
474 r = pControl->Start(null, null, &extraData, this);
482 SharePopup::StartEmailAppControl(void)
485 ShareInfo* pShareInfo = null;
486 result r = E_FAILURE;
487 bool imageAttachment = false;
489 extraData.Construct();
491 if (__pShareList != null)
493 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
494 if (pShareInfo != null)
496 String testURL = pShareInfo->GetPageURL();
497 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
503 if (pShareInfo != null)
505 textVal.Append(pShareInfo->GetPageTitle());
506 textVal.Append(L" <");
507 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
508 textVal.Append(pShareInfo->GetPageURL().GetPointer());
509 textVal.Append(L">");
512 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
513 String subjectVal = L"";
514 String textKey = L"http://tizen.org/appcontrol/data/text";
516 String toKey = L"http://tizen.org/appcontrol/data/to";
518 String ccKey = L"http://tizen.org/appcontrol/data/cc";
520 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
522 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
523 String resultVal = "true";
526 //String attachKey = L"attachments";
527 String attachKey = L"http://tizen.org/appcontrol/data/path";
529 if (pShareInfo != null)
531 imageAttachment = pShareInfo->GetImageAttached();
534 attachVal = pShareInfo->GetImagePath();
535 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
543 ArrayList* pDataList = null;
544 pDataList = new (std::nothrow) ArrayList();
545 pDataList->Construct();
546 pDataList->Add(&attachVal);
548 extraData.Add(&subjectKey, &subjectVal);
549 extraData.Add(&textKey, &textVal);
550 extraData.Add(&toKey, &toVal);
551 extraData.Add(&ccKey, &ccVal);
552 extraData.Add(&bccKey, &bccVal);
553 extraData.Add(&resultKey, &resultVal);
554 if(attachVal.GetLength() > 0)
556 extraData.Add(&attachKey, pDataList);
559 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
562 r = pAc->Start(null, null, &extraData, this);
570 SharePopup::StartMessageAppControl(void)
573 ShareInfo* pShareInfo = null;
574 result r = E_FAILURE;
575 bool imageAttachment = false;
577 extraData.Construct();
579 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
581 String textKey = L"http://tizen.org/appcontrol/data/text";
583 String attachKey = L"http://tizen.org/appcontrol/data/path";
585 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
586 String resultVal = "true";
587 ArrayList* pDataList = null;
589 if (__pShareList != null)
591 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
592 if (pShareInfo != null)
594 String testURL = pShareInfo->GetPageURL();
595 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
599 if (pShareInfo != null)
601 textVal.Append(pShareInfo->GetPageTitle());
602 if(pShareInfo->GetPageTitle().GetLength() > 0)
604 textVal.Append(L" <");
608 textVal.Append(L"<");
610 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
611 textVal.Append(pShareInfo->GetPageURL().GetPointer());
612 textVal.Append(L">");
614 if (pShareInfo != null)
616 imageAttachment = pShareInfo->GetImageAttached();
621 attachVal = pShareInfo->GetImagePath();
623 pDataList = new (std::nothrow) ArrayList();
624 pDataList->Construct();
625 pDataList->Add(&attachVal);
634 extraData.Add(&typeKey, &typeVal);
638 // type is MMMS, attach the image
639 extraData.Add(&attachKey, pDataList);
643 // type is SMS , attach the text
644 extraData.Add(&textKey, &textVal);
646 extraData.Add(&resultKey, &resultVal);
647 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
650 r = pAc->Start(null, null, &extraData, this);
661 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
663 AppLog("InternetApp::OnForeground called");
667 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
669 AppLog("SharePopup::OnAppControlCompleteResponseReceived");
671 ShareInfo* pShareInfo = null;
672 result r = E_FAILURE;
679 if (__pShareList != null)
681 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
685 bool imageAttachment = false;
686 if (pShareInfo != null)
688 imageAttachment = pShareInfo->GetImageAttached();
691 attachVal = pShareInfo->GetImagePath();
692 AppLog("SharePopup:: imagePath is %S",attachVal.GetPointer());
693 r = File::Remove(attachVal);
696 AppLog("removed success");
700 AppLog("removed failure");
703 __pShareList->RemoveAll(true);
705 Popup::SetShowState(false);
707 Frame* pCurrentFrame = null;
708 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
710 if (pCurrentFrame != null)
712 pCurrentFrame->SetEnabled(true);
713 pCurrentFrame->Invalidate(true);
715 __appControlOngoing = false;
719 SharePopup::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
721 AppLog("ConfirmationPopup::OnKeyReleased %d",keyEventInfo.GetKeyCode());
722 if(keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
724 if(GetShowState() == true)