2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.1 (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
8 // http://floralicense.org/license/
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.
18 * @file ClEventSelectorForm.cpp
19 * @brief This is the implementation file for the EventSelectorForm class.
22 #include "ClCalendarApp.h"
23 #include "ClEventItem.h"
24 #include "ClEventSelectorForm.h"
25 #include "ClMainFrame.h"
26 #include "ClResourceManager.h"
29 using namespace Tizen;
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Social;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
39 const int IDA_EVENT_SELECTOR_FORM_FOOTER_DONE = 70001;
41 EventSelectorForm::EventSelectorForm(void)
42 : __selectionType(EVENT_SELECTOR_FORM_SELECTION_TYPE_SINGLE)
44 , __pListViewContents(null)
45 , __pCalendarbook(null)
46 , __pTimeFormatter(null)
50 EventSelectorForm::~EventSelectorForm(void)
55 EventSelectorForm::Initialize(void)
57 return Construct(L"IDL_EVENT_SELECTOR_FORM");
61 EventSelectorForm::OnInitializing(void)
63 SetFormBackEventListener(this);
64 Footer* pFooter = GetFooter();
65 pFooter->AddActionEventListener(*this);
67 Calendarbook* pCalendarbook = new (std::nothrow) Calendarbook();
68 pCalendarbook->Construct(*this);
70 CalendarbookFilter calendarFilter(CB_FI_TYPE_CALENDAR);
71 calendarFilter.AppendInt(FI_CONJ_OP_NONE, CALENDAR_FI_PR_ITEM_TYPE, FI_CMP_OP_EQUAL, CALENDAR_ITEM_TYPE_EVENT_ONLY);
72 IList* pAllCalendars = pCalendarbook->SearchN(calendarFilter);
73 __allCalendars.Construct(pAllCalendars->GetCount());
74 IEnumerator* pEnum = pAllCalendars->GetEnumeratorN();
75 while (pEnum->MoveNext() == E_SUCCESS)
77 Calendar* pCalendar = static_cast<Calendar*>(pEnum->GetCurrent());
78 __allCalendars.Add(new (std::nothrow) Integer(pCalendar->GetRecordId()), pCalendar);
81 pAllCalendars->RemoveAll(false);
84 __pDateFormatter = ResourceManager::CreateDateFormatterN(Locales::DATE_TIME_STYLE_SHORT);
85 __pTimeFormatter = ResourceManager::CreateTimeFormatterN();
87 __pListViewContents = dynamic_cast<ListView*>(GetControl(L"IDC_LISTVIEW"));
88 TryCatch(__pListViewContents != null, , "[E_FAILURE] Unable to get listview.");
90 __pListViewContents->SetItemProvider(*this);
91 __pListViewContents->AddListViewItemEventListener(*this);
92 __pCalendarbook = pCalendarbook;
101 EventSelectorForm::OnTerminating(void)
103 __allCalendars.RemoveAll(true);
105 if (__pEvents != null)
107 __pEvents->RemoveAll(true);
111 delete __pCalendarbook;
112 delete __pDateFormatter;
113 delete __pTimeFormatter;
118 EventSelectorForm::OnFormBackRequested(Form& source)
120 result r = SendAppControlResult(APP_CTRL_RESULT_CANCELED);
121 AppLogDebugIf(r != E_SUCCESS, "[%s] Unable to return result.", GetErrorMessage(r));
123 UiApp::GetInstance()->Terminate();
127 EventSelectorForm::GetItemCount(void)
129 if (__pEvents == null)
133 return __pEvents->GetCount();
137 EventSelectorForm::CreateItem(int index, int itemWidth)
139 if (__pEvents == null)
144 CalEvent* pEvent = static_cast<CalEvent*>(__pEvents->GetAt(index));
145 EventItem* pItem = new (std::nothrow) EventItem();
146 pItem->Initialize((__selectionType == EVENT_SELECTOR_FORM_SELECTION_TYPE_SINGLE) ? EVENT_ITEM_STYLE_NORMAL : EVENT_ITEM_STYLE_SELECTION, itemWidth);
147 pItem->SetTitle(pEvent->GetSubject());
148 pItem->SetCalendarColor(GetCalendarColor(pEvent->GetCalendarId()));
149 pItem->SetLocation(pEvent->GetLocation());
150 DateTime startTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetStartTime());
151 DateTime endTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetEndTime());
152 pItem->SetDateRangeText(GetDateRangeText(startTime, endTime, pEvent->IsAllDayEvent()));
153 pItem->SetReminder(pEvent->GetAllReminders().GetCount() > 0);
154 pItem->SetRepeat(pEvent->IsRecurring());
155 pItem->SetPriority(pEvent->GetPriority());
156 // pItem->SetFacebookEvent(false);
157 pItem->UpdateElements();
163 EventSelectorForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)
170 EventSelectorForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
172 if (status == LIST_ITEM_STATUS_SELECTED && __selectionType == EVENT_SELECTOR_FORM_SELECTION_TYPE_SINGLE)
174 result r = E_SUCCESS;
175 LinkedList* pArgs = new (std::nothrow) LinkedList();
176 pArgs->Add(__pEvents->GetAt(index));
177 r = SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pArgs);
178 pArgs->RemoveAll(false);
180 TryCatch(r == E_SUCCESS, , "[%s] Unable to return result.", GetErrorMessage(r));
182 UiApp::GetInstance()->Terminate();
186 SendAppControlResult(APP_CTRL_RESULT_FAILED);
187 UiApp::GetInstance()->Terminate();
192 EventSelectorForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
198 EventSelectorForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus status)
204 EventSelectorForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
210 EventSelectorForm::OnListViewItemReordered(ListView& listView, int indexFrom, int indexTo)
216 EventSelectorForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
220 pArgs->RemoveAll(true);
224 CalendarApp* pApp = static_cast<CalendarApp*>(UiApp::GetInstance());
225 const String* pItemType = null;
226 const String* pSelectionMode = pApp->GetArgument(KEY_DATA_SELECTION_MODE);
227 if (pSelectionMode != null && pSelectionMode->Equals(VALUE_CALENDAR_MULTIPLE_SELECTION_MODE, false) == true)
229 __selectionType = EVENT_SELECTOR_FORM_SELECTION_TYPE_MULTIPLE;
232 TryCatch(pApp->GetArgument(KEY_SOCIAL_RESULT_TYPE) != null, , "[E_FAILURE] Unable to get result type.");
234 pItemType = pApp->GetArgument(KEY_SOCIAL_ITEM_TYPE);
235 TryCatch(pItemType != null, , "[E_FAILURE] Unable to get item type.");
236 TryCatch(pItemType->Equals(VALUE_CALENDAR_EVENT_TYPE, false) == true, , "[E_FAILURE] Invalid item type.");
238 if (__selectionType == EVENT_SELECTOR_FORM_SELECTION_TYPE_SINGLE)
240 GetFooter()->RemoveAllItems();
244 __pListViewContents->UpdateList();
248 SendAppControlResult(APP_CTRL_RESULT_FAILED);
249 UiApp::GetInstance()->Terminate();
253 EventSelectorForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
259 EventSelectorForm::OnActionPerformed(const Control& source, int actionId)
263 case IDA_EVENT_SELECTOR_FORM_FOOTER_DONE:
264 result r = E_SUCCESS;
266 LinkedList* pArgs = new (std::nothrow) LinkedList();
267 IEnumerator* pEnum = __pEvents->GetEnumeratorN();
268 while (pEnum->MoveNext() == E_SUCCESS)
270 if (__pListViewContents->IsItemChecked(index++) == true)
272 pArgs->Add(pEnum->GetCurrent());
276 r = SendAppControlResult(APP_CTRL_RESULT_SUCCEEDED, pArgs);
277 pArgs->RemoveAll(false);
279 TryCatch(r == E_SUCCESS, , "[%s] Unable to return result.", GetErrorMessage(r));
281 UiApp::GetInstance()->Terminate();
285 SendAppControlResult(APP_CTRL_RESULT_FAILED);
286 UiApp::GetInstance()->Terminate();
292 EventSelectorForm::CreateColorBarBitmapN(const Dimension& size, const Color& color)
294 Bitmap* pBitmap = new (std::nothrow) Bitmap();
295 pBitmap->Construct(size, BITMAP_PIXEL_FORMAT_ARGB8888);
297 BufferInfo bufferinfo;
298 pBitmap->Lock(bufferinfo);
301 canvas.Construct(bufferinfo);
302 canvas.SetBackgroundColor(color);
311 EventSelectorForm::GetCalendarColor(const RecordId& calendarId) const
313 const Calendar* pCalendar = static_cast<const Calendar*>(__allCalendars.GetValue(Integer(calendarId)));
317 pCalendar->GetColor(r, g, b);
318 return Color(r, g, b);
322 EventSelectorForm::GetDateRangeText(const DateTime& start, const DateTime& end, bool isAllDayEvent) const
324 if (start.GetYear() == end.GetYear() && start.GetMonth() == end.GetMonth() && start.GetDay() == end.GetDay())
327 __pDateFormatter->Format(start, dateText);
328 if (isAllDayEvent == true)
335 __pTimeFormatter->Format(start, startText);
336 __pTimeFormatter->Format(end, endText);
337 return dateText + L" " + startText + L" ~ " + endText;
340 String startDateText;
342 __pDateFormatter->Format(start, startDateText);
343 __pDateFormatter->Format(end, endDateText);
344 if (isAllDayEvent == true)
346 return startDateText + L" ~ " + endDateText;
349 String startTimeText;
351 __pTimeFormatter->Format(start, startTimeText);
352 __pTimeFormatter->Format(end, endTimeText);
353 return startDateText + L" " + startTimeText + L" ~ " + endDateText + L" " + endTimeText;
357 EventSelectorForm::LoadAllEvents(void)
359 CalendarbookFilter eventFilter(CB_FI_TYPE_EVENT);
360 IList* pList = __pCalendarbook->SearchN(eventFilter);
361 TryReturn(pList != null, E_FAILURE, "[E_FAILURE] Unable to get events.");
363 if (__pEvents != null)
365 __pEvents->RemoveAll(true);
373 EventSelectorForm::SendAppControlResult(AppCtrlResult appControlResult, const IList* pResultList)
375 CalendarApp* pApp = static_cast<CalendarApp*>(UiApp::GetInstance());
376 TryReturn(pApp != null, E_FAILURE, "[E_FAILURE] Unable to get app instance.");
378 HashMap* pArgs = null;
379 if (pResultList != null && pResultList->GetCount() > 0)
381 pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
384 const String* pResultType = pApp->GetArgument(KEY_SOCIAL_RESULT_TYPE);
385 if (pResultType != null && *pResultType == VALUE_SOCIAL_ITEM_ID)
387 int itemCount = pResultList->GetCount();
388 ArrayList* pEvents = new (std::nothrow) ArrayList(SingleObjectDeleter);
389 pEvents->Construct(itemCount);
390 for (int i = 0; i < itemCount; ++i)
392 pEvents->Add(new (std::nothrow) String(Integer::ToString(static_cast<const CalEvent*>(pResultList->GetAt(i))->GetRecordId())));
394 pArgs->Add(new (std::nothrow) String(KEY_SOCIAL_ITEM_ID), pEvents);
398 String* pPath = new (std::nothrow) String(CalendarApp::GetExportVcsFilePath());
399 __pCalendarbook->ExportEventsToVcalendar(*pResultList, *pPath);
401 ArrayList* pPaths = new (std::nothrow) ArrayList(SingleObjectDeleter);
402 pPaths->Construct(1);
404 pArgs->Add(new (std::nothrow) String(KEY_DATA_PATH), pPaths);
408 result r = AppControlProviderManager::GetInstance()->SendAppControlResult(pApp->GetRequestId(), appControlResult, pArgs);
411 AppLogDebugIf(r != E_SUCCESS, "[%s] Unable to return result.", GetErrorMessage(r));
416 EventSelectorForm::OnCalendarEventsChanged(const IList& eventChangeInfoList)
419 __pListViewContents->UpdateList();
423 EventSelectorForm::OnCalendarTodosChanged(const IList& todoChangeInfoList)