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