Updates license
[apps/osp/Calendar.git] / src / ClEventDeleterForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
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        ClEventDeleterForm.cpp
19  * @brief       This is the implementation file for the EventDeleterForm class.
20  */
21
22 #include <FApp.h>
23 #include "ClEventDeleterForm.h"
24 #include "ClMainFrame.h"
25 #include "ClResourceManager.h"
26 #include "ClEventListPresentationModel.h"
27 #include "ClTypes.h"
28 #include "ClEventItem.h"
29 #include "ClTwoButtonPopup.h"
30
31 using namespace Tizen;
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Runtime;
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;
41 using namespace Tizen::Locales;
42
43 static const int IDA_EVENT_DELETER_FORM_FOOTER_DELETE = 75001;
44 static const int IDA_EVENT_DELETER_FORM_DELETE_COMPLETE = 75009;
45 static const int IDA_SELECT_ALL_CHECKED = 75010;
46 static const int IDA_SELECT_ALL_UNCHECKED = 75011;
47 static const int IDA_BEFORE_TODAY_CHECKED = 75020;
48 static const int IDA_BEFORE_TODAY_UNCHECKED = 75021;
49
50 static const int ID_LIST_ITEM_BEFORE_AFTER = 100;
51
52 static const int H_ITEM = 112;
53 static const int H_GROUP_ITEM = 76;
54 static const int H_COUNT_LABEL = 48;
55 static const int LEFT_MARGIN = 16;
56 static const int TOTAL_MARGIN = 32;
57 static const int FONT_SIZE_EVENT_SUB_LIST = 32;
58 static const int TOP_BOTTOM_GROUP_ITEM_COUNT = 2;
59 static const int TOP_BOTTOM_ITEM_COUNT = 1;
60 static const int H_GROUP_ITEM_MINIMUM = 0;
61 static const int PREVIOUS_DATE = -1;
62 static const int NEXT_DATE = 1;
63
64 static const unsigned int COLOR_GROUP_ITEM_BACKGROUND = Color32<248, 246, 239>::Value;
65 static const unsigned int COLOR_GROUP_ITEM_TODAY_BACKGROUND = Color32<239, 236, 224>::Value;
66 static const unsigned int COLOR_GROUP_ITEM_TEXT = Color32<128, 128, 128>::Value;
67 static const unsigned int COLOR_GROUP_ITEM_TODAY_TEXT = Color32<59, 115, 182>::Value;
68 static const unsigned int COLOR_TOP_BOTTOM_ITEM_TEXT = Color32<42, 137, 194>::Value;
69 static const unsigned int COLOR_ITEM_BACKGROUND = Color32<248, 246, 239>::Value;
70 static const unsigned int COLOR_ITEM_TODAY_BACKGROUND = Color32<239, 236, 224>::Value;
71 static const unsigned int COLOR_ITEM_TEXT_PRESSED = Color32<255, 255, 255>::Value;
72
73
74 class AsyncDeleter
75         : public Thread
76 {
77 public:
78         result Initialize(EventListPresentationModel* pPm, IList* pList, Control* pTarget);
79
80         virtual Object* Run(void);
81 private:
82         EventListPresentationModel* __pPm;
83         IList* __pList;
84         Control* __pTarget;
85 };
86
87 result
88 AsyncDeleter::Initialize(EventListPresentationModel* pPm, IList* pList, Control* pTarget)
89 {
90         __pPm = pPm;
91         __pList = pList;
92         __pTarget = pTarget;
93         return Construct(DEFAULT_STACK_SIZE, THREAD_PRIORITY_LOW);
94 }
95
96 Object*
97 AsyncDeleter::Run(void)
98 {
99         __pPm->RemoveEvents(*__pList, true);
100         delete __pList;
101
102         if (__pTarget != null)
103         {
104                 __pTarget->SendUserEvent(IDA_EVENT_DELETER_FORM_DELETE_COMPLETE, null);
105         }
106         return null;
107 }
108
109 EventDeleterForm::EventDeleterForm(void)
110         : __pPm(null)
111         , __pList(null)
112         , __pGroupedListViewDeleteList(null)
113         , __pCalendarbook(null)
114         , __pDateFormatter(null)
115         , __pTimeFormatter(null)
116         , __pSelectAll(null)
117         , __pSelectBeforeToday(null)
118         , __pPanel(null)
119         , __pLabel(null)
120         , __pTwoButtonPopup(null)
121         , __pThread(null)
122         , __pProgressPopup(null)
123         , __topBottomItemEnabled(false)
124 {
125 }
126
127 EventDeleterForm::~EventDeleterForm(void)
128 {
129
130 }
131
132 result
133 EventDeleterForm::Initialize(void)
134 {
135         return Construct(L"IDL_EVENT_DELETER_FORM");
136 }
137
138 result
139 EventDeleterForm::OnInitializing(void)
140 {
141         SetFormBackEventListener(this);
142         Footer* pFooter = GetFooter();
143         pFooter->AddActionEventListener(*this);
144
145         __pPanel = dynamic_cast<Panel*>(GetControl(L"IDC_PANEL"));
146         AppAssertf(__pPanel != null, "[E_FAILURE] Unable to get Panel.");
147
148         __pSelectAll = dynamic_cast<CheckButton*>(GetControl(L"IDC_SELECTALL_CHECKBUTTON", true));
149         AppAssertf(__pSelectAll != null, "[E_FAILURE] Unable to get CheckButton.");
150         __pSelectAll->SetActionId(IDA_SELECT_ALL_CHECKED, IDA_SELECT_ALL_UNCHECKED);
151         __pSelectAll->SetEnabled(false);
152         __pSelectAll->AddActionEventListener(*this);
153
154         __pSelectBeforeToday = dynamic_cast<CheckButton*>(GetControl(L"IDC_BEFORETODAY_CHECKBUTTON", true));
155         AppAssertf(__pSelectBeforeToday != null, "[E_FAILURE] Unable to get CheckButton.");
156         __pSelectBeforeToday->SetActionId(IDA_BEFORE_TODAY_CHECKED, IDA_BEFORE_TODAY_UNCHECKED);
157         __pSelectBeforeToday->AddActionEventListener(*this);
158         __pSelectBeforeToday->SetEnabled(false);
159         __pSelectBeforeToday->SetShowState(false);
160         __pPanel->SetSize(Dimension(GetClientAreaBounds().width, H_ITEM));
161
162         __pGroupedListViewDeleteList = dynamic_cast<GroupedListView*>(GetControl(L"IDC_GROUPEDLISTVIEW"));
163         AppAssertf(__pGroupedListViewDeleteList != null, "[E_FAILURE] Unable to get GroupedListView.");
164         __pGroupedListViewDeleteList->SetItemProvider(*this);
165         __pGroupedListViewDeleteList->SetTextOfEmptyList(ResourceManager::GetString(IDS_CLD_BODY_NO_EVENTS));
166         __pGroupedListViewDeleteList->SetBitmapOfEmptyList(ResourceManager::GetBitmapN(IDB_LIST_VIEW_NO_CONTENTS_TEXT));
167         __pGroupedListViewDeleteList->AddGroupedListViewItemEventListener(*this);
168
169         __pLabel = dynamic_cast<Label*>(GetControl(L"IDC_LABEL"));
170         AppAssertf(__pLabel != null, "[E_FAILURE] Unable to get Label.");
171
172         __pPm = EventListPresentationModel::GetInstance();
173
174         __pDateFormatter = ResourceManager::CreateDateFormatterN(DATE_TIME_STYLE_SHORT);
175
176         __pTwoButtonPopup = new (std::nothrow) TwoButtonPopup();
177         __pTwoButtonPopup->Initialize();
178
179         return E_SUCCESS;
180 }
181
182 result
183 EventDeleterForm::OnTerminating(void)
184 {
185         if (__pThread != null)
186         {
187                 __pThread->Join();
188                 delete __pThread;
189         }
190
191         delete __pCalendarbook;
192         delete __pDateFormatter;
193         delete __pTimeFormatter;
194         if (__pTwoButtonPopup != null)
195         {
196                 __pTwoButtonPopup->Destroy();
197         }
198         if (__pProgressPopup != null)
199         {
200                 __pProgressPopup->Destroy();
201         }
202         __pPm->RemoveCalendarEventChangedEventListener(*this);
203
204         return E_SUCCESS;
205 }
206
207 void
208 EventDeleterForm::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
209 {
210         switch (requestId)
211         {
212         case IDA_EVENT_POPUP_DELETE:
213         {
214                 if (__pThread != null)
215                 {
216                         __pThread->Join();
217                         delete __pThread;
218                 }
219
220                 if (__pProgressPopup == null)
221                 {
222                         __pProgressPopup = new (std::nothrow) ProgressPopup();
223                         __pProgressPopup->Construct(false, false);
224                 }
225                 __pProgressPopup->SetShowState(true);
226                 __pProgressPopup->Show();
227
228                 LinkedList* pDeleteEvents = new (std::nothrow) LinkedList(SingleObjectDeleter);
229                 for (int i = __pGroupedListViewDeleteList->GetGroupCount() - 1; i >= 0; i--)
230                 {
231                         for (int j = __pGroupedListViewDeleteList->GetItemCountAt(i) - 1; j >= 0 ; j--)
232                         {
233                                 if (__pGroupedListViewDeleteList->IsItemChecked(i, j) == true)
234                                 {
235                                         int actualGroupIndex = i;
236                                         if (__topBottomItemEnabled == true)
237                                         {
238                                                 actualGroupIndex -= TOP_BOTTOM_ITEM_COUNT;
239                                         }
240                                         pDeleteEvents->Add(new (std::nothrow) CalEventInstance(*__pPm->GetEventWithWholeIndex(actualGroupIndex, j)));
241                                         __pGroupedListViewDeleteList->SetItemChecked(i, j, false);
242                                 }
243                         }
244                 }
245
246                 AsyncDeleter* pAsyncDeleter = new (std::nothrow) AsyncDeleter();
247                 pAsyncDeleter->Initialize(__pPm, pDeleteEvents, this);
248                 pAsyncDeleter->Start();
249                 __pThread = pAsyncDeleter;
250                 break;
251         }
252         case IDA_EVENT_DELETER_FORM_DELETE_COMPLETE:
253                 __pThread->Join();
254                 delete __pThread;
255                 __pThread = null;
256                 __pProgressPopup->SetShowState(false);
257
258                 __pGroupedListViewDeleteList->UpdateList();
259
260                 __pSelectAll->SetSelected(IsSelectedAllEvent());
261                 __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
262                 UpdateSelectedLabel();
263                 break;
264         default:
265                 break;
266         }
267
268         if (pArgs != null)
269         {
270                 pArgs->RemoveAll(true);
271                 delete pArgs;
272         }
273 }
274
275 void
276 EventDeleterForm::OnFormBackRequested(Form& source)
277 {
278         SceneManager::GetInstance()->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
279 }
280
281 int
282 EventDeleterForm::GetGroupCount(void)
283 {
284         int groupCount = __pPm->GetWholeDayCount();
285
286         if (groupCount == 1 && __pPm->GetEventWithWholeIndex(0, 0) == null)
287         {
288                 groupCount = 0;
289         }
290
291         if (groupCount != 0 && __topBottomItemEnabled == true)
292         {
293                 groupCount += TOP_BOTTOM_GROUP_ITEM_COUNT;
294         }
295
296         return groupCount;
297 }
298
299 int
300 EventDeleterForm::GetItemCount(int groupIndex)
301 {
302         int itemCount = 0;
303         int actualGroupIndex = groupIndex;
304
305         if (__topBottomItemEnabled == true)
306         {
307                 if (groupIndex == 0 || groupIndex == GetGroupCount() - 1)
308                 {
309                         return TOP_BOTTOM_ITEM_COUNT;
310                 }
311                 else
312                 {
313                         actualGroupIndex = groupIndex - (TOP_BOTTOM_GROUP_ITEM_COUNT / 2);
314                 }
315         }
316
317         itemCount = __pPm->GetWholeEventCount(actualGroupIndex);
318
319         return itemCount;
320 }
321
322 GroupItem*
323 EventDeleterForm::CreateGroupItem(int groupIndex, int itemWidth)
324 {
325         GroupItem* pItem = new (std::nothrow) GroupItem();
326
327         DateTime date;
328
329         if (__topBottomItemEnabled == true && (groupIndex == 0 || groupIndex == GetGroupCount() - 1))
330         {
331                 pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM_MINIMUM));
332                 return pItem;
333         }
334
335         String dateString;
336         int actualGroupIndex = groupIndex;
337         int itemCount = 0;
338
339         if (__topBottomItemEnabled == true)
340         {
341                 actualGroupIndex -= 1;
342         }
343
344         date = __pPm->GetDateTimeFromGroupIndex(actualGroupIndex);
345         dateString = __pPm->GetDateString(date);
346         itemCount = __pPm->GetWholeEventCount(actualGroupIndex);
347
348         if (itemCount == 0)//This is Today Index.(event is empty)
349         {
350                 pItem->Construct(Dimension(itemWidth, 0));
351                 return pItem;
352         }
353         else
354         {
355                 pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
356         }
357
358         pItem->SetElement(dateString);
359
360         if (EventListPresentationModel::IsToday(date) == true)
361         {
362                 pItem->SetBackgroundColor(Color(COLOR_GROUP_ITEM_TODAY_BACKGROUND));
363                 pItem->SetTextColor(Color(COLOR_GROUP_ITEM_TODAY_TEXT));
364         }
365         else
366         {
367                 pItem->SetBackgroundColor(Color(COLOR_GROUP_ITEM_BACKGROUND));
368                 pItem->SetTextColor(Color(COLOR_GROUP_ITEM_TEXT));
369         }
370
371         return pItem;
372 }
373
374 ListItemBase*
375 EventDeleterForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
376 {
377         if (__topBottomItemEnabled == true)
378         {
379                 if (groupIndex == 0 || groupIndex == GetGroupCount() - 1)
380                 {
381                         CustomItem* pItem = new (std::nothrow) CustomItem();
382
383                         String string;
384                         String dateString;
385                         if (groupIndex == 0)
386                         {
387                                 __pDateFormatter->Format(__pPm->GetViewMinRange(), dateString);
388                                 string = ResourceManager::GetString(IDS_LIST_VIEW_TAP_VIEW_BEFORE);
389                         }
390                         else
391                         {
392                                 __pDateFormatter->Format(__pPm->GetViewMaxRange(), dateString);
393                                 string = ResourceManager::GetString(IDS_LIST_VIEW_TAP_VIEW_AFTER);
394                         }
395                         string.Append(L" ");
396                         string.Append(dateString);
397
398                         pItem->Construct(Dimension(itemWidth, H_ITEM), LIST_ANNEX_STYLE_NORMAL);
399                         // TBD : Background color of item must be transparent.(will be in SDK 2.1)
400                         pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(COLOR_ITEM_BACKGROUND));
401                         pItem->AddElement(Rectangle(LEFT_MARGIN, 0, itemWidth - TOTAL_MARGIN, H_ITEM)
402                                                                                         , ID_LIST_ITEM_BEFORE_AFTER, string, FONT_SIZE_EVENT_SUB_LIST
403                                                                                         , Color(COLOR_TOP_BOTTOM_ITEM_TEXT), Color(COLOR_ITEM_TEXT_PRESSED), Color(COLOR_ITEM_TEXT_PRESSED));
404
405                         if (groupIndex == 0)
406                         {
407                                 DateTime minDateTime = Calendarbook::GetMinDateTime();
408                                 minDateTime.AddYears(1);
409                                 __pGroupedListViewDeleteList->SetItemEnabled(groupIndex, itemIndex, __pPm->GetViewMinRange() > minDateTime);
410                         }
411                         else
412                         {
413                                 DateTime maxDateTime = Calendarbook::GetMaxDateTime();
414                                 maxDateTime.AddYears(-1);
415                                 __pGroupedListViewDeleteList->SetItemEnabled(groupIndex, itemIndex, __pPm->GetViewMaxRange() < maxDateTime);
416                         }
417                         return pItem;
418                 }
419                 else
420                 {
421                         groupIndex -= TOP_BOTTOM_ITEM_COUNT;
422                 }
423         }
424         __pGroupedListViewDeleteList->SetItemEnabled(groupIndex, itemIndex, true);
425
426         const CalEventInstance* pEvent = __pPm->GetEventWithWholeIndex(groupIndex, itemIndex);
427         TryReturn((pEvent != null), null, "[E_SYSTEM] Unable to get event instance.");
428
429         EventItem* pItem = new (std::nothrow) EventItem();
430         pItem->Initialize(EVENT_ITEM_STYLE_SELECTION, itemWidth);
431         if (EventListPresentationModel::IsToday(__pPm->GetDateTimeFromGroupIndex(groupIndex)) == true)
432         {
433                 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, Color(COLOR_ITEM_TODAY_BACKGROUND));
434         }
435         pItem->SetTitle(pEvent->GetSubject());
436         pItem->SetCalendarColor(__pPm->GetCalendarColor(pEvent->GetCalendarId()));
437         if (pEvent->IsAllDayEvent() == true)
438         {
439                 pItem->SetAllDayEvent();
440         }
441         else
442         {
443                 DateTime startTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetStartTime());
444                 DateTime endTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetEndTime());
445                 pItem->SetDateRange(startTime, endTime, __pPm->GetDateTimeFromGroupIndex(groupIndex), __pPm->GetTimeFormatter());
446         }
447
448         pItem->SetReminder(pEvent->HasReminder());
449         pItem->SetRepeat(pEvent->IsRecurring());
450         pItem->SetPriority(pEvent->GetPriority());
451 //      pItem->SetFacebookEvent(false);
452         pItem->UpdateElements();
453
454         return pItem;
455 }
456
457 bool
458 EventDeleterForm::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
459 {
460         delete pItem;
461         return true;
462 }
463
464 bool
465 EventDeleterForm::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
466 {
467         delete pItem;
468         return true;
469 }
470
471 void
472 EventDeleterForm::OnGroupedListViewItemStateChanged(GroupedListView& listView, int groupIndex, int itemIndex,
473                                                                                                          int elementId, ListItemStatus status)
474 {
475         if (__topBottomItemEnabled == true)
476         {
477                 DateTime today = EventListPresentationModel::GetToday();
478                 today.SetValue(today.GetYear(), today.GetMonth(), today.GetDay(), 0, 0, 0);
479
480                 if (groupIndex == 0)
481                 {
482                         DateTime startDate = __pPm->GetDateTimeFromGroupIndex(0);
483                         DateTime minRange = __pPm->GetViewMinRange();
484                         minRange.AddMonths(PREVIOUS_DATE);
485                         DateTime minDateTime = Calendarbook::GetMinDateTime();
486                         minDateTime.AddYears(1);
487                         if (minRange < minDateTime)
488                         {
489                                 minRange = minDateTime;
490                         }
491
492                         __pPm->SetViewRange(minRange, __pPm->GetViewMaxRange());
493                         __pPm->SetViewType(VIEW_TYPE_LIST);
494
495                         __pGroupedListViewDeleteList->RefreshList(0, 0, LIST_REFRESH_TYPE_ITEM_MODIFY);
496                         int addedGroupCount = __pPm->GetGroupIndex(startDate);
497                         for (int i = 0; i < addedGroupCount; ++i)
498                         {
499                                 __pGroupedListViewDeleteList->RefreshList(i + TOP_BOTTOM_ITEM_COUNT, -1, LIST_REFRESH_TYPE_ITEM_ADD);
500
501                                 DateTime date = __pPm->GetDateTimeFromGroupIndex(i);
502                                 int itemCount = __pPm->GetWholeEventCount(i);
503                                 for (int j = 0; j < itemCount; ++j)
504                                 {
505                                         if (__pSelectAll->IsSelected() == true || (__pSelectBeforeToday->IsSelected() == true && date < today))
506                                         {
507                                                 __pGroupedListViewDeleteList->SetItemChecked(i + TOP_BOTTOM_ITEM_COUNT, j, true);
508                                         }
509                                 }
510                         }
511
512                         if (__pGroupedListViewDeleteList->IsGroupExpanded(__pGroupedListViewDeleteList->GetGroupCount() - 1) == false)
513                         {
514                                 __pGroupedListViewDeleteList->ExpandGroup(__pGroupedListViewDeleteList->GetGroupCount() - 1);
515                         }
516
517                         __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
518                         UpdateSelectedLabel();
519                         return;
520                 }
521                 else if (groupIndex == __pGroupedListViewDeleteList->GetGroupCount() - 1)
522                 {
523                         int prevGroupCount = __pPm->GetWholeDayCount();
524                         DateTime maxRange = __pPm->GetViewMaxRange();
525                         maxRange.AddMonths(NEXT_DATE);
526                         DateTime maxDateTime = Calendarbook::GetMaxDateTime();
527                         maxDateTime.AddYears(-1);
528                         if (maxRange > maxDateTime)
529                         {
530                                 maxRange = maxDateTime;
531                         }
532
533                         __pPm->SetViewRange(__pPm->GetViewMinRange(), maxRange);
534                         __pPm->SetViewType(VIEW_TYPE_LIST);
535
536                         int groupCount = __pPm->GetWholeDayCount();
537                         for (int i = prevGroupCount; i < groupCount; ++i)
538                         {
539                                 __pGroupedListViewDeleteList->RefreshList(i + TOP_BOTTOM_ITEM_COUNT, -1, LIST_REFRESH_TYPE_ITEM_ADD);
540
541                                 DateTime date = __pPm->GetDateTimeFromGroupIndex(i);
542                                 int itemCount = __pPm->GetWholeEventCount(i);
543                                 for (int j = 0; j < itemCount; ++j)
544                                 {
545                                         if (__pSelectAll->IsSelected() == true || (__pSelectBeforeToday->IsSelected() == true && date < today))
546                                         {
547                                                 __pGroupedListViewDeleteList->SetItemChecked(i + TOP_BOTTOM_ITEM_COUNT, j, true);
548                                         }
549                                 }
550                         }
551
552                         __pGroupedListViewDeleteList->RefreshList(__pGroupedListViewDeleteList->GetGroupCount() - 1, 0, LIST_REFRESH_TYPE_ITEM_MODIFY);
553                         if (__pGroupedListViewDeleteList->IsGroupExpanded(__pGroupedListViewDeleteList->GetGroupCount() - 1) == false)
554                         {
555                                 __pGroupedListViewDeleteList->ExpandGroup(__pGroupedListViewDeleteList->GetGroupCount() - 1);
556                         }
557
558                         __pGroupedListViewDeleteList->ScrollToItem(__pGroupedListViewDeleteList->GetGroupCount() - 1, 0);
559                         __pGroupedListViewDeleteList->Invalidate(false);
560
561                         __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
562                         UpdateSelectedLabel();
563                         return;
564                 }
565         }
566
567         if (__pGroupedListViewDeleteList->IsItemChecked(groupIndex, itemIndex) == true)
568         {
569                 __pSelectAll->SetSelected(IsSelectedAllEvent());
570                 __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
571         }
572         else if (__pGroupedListViewDeleteList->IsItemChecked(groupIndex, itemIndex) == false)
573         {
574                 __pSelectAll->SetSelected(false);
575
576                 int actualIndex = (__topBottomItemEnabled == true) ? groupIndex - TOP_BOTTOM_ITEM_COUNT : groupIndex;
577                 if (__pPm->GetCurrentDate() > __pPm->GetDateTimeFromGroupIndex(actualIndex))
578                 {
579                         __pSelectBeforeToday->SetSelected(false);
580                 }
581                 Invalidate(true);
582         }
583         UpdateSelectedLabel();
584 }
585
586 void
587 EventDeleterForm::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex,
588                                                                                          SweepDirection direction)
589 {
590 }
591
592 void
593 EventDeleterForm::OnGroupedListViewContextItemStateChanged(GroupedListView& listView,
594                                                                                                                          int groupIndex, int itemIndex,
595                                                                                                                          int elementId, ListContextItemStatus status)
596 {
597 }
598
599 void
600 EventDeleterForm::OnGroupedListViewItemLongPressed(GroupedListView& listView, int groupIndex, int itemIndex,
601                                                                                                         int elementId, bool& invokeListViewItemCallback)
602 {
603 }
604
605 void
606 EventDeleterForm::OnGroupedListViewGroupItemSelected(GroupedListView& listView, int groupIndex)
607 {
608         if (listView.IsGroupExpanded(groupIndex) == true)
609         {
610                 listView.CollapseGroup(groupIndex);
611         }
612         else
613         {
614                 listView.ExpandGroup(groupIndex);
615         }
616         listView.Invalidate(true);
617 }
618
619 void
620 EventDeleterForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
621 {
622         DateTime minRange = __pPm->GetCurrentDate();
623         minRange.SetValue(minRange.GetYear(), minRange.GetMonth(), minRange.GetDay());
624         DateTime maxRange;
625
626         if (previousSceneId == IDSCN_YEAR)
627         {
628                 minRange.SetValue(minRange.GetYear(), 1, 1);
629                 maxRange = minRange;
630                 maxRange.AddYears(NEXT_DATE);
631                 maxRange.AddSeconds(PREVIOUS_DATE);
632                 __pSelectAll->SetText(ResourceManager::GetString(IDS_CLD_MBODY_ALL_THIS_YEAR));
633         }
634         else if (previousSceneId == IDSCN_MONTH)
635         {
636                 minRange.SetValue(minRange.GetYear(), minRange.GetMonth(), 1);
637                 maxRange = minRange;
638                 maxRange.AddMonths(NEXT_DATE);
639                 maxRange.AddSeconds(PREVIOUS_DATE);
640                 __pSelectAll->SetText(ResourceManager::GetString(IDS_CLD_BODY_ALL_THIS_MONTH));
641         }
642         else if (previousSceneId == IDSCN_DAY)
643         {
644                 maxRange = minRange;
645                 maxRange.AddDays(NEXT_DATE);
646                 maxRange.AddSeconds(PREVIOUS_DATE);
647                 __pSelectAll->SetText(ResourceManager::GetString(IDS_CLD_BODY_ALL_THIS_DAY));
648         }
649         else if (previousSceneId == IDSCN_LIST)
650         {
651                 minRange = __pPm->GetViewMinRange();
652                 maxRange = __pPm->GetViewMaxRange();
653
654                 __topBottomItemEnabled = true;
655
656                 __pSelectBeforeToday->SetShowState(true);
657                 __pPanel->SetSize(Dimension(GetClientAreaBounds().width, H_ITEM * 2));
658         }
659
660         __pPm->SetViewType(VIEW_TYPE_LIST);
661         __pPm->SetViewRange(minRange, maxRange);
662         __pPm->AddCalendarEventChangedEventListener(*this);
663         UpdateSelectedLabel();
664
665         GetFooter()->SetItemEnabled(0, false);
666         Invalidate(true);
667 }
668
669 void
670 EventDeleterForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
671 {
672
673 }
674
675 void
676 EventDeleterForm::OnActionPerformed(const Control& source, int actionId)
677 {
678         TwoButtonPopupStyle style = TWO_BUTTON_POPUP_STYLE_SINGLE_EVENT;
679
680         DateTime today = EventListPresentationModel::GetToday();
681         today.SetValue(today.GetYear(), today.GetMonth(), today.GetDay(), 0, 0, 0);
682
683         int startGroupIndex = 0;
684         int endGroupIndex = __pGroupedListViewDeleteList->GetGroupCount() - 1;
685         if (__topBottomItemEnabled == true)
686         {
687                 startGroupIndex = TOP_BOTTOM_ITEM_COUNT;
688                 endGroupIndex -= TOP_BOTTOM_ITEM_COUNT;
689         }
690
691         switch (actionId)
692         {
693         case IDA_EVENT_DELETER_FORM_FOOTER_DELETE:
694                 for (int i = startGroupIndex; i <= endGroupIndex; i++)
695                 {
696                         int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
697                         for (int j = 0; j < itemCount; j++)
698                         {
699                                 if (__pGroupedListViewDeleteList->IsItemChecked(i, j) == true)
700                                 {
701                                         const CalEventInstance* pEventInstance = __pPm->GetEventWithWholeIndex(i - startGroupIndex, j);
702                                         if (pEventInstance != null && pEventInstance->IsRecurring() == true)
703                                         {
704                                                 style = TWO_BUTTON_POPUP_STYLE_REPEATED_EVENT;
705                                                 break;
706                                         }
707                                 }
708                         }
709                 }
710
711                 __pTwoButtonPopup->RequestPopup(style, this);
712                 break;
713         case IDA_SELECT_ALL_CHECKED:
714                 for (int i = startGroupIndex; i <= endGroupIndex; i++)
715                 {
716                         int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
717                         for (int j = 0; j < itemCount; j++)
718                         {
719                                 __pGroupedListViewDeleteList->SetItemChecked(i, j, true);
720                         }
721                 }
722                 __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
723                 UpdateSelectedLabel();
724                 break;
725         case IDA_SELECT_ALL_UNCHECKED:
726                 for (int i = startGroupIndex; i <= endGroupIndex; i++)
727                 {
728                         int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
729                         for (int j = 0; j < itemCount; j++)
730                         {
731                                 __pGroupedListViewDeleteList->SetItemChecked(i, j, false);
732                         }
733                 }
734                 __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
735                 UpdateSelectedLabel();
736                 break;
737         case IDA_BEFORE_TODAY_CHECKED:
738                 if (__topBottomItemEnabled == true)
739                 {
740                         for (int i = startGroupIndex; i <= endGroupIndex && __pPm->GetDateTimeFromGroupIndex(i - startGroupIndex) < today; i++)
741                         {
742                                 int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
743                                 for (int j = 0; j < itemCount; j++)
744                                 {
745                                         __pGroupedListViewDeleteList->SetItemChecked(i, j, true);
746                                 }
747                         }
748                         __pSelectAll->SetSelected(IsSelectedAllEvent());
749                         __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
750                         UpdateSelectedLabel();
751                 }
752                 break;
753         case IDA_BEFORE_TODAY_UNCHECKED:
754                 if (__topBottomItemEnabled == true)
755                 {
756                         for (int i = startGroupIndex; i <= endGroupIndex && __pPm->GetDateTimeFromGroupIndex(i - startGroupIndex) < today; i++)
757                         {
758                                 int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
759                                 for (int j = 0; j < itemCount; j++)
760                                 {
761                                         __pGroupedListViewDeleteList->SetItemChecked(i, j, false);
762                                 }
763                         }
764                         __pSelectAll->SetSelected(IsSelectedAllEvent());
765                         UpdateSelectedLabel();
766                 }
767                 break;
768         }
769 }
770
771 void
772 EventDeleterForm::OnCalendarEventChanged(void)
773 {
774         __pGroupedListViewDeleteList->UpdateList();
775
776         __pSelectAll->SetSelected(IsSelectedAllEvent());
777         __pSelectBeforeToday->SetSelected(IsSelectedAllEventBeforeToday());
778         UpdateSelectedLabel();
779 }
780
781 int
782 EventDeleterForm::GetSelectedEventCount(void)
783 {
784         int startGroupIndex = 0;
785         int endGroupIndex = __pGroupedListViewDeleteList->GetGroupCount() - 1;
786         if (__topBottomItemEnabled == true)
787         {
788                 startGroupIndex = TOP_BOTTOM_ITEM_COUNT;
789                 endGroupIndex -= TOP_BOTTOM_ITEM_COUNT;
790         }
791
792         if (endGroupIndex < 0)
793         {
794                 return 0;
795         }
796
797         int count = 0;
798         for (int i = startGroupIndex; i <= endGroupIndex; i++)
799         {
800                 int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
801                 for (int j = 0; j < itemCount; j++)
802                 {
803                         if (__pGroupedListViewDeleteList->IsItemChecked(i, j) == true)
804                         {
805                                 count++;
806                         }
807                 }
808         }
809         return count;
810 }
811
812 bool
813 EventDeleterForm::IsSelectedAllEvent(void)
814 {
815         int startGroupIndex = 0;
816         int endGroupIndex = __pGroupedListViewDeleteList->GetGroupCount() - 1;
817         if (__topBottomItemEnabled == true)
818         {
819                 startGroupIndex = TOP_BOTTOM_ITEM_COUNT;
820                 endGroupIndex -= TOP_BOTTOM_ITEM_COUNT;
821         }
822
823         if (endGroupIndex < 0)
824         {
825                 return false;
826         }
827
828         for (int i = startGroupIndex; i <= endGroupIndex; i++)
829         {
830                 int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
831                 for (int j = 0; j < itemCount; j++)
832                 {
833                         if (__pGroupedListViewDeleteList->IsItemChecked(i, j) == false)
834                         {
835                                 return false;
836                         }
837                 }
838         }
839         return true;
840 }
841 bool
842 EventDeleterForm::IsSelectedAllEventBeforeToday(void)
843 {
844         DateTime today = EventListPresentationModel::GetToday();
845         today.SetValue(today.GetYear(), today.GetMonth(), today.GetDay(), 0, 0, 0);
846
847         if (__pPm->GetDateTimeFromGroupIndex(0) >= today)
848         {
849                 return false;
850         }
851
852         int startGroupIndex = 0;
853         int endGroupIndex = __pGroupedListViewDeleteList->GetGroupCount() - 1;
854         if (__topBottomItemEnabled == true)
855         {
856                 startGroupIndex = TOP_BOTTOM_ITEM_COUNT;
857                 endGroupIndex -= TOP_BOTTOM_ITEM_COUNT;
858         }
859
860         if (endGroupIndex < 0)
861         {
862                 return false;
863         }
864
865         for (int i = startGroupIndex; i <= endGroupIndex && __pPm->GetDateTimeFromGroupIndex(i - startGroupIndex) < today; i++)
866         {
867                 int itemCount = __pGroupedListViewDeleteList->GetItemCountAt(i);
868                 for (int j = 0; j < itemCount; j++)
869                 {
870                         if (__pGroupedListViewDeleteList->IsItemChecked(i, j) == false)
871                         {
872                                 return false;
873                         }
874                 }
875         }
876         return true;
877 }
878
879 result
880 EventDeleterForm::UpdateSelectedLabel(void)
881 {
882         int itemCount = GetSelectedEventCount();
883         int groupCount = GetGroupCount();
884         if (groupCount == 0 || (groupCount == 1 && __pPm->GetEventWithWholeIndex(0, 0) == null))
885         {
886                 AppLogDebug("Select button enable.");
887                 __pSelectAll->SetEnabled(false);
888                 __pSelectBeforeToday->SetEnabled(false);
889         }
890         else
891         {
892                 AppLogDebug("Select button disable.");
893                 __pSelectAll->SetEnabled(true);
894                 __pSelectBeforeToday->SetEnabled(true);
895         }
896
897         if (itemCount > 0)
898         {
899                 GetFooter()->SetItemEnabled(0, true);
900
901                 String labelString = ResourceManager::GetString(itemCount > 1 ? IDS_COM_BODY_PD_SELECTED : IDS_COM_BODY_PD_1_SELECTED);
902                 labelString.Format(labelString.GetLength() + Integer::ToString(itemCount).GetLength(), labelString.GetPointer(), itemCount);
903                 __pLabel->SetText(labelString);
904                 __pLabel->SetSize(GetClientAreaBounds().width, H_COUNT_LABEL);
905         }
906         else
907         {
908                 GetFooter()->SetItemEnabled(0, false);
909
910                 __pLabel->SetSize(GetClientAreaBounds().width, 0);
911         }
912         Invalidate(true);
913         return E_SUCCESS;
914 }