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