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::Graphics;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39 using namespace Tizen::Ui::Scenes;
41 const int SharePopup::IDA_CANCEL_BUTTON = 101;
42 const int SharePopup::ID_FORMAT_MESSAGE_STRING = 500;
43 const int SharePopup::ID_FORMAT_EMAIL_STRING = 501;
44 const int SharePopup::ID_FORMAT_FACEBOOK_STRING = 502;
45 const int SharePopup::ID_FORMAT_TWITTER_STRING = 503;
47 ShareInfo:: ShareInfo(void)
49 isImageAttached = false;
53 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;
115 SharePopup::~SharePopup(void)
121 SharePopup::Initialize(void)
123 Button* pCancelButton = null;
125 Popup::Construct(L"IDL_SHARE_POPUP");
126 SetName(L"CommonPopup");
128 __pShareList = new(std::nothrow) ArrayList();
129 __pShareList->Construct();
131 __pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW"));
137 __pList->SetItemProvider(*this);
138 __pList->AddListViewItemEventListener(*this);
140 pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON1", true));
143 pCancelButton->AddActionEventListener(*this);
144 pCancelButton->SetActionId(IDA_CANCEL_BUTTON);
151 SharePopup::OnTerminating(void)
153 result r = E_SUCCESS;
158 SharePopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
162 case IDA_CANCEL_BUTTON:
164 Popup::SetShowState(false);
175 SharePopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
181 SharePopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
187 if(__appControlOngoing == false)
189 __appControlOngoing = true;
191 StartMessageAppControl();
197 if(__appControlOngoing == false)
199 __appControlOngoing = true;
201 StartEmailAppControl();
212 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
218 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
223 Tizen::Ui::Controls::ListItemBase*
224 SharePopup::CreateItem(int index, int itemWidth)
226 result r = E_FAILURE;
227 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
229 int elementHeight = 50;
230 int listItemHeight = 75;
232 CustomItem* pItem = new(std::nothrow) CustomItem();
233 r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemHeight), style);
236 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
245 AppLogDebug("SharePopUp CreateItem 0");
246 // IDS_SHARE_VIA_MESSAGE
247 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_MESSAGE_STRING, CommonUtil::GetString(L"IDS_BR_OPT_MESSAGES"), true);
252 AppLogDebug("SharePopUp CreateItem 1");
253 // IDS_SHARE_VIA_EMAIL
254 pItem->AddElement(Rectangle(45, 0, GetClientAreaBounds().width, listItemHeight), ID_FORMAT_EMAIL_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SENDURLVIA_EMAIL"), true);
264 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
270 SharePopup::GetItemCount(void)
276 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
278 result r = E_FAILURE;
280 if (__pShareList != NULL)
282 r = __pShareList->Add(*pShareInfo);
287 void SharePopup::RemoveAllShareInfo()
289 __pShareList->RemoveAll();
293 SharePopup::StartEmailAppControl(void)
296 ShareInfo* pShareInfo = null;
297 result r = E_FAILURE;
298 bool imageAttachment = false;
300 extraData.Construct();
302 if (__pShareList != null)
304 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
305 if (pShareInfo != null)
307 String testURL = pShareInfo->GetPageURL();
308 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
314 if (pShareInfo != null)
316 textVal.Append(pShareInfo->GetPageTitle());
317 textVal.Append(L" <");
318 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
319 textVal.Append(pShareInfo->GetPageURL().GetPointer());
320 textVal.Append(L">");
323 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
324 String subjectVal = L"";
325 String textKey = L"http://tizen.org/appcontrol/data/text";
327 String toKey = L"http://tizen.org/appcontrol/data/to";
329 String ccKey = L"http://tizen.org/appcontrol/data/cc";
331 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
333 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
334 String resultVal = "true";
337 //String attachKey = L"attachments";
338 String attachKey = L"http://tizen.org/appcontrol/data/path";
340 if (pShareInfo != null)
342 imageAttachment = pShareInfo->GetImageAttached();
345 attachVal = pShareInfo->GetImagePath();
346 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
354 ArrayList* pDataList = null;
355 pDataList = new (std::nothrow) ArrayList();
356 pDataList->Construct();
357 pDataList->Add(&attachVal);
359 extraData.Add(&subjectKey, &subjectVal);
360 extraData.Add(&textKey, &textVal);
361 extraData.Add(&toKey, &toVal);
362 extraData.Add(&ccKey, &ccVal);
363 extraData.Add(&bccKey, &bccVal);
364 extraData.Add(&resultKey, &resultVal);
365 if(attachVal.GetLength() > 0)
367 extraData.Add(&attachKey, pDataList);
370 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
373 r = pAc->Start(null, null, &extraData, this);
377 if (pShareInfo != null)
386 SharePopup::StartMessageAppControl(void)
389 ShareInfo* pShareInfo = null;
390 result r = E_FAILURE;
391 bool imageAttachment = false;
393 extraData.Construct();
395 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
397 String textKey = L"http://tizen.org/appcontrol/data/text";
399 String attachKey = L"http://tizen.org/appcontrol/data/path";
401 String resultKey = L"http://tizen.org/appcontrol/data/return_result";
402 String resultVal = "true";
403 ArrayList* pDataList = null;
405 if (__pShareList != null)
407 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
408 if (pShareInfo != null)
410 String testURL = pShareInfo->GetPageURL();
411 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
415 if (pShareInfo != null)
417 textVal.Append(pShareInfo->GetPageTitle());
418 if(pShareInfo->GetPageTitle().GetLength() > 0)
420 textVal.Append(L" <");
424 textVal.Append(L"<");
426 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
427 textVal.Append(pShareInfo->GetPageURL().GetPointer());
428 textVal.Append(L">");
430 if (pShareInfo != null)
432 imageAttachment = pShareInfo->GetImageAttached();
437 attachVal = pShareInfo->GetImagePath();
439 pDataList = new (std::nothrow) ArrayList();
440 pDataList->Construct();
441 pDataList->Add(&attachVal);
450 extraData.Add(&typeKey, &typeVal);
454 // type is MMMS, attach the image
455 extraData.Add(&attachKey, pDataList);
459 // type is SMS , attach the text
460 extraData.Add(&textKey, &textVal);
462 extraData.Add(&resultKey, &resultVal);
463 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
466 r = pAc->Start(null, null, &extraData, this);
472 if (pShareInfo != null)
483 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
485 AppLog("InternetApp::OnForeground called");
489 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
491 AppLog("SharePopup::OnAppControlCompleteResponseReceived");
492 Popup::SetShowState(false);
494 __appControlOngoing = false;