7a0b802d30610333f715cdae4390b819ef7071ac
[apps/osp/Calendar.git] / src / ClSharePopup.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        ClSharePopup.cpp
19  * @brief       This is the implementation file for the SharePopup class.
20  */
21
22 #include <FApp.h>
23 #include <FBase.h>
24 #include <FGraphics.h>
25 #include <FIo.h>
26 #include "ClCalendarApp.h"
27 #include "ClSharePopup.h"
28 #include "ClResourceManager.h"
29 #include "ClTypes.h"
30
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Io;
36 using namespace Tizen::Social;
37 using namespace Tizen::Ui;
38 using namespace Tizen::Ui::Controls;
39
40 enum{
41         SHARE_EMAIL = 0,
42         SHARE_MESSAGE,
43         SHARE_COUNT
44 };
45
46 static const int IDA_SHARE_POPUP_CLOSE = 63010;
47 static const int IDA_SHARE_ITEM = 63020;
48
49 static const int H_ITEM = 110;
50 static const int W_ITEM_MARGIN = 45;
51
52 SharePopup::SharePopup(void)
53         : __pListView(null)
54         , __eventId(INVALID_RECORD_ID)
55 {
56 }
57
58 SharePopup::~SharePopup(void)
59 {
60 }
61
62 result
63 SharePopup::Initialize(void)
64 {
65         return Construct(L"IDL_SHARE_POPUP");
66 }
67
68 result
69 SharePopup::RequestShare(RecordId eventId)
70 {
71         __eventId = eventId;
72         SetShowState(true);
73         return Show();
74 }
75
76 result
77 SharePopup::OnInitializing(void)
78 {
79         __pListView = dynamic_cast<ListView*>(GetControl(L"IDC_LISTVIEW_SHARE"));
80         AppAssertf(__pListView != null, "[E_FAILURE] Unable to get listview.");
81         __pListView->SetItemProvider(*this);
82         __pListView->AddListViewItemEventListener(*this);
83         // TBD : Below code will be deleted.(Tizen SDK 2.0 has a defect on first drawing.)
84         __pListView->UpdateList();
85
86         Button* pButtonCancel = dynamic_cast<Button*>(GetControl(L"IDC_BUTTON_CLOSE"));
87         AppAssertf(pButtonCancel != null, "[E_FAILURE] Unable to get button.");
88         pButtonCancel->SetActionId(IDA_SHARE_POPUP_CLOSE);
89         pButtonCancel->AddActionEventListener(*this);
90
91         return E_SUCCESS;
92 }
93
94 result
95 SharePopup::OnTerminating(void)
96 {
97         return E_SUCCESS;
98 }
99
100 int
101 SharePopup::GetItemCount(void)
102 {
103         return SHARE_COUNT;
104 }
105
106 ListItemBase*
107 SharePopup::CreateItem(int index, int itemWidth)
108 {
109         CustomItem* pItem = new (std::nothrow) CustomItem();
110         pItem->Construct(Dimension(itemWidth, H_ITEM), LIST_ANNEX_STYLE_NORMAL);
111
112         switch (index)
113         {
114         case SHARE_EMAIL:
115                 pItem->AddElement(Rectangle(W_ITEM_MARGIN, 0, itemWidth - (W_ITEM_MARGIN << 1), H_ITEM),
116                                                  IDA_SHARE_ITEM, ResourceManager::GetString(IDS_CLD_OPT_SENDVIA_EMAIL));
117                 break;
118         case SHARE_MESSAGE:
119                 pItem->AddElement(Rectangle(W_ITEM_MARGIN, 0, itemWidth - (W_ITEM_MARGIN << 1), H_ITEM),
120                                                  IDA_SHARE_ITEM, ResourceManager::GetString(IDS_CLD_OPT_MESSAGE_SEND_VIA));
121                 break;
122         }
123
124         return pItem;
125 }
126
127 bool
128 SharePopup::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
129 {
130         return true;
131 }
132
133 void
134 SharePopup::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
135 {
136         if (status == LIST_ITEM_STATUS_SELECTED)
137         {
138                 String operationId;
139                 String uri;
140                 switch (index)
141                 {
142                 case SHARE_EMAIL:
143                         operationId = L"http://tizen.org/appcontrol/operation/compose";
144                         uri = L"mailto:";
145                         break;
146                 case SHARE_MESSAGE:
147                         operationId = L"http://tizen.org/appcontrol/operation/compose";
148                         uri = L"mmsto:";
149                         break;
150                 default:
151                         AppLogDebug("[E_FAILURE] Invalid condition.");
152                         return;
153                 }
154
155                 Calendarbook calendarbook;
156                 calendarbook.Construct();
157                 CalEvent* pEvent = calendarbook.GetEventN(__eventId);
158                 TryReturnVoid(pEvent != null, "[E_FAILURE] Unable to get event.(ID=%d)", __eventId);
159
160                 HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
161                 pArgs->Construct(1);
162
163                 String* pPath = new (std::nothrow) String(CalendarApp::GetExportVcsFilePath());
164                 LinkedList events(SingleObjectDeleter);
165                 events.Add(calendarbook.GetEventN(__eventId));
166                 calendarbook.ExportEventsToVcalendar(events, *pPath);
167
168                 ArrayList* pPaths = new (std::nothrow) ArrayList(SingleObjectDeleter);
169                 pPaths->Construct(1);
170                 pPaths->Add(pPath);
171                 pArgs->Add(new (std::nothrow) String(KEY_DATA_PATH), pPaths);
172
173                 AppControl::FindAndStart(operationId, &uri, null, null, pArgs, null);
174                 delete pArgs;
175
176                 SetShowState(false);
177         }
178 }
179
180 void
181 SharePopup::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
182 {
183 }
184
185 void
186 SharePopup::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus status)
187 {
188 }
189
190 void
191 SharePopup::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
192 {
193 }
194
195 void
196 SharePopup::OnListViewItemReordered(ListView& listView, int indexFrom, int indexTo)
197 {
198 }
199
200 void
201 SharePopup::OnActionPerformed(const Control& source, int actionId)
202 {
203         if (actionId == IDA_SHARE_POPUP_CLOSE)
204         {
205                 SetShowState(false);
206         }
207 }