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);
199 Frame* pCurrentFrame = null;
200 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
202 if (pCurrentFrame != null)
204 pCurrentFrame->SetEnabled(true);
205 pCurrentFrame->Invalidate(true);
210 SharePopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
214 case IDA_CANCEL_BUTTON:
216 Popup::SetShowState(false);
227 SharePopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
233 SharePopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
239 if(__appControlOngoing == false)
241 __appControlOngoing = true;
243 StartMessageAppControl();
246 __pTimer = new(std::nothrow) Timer();
247 __pTimer->Construct(*this);
249 __pTimer->Start(2500);
255 if(__appControlOngoing == false)
257 __appControlOngoing = true;
259 StartEmailAppControl();
262 __pTimer = new(std::nothrow) Timer();
263 __pTimer->Construct(*this);
265 __pTimer->Start(2500);
271 if(__appControlOngoing == false)
273 __appControlOngoing = true;
274 //share via third party app
275 StartAppControl(index);
278 __pTimer = new(std::nothrow) Timer();
279 __pTimer->Construct(*this);
281 __pTimer->Start(2500);
285 Frame* pCurrentFrame = null;
286 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
288 if (pCurrentFrame != null)
290 pCurrentFrame->SetEnabled(false);
291 pCurrentFrame->Invalidate(true);
296 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
302 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
307 Tizen::Ui::Controls::ListItemBase*
308 SharePopup::CreateItem(int index, int itemWidth)
310 AppLog("SharePopup::CreateItem index %d",index);
311 result r = E_FAILURE;
312 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
314 int elementHeight = 50;
315 int listItemHeight = 75;
317 CustomItem* pItem = new(std::nothrow) CustomItem();
318 r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemHeight), style);
321 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
332 AppLogDebug("SharePopUp CreateItem 0");
333 // IDS_SHARE_VIA_MESSAGE
334 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SENDURLVIA_MESSAGE"), true);
339 AppLogDebug("SharePopUp CreateItem 1");
340 // IDS_SHARE_VIA_EMAIL
341 pItem->AddElement(Rectangle(45, 0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_EMAIL_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SENDURLVIA_EMAIL"), true);
345 if(__pAppControlList)
347 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(index -2));
348 AppLog("SharePopup::CreateItem appcontrol count %d",__pAppControlList->GetCount());
350 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING+index, pControl->GetAppName(), true);
358 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
364 SharePopup::GetItemCount(void)
366 String* pStrId = new String(L"http://tizen.org/appcontrol/operation/share_text");
367 __pAppControlList = AppManager::FindAppControlsN(pStrId,null,null,null);
368 if(__pAppControlList == null)
372 int count = __pAppControlList->GetCount();
373 AppLog("SharePopup::GetItemCount appcontrol count %d",count);
375 for(int pos = 0; pos < count; pos++)
377 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(pos));
378 AppLog("pControl->GetAppName() %ls",pControl->GetAppName().GetPointer());
379 if( pControl->GetAppId().Equals(L"8r4r5ddzzn.Messages",false) == true || pControl->GetAppId().Equals(L"vxqbrefica.Email",false) == true)
381 AppLog("Removed pControl->GetAppName %ls pControl->GetAppId() %ls",pControl->GetAppName().GetPointer(),pControl->GetAppId().GetPointer());
382 __pAppControlList->RemoveAt(pos,true);
389 AppLog("removeCount %d",removeCount);
390 if(count+removeCount >=2)
391 return count+removeCount;
397 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
399 result r = E_FAILURE;
401 if (__pShareList != NULL)
403 r = __pShareList->Add(*pShareInfo);
408 void SharePopup::RemoveAllShareInfo()
410 __pShareList->RemoveAll();
414 SharePopup::StartAppControl(int index)
417 ShareInfo* pShareInfo = null;
418 result r = E_FAILURE;
419 bool imageAttachment = false;
421 extraData.Construct();
423 if (__pShareList != null)
425 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
426 if (pShareInfo != null)
428 String testURL = pShareInfo->GetPageURL();
429 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
435 if (pShareInfo != null)
437 textVal.Append(pShareInfo->GetPageTitle());
438 textVal.Append(L" <");
439 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
440 textVal.Append(pShareInfo->GetPageURL().GetPointer());
441 textVal.Append(L">");
445 String textKey = L"http://tizen.org/appcontrol/data/text";
447 //String attachKey = L"attachments";
448 String attachKey = L"http://tizen.org/appcontrol/data/path";
450 if (pShareInfo != null)
452 imageAttachment = pShareInfo->GetImageAttached();
455 attachVal = pShareInfo->GetImagePath();
456 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
464 ArrayList* pDataList = null;
465 pDataList = new (std::nothrow) ArrayList();
466 pDataList->Construct();
467 pDataList->Add(&attachVal);
470 extraData.Add(&textKey, &textVal);
472 if(attachVal.GetLength() > 0)
474 extraData.Add(&attachKey, pDataList);
477 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(index - 2));
478 AppLog("pControl AppControl Name %ls",pControl->GetAppName().GetPointer());
481 r = pControl->Start(null, null, &extraData, this);
482 AppLog("AppControl Start %s",GetErrorMessage(r));
490 SharePopup::StartEmailAppControl(void)
493 ShareInfo* pShareInfo = null;
494 result r = E_FAILURE;
495 bool imageAttachment = false;
497 extraData.Construct();
499 if (__pShareList != null)
501 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
502 if (pShareInfo != null)
504 String testURL = pShareInfo->GetPageURL();
505 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
511 if (pShareInfo != null)
513 textVal.Append(pShareInfo->GetPageTitle());
514 textVal.Append(L" <");
515 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
516 textVal.Append(pShareInfo->GetPageURL().GetPointer());
517 textVal.Append(L">");
520 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
521 String subjectVal = L"";
522 String textKey = L"http://tizen.org/appcontrol/data/text";
524 String toKey = L"http://tizen.org/appcontrol/data/to";
526 String ccKey = L"http://tizen.org/appcontrol/data/cc";
528 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
530 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
531 String resultVal = "true";
534 //String attachKey = L"attachments";
535 String attachKey = L"http://tizen.org/appcontrol/data/path";
537 if (pShareInfo != null)
539 imageAttachment = pShareInfo->GetImageAttached();
542 attachVal = pShareInfo->GetImagePath();
543 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
551 ArrayList* pDataList = null;
552 pDataList = new (std::nothrow) ArrayList();
553 pDataList->Construct();
554 pDataList->Add(&attachVal);
556 extraData.Add(&subjectKey, &subjectVal);
557 extraData.Add(&textKey, &textVal);
558 extraData.Add(&toKey, &toVal);
559 extraData.Add(&ccKey, &ccVal);
560 extraData.Add(&bccKey, &bccVal);
561 extraData.Add(&resultKey, &resultVal);
562 if(attachVal.GetLength() > 0)
564 extraData.Add(&attachKey, pDataList);
567 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
570 r = pAc->Start(null, null, &extraData, this);
578 SharePopup::StartMessageAppControl(void)
581 ShareInfo* pShareInfo = null;
582 result r = E_FAILURE;
583 bool imageAttachment = false;
585 extraData.Construct();
587 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
589 String textKey = L"http://tizen.org/appcontrol/data/text";
591 String attachKey = L"http://tizen.org/appcontrol/data/path";
593 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
594 String resultVal = "true";
595 ArrayList* pDataList = null;
597 if (__pShareList != null)
599 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
600 if (pShareInfo != null)
602 String testURL = pShareInfo->GetPageURL();
603 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
607 if (pShareInfo != null)
609 textVal.Append(pShareInfo->GetPageTitle());
610 if(pShareInfo->GetPageTitle().GetLength() > 0)
612 textVal.Append(L" <");
616 textVal.Append(L"<");
618 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
619 textVal.Append(pShareInfo->GetPageURL().GetPointer());
620 textVal.Append(L">");
622 if (pShareInfo != null)
624 imageAttachment = pShareInfo->GetImageAttached();
629 attachVal = pShareInfo->GetImagePath();
631 pDataList = new (std::nothrow) ArrayList();
632 pDataList->Construct();
633 pDataList->Add(&attachVal);
642 extraData.Add(&typeKey, &typeVal);
646 // type is MMMS, attach the image
647 extraData.Add(&attachKey, pDataList);
651 // type is SMS , attach the text
652 extraData.Add(&textKey, &textVal);
654 extraData.Add(&resultKey, &resultVal);
655 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
658 r = pAc->Start(null, null, &extraData, this);
669 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
671 AppLog("InternetApp::OnForeground called");
675 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
677 AppLog("SharePopup::OnAppControlCompleteResponseReceived");
679 ShareInfo* pShareInfo = null;
680 result r = E_FAILURE;
687 if (__pShareList != null)
689 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
693 bool imageAttachment = false;
694 if (pShareInfo != null)
696 imageAttachment = pShareInfo->GetImageAttached();
699 attachVal = pShareInfo->GetImagePath();
700 AppLog("SharePopup:: imagePath is %S",attachVal.GetPointer());
701 r = File::Remove(attachVal);
704 AppLog("removed success");
708 AppLog("removed failure");
711 __pShareList->RemoveAll(true);
713 Popup::SetShowState(false);
715 Frame* pCurrentFrame = null;
716 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
718 if (pCurrentFrame != null)
720 pCurrentFrame->SetEnabled(true);
721 pCurrentFrame->Invalidate(true);
723 __appControlOngoing = false;
727 SharePopup::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
729 AppLog("ConfirmationPopup::OnKeyReleased %d",keyEventInfo.GetKeyCode());
730 if(keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
732 if(GetShowState() == true)