NABI_SE Issue Fix: 45902 45915 and internal issue fix
[apps/osp/Contacts.git] / src / CtContactEditorForm.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        CtContactEditorForm.cpp
19  * @brief       This is the implementation file for the ContactEditorForm class.
20  */
21
22 #include <FApp.h>
23 #include <FMedia.h>
24 #include "CtContactEditorForm.h"
25 #include "CtContactPresentationModel.h"
26 #include "CtContactsApp.h"
27 #include "CtContactValueListItemProvider.h"
28 #include "CtResourceManager.h"
29 #include "CtSceneRegister.h"
30 #include "CtTypes.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Graphics;
37 using namespace Tizen::Io;
38 using namespace Tizen::Media;
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 static const int IDA_ACTION_BAR_SAVE = 11;
46 static const int IDA_BUTTON_THUMBNAIL_ADD = 21;
47 static const int IDA_BUTTON_THUMBNAIL_DELETE = 22;
48 static const int IDA_BUTTON_CAMERA = 23;
49 static const int IDA_BUTTON_EXPANDABLE = 24;
50 static const int IDA_BUTTON_MORE_INFO = 25;
51 static const int IDA_BUTTON_BIRTHDAY_CLEAR = 26;
52 static const int IDA_BUTTON_DEFAULT_PHONE_NUMBER = 27;
53 static const int IDA_BUTTON_RINGTONE_CLEAR = 28;
54 static const int IDA_BUTTON_TYPE = 29;
55 static const int IDA_CONTEXT_MENU_ITEM_JOB_TITLE = 31;
56 static const int IDA_CONTEXT_MENU_ITEM_DEPARTMENT = 32;
57 static const int IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER = 33;
58 static const int IDA_CONTEXT_MENU_ITEM_URL = 34;
59 static const int IDA_CONTEXT_MENU_ITEM_BIRTHDAY = 35;
60 static const int IDA_CONTEXT_MENU_ITEM_NOTE = 36;
61 static const int IDA_INPUT_FIELD_DISPLAY_NAME = 41;
62 static const int IDA_POPUP_SAVE_CONTACT_OK = 44;
63 static const int IDA_POPUP_SAVE_CONTACT_CANCEL = 45;
64
65 static const wchar_t* IDB_EXPAND_BUTTON_NORMAL = L"00_circle_button.png";
66 static const wchar_t* IDB_EXPAND_BUTTON_PRESSED = L"00_circle_button_press.png";
67 static const wchar_t* IDB_EXPAND_CLOSED = L"00_button_expand_closed.png";
68 static const wchar_t* IDB_EXPAND_CLOSED_PRESSED = L"00_button_expand_closed_press.png";
69 static const wchar_t* IDB_EXPAND_OPENED = L"00_button_expand_opened.png";
70 static const wchar_t* IDB_EXPAND_OPENED_PRESSED = L"00_button_expand_opened_press.png";
71 static const wchar_t* IDB_BUTTON_DELETE_NORMAL = L"00_circle_button_delete.png";
72 static const wchar_t* IDB_BUTTON_DELETE_PRESSED = L"00_circle_button_delete_press.png";
73 static const wchar_t* IDB_BUTTON_MINUS = L"00_button_expand_minus_press.png";
74 static const wchar_t* IDB_BUTTON_MINUS_PRESSED = L"00_button_expand_minus_press.png";
75 static const wchar_t* IDB_BUTTON_RESET_NORMAL = L"00_button_refresh.png";
76 static const wchar_t* IDB_BUTTON_RESET_PRESSED = L"00_button_refresh_press.png";
77 static const wchar_t* IDB_BUTTON_ADD= L"C02_caller_id_icon_add.png";
78 static const wchar_t* IDB_BUTTON_ADD_PRESSED = L"C02_caller_id_icon_add_press.png";
79 static const wchar_t* IDB_BUTTON_CAMERA = L"C02_caller_id_icon_camera.png";
80 static const wchar_t* IDB_BUTTON_CAMERA_PRESSED = L"C02_caller_id_icon_camera_press.png";
81 static const wchar_t* IDB_BUTTON_DROPBOX = L"C02_button_icon_dropbox.png";
82 static const wchar_t* IDB_THUMBNAIL_BACKGROUND = L"C02_created_photo_bg.png";
83 static const wchar_t* IDB_DETAILS_RESET_NORMAL = L"00_button_refresh.png";
84 static const wchar_t* IDB_DETAILS_RESET_PRESSED = L"00_button_refresh_press.png";
85
86 static const wchar_t* INPUT_DATA_SELECTION_MODE_SINGLE = L"single";
87 static const wchar_t* INPUT_KEY_SELECTION_MODE = L"http://tizen.org/appcontrol/data/selection_mode";
88 static const wchar_t* INPUT_KEY_ALLOW_SWITCH = L"http://tizen.org/appcontrol/data/camera/allow_switch";
89 static const wchar_t* INPUT_MIME_TYPE_CAMERA = L"image/jpg";
90 static const wchar_t* INPUT_MIME_TYPE_GALLERY = L"image/*";
91 static const wchar_t* INPUT_MIME_TYPE_AUDIO = L"audio/*";
92 static const wchar_t* INPUT_VALUE_FALSE = L"false";
93 static const wchar_t* OUTPUT_KEY_SELECTED = L"http://tizen.org/appcontrol/data/selected";
94 static const wchar_t* SD_CARD_UNMOUNTED = L"Unmounted";
95
96 static const int H_ITEM = 112;
97 static const int H_DOUBLE_LINE_ITEM = 140;
98 static const int H_LABEL = 40;
99 static const int H_DESCRIPTION_CONTAINER = 136;
100 static const int H_DIVIDER = 1;
101 static const int W_DIVIDER = 1;
102 static const int H_EMPTY_SPACE = 32;
103 static const int H_EXPANDED_NAME_FIELDS = 672;
104 static const int H_BUTTON = 74;
105 static const int H_ICON_BUTTON = 74;
106 static const int W_THUMBNAIL = 360;
107 static const int W_TITLE_LABEL = 170;
108 static const int X_MORE_INFORMATION_BUTTON = 60;
109 static const int Y_MORE_INFORMATION_BUTTON = 30;
110 static const int Y_DEFAULT_NUMBER_BUTTON = 19;
111 static const int W_ITEM_GAP = 16;
112 static const int W_TYPE_BUTTON = 186;
113 static const int W_THUMBNAIL_DELETE_BUTTON_GAP = 10;
114 static const int H_THUMBNAIL_DELETE_BUTTON_GAP = 10;
115 static const int H_THUMBNAIL_GROUP_ITEM_HEIGHT = 34;
116 static const int H_NAMEFIELD_GROUP_ITEM_HEIGHT = 40;
117 static const int H_GROUP_RINGTONE_TITLE_GAP = 22;
118 static const int H_GROUP_RINGTONE_TITLE_LABEL = 42;
119 static const int H_GROUP_RINGTONE_VALUE_LABEL = 54;
120 static const int W_DROPBOX_ICON = 29;
121 static const int H_DROPBOX_ICON = 29;
122 static const int W_SAVE_CONTACT_POPUP = 688;
123 static const int H_SAVE_CONTACT_POPUP = 230;
124 static const int W_SAVE_CONTACT_LABEL = 656;
125 static const int H_SAVE_CONTACT_LABEL = 80;
126 static const int X_SAVE_CONTACT_LABEL = 16;
127 static const int Y_SAVE_CONTACT_LABEL = 32;
128 static const int Y_SAVE_CONTACT_BUTTON = 132;
129 static const int H_SAVE_CONTACT_BUTTON = 74;
130 static const int W_SAVE_CONTACT_BUTTON = 318;
131 static const int W_POPUP_ITEM_GAP = 20;
132 static const int X_REFRESH_BUTTON_MARGIN = 88;
133 static const int Y_EDIT_FIELD_GAP = 5;
134 static const int H_EDIT_FIELD_GAP = 10;
135
136 static const int X_MORE_INFO_PANEL_GAP = 5;
137 static const int H_MORE_INFO_PANEL_GAP = 10;
138
139 static const int FONT_SIZE_SAVE_CONTACT_CONFIRM = 42;
140 static const int FONT_SIZE_SAVE_CONTACT_BUTTON = 36;
141
142 static const int FONT_SIZE_VALUE_TEXT = 44;
143 static const int FONT_SIZE_TITLE_TEXT = 32;
144
145 static const int GROUP_ITEM_COUNT = 11;
146 static const int NAME_FIELD_ITEM_COUNT = 1;
147
148 static const int EDIT_FIELD_EXTENDED_LENGTH = 100;
149
150 static const int MESSAGE_BOX_TIMEOUT_MS = 300000;
151
152 static const unsigned int COLOR_TABLE_VIEW_BG = Color32<248, 246, 239>::Value;
153 static const unsigned int COLOR_DIVIDER = Color32<169, 169, 169>::Value;
154 static const unsigned int COLOR_THUMBNAIL_BACKGROUND = Color32<239, 237, 229>::Value;
155 static const unsigned int COLOR_ITEM_TITLE = Color32<128, 128, 128>::Value;
156
157 static const int TABLE_VIEW_DELETE_INPUT_FIELD_ID = 0xE0000000;
158 static const int TABLE_VIEW_INPUT_FIELD_ACTION_MASK = 0xF0000000;
159 static const int TABLE_VIEW_INPUT_FIELD_INDEX_MASK = 0x0F000000;
160 static const int TABLE_VIEW_GROUP_INDEX_MASK = 0x00FF0000;
161 static const int TABLE_VIEW_ITEM_INDEX_MASK = 0x0000FFFF;
162 static const int TABLE_VIEW_GROUP_INDEX_SHIFT = 16;
163 static const int TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT = 24;
164 static const int TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT = 28;
165 static const int TABLE_VIEW_THUMBNAIL_FIELD_INDEX = 0;
166 static const int TABLE_VIEW_NAME_FIELD_INDEX = 1;
167 static const int TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX = 2;
168 static const int TABLE_VIEW_EMAIL_FIELD_INDEX = 3;
169 static const int TABLE_VIEW_ADDRESS_FIELD_INDEX = 4;
170 static const int TABLE_VIEW_IM_ADDRESS_FIELD_INDEX = 5;
171 static const int TABLE_VIEW_URL_FIELD_INDEX = 6;
172 static const int TABLE_VIEW_BIRTHDAY_FIELD_INDEX = 7;
173 static const int TABLE_VIEW_NOTE_FIELD_INDEX = 8;
174 static const int TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX = 9;
175 static const int TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX = 10;
176
177 static const wchar_t* INPUT_TYPE_PHONE = L"phone";
178 static const wchar_t* INPUT_TYPE_EMAIL = L"email";
179 static const wchar_t* INPUT_TYPE_URL = L"url";
180 static const wchar_t* VIEW_TYPE = L"viewType";
181 static const wchar_t* VIEW_TYPE_VALUE_CONTACT = L"contact";
182 static const wchar_t* VIEW_TYPE_CONTACT_ID = L"contactId";
183
184 ContactEditorForm::ContactEditorForm(void)
185 : __isExpandable(false)
186 , __isAppControl(false)
187 , __isJobTitleEnabled(false)
188 , __isDepartmentEnabled(false)
189 , __isDefaultPhoneNumberButtonEnabled(false)
190 , __isSaved(false)
191 , __isMoreInformationContextMenuShowing(false)
192 , __isTypeContextMenuShowing(false)
193 , __isKeypadOpened(false)
194 , __isScrollOccurred(false)
195 , __isContactModified(false)
196 , __scrolledDistance(0)
197 , __delGroupIndex(-1)
198 , __delItemIndex(-1)
199 , __itemIndex(-1)
200 , __groupIndex(-1)
201 , __pAppControl(null)
202 , __pPhoneNumberFieldItem(null)
203 , __pEmailFieldItem(null)
204 , __pAddressFieldItem(null)
205 , __pImAddressFieldItem(null)
206 , __pUrlFieldItem(null)
207 , __pFileEventManager(null)
208 , __pSaveContactPopup(null)
209 , __pCurrentFocusedItem(null)
210 , __pDefaultPhoneNumberContextMenu(null)
211 , __pMoreInformationContextMenu(null)
212 , __pThumbnailContextMenu(null)
213 , __pTypeContextMenu(null)
214 , __pTableView(null)
215 , __pNameFieldItem(null)
216 , __pNoteFieldItem(null)
217 , __pPresentationModel(null)
218 {
219 }
220
221 ContactEditorForm::~ContactEditorForm(void)
222 {
223 }
224
225 void
226 ContactEditorForm::Initialize(void)
227 {
228         Construct(FORM_STYLE_NORMAL | FORM_STYLE_INDICATOR | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
229 }
230
231 result
232 ContactEditorForm::OnInitializing(void)
233 {
234         SetFormBackEventListener(this);
235         SettingInfo::AddSettingEventListener(*this);
236
237         Footer* pFooter = GetFooter();
238
239         FooterItem footerItemSave;
240         footerItemSave.Construct(IDA_ACTION_BAR_SAVE);
241         footerItemSave.SetText(ResourceManager::GetString(L"IDS_COM_SK_SAVE"));
242
243         pFooter->AddItem(footerItemSave);
244         pFooter->AddActionEventListener(*this);
245
246         __pTableView = new (std::nothrow) GroupedTableView();
247         __pTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), false, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
248         __pTableView->SetItemProvider(this);
249         __pTableView->AddScrollEventListener(*this);
250         __pTableView->AddGroupedTableViewItemEventListener(*this);
251         AddControl(__pTableView);
252
253         __pPhoneNumberFieldItem = new (std::nothrow) ArrayList();
254         __pPhoneNumberFieldItem->Construct();
255
256         __pEmailFieldItem = new (std::nothrow) ArrayList();
257         __pEmailFieldItem->Construct();
258
259         __pAddressFieldItem = new (std::nothrow) ArrayList();
260         __pAddressFieldItem->Construct();
261
262         __pImAddressFieldItem = new (std::nothrow) ArrayList();
263         __pImAddressFieldItem->Construct();
264
265         __pUrlFieldItem = new (std::nothrow) ArrayList();
266         __pUrlFieldItem->Construct();
267
268         __pPresentationModel = new (std::nothrow) ContactPresentationModel();
269         __pPresentationModel->Construct();
270         __pPresentationModel->AddContactChangeListener(*this);
271
272         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
273
274         return E_SUCCESS;
275 }
276
277 result
278 ContactEditorForm::OnTerminating(void)
279 {
280         AppLog("ContactEditorForm::OnTerminating()");
281
282         result r = E_SUCCESS;
283
284         __pTableView->SetItemProvider(null);
285
286         if (__pPresentationModel != null)
287         {
288                 __pPresentationModel->RemoveContactChangeListener(*this);
289                 delete __pPresentationModel;
290         }
291
292         if (__pPhoneNumberFieldItem)
293         {
294                 __pPhoneNumberFieldItem->RemoveAll(true);
295                 delete __pPhoneNumberFieldItem;
296         }
297
298         if (__pEmailFieldItem)
299         {
300                 __pEmailFieldItem->RemoveAll(true);
301                 delete __pEmailFieldItem;
302         }
303
304         if (__pAddressFieldItem)
305         {
306                 __pAddressFieldItem->RemoveAll(true);
307                 delete __pAddressFieldItem;
308         }
309
310         if (__pUrlFieldItem)
311         {
312                 __pUrlFieldItem->RemoveAll(true);
313                 delete __pUrlFieldItem;
314         }
315
316         if (__pImAddressFieldItem)
317         {
318                 __pImAddressFieldItem->RemoveAll(true);
319                 delete __pImAddressFieldItem;
320         }
321         if (__pSaveContactPopup)
322         {
323                 delete __pSaveContactPopup;
324         }
325         delete __pAppControl;
326         delete __pNameFieldItem;
327         delete __pNoteFieldItem;
328         delete __pDefaultPhoneNumberContextMenu;
329         delete __pMoreInformationContextMenu;
330         delete __pThumbnailContextMenu;
331         delete __pTypeContextMenu;
332         delete __pFileEventManager;
333
334         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
335         SettingInfo::RemoveSettingEventListener(*this);
336
337         return r;
338 }
339
340 void
341 ContactEditorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
342 {
343         SetFocus();
344
345         if( IsSaveContactValid() == true  && __isContactModified == true)
346         {
347                 ShowSaveContactPopup();
348                 return;
349         }
350         if (__isAppControl == true)
351         {
352                 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
353                 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
354
355                 result r = pAppManager->SendAppControlResult(pContactsApp->GetRequestId(), APP_CTRL_RESULT_CANCELED, null);
356                 AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
357
358                 UiApp::GetInstance()->Terminate();
359         }
360         else
361         {
362                 SceneManager* pSceneManager = SceneManager::GetInstance();
363
364                 result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
365                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
366         }
367 }
368
369 void
370 ContactEditorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
371 {
372         AppLog("ContactEditorForm::OnActionPerformed(), actionId %d", actionId);
373
374         if ((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) == TABLE_VIEW_DELETE_INPUT_FIELD_ID)
375         {
376                 int groupIndex = (actionId & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
377                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
378
379                 if (groupIndex > TABLE_VIEW_NAME_FIELD_INDEX)
380                 {
381                         DeleteInputField(groupIndex, itemIndex);
382                         __isContactModified = true;
383                 }
384
385                 return;
386         }
387         else if (&source == __pDefaultPhoneNumberContextMenu)
388         {
389                 SetAsDefaultPhoneNumber(actionId);
390                 __isContactModified = true;
391
392                 return;
393         }
394         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
395         {
396                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
397                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
398
399                 TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(itemIndex));
400                 if (pItem == null)
401                 {
402                         return;
403                 }
404                 pItem->SetName(Integer::ToString(selectedItemIndex));
405
406                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
407                 if (pButtonType == null)
408                 {
409                         return;
410                 }
411
412                 pButtonType->SetText(__pPresentationModel->GetPhoneNumberTypeString((DetailPhoneNumberType)selectedItemIndex));
413                 pButtonType->Invalidate(false);
414
415                 __isContactModified = true;
416                 return;
417         }
418         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_EMAIL_FIELD_INDEX)
419         {
420                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
421                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
422
423                 TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(itemIndex));
424                 if (pItem == null)
425                 {
426                         return;
427                 }
428                 pItem->SetName(Integer::ToString(selectedItemIndex));
429
430                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
431                 if (pButtonType == null)
432                 {
433                         return;
434                 }
435
436                 pButtonType->SetText(__pPresentationModel->GetEmailTypeString((DetailEmailType)selectedItemIndex));
437                 pButtonType->Invalidate(false);
438
439                 __isContactModified = true;
440                 return;
441         }
442         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_ADDRESS_FIELD_INDEX)
443         {
444                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
445                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
446
447                 TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(itemIndex));
448                 if (pItem == null)
449                 {
450                         return;
451                 }
452                 pItem->SetName(Integer::ToString(selectedItemIndex));
453
454                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
455                 if (pButtonType == null)
456                 {
457                         return;
458                 }
459
460                 pButtonType->SetText(__pPresentationModel->GetAddressTypeString((DetailAddressType)selectedItemIndex));
461                 pButtonType->Invalidate(false);
462
463                 __isContactModified = true;
464                 return;
465         }
466         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_IM_ADDRESS_FIELD_INDEX)
467         {
468                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
469                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
470
471                 TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(itemIndex));
472                 if (pItem == null)
473                 {
474                         return;
475                 }
476                 pItem->SetName(Integer::ToString(selectedItemIndex));
477
478                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
479                 if (pButtonType == null)
480                 {
481                         return;
482                 }
483
484                 pButtonType->SetText(__pPresentationModel->GetImAddressTypeString((DetailImAddressType)selectedItemIndex));
485                 pButtonType->Invalidate(false);
486
487                 __isContactModified = true;
488                 return;
489         }
490         else if (((actionId & TABLE_VIEW_INPUT_FIELD_ACTION_MASK) >> TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT) == TABLE_VIEW_URL_FIELD_INDEX)
491         {
492                 int itemIndex = (actionId & TABLE_VIEW_ITEM_INDEX_MASK);
493                 int selectedItemIndex = (actionId & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
494
495                 TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(itemIndex));
496                 if (pItem == null)
497                 {
498                         return;
499                 }
500                 pItem->SetName(Integer::ToString(selectedItemIndex));
501
502                 Button* pButtonType = static_cast<Button *>(pItem->GetControl(1));
503                 if (pButtonType == null)
504                 {
505                         return;
506                 }
507
508                 pButtonType->SetText(__pPresentationModel->GetUrlTypeString((DetailUrlType)selectedItemIndex));
509                 pButtonType->Invalidate(false);
510
511                 __isContactModified = true;
512                 return;
513         }
514
515         switch (actionId)
516         {
517         case IDA_ACTION_BAR_SAVE:
518                 {
519                         result r = E_SUCCESS;
520
521                         DateTime changedDate;
522                         DateTime currentDate;
523                         SystemTime::GetCurrentTime(currentDate);
524
525                         __pPresentationModel->GetBirthday(changedDate);
526
527                         if (changedDate.CompareTo(currentDate) > 0)
528                         {
529                                 int modalResult;
530                                 MessageBox invalidBirthYear;
531                                 invalidBirthYear.Construct(L"", ResourceManager::GetString(L"IDS_SAPPS_POP_INVALID_DATE_OF_BIRTH"), MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT_MS);
532                                 invalidBirthYear.ShowAndWait(modalResult);
533                                 __pPresentationModel->SetBirthday(currentDate);
534                                 __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
535                         }
536                         else
537                         {
538                                 r = SaveContactData();
539                                 if (r != E_SUCCESS)
540                                 {
541                                         return;
542                                 }
543                                 SetFocus();
544
545                                 __isSaved = true;
546                         }
547                 }
548                 break;
549         case IDA_BUTTON_THUMBNAIL_ADD:
550                 {
551                         if (__pCurrentFocusedItem != null)
552                         {
553                                 SetFocus();
554                         }
555                         LaunchAppControl(PROVIDER_ID_GALLERY, OPERATION_ID_PICK);
556                 }
557                 break;
558         case IDA_BUTTON_THUMBNAIL_DELETE:
559                 {
560                         __pPresentationModel->SetThumbnail(L"");
561                         __isContactModified = true;
562                         __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
563
564                         delete __pFileEventManager;
565                         __pFileEventManager = null;
566                 }
567                 break;
568         case IDA_BUTTON_CAMERA:
569                 {
570                         if (__pCurrentFocusedItem != null)
571                         {
572                                 SetFocus();
573                         }
574                         LaunchAppControl(PROVIDER_ID_CAMERA, OPERATION_ID_CREATE_CONTENT);
575                 }
576                 break;
577         case IDA_BUTTON_EXPANDABLE:
578                 {
579                         ChangeNameFieldStatus();
580
581                         if (__pCurrentFocusedItem == __pNameFieldItem)
582                         {
583                                 __pCurrentFocusedItem = null;
584                         }
585
586                         __pTableView->RefreshItem(TABLE_VIEW_NAME_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
587
588                         Rectangle clientBounds = GetClientAreaBounds();
589                         __pTableView->SetSize(clientBounds.width, clientBounds.height);
590
591                         if (__pCurrentFocusedItem != null)
592                         {
593                                 SetFocus();
594                         }
595                 }
596                 break;
597         case IDA_BUTTON_MORE_INFO:
598                 {
599                         if (__pCurrentFocusedItem != null)
600                         {
601                                 if (__isKeypadOpened)
602                                 {
603                                         __isMoreInformationContextMenuShowing = true;
604                                         __scrolledDistance = 0;
605                                 }
606                         }
607
608                         Control* pParentPanel = source.GetParent();
609                         if (pParentPanel == null)
610                         {
611                                 return;
612                         }
613
614                         Control* pParentTableViewItem = pParentPanel->GetParent();
615                         if (pParentTableViewItem == null)
616                         {
617                                 return;
618                         }
619
620                         Point contextMenuPos;
621
622                         contextMenuPos.x = pParentTableViewItem->GetWidth() / 2;
623                         contextMenuPos.y = GetClientAreaBounds().y + pParentTableViewItem->GetY() + source.GetY() - __scrolledDistance;
624
625                         ShowMoreInformationContextMenu(contextMenuPos);
626                 }
627                 break;
628         case IDA_BUTTON_BIRTHDAY_CLEAR:
629                 {
630                         DateTime currentDate;
631                         Tizen::System::SystemTime::GetCurrentTime(currentDate);
632                         __pPresentationModel->SetBirthday(currentDate);
633
634                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
635                         __isContactModified = true;
636                 }
637                 break;
638         case IDA_CONTEXT_MENU_ITEM_JOB_TITLE:
639                 {
640                         __isExpandable = false;
641                         __isJobTitleEnabled = true;
642
643                         ChangeNameFieldStatus();
644
645                         __pTableView->RefreshItem(TABLE_VIEW_NAME_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
646
647                         if (IsMoreInformationButtonVisible() == false)
648                         {
649                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
650                         }
651                         __pTableView->ScrollToItem(TABLE_VIEW_NAME_FIELD_INDEX, 0);
652                 }
653                 break;
654         case IDA_CONTEXT_MENU_ITEM_DEPARTMENT:
655                 {
656                         __isExpandable = false;
657                         __isDepartmentEnabled = true;
658
659                         ChangeNameFieldStatus();
660
661                         __pTableView->RefreshItem(TABLE_VIEW_NAME_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
662
663                         if (IsMoreInformationButtonVisible() == false)
664                         {
665                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
666                         }
667                         __pTableView->ScrollToItem(TABLE_VIEW_NAME_FIELD_INDEX, 0);
668                 }
669                 break;
670         case IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER:
671                 {
672                         SaveContactData(false);
673
674                         int index = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
675
676                         __pTableView->RefreshItem(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
677
678                         if (IsMoreInformationButtonVisible() == false)
679                         {
680                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
681                         }
682                         __pTableView->ScrollToItem(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, 0);
683                 }
684                 break;
685         case IDA_CONTEXT_MENU_ITEM_URL:
686                 {
687                         SaveContactData(false);
688
689                         int index = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
690
691                         __pTableView->RefreshItem(TABLE_VIEW_URL_FIELD_INDEX, index, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
692
693                         if (IsMoreInformationButtonVisible() == false)
694                         {
695                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
696                         }
697                         __pTableView->ScrollToItem(TABLE_VIEW_URL_FIELD_INDEX, 0);
698                 }
699                 break;
700         case IDA_CONTEXT_MENU_ITEM_BIRTHDAY:
701                 {
702                         DateTime currentDate;
703
704                         Tizen::System::SystemTime::GetCurrentTime(currentDate);
705                         __pPresentationModel->SetBirthday(currentDate);
706
707                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
708
709                         if (IsMoreInformationButtonVisible() == false)
710                         {
711                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
712                         }
713                         __pTableView->ScrollToItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0);
714                 }
715                 break;
716         case IDA_CONTEXT_MENU_ITEM_NOTE:
717                 {
718                         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
719
720                         if (IsMoreInformationButtonVisible() == false)
721                         {
722                                 __pTableView->RefreshItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
723                         }
724                         __pTableView->ScrollToItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0);
725                 }
726                 break;
727         case IDA_BUTTON_DEFAULT_PHONE_NUMBER:
728                 {
729                         Control* pParent = source.GetParent();
730                         Point contextMenuPos;
731
732                         contextMenuPos.x = pParent->GetWidth() / 2;
733                         contextMenuPos.y = GetClientAreaBounds().y + pParent->GetY() + source.GetY() + (source.GetHeight() / 2) - __scrolledDistance;
734
735                         if (__pCurrentFocusedItem != null)
736                         {
737                                 SetFocus();
738                         }
739
740                         SaveContactData(false);
741                         ShowDefaultPhoneNumberContextMenu(contextMenuPos);
742                 }
743                 break;
744         case IDA_POPUP_SAVE_CONTACT_OK:
745                 {
746                         HideSaveContactPopup();
747
748                         DateTime changedDate;
749                         DateTime currentDate;
750                         SystemTime::GetCurrentTime(currentDate);
751
752                         __pPresentationModel->GetBirthday(changedDate);
753
754                         if (changedDate.CompareTo(currentDate) > 0)
755                         {
756                                 int modalResult;
757                                 MessageBox invalidBirthYear;
758                                 invalidBirthYear.Construct(L"", ResourceManager::GetString(L"IDS_SAPPS_POP_INVALID_DATE_OF_BIRTH"), MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT_MS);
759                                 invalidBirthYear.ShowAndWait(modalResult);
760                                 __pPresentationModel->SetBirthday(currentDate);
761                                 __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
762                         }
763                         else
764                         {
765                                 result r = SaveContactData();
766                                 if (r != E_SUCCESS)
767                                 {
768                                         return;
769                                 }
770                                 SetFocus();
771                                 __isSaved = true;
772                         }
773                 }
774                 break;
775         case IDA_POPUP_SAVE_CONTACT_CANCEL:
776                 {
777                         HideSaveContactPopup();
778
779                         if (__isAppControl == true)
780                         {
781                                 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
782                                 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
783
784                                 result r = pAppManager->SendAppControlResult(pContactsApp->GetRequestId(), APP_CTRL_RESULT_CANCELED, null);
785                                 AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
786
787                                 UiApp::GetInstance()->Terminate();
788                         }
789                         else
790                         {
791
792                                 SceneManager* pSceneManager = SceneManager::GetInstance();
793
794                                 result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
795                                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
796                         }
797                 }
798                 break;
799         case IDA_BUTTON_RINGTONE_CLEAR:
800                 {
801                         __pPresentationModel->SetValue(DETAIL_PROPERTY_RINGTONE, L"", 0);
802                         __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
803                 }
804                 break;
805
806         case IDA_BUTTON_TYPE:
807                 {
808                         Control* pParent = source.GetParent();
809                         Point position = pParent->GetPosition();
810                         Point itemPosition(position.x + source.GetX(), GetClientAreaBounds().y + position.y + source.GetY() + (source.GetHeight() / 2) - __scrolledDistance);
811                         String typeString = pParent->GetName();
812                         String itemIndexTag = source.GetName();
813                         int type;
814                         int itemIndex;
815
816                         Integer::Parse(itemIndexTag, itemIndex);
817                         Integer::Parse(typeString, type);
818                         ShowTypeContextMenu(type, itemPosition, itemIndex);
819                 }
820                 break;
821         default:
822                 break;
823         }
824 }
825
826 void
827 ContactEditorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId,
828                                                                                          Tizen::Base::Collection::IList* pArgs)
829 {
830         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
831         TryReturnVoid(pContactsApp != null, "Unable to cast UiApp to ContactsApp");
832
833         pContactsApp->AddContactsAppChangeEventListener(*this);
834
835         Header* pHeader = GetHeader();
836         Footer* pFooter = GetFooter();
837
838         if (previousSceneId.Equals(IDSCN_GROUP_SELECTOR, true) || previousSceneId.Equals(IDSCN_GROUP_EDITOR, true))
839         {
840                 if (pArgs != null)
841                 {
842                         Integer* pCategoryId = null;
843                         int prevCount = 0;
844                         int curCount  = 0;
845
846                         IList* pCategoryList = __pPresentationModel->GetAssignedCategoryIdListN();
847                         prevCount = pCategoryList->GetCount();
848                         delete pCategoryList;
849
850                         __pPresentationModel->RemoveContactFromAllCategories();
851
852                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
853                         while (pEnum->MoveNext() == E_SUCCESS)
854                         {
855                                 pCategoryId = static_cast<Integer*>(pEnum->GetCurrent());
856                                 if (pCategoryId != null)
857                                 {
858                                         __pPresentationModel->AddContactToCategory(pCategoryId->ToInt());
859                                         __isContactModified = true;
860                                         curCount++;
861                                 }
862                         }
863
864                         if(prevCount > 0 && curCount == 0)
865                         {
866                                 __isContactModified = true;
867                         }
868
869                         delete pEnum;
870
871                         pArgs->RemoveAll(true);
872                         delete pArgs;
873                 }
874
875                 __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
876
877                 return;
878         }
879
880         if (pContactsApp->GetOperationId() == OPERATION_ID_ADD)
881         {
882                 __isAppControl = true;
883                 __pPresentationModel->PrepareNewContact();
884
885                 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
886                 pFooter->SetItemEnabled(0, false);
887         }
888         else if (pContactsApp->GetOperationId() == OPERATION_ID_EDIT)
889         {
890                 __isAppControl = true;
891
892                 if (pArgs != null)
893                 {
894                         String* pArgString = null;
895                         String type;
896                         String content;
897
898                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
899                         while (pEnum->MoveNext() == E_SUCCESS)
900                         {
901                                 pArgString = static_cast<String*>(pEnum->GetCurrent());
902                                 if (pArgString != null)
903                                 {
904                                         ParseAppControlArgument(*pArgString, type, content);
905
906                                         if (type.Equals(RETURN_TYPE_ITEM_ID, false))
907                                         {
908                                                 RecordId contactId;
909                                                 Integer::Parse(content, contactId);
910                                                 result r = __pPresentationModel->SetContactId(contactId, true);
911
912                                                 if (IsFailed(r))
913                                                 {
914                                                         AppLogDebug("Invalid contactId has been input : %d", contactId);
915                                                         UiApp::GetInstance()->Terminate();
916                                                 }
917
918                                                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE).IsEmpty() == false)
919                                                 {
920                                                         __isJobTitleEnabled = true;
921                                                 }
922                                                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT).IsEmpty() == false)
923                                                 {
924                                                         __isDepartmentEnabled = true;
925                                                 }
926                                                 break;
927                                         }
928                                 }
929                         }
930                         delete pEnum;
931
932                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_SK_EDIT"));
933                 }
934         }
935         else
936         {
937                 if (pArgs != null)
938                 {
939                         Integer* pContactId = null;
940
941                         pContactId = static_cast<Integer*>(pArgs->GetAt(0));
942                         if (pContactId != null)
943                         {
944                                 if (pContactId->ToInt() != INVALID_RECORD_ID)
945                                 {
946                                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_SK_EDIT"));
947                                         __pPresentationModel->SetContactId(pContactId->ToInt(), true);
948                                 }
949                                 else
950                                 {
951                                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
952
953                                         String* pVcfPath = static_cast<String*>(pArgs->GetAt(1));
954                                         if (pVcfPath != null)
955                                         {
956                                                 __pPresentationModel->SetVcfPath(*pVcfPath, true);
957                                         }
958                                 }
959                         }
960
961                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE).IsEmpty() == false)
962                         {
963                                 __isJobTitleEnabled = true;
964                         }
965                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT).IsEmpty() == false)
966                         {
967                                 __isDepartmentEnabled = true;
968                         }
969                 }
970                 else
971                 {
972                         pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
973                         pFooter->SetItemEnabled(0, false);
974                         __pPresentationModel->PrepareNewContact();
975                 }
976         }
977
978         if (__isAppControl == true)
979         {
980                 if (pArgs != null)
981                 {
982                         String* pArgString = null;
983                         String type;
984                         String content;
985
986                         IEnumerator* pEnum = pArgs->GetEnumeratorN();
987                         while (pEnum->MoveNext() == E_SUCCESS)
988                         {
989                                 pArgString = static_cast<String*>(pEnum->GetCurrent());
990                                 if (pArgString != null)
991                                 {
992                                         result r = E_SUCCESS;
993                                         ParseAppControlArgument(*pArgString, type, content);
994
995                                         if (type.Equals(INPUT_TYPE_PHONE, false))
996                                         {
997                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_PHONE_NUMBER, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER));
998                                         }
999                                         else if (type.Equals(INPUT_TYPE_EMAIL, false))
1000                                         {
1001                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_EMAIL, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL));
1002                                         }
1003                                         else if (type.Equals(INPUT_TYPE_URL, false))
1004                                         {
1005                                                 r = __pPresentationModel->SetValue(DETAIL_PROPERTY_URL, content, __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL));
1006                                         }
1007
1008                                         if (r == E_SUCCESS)
1009                                         {
1010                                                 pFooter->SetItemEnabled(0, true);
1011                                         }
1012                                 }
1013                         }
1014                         delete pEnum;
1015                 }
1016         }
1017
1018         if (pArgs != null)
1019         {
1020                 pArgs->RemoveAll(true);
1021                 delete pArgs;
1022         }
1023 }
1024
1025 void
1026 ContactEditorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
1027 {
1028         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
1029
1030         pContactsApp->RemoveContactsAppChangeEventListener(*this);
1031 }
1032
1033 void
1034 ContactEditorForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
1035 {
1036 }
1037
1038 void
1039 ContactEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
1040 {
1041         Rectangle clientBounds = GetClientAreaBounds();
1042
1043         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1044         __isKeypadOpened = true;
1045 }
1046
1047 void
1048 ContactEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
1049 {
1050         if (__pCurrentFocusedItem != null)
1051         {
1052                 Rectangle clientBounds = GetClientAreaBounds();
1053
1054                 AppLogDebug("Contacts::OnKeypadclosed bounds are width:(%d), height:(%d)", clientBounds.width, clientBounds.height);
1055                 __pTableView->SetSize(clientBounds.width, clientBounds.height);
1056         }
1057         else if (__isMoreInformationContextMenuShowing)
1058         {
1059                 Point anchorPosition = __pMoreInformationContextMenu->GetAnchorPosition();
1060                 __pTableView->ScrollToItem(TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX, 0, TABLE_VIEW_SCROLL_ITEM_ALIGNMENT_BOTTOM);
1061                 anchorPosition.y -= __scrolledDistance;
1062                 __pMoreInformationContextMenu->SetAnchorPosition(anchorPosition);
1063                 __pMoreInformationContextMenu->Show();
1064
1065                 __isMoreInformationContextMenuShowing = false;
1066         }
1067         __isKeypadOpened = false;
1068 }
1069
1070 void
1071 ContactEditorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1072 {
1073 }
1074
1075 void
1076 ContactEditorForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
1077 {
1078         Rectangle clientBounds = GetClientAreaBounds();
1079         int diff = clientBounds.height - __pTableView->GetHeight();
1080
1081         if (__pTypeContextMenu != null)
1082         {
1083                 int yPos = __pTypeContextMenu->GetAnchorPosition().y;
1084                 __pTypeContextMenu->SetAnchorPosition(Point(__pTypeContextMenu->GetAnchorPosition().x, yPos + diff));
1085                 __pTypeContextMenu->Show();
1086         }
1087         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1088 }
1089
1090 void
1091 ContactEditorForm::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1092 {
1093         SceneManager* pSceneManager = SceneManager::GetInstance();
1094
1095         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED && groupIndex == TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX)
1096         {
1097                 if (__pCurrentFocusedItem != null)
1098                 {
1099                         SetFocus();
1100                 }
1101
1102                 if (itemIndex == 0)
1103                 {
1104                         if (__pPresentationModel->GetCategoryCount() > 0)
1105                         {
1106                                 IList* pCategoryList = __pPresentationModel->GetAssignedCategoryIdListN();
1107
1108                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_SELECTOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pCategoryList);
1109                         }
1110                         else
1111                         {
1112                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
1113                         }
1114
1115                         return;
1116                 }
1117                 else if (itemIndex == 2)
1118                 {
1119                         LaunchAppControl(PROVIDER_ID_FILEMANAGER, OPERATION_ID_PICK);
1120                 }
1121         }
1122 }
1123
1124 void
1125 ContactEditorForm::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem *pContextItem, bool activated)
1126 {
1127 }
1128
1129 void
1130 ContactEditorForm::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
1131 {
1132 }
1133
1134 int
1135 ContactEditorForm::GetGroupCount(void)
1136 {
1137         return GROUP_ITEM_COUNT;
1138 }
1139
1140 int
1141 ContactEditorForm::GetItemCount(int groupIndex)
1142 {
1143         int itemCount = 0;
1144
1145         switch (groupIndex)
1146         {
1147         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1148                 {
1149                         itemCount = 1;
1150                 }
1151                 break;
1152         case TABLE_VIEW_NAME_FIELD_INDEX:
1153                 {
1154                         itemCount = NAME_FIELD_ITEM_COUNT;
1155                 }
1156                 break;
1157         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
1158                 {
1159                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) + 1;
1160
1161                         if (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1)
1162                         {
1163                                 __isDefaultPhoneNumberButtonEnabled = true;
1164                                 itemCount++;
1165                         }
1166                         else
1167                         {
1168                                 __isDefaultPhoneNumberButtonEnabled = false;
1169                         }
1170                 }
1171                 break;
1172         case TABLE_VIEW_EMAIL_FIELD_INDEX:
1173                 {
1174                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL) + 1;
1175                 }
1176                 break;
1177         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
1178                 {
1179                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS) + 1;
1180                 }
1181                 break;
1182         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
1183                 {
1184                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
1185
1186                         if ((itemCount == 0 && __pImAddressFieldItem->GetCount() > 0) || itemCount > 0)
1187                         {
1188                                 itemCount++;
1189                         }
1190                 }
1191                 break;
1192         case TABLE_VIEW_URL_FIELD_INDEX:
1193                 {
1194                         itemCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
1195
1196                         if ((itemCount == 0 && __pUrlFieldItem->GetCount() > 0) || itemCount > 0)
1197                         {
1198                                 itemCount++;
1199                         }
1200                 }
1201                 break;
1202         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1203                 {
1204                         DateTime birthday;
1205                         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
1206                         {
1207                                 itemCount = 0;
1208                         }
1209                         else
1210                         {
1211                                 itemCount = 1;
1212                         }
1213                 }
1214                 break;
1215         case TABLE_VIEW_NOTE_FIELD_INDEX:
1216                 {
1217                         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_NOTE).IsEmpty() == false || __pNoteFieldItem != null )
1218                         {
1219                                 itemCount = 1;
1220                         }
1221                         else
1222                         {
1223                                 itemCount = 0;
1224                         }
1225                 }
1226                 break;
1227         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1228                 {
1229                         itemCount = 3;
1230                 }
1231                 break;
1232         case TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX:
1233                 {
1234                         if (IsMoreInformationButtonVisible())
1235                         {
1236                                 itemCount = 1;
1237                         }
1238                         else
1239                         {
1240                                 itemCount = 0;
1241                         }
1242                 }
1243                 break;
1244         default:
1245                 break;
1246         }
1247
1248         return itemCount;
1249 }
1250
1251 int
1252 ContactEditorForm::GetDefaultGroupItemHeight(void)
1253 {
1254         return H_EMPTY_SPACE;
1255 }
1256
1257 int
1258 ContactEditorForm::GetDefaultItemHeight(void)
1259 {
1260         return H_ITEM;
1261 }
1262
1263 TableViewGroupItem*
1264 ContactEditorForm::CreateGroupItem(int groupIndex, int itemWidth)
1265 {
1266         int groupItemHeight = H_EMPTY_SPACE;
1267
1268         if (groupIndex == TABLE_VIEW_THUMBNAIL_FIELD_INDEX)
1269         {
1270                 groupItemHeight = H_THUMBNAIL_GROUP_ITEM_HEIGHT;
1271         }
1272         else if (groupIndex == TABLE_VIEW_NAME_FIELD_INDEX)
1273         {
1274                 groupItemHeight = H_NAMEFIELD_GROUP_ITEM_HEIGHT;
1275         }
1276         else if (groupIndex == TABLE_VIEW_BIRTHDAY_FIELD_INDEX)
1277         {
1278                 groupItemHeight = Y_EDIT_FIELD_GAP;
1279         }
1280         else if (groupIndex == TABLE_VIEW_NOTE_FIELD_INDEX)
1281         {
1282                 groupItemHeight = H_EDIT_FIELD_GAP;
1283         }
1284         else if ((groupIndex > TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX && groupIndex < TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX) || groupIndex == TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX)
1285         {
1286                 groupItemHeight = 0;
1287         }
1288
1289         TableViewGroupItem* pGroupItem = new (std::nothrow) TableViewGroupItem();
1290         pGroupItem->Construct(Dimension(itemWidth, groupItemHeight));
1291         pGroupItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
1292         pGroupItem->SetEnabled(false);
1293
1294         Panel* pPanel = new (std::nothrow) Panel();
1295         pPanel->Construct(Rectangle(0, -(H_DIVIDER), itemWidth, groupItemHeight + H_DIVIDER));
1296         pPanel->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG));
1297
1298         pGroupItem->AddControl(pPanel);
1299
1300         return pGroupItem;
1301 }
1302
1303 bool
1304 ContactEditorForm::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
1305 {
1306         delete pItem;
1307         pItem = null;
1308
1309         return true;
1310 }
1311
1312 TableViewItem*
1313 ContactEditorForm::CreateItem(int groupIndex, int itemIndex, int itemWidth)
1314 {
1315         TableViewItem* pItem = null;
1316
1317         switch (groupIndex)
1318         {
1319         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1320                 {
1321                         pItem = GetThumbnailField(itemWidth);
1322                 }
1323                 break;
1324         case TABLE_VIEW_NAME_FIELD_INDEX:
1325                 {
1326                         pItem = GetNameFields(itemWidth);
1327                 }
1328                 break;
1329         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
1330                 {
1331                         if ((itemIndex == __pTableView->GetItemCountAt(groupIndex) - 1) && __isDefaultPhoneNumberButtonEnabled == true)
1332                         {
1333                                 pItem = GetDefaultPhoneNumberItem(itemWidth);
1334                                 break;
1335                         }
1336
1337                         pItem = GetPhoneNumberFields(itemIndex, itemWidth);
1338                 }
1339                 break;
1340         case TABLE_VIEW_EMAIL_FIELD_INDEX:
1341                 {
1342                         pItem = GetEmailFields(itemIndex, itemWidth);
1343                 }
1344                 break;
1345         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
1346                 {
1347                         pItem = GetAddressFields(itemIndex, itemWidth);
1348                 }
1349                 break;
1350         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
1351                 {
1352                         pItem = GetImAddressFields(itemIndex, itemWidth);
1353                 }
1354                 break;
1355         case TABLE_VIEW_URL_FIELD_INDEX:
1356                 {
1357                         pItem = GetUrlFields(itemIndex, itemWidth);
1358                 }
1359                 break;
1360         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1361                 {
1362                         pItem = GetBirthdayField(itemWidth);
1363                 }
1364                 break;
1365         case TABLE_VIEW_NOTE_FIELD_INDEX:
1366                 {
1367                         pItem = GetNoteField(itemWidth);
1368                 }
1369                 break;
1370         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1371                 {
1372                         switch (itemIndex)
1373                         {
1374                         case 0:
1375                                 pItem = GetGroupsField(itemWidth);
1376                                 break;
1377                         case 1:
1378                                 {
1379                                         pItem = new (std::nothrow) TableViewItem();
1380                                         pItem->Construct(Dimension(itemWidth, H_DIVIDER * 2));
1381                                         pItem->SetEnabled(false);
1382                                 }
1383                                 break;
1384                         case 2:
1385                                 pItem = GetRingtoneField(itemWidth);
1386                                 break;
1387                         default:
1388                                 break;
1389                         }
1390                 }
1391                 break;
1392         case TABLE_VIEW_MORE_INFORMATION_FIELD_INDEX:
1393                 {
1394                         if (IsMoreInformationButtonVisible())
1395                         {
1396                                 pItem = GetMoreInformationField(itemWidth);
1397                         }
1398                         else
1399                         {
1400                                 pItem = null;
1401                         }
1402                 }
1403                 break;
1404         default:
1405                 break;
1406         }
1407
1408         return pItem;
1409 }
1410
1411 bool
1412 ContactEditorForm::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
1413 {
1414         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
1415         {
1416                 if ((itemIndex == __pPhoneNumberFieldItem->GetCount()) && __isDefaultPhoneNumberButtonEnabled == true)
1417                 {
1418                         delete pItem;
1419                         pItem = null;
1420
1421                         return true;
1422                 }
1423         }
1424
1425         if ((groupIndex > TABLE_VIEW_NAME_FIELD_INDEX && groupIndex < TABLE_VIEW_BIRTHDAY_FIELD_INDEX) || groupIndex == TABLE_VIEW_NOTE_FIELD_INDEX)
1426         {
1427                 if (__delGroupIndex == groupIndex && __delItemIndex == itemIndex)
1428                 {
1429                         __delGroupIndex = -1;
1430                         __delItemIndex  = -1;
1431                 }
1432                 else
1433                 {
1434                         return true;
1435                 }
1436         }
1437         else if (groupIndex == TABLE_VIEW_NAME_FIELD_INDEX)
1438         {
1439                 SaveNameFields();
1440                 __pNameFieldItem = null;
1441         }
1442
1443         if (__pCurrentFocusedItem == pItem && __isKeypadOpened)
1444         {
1445                 __isKeypadOpened = false;
1446         }
1447
1448         delete pItem;
1449         pItem = null;
1450
1451         return true;
1452 }
1453
1454 void
1455 ContactEditorForm::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem)
1456 {
1457 }
1458
1459 void
1460 ContactEditorForm::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
1461 {
1462         if (pItem == null)
1463         {
1464                 return;
1465         }
1466
1467         switch (groupIndex)
1468         {
1469         case TABLE_VIEW_THUMBNAIL_FIELD_INDEX:
1470                 {
1471                         SetThumbnailControls(*pItem, true);
1472                         pItem->Invalidate(true);
1473                 }
1474                 break;
1475         case TABLE_VIEW_NAME_FIELD_INDEX:
1476                 {
1477                         if (__pCurrentFocusedItem == pItem && __isKeypadOpened)
1478                         {
1479                                 __isKeypadOpened = false;
1480                         }
1481                         pItem->RemoveAllControls();
1482                         SetNameFields(*pItem);
1483                         Invalidate(true);
1484                 }
1485             break;
1486         case TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX:
1487                 {
1488                         String valueString;
1489                         Label* pLabel = static_cast<Label *>(pItem->GetControl(1));
1490
1491                         if (pLabel == null)
1492                         {
1493                                 return;
1494                         }
1495
1496                         if (itemIndex == 0)
1497                         {
1498                                 valueString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_GROUP);
1499                                 if (valueString.IsEmpty() == true)
1500                                 {
1501                                         valueString = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
1502                                 }
1503                         }
1504                         else if (itemIndex == 2)
1505                         {
1506                                 String ringtoneName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
1507                                 int index = 0;
1508
1509                                 ringtoneName.LastIndexOf(L"/", ringtoneName.GetLength() - 1, index);
1510
1511                                 if (index != 0)
1512                                 {
1513                                         ringtoneName.SubString(index + 1, valueString);
1514                                 }
1515                         }
1516
1517                         pLabel->SetText(valueString);
1518                         pLabel->Invalidate(false);
1519                 }
1520                 break;
1521         case TABLE_VIEW_BIRTHDAY_FIELD_INDEX:
1522                 {
1523                         int min;
1524                         int max;
1525                         DateTime birthdayDate;
1526                         EditDate* pBirthday = static_cast<EditDate *>(pItem->GetControl(1));
1527
1528                         if (pBirthday == null)
1529                         {
1530                                 return;
1531                         }
1532
1533                         __pPresentationModel->GetBirthday(birthdayDate);
1534
1535                         pBirthday->GetYearRange(min, max);
1536                         max = birthdayDate.GetYear();
1537                         pBirthday->SetYearRange(min, max);
1538                         pBirthday->SetDate(birthdayDate);
1539                         pBirthday->Invalidate(false);
1540                 }
1541                 break;
1542         case TABLE_VIEW_NOTE_FIELD_INDEX:
1543                 {
1544                         Control* pNoteField = pItem->GetControl(1);
1545                         Control* pNoteLabel = pItem->GetControl(0);
1546                         if (pNoteField == null)
1547                         {
1548                                 return;
1549                         }
1550
1551                         pItem->SetSize(pItem->GetWidth(), pNoteLabel->GetHeight() + pNoteField->GetHeight());
1552                 }
1553                 break;
1554         default:
1555                 break;
1556         }
1557 }
1558
1559 Tizen::Ui::Controls::TableViewItem*
1560 ContactEditorForm::GetThumbnailField(int itemWidth)
1561 {
1562         TableViewItem* pThumbnailItem = new (std::nothrow) TableViewItem();
1563         pThumbnailItem->Construct(Dimension(itemWidth, W_THUMBNAIL));
1564         pThumbnailItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1565
1566         SetThumbnailControls(*pThumbnailItem);
1567
1568         return pThumbnailItem;
1569 }
1570
1571 Tizen::Ui::Controls::TableViewItem*
1572 ContactEditorForm::GetNameFields(int itemWidth)
1573 {
1574         __pNameFieldItem = new (std::nothrow) TableViewItem();
1575         __pNameFieldItem->Construct(Dimension(itemWidth, H_ITEM));
1576         __pNameFieldItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1577
1578         SetNameFields(*__pNameFieldItem);
1579
1580         return __pNameFieldItem;
1581 }
1582
1583 void
1584 ContactEditorForm::SetNameFields(Tizen::Ui::Controls::TableViewItem& item)
1585 {
1586         int itemWidth = item.GetWidth();
1587         int itemHeight = H_ITEM;
1588
1589         if (__isExpandable == true)
1590         {
1591                 itemHeight = H_EXPANDED_NAME_FIELDS;
1592
1593                 if (__isJobTitleEnabled == true)
1594                 {
1595                         itemHeight += H_ITEM;
1596                 }
1597
1598                 if (__isDepartmentEnabled)
1599                 {
1600                         itemHeight += H_ITEM;
1601                 }
1602         }
1603
1604         item.SetSize(itemWidth, itemHeight);
1605
1606         Rectangle itemBounds(W_ITEM_GAP, Y_EDIT_FIELD_GAP, itemWidth - (W_ITEM_GAP * 3) - H_BUTTON, H_ITEM - H_EDIT_FIELD_GAP);
1607
1608         if (__isExpandable == true)
1609         {
1610                 EditField* pFirstName = new (std::nothrow) EditField();
1611                 pFirstName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, __pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME).GetLength() + EDIT_FIELD_EXTENDED_LENGTH);
1612                 pFirstName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"));
1613                 pFirstName->AddFocusEventListener(*this);
1614                 pFirstName->AddKeypadEventListener(*this);
1615                 pFirstName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"));
1616                 pFirstName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME));
1617                 pFirstName->AddTextEventListener(*this);
1618
1619                 item.AddControl(pFirstName);
1620                 item.SetIndividualSelectionEnabled(pFirstName, true);
1621
1622                 itemBounds.y += H_ITEM;
1623                 EditField* pMiddleName = new (std::nothrow) EditField();
1624                 pMiddleName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1625                 pMiddleName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"));
1626                 pMiddleName->AddFocusEventListener(*this);
1627                 pMiddleName->AddKeypadEventListener(*this);
1628                 pMiddleName->AddTextEventListener(*this);
1629                 pMiddleName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"));
1630                 pMiddleName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_MIDDLE_NAME));
1631
1632                 item.AddControl(pMiddleName);
1633                 item.SetIndividualSelectionEnabled(pMiddleName, true);
1634
1635                 itemBounds.y += H_ITEM;
1636                 EditField* pLastName = new (std::nothrow) EditField();
1637                 pLastName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, __pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME).GetLength() + EDIT_FIELD_EXTENDED_LENGTH);
1638                 pLastName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"));
1639                 pLastName->AddFocusEventListener(*this);
1640                 pLastName->AddKeypadEventListener(*this);
1641                 pLastName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"));
1642                 pLastName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME));
1643                 pLastName->AddTextEventListener(*this);
1644
1645                 item.AddControl(pLastName);
1646                 item.SetIndividualSelectionEnabled(pLastName, true);
1647
1648                 itemBounds.y += H_ITEM;
1649                 EditField* pSuffix = new (std::nothrow) EditField();
1650                 pSuffix->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1651                 pSuffix->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"));
1652                 pSuffix->AddFocusEventListener(*this);
1653                 pSuffix->AddKeypadEventListener(*this);
1654                 pSuffix->AddTextEventListener(*this);
1655                 pSuffix->SetName(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"));
1656                 pSuffix->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NAME_SUFFIX));
1657
1658                 item.AddControl(pSuffix);
1659                 item.SetIndividualSelectionEnabled(pSuffix, true);
1660
1661                 itemBounds.y += H_ITEM;
1662                 EditField* pNickName = new (std::nothrow) EditField();
1663                 pNickName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1664                 pNickName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"));
1665                 pNickName->AddFocusEventListener(*this);
1666                 pNickName->AddKeypadEventListener(*this);
1667                 pNickName->AddTextEventListener(*this);
1668                 pNickName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"));
1669                 pNickName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NICK_NAME));
1670
1671                 item.AddControl(pNickName);
1672                 item.SetIndividualSelectionEnabled(pNickName, true);
1673
1674                 itemBounds.y += H_ITEM;
1675                 if (__isJobTitleEnabled == true)
1676                 {
1677                         EditField* pJobTitle = new (std::nothrow) EditField();
1678                         pJobTitle->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1679                         pJobTitle->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"));
1680                         pJobTitle->AddFocusEventListener(*this);
1681                         pJobTitle->AddKeypadEventListener(*this);
1682                         pJobTitle->AddTextEventListener(*this);
1683                         pJobTitle->SetName(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"));
1684                         pJobTitle->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_JOB_TITLE));
1685
1686                         item.AddControl(pJobTitle);
1687                         item.SetIndividualSelectionEnabled(pJobTitle, true);
1688
1689                         itemBounds.y += H_ITEM;
1690                 }
1691
1692                 if (__isDepartmentEnabled == true)
1693                 {
1694                         EditField* pDepartment = new (std::nothrow) EditField();
1695                         pDepartment->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1696                         pDepartment->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"));
1697                         pDepartment->AddFocusEventListener(*this);
1698                         pDepartment->AddKeypadEventListener(*this);
1699                         pDepartment->AddTextEventListener(*this);
1700                         pDepartment->SetName(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"));
1701                         pDepartment->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_DEPARTMENT));
1702
1703                         item.AddControl(pDepartment);
1704                         item.SetIndividualSelectionEnabled(pDepartment, true);
1705
1706                         itemBounds.y += H_ITEM;
1707                 }
1708
1709                 EditField* pCompanyName = new (std::nothrow) EditField();
1710                 pCompanyName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY);
1711                 pCompanyName->SetGuideText(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"));
1712                 pCompanyName->AddFocusEventListener(*this);
1713                 pCompanyName->AddKeypadEventListener(*this);
1714                 pCompanyName->SetName(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"));
1715                 pCompanyName->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_COMPANY));
1716
1717                 item.AddControl(pCompanyName);
1718                 item.SetIndividualSelectionEnabled(pCompanyName, true);
1719         }
1720         else
1721         {
1722                 String firstName(__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME));
1723                 String lastName(__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME));
1724
1725                 EditField* pName = new (std::nothrow) EditField();
1726                 pName->Construct(itemBounds, EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, false, firstName.GetLength() + lastName.GetLength() + EDIT_FIELD_EXTENDED_LENGTH);
1727                 pName->SetGuideText(ResourceManager::GetString(L"IDS_COM_BODY_DETAILS_NAME"));
1728                 pName->AddFocusEventListener(*this);
1729                 pName->AddKeypadEventListener(*this);
1730                 pName->SetName(Integer::ToString(IDA_INPUT_FIELD_DISPLAY_NAME));
1731                 pName->AddTextEventListener(*this);
1732
1733                 if (firstName.IsEmpty() == false)
1734                 {
1735                         pName->SetText(firstName);
1736                 }
1737
1738                 if (lastName.IsEmpty() == false)
1739                 {
1740                         pName->AppendText(CHARACTER_SPACE + lastName);
1741                 }
1742
1743                 item.AddControl(pName);
1744                 item.SetIndividualSelectionEnabled(pName, true);
1745         }
1746
1747         Button* pButtonExpand = new (std::nothrow) Button();
1748         pButtonExpand->Construct(Rectangle(itemWidth - (H_BUTTON + W_ITEM_GAP), (H_ITEM - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
1749         pButtonExpand->SetActionId(IDA_BUTTON_EXPANDABLE);
1750         pButtonExpand->AddActionEventListener(*this);
1751
1752         Bitmap* pBitmap = null;
1753         Bitmap* pBitmapPressed = null;
1754
1755         if (__isExpandable == true)
1756         {
1757                 pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_OPENED);
1758                 pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_OPENED_PRESSED);
1759         }
1760         else
1761         {
1762                 pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_CLOSED);
1763                 pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_CLOSED_PRESSED);
1764         }
1765
1766         if (pBitmap != null)
1767         {
1768                 pButtonExpand->SetNormalBitmap(Point(0, 0), *pBitmap);
1769         }
1770
1771         if (pBitmapPressed != null)
1772         {
1773                 pButtonExpand->SetPressedBitmap(Point(0, 0), *pBitmapPressed);
1774         }
1775
1776         delete pBitmap;
1777         delete pBitmapPressed;
1778
1779         pBitmap = ResourceManager::GetBitmapN(IDB_EXPAND_BUTTON_NORMAL);
1780         pBitmapPressed = ResourceManager::GetBitmapN(IDB_EXPAND_BUTTON_PRESSED);
1781
1782         if (pBitmap != null)
1783         {
1784                 pButtonExpand->SetNormalBackgroundBitmap(*pBitmap);
1785                 delete pBitmap;
1786         }
1787         if (pBitmapPressed != null)
1788         {
1789                 pButtonExpand->SetPressedBackgroundBitmap(*pBitmapPressed);
1790                 delete pBitmapPressed;
1791         }
1792
1793         item.AddControl(pButtonExpand);
1794         item.SetIndividualSelectionEnabled(pButtonExpand, true);
1795 }
1796
1797 Tizen::Ui::Controls::TableViewItem*
1798 ContactEditorForm::GetInputFieldN(int groupIndex, int itemIndex, int itemWidth, Tizen::Ui::Controls::EditFieldStyle style, const Tizen::Base::String& titleText, const Tizen::Base::String& guideText, const Tizen::Base::String& text, bool isDeleteButton)
1799 {
1800         TableViewItem* pTableViewItem = new (std::nothrow) TableViewItem();
1801         pTableViewItem->Construct(Dimension(itemWidth, H_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
1802         pTableViewItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
1803
1804         EditField* pInputField = new (std::nothrow) EditField();
1805         pInputField->Construct(Rectangle(W_ITEM_GAP, Y_EDIT_FIELD_GAP, itemWidth - (W_ITEM_GAP * 4) - H_BUTTON - W_TYPE_BUTTON, H_ITEM - H_EDIT_FIELD_GAP), style, INPUT_STYLE_OVERLAY);
1806         pInputField->SetGuideText(guideText);
1807         pInputField->SetText(text);
1808         pInputField->AddKeypadEventListener(*this);
1809         pInputField->AddFocusEventListener(*this);
1810         pInputField->AddTextEventListener(*this);
1811         pInputField->SetEnabled(true);
1812
1813         int parsedItemIndex = 0;
1814         parsedItemIndex |= (groupIndex << TABLE_VIEW_INPUT_FIELD_ACTION_SHIFT);
1815         parsedItemIndex |= (groupIndex << TABLE_VIEW_GROUP_INDEX_SHIFT);
1816         parsedItemIndex |= itemIndex;
1817
1818         pInputField->SetName(Integer::ToString(parsedItemIndex));
1819         pTableViewItem->AddControl(pInputField);
1820
1821         Button *pButtonType = new (std::nothrow) Button();
1822         pButtonType->Construct(Rectangle(pInputField->GetX() + pInputField->GetWidth() + W_ITEM_GAP, (H_ITEM - H_BUTTON) / 2, W_TYPE_BUTTON, H_BUTTON));
1823         pButtonType->SetText(titleText);
1824         pButtonType->SetActionId(IDA_BUTTON_TYPE);
1825         pButtonType->AddActionEventListener(*this);
1826         pButtonType->AddTouchEventListener(*this);
1827         pButtonType->SetName(Integer::ToString(parsedItemIndex));
1828
1829         Bitmap* pDropBoxIcon = ResourceManager::GetBitmapN(IDB_BUTTON_DROPBOX);
1830
1831         if (pDropBoxIcon != null)
1832         {
1833                 pButtonType->SetNormalBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1834                 pButtonType->SetPressedBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1835                 pButtonType->SetDisabledBitmap(Point(W_TYPE_BUTTON - W_DROPBOX_ICON, H_BUTTON - H_DROPBOX_ICON), *pDropBoxIcon);
1836                 delete pDropBoxIcon;
1837         }
1838         pTableViewItem->AddControl(pButtonType);
1839
1840         Button *pButtonDelete = new (std::nothrow) Button();
1841         pButtonDelete->Construct(Rectangle(itemWidth - H_BUTTON - W_ITEM_GAP, (H_ITEM - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
1842         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS);
1843         Bitmap* pBitmapPressed = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS_PRESSED);
1844
1845         if (pBitmap != null)
1846         {
1847                 pButtonDelete->SetNormalBitmap(Point(0, 0), *pBitmap);
1848                 delete pBitmap;
1849         }
1850         if (pBitmapPressed != null)
1851         {
1852                 pButtonDelete->SetPressedBitmap(Point(0, 0), *pBitmapPressed);
1853                 delete pBitmapPressed;
1854         }
1855
1856         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_NORMAL);
1857         pBitmapPressed = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_PRESSED);
1858
1859         if (pBitmap != null)
1860         {
1861                 pButtonDelete->SetNormalBackgroundBitmap(*pBitmap);
1862                 delete pBitmap;
1863         }
1864         if (pBitmapPressed != null)
1865         {
1866                 pButtonDelete->SetPressedBackgroundBitmap(*pBitmapPressed);
1867                 delete pBitmapPressed;
1868         }
1869
1870         int actionId = 0;
1871         actionId |= TABLE_VIEW_DELETE_INPUT_FIELD_ID;
1872         actionId |= (groupIndex << TABLE_VIEW_GROUP_INDEX_SHIFT);
1873         actionId |= itemIndex;
1874
1875         pButtonDelete->SetActionId(actionId);
1876         pButtonDelete->AddActionEventListener(*this);
1877
1878         pTableViewItem->AddControl(pButtonDelete);
1879
1880         if (isDeleteButton == false)
1881         {
1882                 pButtonDelete->SetShowState(false);
1883         }
1884
1885         pTableViewItem->SetIndividualSelectionEnabled(pInputField, true);
1886         pTableViewItem->SetIndividualSelectionEnabled(pButtonType, true);
1887         pTableViewItem->SetIndividualSelectionEnabled(pButtonDelete, true);
1888
1889         return pTableViewItem;
1890 }
1891
1892 Tizen::Ui::Controls::TableViewItem*
1893 ContactEditorForm::GetPhoneNumberFields(int itemIndex, int itemWidth)
1894 {
1895         if (__pPhoneNumberFieldItem->GetCount() == 0)
1896         {
1897                 int phoneNumberCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER);
1898                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_NUMBER");
1899                 String defaultPhoneNumber = __pPresentationModel->GetValue(DETAIL_PROPERTY_DEFAULT_PHONE_NUMBER);
1900
1901                 for (int i = 0; i < phoneNumberCount; i++)
1902                 {
1903                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_PHONE_NUMBER, i);
1904                         String phoneNumberString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i);
1905
1906                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, typeString, guideText, phoneNumberString, true);
1907                         pItem->SetName(Integer::ToString(__pPresentationModel->GetPhoneNumberType(i)));
1908
1909                         __pPhoneNumberFieldItem->Add(*pItem);
1910                 }
1911
1912                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, phoneNumberCount, itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, __pPresentationModel->GetPhoneNumberTypeString(DETAIL_PHONENUMBER_TYPE_MOBILE), guideText);
1913                 pItem->SetName(Integer::ToString(DETAIL_PHONENUMBER_TYPE_MOBILE));
1914
1915                 __pPhoneNumberFieldItem->Add(*pItem);
1916                 SetAsDefaultPhoneNumber(__pPresentationModel->GetDefaultNumberIndex());
1917         }
1918
1919         if (__pPhoneNumberFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) + 1))
1920         {
1921                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, __pPhoneNumberFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_PHONE_NUMBER, __pPresentationModel->GetPhoneNumberTypeString(DETAIL_PHONENUMBER_TYPE_MOBILE), ResourceManager::GetString(L"IDS_PB_BODY_NUMBER"));
1922                 pItem->SetName(Integer::ToString(DETAIL_PHONENUMBER_TYPE_MOBILE));
1923
1924                 __pPhoneNumberFieldItem->Add(*pItem);
1925         }
1926
1927         TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(itemIndex));
1928         if (pItem == null)
1929         {
1930                 return null;
1931         }
1932
1933         return pItem;
1934 }
1935
1936 Tizen::Ui::Controls::TableViewItem*
1937 ContactEditorForm::GetEmailFields(int itemIndex, int itemWidth)
1938 {
1939         if (__pEmailFieldItem->GetCount() == 0)
1940         {
1941                 int emailCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL);
1942                 String guideText = ResourceManager::GetString(L"IDS_COM_BODY_EMAIL");
1943
1944                 for (int i = 0; i < emailCount; i++)
1945                 {
1946                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_EMAIL, i);
1947                         String emailString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_EMAIL, i);
1948
1949                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_EMAIL, typeString, guideText, emailString, true);
1950                         pItem->SetName(Integer::ToString(__pPresentationModel->GetEmailType(i)));
1951
1952                         __pEmailFieldItem->Add(*pItem);
1953                 }
1954
1955                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, emailCount, itemWidth, EDIT_FIELD_STYLE_EMAIL, __pPresentationModel->GetEmailTypeString(DETAIL_EMAIL_TYPE_HOME), guideText);
1956                 pItem->SetName(Integer::ToString(DETAIL_EMAIL_TYPE_HOME));
1957
1958                 __pEmailFieldItem->Add(*pItem);
1959         }
1960
1961         if (__pEmailFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL) + 1))
1962         {
1963                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_EMAIL_FIELD_INDEX, __pEmailFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_EMAIL, __pPresentationModel->GetEmailTypeString(DETAIL_EMAIL_TYPE_HOME), ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"));
1964                 pItem->SetName(Integer::ToString(DETAIL_EMAIL_TYPE_HOME));
1965
1966                 __pEmailFieldItem->Add(*pItem);
1967         }
1968
1969         TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(itemIndex));
1970         if (pItem == null)
1971         {
1972                 return null;
1973         }
1974
1975         return pItem;
1976 }
1977
1978 Tizen::Ui::Controls::TableViewItem*
1979 ContactEditorForm::GetAddressFields(int itemIndex, int itemWidth)
1980 {
1981         if (__pAddressFieldItem->GetCount() == 0)
1982         {
1983                 int addressCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS);
1984                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_ADDRESS");
1985
1986                 for (int i = 0; i < addressCount; i++)
1987                 {
1988                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_ADDRESS, i);
1989                         String addressString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_ADDRESS, i);
1990
1991                         TableViewItem* pItem= GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_NORMAL, typeString, guideText, addressString, true);
1992                         pItem->SetName(Integer::ToString(__pPresentationModel->GetAddressType(DETAIL_PROPERTY_ADDRESS, i)));
1993
1994                         __pAddressFieldItem->Add(*pItem);
1995                 }
1996
1997                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, addressCount, itemWidth, EDIT_FIELD_STYLE_NORMAL, ResourceManager::GetString(L"IDS_PB_BODY_HOME"), guideText);
1998                 pItem->SetName(Integer::ToString(DETAIL_ADDRESS_TYPE_HOME));
1999
2000                 __pAddressFieldItem->Add(*pItem);
2001         }
2002
2003         if (__pAddressFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_ADDRESS) + 1))
2004         {
2005                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_ADDRESS_FIELD_INDEX, __pAddressFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_NORMAL, ResourceManager::GetString(L"IDS_PB_BODY_HOME"), ResourceManager::GetString(L"IDS_PB_BODY_ADDRESS"));
2006                 pItem->SetName(Integer::ToString(DETAIL_ADDRESS_TYPE_HOME));
2007
2008                 __pAddressFieldItem->Add(*pItem);
2009         }
2010
2011         TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(itemIndex));
2012         if (pItem == null)
2013         {
2014                 return null;
2015         }
2016
2017         return pItem;
2018 }
2019
2020 Tizen::Ui::Controls::TableViewItem*
2021 ContactEditorForm::GetImAddressFields(int itemIndex, int itemWidth)
2022 {
2023         if (__pImAddressFieldItem->GetCount() == 0)
2024         {
2025                 int imCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS);
2026                 String guideText = ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB");
2027
2028                 for (int i = 0; i < imCount; i++)
2029                 {
2030                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_IM_ADDRESS, i);
2031                         String imString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_IM_ADDRESS, i);
2032
2033                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_NORMAL, typeString, guideText, imString, true);
2034                         pItem->SetName(Integer::ToString(__pPresentationModel->GetImAddressType(i)));
2035
2036                         __pImAddressFieldItem->Add(*pItem);
2037                 }
2038
2039                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, imCount, itemWidth, EDIT_FIELD_STYLE_NORMAL, IM_ADDRESS_YAHOO, guideText);
2040                 pItem->SetName(Integer::ToString(DETAIL_IM_ADDRESS_TYPE_YAHOO));
2041
2042                 __pImAddressFieldItem->Add(*pItem);
2043         }
2044
2045         if (__pImAddressFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_IM_ADDRESS) + 1))
2046         {
2047                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_IM_ADDRESS_FIELD_INDEX, __pImAddressFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_NORMAL, IM_ADDRESS_YAHOO, ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB"));
2048                 pItem->SetName(Integer::ToString(DETAIL_IM_ADDRESS_TYPE_YAHOO));
2049
2050                 __pImAddressFieldItem->Add(*pItem);
2051         }
2052
2053         TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(itemIndex));
2054         if (pItem == null)
2055         {
2056                 return null;
2057         }
2058
2059         return pItem;
2060 }
2061
2062 Tizen::Ui::Controls::TableViewItem*
2063 ContactEditorForm::GetUrlFields(int itemIndex, int itemWidth)
2064 {
2065         if (__pUrlFieldItem->GetCount() == 0)
2066         {
2067                 int urlCount = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL);
2068                 String guideText = ResourceManager::GetString(L"IDS_PB_BODY_URL");
2069
2070                 for (int i = 0; i < urlCount; i++)
2071                 {
2072                         String typeString = __pPresentationModel->GetType(DETAIL_PROPERTY_URL, i);
2073                         String urlString =  __pPresentationModel->GetValue(DETAIL_PROPERTY_URL, i);
2074
2075                         TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, i, itemWidth, EDIT_FIELD_STYLE_URL, typeString, guideText, urlString, true);
2076                         pItem->SetName(Integer::ToString(__pPresentationModel->GetUrlType(i)));
2077
2078                         __pUrlFieldItem->Add(*pItem);
2079                 }
2080
2081                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, urlCount, itemWidth, EDIT_FIELD_STYLE_URL, __pPresentationModel->GetUrlTypeString(DETAIL_URL_TYPE_HOME), guideText);
2082                 pItem->SetName(Integer::ToString(DETAIL_URL_TYPE_HOME));
2083
2084                 __pUrlFieldItem->Add(*pItem);
2085         }
2086
2087         if (__pUrlFieldItem->GetCount() != (__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_URL) + 1))
2088         {
2089                 TableViewItem* pItem = GetInputFieldN(TABLE_VIEW_URL_FIELD_INDEX, __pUrlFieldItem->GetCount(), itemWidth, EDIT_FIELD_STYLE_URL, __pPresentationModel->GetUrlTypeString(DETAIL_URL_TYPE_HOME), ResourceManager::GetString(L"IDS_PB_BODY_URL"));
2090                 pItem->SetName(Integer::ToString(DETAIL_URL_TYPE_HOME));
2091
2092                 __pUrlFieldItem->Add(*pItem);
2093         }
2094
2095         TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(itemIndex));
2096         if (pItem == null)
2097         {
2098                 return null;
2099         }
2100
2101         return pItem;
2102 }
2103 Tizen::Ui::Controls::TableViewItem*
2104 ContactEditorForm::GetGroupsField(int itemWidth)
2105 {
2106         TableViewItem* pGroupsItem = new (std::nothrow) TableViewItem();
2107         pGroupsItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2108         pGroupsItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
2109
2110         Label* pLabelTitle = new (std::nothrow) Label();
2111         pLabelTitle->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP, itemWidth, H_GROUP_RINGTONE_TITLE_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_GROUPS"));
2112         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2113         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
2114         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2115
2116         pGroupsItem->AddControl(pLabelTitle);
2117
2118         String groupsName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_GROUP);
2119         if (groupsName.IsEmpty() == true)
2120         {
2121                 groupsName = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
2122         }
2123
2124         Label* pLabelGroupName = new (std::nothrow) Label();
2125         pLabelGroupName->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP + H_GROUP_RINGTONE_TITLE_LABEL, itemWidth, H_GROUP_RINGTONE_VALUE_LABEL), groupsName);
2126         pLabelGroupName->SetTextConfig(FONT_SIZE_VALUE_TEXT, LABEL_TEXT_STYLE_NORMAL);
2127         pLabelGroupName->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2128
2129         pGroupsItem->AddControl(pLabelGroupName);
2130
2131         return pGroupsItem;
2132 }
2133
2134 Tizen::Ui::Controls::TableViewItem*
2135 ContactEditorForm::GetBirthdayField(int itemWidth)
2136 {
2137         DateTime birthdayDate;
2138         EditDate* pBirthday = new (std::nothrow) EditDate();
2139         pBirthday->Construct(Point(W_TITLE_LABEL, 0));
2140         pBirthday->AddDateChangeEventListener(*this);
2141
2142         __pPresentationModel->GetBirthday(birthdayDate);
2143         pBirthday->SetDate(birthdayDate);
2144
2145         DateTime currentDate;
2146         Tizen::System::SystemTime::GetCurrentTime(currentDate);
2147         int min;
2148         int max;
2149         pBirthday->GetYearRange(min, max);
2150         max = currentDate.GetYear();
2151         pBirthday->SetYearRange(min, max);
2152
2153         TableViewItem* pBirthdayItem = new (std::nothrow) TableViewItem();
2154         pBirthdayItem->Construct(Dimension(itemWidth, H_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2155         pBirthdayItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
2156         pBirthdayItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2157
2158         Label* pLabelTitle = new (std::nothrow) Label();
2159         pLabelTitle->Construct(Rectangle(0, 0, W_TITLE_LABEL, pBirthdayItem->GetHeight()), L"");
2160         pLabelTitle->SetText(ResourceManager::GetString(L"IDS_PB_BODY_BIRTHDAY"));
2161         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2162         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
2163         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2164
2165         pBirthdayItem->AddControl(pLabelTitle);
2166         pBirthdayItem->AddControl(pBirthday);
2167
2168         Button* pClearButton = new (std::nothrow) Button();
2169         pClearButton->Construct(Rectangle(itemWidth - (H_BUTTON * 2), (pBirthdayItem->GetHeight() - H_BUTTON) / 2, H_BUTTON, H_BUTTON));
2170         pClearButton->SetActionId(IDA_BUTTON_BIRTHDAY_CLEAR);
2171         pClearButton->AddActionEventListener(*this);
2172
2173         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RESET_NORMAL);
2174         if (pBitmap != null)
2175         {
2176                 pClearButton->SetNormalBitmap(Point(0, 0), *pBitmap);
2177                 delete pBitmap;
2178         }
2179         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RESET_PRESSED);
2180         if (pBitmap != null)
2181         {
2182                 pClearButton->SetPressedBitmap(Point(0, 0), *pBitmap);
2183                 delete pBitmap;
2184         }
2185
2186         pBirthdayItem->AddControl(pClearButton);
2187         pBirthdayItem->SetIndividualSelectionEnabled(pBirthday, true);
2188         pBirthdayItem->SetIndividualSelectionEnabled(pClearButton, true);
2189
2190         return pBirthdayItem;
2191 }
2192
2193 Tizen::Ui::Controls::TableViewItem*
2194 ContactEditorForm::GetNoteField(int itemWidth)
2195 {
2196         if (__pNoteFieldItem != null)
2197         {
2198                 return __pNoteFieldItem;
2199         }
2200
2201         __pNoteFieldItem = new (std::nothrow) TableViewItem();
2202         __pNoteFieldItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2203         __pNoteFieldItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
2204         __pNoteFieldItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2205
2206
2207         Label* pNoteTitle = new (std::nothrow) Label();
2208         pNoteTitle->Construct(Rectangle(0, 0, itemWidth, H_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_NOTE"));
2209         pNoteTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2210         pNoteTitle->SetTextColor(COLOR_ITEM_TITLE);
2211         pNoteTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2212         __pNoteFieldItem->AddControl(pNoteTitle);
2213
2214         ExpandableEditArea* pNoteEditArea = new (std::nothrow) ExpandableEditArea();
2215         pNoteEditArea->Construct(Rectangle(Y_EDIT_FIELD_GAP, H_LABEL, itemWidth - H_EDIT_FIELD_GAP, H_DOUBLE_LINE_ITEM - H_LABEL - H_EDIT_FIELD_GAP), EXPANDABLE_EDIT_AREA_STYLE_NORMAL, EXPANDABLE_EDIT_AREA_TITLE_STYLE_NONE);
2216         pNoteEditArea->SetTitleText(ResourceManager::GetString(L"IDS_PB_BODY_NOTE"));
2217         pNoteEditArea->SetText(__pPresentationModel->GetValue(DETAIL_PROPERTY_NOTE));
2218         pNoteEditArea->AddExpandableEditAreaEventListener(*this);
2219         pNoteEditArea->AddKeypadEventListener(*this);
2220         pNoteEditArea->AddFocusEventListener(*this);
2221         pNoteEditArea->AddTextEventListener(*this);
2222
2223         __pNoteFieldItem->AddControl(pNoteEditArea);
2224         __pNoteFieldItem->SetIndividualSelectionEnabled(pNoteEditArea, true);
2225
2226         return __pNoteFieldItem;
2227 }
2228
2229 Tizen::Ui::Controls::TableViewItem*
2230 ContactEditorForm::GetRingtoneField(int itemWidth)
2231 {
2232         TableViewItem* pRingtoneItem = new (std::nothrow) TableViewItem();
2233         pRingtoneItem->Construct(Dimension(itemWidth, H_DOUBLE_LINE_ITEM), TABLE_VIEW_ANNEX_STYLE_NORMAL);
2234         pRingtoneItem->SetBackgroundColor(COLOR_THUMBNAIL_BACKGROUND);
2235
2236         Label* pLabelTitle = new (std::nothrow) Label();
2237         pLabelTitle->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP, itemWidth, H_GROUP_RINGTONE_TITLE_LABEL), ResourceManager::GetString(L"IDS_PB_BODY_RINGTONE"));
2238         pLabelTitle->SetTextConfig(FONT_SIZE_TITLE_TEXT, LABEL_TEXT_STYLE_BOLD);
2239         pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
2240         pLabelTitle->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2241
2242         pRingtoneItem->AddControl(pLabelTitle);
2243
2244         String ringtoneName =  __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
2245         String trimmedPath;
2246         int index = 0;
2247
2248         ringtoneName.LastIndexOf(L"/", ringtoneName.GetLength() - 1, index);
2249
2250         if (index != 0)
2251         {
2252                 ringtoneName.SubString(index + 1, trimmedPath);
2253         }
2254
2255         Label* pLabelRingToneName = new (std::nothrow) Label();
2256         pLabelRingToneName->Construct(Rectangle(0, H_GROUP_RINGTONE_TITLE_GAP + H_GROUP_RINGTONE_TITLE_LABEL, itemWidth - H_GROUP_RINGTONE_TITLE_GAP - H_ICON_BUTTON, H_GROUP_RINGTONE_VALUE_LABEL), trimmedPath);
2257         pLabelRingToneName->SetTextConfig(FONT_SIZE_VALUE_TEXT, LABEL_TEXT_STYLE_NORMAL);
2258         pLabelRingToneName->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
2259         pRingtoneItem->AddControl(pLabelRingToneName);
2260
2261         Button* pClearButton = new (std::nothrow) Button();
2262         pClearButton->Construct(Rectangle(itemWidth - X_REFRESH_BUTTON_MARGIN, (pRingtoneItem->GetHeight() - H_ICON_BUTTON) / 2, H_ICON_BUTTON, H_ICON_BUTTON));
2263         pClearButton->SetActionId(IDA_BUTTON_RINGTONE_CLEAR);
2264         pClearButton->AddActionEventListener(*this);
2265
2266         Bitmap* pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_NORMAL);
2267         if (pReset != null)
2268         {
2269                 pClearButton->SetNormalBitmap(Point(0, 0), *pReset);
2270                 delete pReset;
2271         }
2272         pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_PRESSED);
2273         if (pReset != null)
2274         {
2275                 pClearButton->SetPressedBitmap(Point(0, 0), *pReset);
2276                 delete pReset;
2277         }
2278
2279         pRingtoneItem->AddControl(pClearButton);
2280         pRingtoneItem->SetIndividualSelectionEnabled(pClearButton, true);
2281
2282         return pRingtoneItem;
2283 }
2284
2285 Tizen::Ui::Controls::TableViewItem*
2286 ContactEditorForm::GetMoreInformationField(int itemWidth)
2287 {
2288         TableViewItem* pMoreInformationItem = new (std::nothrow) TableViewItem();
2289         pMoreInformationItem->Construct(Dimension(itemWidth, H_DESCRIPTION_CONTAINER));
2290         pMoreInformationItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
2291         pMoreInformationItem->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2292
2293         Panel* pPanel = new (std::nothrow) Panel();
2294         pPanel->Construct(Rectangle(X_MORE_INFO_PANEL_GAP, X_MORE_INFO_PANEL_GAP, itemWidth - H_MORE_INFO_PANEL_GAP, H_DESCRIPTION_CONTAINER - H_MORE_INFO_PANEL_GAP));
2295         pPanel->SetBackgroundColor(Color(COLOR_TABLE_VIEW_BG));
2296
2297         pMoreInformationItem->AddControl(pPanel);
2298
2299         Button* pButtonMoreInformation = new (std::nothrow) Button();
2300         pButtonMoreInformation->Construct(Rectangle(X_MORE_INFORMATION_BUTTON, Y_MORE_INFORMATION_BUTTON, itemWidth - (X_MORE_INFORMATION_BUTTON * 2), H_BUTTON));
2301         pButtonMoreInformation->SetText(ResourceManager::GetString(L"IDS_KA_BODY_MORE_INFORMATION"));
2302         pButtonMoreInformation->SetActionId(IDA_BUTTON_MORE_INFO);
2303         pButtonMoreInformation->AddActionEventListener(*this);
2304
2305         pPanel->AddControl(pButtonMoreInformation);
2306
2307         return pMoreInformationItem;
2308 }
2309
2310 Tizen::Ui::Controls::TableViewItem*
2311 ContactEditorForm::GetDefaultPhoneNumberItem(int itemWidth)
2312 {
2313         TableViewItem* pDefaultPhoneNumberItem = new (std::nothrow) TableViewItem();
2314         pDefaultPhoneNumberItem->Construct(Dimension(itemWidth, H_ITEM));
2315         pDefaultPhoneNumberItem->SetBackgroundColor(Color(0), TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
2316
2317         Button* pButtonDefaultNumber = new (std::nothrow) Button();
2318         pButtonDefaultNumber->Construct(Rectangle(X_MORE_INFORMATION_BUTTON, Y_DEFAULT_NUMBER_BUTTON, itemWidth - (X_MORE_INFORMATION_BUTTON * 2), H_BUTTON));
2319         pButtonDefaultNumber->SetText(ResourceManager::GetString(L"IDS_PB_BODY_MARK_AS_DEFAULT_NUMBER"));
2320         pButtonDefaultNumber->SetActionId(IDA_BUTTON_DEFAULT_PHONE_NUMBER);
2321         pButtonDefaultNumber->AddActionEventListener(*this);
2322
2323         pDefaultPhoneNumberItem->AddControl(pButtonDefaultNumber);
2324         pDefaultPhoneNumberItem->SetIndividualSelectionEnabled(pButtonDefaultNumber, true);
2325
2326         return pDefaultPhoneNumberItem;
2327 }
2328
2329 result
2330 ContactEditorForm::DeleteInputField(int groupIndex, int itemIndex)
2331 {
2332         result r = E_SUCCESS;
2333         ArrayList* pFieldList = null;
2334
2335         switch (groupIndex)
2336         {
2337         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
2338                 {
2339                         pFieldList = __pPhoneNumberFieldItem;
2340                         TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(itemIndex));
2341                         if (pItem != null)
2342                         {
2343                                 String phoneNumberTypeString(pItem->GetName());
2344                                 int phoneNumberType;
2345
2346                                 Integer::Parse(phoneNumberTypeString, phoneNumberType);
2347                                 __pPresentationModel->SetPhoneNumber((DetailPhoneNumberType)phoneNumberType, L"", itemIndex);
2348                         }
2349                 }
2350                 break;
2351         case TABLE_VIEW_EMAIL_FIELD_INDEX:
2352                 {
2353                         pFieldList = __pEmailFieldItem;
2354                         TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(itemIndex));
2355                         if (pItem != null)
2356                         {
2357                                 String emailTypeString(pItem->GetName());
2358                                 int emailType;
2359
2360                                 Integer::Parse(emailTypeString, emailType);
2361                                 __pPresentationModel->SetEmail((DetailEmailType)emailType, L"", itemIndex);
2362                         }
2363                 }
2364                 break;
2365         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
2366                 {
2367                         pFieldList = __pAddressFieldItem;
2368
2369                         TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(itemIndex));
2370                         if (pItem != null)
2371                         {
2372                                 String addressTypeString(pItem->GetName());
2373                                 int addressType;
2374
2375                                 Integer::Parse(addressTypeString, addressType);
2376                                 __pPresentationModel->SetAddress((DetailAddressType)addressType, L"", itemIndex);
2377                         }
2378                 }
2379                 break;
2380         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
2381                 {
2382                         pFieldList = __pImAddressFieldItem;
2383
2384                         TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(itemIndex));
2385                         if (pItem != null)
2386                         {
2387                                 String imAddressTypeString(pItem->GetName());
2388                                 int imAddressType;
2389
2390                                 Integer::Parse(imAddressTypeString, imAddressType);
2391                                 __pPresentationModel->SetImAddress((DetailImAddressType)imAddressType, L"", itemIndex);
2392                         }
2393                 }
2394                 break;
2395         case TABLE_VIEW_URL_FIELD_INDEX:
2396                 {
2397                         pFieldList = __pUrlFieldItem;
2398
2399                         TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(itemIndex));
2400                         if (pItem != null)
2401                         {
2402                                 String urlTypeString(pItem->GetName());
2403                                 int urlType;
2404
2405                                 Integer::Parse(urlTypeString, urlType);
2406                                 __pPresentationModel->SetUrl((DetailUrlType)urlType, L"", itemIndex);
2407                         }
2408                 }
2409                 break;
2410         default:
2411                 break;
2412         }
2413
2414         TryReturn(pFieldList != null, E_FAILURE, "[E_FAILURE] Unable to delete the item.")
2415
2416         r = pFieldList->RemoveAt(itemIndex, false);
2417         __delGroupIndex = groupIndex;
2418         __delItemIndex  = itemIndex;
2419         __pTableView->RefreshItem(groupIndex, itemIndex, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
2420
2421         Rectangle clientBounds = GetClientAreaBounds();
2422         __pTableView->SetSize(clientBounds.width, clientBounds.height);
2423
2424         for (int i = itemIndex; i < pFieldList->GetCount(); i++)
2425         {
2426                 TableViewItem* pItem = static_cast<TableViewItem *>(pFieldList->GetAt(i));
2427                 if (pItem == null)
2428                 {
2429                         return E_FAILURE;
2430                 }
2431
2432                 int parsedIndex;
2433                 EditField* pInputField = static_cast<EditField*>(pItem->GetControl(0));
2434                 if (pInputField == null)
2435                 {
2436                         return E_FAILURE;
2437                 }
2438
2439                 result r = Integer::Decode(pInputField->GetName(), parsedIndex);
2440                 if (r == E_NUM_FORMAT)
2441                 {
2442                         return E_FAILURE;
2443                 }
2444                 pInputField->SetName(Integer::ToString(parsedIndex - 1));
2445
2446                 Button* pTypeButton = static_cast<Button*>(pItem->GetControl(1));
2447                 if (pTypeButton == null)
2448                 {
2449                         return E_FAILURE;
2450                 }
2451
2452                 r = Integer::Decode(pTypeButton->GetName(), parsedIndex);
2453                 if (r == E_NUM_FORMAT)
2454                 {
2455                         return E_FAILURE;
2456                 }
2457                 pTypeButton->SetName(Integer::ToString(parsedIndex - 1));
2458
2459                 Button* pDeleteButton = static_cast<Button *>(pItem->GetControl(2));
2460                 if (pDeleteButton == null)
2461                 {
2462                         return E_FAILURE;
2463                 }
2464                 pDeleteButton->SetActionId(pDeleteButton->GetActionId() - 1);
2465         }
2466
2467         SaveContactData(false);
2468         SetSaveButtonEnabled(IsSaveContactValid());
2469         
2470         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
2471         {
2472                 if (itemIndex == __pPresentationModel->GetDefaultNumberIndex())
2473                 {
2474                         if (itemIndex > 0)
2475                         {
2476                                 SetAsDefaultPhoneNumber(itemIndex - 1);
2477                         }
2478                         else
2479                         {
2480                                 SetAsDefaultPhoneNumber(itemIndex);
2481                         }
2482                 }
2483                 else if (itemIndex < __pPresentationModel->GetDefaultNumberIndex())
2484                 {
2485                         SetAsDefaultPhoneNumber(__pPresentationModel->GetDefaultNumberIndex() - 1);
2486                 }
2487         }
2488
2489         if (__isDefaultPhoneNumberButtonEnabled == true && __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) < 2)
2490         {
2491                 __pTableView->RefreshItem(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, __pTableView->GetItemCountAt(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX) - 1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
2492
2493                 __isDefaultPhoneNumberButtonEnabled = false;
2494         }
2495
2496         return r;
2497 }
2498
2499 void
2500 ContactEditorForm::SetThumbnailControls(Tizen::Ui::Controls::TableViewItem& item, bool isUpdated)
2501 {
2502         Label* pLabelThumbnail = null;
2503         Button* pButtonAdd = null;
2504         Button* pButtonDelete = null;
2505
2506         if (isUpdated == false)
2507         {
2508                 int itemWidth = GetBounds().width;
2509
2510                 pLabelThumbnail = new (std::nothrow) Label();
2511                 pLabelThumbnail->Construct(Rectangle((itemWidth - W_THUMBNAIL) / 2, Y_EDIT_FIELD_GAP, W_THUMBNAIL, W_THUMBNAIL - H_EDIT_FIELD_GAP), L"");
2512
2513                 item.AddControl(pLabelThumbnail);
2514
2515                 Bitmap* pBitmapItem = null;
2516                 Bitmap* pBitmapItemPressed = null;
2517
2518                 pButtonAdd = new (std::nothrow) Button();
2519                 pButtonAdd->Construct(Rectangle(pLabelThumbnail->GetX() + ((pLabelThumbnail->GetWidth() - H_BUTTON) / 2), pLabelThumbnail->GetY() + ((pLabelThumbnail->GetHeight() - H_BUTTON) / 2), H_BUTTON, H_BUTTON));
2520                 pButtonAdd->SetActionId(IDA_BUTTON_THUMBNAIL_ADD);
2521                 pButtonAdd->AddActionEventListener(*this);
2522
2523                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_ADD);
2524                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_ADD_PRESSED);
2525
2526                 if (pBitmapItem != null)
2527                 {
2528                         pButtonAdd->SetNormalBackgroundBitmap(*pBitmapItem);
2529                         delete pBitmapItem;
2530                 }
2531                 if (pBitmapItemPressed != null)
2532                 {
2533                         pButtonAdd->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2534                         delete pBitmapItemPressed;
2535                 }
2536                 item.AddControl(pButtonAdd);
2537                 item.SetIndividualSelectionEnabled(pButtonAdd, true);
2538
2539                 pButtonDelete = new (std::nothrow) Button();
2540                 pButtonDelete->Construct(Rectangle(pLabelThumbnail->GetX() + W_THUMBNAIL_DELETE_BUTTON_GAP, pLabelThumbnail->GetY() + H_THUMBNAIL_DELETE_BUTTON_GAP, H_BUTTON, H_BUTTON));
2541                 pButtonDelete->SetActionId(IDA_BUTTON_THUMBNAIL_DELETE);
2542                 pButtonDelete->AddActionEventListener(*this);
2543
2544                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS);
2545                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_MINUS_PRESSED);
2546
2547                 if (pBitmapItem != null)
2548                 {
2549                         pButtonDelete->SetNormalBitmap(Point(0, 0), *pBitmapItem);
2550                         delete pBitmapItem;
2551                 }
2552                 if (pBitmapItemPressed != null)
2553                 {
2554                         pButtonDelete->SetPressedBitmap(Point(0, 0), *pBitmapItemPressed);
2555                         delete pBitmapItemPressed;
2556                 }
2557
2558                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_NORMAL);
2559                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_DELETE_PRESSED);
2560
2561                 if (pBitmapItem != null)
2562                 {
2563                         pButtonDelete->SetNormalBackgroundBitmap(*pBitmapItem);
2564                         delete pBitmapItem;
2565                 }
2566                 if (pBitmapItemPressed != null)
2567                 {
2568                         pButtonDelete->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2569                         delete pBitmapItemPressed;
2570                 }
2571                 item.AddControl(pButtonDelete);
2572                 item.SetIndividualSelectionEnabled(pButtonDelete, true);
2573
2574                 Button* pButtonCamera = new (std::nothrow) Button();
2575                 pButtonCamera->Construct(Rectangle(pLabelThumbnail->GetX() + pLabelThumbnail->GetWidth(), pLabelThumbnail->GetY() + pLabelThumbnail->GetHeight() - H_BUTTON, H_BUTTON, H_BUTTON));
2576                 pButtonCamera->SetActionId(IDA_BUTTON_CAMERA);
2577                 pButtonCamera->AddActionEventListener(*this);
2578
2579                 pBitmapItem = ResourceManager::GetBitmapN(IDB_BUTTON_CAMERA);
2580                 pBitmapItemPressed = ResourceManager::GetBitmapN(IDB_BUTTON_CAMERA_PRESSED);
2581                 if (pBitmapItem != null)
2582                 {
2583                         pButtonCamera->SetNormalBackgroundBitmap(*pBitmapItem);
2584                         delete pBitmapItem;
2585                 }
2586                 if (pBitmapItemPressed != null)
2587                 {
2588                         pButtonCamera->SetPressedBackgroundBitmap(*pBitmapItemPressed);
2589                         delete pBitmapItemPressed;
2590                 }
2591
2592                 item.AddControl(pButtonCamera);
2593                 item.SetIndividualSelectionEnabled(pButtonCamera, true);
2594         }
2595         else
2596         {
2597                 pLabelThumbnail = static_cast<Label*>(item.GetControl(0));
2598                 TryReturnVoid(pLabelThumbnail != null, "[E_FAILURE] Unable to get a thumbnail control.");
2599
2600                 pButtonAdd = static_cast<Button*>(item.GetControl(1));
2601                 TryReturnVoid(pButtonAdd != null, "[E_FAILURE] Unable to get a button.");
2602
2603                 pButtonDelete = static_cast<Button*>(item.GetControl(2));
2604                 TryReturnVoid(pButtonDelete != null, "[E_FAILURE] Unable to get a button.");
2605         }
2606
2607         Bitmap* pThumbnail = null;
2608         String thumbnailPath = __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL);
2609
2610         if (thumbnailPath.IsEmpty() == false)
2611         {
2612                 ImageBuffer thumbnailImageBuffer;
2613                 result r = thumbnailImageBuffer.Construct(thumbnailPath);
2614                 if (r == E_SUCCESS)
2615                 {
2616                         pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
2617                 }
2618                 if (pThumbnail != null)
2619                 {
2620                         pThumbnail->SetScalingQuality(BITMAP_SCALING_QUALITY_HIGH);
2621                         pThumbnail->Scale(Dimension(W_THUMBNAIL, W_THUMBNAIL));
2622                         pLabelThumbnail->SetBackgroundBitmap(*pThumbnail);
2623                 }
2624                 pButtonAdd->SetShowState(false);
2625                 pButtonDelete->SetShowState(true);
2626         }
2627         else
2628         {
2629                 pThumbnail = ResourceManager::GetBitmapN(IDB_THUMBNAIL_BACKGROUND);
2630                 if (pThumbnail != null)
2631                 {
2632                         pLabelThumbnail->SetBackgroundBitmap(*pThumbnail);
2633                         pButtonAdd->SetShowState(true);
2634                         pButtonDelete->SetShowState(false);
2635                 }
2636         }
2637
2638         delete pThumbnail;
2639 }
2640
2641 void
2642 ContactEditorForm::AddHorizontalDivider(Tizen::Ui::Controls::TableViewItem* pItem, int positionY, int width)
2643 {
2644         Label* pDivider = new (std::nothrow) Label();
2645         pDivider->Construct(Rectangle(0, positionY, width, H_DIVIDER), L"");
2646         pDivider->SetBackgroundColor(Color(COLOR_DIVIDER));
2647         pDivider->SetEnabled(false);
2648
2649         pItem->AddControl(pDivider);
2650 }
2651
2652 void
2653 ContactEditorForm::AddVerticalDivider(Tizen::Ui::Controls::TableViewItem* pItem, int positionX, int positionY)
2654 {
2655         Label* pDivider = new (std::nothrow) Label();
2656         pDivider->Construct(Rectangle(positionX, positionY, W_DIVIDER, H_ITEM), L"");
2657         pDivider->SetBackgroundColor(Color(COLOR_DIVIDER));
2658         pDivider->SetEnabled(false);
2659
2660         pItem->AddControl(pDivider);
2661 }
2662
2663 result
2664 ContactEditorForm::SetAsDefaultPhoneNumber(int index)
2665 {
2666         result r = E_SUCCESS;
2667         TableViewItem* pItem = null;
2668         EditField* pEditField = null;
2669
2670         pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(index));
2671         if (pItem == null)
2672         {
2673                 r = E_FAILURE;
2674                 goto CATCH;
2675         }
2676
2677         pEditField = static_cast<EditField *>(pItem->GetControl(0));
2678         if (pEditField == null)
2679         {
2680                 r = E_FAILURE;
2681                 goto CATCH;
2682         }
2683
2684         __pPresentationModel->SetValue(DETAIL_PROPERTY_DEFAULT_PHONE_NUMBER, L"", index);
2685
2686         if (pEditField->IsVisible() == false)
2687         {
2688                 __pTableView->ScrollToItem(TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX, index);
2689         }
2690         pEditField->Invalidate(true);
2691
2692 CATCH:
2693         return r;
2694 }
2695
2696 result
2697 ContactEditorForm::ChangeNameFieldStatus(void)
2698 {
2699         result r = E_SUCCESS;
2700
2701         r = SaveNameFields();
2702
2703         __isExpandable = (__isExpandable == true) ? false : true;
2704
2705         return r;
2706 }
2707
2708 result
2709 ContactEditorForm::SaveContactData(bool isSaved)
2710 {
2711         result r = E_SUCCESS;
2712
2713         if (isSaved == true)
2714         {
2715                 long long avialableMemory = 0;
2716                 result r = E_SUCCESS;
2717
2718                 String key(RUNTIMEINFO_INTERNAL_MEMORY_KEY);
2719
2720                 r  = RuntimeInfo::GetValue(key, avialableMemory);
2721                 if (avialableMemory == 0)
2722                 {
2723                         int modalResult = 0;
2724                         MessageBox memoryFullMessageBox;
2725                         memoryFullMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_EMAIL_POP_DEVICE_STORAGE_FULL"), MSGBOX_STYLE_NONE, 1000);
2726                         memoryFullMessageBox.ShowAndWait(modalResult);
2727                         return E_FAILURE;
2728                 }
2729         }
2730
2731         r = SaveNameFields();
2732
2733         for (int i = 0; i < __pPhoneNumberFieldItem->GetCount(); i++)
2734         {
2735                 r = E_SUCCESS;
2736                 TableViewItem* pItem = static_cast<TableViewItem *>(__pPhoneNumberFieldItem->GetAt(i));
2737                 if (pItem == null)
2738                 {
2739                         r = E_FAILURE;
2740                         break;
2741                 }
2742
2743                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2744                 if (pEditField == null)
2745                 {
2746                         r = E_FAILURE;
2747                         break;
2748                 }
2749
2750                 String phoneNumberString(pEditField->GetText());
2751                 String phoneNumberTypeString(pItem->GetName());
2752                 int phoneNumberType;
2753                 phoneNumberString.Trim();
2754                 wchar_t ch;
2755
2756                 for (int i = 0; i < phoneNumberString.GetLength(); i++)
2757                 {
2758                         phoneNumberString.GetCharAt(i, ch);
2759
2760                         if(ch == '+' && i == 0)
2761                         {
2762                                 continue;
2763                         }
2764                         else if ((ch < '0' || ch > '9') && (ch != '*') && (ch != '#'))
2765                         {
2766                                 r = E_FAILURE;
2767                                 break;
2768                         }
2769                         else
2770                         {
2771                                 r = E_SUCCESS;
2772                         }
2773                 }
2774
2775                 if (isSaved == true && phoneNumberString.GetLength() > 0 && r != E_SUCCESS)
2776                 {
2777                         int modalResult;
2778                         MessageBox invalidNumberMessage;
2779                         invalidNumberMessage.Construct(L"", ResourceManager::GetString(L"IDS_PB_BODY_INVALID_NUMBER"), MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT_MS);
2780                         invalidNumberMessage.ShowAndWait(modalResult);
2781
2782                         return E_FAILURE;
2783                 }
2784
2785                 Integer::Parse(phoneNumberTypeString, phoneNumberType);
2786
2787                 __pPresentationModel->SetPhoneNumber((DetailPhoneNumberType)phoneNumberType, phoneNumberString, i);
2788         }
2789
2790         for (int i = 0; i < __pEmailFieldItem->GetCount(); i++)
2791         {
2792                 TableViewItem* pItem = static_cast<TableViewItem *>(__pEmailFieldItem->GetAt(i));
2793                 if (pItem == null)
2794                 {
2795                         r = E_FAILURE;
2796                         break;
2797                 }
2798
2799                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2800                 if (pEditField == null)
2801                 {
2802                         r = E_FAILURE;
2803                         break;
2804                 }
2805
2806                 String emailString(pEditField->GetText());
2807                 String remainingString;
2808                 String emailTypeString(pItem->GetName());
2809                 int emailType;
2810
2811                 emailString.Trim();
2812                 Integer::Parse(emailTypeString, emailType);
2813
2814                 r = __pPresentationModel->SetEmail((DetailEmailType)emailType, emailString, i);
2815
2816                 if (isSaved == true && r == E_SUCCESS)
2817                 {
2818                         if(emailString.GetLength() > 0)
2819                         {
2820                                 bool isValidEmail = ValidateEmailAddress(emailString);
2821                                 if (isValidEmail != true)
2822                                 {
2823                                         int modalResult;
2824                                         MessageBox invalidEmailMessage;
2825                                         invalidEmailMessage.Construct(L"", ResourceManager::GetString(L"IDS_PB_POP_INVALID_EMAIL_ADDRESS"), MSGBOX_STYLE_OK, MESSAGE_BOX_TIMEOUT_MS);
2826                                         invalidEmailMessage.ShowAndWait(modalResult);
2827                                         pEditField->ShowKeypad();
2828
2829                                         return E_FAILURE;
2830                                 }
2831                         }
2832                 }
2833         }
2834
2835         for (int i = 0; i < __pAddressFieldItem->GetCount(); i++)
2836         {
2837                 TableViewItem* pItem = static_cast<TableViewItem *>(__pAddressFieldItem->GetAt(i));
2838                 if (pItem == null)
2839                 {
2840                         r = E_FAILURE;
2841                         break;
2842                 }
2843
2844                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2845                 if (pEditField == null)
2846                 {
2847                         r = E_FAILURE;
2848                         break;
2849                 }
2850
2851                 String addressString(pEditField->GetText());
2852
2853                 addressString.Trim();
2854                 __pPresentationModel->SetValue(DETAIL_PROPERTY_ADDRESS_STREET, addressString, i);
2855         }
2856
2857         for (int i = 0; i < __pImAddressFieldItem->GetCount(); i++)
2858         {
2859                 TableViewItem* pItem = static_cast<TableViewItem *>(__pImAddressFieldItem->GetAt(i));
2860                 if (pItem == null)
2861                 {
2862                         r = E_FAILURE;
2863                         break;
2864                 }
2865
2866                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2867                 if (pEditField == null)
2868                 {
2869                         r = E_FAILURE;
2870                         break;
2871                 }
2872
2873                 String addressString(pEditField->GetText());
2874                 String addressTypeString(pItem->GetName());
2875                 int addressType;
2876
2877                 addressString.Trim();
2878                 Integer::Parse(addressTypeString, addressType);
2879
2880                 __pPresentationModel->SetImAddress((DetailImAddressType)addressType, addressString, i);
2881         }
2882
2883         for (int i = 0; i < __pUrlFieldItem->GetCount(); i++)
2884         {
2885                 TableViewItem* pItem = static_cast<TableViewItem *>(__pUrlFieldItem->GetAt(i));
2886                 if (pItem == null)
2887                 {
2888                         r = E_FAILURE;
2889                         break;
2890                 }
2891
2892                 EditField* pEditField = static_cast<EditField *>(pItem->GetControl(0));
2893                 if (pEditField == null)
2894                 {
2895                         r = E_FAILURE;
2896                         break;
2897                 }
2898
2899                 String urlString(pEditField->GetText());
2900                 String urlTypeString(pItem->GetName());
2901                 int urlType;
2902
2903                 urlString.Trim();
2904                 Integer::Parse(urlTypeString, urlType);
2905
2906                 __pPresentationModel->SetUrl((DetailUrlType)urlType, urlString, i);
2907         }
2908
2909         if (__pNoteFieldItem != null)
2910         {
2911                 String noteString;
2912                 ExpandableEditArea* pNoteEditArea = static_cast<ExpandableEditArea *>(__pNoteFieldItem->GetControl(1));
2913                 if (pNoteEditArea != null)
2914                 {
2915                         noteString.Append(pNoteEditArea->GetText());
2916                 }
2917
2918                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NOTE, noteString);
2919         }
2920
2921         if (isSaved == true)
2922         {
2923                 r = __pPresentationModel->AddAddressBook();
2924         }
2925         return r;
2926 }
2927
2928 result
2929 ContactEditorForm::SaveNameFields(void)
2930 {
2931         result r = E_SUCCESS;
2932
2933         if (__pNameFieldItem == null)
2934         {
2935                 return E_FAILURE;
2936         }
2937
2938         if (__isExpandable == true)
2939         {
2940                 EditField* pFirstName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_FIRST_NAME"), false));
2941                 if (pFirstName == null)
2942                 {
2943                         return E_FAILURE;
2944                 }
2945                 __pPresentationModel->SetValue(DETAIL_PROPERTY_FIRST_NAME, pFirstName->GetText());
2946
2947                 EditField* pLastName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_LAST_NAME"), false));
2948                 if (pLastName == null)
2949                 {
2950                         return E_FAILURE;
2951                 }
2952
2953                 __pPresentationModel->SetValue(DETAIL_PROPERTY_LAST_NAME, pLastName->GetText());
2954
2955                 EditField* pMiddleName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_MIDDLE_NAME"), false));
2956                 if (pMiddleName == null)
2957                 {
2958                         return E_FAILURE;
2959                 }
2960                 __pPresentationModel->SetValue(DETAIL_PROPERTY_MIDDLE_NAME, pMiddleName->GetText());
2961
2962                 EditField* pSuffix = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_SUFFIX"), false));
2963                 if (pSuffix == null)
2964                 {
2965                         return E_FAILURE;
2966                 }
2967                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NAME_SUFFIX, pSuffix->GetText());
2968
2969                 EditField* pNickName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_NICKNAME"), false));
2970                 if (pNickName == null)
2971                 {
2972                         return E_FAILURE;
2973                 }
2974                 __pPresentationModel->SetValue(DETAIL_PROPERTY_NICK_NAME, pNickName->GetText());
2975
2976                 EditField* pCompanyName = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_COMPANY"), false));
2977                 if (pCompanyName == null)
2978                 {
2979                         return E_FAILURE;
2980                 }
2981                 __pPresentationModel->SetValue(DETAIL_PROPERTY_COMPANY, pCompanyName->GetText());
2982
2983                 if (__isJobTitleEnabled == true)
2984                 {
2985                         EditField* pJobTitle = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"), false));
2986                         if (pJobTitle == null)
2987                         {
2988                                 return E_FAILURE;
2989                         }
2990                         __pPresentationModel->SetValue(DETAIL_PROPERTY_JOB_TITLE, pJobTitle->GetText());
2991                 }
2992
2993                 if (__isDepartmentEnabled == true)
2994                 {
2995                         EditField* pDepartment = static_cast<EditField *>(__pNameFieldItem->GetControl(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"), false));
2996                         if (pDepartment == null)
2997                         {
2998                                 return E_FAILURE;
2999                         }
3000                         __pPresentationModel->SetValue(DETAIL_PROPERTY_DEPARTMENT, pDepartment->GetText());
3001                 }
3002         }
3003         else
3004         {
3005                 EditField* pName = static_cast<EditField *>(__pNameFieldItem->GetControl(Integer::ToString(IDA_INPUT_FIELD_DISPLAY_NAME), false));
3006                 if (pName == null)
3007                 {
3008                         return E_FAILURE;
3009                 }
3010
3011                 String displayName(pName->GetText());
3012                 String firstName;
3013                 String lastName;
3014                 int delimeterIndex;
3015
3016                 displayName.IndexOf(CHARACTER_SPACE, 0, delimeterIndex);
3017
3018                 if (delimeterIndex < 0)
3019                 {
3020                         firstName.Append(displayName);
3021                 }
3022                 else
3023                 {
3024                         displayName.SubString(0, delimeterIndex++, firstName);
3025                         displayName.SubString(delimeterIndex, displayName.GetLength() - delimeterIndex, lastName);
3026                 }
3027
3028                 __pPresentationModel->SetValue(DETAIL_PROPERTY_FIRST_NAME, firstName);
3029                 __pPresentationModel->SetValue(DETAIL_PROPERTY_LAST_NAME, lastName);
3030         }
3031
3032         return r;
3033 }
3034
3035 bool
3036 ContactEditorForm::IsSaveContactValid(void)
3037 {
3038         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_FIRST_NAME).IsEmpty() == false)
3039         {
3040                 return true;
3041         }
3042
3043         if (__pPresentationModel->GetValue(DETAIL_PROPERTY_LAST_NAME).IsEmpty() == false)
3044         {
3045                 return true;
3046         }
3047
3048         for (int i = 0; i < __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER); i++)
3049         {
3050                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i).IsEmpty() == false)
3051                 {
3052                         return true;
3053                 }
3054         }
3055
3056         for (int i = 0; i < __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_EMAIL); i++)
3057         {
3058                 if (__pPresentationModel->GetValue(DETAIL_PROPERTY_EMAIL, i).IsEmpty() == false)
3059                 {
3060                         return true;
3061                 }
3062         }
3063
3064         return false;
3065 }
3066
3067 void
3068 ContactEditorForm::SetSaveButtonEnabled(bool enable)
3069 {
3070         Footer* pFooter = GetFooter();
3071
3072         if (enable)
3073         {
3074                 pFooter->SetItemEnabled(0, true);
3075         }
3076         else
3077         {
3078                 pFooter->SetItemEnabled(0, false);
3079         }
3080
3081         pFooter->Invalidate(true);
3082 }
3083
3084 bool
3085 ContactEditorForm::IsMoreInformationButtonVisible(void)
3086 {
3087         if (__isJobTitleEnabled == false)
3088         {
3089                 return true;
3090         }
3091
3092         if (__isDepartmentEnabled == false)
3093         {
3094                 return true;
3095         }
3096
3097         if (__pImAddressFieldItem->GetCount() == 0)
3098         {
3099                 return true;
3100         }
3101
3102         if (__pUrlFieldItem->GetCount() == 0)
3103         {
3104                 return true;
3105         }
3106
3107         DateTime birthday;
3108         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
3109         {
3110                 return true;
3111         }
3112
3113         if (__pNoteFieldItem == null)
3114         {
3115                 return true;
3116         }
3117
3118         return false;
3119 }
3120
3121 void
3122 ContactEditorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
3123 {
3124         TableViewItem* pTableViewItem = static_cast<TableViewItem *>(source.GetParent());
3125
3126         __isContactModified = true;
3127
3128         if (pTableViewItem == null)
3129         {
3130                 return;
3131         }
3132
3133         SaveContactData(false);
3134         SetSaveButtonEnabled(IsSaveContactValid());
3135
3136         if (__pNameFieldItem == pTableViewItem)
3137         {
3138                 return;
3139         }
3140
3141         EditField* pEditField = const_cast<EditField *>(static_cast<const EditField *>(&source));
3142         if (pEditField == null)
3143         {
3144                 return;
3145         }
3146
3147         Control* pDeleteButton = pTableViewItem->GetControl(2);
3148         if (pDeleteButton == null)
3149         {
3150                 return;
3151         }
3152
3153         int index = 0;
3154         int groupIndex = 0;
3155         int inputFlag = 0;
3156         int itemCount = 0;
3157
3158         Integer::Decode(pEditField->GetName(), index);
3159         groupIndex = (index & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
3160         inputFlag = (index & TABLE_VIEW_INPUT_FIELD_INDEX_MASK) >> TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3161         itemCount = __pTableView->GetItemCountAt(groupIndex);
3162
3163         String trimmedString = pEditField->GetText();
3164         trimmedString.Trim();
3165
3166         if (trimmedString.IsEmpty())
3167         {
3168                 pDeleteButton->SetShowState(false);
3169         }
3170         else if (pDeleteButton->GetShowState() == false)
3171         {
3172                 pDeleteButton->SetShowState(true);
3173                 if (inputFlag <= 0)
3174                 {
3175                         index |= (1 << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT);
3176                         pEditField->SetName(Integer::ToString(index));
3177
3178                         if (groupIndex == TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX)
3179                         {
3180                                 if (__isDefaultPhoneNumberButtonEnabled == false && __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1)
3181                                 {
3182                                         __isDefaultPhoneNumberButtonEnabled = true;
3183                                         __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex), TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
3184                                 }
3185                                 else if (itemCount > 1)
3186                                 {
3187                                         itemCount--;
3188                                 }
3189                         }
3190
3191                         ArrayList* pFieldList = null;
3192                         switch (groupIndex)
3193                         {
3194                         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
3195                                 {
3196                                         pFieldList = __pPhoneNumberFieldItem;
3197                                 }
3198                                 break;
3199                         case TABLE_VIEW_EMAIL_FIELD_INDEX:
3200                                 {
3201                                         pFieldList = __pEmailFieldItem;
3202                                 }
3203                                 break;
3204                         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
3205                                 {
3206                                         pFieldList = __pAddressFieldItem;
3207                                 }
3208                                 break;
3209                         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
3210                                 {
3211                                         pFieldList = __pImAddressFieldItem;
3212                                 }
3213                                 break;
3214                         case TABLE_VIEW_URL_FIELD_INDEX:
3215                                 {
3216                                         pFieldList = __pUrlFieldItem;
3217                                 }
3218                                 break;
3219                         default:
3220                                 break;
3221                         }
3222
3223                         if (pFieldList != null)
3224                         {
3225                                 TableViewItem* pItem = static_cast<TableViewItem*>(pFieldList->GetAt(pFieldList->GetCount() - 1));
3226                                 if (pItem != null)
3227                                 {
3228                                         EditField* pInputField = static_cast<EditField*>(pItem->GetControl(0));
3229
3230                                         if (pInputField != null && pInputField->GetTextLength() != 0)
3231                                         {
3232                                                 __pTableView->RefreshItem(groupIndex, itemCount, TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
3233                                         }
3234                                 }
3235                         }
3236                 }
3237         }
3238         if(__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) <= 1 && __isDefaultPhoneNumberButtonEnabled == true)
3239         {
3240                 __isDefaultPhoneNumberButtonEnabled = false;
3241                 __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex) - 1, TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE);
3242         }
3243         else if(__pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER) > 1 && __isDefaultPhoneNumberButtonEnabled == false)
3244         {
3245                 __isDefaultPhoneNumberButtonEnabled = true;
3246                 __pTableView->RefreshItem(groupIndex, __pTableView->GetItemCountAt(groupIndex), TABLE_VIEW_REFRESH_TYPE_ITEM_ADD);
3247         }
3248 }
3249
3250 void
3251 ContactEditorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
3252 {
3253 }
3254
3255 result
3256 ContactEditorForm::ParseAppControlArgument(const Tizen::Base::String& argument, Tizen::Base::String& type, Tizen::Base::String& content)
3257 {
3258         result r = E_SUCCESS;
3259
3260         if (argument.IsEmpty() || argument.Contains(DELIMITER) == false)
3261         {
3262                 return E_FAILURE;
3263         }
3264
3265         int delimiterIndex;
3266
3267         argument.IndexOf(DELIMITER, 0, delimiterIndex);
3268         argument.SubString(0, delimiterIndex++, type);
3269         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get type", GetErrorMessage(r));
3270         argument.SubString(delimiterIndex, argument.GetLength() - delimiterIndex, content);
3271         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get type", GetErrorMessage(r));
3272
3273         return r;
3274 }
3275
3276 void
3277 ContactEditorForm::OnFocusGained(const Tizen::Ui::Control& source)
3278 {
3279         __pCurrentFocusedItem = source.GetParent();
3280
3281         if (__pCurrentFocusedItem == __pNameFieldItem)
3282         {
3283                 return;
3284         }
3285
3286         ArrayList* pFieldList = null;
3287         int groupIndex;
3288         int itemIndex;
3289
3290         const EditField* pEditField = static_cast<const EditField*>(&source);
3291         if (pEditField != null)
3292         {
3293                 int index;
3294
3295                 Integer::Decode(pEditField->GetName(), index);
3296                 groupIndex = (index & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
3297                 itemIndex = (index & TABLE_VIEW_ITEM_INDEX_MASK);
3298         }
3299
3300         switch (groupIndex)
3301         {
3302         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
3303                 {
3304                         pFieldList = __pPhoneNumberFieldItem;
3305                 }
3306                 break;
3307         case TABLE_VIEW_EMAIL_FIELD_INDEX:
3308                 {
3309                         pFieldList = __pEmailFieldItem;
3310                 }
3311                 break;
3312         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
3313                 {
3314                         pFieldList = __pAddressFieldItem;
3315                 }
3316                 break;
3317         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
3318                 {
3319                         pFieldList = __pImAddressFieldItem;
3320                 }
3321                 break;
3322         case TABLE_VIEW_URL_FIELD_INDEX:
3323                 {
3324                         pFieldList = __pUrlFieldItem;
3325                 }
3326                 break;
3327         default:
3328                 break;
3329         }
3330
3331         TryReturnVoid(pFieldList != null, "[E_FAILURE] Unable to get a input field.");
3332
3333         for (int i = pFieldList->GetCount() - 2; i >= 0; i--)
3334         {
3335                 TableViewItem* pTableViewItem = static_cast<TableViewItem*>(pFieldList->GetAt(i));
3336                 if (pTableViewItem != null)
3337                 {
3338                         EditField* pInputField = static_cast<EditField*>(pTableViewItem->GetControl(0));
3339                         if (i != itemIndex && pInputField != null && pInputField->GetTextLength() == 0)
3340                         {
3341                                 DeleteInputField(groupIndex, i);
3342                         }
3343                 }
3344         }
3345 }
3346
3347 void
3348 ContactEditorForm::OnFocusLost(const Tizen::Ui::Control& source)
3349 {
3350         if (__pCurrentFocusedItem == __pNameFieldItem)
3351         {
3352                 SaveNameFields();
3353         }
3354
3355         __pCurrentFocusedItem = null;
3356 }
3357
3358 void
3359 ContactEditorForm::ShowDefaultPhoneNumberContextMenu(const Tizen::Graphics::Point& position)
3360 {
3361         if (__pDefaultPhoneNumberContextMenu != null)
3362         {
3363                 delete __pDefaultPhoneNumberContextMenu;
3364                 __pDefaultPhoneNumberContextMenu = null;
3365         }
3366
3367         __pDefaultPhoneNumberContextMenu = new (std::nothrow) ContextMenu();
3368         __pDefaultPhoneNumberContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST);
3369         __pDefaultPhoneNumberContextMenu->AddActionEventListener(*this);
3370         __pDefaultPhoneNumberContextMenu->SetFocusable(true);
3371
3372         int count = __pPresentationModel->GetMultiValuesCount(DETAIL_PROPERTY_PHONE_NUMBER);
3373         int defaultPhoneNumberIndex = __pPresentationModel->GetDefaultNumberIndex();
3374
3375         for (int i = 0; i < count; i++)
3376         {
3377                 String phoneNumber(__pPresentationModel->GetValue(DETAIL_PROPERTY_PHONE_NUMBER, i));
3378
3379                 if (i != defaultPhoneNumberIndex)
3380                 {
3381                         phoneNumber.Insert(__pPresentationModel->GetType(DETAIL_PROPERTY_PHONE_NUMBER, i) + CHARACTER_SPACE, 0);
3382                         __pDefaultPhoneNumberContextMenu->AddItem(phoneNumber, i);
3383                 }
3384         }
3385
3386         if (__pDefaultPhoneNumberContextMenu->GetItemCount() > 0)
3387         {
3388                 __pDefaultPhoneNumberContextMenu->Show();
3389         }
3390 }
3391
3392 void
3393 ContactEditorForm::ShowMoreInformationContextMenu(const Tizen::Graphics::Point& position)
3394 {
3395         if (__pMoreInformationContextMenu != null)
3396         {
3397                 delete __pMoreInformationContextMenu;
3398                 __pMoreInformationContextMenu = null;
3399         }
3400
3401         __pMoreInformationContextMenu = new (std::nothrow) ContextMenu();
3402         __pMoreInformationContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST);
3403
3404         __pMoreInformationContextMenu->SetMaxVisibleItemsCount(6);
3405         __pMoreInformationContextMenu->AddActionEventListener(*this);
3406         __pMoreInformationContextMenu->SetFocusable(true);
3407
3408         if (__isJobTitleEnabled == false)
3409         {
3410                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_JOB_TITLE"), IDA_CONTEXT_MENU_ITEM_JOB_TITLE);
3411         }
3412
3413         if (__isDepartmentEnabled == false)
3414         {
3415                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_DEPARTMENT"), IDA_CONTEXT_MENU_ITEM_DEPARTMENT);
3416         }
3417
3418         if (__pImAddressFieldItem->GetCount() == 0)
3419         {
3420                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_HEADER_INSTANT_MESSENGER_ABB"), IDA_CONTEXT_MENU_ITEM_INSTANT_MESSENGER);
3421         }
3422
3423         if (__pUrlFieldItem->GetCount() == 0)
3424         {
3425                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_URL"), IDA_CONTEXT_MENU_ITEM_URL);
3426         }
3427
3428         DateTime birthday;
3429         if (__pPresentationModel->GetBirthday(birthday) != E_SUCCESS)
3430         {
3431                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_BIRTHDAY"), IDA_CONTEXT_MENU_ITEM_BIRTHDAY);
3432         }
3433
3434         if (__pNoteFieldItem == null)
3435         {
3436                 __pMoreInformationContextMenu->AddItem(ResourceManager::GetString(L"IDS_PB_BODY_NOTE"), IDA_CONTEXT_MENU_ITEM_NOTE);
3437         }
3438
3439         if (__isMoreInformationContextMenuShowing == false)
3440         {
3441                 __pMoreInformationContextMenu->Show();
3442         }
3443
3444         SetFocus();
3445 }
3446
3447 void
3448 ContactEditorForm::ShowTypeContextMenu(int currentType, const Tizen::Graphics::Point& position, int itemTag)
3449 {
3450         int groupIndex = (itemTag & TABLE_VIEW_GROUP_INDEX_MASK) >> TABLE_VIEW_GROUP_INDEX_SHIFT;
3451
3452         __groupIndex = groupIndex;
3453         __itemIndex = itemTag;
3454
3455         if (__isKeypadOpened)
3456         {
3457                 __isTypeContextMenuShowing = true;
3458         }
3459
3460         if (__pTypeContextMenu != null)
3461         {
3462                 delete __pTypeContextMenu;
3463                 __pTypeContextMenu = null;
3464         }
3465
3466         __pTypeContextMenu = new (std::nothrow) ContextMenu();
3467         __pTypeContextMenu->Construct(position, CONTEXT_MENU_STYLE_LIST, CONTEXT_MENU_ANCHOR_DIRECTION_LEFTWARD);
3468         __pTypeContextMenu->AddActionEventListener(*this);
3469         __pTypeContextMenu->SetFocusable(true);
3470
3471         switch (groupIndex)
3472         {
3473         case TABLE_VIEW_PHONE_NUMBER_FIELD_INDEX:
3474                 {
3475                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_PHONENUMBER_TYPE_OTHER + 1);
3476                         for (int i = 0; i <= DETAIL_PHONENUMBER_TYPE_OTHER; i++)
3477                         {
3478                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3479                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetPhoneNumberTypeString((DetailPhoneNumberType)i), itemTag | index);
3480                         }
3481                 }
3482                 break;
3483         case TABLE_VIEW_EMAIL_FIELD_INDEX:
3484                 {
3485                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_EMAIL_TYPE_OTHER + 1);
3486                         for (int i = 0; i <= DETAIL_EMAIL_TYPE_OTHER; i++)
3487                         {
3488                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3489                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetAddressTypeString((DetailAddressType)i), itemTag | index);
3490                         }
3491                 }
3492                 break;
3493         case TABLE_VIEW_ADDRESS_FIELD_INDEX:
3494                 {
3495                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_ADDRESS_TYPE_OTHER + 1);
3496                         for (int i = 0; i <= DETAIL_ADDRESS_TYPE_OTHER; i++)
3497                         {
3498                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3499                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetAddressTypeString((DetailAddressType)i), itemTag | index);
3500                         }
3501                 }
3502                 break;
3503         case TABLE_VIEW_IM_ADDRESS_FIELD_INDEX:
3504                 {
3505                         __pTypeContextMenu->SetMaxVisibleItemsCount(7); // Temporary the code due to limit max count(8) by UI framework.
3506                         for (int i = 0; i <= DETAIL_IM_ADDRESS_TYPE_OTHER; i++)
3507                         {
3508                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3509                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetImAddressTypeString((DetailImAddressType)i), itemTag | index);
3510                         }
3511                 }
3512                 break;
3513         case TABLE_VIEW_URL_FIELD_INDEX:
3514                 {
3515                         __pTypeContextMenu->SetMaxVisibleItemsCount(DETAIL_URL_TYPE_OTHER + 1);
3516                         for (int i = 0; i <= DETAIL_URL_TYPE_OTHER; i++)
3517                         {
3518                                 int index = i << TABLE_VIEW_INPUT_FIELD_INDEX_SHIFT;
3519                                 __pTypeContextMenu->AddItem(__pPresentationModel->GetUrlTypeString((DetailUrlType)i), itemTag | index);
3520                         }
3521                 }
3522                 break;
3523         default:
3524                 {
3525                         __isTypeContextMenuShowing = false;
3526                         __groupIndex = -1;
3527                         __itemIndex = -1;
3528                         delete __pTypeContextMenu;
3529                         __pTypeContextMenu = null;
3530                 }
3531                 break;
3532         }
3533
3534         if (__pTypeContextMenu != null)
3535         {
3536                 __pTypeContextMenu->RemoveItemAt(currentType);
3537                 __pTypeContextMenu->Show();
3538         }
3539 }
3540
3541 void
3542 ContactEditorForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3543 {
3544         __isScrollOccurred = false;
3545 }
3546
3547 void
3548 ContactEditorForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3549 {
3550         if (__isScrollOccurred || source.Contains(currentPosition) == false)
3551         {
3552                 return;
3553         }
3554 }
3555
3556 void
3557 ContactEditorForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3558 {
3559 }
3560
3561 void
3562 ContactEditorForm::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3563 {
3564 }
3565
3566 void
3567 ContactEditorForm::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3568 {
3569 }
3570
3571 void
3572 ContactEditorForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
3573 {
3574 }
3575
3576 void
3577 ContactEditorForm::OnScrollEndReached (Tizen::Ui::Control &source, Tizen::Ui::Controls::ScrollEndEvent type)
3578 {
3579 }
3580
3581 void
3582 ContactEditorForm::OnScrollPositionChanged (Tizen::Ui::Control &source, int scrollPos)
3583 {
3584         int scrollDif = scrollPos - __scrolledDistance;
3585         if (__isTypeContextMenuShowing)
3586         {
3587                 Point anchorPosition = __pTypeContextMenu->GetAnchorPosition();
3588
3589                 anchorPosition.y -= scrollDif;
3590                 __pTypeContextMenu->SetAnchorPosition(anchorPosition);
3591                 __pTypeContextMenu->Show();
3592
3593                 __isTypeContextMenuShowing = false;
3594                 __groupIndex = -1;
3595                 __itemIndex = -1;
3596         }
3597
3598         __scrolledDistance = scrollPos;
3599
3600         if (__isScrollOccurred == false)
3601         {
3602                 __isScrollOccurred = true;
3603         }
3604 }
3605
3606 void
3607 ContactEditorForm::OnScrollStopped (Tizen::Ui::Control &source)
3608 {
3609 }
3610
3611 void
3612 ContactEditorForm::OnExpandableEditAreaLineAdded (Tizen::Ui::Controls::ExpandableEditArea &source, int newLineCount)
3613 {
3614         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3615 }
3616
3617 void
3618 ContactEditorForm::OnExpandableEditAreaLineRemoved (Tizen::Ui::Controls::ExpandableEditArea &source, int newLineCount)
3619 {
3620         __pTableView->RefreshItem(TABLE_VIEW_NOTE_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3621 }
3622
3623 void
3624 ContactEditorForm::OnDateChanged(const Tizen::Ui::Control& source, int year, int month, int day)
3625 {
3626         DateTime changedDate;
3627
3628         changedDate.SetValue(year, month, day);
3629         __pPresentationModel->SetBirthday(changedDate);
3630         __isContactModified = true;
3631 }
3632
3633 void
3634 ContactEditorForm::OnDateChangeCanceled(const Tizen::Ui::Control& source)
3635 {
3636 }
3637
3638 void
3639 ContactEditorForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
3640 {
3641         AppLogDebug("ENTER");
3642
3643         if (__pAppControl != null)
3644         {
3645                 delete __pAppControl;
3646                 __pAppControl = null;
3647         }
3648
3649         TryReturnVoid(appControlResult == APP_CTRL_RESULT_SUCCEEDED, "[E_FAILURE] The result of an appcontrol is not succeeded.");
3650         TryReturnVoid(pExtraData != null, "[E_FAILURE] The extra data is null.");
3651
3652         const String *pResultString = null;
3653         const ArrayList* pResultList = dynamic_cast<const ArrayList*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
3654         if (pResultList != null)
3655         {
3656                 pResultString = static_cast<const String*>(pResultList->GetAt(0));
3657         }
3658         else
3659         {
3660                 pResultString = static_cast<const String*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
3661         }
3662         TryReturnVoid(pResultString != null, "[E_FAILURE] Unable to get file path.");
3663
3664         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
3665         {
3666                 __pPresentationModel->SetThumbnail(*pResultString);
3667                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3668
3669                 if (__pFileEventManager == null)
3670                 {
3671                         __pFileEventManager = new (std::nothrow) FileEventManager();
3672                         __pFileEventManager->Construct(*this);
3673                 }
3674                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
3675         }
3676         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
3677         {
3678                 int width = 0;
3679                 int height = 0;
3680                 ImageFormat imageFormat;
3681                 result r = ImageBuffer::GetImageInfo(*pResultString, imageFormat, width, height);
3682
3683                 if (r != E_SUCCESS)
3684                 {
3685                         int modalResult = 0;
3686                         MessageBox unsupportedMessageBox;
3687                         unsupportedMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_MP_POP_INVALID_FILE"), MSGBOX_STYLE_NONE, 3000);
3688                         unsupportedMessageBox.ShowAndWait(modalResult);
3689
3690                         return;
3691                 }
3692
3693                 __pPresentationModel->SetThumbnail(*pResultString);
3694                 __isContactModified = true;
3695                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3696
3697                 if (__pFileEventManager == null)
3698                 {
3699                         __pFileEventManager = new (std::nothrow) FileEventManager();
3700                         __pFileEventManager->Construct(*this);
3701                 }
3702                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
3703         }
3704         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
3705         {
3706                 __pPresentationModel->SetValue(DETAIL_PROPERTY_RINGTONE, *pResultString);
3707                 __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3708
3709                 if (__pFileEventManager == null)
3710                 {
3711                         __pFileEventManager = new (std::nothrow) FileEventManager();
3712                         __pFileEventManager->Construct(*this);
3713                 }
3714                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
3715
3716                 __isContactModified = true;
3717         }
3718
3719         AppLogDebug("EXIT");
3720 }
3721
3722 result
3723 ContactEditorForm::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId)
3724 {
3725         result r = E_SUCCESS;
3726
3727         String uri;
3728         String mimeType;
3729         HashMap extraData;
3730         extraData.Construct();
3731
3732         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
3733         {
3734                 mimeType.Append(INPUT_MIME_TYPE_CAMERA);
3735                 extraData.Add(new (std::nothrow) String(INPUT_KEY_ALLOW_SWITCH), new (std::nothrow) String(INPUT_VALUE_FALSE));
3736         }
3737         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
3738         {
3739                 mimeType.Append(INPUT_MIME_TYPE_GALLERY);
3740                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
3741         }
3742         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
3743         {
3744                 mimeType.Append(INPUT_MIME_TYPE_AUDIO);
3745                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
3746         }
3747
3748         __pAppControl = AppManager::FindAppControlN(appId, operationId);
3749
3750         if (__pAppControl != null)
3751         {
3752                 r = __pAppControl->Start(&uri, &mimeType, &extraData, this);
3753                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control.", GetErrorMessage(r));
3754
3755                 SetEnabled(false);
3756                 Invalidate(true);
3757         }
3758         extraData.RemoveAll(true);
3759
3760         return r;
3761
3762 CATCH:
3763         extraData.RemoveAll(true);
3764         delete __pAppControl;
3765         __pAppControl = null;
3766
3767         return r;
3768 }
3769
3770 void
3771 ContactEditorForm::OnContactsChanged(void)
3772 {
3773         SceneManager* pSceneManager = SceneManager::GetInstance();
3774         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
3775
3776         if (__isSaved == false)
3777         {
3778                 if (__pPresentationModel->IsContactRemoved())
3779                 {
3780                         if (pContactsApp->GetOperationId() == OPERATION_ID_VIEW)
3781                         {
3782                                 __pPresentationModel->RemoveContactChangeListener(*this);
3783                         }
3784                         else
3785                         {
3786                                 if (__pAppControl != null)
3787                                 {
3788                                         __pAppControl->Stop();
3789                                 }
3790                                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
3791                         }
3792                 }
3793
3794                 return;
3795         }
3796
3797         SetFocus();
3798
3799         if (__isAppControl)
3800         {
3801                 AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
3802                 HashMap* pReturnValue = new (std::nothrow) HashMap();
3803                 pReturnValue->Construct();
3804
3805                 pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), new (std::nothrow) String(Integer::ToString(__pPresentationModel->GetContactId())));
3806
3807                 result r = pAppManager->SendAppControlResult(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
3808                 AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
3809
3810                 UiApp::GetInstance()->Terminate();
3811         }
3812         else
3813         {
3814                 ArrayList* pArg = null;
3815
3816                 if (__pPresentationModel->GetVcfPath().IsEmpty() == false)
3817                 {
3818                         pArg = new (std::nothrow) ArrayList();
3819                         pArg->Construct();
3820
3821                         String* pViewType = new (std::nothrow) String();
3822                         String* pValueType = new (std::nothrow) String();
3823
3824                         pViewType->Append(VIEW_TYPE);
3825                         pViewType->Append(DELIMITER);
3826                         pViewType->Append(VIEW_TYPE_VALUE_CONTACT);
3827
3828                         pValueType->Append(VIEW_TYPE_CONTACT_ID);
3829                         pValueType->Append(DELIMITER);
3830                         pValueType->Append(Integer::ToString(__pPresentationModel->GetContactId()));
3831
3832                         pArg->Add(pViewType);
3833                         pArg->Add(pValueType);
3834                 }
3835                 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArg);
3836         }
3837
3838         __isSaved = false;
3839 }
3840
3841 void
3842 ContactEditorForm::OnCategoriesChanged(void)
3843 {
3844 }
3845
3846 void
3847 ContactEditorForm::OnForeground(void)
3848 {
3849 }
3850
3851 void
3852 ContactEditorForm::OnBackground(void)
3853 {
3854         if (IsEnabled() == false)
3855         {
3856                 SetEnabled(true);
3857                 Invalidate(true);
3858         }
3859 }
3860
3861 void
3862 ContactEditorForm::OnFileEventOccured(const unsigned long events, const Tizen::Base::String &path, const unsigned int eventId)
3863 {
3864         String thumbnailPath = __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL);
3865         if (thumbnailPath.Equals(path, false) == true)
3866         {
3867                 __pPresentationModel->SetThumbnail(L"");
3868                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3869         }
3870         else
3871         {
3872                 String ringtonePath = __pPresentationModel->GetValue(DETAIL_PROPERTY_RINGTONE);
3873                 if (ringtonePath.Equals(ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT"), false) == true )
3874                 {
3875                         __pTableView->RefreshItem(TABLE_VIEW_GROUP_RINGTONE_FIELD_INDEX, 2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3876                 }
3877         }
3878 }
3879
3880 void
3881 ContactEditorForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
3882 {
3883         if (deviceType != DEVICE_TYPE_STORAGE_CARD || __pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL).IsEmpty())
3884         {
3885                 return;
3886         }
3887
3888         if (state.Equals(SD_CARD_UNMOUNTED, false) && File::IsFileExist(__pPresentationModel->GetValue(DETAIL_PROPERTY_THUMBNAIL)) == false)
3889         {
3890                 __pPresentationModel->SetThumbnail(L"");
3891                 __pTableView->RefreshItem(TABLE_VIEW_THUMBNAIL_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
3892         }
3893 }
3894
3895 bool ContactEditorForm::ValidateEmailAddress(const Tizen::Base::String& emailAddress)
3896 {
3897         int count = 0;
3898         int index = 0;
3899         const wchar_t* tmpChar;
3900         const wchar_t* tmpDomain;
3901         String splChars = L"([<@,;\\:\">])";
3902
3903         for (tmpChar = emailAddress.GetPointer(), index=0; index < emailAddress.GetLength(); tmpChar++, index++)
3904         {
3905                 if (*tmpChar == '\"' && (tmpChar == emailAddress.GetPointer() || *(tmpChar-1) == '.' || *(tmpChar-1) == '\"'))
3906                 {
3907                         while (*++tmpChar)
3908                         {
3909                                 if (*tmpChar == '\"')
3910                                 {
3911                                         break;
3912                                 }
3913                                 if (*tmpChar == '\\' && (*++tmpChar == ' '))
3914                                 {
3915                                         continue;
3916                                 }
3917                                 if (*tmpChar <= ' ' || *tmpChar >= 127)
3918                                 {
3919                                         return false;
3920                                 }
3921                         }
3922                         if (!*tmpChar++)
3923                         {
3924                                 return false;
3925                         }
3926                         if (*tmpChar == '@')
3927                         {
3928                                 break;
3929                         }
3930                         if (*tmpChar != '.')
3931                         {
3932                                 return false;
3933                         }
3934                         continue;
3935                 }
3936                 if (*tmpChar == '@')
3937                 {
3938                         break;
3939                 }
3940                 if (*tmpChar <= ' ' || *tmpChar >= 127)
3941                 {
3942                         return false;
3943                 }
3944                 if (splChars.IndexOf(*tmpChar, 0, index) != E_OBJ_NOT_FOUND)
3945                 {
3946                         return false;
3947                 }
3948         }
3949         if (tmpChar == emailAddress.GetPointer() || *(tmpChar-1) == '.')
3950         {
3951                 return false;
3952         }
3953
3954         if (!*(tmpDomain = ++tmpChar))
3955         {
3956                 return false;
3957         }
3958         do
3959         {
3960                 if (*tmpChar == '.')
3961                 {
3962                         if (tmpChar == tmpDomain || *(tmpChar-1) == '.')
3963                         {
3964                                 return false;
3965                         }
3966                         count++;
3967                 }
3968                 if (*tmpChar <= ' ' || *tmpChar >= 127)
3969                 {
3970                         return false;
3971                 }
3972                 if (splChars.IndexOf(*tmpChar, 0, index) != E_OBJ_NOT_FOUND)
3973                 {
3974                         return false;
3975                 }
3976         } while (*++tmpChar);
3977
3978         if (*(tmpChar-1) == '.')
3979         {
3980                 return false;
3981         }
3982
3983         if (count >= 1)
3984         {
3985                 return true;
3986         }
3987
3988         return false;
3989 }
3990
3991 void
3992 ContactEditorForm::OnSettingChanged(Tizen::Base::String &key)
3993 {
3994         if(key == L"http://tizen.org/setting/locale.date_time")
3995         {
3996                 DateTime bday;
3997                 __pPresentationModel->GetBirthday(bday);
3998
3999                 DateTime currentDate;
4000                 Tizen::System::SystemTime::GetCurrentTime(currentDate);
4001
4002                 if(bday > currentDate)
4003                 {
4004                         __pPresentationModel->SetBirthday(currentDate);
4005                         __pTableView->RefreshItem(TABLE_VIEW_BIRTHDAY_FIELD_INDEX, 0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
4006                 }
4007         }
4008 }
4009
4010 bool
4011 ContactEditorForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
4012 {
4013         return false;
4014 }
4015
4016 bool
4017 ContactEditorForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
4018 {
4019         if (keyEventInfo.GetKeyCode() == KEY_BACK)
4020         {
4021                 if (__pSaveContactPopup && __pSaveContactPopup->GetShowState() == true)
4022                 {
4023                         HideSaveContactPopup();
4024                         return true;
4025                 }
4026         }
4027         return false;
4028 }
4029
4030 bool
4031 ContactEditorForm::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
4032 {
4033         return false;
4034 }
4035
4036 bool
4037 ContactEditorForm::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
4038 {
4039         return false;
4040 }
4041
4042 void
4043 ContactEditorForm::ShowSaveContactPopup(void)
4044 {
4045         if (__pSaveContactPopup == null)
4046         {
4047                 __pSaveContactPopup = new (std::nothrow) Popup();
4048                 __pSaveContactPopup->Construct(false, Dimension(W_SAVE_CONTACT_POPUP, H_SAVE_CONTACT_POPUP));
4049                 __pSaveContactPopup->SetPropagatedKeyEventListener(this);
4050
4051                 Rectangle popupClientBounds = __pSaveContactPopup->GetClientAreaBounds();
4052
4053                 Label* pLabel = new (std::nothrow) Label();
4054                 pLabel->Construct(Rectangle(X_SAVE_CONTACT_LABEL, Y_SAVE_CONTACT_LABEL, W_SAVE_CONTACT_LABEL, H_SAVE_CONTACT_LABEL), ResourceManager::GetString(L"IDS_PB_POP_SAVE_CONTACT_Q"));
4055                 pLabel->SetTextConfig(FONT_SIZE_SAVE_CONTACT_CONFIRM, LABEL_TEXT_STYLE_NORMAL);
4056                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
4057                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
4058
4059                 Button* pSaveButton = new (std::nothrow) Button();
4060                 pSaveButton->Construct(Rectangle(X_SAVE_CONTACT_LABEL, Y_SAVE_CONTACT_BUTTON, W_SAVE_CONTACT_BUTTON, H_SAVE_CONTACT_BUTTON), ResourceManager::GetString(L"IDS_COM_SK_SAVE"));
4061                 pSaveButton->SetTextSize(FONT_SIZE_SAVE_CONTACT_BUTTON);
4062                 pSaveButton->SetActionId(IDA_POPUP_SAVE_CONTACT_OK);
4063                 pSaveButton->AddActionEventListener(*this);
4064
4065                 Button* pCancelButton = new (std::nothrow) Button();
4066                 pCancelButton->Construct(Rectangle(X_SAVE_CONTACT_LABEL + W_SAVE_CONTACT_BUTTON + W_POPUP_ITEM_GAP, Y_SAVE_CONTACT_BUTTON, W_SAVE_CONTACT_BUTTON, H_SAVE_CONTACT_BUTTON), ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
4067                 pCancelButton->SetTextSize(FONT_SIZE_SAVE_CONTACT_BUTTON);
4068                 pCancelButton->SetActionId(IDA_POPUP_SAVE_CONTACT_CANCEL);
4069                 pCancelButton->AddActionEventListener(*this);
4070
4071                 __pSaveContactPopup->AddControl(pLabel);
4072                 __pSaveContactPopup->AddControl(pSaveButton);
4073                 __pSaveContactPopup->AddControl(pCancelButton);
4074         }
4075
4076         __pSaveContactPopup->SetShowState(true);
4077         __pSaveContactPopup->Show();
4078 }
4079
4080 void
4081 ContactEditorForm::HideSaveContactPopup(void)
4082 {
4083         __pSaveContactPopup->SetShowState(false);
4084         Invalidate(true);
4085 }