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 ClEventSearcherForm.cpp
19 * @brief This is the implementation file for the EventSearcherForm class.
22 #include <FGraphics.h>
25 #include "ClEventItem.h"
26 #include "ClEventSearcherForm.h"
27 #include "ClEventSearchPresentationModel.h"
28 #include "ClResourceManager.h"
29 #include "ClSharePopup.h"
30 #include "ClThreeButtonPopup.h"
31 #include "ClTwoButtonPopup.h"
34 using namespace Tizen::Base;
35 using namespace Tizen::Base::Collection;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Social;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
42 static const RecordId ID_DEFAULT_BIRTHDAY_CALENDAR = 3;
44 static const int IDA_EVENT_SEARCHER_CONTEXT_MENU_EDIT = 50101;
45 static const int IDA_EVENT_SEARCHER_CONTEXT_MENU_SHARE = 50102;
46 static const int IDA_EVENT_SEARCHER_CONTEXT_MENU_DELETE = 50103;
48 static const int GROUP_ITEM_HEIGHT = 76;
49 static const unsigned int COLOR_GROUP_ITEM_BACKGROUND = Color32<248, 246, 239>::Value;
50 static const unsigned int COLOR_GROUP_ITEM_TODAY_BACKGROUND = Color32<239, 236, 224>::Value;
51 static const unsigned int COLOR_GROUP_ITEM_TEXT = Color32<128, 128, 128>::Value;
52 static const unsigned int COLOR_GROUP_ITEM_TODAY_TEXT = Color32<59, 115, 182>::Value;
53 static const unsigned int COLOR_ITEM_TODAY_BACKGROUND = Color32<239, 236, 224>::Value;
54 static const unsigned int COLOR_ITEM_DELETE_TEXT = Color32<255, 255, 255>::Value;
55 static const unsigned int COLOR_ITEM_DELETE_BACKGROUND = Color32<208, 82, 82>::Value;
56 static const unsigned int COLOR_ITEM_DELETE_PRESSED_BACKGROUND = Color32<194, 71, 71>::Value;
59 EventSearcherForm::EventSearcherForm(void)
61 , __pSearchBarInput(null)
62 , __pGroupedListViewEvents(null)
63 , __pContextItem(null)
64 , __pContextItemNoEdit(null)
66 , __pThreeButtonPopup(null)
67 , __pTwoButtonPopup(null)
73 EventSearcherForm::~EventSearcherForm(void)
78 EventSearcherForm::Initialize(void)
80 return Construct(L"IDL_EVENT_SEARCHER_FORM");
84 EventSearcherForm::OnInitializing(void)
86 String fontSizeString;
87 Tizen::System::SettingInfo::GetValue(L"http://tizen.org/setting/font.size", fontSizeString);
89 AppLogDebug("fontSize: %ls", fontSizeString.GetPointer());
90 if (fontSizeString == L"small")
95 else if (fontSizeString == L"medium")
100 else if (fontSizeString == L"large")
103 __itemHeight = 157.f;
105 else if (fontSizeString == L"huge")
108 __itemHeight = 176.f;
110 else if (fontSizeString == L"giant")
113 __itemHeight = 205.f;
115 __pPm = new (std::nothrow) EventSearchPresentationModel();
118 __pSearchBarInput = dynamic_cast<SearchBar*>(GetControl(L"IDC_SEARCHBAR"));
119 TryReturn(__pSearchBarInput != null, E_FAILURE, "[E_FAILURE] Unable to get searchbar.");
121 __pGroupedListViewEvents = dynamic_cast<GroupedListView*>(GetControl(L"IDC_GROUPEDLISTVIEW"));
122 TryReturn(__pGroupedListViewEvents != null, E_FAILURE, "[E_FAILURE] Unable to get groupedlistview.");
124 __pSearchBarInput->AddKeypadEventListener(*this);
125 __pSearchBarInput->AddActionEventListener(*this);
126 __pSearchBarInput->AddTextEventListener(*this);
127 __pSearchBarInput->SetContentAreaVisible(false);
128 __pSearchBarInput->SetMode(SEARCH_BAR_MODE_INPUT);
129 __pGroupedListViewEvents->SetItemProvider(*this);
130 __pGroupedListViewEvents->AddGroupedListViewItemEventListener(*this);
132 SetFormBackEventListener(this);
133 Tizen::System::SettingInfo::AddSettingEventListener(*this);
135 __pSharePopup = new (std::nothrow) SharePopup();
136 __pSharePopup->Initialize();
138 __pThreeButtonPopup = new (std::nothrow) ThreeButtonPopup();
139 __pThreeButtonPopup->Initialize();
141 __pTwoButtonPopup = new (std::nothrow) TwoButtonPopup();
142 __pTwoButtonPopup->Initialize();
144 __pContextItem = new (std::nothrow) ListContextItem();
145 __pContextItem->Construct();
146 __pContextItem->AddElement(IDA_EVENT_SEARCHER_CONTEXT_MENU_EDIT, ResourceManager::GetString(IDS_CLD_SK3_EDIT), true);
147 __pContextItem->AddElement(IDA_EVENT_SEARCHER_CONTEXT_MENU_SHARE, ResourceManager::GetString(IDS_COM_SK4_SHARE), true);
148 __pContextItem->AddElement(IDA_EVENT_SEARCHER_CONTEXT_MENU_DELETE, ResourceManager::GetString(IDS_CLD_SK3_DELETE), true);
149 __pContextItem->SetElementBackgroundColor(IDA_EVENT_SEARCHER_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, Color(COLOR_ITEM_DELETE_BACKGROUND));
150 __pContextItem->SetElementBackgroundColor(IDA_EVENT_SEARCHER_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED, Color(COLOR_ITEM_DELETE_PRESSED_BACKGROUND));
151 __pContextItem->SetElementTextColor(IDA_EVENT_SEARCHER_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, Color(COLOR_ITEM_DELETE_TEXT));
153 __pContextItemNoEdit = new (std::nothrow) ListContextItem();
154 __pContextItemNoEdit->Construct();
155 __pContextItemNoEdit->AddElement(IDA_EVENT_SEARCHER_CONTEXT_MENU_SHARE, ResourceManager::GetString(IDS_COM_SK4_SHARE), true);
161 EventSearcherForm::OnTerminating(void)
164 delete __pContextItem;
165 delete __pContextItemNoEdit;
168 __pSharePopup->Destroy();
170 if (__pThreeButtonPopup)
172 __pThreeButtonPopup->Destroy();
174 if (__pTwoButtonPopup)
176 __pTwoButtonPopup->Destroy();
178 Tizen::System::SettingInfo::RemoveSettingEventListener(*this);
183 EventSearcherForm::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
187 case IDA_EVENT_POPUP_DELETE:
188 __pPm->RemoveEvent(*static_cast<const CalEventInstance*>(pArgs->GetAt(0)));
190 case IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_EDIT:
191 pArgs->Add(new (std::nothrow) Boolean(true));
192 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
193 SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
197 AppLogException("[%d] invalid requestId", requestId);
203 pArgs->RemoveAll(true);
209 EventSearcherForm::OnActionPerformed(const Control& source, int actionId)
211 if (actionId == __pSearchBarInput->GetButtonActionId())
213 __pSearchBarInput->SetMode(SEARCH_BAR_MODE_NORMAL);
214 __pSearchBarInput->Invalidate(false);
215 if (__pPm->GetSearchText() != __pSearchBarInput->GetText())
217 __pPm->SearchEvent(__pSearchBarInput->GetText());
218 __pGroupedListViewEvents->UpdateList();
224 EventSearcherForm::OnTextValueChanged(const Control& source)
226 if (__pPm->GetSearchText() != __pSearchBarInput->GetText())
228 __pPm->SearchEvent(__pSearchBarInput->GetText());
229 __pGroupedListViewEvents->UpdateList();
234 EventSearcherForm::OnTextValueChangeCanceled(const Control& source)
236 AppLogDebug("Enter");
237 if (__pPm->GetSearchText() != __pSearchBarInput->GetText())
239 __pPm->SearchEvent(__pSearchBarInput->GetText());
240 __pGroupedListViewEvents->UpdateList();
245 EventSearcherForm::OnFormBackRequested(Form& source)
248 SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
252 EventSearcherForm::GetGroupCount(void)
254 return __pPm->GetWholeDayCount();
258 EventSearcherForm::GetItemCount(int groupIndex)
260 return __pPm->GetWholeEventCount(groupIndex);
264 EventSearcherForm::CreateGroupItem(int groupIndex, int itemWidth)
266 GroupItem* pItem = new (std::nothrow) GroupItem();
267 pItem->Construct(Dimension(itemWidth, GROUP_ITEM_HEIGHT));
269 DateTime date = __pPm->GetDateTimeFromGroupIndex(groupIndex);
270 pItem->SetElement(__pPm->GetDateString(date));
272 if (EventSearchPresentationModel::IsToday(date) == true)
274 pItem->SetTextColor(Color(COLOR_GROUP_ITEM_TODAY_TEXT));
278 pItem->SetTextColor(Color(COLOR_GROUP_ITEM_TEXT));
285 EventSearcherForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
292 EventSearcherForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
294 const CalEvent* pEvent = __pPm->GetEvent(groupIndex, itemIndex);
300 DateTime startWallTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetStartTime());
301 DateTime endWallTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetEndTime());
303 EventItem* pItem = new (std::nothrow) EventItem();
304 pItem->Initialize(EVENT_ITEM_STYLE_NORMAL, itemWidth, __itemHeight);
305 pItem->SetTitle(pEvent->GetSubject());
306 pItem->SetFontSize(__fontSize);
307 pItem->SetLocation(pEvent->GetLocation());
308 pItem->SetSearchText(__pPm->GetSearchText());
309 pItem->SetCalendarColor(__pPm->GetCalendarColor(pEvent->GetCalendarId()));
310 if (pEvent->IsAllDayEvent() == true)
312 pItem->SetAllDayEvent();
316 pItem->SetDateRange(startWallTime, endWallTime, __pPm->GetDateTimeFromGroupIndex(groupIndex), __pPm->GetTimeFormatter());
319 pItem->SetReminder(pEvent->GetAllReminders().GetCount() > 0);
320 pItem->SetRepeat(pEvent->IsRecurring());
321 pItem->SetPriority(pEvent->GetPriority());
323 pItem->SetContextItem((pEvent->GetCalendarId() == ID_DEFAULT_BIRTHDAY_CALENDAR) ? __pContextItemNoEdit : __pContextItem);
325 pItem->UpdateElements();
330 EventSearcherForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
337 EventSearcherForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex,
338 int elementId, ListItemStatus status)
341 if (status == LIST_ITEM_STATUS_SELECTED)
343 LinkedList* pList = new (std::nothrow) LinkedList(SingleObjectDeleter);
344 pList->Add(__pPm->GetEventInstanceN(groupIndex, itemIndex));
345 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_DETAILS,
346 SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
351 EventSearcherForm::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex, SweepDirection direction)
356 EventSearcherForm::OnGroupedListViewContextItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex,
357 int elementId, ListContextItemStatus status)
360 CalEventInstance* pEventInstance = __pPm->GetEventInstanceN(groupIndex, itemIndex);
361 if (pEventInstance && status == LIST_CONTEXT_ITEM_STATUS_SELECTED)
365 case IDA_EVENT_SEARCHER_CONTEXT_MENU_EDIT:
367 LinkedList* pList = new (std::nothrow) LinkedList(SingleObjectDeleter);
368 pList->Add(new (std::nothrow) CalEventInstance(*pEventInstance));
369 pList->Add(new (std::nothrow) Boolean(true));
370 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
371 SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
374 case IDA_EVENT_SEARCHER_CONTEXT_MENU_SHARE:
375 __pSharePopup->RequestShare(pEventInstance->GetOriginalEventId());
377 case IDA_EVENT_SEARCHER_CONTEXT_MENU_DELETE:
378 if (__pPm->IsEditableAllEvent(*pEventInstance))
380 __pTwoButtonPopup->RequestPopup(TWO_BUTTON_POPUP_STYLE_REPEATED_EVENT, this, pEventInstance);
384 __pTwoButtonPopup->RequestPopup(TWO_BUTTON_POPUP_STYLE_SINGLE_EVENT, this, pEventInstance);
389 delete pEventInstance;
393 EventSearcherForm::OnGroupedListViewItemLongPressed(GroupedListView& listView, int groupIndex, int itemIndex,
394 int elementId, bool& invokeListViewItemCallback)
399 EventSearcherForm::OnGroupedListViewGroupItemSelected(GroupedListView& listView, int groupIndex)
401 if (__pGroupedListViewEvents->IsGroupExpanded(groupIndex) == true)
403 __pGroupedListViewEvents->CollapseGroup(groupIndex);
407 __pGroupedListViewEvents->ExpandGroup(groupIndex);
412 EventSearcherForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
414 __pGroupedListViewEvents->UpdateList();
415 __pPm->AddCalendarEventChangedEventListener(*this);
419 EventSearcherForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
421 __pPm->RemoveCalendarEventChangedEventListener(*this);
425 EventSearcherForm::OnSettingChanged(Tizen::Base::String& key)
427 if (key.Equals(KEY_SYSTEM_DATE,false))
429 __pGroupedListViewEvents->UpdateList();
434 EventSearcherForm::OnKeypadWillOpen(Control& source)
439 EventSearcherForm::OnKeypadOpened(Control& source)
444 EventSearcherForm::OnKeypadClosed(Control& source)
449 EventSearcherForm::OnKeypadActionPerformed(Control& source, KeypadAction keypadAction)
451 AppLogDebug("Enter");
452 if (keypadAction == KEYPAD_ACTION_SEARCH)
454 if (__pPm->GetSearchText() != __pSearchBarInput->GetText())
456 __pPm->SearchEvent(__pSearchBarInput->GetText());
457 __pGroupedListViewEvents->UpdateList();
459 __pSearchBarInput->HideKeypad();
464 EventSearcherForm::OnCalendarEventChanged(void)
466 __pGroupedListViewEvents->UpdateList();