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)
60 ShareInfo::SetPageTitle(Tizen::Base::String aPageTitle)
63 __pageTitle.Append(aPageTitle);
67 ShareInfo::SetPageUrl(Tizen::Base::String aPageURL)
70 __pageURL.Append(aPageURL);
74 ShareInfo::GetPageTitle(void)
80 ShareInfo::GetPageURL(void)
86 ShareInfo::SetImageAttached(bool imageAttached)
88 isImageAttached = imageAttached;
92 ShareInfo::GetImageAttached()
94 return isImageAttached;
98 ShareInfo::SetImagePath(Tizen::Base::String aImagePath)
101 __imagePath.Append(aImagePath);
105 ShareInfo::GetImagePath(void)
110 SharePopup::SharePopup(void)
111 :__pList(null),__pShareList(null)
113 __appControlOngoing = false;
117 SharePopup::~SharePopup(void)
123 SharePopup::Initialize(void)
125 Button* pCancelButton = null;
127 Popup::Construct(L"IDL_SHARE_POPUP");
128 SetName(L"CommonPopup");
130 __pShareList = new(std::nothrow) ArrayList();
131 __pShareList->Construct();
133 __pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW"));
139 __pList->SetItemProvider(*this);
140 __pList->AddListViewItemEventListener(*this);
142 pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON1", true));
145 pCancelButton->AddActionEventListener(*this);
146 pCancelButton->SetActionId(IDA_CANCEL_BUTTON);
149 __pTimer = new(std::nothrow) Timer();
150 __pTimer->Construct(*this);
151 SetPropagatedKeyEventListener(this);
156 SharePopup::OnTerminating(void)
158 result r = E_SUCCESS;
163 SharePopup::OnTimerExpired(Timer& timer)
165 Popup::SetShowState(false);
170 SharePopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
174 case IDA_CANCEL_BUTTON:
176 Popup::SetShowState(false);
187 SharePopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
193 SharePopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
199 if(__appControlOngoing == false)
201 __appControlOngoing = true;
203 StartMessageAppControl();
204 __pTimer->Start(2500);
210 if(__appControlOngoing == false)
212 __appControlOngoing = true;
214 StartEmailAppControl();
215 __pTimer->Start(2500);
226 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
232 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
237 Tizen::Ui::Controls::ListItemBase*
238 SharePopup::CreateItem(int index, int itemWidth)
240 result r = E_FAILURE;
241 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
243 int elementHeight = 50;
244 int listItemHeight = 75;
246 CustomItem* pItem = new(std::nothrow) CustomItem();
247 r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemHeight), style);
250 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
259 AppLogDebug("SharePopUp CreateItem 0");
260 // IDS_SHARE_VIA_MESSAGE
261 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING, CommonUtil::GetString(L"IDS_BR_OPT_MESSAGES"), true);
266 AppLogDebug("SharePopUp CreateItem 1");
267 // IDS_SHARE_VIA_EMAIL
268 pItem->AddElement(Rectangle(45, 0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_EMAIL_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SENDURLVIA_EMAIL"), true);
278 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
284 SharePopup::GetItemCount(void)
290 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
292 result r = E_FAILURE;
294 if (__pShareList != NULL)
296 r = __pShareList->Add(*pShareInfo);
301 void SharePopup::RemoveAllShareInfo()
303 __pShareList->RemoveAll();
307 SharePopup::StartEmailAppControl(void)
310 ShareInfo* pShareInfo = null;
311 result r = E_FAILURE;
312 bool imageAttachment = false;
314 extraData.Construct();
316 if (__pShareList != null)
318 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
319 if (pShareInfo != null)
321 String testURL = pShareInfo->GetPageURL();
322 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
328 if (pShareInfo != null)
330 textVal.Append(pShareInfo->GetPageTitle());
331 textVal.Append(L" <");
332 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
333 textVal.Append(pShareInfo->GetPageURL().GetPointer());
334 textVal.Append(L">");
337 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
338 String subjectVal = L"";
339 String textKey = L"http://tizen.org/appcontrol/data/text";
341 String toKey = L"http://tizen.org/appcontrol/data/to";
343 String ccKey = L"http://tizen.org/appcontrol/data/cc";
345 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
347 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
348 String resultVal = "true";
351 //String attachKey = L"attachments";
352 String attachKey = L"http://tizen.org/appcontrol/data/path";
354 if (pShareInfo != null)
356 imageAttachment = pShareInfo->GetImageAttached();
359 attachVal = pShareInfo->GetImagePath();
360 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
368 ArrayList* pDataList = null;
369 pDataList = new (std::nothrow) ArrayList();
370 pDataList->Construct();
371 pDataList->Add(&attachVal);
373 extraData.Add(&subjectKey, &subjectVal);
374 extraData.Add(&textKey, &textVal);
375 extraData.Add(&toKey, &toVal);
376 extraData.Add(&ccKey, &ccVal);
377 extraData.Add(&bccKey, &bccVal);
378 extraData.Add(&resultKey, &resultVal);
379 if(attachVal.GetLength() > 0)
381 extraData.Add(&attachKey, pDataList);
384 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
387 r = pAc->Start(null, null, &extraData, this);
395 SharePopup::StartMessageAppControl(void)
398 ShareInfo* pShareInfo = null;
399 result r = E_FAILURE;
400 bool imageAttachment = false;
402 extraData.Construct();
404 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
406 String textKey = L"http://tizen.org/appcontrol/data/text";
408 String attachKey = L"http://tizen.org/appcontrol/data/path";
410 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
411 String resultVal = "true";
412 ArrayList* pDataList = null;
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());
424 if (pShareInfo != null)
426 textVal.Append(pShareInfo->GetPageTitle());
427 if(pShareInfo->GetPageTitle().GetLength() > 0)
429 textVal.Append(L" <");
433 textVal.Append(L"<");
435 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
436 textVal.Append(pShareInfo->GetPageURL().GetPointer());
437 textVal.Append(L">");
439 if (pShareInfo != null)
441 imageAttachment = pShareInfo->GetImageAttached();
446 attachVal = pShareInfo->GetImagePath();
448 pDataList = new (std::nothrow) ArrayList();
449 pDataList->Construct();
450 pDataList->Add(&attachVal);
459 extraData.Add(&typeKey, &typeVal);
463 // type is MMMS, attach the image
464 extraData.Add(&attachKey, pDataList);
468 // type is SMS , attach the text
469 extraData.Add(&textKey, &textVal);
471 extraData.Add(&resultKey, &resultVal);
472 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
475 r = pAc->Start(null, null, &extraData, this);
486 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
488 AppLog("InternetApp::OnForeground called");
492 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
494 AppLog("SharePopup::OnAppControlCompleteResponseReceived");
496 ShareInfo* pShareInfo = null;
497 result r = E_FAILURE;
499 if (__pShareList != null)
501 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
505 bool imageAttachment = false;
506 if (pShareInfo != null)
508 imageAttachment = pShareInfo->GetImageAttached();
511 attachVal = pShareInfo->GetImagePath();
512 AppLog("SharePopup:: imagePath is %S",attachVal.GetPointer());
513 r = File::Remove(attachVal);
516 AppLog("removed success");
520 AppLog("removed failure");
523 if (pShareInfo != null)
528 Popup::SetShowState(false);
530 __appControlOngoing = false;
534 SharePopup::OnKeyReleased (Control &source, const KeyEventInfo &keyEventInfo)
536 AppLog("ConfirmationPopup::OnKeyReleased %d",keyEventInfo.GetKeyCode());
537 if(keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
539 if(GetShowState() == true)