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