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();
405 SharePopup::StartAppControl(int index)
408 ShareInfo* pShareInfo = null;
409 result r = E_FAILURE;
410 bool imageAttachment = false;
412 extraData.Construct();
414 if (__pShareList != null)
416 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
417 if (pShareInfo != null)
419 String testURL = pShareInfo->GetPageURL();
420 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
426 if (pShareInfo != null)
428 textVal.Append(pShareInfo->GetPageTitle());
429 textVal.Append(L" <");
430 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
431 textVal.Append(pShareInfo->GetPageURL().GetPointer());
432 textVal.Append(L">");
436 String textKey = L"http://tizen.org/appcontrol/data/text";
438 //String attachKey = L"attachments";
439 String attachKey = L"http://tizen.org/appcontrol/data/path";
441 if (pShareInfo != null)
443 imageAttachment = pShareInfo->GetImageAttached();
446 attachVal = pShareInfo->GetImagePath();
447 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
455 ArrayList* pDataList = null;
456 pDataList = new (std::nothrow) ArrayList();
457 pDataList->Construct();
458 pDataList->Add(&attachVal);
461 extraData.Add(&textKey, &textVal);
463 if(attachVal.GetLength() > 0)
465 extraData.Add(&attachKey, pDataList);
468 AppControl * pControl = dynamic_cast<AppControl*>(__pAppControlList->GetAt(index - 2));
471 r = pControl->Start(null, null, &extraData, this);
479 SharePopup::StartEmailAppControl(void)
482 ShareInfo* pShareInfo = null;
483 result r = E_FAILURE;
484 bool imageAttachment = false;
486 extraData.Construct();
488 if (__pShareList != null)
490 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
491 if (pShareInfo != null)
493 String testURL = pShareInfo->GetPageURL();
494 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
500 if (pShareInfo != null)
502 textVal.Append(pShareInfo->GetPageTitle());
503 textVal.Append(L" <");
504 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
505 textVal.Append(pShareInfo->GetPageURL().GetPointer());
506 textVal.Append(L">");
509 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
510 String subjectVal = L"";
511 String textKey = L"http://tizen.org/appcontrol/data/text";
513 String toKey = L"http://tizen.org/appcontrol/data/to";
515 String ccKey = L"http://tizen.org/appcontrol/data/cc";
517 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
519 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
520 String resultVal = "true";
523 //String attachKey = L"attachments";
524 String attachKey = L"http://tizen.org/appcontrol/data/path";
526 if (pShareInfo != null)
528 imageAttachment = pShareInfo->GetImageAttached();
531 attachVal = pShareInfo->GetImagePath();
532 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
540 ArrayList* pDataList = null;
541 pDataList = new (std::nothrow) ArrayList();
542 pDataList->Construct();
543 pDataList->Add(&attachVal);
545 extraData.Add(&subjectKey, &subjectVal);
546 extraData.Add(&textKey, &textVal);
547 extraData.Add(&toKey, &toVal);
548 extraData.Add(&ccKey, &ccVal);
549 extraData.Add(&bccKey, &bccVal);
550 extraData.Add(&resultKey, &resultVal);
551 if(attachVal.GetLength() > 0)
553 extraData.Add(&attachKey, pDataList);
556 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
559 r = pAc->Start(null, null, &extraData, this);
567 SharePopup::StartMessageAppControl(void)
570 ShareInfo* pShareInfo = null;
571 result r = E_FAILURE;
572 bool imageAttachment = false;
574 extraData.Construct();
576 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
578 String textKey = L"http://tizen.org/appcontrol/data/text";
580 String attachKey = L"http://tizen.org/appcontrol/data/path";
582 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
583 String resultVal = "true";
584 ArrayList* pDataList = null;
586 if (__pShareList != null)
588 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
589 if (pShareInfo != null)
591 String testURL = pShareInfo->GetPageURL();
592 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
596 if (pShareInfo != null)
598 textVal.Append(pShareInfo->GetPageTitle());
599 if(pShareInfo->GetPageTitle().GetLength() > 0)
601 textVal.Append(L" <");
605 textVal.Append(L"<");
607 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
608 textVal.Append(pShareInfo->GetPageURL().GetPointer());
609 textVal.Append(L">");
611 if (pShareInfo != null)
613 imageAttachment = pShareInfo->GetImageAttached();
618 attachVal = pShareInfo->GetImagePath();
620 pDataList = new (std::nothrow) ArrayList();
621 pDataList->Construct();
622 pDataList->Add(&attachVal);
631 extraData.Add(&typeKey, &typeVal);
635 // type is MMMS, attach the image
636 extraData.Add(&attachKey, pDataList);
640 // type is SMS , attach the text
641 extraData.Add(&textKey, &textVal);
643 extraData.Add(&resultKey, &resultVal);
644 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
647 r = pAc->Start(null, null, &extraData, this);
658 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
660 AppLog("InternetApp::OnForeground called");
664 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
666 AppLog("SharePopup::OnAppControlCompleteResponseReceived");
668 ShareInfo* pShareInfo = null;
669 result r = E_FAILURE;
676 if (__pShareList != null)
678 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
682 bool imageAttachment = false;
683 if (pShareInfo != null)
685 imageAttachment = pShareInfo->GetImageAttached();
688 attachVal = pShareInfo->GetImagePath();
689 AppLog("SharePopup:: imagePath is %S",attachVal.GetPointer());
690 r = File::Remove(attachVal);
693 AppLog("removed success");
697 AppLog("removed failure");
700 __pShareList->RemoveAll(true);
702 Popup::SetShowState(false);
704 Frame* pCurrentFrame = null;
705 pCurrentFrame = Application::GetInstance()->GetAppFrame()->GetFrame();
707 if (pCurrentFrame != null)
709 pCurrentFrame->SetEnabled(true);
710 pCurrentFrame->Invalidate(true);
712 __appControlOngoing = false;
716 SharePopup::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
718 AppLog("ConfirmationPopup::OnKeyReleased %d",keyEventInfo.GetKeyCode());
719 if(keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
721 if(GetShowState() == true)