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