c2ca40d405947e03060a1d12df7c7708a5743137
[apps/osp/Contacts.git] / src / CtContactListEditorPanel.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        CtContactListEditorPanel.cpp
19  * @brief       This is the implementation file for the ContactListEditorPanel class.
20  */
21
22 #include <FSocial.h>
23 #include "CtContactListEditorPanel.h"
24 #include "CtContactListItem.h"
25 #include "CtContactListPresentationModel.h"
26 #include "CtContactsApp.h"
27 #include "CtMainForm.h"
28 #include "CtResourceManager.h"
29 #include "CtSceneRegister.h"
30 #include "CtSearchListItem.h"
31 #include "CtSearchListEventListener.h"
32 #include "CtTypes.h"
33
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Base::Collection;
37 using namespace Tizen::Graphics;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
41 using namespace Tizen::Social;
42
43 static const int IDA_HEADER_CONTACTS = 10;
44 static const int IDA_HEADER_GROUPS = 11;
45 static const int IDA_HEADER_FAVORITES = 12;
46 static const int IDA_CHECK_SELECT_ALL_CHECKED = 20;
47 static const int IDA_CHECK_SELECT_ALL_UNCHECKED = 21;
48 static const int IDA_FOOTER_DELETE = 30;
49 static const int IDA_FOOTER_CANCEL = 31;
50 static const int IDA_FOOTER_DONE = 32;
51 static const int IDA_POPUP_CONTACT_VALUE_CLOSE = 40;
52 static const int IDA_POPUP_DELETE_OK = 41;
53 static const int IDA_POPUP_DELETE_CANCEL = 42;
54 static const int IDA_POPUP_DELETE_PROGRESS_CANCEL = 43;
55
56 static const int X_EMPTY_IMAGE = 220;
57 static const int Y_EMPTY_IMAGE = 300;
58 static const int W_EMPTY_IMAGE = 280;
59 static const int H_EMPTY_IMAGE = 280;
60 static const int Y_EMPTY_COMMENT = 618;
61 static const int H_EMPTY_COMMENT = 38;
62 static const int W_INITIAL_PANEL = 10;
63 static const int H_INITIAL_PANEL = 10;
64 static const int H_SELECT_ALL = 112;
65 static const int H_SEARCHBAR = 86;
66 static const int H_BOTTOM_LABEL = 48;
67 static const int H_GROUP_ITEM = 76;
68 static const int W_CONTACT_VALUE_POPUP = 688;
69 static const int H_CONTACT_VALUE_POPUP = 532;
70 static const int H_CONTACT_VALUE_POPUP_LIST_VIEW = 338;
71 static const int H_CLOSE_BUTTON = 74;
72 static const int Y_CLOSE_BUTTON = 358;
73 static const int W_CLOSE_BUTTON = 394;
74 static const int H_DELETE_PROGRESS_POPUP = 308;
75 static const int Y_DELETE_POPUP_TITLE = 20;
76 static const int H_DELETE_POPUP_ELEMENT = 60;
77 static const int H_DELETE_POPUP_PROGRESS = 34;
78 static const int Y_DELETE_POPUP_CANCEL_BUTTON = 214;
79 static const int H_DELETE_POPUP_CANCEL_BUTTON = 74;
80 static const int W_DELETE_POPUP_CANCEL_BUTTON = 394;
81 static const int X_LIST_ITEM_TEXT_MARGIN = 32;
82 static const int H_CHECK_LABEL = 72;
83 static const int Y_CHECK_LABEL = 20;
84
85 static const int FONT_SIZE_EMPTY_COMMENT = 32;
86 static const int FONT_SIZE_BOTTOM_LABEL = 32;
87 static const int FONT_SIZE_DELETE_POPUP_TEXT = 36;
88
89 static const unsigned int COLOR_EMPTY_COMMENT = Color32<102, 102, 102>::Value;
90 static const unsigned int COLOR_BOTTOM_LABEL_BG = Color32<68, 68, 68>::Value;
91 static const unsigned int COLOR_BOTTOM_LABEL_FONT = Color32<255, 255, 255>::Value;
92 static const unsigned int COLOR_DELETE_POPUP_TEXT = Color32<128, 128, 128>::Value;
93 static const unsigned int COLOR_CHECK_LABEL_BG = Color32<220, 218, 211>::Value;
94 static const unsigned int COLOR_DELETE_BUTTON_NORMAL = Color32<213, 82, 82>::Value;
95 static const unsigned int COLOR_DELETE_BUTTON_PRESSED = Color32<194, 71, 71>::Value;
96 static const unsigned int COLOR_DELETE_BUTTON_TEXT = Color32<248, 246, 239>::Value;
97
98 static const int LIST_VIEW_GROUP_INDEX_SHIFT = 16;
99 static const int LIST_VIEW_MASK = 0xFFFF;
100
101 static const wchar_t* IDB_NO_CONTENTS = L"00_Nocontents_text.png";
102
103 ContactListEditorPanel::ContactListEditorPanel(void)
104 : __pTempContactValueHashMap(null)
105 , __pSelectAll(null)
106 , __pListView(null)
107 , __pSearchListView(null)
108 , __pSearchBar(null)
109 , __pCheckLabel(null)
110 , __pEmptyImageLabel(null)
111 , __pEmptyCommentLabel(null)
112 , __pBottomLabel(null)
113 , __pMultipleContactValuePopup(null)
114 , __pDeleteProgressPopup(null)
115 , __pDeleteConfirmationPopup(null)
116 , __pContactValueListEvent(null)
117 , __pPresentationModel(null)
118 , __pSearchListEvent(null)
119 , __isContactRemoved(false)
120 , __selectedIndex(-1)
121 , __selectedSearchIndex(-1)
122 , __deleteGroupIndex(0)
123 , __deleteItemIndex(0)
124 {
125         __deleteContactTimer.Construct(*this);
126 }
127
128 ContactListEditorPanel::~ContactListEditorPanel(void)
129 {
130 }
131
132 void
133 ContactListEditorPanel::Initialize(void)
134 {
135         Construct(Rectangle(0, 0, W_INITIAL_PANEL, H_INITIAL_PANEL));
136 }
137
138 result
139 ContactListEditorPanel::OnInitializing(void)
140 {
141         const Form* pForm = dynamic_cast<Form*>(GetParent());
142         AppAssert(pForm);
143
144         FloatRectangle clientBounds = pForm->GetClientAreaBoundsF();
145         SetBounds(FloatRectangle(0, 0, clientBounds.width, clientBounds.height));
146
147         __pPresentationModel = ContactListPresentationModel::GetInstance();
148
149         __pCheckLabel = new (std::nothrow) Label();
150         __pCheckLabel->Construct(Rectangle(0, H_SEARCHBAR + Y_CHECK_LABEL, clientBounds.width, H_CHECK_LABEL), L"");
151         __pCheckLabel->SetBackgroundColor(COLOR_CHECK_LABEL_BG);
152
153         AddControl(__pCheckLabel);
154
155         __pSelectAll = new (std::nothrow) CheckButton();
156         __pSelectAll->Construct(Rectangle(0, H_SEARCHBAR, clientBounds.width, H_SELECT_ALL), CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE);
157         __pSelectAll->SetText(ResourceManager::GetString(L"IDS_COM_BODY_SELECT_ALL"));
158         __pSelectAll->SetActionId(IDA_CHECK_SELECT_ALL_CHECKED, IDA_CHECK_SELECT_ALL_UNCHECKED);
159         __pSelectAll->AddActionEventListener(*this);
160
161         AddControl(__pSelectAll);
162
163         __pListView = new (std::nothrow) GroupedListView();
164         __pListView->Construct(Rectangle(0, H_SEARCHBAR + H_SELECT_ALL, clientBounds.width, clientBounds.height - H_SEARCHBAR - H_SELECT_ALL - H_BOTTOM_LABEL), GROUPED_LIST_VIEW_STYLE_INDEXED, true, true);
165         __pListView->SetItemProvider(*this);
166         __pListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_PB_BODY_NO_CONTACTS"));
167         __pListView->AddFastScrollListener(*this);
168         __pListView->AddGroupedListViewItemEventListener(*this);
169         __pListView->AddTouchEventListener(*this);
170
171         AddControl(__pListView);
172
173         __pSearchBar = new (std::nothrow) SearchBar();
174         __pSearchBar->Construct(Rectangle(0, 0, clientBounds.width, H_SEARCHBAR));
175         __pSearchBar->SetGuideText(ResourceManager::GetString(L"IDS_COM_BODY_SEARCH"));
176         __pSearchBar->AddSearchBarEventListener(*this);
177         __pSearchBar->AddTextEventListener(*this);
178         __pSearchBar->AddKeypadEventListener(*this);
179         __pSearchBar->SetContentAreaSize(Dimension(0, 0));
180
181         __pSearchListEvent = new (std::nothrow) SearchListEventListener(LIST_ANNEX_STYLE_MARK, __pPresentationModel);
182
183         AddControl(__pSearchBar);
184
185         __pSearchListView = new (std::nothrow) GroupedListView();
186         __pSearchListView->Construct(Rectangle(0, H_SEARCHBAR, clientBounds.width, clientBounds.height - H_SEARCHBAR - H_BOTTOM_LABEL), GROUPED_LIST_VIEW_STYLE_INDEXED, true, false);
187         __pSearchListView->SetItemProvider(*__pSearchListEvent);
188         __pSearchListView->AddGroupedListViewItemEventListener(*this);
189         __pSearchListView->AddTouchEventListener(*this);
190         __pSearchListView->SetTextOfEmptyList(ResourceManager::GetString(L"IDS_PB_BODY_NO_CONTACTS"));
191         __pSearchListView->SetShowState(false);
192
193         AddControl(__pSearchListView);
194
195         __pEmptyImageLabel = new (std::nothrow) Label();
196         __pEmptyImageLabel->Construct(Rectangle(X_EMPTY_IMAGE, Y_EMPTY_IMAGE, W_EMPTY_IMAGE, H_EMPTY_IMAGE), L"");
197         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_NO_CONTENTS);
198         if (pBitmap != null)
199         {
200                 __pEmptyImageLabel->SetBackgroundBitmap(*pBitmap);
201                 delete pBitmap;
202         }
203         __pEmptyImageLabel->SetShowState(false);
204
205         AddControl(__pEmptyImageLabel);
206
207         __pEmptyCommentLabel = new (std::nothrow) Label();
208         __pEmptyCommentLabel->Construct(Rectangle(0, Y_EMPTY_COMMENT, clientBounds.width, H_EMPTY_COMMENT),
209                                                                                                                                 ResourceManager::GetString(L"IDS_PB_BODY_NO_CONTACTS"));
210         __pEmptyCommentLabel->SetTextConfig(FONT_SIZE_EMPTY_COMMENT, LABEL_TEXT_STYLE_NORMAL);
211         __pEmptyCommentLabel->SetTextColor(Color(COLOR_EMPTY_COMMENT));
212         __pEmptyCommentLabel->SetShowState(false);
213
214         AddControl(__pEmptyCommentLabel);
215
216         __pBottomLabel = new (std::nothrow) Label();
217         __pBottomLabel->Construct(FloatRectangle(0, clientBounds.height - H_BOTTOM_LABEL, clientBounds.width, H_BOTTOM_LABEL),
218                                                                                                         ResourceManager::GetString(L"IDS_COM_POP_SELECTED") + INITIAL_SELECTED_COUNT);
219         __pBottomLabel->SetBackgroundColor(Color(COLOR_BOTTOM_LABEL_BG));
220         __pBottomLabel->SetTextColor(Color(COLOR_BOTTOM_LABEL_FONT));
221         __pBottomLabel->SetTextConfig(FONT_SIZE_BOTTOM_LABEL, LABEL_TEXT_STYLE_BOLD);
222         __pBottomLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
223         __pBottomLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
224         AddControl(__pBottomLabel);
225
226         __pTempContactValueHashMap = new (std::nothrow) HashMap();
227         __pTempContactValueHashMap->Construct();
228
229         return E_SUCCESS;
230 }
231
232 result
233 ContactListEditorPanel::OnTerminating(void)
234 {
235         result r = E_SUCCESS;
236
237         if (__pPresentationModel != null)
238         {
239                 __pPresentationModel->RemoveContactChangeListener(*this);
240         }
241
242         delete __pSearchListEvent;
243
244         __pTempContactValueHashMap->RemoveAll(true);
245         delete __pTempContactValueHashMap;
246
247         delete __pDeleteProgressPopup;
248         delete __pDeleteConfirmationPopup;
249         delete __pMultipleContactValuePopup;
250
251         return r;
252 }
253
254 void
255 ContactListEditorPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
256 {
257         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
258         SceneManager* pSceneManager = SceneManager::GetInstance();
259         Form* pForm = dynamic_cast<Form*>(GetParent());
260         AppAssert(pForm);
261
262         switch (actionId)
263         {
264         case IDA_HEADER_CONTACTS:
265                 {
266                         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
267                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK && pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
268                         {
269                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
270                         }
271                         else
272                         {
273                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
274                         }
275                 }
276                 break;
277         case IDA_HEADER_GROUPS:
278                 {
279                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
280                 }
281                 break;
282         case IDA_HEADER_FAVORITES:
283                 {
284                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
285                         {
286                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
287                                 {
288                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
289                                 }
290                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
291                                 {
292                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST_EDITOR));
293                                 }
294                         }
295                         else
296                         {
297                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
298                         }
299                 }
300                 break;
301         case IDA_CHECK_SELECT_ALL_CHECKED:
302                 {
303                         for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
304                         {
305                                 int itemCount = __pListView->GetItemCountAt(groupIndex);
306                                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
307                                 {
308                                         __pListView->SetItemChecked(groupIndex, itemIndex, true);
309
310                                         int index = 0;
311                                         index |= groupIndex << LIST_VIEW_GROUP_INDEX_SHIFT;
312                                         index |= itemIndex;
313                                         Integer hashMapIndex(index);
314
315                                         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
316                                         {
317                                                 if (__pTempContactValueHashMap->GetValue(hashMapIndex) == null)
318                                                 {
319                                                         String phoneNumber = __pPresentationModel->GetDefaultPhoneNumber(groupIndex, itemIndex);
320                                                         __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(index)), *(new (std::nothrow) String(phoneNumber)));
321                                                 }
322                                         }
323                                         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
324                                         {
325                                                 if (__pTempContactValueHashMap->GetValue(hashMapIndex) == null)
326                                                 {
327                                                         String email = __pPresentationModel->GetDefaultEmail(groupIndex, itemIndex);
328                                                         __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(index)), *(new (std::nothrow) String(email)));
329                                                 }
330                                         }
331                                 }
332                         }
333                         __pListView->Invalidate(true);
334                         UpdateBottomLabel();
335                 }
336                 break;
337         case IDA_CHECK_SELECT_ALL_UNCHECKED:
338                 {
339                         for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
340                         {
341                                 int itemCount = __pListView->GetItemCountAt(groupIndex);
342                                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
343                                 {
344                                         __pListView->SetItemChecked(groupIndex, itemIndex, false);
345                                 }
346                         }
347                         __pTempContactValueHashMap->RemoveAll(true);
348                         __pListView->Invalidate(true);
349                         UpdateBottomLabel();
350                 }
351                 break;
352         case IDA_FOOTER_DELETE:
353                 {
354                         ShowDeleteConfirmationPopup();
355                 }
356                 break;
357         case IDA_FOOTER_CANCEL:
358                 {
359                         pSceneManager->GoBackward(BackwardSceneTransition());
360                 }
361                 break;
362         case IDA_FOOTER_DONE:
363                 {
364                         ReturnMultipleValues();
365                 }
366                 break;
367         case IDA_POPUP_CONTACT_VALUE_CLOSE:
368                 {
369                         HideContactValuePopup();
370                 }
371                 break;
372         case IDA_POPUP_DELETE_OK:
373                 {
374                         ShowDeleteProgressPopup();
375                 }
376                 break;
377         case IDA_POPUP_DELETE_CANCEL:
378                 {
379                         HideDeleteConfirmationPopup();
380                 }
381                 break;
382         case IDA_POPUP_DELETE_PROGRESS_CANCEL:
383                 {
384                         __deleteContactTimer.Cancel();
385                         HideDeleteProgressPopup();
386                         pSceneManager->GoBackward(BackwardSceneTransition());
387                 }
388                 break;
389         default:
390                 break;
391         }
392 }
393
394 void
395 ContactListEditorPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
396                                                                                 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
397 {
398         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
399
400         Form* pForm = dynamic_cast<Form*>(GetParent());
401         AppAssert(pForm);
402
403         Header* pHeader = pForm->GetHeader();
404         pHeader->AddActionEventListener(*this);
405
406         Footer* pFooter = pForm->GetFooter();
407         pFooter->RemoveAllItems();
408         pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
409         pForm->SetFormMenuEventListener(null);
410
411         __pPresentationModel->InitializeContactList();
412         __pListView->SetFastScrollIndex(__pPresentationModel->GetAllKeys(), false);
413         __pListView->UpdateList();
414
415         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
416         {
417                 pFooter->SetShowState(true);
418
419                 FooterItem footerItemDone;
420                 footerItemDone.Construct(IDA_FOOTER_DONE);
421                 footerItemDone.SetText(ResourceManager::GetString(L"IDS_COM_SK_DONE"));
422                 pFooter->AddItem(footerItemDone);
423
424                 if (__pPresentationModel->GetContactCount() == 0)
425                 {
426                         pFooter->SetItemEnabled(0, false);
427
428                         __pSearchBar->SetShowState(false);
429                         __pCheckLabel->SetShowState(false);
430                         __pSelectAll->SetShowState(false);
431                         __pListView->SetShowState(false);
432                         __pEmptyImageLabel->SetShowState(true);
433                         __pEmptyCommentLabel->SetShowState(true);
434                         __pBottomLabel->SetShowState(false);
435
436                 }
437                 else
438                 {
439                         for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
440                         {
441                                 int itemCount = __pListView->GetItemCountAt(groupIndex);
442                                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
443                                 {
444                                         __pListView->SetItemChecked(groupIndex, itemIndex, false);
445                                 }
446                         }
447
448                          pFooter->SetItemEnabled(0, false);
449
450                         __pSearchBar->SetShowState(true);
451                         __pCheckLabel->SetShowState(true);
452                         __pSelectAll->SetShowState(true);
453                         __pListView->SetShowState(true);
454                         __pEmptyImageLabel->SetShowState(false);
455                         __pEmptyCommentLabel->SetShowState(false);
456
457                         __pSelectAll->SetSelected(false);
458                 }
459         }
460         else
461         {
462                 __pSelectAll->SetSelected(false);
463                 for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
464                 {
465                         int itemCount = __pListView->GetItemCountAt(groupIndex);
466                         for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
467                         {
468                                 __pListView->SetItemChecked(groupIndex, itemIndex, false);
469                         }
470                 }
471
472                 FooterItem footerDelete;
473                 footerDelete.Construct(IDA_FOOTER_DELETE);
474                 footerDelete.SetText(ResourceManager::GetString(L"IDS_COM_SK_DELETE"));
475
476                 FooterItem footerCancel;
477                 footerCancel.Construct(IDA_FOOTER_CANCEL);
478                 footerCancel.SetText(ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
479                 pFooter->AddItem(footerCancel);
480                 pFooter->AddItem(footerDelete);
481                 pFooter->SetItemEnabled(1, false);
482         }
483
484         __pPresentationModel->AddContactChangeListener(*this);
485         pFooter->AddActionEventListener(*this);
486         UpdateBottomLabel();
487
488         if (pArgs != null)
489         {
490                 pArgs->RemoveAll(true);
491                 delete pArgs;
492         }
493 }
494
495 void
496 ContactListEditorPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
497                                                                                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
498 {
499         Form* pForm = dynamic_cast<Form*>(GetParent());
500         AppAssert(pForm);
501
502         if (pForm->IsFooterVisible() == false)
503         {
504                 pForm->SetActionBarsVisible(FORM_ACTION_BAR_FOOTER, true);
505         }
506
507         Header* pHeader = pForm->GetHeader();
508         pHeader->RemoveActionEventListener(*this);
509
510         Footer* pFooter = pForm->GetFooter();
511         pFooter->RemoveActionEventListener(*this);
512
513         if (__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
514         {
515                 __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
516         }
517
518         __pPresentationModel->RemoveContactChangeListener(*this);
519 }
520
521 result
522 ContactListEditorPanel::RemoveContactList(void)
523 {
524         result r = E_FAILURE;
525
526         for (int groupIndex = __deleteGroupIndex; groupIndex < __pListView->GetGroupCount(); groupIndex++)
527         {
528                 int itemCount = __pListView->GetItemCountAt(groupIndex);
529                 for (int itemIndex = __deleteItemIndex; itemIndex < itemCount; itemIndex++)
530                 {
531                         if (__pListView->IsItemChecked(groupIndex, itemIndex) == true)
532                         {
533                                 r = __pPresentationModel->RemoveContact(groupIndex, itemIndex, false);
534
535                                 __deleteGroupIndex = groupIndex;
536                                 __deleteItemIndex = ++itemIndex;
537
538                                 return r;
539                         }
540                 }
541                 __deleteItemIndex = 0;
542         }
543
544         __deleteGroupIndex = 0;
545         __deleteItemIndex = 0;
546
547         return r;
548 }
549
550 int
551 ContactListEditorPanel::GetCheckedContactCounts(void)
552 {
553         int contactCount = 0;
554
555         for (int groupIndex = __deleteGroupIndex; groupIndex < __pListView->GetGroupCount(); groupIndex++)
556         {
557                 int itemCount = __pListView->GetItemCountAt(groupIndex);
558                 for (int itemIndex = __deleteItemIndex; itemIndex < itemCount; itemIndex++)
559                 {
560                         if (__pListView->IsItemChecked(groupIndex, itemIndex) == true)
561                         {
562                                 contactCount++;
563                         }
564                 }
565         }
566
567         return contactCount;
568 }
569
570 Tizen::Ui::Controls::ListItemBase*
571 ContactListEditorPanel::CreateItem(int groupIndex, int itemIndex, int itemWidth)
572 {
573         String name;
574         Bitmap* pThumbnail = null;
575
576         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
577
578         CustomItem* pItem = new (std::nothrow) CustomItem();
579         pItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight()), LIST_ANNEX_STYLE_MARK);
580
581         __pPresentationModel->GetContactItemInfoN(groupIndex, itemIndex, name, pThumbnail);
582
583         ContactListItem* pCustomElement = new (std::nothrow) ContactListItem(name, pThumbnail);
584         pItem->AddElement(Rectangle(0, 0, itemWidth - (ListItemBase::GetAnnexWidth(LIST_ANNEX_STYLE_MARK) + X_LIST_ITEM_TEXT_MARGIN), pContactsApp->GetListItemSingleLineHeight()), 0, *(static_cast<ICustomElement *>(pCustomElement)));
585
586         return pItem;
587 }
588
589 bool
590 ContactListEditorPanel::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
591 {
592         delete pItem;
593         pItem = null;
594
595         return true;
596 }
597
598 int
599 ContactListEditorPanel::GetItemCount(int groupIndex)
600 {
601         return __pPresentationModel->GetContactCount(groupIndex);
602 }
603
604 int
605 ContactListEditorPanel::GetGroupCount(void)
606 {
607         return __pPresentationModel->GetKeyCount();
608 }
609
610 Tizen::Ui::Controls::GroupItem*
611 ContactListEditorPanel::CreateGroupItem(int groupIndex, int itemWidth)
612 {
613         GroupItem* pItem = new (std::nothrow) GroupItem();
614         pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
615         pItem->SetElement(__pPresentationModel->GetKey(groupIndex), null);
616
617         return pItem;
618 }
619
620 bool
621 ContactListEditorPanel::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::GroupItem* pItem, int itemWidth)
622 {
623         delete pItem;
624         pItem = null;
625
626         return true;
627 }
628
629 void
630 ContactListEditorPanel::OnSearchBarModeChanged(Tizen::Ui::Controls::SearchBar& source, Tizen::Ui::Controls::SearchBarMode mode)
631 {
632         if (mode == SEARCH_BAR_MODE_NORMAL)
633         {
634                 int count = __pPresentationModel->GetSearchedContactCount();
635                 bool isChecked = true;
636
637                 for (int index = 0; index < count; index++)
638                 {
639                         int groupIndex = 0;
640                         int itemIndex = 0;
641
642                         __pPresentationModel->GetItemMainIndex(index, groupIndex, itemIndex);
643
644                         __pListView->SetItemChecked(groupIndex, itemIndex, __pSearchListView->IsItemChecked(0, index));
645                 }
646
647                 for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount() && isChecked == true; groupIndex++)
648                 {
649                         int itemCount = __pListView->GetItemCountAt(groupIndex);
650                         for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
651                         {
652                                 if (__pListView->IsItemChecked(groupIndex, itemIndex) == false)
653                                 {
654                                         isChecked = false;
655                                         break;
656                                 }
657                         }
658                 }
659
660                 __pListView->SetShowState(true);
661                 __pListView->Invalidate(true);
662                 __pCheckLabel->SetShowState(true);
663                 __pSelectAll->SetShowState(true);
664                 __pSelectAll->SetSelected(isChecked);
665                 __pSearchListView->SetShowState(false);
666                 __pPresentationModel->ResetSearchedContactList();
667                 __pSearchListView->UpdateList();
668         }
669 }
670
671 void
672 ContactListEditorPanel::OnGroupedListViewContextItemStateChanged(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
673 {
674 }
675
676 void
677 ContactListEditorPanel::OnGroupedListViewItemStateChanged(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, int elementId, Tizen::Ui::Controls::ListItemStatus status)
678 {
679         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
680
681         int mainGroupIndex = groupIndex;
682         int mainItemIndex = itemIndex;
683
684         if (listView.Equals(*__pSearchListView) == true)
685         {
686                 __selectedSearchIndex = 0;
687                 __selectedSearchIndex |= groupIndex << LIST_VIEW_GROUP_INDEX_SHIFT;
688                 __selectedSearchIndex |= itemIndex;
689
690                 __pPresentationModel->GetItemMainIndex(itemIndex, mainGroupIndex, mainItemIndex);
691         }
692
693         __selectedIndex = 0;
694         __selectedIndex |= mainGroupIndex << LIST_VIEW_GROUP_INDEX_SHIFT;
695         __selectedIndex |= mainItemIndex;
696
697         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
698         {
699                 if (listView.IsItemChecked(groupIndex, itemIndex) == true)
700                 {
701                         IList* pList = null;
702                         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
703                         {
704                                 pList = __pPresentationModel->GetAllPhoneNumbersN(mainGroupIndex, mainItemIndex);
705
706                                 if (pList == null)
707                                 {
708                                         ReturnResultFailed();
709                                 }
710                                 else
711                                 {
712                                         if (pList->GetCount() > 1)
713                                         {
714                                                 listView.SetItemChecked(groupIndex, itemIndex, false);
715                                                 __pContactValueListEvent = new (std::nothrow) ContactValueListItemProvider(pList);
716                                                 ShowContactValuePopup(mainGroupIndex, mainItemIndex);
717                                         }
718                                         else if (pList->GetCount() == 1)
719                                         {
720                                                 String* pContactValueInfo = static_cast<String *>(pList->GetAt(0));
721                                                 int blankIndex = 0;
722                                                 pContactValueInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
723                                                 pContactValueInfo->Remove(0, blankIndex + 1);
724                                                 __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(__selectedIndex)), *(new (std::nothrow) String(*pContactValueInfo)));
725                                                 delete pList;
726                                         }
727                                 }
728                         }
729                         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
730                         {
731                                 pList = __pPresentationModel->GetAllEmailsN(mainGroupIndex, mainItemIndex);
732
733                                 if (pList == null)
734                                 {
735                                         ReturnResultFailed();
736                                 }
737                                 else
738                                 {
739                                         if (pList->GetCount() > 1)
740                                         {
741                                                 listView.SetItemChecked(groupIndex, itemIndex, false);
742                                                 __pContactValueListEvent = new (std::nothrow) ContactValueListItemProvider(pList);
743                                                 ShowContactValuePopup(mainGroupIndex, mainItemIndex);
744                                         }
745                                         else if (pList->GetCount() == 1)
746                                         {
747                                                 String* pContactValueInfo = static_cast<String *>(pList->GetAt(0));
748                                                 int blankIndex = 0;
749                                                 pContactValueInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
750                                                 pContactValueInfo->Remove(0, blankIndex + 1);
751                                                 __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(__selectedIndex)), *(new (std::nothrow) String(*pContactValueInfo)));
752                                                 delete pList;
753                                         }
754                                 }
755                         }
756                 }
757                 else
758                 {
759                         Integer keyIndex(__selectedIndex);
760                         __pTempContactValueHashMap->Remove(keyIndex, true);
761                 }
762         }
763
764         if (listView.Equals(*__pListView) == true)
765         {
766                 if (listView.IsItemChecked(groupIndex, itemIndex) == true)
767                 {
768                         bool isChecked = true;
769                         for (int groupIndex = 0; groupIndex < listView.GetGroupCount() && isChecked == true; groupIndex++)
770                         {
771                                 int itemCount = listView.GetItemCountAt(groupIndex);
772                                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
773                                 {
774                                         if (listView.IsItemChecked(groupIndex, itemIndex) == false)
775                                         {
776                                                 isChecked = false;
777                                                 break;
778                                         }
779                                 }
780                         }
781                         __pSelectAll->SetSelected(isChecked);
782                 }
783                 else if (listView.IsItemChecked(groupIndex, itemIndex) == false)
784                 {
785                         __pSelectAll->SetSelected(false);
786                 }
787         }
788         else if (listView.Equals(*__pSearchListView) == true)
789         {
790                 int count = __pPresentationModel->GetSearchedContactCount();
791
792                 for (int index = 0; index < count; index++)
793                 {
794                         int groupIndex = 0;
795                         int itemIndex = 0;
796
797                         __pPresentationModel->GetItemMainIndex(index, groupIndex, itemIndex);
798
799                         __pListView->SetItemChecked(groupIndex, itemIndex, __pSearchListView->IsItemChecked(0, index));
800                 }
801         }
802
803         UpdateBottomLabel();
804 }
805
806 void
807 ContactListEditorPanel::OnGroupedListViewItemSwept(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, Tizen::Ui::Controls::SweepDirection direction)
808 {
809 }
810
811 void
812 ContactListEditorPanel::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
813 {
814 }
815
816 void
817 ContactListEditorPanel::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
818 {
819         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
820
821         int groupIndex = (__selectedIndex >> LIST_VIEW_GROUP_INDEX_SHIFT) & LIST_VIEW_MASK;
822         int itemIndex = __selectedIndex & LIST_VIEW_MASK;
823
824         IList* pList = null;
825         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
826         {
827                 pList = __pPresentationModel->GetAllPhoneNumbersN(groupIndex, itemIndex);
828         }
829         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
830         {
831                 pList = __pPresentationModel->GetAllEmailsN(groupIndex, itemIndex);
832         }
833
834         if (pList == null)
835         {
836                 ReturnResultFailed();
837         }
838         else
839         {
840                 String* pContactValueInfo = static_cast<String *>(pList->GetAt(index));
841                 int blankIndex = 0;
842                 pContactValueInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
843                 pContactValueInfo->Remove(0, blankIndex + 1);
844                 __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(__selectedIndex)), *(new (std::nothrow) String(*pContactValueInfo)));
845         }
846         delete pList;
847
848         HideContactValuePopup();
849
850         if (__pListView->GetShowState() == true)
851         {
852                 __pListView->SetItemChecked(groupIndex, itemIndex, true);
853
854                 bool isChecked = true;
855                 for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount() && isChecked == true; groupIndex++)
856                 {
857                         int itemCount = __pListView->GetItemCountAt(groupIndex);
858                         for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
859                         {
860                                 if (__pListView->IsItemChecked(groupIndex, itemIndex) == false)
861                                 {
862                                         isChecked = false;
863                                         break;
864                                 }
865                         }
866                 }
867
868                 __pSelectAll->SetSelected(isChecked);
869         }
870         else
871         {
872                 groupIndex = (__selectedSearchIndex >> LIST_VIEW_GROUP_INDEX_SHIFT) & LIST_VIEW_MASK;
873                 itemIndex = __selectedSearchIndex & LIST_VIEW_MASK;
874                 __pSearchListView->SetItemChecked(groupIndex, itemIndex, true);
875
876                 int count = __pPresentationModel->GetSearchedContactCount();
877
878                 for (int index = 0; index < count; index++)
879                 {
880                         __pPresentationModel->GetItemMainIndex(index, groupIndex, itemIndex);
881
882                         __pListView->SetItemChecked(groupIndex, itemIndex, __pSearchListView->IsItemChecked(0, index));
883                 }
884         }
885
886         UpdateBottomLabel();
887 }
888
889 void
890 ContactListEditorPanel::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
891 {
892 }
893
894 void
895 ContactListEditorPanel::OnFastScrollIndexSelected(Tizen::Ui::Control& source, Tizen::Base::String& index)
896 {
897         __pListView->ScrollToItem(__pPresentationModel->GetKeyIndex(index), -1);
898         __pListView->Invalidate(false);
899 }
900
901 void
902 ContactListEditorPanel::OnTextValueChanged(const Tizen::Ui::Control& source)
903 {
904         String searchText = __pSearchBar->GetText();
905         searchText.Trim();
906
907         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
908         if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
909         {
910                 __pPresentationModel->SetSearchText(searchText, SEARCH_TYPE_HAS_PHONE_ONLY);
911         }
912         else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
913         {
914                 __pPresentationModel->SetSearchText(searchText, SEARCH_TYPE_HAS_EMAIL_ONLY);
915         }
916         else
917         {
918                 __pPresentationModel->SetSearchText(searchText, SEARCH_TYPE_NORMAL);
919         }
920
921         if (searchText.GetLength() != 0)
922         {
923                 __pCheckLabel->SetShowState(false);
924                 __pSelectAll->SetShowState(false);
925                 __pListView->SetShowState(false);
926                 __pSearchListView->SetShowState(true);
927
928                 __pSearchListView->UpdateList();
929
930                 int count = __pPresentationModel->GetSearchedContactCount();
931
932                 for (int index = 0; index < count; index++)
933                 {
934                         int groupIndex = 0;
935                         int itemIndex = 0;
936
937                         __pPresentationModel->GetItemMainIndex(index, groupIndex, itemIndex);
938                         __pSearchListView->SetItemChecked(0, index, __pListView->IsItemChecked(groupIndex, itemIndex));
939                 }
940
941                 __pSearchListView->Invalidate(true);
942         }
943         else
944         {
945                 __pCheckLabel->SetShowState(true);
946                 __pSelectAll->SetShowState(true);
947                 __pListView->SetShowState(true);
948                 __pSearchListView->SetShowState(false);
949
950                 int count = __pPresentationModel->GetSearchedContactCount();
951                 bool isChecked = true;
952
953                 for (int index = 0; index < count; index++)
954                 {
955                         int groupIndex = 0;
956                         int itemIndex = 0;
957
958                         __pPresentationModel->GetItemMainIndex(index, groupIndex, itemIndex);
959                         __pListView->SetItemChecked(groupIndex, itemIndex, __pSearchListView->IsItemChecked(0, index));
960                 }
961
962                 for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount() && isChecked == true; groupIndex++)
963                 {
964                         int itemCount = __pListView->GetItemCountAt(groupIndex);
965                         for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
966                         {
967                                 if (__pListView->IsItemChecked(groupIndex, itemIndex) == false)
968                                 {
969                                         isChecked = false;
970                                         break;
971                                 }
972                         }
973                 }
974
975                 __pSelectAll->SetSelected(isChecked);
976                 __pListView->Invalidate(true);
977         }
978 }
979
980 void
981 ContactListEditorPanel::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
982 {
983 }
984
985 void
986 ContactListEditorPanel::OnContactsChanged(void)
987 {
988         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
989         Form* pForm = dynamic_cast<Form*>(GetParent());
990         AppAssert(pForm);
991
992         HideContactValuePopup();
993
994         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
995         {
996                 Footer* pFooter = pForm->GetFooter();
997                 pFooter->RemoveAllItems();
998
999                 FooterItem footerItemDone;
1000                 footerItemDone.Construct(IDA_FOOTER_DONE);
1001                 footerItemDone.SetText(ResourceManager::GetString(L"IDS_COM_SK_DONE"));
1002                 pFooter->AddItem(footerItemDone);
1003
1004                 __pPresentationModel->InitializeContactList();
1005
1006                 if (__pPresentationModel->GetContactCount() == 0)
1007                 {
1008                         pFooter->SetItemEnabled(0, false);
1009
1010                         __pSearchBar->SetShowState(false);
1011                         __pCheckLabel->SetShowState(false);
1012                         __pSelectAll->SetShowState(false);
1013                         __pListView->SetShowState(false);
1014                         __pEmptyImageLabel->SetShowState(true);
1015                         __pEmptyCommentLabel->SetShowState(true);
1016                         __pBottomLabel->SetShowState(false);
1017                 }
1018                 else
1019                 {
1020                         if (__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
1021                         {
1022                                 Form* pForm = dynamic_cast<Form*>(GetParent());
1023                                 AppAssert(pForm);
1024
1025                                 __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
1026                                 pForm->SetFocus();
1027                         }
1028
1029                         __pListView->SetShowState(true);
1030                         __pSelectAll->SetShowState(true);
1031                         __pCheckLabel->SetShowState(true);
1032
1033                         for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
1034                         {
1035                                 int itemCount = __pListView->GetItemCountAt(groupIndex);
1036                                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
1037                                 {
1038                                         if (__pListView->IsItemChecked(groupIndex, itemIndex) == true)
1039                                         {
1040                                                 __pListView->SetItemChecked(groupIndex, itemIndex, false);
1041                                         }
1042                                 }
1043                         }
1044
1045                         pFooter->SetItemEnabled(0, false);
1046
1047                         __pSearchBar->SetShowState(true);
1048                         __pSelectAll->SetSelected(false);
1049                         __pEmptyImageLabel->SetShowState(false);
1050                         __pEmptyCommentLabel->SetShowState(false);
1051                         UpdateBottomLabel();
1052
1053                         __pListView->SetFastScrollIndex(__pPresentationModel->GetAllKeys(), false);
1054                         __pListView->UpdateList();
1055                 }
1056         }
1057         else if (__isContactRemoved == false)
1058         {
1059                 __pPresentationModel->InitializeContactList();
1060                 if( __pPresentationModel->GetContactCount() == 0)
1061                 {
1062                         SceneManager* pSceneManager = SceneManager::GetInstance();
1063                         pSceneManager->GoBackward(BackwardSceneTransition());
1064                         return;
1065                 }
1066                 if (__pSearchBar->GetMode() == SEARCH_BAR_MODE_INPUT)
1067                 {
1068                         Form* pForm = dynamic_cast<Form*>(GetParent());
1069                         AppAssert(pForm);
1070
1071                         __pSearchBar->SetMode(SEARCH_BAR_MODE_NORMAL);
1072                         pForm->SetFocus();
1073                 }
1074                 __pSelectAll->SetSelected(false);
1075
1076                 for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
1077                 {
1078                         int itemCount = __pListView->GetItemCountAt(groupIndex);
1079                         for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
1080                         {
1081                                 if (__pListView->IsItemChecked(groupIndex, itemIndex) == true)
1082                                 {
1083                                         __pListView->SetItemChecked(groupIndex, itemIndex, false);
1084                                 }
1085                         }
1086                 }
1087                 UpdateBottomLabel();
1088                 __pListView->SetFastScrollIndex(__pPresentationModel->GetAllKeys(), false);
1089                 __pListView->UpdateList();
1090         }
1091 }
1092
1093 void
1094 ContactListEditorPanel::OnCategoriesChanged(void)
1095 {
1096 }
1097
1098 result
1099 ContactListEditorPanel::UpdateBottomLabel(void)
1100 {
1101         Form* pForm = dynamic_cast<Form*>(GetParent());
1102         AppAssert(pForm);
1103         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1104         int selectedCount = 0;
1105         int fotterItemIndex = 1;
1106
1107         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
1108         {
1109                 fotterItemIndex = 0;
1110         }
1111
1112
1113         for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
1114         {
1115                 int itemCount = __pListView->GetItemCountAt(groupIndex);
1116                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
1117                 {
1118                         if (__pListView->IsItemChecked(groupIndex, itemIndex) == true)
1119                         {
1120                                 selectedCount++;
1121                         }
1122                 }
1123         }
1124
1125         String selected = ResourceManager::GetString(L"IDS_COM_POP_SELECTED");
1126         selected.Append(L" (");
1127         selected.Append(selectedCount);
1128         selected.Append(L")");
1129         __pBottomLabel->SetText(selected);
1130         __pBottomLabel->SetPosition(FloatPoint(0, pForm->GetClientAreaBoundsF().height - H_BOTTOM_LABEL));
1131         __pBottomLabel->Invalidate(false);
1132
1133         Footer* pFooter = pForm->GetFooter();
1134
1135         if (selectedCount > 0 && __pBottomLabel->GetShowState() == false)
1136         {
1137                 __pBottomLabel->SetShowState(true);
1138                 __pListView->SetSize(__pListView->GetSize().width, __pListView->GetSize().height - H_BOTTOM_LABEL);
1139                 __pSearchListView->SetSize(__pSearchListView->GetSize().width, __pSearchListView->GetSize().height - H_BOTTOM_LABEL);
1140                 pFooter->SetItemEnabled(fotterItemIndex, true);
1141         }
1142         else if (selectedCount == 0 && __pBottomLabel->GetShowState() == true)
1143         {
1144                 __pBottomLabel->SetShowState(false);
1145                 __pListView->SetSize(__pListView->GetSize().width, __pListView->GetSize().height + H_BOTTOM_LABEL);
1146                 __pSearchListView->SetSize(__pSearchListView->GetSize().width, __pSearchListView->GetSize().height + H_BOTTOM_LABEL);
1147                 pFooter->SetItemEnabled(fotterItemIndex, false);
1148         }
1149
1150         pFooter->Invalidate(true);
1151
1152         return E_SUCCESS;
1153 }
1154
1155 void
1156 ContactListEditorPanel::ShowContactValuePopup(int groupIndex, int itemIndex)
1157 {
1158         delete __pMultipleContactValuePopup;
1159         __pMultipleContactValuePopup = new (std::nothrow) Popup();
1160         __pMultipleContactValuePopup->Construct(true, Dimension(W_CONTACT_VALUE_POPUP, H_CONTACT_VALUE_POPUP));
1161         __pMultipleContactValuePopup->SetTitleText(__pPresentationModel->GetName(groupIndex, itemIndex));
1162         __pMultipleContactValuePopup->SetPropagatedKeyEventListener(this);
1163
1164         Rectangle popupClientBounds = __pMultipleContactValuePopup->GetClientAreaBounds();
1165
1166         ListView* pListView = new (std::nothrow) ListView();
1167         pListView->Construct(Rectangle(0, 0, popupClientBounds.width, H_CONTACT_VALUE_POPUP_LIST_VIEW));
1168         pListView->SetItemProvider(*__pContactValueListEvent);
1169         pListView->AddListViewItemEventListener(*this);
1170
1171         __pMultipleContactValuePopup->AddControl(pListView);
1172
1173         Button* pCancelButton = new (std::nothrow) Button();
1174         pCancelButton->Construct(Rectangle((popupClientBounds.width - W_CLOSE_BUTTON) / 2, Y_CLOSE_BUTTON, W_CLOSE_BUTTON, H_CLOSE_BUTTON), ResourceManager::GetString(L"IDS_COM_POP_CLOSE"));
1175         pCancelButton->SetActionId(IDA_POPUP_CONTACT_VALUE_CLOSE);
1176         pCancelButton->AddActionEventListener(*this);
1177
1178         __pMultipleContactValuePopup->AddControl(pCancelButton);
1179         __pMultipleContactValuePopup->SetShowState(true);
1180         __pMultipleContactValuePopup->Show();
1181 }
1182
1183 void
1184 ContactListEditorPanel::HideContactValuePopup(void)
1185 {
1186         if (__pMultipleContactValuePopup != null)
1187         {
1188                 __pMultipleContactValuePopup->SetShowState(false);
1189                 Invalidate(true);
1190         }
1191 }
1192
1193 void
1194 ContactListEditorPanel::ShowDeleteConfirmationPopup(void)
1195 {
1196         if (__pDeleteConfirmationPopup == null)
1197         {
1198                 __pDeleteConfirmationPopup = new (std::nothrow) Popup();
1199                 __pDeleteConfirmationPopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_POPUP));
1200                 __pDeleteConfirmationPopup->SetPropagatedKeyEventListener(this);
1201
1202                 Rectangle popupClientBounds = __pDeleteConfirmationPopup->GetClientAreaBounds();
1203
1204                 Label* pLabel = new (std::nothrow) Label();
1205                 pLabel->Construct(Rectangle(X_DELETE_LABEL, Y_DELETE_LABEL, W_DELETE_LABEL, H_DELETE_LABEL), ResourceManager::GetString(L"IDS_COM_POP_DELETE_Q"));
1206                 pLabel->SetTextConfig(FONT_SIZE_DELETE_CONFIRM, LABEL_TEXT_STYLE_NORMAL);
1207                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
1208                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1209
1210                 Button* pDeleteButton = new (std::nothrow) Button();
1211                 pDeleteButton->Construct(Rectangle(X_DELETE_LABEL + W_DELETE_BUTTON + W_POPUP_ITEM_GAP, Y_DELETE_BUTTON, W_DELETE_BUTTON, H_DELETE_BUTTON), ResourceManager::GetString(L"IDS_COM_SK_DELETE"));
1212                 pDeleteButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_DELETE_BUTTON_NORMAL);
1213                 pDeleteButton->SetColor(BUTTON_STATUS_PRESSED, COLOR_DELETE_BUTTON_PRESSED);
1214                 pDeleteButton->SetTextColor(COLOR_DELETE_BUTTON_TEXT);
1215                 pDeleteButton->SetTextSize(FONT_SIZE_DELETE_BUTTON);
1216                 pDeleteButton->SetActionId(IDA_POPUP_DELETE_OK);
1217                 pDeleteButton->AddActionEventListener(*this);
1218
1219                 Button* pCancelButton = new (std::nothrow) Button();
1220                 pCancelButton->Construct(Rectangle(X_DELETE_LABEL, Y_DELETE_BUTTON, W_DELETE_BUTTON, H_DELETE_BUTTON), ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
1221                 pCancelButton->SetTextSize(FONT_SIZE_DELETE_BUTTON);
1222                 pCancelButton->SetActionId(IDA_POPUP_DELETE_CANCEL);
1223                 pCancelButton->AddActionEventListener(*this);
1224
1225                 __pDeleteConfirmationPopup->AddControl(pLabel);
1226                 __pDeleteConfirmationPopup->AddControl(pDeleteButton);
1227                 __pDeleteConfirmationPopup->AddControl(pCancelButton);
1228         }
1229
1230         __pDeleteConfirmationPopup->SetShowState(true);
1231         __pDeleteConfirmationPopup->Show();
1232 }
1233
1234 void
1235 ContactListEditorPanel::HideDeleteConfirmationPopup(void)
1236 {
1237         if (__pDeleteConfirmationPopup != null)
1238         {
1239                 __pDeleteConfirmationPopup->SetShowState(false);
1240                 Invalidate(true);
1241         }
1242 }
1243
1244 void
1245 ContactListEditorPanel::ShowDeleteProgressPopup(void)
1246 {
1247         if (__pDeleteProgressPopup != null)
1248         {
1249                 delete __pDeleteProgressPopup;
1250         }
1251
1252         __pDeleteProgressPopup = new (std::nothrow) Popup();
1253         __pDeleteProgressPopup->Construct(false, Dimension(W_DELETE_POPUP, H_DELETE_PROGRESS_POPUP));
1254         __pDeleteProgressPopup->AddWindowEventListener(*this);
1255
1256         Rectangle clientBounds = __pDeleteProgressPopup->GetClientAreaBounds();
1257
1258         Label* pLabelTitle = new (std::nothrow) Label();
1259         pLabelTitle->Construct(Rectangle(0, Y_DELETE_POPUP_TITLE, clientBounds.width, H_DELETE_POPUP_ELEMENT), ResourceManager::GetString(L"IDS_PB_POP_DELETING_CONTACTS_ING"));
1260         pLabelTitle->SetTextColor(COLOR_DELETE_POPUP_TEXT);
1261         pLabelTitle->SetTextConfig(FONT_SIZE_DELETE_POPUP_TEXT, LABEL_TEXT_STYLE_BOLD);
1262         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1263
1264         __pDeleteProgressPopup->AddControl(pLabelTitle);
1265
1266         Progress* pProgress = new (std::nothrow) Progress();
1267         pProgress->Construct(Rectangle(0, Y_DELETE_POPUP_TITLE + H_DELETE_POPUP_ELEMENT, clientBounds.width, H_DELETE_POPUP_PROGRESS), 0, GetCheckedContactCounts());
1268
1269         __pDeleteProgressPopup->AddControl(pProgress);
1270
1271         Label* pLabelPercentage = new (std::nothrow) Label();
1272         pLabelPercentage->Construct(Rectangle(0, pProgress->GetY() + pProgress->GetHeight(), clientBounds.width / 2, H_DELETE_POPUP_ELEMENT), Integer::ToString(pProgress->GetPercentComplete()) + L"%");
1273         pLabelPercentage->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
1274         pLabelPercentage->SetTextColor(COLOR_DELETE_POPUP_TEXT);
1275         pLabelPercentage->SetTextConfig(FONT_SIZE_DELETE_POPUP_TEXT, LABEL_TEXT_STYLE_NORMAL);
1276
1277         __pDeleteProgressPopup->AddControl(pLabelPercentage);
1278
1279         String currentOfTotal(Integer::ToString(pProgress->GetValue()) + L" / " + Integer::ToString(GetCheckedContactCounts()));
1280         Label* pLabelTotal = new (std::nothrow) Label();
1281         pLabelTotal->Construct(Rectangle(clientBounds.width / 2, pLabelPercentage->GetY(), clientBounds.width / 2, H_DELETE_POPUP_ELEMENT), currentOfTotal);
1282         pLabelTotal->SetTextHorizontalAlignment(ALIGNMENT_RIGHT);
1283         pLabelTotal->SetTextColor(COLOR_DELETE_POPUP_TEXT);
1284         pLabelTotal->SetTextConfig(FONT_SIZE_DELETE_POPUP_TEXT, LABEL_TEXT_STYLE_NORMAL);
1285
1286         __pDeleteProgressPopup->AddControl(pLabelTotal);
1287
1288         Button* pCancelButton = new (std::nothrow) Button();
1289         pCancelButton->Construct(Rectangle((clientBounds.width - W_DELETE_POPUP_CANCEL_BUTTON) / 2, Y_DELETE_POPUP_CANCEL_BUTTON, W_DELETE_POPUP_CANCEL_BUTTON, H_DELETE_POPUP_CANCEL_BUTTON));
1290         pCancelButton->SetText(ResourceManager::GetString("IDS_PB_SK_CANCEL"));
1291         pCancelButton->SetActionId(IDA_POPUP_DELETE_PROGRESS_CANCEL);
1292         pCancelButton->AddActionEventListener(*this);
1293
1294         __pDeleteProgressPopup->AddControl(pCancelButton);
1295         __pDeleteProgressPopup->Show();
1296
1297         __isContactRemoved = true;
1298 }
1299
1300 void
1301 ContactListEditorPanel::HideDeleteProgressPopup(void)
1302 {
1303         if (__pDeleteProgressPopup != null)
1304         {
1305                 delete __pDeleteProgressPopup;
1306                 __pDeleteProgressPopup = null;
1307         }
1308         __isContactRemoved = false;
1309
1310         __pListView->UpdateList();
1311         Invalidate(true);
1312 }
1313
1314 void
1315 ContactListEditorPanel::ReturnValues(RequestId requestId, Tizen::App::AppCtrlResult appCtrlResult, const Tizen::Base::Collection::IMap* pReturnValue)
1316 {
1317         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
1318         result r = pAppManager->SendAppControlResult(requestId, appCtrlResult, pReturnValue);
1319         AppLogDebug("[%s] The return result from SendAppControlResult(), AppCtrlResult value : %d.", GetErrorMessage(r), appCtrlResult);
1320
1321         UiApp::GetInstance()->Terminate();
1322 }
1323
1324 void
1325 ContactListEditorPanel::ReturnMultipleValues(void)
1326 {
1327         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1328
1329         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
1330         {
1331                 ArrayList* pValueList = new (std::nothrow) ArrayList();
1332                 pValueList->Construct();
1333
1334                 HashMap* pReturnValue = new (std::nothrow) HashMap();
1335                 pReturnValue->Construct();
1336
1337                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
1338                 {
1339                         IMapEnumerator* pMapEnum = __pTempContactValueHashMap->GetMapEnumeratorN();
1340                         while (pMapEnum->MoveNext() == E_SUCCESS)
1341                         {
1342                                 String* pValue = static_cast<String*> (pMapEnum->GetValue());
1343                                 pValueList->Add(new (std::nothrow) String(*pValue));
1344                         }
1345                         pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_PHONE), pValueList);
1346
1347                         delete pMapEnum;
1348                 }
1349                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
1350                 {
1351                         IMapEnumerator* pMapEnum = __pTempContactValueHashMap->GetMapEnumeratorN();
1352                         while (pMapEnum->MoveNext() == E_SUCCESS)
1353                         {
1354                                 String* pValue = static_cast<String*> (pMapEnum->GetValue());
1355                                 pValueList->Add(new (std::nothrow) String(*pValue));
1356                         }
1357                         pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_EMAIL), pValueList);
1358
1359                         delete pMapEnum;
1360                 }
1361                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_ITEM_ID)
1362                 {
1363                         for (int groupIndex = 0; groupIndex < __pListView->GetGroupCount(); groupIndex++)
1364                         {
1365                                 int itemCount = __pListView->GetItemCountAt(groupIndex);
1366                                 for (int itemIndex = 0; itemIndex < itemCount; itemIndex++)
1367                                 {
1368                                         if (__pListView->IsItemChecked(groupIndex, itemIndex) == true)
1369                                         {
1370                                                 String contactId;
1371                                                 contactId.Append(__pPresentationModel->GetContactId(groupIndex, itemIndex));
1372                                                 pValueList->Add(new (std::nothrow) String(contactId));
1373                                         }
1374                                 }
1375                         }
1376                         pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), pValueList);
1377                 }
1378                 else
1379                 {
1380                         delete pValueList;
1381
1382                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
1383
1384                         return;
1385                 }
1386
1387                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
1388         }
1389 }
1390
1391 void
1392 ContactListEditorPanel::ReturnResultFailed(void)
1393 {
1394         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1395
1396         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, null);
1397 }
1398
1399 void
1400 ContactListEditorPanel::OnKeypadWillOpen(Tizen::Ui::Control& source)
1401 {
1402 }
1403
1404 void
1405 ContactListEditorPanel::OnKeypadOpened(Tizen::Ui::Control& source)
1406 {
1407         Form* pForm = dynamic_cast<Form*>(GetParent());
1408         AppAssert(pForm);
1409
1410         if (__pBottomLabel->GetShowState() == true)
1411         {
1412                 __pSearchListView->SetBounds(Rectangle(0, H_SEARCHBAR, pForm->GetClientAreaBounds().width, pForm->GetClientAreaBounds().height - H_SEARCHBAR - H_BOTTOM_LABEL));
1413                 __pBottomLabel->SetPosition(FloatPoint(0, pForm->GetClientAreaBoundsF().height - H_BOTTOM_LABEL));
1414                 __pBottomLabel->Invalidate(true);
1415         }
1416         else
1417         {
1418                 __pSearchListView->SetBounds(Rectangle(0, H_SEARCHBAR, pForm->GetClientAreaBounds().width, pForm->GetClientAreaBounds().height - H_SEARCHBAR));
1419         }
1420 }
1421
1422 void
1423 ContactListEditorPanel::OnKeypadClosed(Tizen::Ui::Control& source)
1424 {
1425         Form* pForm = dynamic_cast<Form*>(GetParent());
1426         AppAssert(pForm);
1427
1428         if (__pBottomLabel->GetShowState() == true)
1429         {
1430                 __pSearchListView->SetBounds(Rectangle(0, H_SEARCHBAR, pForm->GetClientAreaBounds().width, pForm->GetClientAreaBounds().height - H_SEARCHBAR - H_BOTTOM_LABEL));
1431                 __pBottomLabel->SetPosition(FloatPoint(0, pForm->GetClientAreaBoundsF().height - H_BOTTOM_LABEL));
1432                 __pBottomLabel->Invalidate(true);
1433                 if (SceneManager::GetInstance()->GetCurrentSceneId() == IDSCN_CONTACT_LIST_EDITOR)
1434                 {
1435                         UpdateBottomLabel();
1436                 }
1437         }
1438         else
1439         {
1440                 __pSearchListView->SetBounds(Rectangle(0, H_SEARCHBAR, pForm->GetClientAreaBounds().width, pForm->GetClientAreaBounds().height - H_SEARCHBAR));
1441         }
1442 }
1443
1444 void
1445 ContactListEditorPanel::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
1446 {
1447         Form* pForm = dynamic_cast<Form*>(GetParent());
1448         AppAssert(pForm);
1449         if (__pBottomLabel->GetShowState() == true)
1450         {
1451                 __pSearchListView->SetBounds(Rectangle(0, H_SEARCHBAR, pForm->GetClientAreaBounds().width, pForm->GetClientAreaBounds().height - H_SEARCHBAR - H_BOTTOM_LABEL));
1452                 __pBottomLabel->SetPosition(FloatPoint(0, pForm->GetClientAreaBoundsF().height - H_BOTTOM_LABEL));
1453                 __pBottomLabel->Invalidate(true);
1454         }
1455         else
1456         {
1457                 __pSearchListView->SetBounds(Rectangle(0, H_SEARCHBAR, pForm->GetClientAreaBounds().width, pForm->GetClientAreaBounds().height - H_SEARCHBAR));
1458         }
1459 }
1460
1461 void
1462 ContactListEditorPanel::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1463 {
1464         if (keypadAction == KEYPAD_ACTION_SEARCH)
1465         {
1466                 __pSearchBar->HideKeypad();
1467         }
1468 }
1469
1470 void
1471 ContactListEditorPanel::OnWindowActivated (const Tizen::Ui::Window &source)
1472 {
1473         __deleteContactTimer.Start(1);
1474 }
1475
1476 void
1477 ContactListEditorPanel::OnWindowDeactivated (const Tizen::Ui::Window &source)
1478 {
1479 }
1480
1481 void
1482 ContactListEditorPanel::OnTimerExpired(Tizen::Base::Runtime::Timer &timer)
1483 {
1484         Progress* pProgress = static_cast<Progress *>(__pDeleteProgressPopup->GetControl(1));
1485
1486         pProgress->SetValue(pProgress->GetValue() + 1);
1487         pProgress->Invalidate(false);
1488
1489         Label* pLabelPercentage = static_cast<Label *>(__pDeleteProgressPopup->GetControl(2));
1490
1491         pLabelPercentage->SetText(Integer::ToString(pProgress->GetPercentComplete()) + L"%");
1492         pLabelPercentage->Invalidate(false);
1493
1494         Label* pLabelTotal = static_cast<Label *>(__pDeleteProgressPopup->GetControl(3));
1495
1496         String currentOfTotal = pLabelTotal->GetText();
1497         currentOfTotal.Remove(0, Integer::ToString(pProgress->GetValue() - 1).GetLength());
1498         currentOfTotal.Insert(Integer::ToString(pProgress->GetValue()), 0);
1499         pLabelTotal->SetText(currentOfTotal);
1500         pLabelTotal->Invalidate(false);
1501
1502         if (RemoveContactList() == E_SUCCESS)
1503         {
1504                 __deleteContactTimer.Start(1);
1505         }
1506         else
1507         {
1508                 SceneManager* pSceneManager = SceneManager::GetInstance();
1509                 pSceneManager->GoBackward(BackwardSceneTransition());
1510         }
1511 }
1512
1513 void
1514 ContactListEditorPanel::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo & touchInfo)
1515 {
1516         GroupedListView* pList = static_cast<GroupedListView*>(&const_cast<Control&>(source));
1517         if (pList != null)
1518         {
1519                 pList->SetFocus();
1520         }
1521 }
1522
1523 void
1524 ContactListEditorPanel::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1525 {
1526 }
1527
1528 void
1529 ContactListEditorPanel::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1530 {
1531 }
1532
1533 void
1534 ContactListEditorPanel::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1535 {
1536 }
1537
1538 void
1539 ContactListEditorPanel::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
1540 {
1541 }
1542
1543 bool
1544 ContactListEditorPanel::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1545 {
1546         return false;
1547 }
1548
1549 bool
1550 ContactListEditorPanel::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
1551 {
1552         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
1553         {
1554                 if (__pDeleteConfirmationPopup && __pDeleteConfirmationPopup->GetShowState() == true)
1555                 {
1556                         HideDeleteConfirmationPopup();
1557                         return true;
1558                 }
1559                 if (__pMultipleContactValuePopup && __pMultipleContactValuePopup->GetShowState() == true)
1560                 {
1561                         HideContactValuePopup();
1562                         return true;
1563                 }
1564         }
1565         return false;
1566 }
1567
1568 bool
1569 ContactListEditorPanel::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1570 {
1571         return false;
1572 }
1573
1574 bool
1575 ContactListEditorPanel::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
1576 {
1577         return false;
1578 }