Fixed Nabi issue N_SE-40542,N_SE-39949,N_SE-40229
[apps/osp/Internet.git] / src / IntSharePopup.cpp
1 //
2
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://floralicense.org/license/
10 //
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.
16 //
17
18 /*
19  * IntSharePopUp.cpp
20  *@file:        IntSharePopup.cpp
21  *@brief:       Share Popup for sharing bookmark via message, email etc
22  */
23
24 #include <FAppUiApp.h>
25 #include <FUi.h>
26 #include <FBase.h>
27 #include <FIo.h>
28
29 #include "IntCommonLib.h"
30 #include "IntSharePopup.h"
31
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;
40
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;
46
47 ShareInfo::     ShareInfo(void)
48 {
49         isImageAttached = false;
50
51 }
52
53 ShareInfo::     ~ShareInfo(void)
54 {
55
56 }
57
58 void
59 ShareInfo::SetPageTitle(Tizen::Base::String aPageTitle)
60 {
61         __pageTitle.Clear();
62         __pageTitle.Append(aPageTitle);
63 }
64
65 void
66 ShareInfo::SetPageUrl(Tizen::Base::String aPageURL)
67 {
68         __pageURL.Clear();
69         __pageURL.Append(aPageURL);
70 }
71
72 Tizen::Base::String
73 ShareInfo::GetPageTitle(void)
74 {
75         return __pageTitle;
76 }
77
78 Tizen::Base::String
79 ShareInfo::GetPageURL(void)
80 {
81         return __pageURL;
82 }
83
84 void
85 ShareInfo::SetImageAttached(bool imageAttached)
86 {
87         isImageAttached = imageAttached;
88 }
89
90 bool
91 ShareInfo::GetImageAttached()
92 {
93         return isImageAttached;
94 }
95
96 void
97 ShareInfo::SetImagePath(Tizen::Base::String aImagePath)
98 {
99         __imagePath.Clear();
100         __imagePath.Append(aImagePath);
101 }
102
103 Tizen::Base::String
104 ShareInfo::GetImagePath(void)
105 {
106         return __imagePath;
107 }
108
109 SharePopup::SharePopup(void)
110 :__pList(null),__pShareList(null)
111 {
112         __appControlOngoing = false;
113 }
114
115 SharePopup::~SharePopup(void)
116 {
117
118 }
119
120 bool
121 SharePopup::Initialize(void)
122 {
123         Button* pCancelButton = null;
124
125         Popup::Construct(L"IDL_SHARE_POPUP");
126         SetName(L"CommonPopup");
127
128         __pShareList = new(std::nothrow) ArrayList();
129         __pShareList->Construct();
130
131         __pList = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW"));
132         if (__pList == null)
133         {
134                 return false;
135         }
136
137         __pList->SetItemProvider(*this);
138         __pList->AddListViewItemEventListener(*this);
139
140         pCancelButton = static_cast< Button* >(GetControl(L"IDC_BUTTON1", true));
141         if (pCancelButton)
142         {
143                 pCancelButton->AddActionEventListener(*this);
144                 pCancelButton->SetActionId(IDA_CANCEL_BUTTON);
145         }
146
147         return true;
148 }
149
150 result
151 SharePopup::OnTerminating(void)
152 {
153         result r = E_SUCCESS;
154         return r;
155 }
156
157 void
158 SharePopup::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
159 {
160         switch(actionId)
161         {
162         case IDA_CANCEL_BUTTON:
163         {
164                 Popup::SetShowState(false);
165                 Popup::Show();
166         }
167         break;
168         default:
169                 break;
170         }
171         return;
172 }
173
174 void
175 SharePopup::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
176 {
177         return;
178 }
179
180 void
181 SharePopup::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
182 {
183         switch (index)
184         {
185         case 0:
186         {
187                 if(__appControlOngoing == false)
188                 {
189                         __appControlOngoing = true;
190                         // share via message
191                         StartMessageAppControl();
192                 }
193         }
194         break;
195         case 1:
196         {
197                 if(__appControlOngoing == false)
198                 {
199                         __appControlOngoing = true;
200                         // share via email
201                         StartEmailAppControl();
202                 }
203
204         }
205         break;
206         default:
207                 break;
208         }
209 }
210
211 void
212 SharePopup::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
213 {
214         return;
215 }
216
217 void
218 SharePopup::OnListViewItemLongPressed(Tizen::Ui::Controls::ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
219 {
220         return;
221 }
222
223 Tizen::Ui::Controls::ListItemBase*
224 SharePopup::CreateItem(int index, int itemWidth)
225 {
226         result r = E_FAILURE;
227         ListAnnexStyle style = LIST_ANNEX_STYLE_NORMAL;
228         int textSize = 35;
229         int elementHeight = 50;
230         int listItemHeight = 75;
231
232         CustomItem* pItem = new(std::nothrow) CustomItem();
233         r = pItem->Construct(Dimension(GetClientAreaBounds().width, listItemHeight), style);
234         if (IsFailed(r))
235         {
236                 AppLogDebug("Create Item Failed with error %s", GetErrorMessage(r));
237                 delete pItem;
238                 return null;
239         }
240
241         switch(index)
242         {
243         case 0:
244         {
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);
248         }
249         break;
250         case 1:
251         {
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);
255         }
256         break;
257         default:
258                 break;
259         }
260         return pItem;
261 }
262
263 bool
264 SharePopup::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
265 {
266         return true;
267 }
268
269 int
270 SharePopup::GetItemCount(void)
271 {
272         return 2;
273 }
274
275 result
276 SharePopup::AddShareInfo(ShareInfo* pShareInfo)
277 {
278         result r = E_FAILURE;
279
280         if (__pShareList != NULL)
281         {
282                 r = __pShareList->Add(*pShareInfo);
283         }
284         return r;
285 }
286
287 void SharePopup::RemoveAllShareInfo()
288 {
289         __pShareList->RemoveAll();
290 }
291
292 void
293 SharePopup::StartEmailAppControl(void)
294 {
295    HashMap extraData;
296    ShareInfo* pShareInfo = null;
297    result r = E_FAILURE;
298    bool imageAttachment = false;
299
300    extraData.Construct();
301
302    if (__pShareList != null)
303         {
304                 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
305                 if (pShareInfo != null)
306                 {
307                         String testURL = pShareInfo->GetPageURL();
308                         AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
309                 }
310         }
311
312    String textVal;
313
314         if (pShareInfo != null)
315         {
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">");
321         }
322
323    String subjectKey = L"http://tizen.org/appcontrol/data/subject";
324    String subjectVal = L"";
325    String textKey = L"http://tizen.org/appcontrol/data/text";
326
327    String toKey = L"http://tizen.org/appcontrol/data/to";
328    String toVal = L"";
329    String ccKey = L"http://tizen.org/appcontrol/data/cc";
330    String ccVal = L"";
331    String bccKey = L"http://tizen.org/appcontrol/data/bcc";
332    String bccVal = L"";
333    String resultKey = L"http://tizen.org/appcontrol/data/return_result";
334    String resultVal = "true";
335
336
337    //String attachKey = L"attachments";
338    String attachKey = L"http://tizen.org/appcontrol/data/path";
339    String attachVal;
340         if (pShareInfo != null)
341         {
342                 imageAttachment = pShareInfo->GetImageAttached();
343                 if (imageAttachment)
344                 {
345                         attachVal = pShareInfo->GetImagePath();
346                         AppLog("SharePopup::StartEmailAppControl imagePath is %S",attachVal.GetPointer());
347                 }
348                 else
349                 {
350                          attachVal = L"";
351                 }
352         }
353
354         ArrayList* pDataList = null;
355         pDataList = new (std::nothrow) ArrayList();
356         pDataList->Construct();
357         pDataList->Add(&attachVal);
358
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)
366    {
367            extraData.Add(&attachKey, pDataList);
368    }
369
370    AppControl* pAc = AppManager::FindAppControlN(L"tizen.email", L"http://tizen.org/appcontrol/operation/compose");
371    if (pAc)
372    {
373           r = pAc->Start(null, null, &extraData, this);
374            delete pAc;
375    }
376
377    if (pShareInfo != null)
378    {
379            delete pShareInfo;
380    }
381    delete pDataList;
382
383 }
384
385 void
386 SharePopup::StartMessageAppControl(void)
387 {
388         HashMap extraData;
389         ShareInfo* pShareInfo = null;
390         result r = E_FAILURE;
391         bool imageAttachment = false;
392
393         extraData.Construct();
394
395         String typeKey = L"http://tizen.org/appcontrol/data/message/type";
396         String typeVal;
397         String textKey = L"http://tizen.org/appcontrol/data/text";
398         String textVal;
399         String attachKey = L"http://tizen.org/appcontrol/data/path";
400         String attachVal;
401         String resultKey = L"http://tizen.org/appcontrol/data/return_result";
402         String resultVal = "true";
403         ArrayList* pDataList = null;
404
405         if (__pShareList != null)
406         {
407                 pShareInfo = dynamic_cast<ShareInfo*>(__pShareList->GetAt(0));
408                 if (pShareInfo != null)
409                 {
410                         String testURL = pShareInfo->GetPageURL();
411                         AppLogDebug("getpageURL getpageURL is %ls", testURL.GetPointer());
412                 }
413         }
414
415         if (pShareInfo != null)
416         {
417                 textVal.Append(pShareInfo->GetPageTitle());
418                 if(pShareInfo->GetPageTitle().GetLength() > 0)
419                 {
420                         textVal.Append(L" <");
421                 }
422                 else
423                 {
424                         textVal.Append(L"<");
425                 }
426                 AppLog("share info url is %ls",pShareInfo->GetPageURL().GetPointer());
427                 textVal.Append(pShareInfo->GetPageURL().GetPointer());
428                 textVal.Append(L">");
429         }
430         if (pShareInfo != null)
431         {
432                 imageAttachment = pShareInfo->GetImageAttached();
433                 if (imageAttachment)
434                 {
435                         // type is mms
436                         typeVal = L"mms";
437                         attachVal = pShareInfo->GetImagePath();
438
439                         pDataList = new (std::nothrow) ArrayList();
440                         pDataList->Construct();
441                         pDataList->Add(&attachVal);
442                 }
443                 else
444                 {
445                         typeVal = L"sms";
446                         // type is sms
447                 }
448         }
449
450         extraData.Add(&typeKey, &typeVal);
451
452         if (imageAttachment)
453         {
454                 // type is MMMS, attach the image
455                 extraData.Add(&attachKey, pDataList);
456         }
457         else
458         {
459                 // type is SMS , attach the text
460                 extraData.Add(&textKey, &textVal);
461         }
462         extraData.Add(&resultKey, &resultVal);
463         AppControl* pAc = AppManager::FindAppControlN(L"tizen.messages", L"http://tizen.org/appcontrol/operation/compose");
464         if (pAc)
465         {
466                 r = pAc->Start(null, null, &extraData, this);
467                 delete pAc;
468         }
469
470
471
472         if (pShareInfo != null)
473         {
474                 delete pShareInfo;
475         }
476         if(pDataList)
477         {
478                 delete pDataList;
479         }
480 }
481
482 void
483 SharePopup::OnAppControlCompleted(const Tizen::Base::String& providerId, const Tizen::Base::String& operationId, const Tizen::Base::Collection::IList* pResultList)
484 {
485         AppLog("InternetApp::OnForeground called");
486
487 }
488
489 void SharePopup::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
490 {
491         AppLog("SharePopup::OnAppControlCompleteResponseReceived");
492         Popup::SetShowState(false);
493         Popup::Show();
494         __appControlOngoing = false;
495 }