3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Flora License, Version 1.0 (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;
52 ShareInfo:: ~ShareInfo(void)
58 ShareInfo::SetPageTitle(Tizen::Base::String aPageTitle)
61 __pageTitle.Append(aPageTitle);
65 ShareInfo::SetPageUrl(Tizen::Base::String aPageURL)
68 __pageURL.Append(aPageURL);
72 ShareInfo::GetPageTitle(void)
78 ShareInfo::GetPageURL(void)
84 ShareInfo::SetImageAttached(bool imageAttached)
86 isImageAttached = imageAttached;
90 ShareInfo::GetImageAttached()
92 return isImageAttached;
96 ShareInfo::SetImagePath(Tizen::Base::String aImagePath)
99 __imagePath.Append(aImagePath);
103 ShareInfo::GetImagePath(void)
108 SharePopup::SharePopup(void)
109 :__pList(null),__pShareList(null)
114 SharePopup::~SharePopup(void)
120 SharePopup::Initialize(void)
122 Button* pCancelButton = null;
124 Popup::Construct(L"IDL_SHARE_POPUP");
125 SetName(L"CommonPopup");
127 __pShareList = new(std::nothrow) ArrayList();
128 __pShareList->Construct();
130 __pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW"));
136 __pList->SetItemProvider(*this);
137 __pList->AddListViewItemEventListener(*this);
139 pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON1", true));
142 pCancelButton->AddActionEventListener(*this);
143 pCancelButton->SetActionId(IDA_CANCEL_BUTTON);
150 SharePopup::OnTerminating(void)
152 result r = E_SUCCESS;
157 SharePopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
161 case IDA_CANCEL_BUTTON:
163 Popup::SetShowState(false);
174 SharePopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
180 SharePopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
186 Popup::SetShowState(false);
189 StartMessageAppControl();
194 Popup::SetShowState(false);
197 StartEmailAppControl();
206 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
212 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
217 Tizen::Ui::Controls::ListItemBase*
218 SharePopup::CreateItem(int index, int itemWidth)
220 result r = E_FAILURE;
221 ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
223 int elementHeight = 50;
224 int listItemWidth = 80;
226 CustomItem* pItem = new(std::nothrow) CustomItem();
227 r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemWidth), style);
230 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
239 AppLogDebug("SharePopUp CreateItem 0");
240 // IDS_SHARE_VIA_MESSAGE
241 pItem->AddElement(Rectangle(45,0, GetClientAreaBounds().width, listItemWidth), ID_FORMAT_MESSAGE_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SHARE_VIA_MESSAGES"), true);
246 AppLogDebug("SharePopUp CreateItem 1");
247 // IDS_SHARE_VIA_EMAIL
248 pItem->AddElement(Rectangle(45, 0, GetClientAreaBounds().width, listItemWidth), ID_FORMAT_EMAIL_STRING, CommonUtil::GetString(L"IDS_BR_OPT_SHARE_VIA_EMAIL"), true);
258 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
264 SharePopup::GetItemCount(void)
270 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
272 result r = E_FAILURE;
274 if (__pShareList != NULL)
276 r = __pShareList->Add(*pShareInfo);
281 void SharePopup::RemoveAllShareInfo()
283 __pShareList->RemoveAll();
287 SharePopup::StartEmailAppControl(void)
290 ShareInfo* pShareInfo = null;
291 result r = E_FAILURE;
292 bool imageAttachment = false;
294 extraData.Construct();
296 if (__pShareList != null)
298 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
299 if (pShareInfo != null)
301 String testURL = pShareInfo->GetPageURL();
302 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
308 if (pShareInfo != null)
310 textVal.Append(pShareInfo->GetPageTitle());
311 textVal.Append(L" <");
312 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
313 textVal.Append(pShareInfo->GetPageURL().GetPointer());
314 textVal.Append(L">");
317 String subjectKey = L"http://tizen.org/appcontrol/data/subject";
318 String subjectVal = L"";
319 String textKey = L"http://tizen.org/appcontrol/data/text";
321 String toKey = L"http://tizen.org/appcontrol/data/to";
323 String ccKey = L"http://tizen.org/appcontrol/data/cc";
325 String bccKey = L"http://tizen.org/appcontrol/data/bcc";
328 //String attachKey = L"attachments";
329 String attachKey = L"http://tizen.org/appcontrol/data/path";
331 if (pShareInfo != null)
333 imageAttachment = pShareInfo->GetImageAttached();
336 attachVal = pShareInfo->GetImagePath();
337 AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
345 ArrayList* pDataList = null;
346 pDataList = new (std::nothrow) ArrayList();
347 pDataList->Construct();
348 pDataList->Add(&attachVal);
350 extraData.Add(&subjectKey, &subjectVal);
351 extraData.Add(&textKey, &textVal);
352 extraData.Add(&toKey, &toVal);
353 extraData.Add(&ccKey, &ccVal);
354 extraData.Add(&bccKey, &bccVal);
355 //extraData.Add(&attachKey, &attachVal);
356 extraData.Add(&attachKey, pDataList);
358 AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
361 pAc->Start(null, null, &extraData, null);
364 if (pShareInfo != null)
373 SharePopup::StartMessageAppControl(void)
376 ShareInfo* pShareInfo = null;
377 bool imageAttachment = false;
379 extraData.Construct();
381 String typeKey = L"http://tizen.org/appcontrol/data/message/type";
383 String textKey = L"http://tizen.org/appcontrol/data/text";
385 String attachKey = L"http://tizen.org/appcontrol/data/path";
387 ArrayList* pDataList = null;
389 if (__pShareList != null)
391 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
392 if (pShareInfo != null)
394 String testURL = pShareInfo->GetPageURL();
395 AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
399 if (pShareInfo != null)
401 textVal.Append(pShareInfo->GetPageTitle());
402 if(pShareInfo->GetPageTitle().GetLength() > 0)
404 textVal.Append(L" <");
408 textVal.Append(L"<");
410 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
411 textVal.Append(pShareInfo->GetPageURL().GetPointer());
412 textVal.Append(L">");
414 if (pShareInfo != null)
416 imageAttachment = pShareInfo->GetImageAttached();
421 attachVal = pShareInfo->GetImagePath();
423 pDataList = new (std::nothrow) ArrayList();
424 pDataList->Construct();
425 pDataList->Add(&attachVal);
434 extraData.Add(&typeKey, &typeVal);
438 // type is MMMS, attach the image
439 extraData.Add(&attachKey, pDataList);
443 // type is SMS , attach the text
444 extraData.Add(&textKey, &textVal);
446 AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
449 pAc->Start(null, null, &extraData, null);
452 if (pShareInfo != null)
463 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)