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