NABI_Issue Fix 53297 53607 53635 53606 53534
[apps/osp/Contacts.git] / src / CtGroupEditorForm.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        CtGroupEditorForm.cpp
19  * @brief       This is the implementation file for the GroupEditorForm class.
20  */
21
22 #include <FApp.h>
23 #include <FMedia.h>
24 #include "CtContactsApp.h"
25 #include "CtGroupEditorForm.h"
26 #include "CtGroupPresentationModel.h"
27 #include "CtResourceManager.h"
28 #include "CtSceneRegister.h"
29 #include "CtTypes.h"
30 #include "CtCommonUtil.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Io;
37 using namespace Tizen::Media;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40 using namespace Tizen::Ui::Scenes;
41 using namespace Tizen::Social;
42 using namespace Tizen::System;
43
44 static const int IDA_HEADER_SAVE = 0;
45 static const int IDA_BUTTON_GALLERY = 10;
46 static const int IDA_BUTTON_TAKE_PHOTO = 11;
47 static const int IDA_BUTTON_REMOVE = 12;
48 static const int IDA_BUTTON_RINGTONE_CLEAR = 13;
49 static const int IDA_POPUP_DISCARD_CHANGES_OK = 20;
50 static const int IDA_POPUP_DISCARD_CHANGES_CANCEL = 21;
51
52 static const wchar_t* IDB_ICON_ADD_NORMAL = L"C02_caller_id_icon_add.png";
53 static const wchar_t* IDB_ICON_ADD_PRESSED = L"C02_caller_id_icon_add_press.png";
54 static const wchar_t* IDB_ICON_CAMERA_NORMAL = L"C02_caller_id_icon_camera.png";
55 static const wchar_t* IDB_ICON_CAMERA_PRESSED = L"C02_caller_id_icon_camera_press.png";
56 static const wchar_t* IDB_ICON_REMOVE_NORMAL = L"00_button_expand_minus_press.png";
57 static const wchar_t* IDB_ICON_REMOVE_PRESSED = L"00_button_expand_minus_press.png";
58 static const wchar_t* IDB_REMOVE_BG_NORMAL = L"00_circle_button_delete.png";
59 static const wchar_t* IDB_REMOVE_BG_PRESSED = L"00_circle_button_delete_press.png";
60 static const wchar_t* IDB_DETAILS_RESET_NORMAL = L"00_button_refresh.png";
61 static const wchar_t* IDB_DETAILS_RESET_PRESSED = L"00_button_refresh_press.png";
62
63 static const int H_ITEM = 128;
64 static const int H_THUMBNAIL = 360;
65 static const int Y_THUMBNAIL = 49;
66 static const int H_ICON_BUTTON = 74;
67 static const int Y_REMOVE_BUTTON = 26;
68 static const int X_REMOVE_BUTTON_MARGIN = 40;
69 static const int X_REFRESH_BUTTON_MARGIN = 88;
70
71 static const int X_RINGTONE_TEXT = 3;
72 static const int Y_RINGTONE_TITLE = 10;
73 static const int Y_RINGTONE_NAME = 68;
74 static const int W_RINGTONE_TEXT = 600;
75 static const int H_RINGTONE_TITLE = 58;
76 static const int H_RINGTONE_NAME = 60;
77
78 static const int X_GROUP_TEXT_GAP = 5;
79 static const int H_GROUP_TEXT_GAP = 10;
80
81 static const unsigned int COLOR_GUIDE_TEXT = Color32<255, 0, 0>::Value;
82 static const unsigned int COLOR_RINGTONE_TITLE = Color32<128, 128, 128>::Value;
83 static const unsigned int COLOR_THUMBNAIL = Color32<239, 237, 229>::Value;
84 static const unsigned int COLOR_TABLE_BG = Color32<248, 246, 239>::Value;
85 static const unsigned int COLOR_ITEM_TITLE = Color32<128, 128, 128>::Value;
86 static const unsigned int COLOR_ITEM_VALUE = Color32<0, 0, 0>::Value;
87 static const unsigned int COLOR_ITEM_PRESSED = Color32<248, 246, 239>::Value;
88 static const unsigned int COLOR_PRESSED = Color32<87, 135, 194>::Value;
89
90 static const int ITEM_COUNT = 3;
91
92 static const int FONT_SIZE_RINGTONE_TITLE = 32;
93
94 static const wchar_t* INPUT_DATA_SELECTION_MODE_SINGLE = L"single";
95 static const wchar_t* INPUT_KEY_SELECTION_MODE = L"http://tizen.org/appcontrol/data/selection_mode";
96 static const wchar_t* INPUT_KEY_IMAGEVIEWER_MODE = L"http://tizen.org/appcontrol/data/image/crop_mode";
97 static const wchar_t* INPUT_KEY_ALLOW_SWITCH = L"http://tizen.org/appcontrol/data/camera/allow_switch";
98 static const wchar_t* INPUT_MIME_TYPE_CAMERA = L"image/jpg";
99 static const wchar_t* INPUT_MIME_TYPE_GALLERY = L"image/*";
100 static const wchar_t* INPUT_MIME_TYPE_AUDIO = L"audio/*";
101 static const wchar_t* INPUT_VALUE_FALSE = L"false";
102 static const wchar_t* INPUT_VALUE_IMAGEVIEWER_TYPE = L"fit_to_screen";
103 static const wchar_t* OUTPUT_KEY_SELECTED = L"http://tizen.org/appcontrol/data/selected";
104 static const wchar_t* THUMBNAIL_LABEL = L"thumbnail";
105 static const wchar_t* THUMBNAIL_EMPTY_LABEL = L"emptyThumbnail";
106 static const wchar_t* ADD_BUTTON = L"add";
107 static const wchar_t* CAMERA_BUTTON = L"camera";
108 static const wchar_t* REMOVE_BUTTON = L"remove";
109 static const wchar_t* SD_CARD_UNMOUNTED = L"Unmounted";
110
111 static const wchar_t* GROUP_EDITOR_LABEL_TITLE = L"GroupLabelTitle";
112 static const wchar_t* GROUP_EDITOR_LABEL_VALUE = L"GroupLabelValue";
113 static const wchar_t* GROUP_EDITOR_STYLE_PANEL = L"GroupStylePanel";
114
115 GroupEditorForm::GroupEditorForm(void)
116  : __pPresentationModel(null)
117  , __pTableView(null)
118  , __pFileEventManager(null)
119  , __isEditMode(false)
120  , __isSaved(false)
121  , __isGroupsChanged(false)
122  , __pDiscardChangesPopup(null)
123 {
124 }
125
126 GroupEditorForm::~GroupEditorForm(void)
127 {
128 }
129
130 void
131 GroupEditorForm::Initialize(void)
132 {
133         Construct(L"IDL_GROUP_EDITOR_FORM");
134 }
135
136 result
137 GroupEditorForm::OnInitializing(void)
138 {
139         Footer* pFooter = GetFooter();
140         pFooter->AddActionEventListener(*this);
141         SetFormBackEventListener(this);
142         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
143
144         __pTableView = new (std::nothrow) TableView();
145         __pTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
146         __pTableView->SetItemProvider(this);
147         __pTableView->AddTableViewItemEventListener(*this);
148         AddControl(__pTableView);
149
150         return E_SUCCESS;
151 }
152
153 result
154 GroupEditorForm::OnTerminating(void)
155 {
156         __pTableView->SetItemProvider(null);
157
158         delete __pPresentationModel;
159         delete __pFileEventManager;
160
161         if (__pDiscardChangesPopup != null)
162         {
163                 delete __pDiscardChangesPopup;
164         }
165
166         DeviceManager::RemoveDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
167
168         return E_SUCCESS;
169 }
170
171 void
172 GroupEditorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
173 {
174         SceneManager* pSceneManager = SceneManager::GetInstance();
175
176         SetFocus();
177
178         Footer* pFooter = GetFooter();
179         FooterItemStatus status;
180         pFooter->GetItemStatus(0, status);
181
182         if (status != FOOTER_ITEM_STATUS_DISABLED && __isGroupsChanged == true)
183         {
184                 ShowDiscardChangesPopup();
185                 return;
186         }
187
188         result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
189         TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
190 }
191
192 void
193 GroupEditorForm::ShowDiscardChangesPopup(void)
194 {
195         if (__pDiscardChangesPopup == null)
196         {
197                 __pDiscardChangesPopup = new (std::nothrow) Popup();
198                 __pDiscardChangesPopup->Construct(false, Dimension(W_SAVE_POPUP, H_SAVE_POPUP));
199                 __pDiscardChangesPopup->SetPropagatedKeyEventListener(this);
200
201                 Rectangle popupClientBounds = __pDiscardChangesPopup->GetClientAreaBounds();
202
203                 Label* pLabel = new (std::nothrow) Label();
204                 pLabel->Construct(Rectangle(X_SAVE_LABEL, Y_SAVE_LABEL, W_SAVE_LABEL, H_SAVE_LABEL), ResourceManager::GetString(L"IDS_PB_POP_DISCARD_CHANGES_Q"));
205                 pLabel->SetTextConfig(FONT_SIZE_SAVE_CONFIRM, LABEL_TEXT_STYLE_NORMAL);
206                 pLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
207                 pLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
208
209                 Button* pSaveButton = new (std::nothrow) Button();
210                 pSaveButton->Construct(Rectangle(X_SAVE_LABEL + W_SAVE_BUTTON + W_POPUP_ITEM_GAP, Y_SAVE_BUTTON, W_SAVE_BUTTON, H_SAVE_BUTTON), ResourceManager::GetString(L"IDS_COM_SK_OK"));
211                 pSaveButton->SetTextSize(FONT_SIZE_SAVE_BUTTON);
212                 pSaveButton->SetActionId(IDA_POPUP_DISCARD_CHANGES_OK);
213                 pSaveButton->AddActionEventListener(*this);
214
215                 Button* pCancelButton = new (std::nothrow) Button();
216                 pCancelButton->Construct(Rectangle(X_SAVE_LABEL, Y_SAVE_BUTTON, W_SAVE_BUTTON, H_SAVE_BUTTON), ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
217                 pCancelButton->SetTextSize(FONT_SIZE_SAVE_BUTTON);
218                 pCancelButton->SetActionId(IDA_POPUP_DISCARD_CHANGES_CANCEL);
219                 pCancelButton->AddActionEventListener(*this);
220
221                 __pDiscardChangesPopup->AddControl(pLabel);
222                 __pDiscardChangesPopup->AddControl(pSaveButton);
223                 __pDiscardChangesPopup->AddControl(pCancelButton);
224         }
225
226         __pDiscardChangesPopup->SetShowState(true);
227         __pDiscardChangesPopup->Show();
228 }
229
230 void
231 GroupEditorForm::HideDiscardChangesPopup(void)
232 {
233         __pDiscardChangesPopup->SetShowState(false);
234         Invalidate(true);
235 }
236
237 void
238 GroupEditorForm::OnFileEventOccured(const unsigned long events, const Tizen::Base::String &path, const unsigned int eventId)
239 {
240         String thumbnailPath = __pPresentationModel->GetThumbnailPath();
241         if (thumbnailPath.Equals(path, false) == true)
242         {
243                 __pPresentationModel->SetThumbnailPath(String());
244                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
245                 __pTableView->RefreshItem(1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
246         }
247         else
248         {
249                 String ringtonePath = __pPresentationModel->GetRingtone();
250                 if (ringtonePath.Equals(path, false) == true )
251                 {
252                         __pPresentationModel->SetRingtone(String());
253                         __pTableView->RefreshItem(2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
254                 }
255         }
256 }
257
258 void
259 GroupEditorForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
260 {
261         if (deviceType != DEVICE_TYPE_STORAGE_CARD || __pPresentationModel->GetThumbnailPath().IsEmpty())
262         {
263                 return;
264         }
265
266         if (state.Equals(SD_CARD_UNMOUNTED, false) && File::IsFileExist(__pPresentationModel->GetThumbnailPath()) == false)
267         {
268                 __pPresentationModel->SetThumbnailPath(L"");
269                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
270         }
271 }
272
273
274 void
275 GroupEditorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
276 {
277         switch (actionId)
278         {
279         case IDA_HEADER_SAVE:
280                 {
281                         result r = E_SUCCESS;
282
283                         if (CommonUtil::isMemoryAvailable() == false)
284                         {
285                                 CommonUtil::showMemoryFullMessageBox();
286                                 return;
287                         }
288
289                         __pTableView->RefreshItem(1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
290
291                         if (__pPresentationModel->IsDefaultCategory() == false && __pPresentationModel->IsDuplicatedCategory() == true)
292                         {
293                                 Footer* pFooter = GetFooter();
294                                 pFooter->SetItemEnabled(0, false);
295                                 break;
296                         }
297
298                         if (__isEditMode)
299                         {
300                                 r = __pPresentationModel->UpdateCategory();
301                                 if (r == E_FAILURE)
302                                 {
303                                         __isSaved = true;
304                                         OnCategoriesChanged();
305                                 }
306                                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to update category", GetErrorMessage(r));
307                         }
308                         else
309                         {
310                                 r = __pPresentationModel->AddCategory();
311                                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to add category", GetErrorMessage(r));
312                         }
313
314                         SetFocus();
315                         __isSaved = true;
316                 }
317                 break;
318         case IDA_BUTTON_GALLERY:
319                 {
320                         LaunchAppControl(PROVIDER_ID_GALLERY, OPERATION_ID_PICK);
321                 }
322                 break;
323         case IDA_BUTTON_TAKE_PHOTO:
324                 {
325                         LaunchAppControl(PROVIDER_ID_CAMERA, OPERATION_ID_CREATE_CONTENT);
326                 }
327                 break;
328         case IDA_BUTTON_REMOVE:
329                 {
330                         __pPresentationModel->SetThumbnailPath(String());
331                         __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
332                         __pTableView->RefreshItem(1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
333
334                         if (__pFileEventManager != null)
335                         {
336                                 delete __pFileEventManager;
337                                 __pFileEventManager = null;
338                         }
339                 }
340                 break;
341         case IDA_BUTTON_RINGTONE_CLEAR:
342                 {
343                         __pPresentationModel->SetRingtone(String());
344                         __pTableView->RefreshItem(2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
345                 }
346                 break;
347         case IDA_POPUP_DISCARD_CHANGES_OK:
348                 {
349                         HideDiscardChangesPopup();
350                         SetFocus();
351
352                         SceneManager* pSceneManager = SceneManager::GetInstance();
353                         result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
354                         TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
355                 }
356                 break;
357         case IDA_POPUP_DISCARD_CHANGES_CANCEL:
358                 {
359                         HideDiscardChangesPopup();
360                 }
361                 break;
362         default:
363                 break;
364         }
365 }
366
367 void
368 GroupEditorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
369                                                                    const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
370 {
371         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
372         pContactsApp->AddContactsAppChangeEventListener(*this);
373
374         RecordId categoryId = INVALID_RECORD_ID;
375
376         if (pArgs != null)
377         {
378                 IEnumerator* pEnum = pArgs->GetEnumeratorN();
379                 if (pEnum->MoveNext() == E_SUCCESS)
380                 {
381                         Integer* pCategoryId = static_cast<Integer*>(pEnum->GetCurrent());
382                         if (pCategoryId != null)
383                         {
384                                 categoryId = pCategoryId->ToInt();
385                                 __isEditMode = true;
386                         }
387                 }
388                 delete pEnum;
389
390                 pArgs->RemoveAll(true);
391                 delete pArgs;
392         }
393
394         __pPresentationModel = new (std::nothrow) GroupPresentationModel();
395         __pPresentationModel->Construct(categoryId);
396         __pPresentationModel->AddContactChangeListener(*this);
397
398         Header* pHeader = GetHeader();
399         if (__isEditMode)
400         {
401                 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_PB_OPT2_EDIT_GROUPS"));
402         }
403         else
404         {
405                 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
406         }
407
408         Footer* pFooter = GetFooter();
409         if (__isEditMode)
410         {
411                 pFooter->SetItemEnabled(0, true);
412         }
413         else
414         {
415                 pFooter->SetItemEnabled(0, false);
416         }
417
418 }
419
420 void
421 GroupEditorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
422                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
423 {
424         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
425         pContactsApp->RemoveContactsAppChangeEventListener(*this);
426
427         __pPresentationModel->RemoveContactChangeListener(*this);
428 }
429
430 int
431 GroupEditorForm::GetItemCount(void)
432 {
433         return ITEM_COUNT;
434 }
435
436 Tizen::Ui::Controls::TableViewItem*
437 GroupEditorForm::CreateItem(int itemIndex, int itemWidth)
438 {
439         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
440
441         Label* pSubjectLabel = null;
442         Label* pContentLabel = null;
443         int itemHeight = H_ITEM + pContactsApp->GetFontHeightOffset();
444
445         if (itemIndex == 0)
446         {
447                 itemHeight = Y_THUMBNAIL * 2 + H_THUMBNAIL;
448         }
449
450         TableViewItem* pItem = new (std::nothrow) TableViewItem();
451         pItem->Construct(Dimension(itemWidth, itemHeight), TABLE_VIEW_ANNEX_STYLE_NORMAL);
452
453         if (itemIndex == 0)
454         {
455                 Label* pThumbnailLabel = new (std::nothrow) Label();
456                 pThumbnailLabel->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2, Y_THUMBNAIL, H_THUMBNAIL, H_THUMBNAIL), L"");
457                 pThumbnailLabel->SetName(THUMBNAIL_LABEL);
458                 pItem->AddControl(pThumbnailLabel);
459                 Label* pEmptyThumbnailLabel = new (std::nothrow) Label();
460                 pEmptyThumbnailLabel->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2, Y_THUMBNAIL, H_THUMBNAIL, H_THUMBNAIL), L"");
461                 pEmptyThumbnailLabel->SetName(THUMBNAIL_EMPTY_LABEL);
462                 pEmptyThumbnailLabel->SetBackgroundColor(COLOR_THUMBNAIL);
463                 pItem->AddControl(pEmptyThumbnailLabel);
464
465                 if (__pPresentationModel->GetThumbnailPath().IsEmpty() == false)
466                 {
467                         Bitmap* pThumbnail = null;
468                         ImageBuffer thumbnailImageBuffer;
469                         result r = thumbnailImageBuffer.Construct(__pPresentationModel->GetThumbnailPath());
470                         if (r == E_SUCCESS)
471                         {
472                                 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_NONE);
473                         }
474                         pThumbnailLabel->SetBackgroundBitmap(*pThumbnail);
475                         delete pThumbnail;
476
477                         pEmptyThumbnailLabel->SetShowState(false);
478                 }
479
480                 Button* pButtonAdd = new (std::nothrow) Button();
481                 pButtonAdd->Construct(Rectangle((itemWidth - H_ICON_BUTTON) / 2, (H_THUMBNAIL - H_ICON_BUTTON) / 2 + Y_THUMBNAIL, H_ICON_BUTTON, H_ICON_BUTTON), L"");
482                 pButtonAdd->SetActionId(IDA_BUTTON_GALLERY);
483                 pButtonAdd->AddActionEventListener(*this);
484                 pButtonAdd->SetName(ADD_BUTTON);
485                 Bitmap* pIconNormal = ResourceManager::GetBitmapN(IDB_ICON_ADD_NORMAL);
486                 Bitmap* pIconPressed = ResourceManager::GetBitmapN(IDB_ICON_ADD_PRESSED);
487                 if (pIconNormal != null)
488                 {
489                         pButtonAdd->SetNormalBackgroundBitmap(*pIconNormal);
490                         delete pIconNormal;
491                 }
492                 if (pIconPressed != null)
493                 {
494                         pButtonAdd->SetPressedBackgroundBitmap(*pIconPressed);
495                         delete pIconPressed;
496                 }
497                 pItem->AddControl(pButtonAdd);
498                 pItem->SetIndividualSelectionEnabled(pButtonAdd, true);
499
500                 Button* pButtonCamera = new (std::nothrow) Button();
501                 pButtonCamera->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2 + H_THUMBNAIL, Y_THUMBNAIL + H_THUMBNAIL - H_ICON_BUTTON, H_ICON_BUTTON, H_ICON_BUTTON), L"");
502                 pButtonCamera->SetActionId(IDA_BUTTON_TAKE_PHOTO);
503                 pButtonCamera->AddActionEventListener(*this);
504                 pButtonCamera->SetName(CAMERA_BUTTON);
505                 pIconNormal = ResourceManager::GetBitmapN(IDB_ICON_CAMERA_NORMAL);
506                 pIconPressed = ResourceManager::GetBitmapN(IDB_ICON_CAMERA_PRESSED);
507                 if (pIconNormal != null)
508                 {
509                         pButtonCamera->SetNormalBackgroundBitmap(*pIconNormal);
510                         delete pIconNormal;
511                 }
512                 if (pIconPressed != null)
513                 {
514                         pButtonCamera->SetPressedBackgroundBitmap(*pIconPressed);
515                         delete pIconPressed;
516                 }
517                 pItem->AddControl(pButtonCamera);
518                 pItem->SetIndividualSelectionEnabled(pButtonCamera, true);
519
520                 Button* pButtonRemove = new (std::nothrow) Button();
521                 pButtonRemove->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2 - X_REMOVE_BUTTON_MARGIN, Y_REMOVE_BUTTON, H_ICON_BUTTON, H_ICON_BUTTON), L"");
522                 pButtonRemove->SetActionId(IDA_BUTTON_REMOVE);
523                 pButtonRemove->AddActionEventListener(*this);
524                 pButtonRemove->SetName(REMOVE_BUTTON);
525                 pIconNormal = ResourceManager::GetBitmapN(IDB_ICON_REMOVE_NORMAL);
526                 pIconPressed = ResourceManager::GetBitmapN(IDB_ICON_REMOVE_PRESSED);
527                 if (pIconNormal != null)
528                 {
529                         pButtonRemove->SetNormalBitmap(Point(0, 0), *pIconNormal);
530                         delete pIconNormal;
531                 }
532                 if (pIconPressed != null)
533                 {
534                         pButtonRemove->SetPressedBitmap(Point(0, 0), *pIconPressed);
535                         delete pIconPressed;
536                 }
537
538                 pIconNormal = ResourceManager::GetBitmapN(IDB_REMOVE_BG_NORMAL);
539                 pIconPressed = ResourceManager::GetBitmapN(IDB_REMOVE_BG_PRESSED);
540                 if (pIconNormal != null)
541                 {
542                         pButtonRemove->SetNormalBackgroundBitmap(*pIconNormal);
543                         delete pIconNormal;
544                 }
545                 if (pIconPressed != null)
546                 {
547                         pButtonRemove->SetPressedBackgroundBitmap(*pIconPressed);
548                         delete pIconPressed;
549                 }
550                 pItem->AddControl(pButtonRemove);
551                 pItem->SetIndividualSelectionEnabled(pButtonRemove, true);
552
553                 if (__pPresentationModel->GetThumbnailPath().IsEmpty() == true)
554                 {
555                         pButtonRemove->SetShowState(false);
556                 }
557                 else
558                 {
559                         pButtonAdd->SetShowState(false);
560                 }
561                 pItem->SetBackgroundColor(COLOR_TABLE_BG, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
562                 pItem->SetBackgroundColor(COLOR_TABLE_BG, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
563         }
564         else if (itemIndex == 1)
565         {
566                 EditField* pEditField = new (std::nothrow) EditField();
567                 pEditField->Construct(Rectangle(X_GROUP_TEXT_GAP, X_GROUP_TEXT_GAP, itemWidth - H_GROUP_TEXT_GAP, H_ITEM + pContactsApp->GetFontHeightOffset() - H_GROUP_TEXT_GAP), EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, EDIT_FIELD_TITLE_STYLE_TOP, !__pPresentationModel->IsDefaultCategory());
568                 pEditField->AddTextEventListener(*this);
569                 pEditField->AddKeypadEventListener(*this);
570                 pEditField->SetText(__pPresentationModel->GetCategoryName());
571                 pEditField->SetTitleText(ResourceManager::GetString(L"IDS_PB_BODY_GROUP_NAME_ABB"));
572                 pEditField->SetTextSize(pContactsApp->GetFontSize());
573                 pEditField->SetEnabled(!__pPresentationModel->IsDefaultCategory());
574
575                 if (__isEditMode == true)
576                 {
577                         String categoryName = __pPresentationModel->GetCategoryName();
578                         if (__pPresentationModel->IsDefaultCategory())
579                         {
580                                 if (categoryName.Equals(DEFAULT_GROUP_FAMILY, false))
581                                 {
582                                         categoryName.Clear();
583                                         categoryName = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT_GROUP_FAMILY");
584                                 }
585                                 else if (categoryName.Equals(DEFAULT_GROUP_FRIENDS, false))
586                                 {
587                                         categoryName.Clear();
588                                         categoryName = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT_GROUP_FRIENDS");
589                                 }
590                                 else if (categoryName.Equals(DEFAULT_GROUP_COWORKERS, false))
591                                 {
592                                         categoryName.Clear();
593                                         categoryName = ResourceManager::GetString(L"IDS_PB_BODY_CO_WORKERS");
594                                 }
595                         }
596                         pEditField->SetText(categoryName);
597                 }
598
599                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
600                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
601
602                 pItem->AddControl(pEditField);
603                 pItem->SetIndividualSelectionEnabled(pEditField, true);
604         }
605         else if (itemIndex == 2)
606         {
607                 Panel* pGroupStyle = new (std::nothrow) Panel();
608                 pGroupStyle->Construct(Rectangle(0, 0, itemWidth , itemHeight), GROUP_STYLE_NONE);
609                 pGroupStyle->SetName(GROUP_EDITOR_STYLE_PANEL);
610                 pGroupStyle->SetBackgroundColor(COLOR_THUMBNAIL);
611                 pGroupStyle->AddTouchEventListener(*this);
612                 pItem->AddKeyEventListener(*this);
613                 pItem->AddControl(pGroupStyle);
614
615                 pSubjectLabel = new (std::nothrow) Label();
616                 pSubjectLabel->Construct(Rectangle(X_RINGTONE_TEXT, Y_RINGTONE_TITLE, W_RINGTONE_TEXT, H_RINGTONE_TITLE),
617                                                                                                         ResourceManager::GetString(L"IDS_PB_BODY_RINGTONE"));
618                 pSubjectLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
619                 pSubjectLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
620                 pSubjectLabel->SetTextColor(Color(COLOR_RINGTONE_TITLE));
621                 pSubjectLabel->SetTextConfig(FONT_SIZE_RINGTONE_TITLE, LABEL_TEXT_STYLE_BOLD);
622                 pSubjectLabel->SetName(GROUP_EDITOR_LABEL_TITLE);
623                 pSubjectLabel->AddTouchEventListener(*this);
624                 pGroupStyle->AddControl(pSubjectLabel);
625
626                 int index = 0;
627                 String ringtonePath = __pPresentationModel->GetRingtone();
628                 String trimmedPath;
629
630                 if (ringtonePath.IsEmpty() == true)
631                 {
632                         trimmedPath = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT");
633                 }
634                 else
635                 {
636                         ringtonePath.LastIndexOf(L"/", ringtonePath.GetLength() - 1, index);
637                         if (index != 0)
638                         {
639                                 ringtonePath.SubString(index + 1, trimmedPath);
640                         }
641                 }
642
643                 pContentLabel = new (std::nothrow) Label();
644                 pContentLabel->Construct(Rectangle(X_RINGTONE_TEXT, Y_RINGTONE_NAME, W_RINGTONE_TEXT, H_RINGTONE_NAME + pContactsApp->GetFontHeightOffset()), trimmedPath);
645                 pContentLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
646                 pContentLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
647                 pContentLabel->SetTextConfig(pContactsApp->GetFontSize(), LABEL_TEXT_STYLE_NORMAL);
648                 pContentLabel->SetName(GROUP_EDITOR_LABEL_VALUE);
649                 pContentLabel->AddTouchEventListener(*this);
650                 pGroupStyle->AddControl(pContentLabel);
651
652                 Button* pClearButton = new (std::nothrow) Button();
653                 pClearButton->Construct(Rectangle(itemWidth - X_REFRESH_BUTTON_MARGIN, (pItem->GetHeight() - H_ICON_BUTTON) / 2, H_ICON_BUTTON, H_ICON_BUTTON));
654                 pClearButton->SetActionId(IDA_BUTTON_RINGTONE_CLEAR);
655                 pClearButton->AddActionEventListener(*this);
656
657                 Bitmap* pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_NORMAL);
658                 if (pReset != null)
659                 {
660                         pClearButton->SetNormalBitmap(Point(0, 0), *pReset);
661                         delete pReset;
662                 }
663                 pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_PRESSED);
664                 if (pReset != null)
665                 {
666                         pClearButton->SetPressedBitmap(Point(0, 0), *pReset);
667                         delete pReset;
668                 }
669
670                 pItem->AddControl(pClearButton);
671                 pItem->SetIndividualSelectionEnabled(pClearButton, true);
672
673                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
674         }
675
676         return pItem;
677 }
678
679 bool
680 GroupEditorForm::DeleteItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
681 {
682         delete pItem;
683         return true;
684 }
685
686 void
687 GroupEditorForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
688 {
689         if (pItem == null)
690         {
691                 return;
692         }
693
694         if (itemIndex == 0)
695         {
696                 Button* pRemoveButton = static_cast<Button*>(pItem->GetControl(REMOVE_BUTTON, false));
697                 Button* pAddButton = static_cast<Button*>(pItem->GetControl(ADD_BUTTON, false));
698                 Label* pThumbnailLabel = static_cast<Label*>(pItem->GetControl(THUMBNAIL_LABEL, false));
699                 Label* pThumbnailEmptyLabel = static_cast<Label*>(pItem->GetControl(THUMBNAIL_EMPTY_LABEL, false));
700                 if (pRemoveButton == null || pAddButton == null ||
701                         pThumbnailLabel == null || pThumbnailEmptyLabel == null)
702                 {
703                         return;
704                 }
705
706                 if (__pPresentationModel->GetThumbnailPath().IsEmpty() == true)
707                 {
708                         pRemoveButton->SetShowState(false);
709                         pThumbnailLabel->SetShowState(false);
710                         pThumbnailEmptyLabel->SetShowState(true);
711                         pAddButton->SetShowState(true);
712                 }
713                 else
714                 {
715                         pAddButton->SetShowState(false);
716                         pThumbnailEmptyLabel->SetShowState(false);
717                         pThumbnailLabel->SetShowState(true);
718                         pRemoveButton->SetShowState(true);
719
720                         Bitmap* pThumbnail = null;
721                         ImageBuffer thumbnailImageBuffer;
722                         result r = thumbnailImageBuffer.Construct(__pPresentationModel->GetThumbnailPath());
723                         if (r == E_SUCCESS)
724                         {
725                                 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
726                         }
727                         pThumbnailLabel->SetBackgroundBitmap(*pThumbnail);
728                         delete pThumbnail;
729
730                         pThumbnailLabel->Invalidate(false);
731                 }
732         }
733         else if (itemIndex == 1)
734         {
735                 EditField* pEditField = static_cast<EditField*>(pItem->GetControl(0));
736                 if (pEditField == null)
737                 {
738                         return;
739                 }
740
741                 String groupName = pEditField->GetText();
742                 groupName.Trim();
743
744                 if (groupName.GetLength() > 0)
745                 {
746                         Footer* pFooter = GetFooter();
747                         pFooter->SetItemEnabled(0, true);
748                         pFooter->Invalidate(true);
749                 }
750
751                 if (__pPresentationModel->IsDefaultCategory() == false && __pPresentationModel->IsDuplicatedCategory() == true)
752                 {
753                         pEditField->SetEnabled(true);
754                         pEditField->Clear();
755                         pEditField->SetGuideTextColor(Color(COLOR_GUIDE_TEXT));
756                         pEditField->SetGuideText(ResourceManager::GetString(L"IDS_PB_POP_GROUP_ALREADY_IN_USE"));
757                         pEditField->SetFocus();
758                         pEditField->Invalidate(false);
759                 }
760         }
761         else if (itemIndex == 2)
762         {
763                 int index = 0;
764                 String ringtonePath = __pPresentationModel->GetRingtone();
765                 String trimmedPath;
766
767                 if (ringtonePath.IsEmpty() == true)
768                 {
769                         trimmedPath = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT");
770                 }
771                 else
772                 {
773                         ringtonePath.LastIndexOf(L"/", ringtonePath.GetLength() - 1, index);
774                         if (index != 0)
775                         {
776                                 ringtonePath.SubString(index + 1, trimmedPath);
777                         }
778                 }
779
780                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
781
782                 if (pPanel == null)
783                 {
784                         return;
785                 }
786
787                 Label* pRingtoneName = static_cast<Label*>(pPanel->GetControl(1));
788
789                 if (pRingtoneName == null)
790                 {
791                         return;
792                 }
793
794                 if (pRingtoneName != null)
795                 {
796                         pRingtoneName->SetText(trimmedPath);
797                         pRingtoneName->Invalidate(true);
798                 }
799         }
800 }
801
802 int
803 GroupEditorForm::GetDefaultItemHeight(void)
804 {
805         return H_ITEM;
806 }
807
808 void
809 GroupEditorForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
810 {
811         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED && itemIndex == 2)
812         {
813                 LaunchAppControl(PROVIDER_ID_FILEMANAGER, OPERATION_ID_PICK);
814         }
815 }
816
817 void
818 GroupEditorForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
819 {
820 }
821
822 void
823 GroupEditorForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView, int itemIndexFrom, int itemIndexTo)
824 {
825 }
826
827 void
828 GroupEditorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
829 {
830         EditField* pEditField = const_cast<EditField *>(static_cast<const EditField *>(&source));
831         if (pEditField == null)
832         {
833                 return;
834         }
835
836         String existingCategoryName = __pPresentationModel->GetCategoryName();
837         String name = pEditField->GetText();
838
839         if (name.IsEmpty())
840         {
841                 pEditField->SetGuideText(String(CHARACTER_SPACE));
842                 pEditField->Invalidate(false);
843
844                 Footer* pFooter = GetFooter();
845                 pFooter->SetItemEnabled(0, false);
846                 pFooter->Invalidate(true);
847                 return;
848         }
849         name.Trim();
850         __pPresentationModel->SetCategoryName(name);
851
852         bool isSaveEnabled = false;
853         wchar_t ch;
854         __isGroupsChanged = false;
855
856         for (int index = 0; index < name.GetLength(); index++)
857         {
858                 name.GetCharAt(index, ch);
859
860                 if (ch != L' ')
861                 {
862                         isSaveEnabled = true;
863                         __isGroupsChanged = true;
864                         break;
865                 }
866         }
867
868         Footer* pFooter = GetFooter();
869
870         pFooter->SetItemEnabled(0, isSaveEnabled);
871         pFooter->Invalidate(true);
872 }
873
874 void
875 GroupEditorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
876 {
877 }
878
879 void
880 GroupEditorForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
881 {
882         Panel* pPanel = null;
883
884         if (source.GetName().Equals(GROUP_EDITOR_STYLE_PANEL, true))
885         {
886                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
887         }
888         else if (source.GetName().Equals(GROUP_EDITOR_LABEL_TITLE, true) || source.GetName().Equals(GROUP_EDITOR_LABEL_VALUE, true))
889         {
890                 pPanel = static_cast<Panel*>(source.GetParent());
891         }
892
893         if (pPanel != null)
894         {
895                 pPanel->SetBackgroundColor(COLOR_PRESSED);
896
897                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
898                 pLabelValue->SetTextColor(Color(COLOR_ITEM_PRESSED));
899
900                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
901                 pLabelTitle->SetTextColor(COLOR_ITEM_PRESSED);
902
903                 pPanel->Invalidate(true);
904         }
905 }
906
907 void
908 GroupEditorForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
909 {
910         Panel* pPanel = null;
911
912         if (source.GetName().Equals(GROUP_EDITOR_STYLE_PANEL, true))
913         {
914                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
915         }
916         else if (source.GetName().Equals(GROUP_EDITOR_LABEL_TITLE, true) || source.GetName().Equals(GROUP_EDITOR_LABEL_VALUE, true))
917         {
918                 pPanel = static_cast<Panel*>(source.GetParent());
919         }
920
921         if (pPanel != null)
922         {
923                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL);
924
925                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
926                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
927
928                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
929                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
930
931                 pPanel->Invalidate(true);
932         }
933
934 }
935
936 void
937 GroupEditorForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
938 {
939         Panel* pPanel = null;
940
941         if (source.GetName().Equals(GROUP_EDITOR_STYLE_PANEL, true))
942         {
943                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
944         }
945         else if (source.GetName().Equals(GROUP_EDITOR_LABEL_TITLE, true) || source.GetName().Equals(GROUP_EDITOR_LABEL_VALUE, true))
946         {
947                 pPanel = static_cast<Panel*>(source.GetParent());
948         }
949
950         if (pPanel != null)
951         {
952                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL);
953
954                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
955                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
956
957                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
958                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
959
960                 pPanel->Invalidate(true);
961         }
962 }
963
964 void
965 GroupEditorForm::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
966 {
967 }
968
969 void
970 GroupEditorForm::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
971 {
972 }
973
974 void
975 GroupEditorForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
976 {
977 }
978
979 void
980 GroupEditorForm::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
981 {
982         if (keyCode == KEY_ENTER )
983         {
984                 TableViewItem* pItem = static_cast<TableViewItem*>(&(const_cast<Control&>(source)));
985                 String valueString;
986                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
987
988                 if (pPanel == null)
989                 {
990                         return;
991                 }
992
993                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
994
995                 if (pLabelValue == null)
996                 {
997                         return;
998                 }
999
1000                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
1001
1002                 if (pLabelTitle == null)
1003                 {
1004                         return;
1005                 }
1006
1007                 pPanel->SetBackgroundColor(COLOR_PRESSED);
1008                 pLabelValue->SetTextColor(Color(COLOR_ITEM_PRESSED));
1009                 pLabelTitle->SetTextColor(COLOR_ITEM_PRESSED);
1010                 pPanel->Invalidate(true);
1011         }
1012 }
1013
1014 void
1015 GroupEditorForm::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1016 {
1017         if (keyCode == KEY_ENTER )
1018         {
1019
1020                 TableViewItem* pItem = static_cast<TableViewItem*>(&(const_cast<Control&>(source)));
1021                 String valueString;
1022                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
1023
1024                 if (pPanel == null)
1025                 {
1026                         return;
1027                 }
1028
1029                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
1030
1031                 if (pLabelValue == null)
1032                 {
1033                         return;
1034                 }
1035
1036                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
1037
1038                 if (pLabelTitle == null)
1039                 {
1040                         return;
1041                 }
1042
1043                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL);
1044                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
1045                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
1046                 pPanel->Invalidate(true);
1047         }
1048 }
1049
1050 void
1051 GroupEditorForm::OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1052 {
1053
1054 }
1055
1056 bool
1057 GroupEditorForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1058 {
1059         return false;
1060 }
1061
1062 bool
1063 GroupEditorForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
1064 {
1065         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
1066         {
1067                 if (__pDiscardChangesPopup && __pDiscardChangesPopup->GetShowState() == true)
1068                 {
1069                         HideDiscardChangesPopup();
1070                         return true;
1071                 }
1072         }
1073         return false;
1074 }
1075
1076 bool
1077 GroupEditorForm::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1078 {
1079         return false;
1080 }
1081
1082 bool
1083 GroupEditorForm::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
1084 {
1085         return false;
1086 }
1087
1088 void
1089 GroupEditorForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
1090 {
1091 }
1092
1093 void
1094 GroupEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
1095 {
1096         Rectangle clientBounds = GetClientAreaBounds();
1097
1098         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1099 }
1100
1101 void
1102 GroupEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
1103 {
1104 }
1105
1106 void
1107 GroupEditorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1108 {
1109 }
1110
1111 void
1112 GroupEditorForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
1113 {
1114         Rectangle clientBounds = GetClientAreaBounds();
1115
1116         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1117 }
1118
1119 void
1120 GroupEditorForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
1121 {
1122         AppLogDebug("ENTER");
1123
1124         SetEnabled(true);
1125         Invalidate(true);
1126
1127         TryReturnVoid(appControlResult == APP_CTRL_RESULT_SUCCEEDED, "[E_FAILURE] The result of an appcontrol is not succeeded.");
1128         TryReturnVoid(pExtraData != null, "[E_FAILURE] The extra data is null.");
1129
1130         const String *pResultString = null;
1131         const ArrayList* pResultList = dynamic_cast<const ArrayList*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
1132         if (pResultList != null)
1133         {
1134                 pResultString = static_cast<const String*>(pResultList->GetAt(0));
1135         }
1136         else
1137         {
1138                 pResultString = static_cast<const String*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
1139         }
1140         TryReturnVoid(pResultString != null, "[E_FAILURE] Unable to get file path.");
1141
1142         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
1143         {
1144                 __pPresentationModel->SetThumbnailPath(*pResultString);
1145                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1146
1147                 if (__pFileEventManager == null)
1148                 {
1149                         __pFileEventManager = new (std::nothrow) FileEventManager();
1150                         __pFileEventManager->Construct(*this);
1151                 }
1152                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
1153                 __isGroupsChanged = true;
1154         }
1155         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
1156         {
1157                 int width = 0;
1158                 int height = 0;
1159                 ImageFormat imageFormat;
1160                 result r = ImageBuffer::GetImageInfo(*pResultString, imageFormat, width, height);
1161
1162                 if (appControlResult == APP_CTRL_RESULT_FAILED || r != E_SUCCESS)
1163                 {
1164                         int modalResult = 0;
1165                         MessageBox unsupportedMessageBox;
1166                         unsupportedMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_MP_POP_INVALID_FILE"), MSGBOX_STYLE_NONE, 3000);
1167                         unsupportedMessageBox.ShowAndWait(modalResult);
1168
1169                         return;
1170                 }
1171
1172                 r = LaunchImageViewerAppControl(*pResultString);
1173         }
1174         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
1175         {
1176                 __pPresentationModel->SetRingtone(*pResultString);
1177                 __pTableView->RefreshItem(2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1178
1179                 if (__pFileEventManager == null)
1180                 {
1181                         __pFileEventManager = new (std::nothrow) FileEventManager();
1182                         __pFileEventManager->Construct(*this);
1183                 }
1184                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
1185                 __isGroupsChanged = true;
1186         }
1187         else if(appId.Equals(String(PROVIDER_ID_IMAGEVIEWER)) && operationId.Equals(String(OPERATION_ID_CROP)))
1188         {
1189                 int width = 0;
1190                 int height = 0;
1191                 ImageFormat imageFormat;
1192                 result r = ImageBuffer::GetImageInfo(*pResultString, imageFormat, width, height);
1193
1194                 if (appControlResult == APP_CTRL_RESULT_FAILED || r != E_SUCCESS)
1195                 {
1196                         int modalResult = 0;
1197                         MessageBox unsupportedMessageBox;
1198                         unsupportedMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_MP_POP_INVALID_FILE"), MSGBOX_STYLE_NONE, 3000);
1199                         unsupportedMessageBox.ShowAndWait(modalResult);
1200
1201                         return;
1202                 }
1203
1204                 __pPresentationModel->SetThumbnailPath(*pResultString);
1205                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1206
1207                 if (__pFileEventManager == null)
1208                 {
1209                         __pFileEventManager = new (std::nothrow) FileEventManager();
1210                         __pFileEventManager->Construct(*this);
1211                 }
1212                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
1213                 __isGroupsChanged = true;
1214
1215                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1216         }
1217
1218         AppLogDebug("EXIT");
1219 }
1220
1221 result
1222 GroupEditorForm::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId)
1223 {
1224         result r = E_SUCCESS;
1225
1226         SetFocus();
1227
1228         String uri;
1229         String mimeType;
1230         HashMap extraData;
1231         extraData.Construct();
1232
1233         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
1234         {
1235                 mimeType.Append(INPUT_MIME_TYPE_CAMERA);
1236                 extraData.Add(new (std::nothrow) String(INPUT_KEY_ALLOW_SWITCH), new (std::nothrow) String(INPUT_VALUE_FALSE));
1237         }
1238         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
1239         {
1240                 mimeType.Append(INPUT_MIME_TYPE_GALLERY);
1241                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
1242         }
1243         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
1244         {
1245                 mimeType.Append(INPUT_MIME_TYPE_AUDIO);
1246                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
1247         }
1248
1249         AppControl* pAppControl = AppManager::FindAppControlN(appId, operationId);
1250
1251         if (pAppControl != null)
1252         {
1253                 r = pAppControl->Start(&uri, &mimeType, &extraData, this);
1254                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control", GetErrorMessage(r));
1255
1256                 SetEnabled(false);
1257                 Invalidate(true);
1258         }
1259
1260 CATCH:
1261         extraData.RemoveAll(true);
1262         delete pAppControl;
1263
1264         return r;
1265 }
1266
1267 result
1268 GroupEditorForm::LaunchImageViewerAppControl(const Tizen::Base::String& filePath)
1269 {
1270         result r = E_SUCCESS;
1271
1272         HashMap extraData;
1273         extraData.Construct();
1274         String typeKey = L"http://tizen.org/appcontrol/data/image/crop_mode";
1275         String typeVal = L"fit_to_screen";
1276         extraData.Add(new (std::nothrow) String(INPUT_KEY_IMAGEVIEWER_MODE), new (std::nothrow) String(INPUT_VALUE_IMAGEVIEWER_TYPE));
1277
1278         AppControl* pAppControl = AppManager::FindAppControlN(PROVIDER_ID_IMAGEVIEWER, OPERATION_ID_CROP);
1279
1280         if (pAppControl != null)
1281         {
1282                 r = pAppControl->Start(&filePath, null, &extraData, this);
1283                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control", GetErrorMessage(r));
1284
1285                 SetEnabled(false);
1286                 Invalidate(true);
1287         }
1288
1289 CATCH:
1290         extraData.RemoveAll(true);
1291         delete pAppControl;
1292
1293         return r;
1294 }
1295
1296 void
1297 GroupEditorForm::OnContactsChanged(void)
1298 {
1299 }
1300
1301 void
1302 GroupEditorForm::OnCategoriesChanged(void)
1303 {
1304         result r = E_SUCCESS;
1305
1306         SceneManager* pSceneManager = SceneManager::GetInstance();
1307
1308         SceneId previousSceneId;
1309         IListT<SceneId>* pHistoryList = pSceneManager->GetSceneHistoryN();
1310         if (pHistoryList != null)
1311         {
1312                 int count = pHistoryList->GetCount();
1313                 r = pHistoryList->GetAt(count - 1, previousSceneId);
1314                 delete pHistoryList;
1315                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to get previous scene id", GetErrorMessage(r));
1316         }
1317
1318         if (previousSceneId.Equals(IDSCN_CONTACT_DETAILS, true) || previousSceneId.Equals(IDSCN_CONTACT_EDITOR, true))
1319         {
1320                 if (__pPresentationModel->GetCategoryCount() > 0)
1321                 {
1322                         ArrayList* pArg = new (std::nothrow) ArrayList();
1323                         pArg->Construct();
1324                         pArg->Add(new (std::nothrow) Integer(__pPresentationModel->GetCategoryId()));
1325
1326                         r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArg);
1327                         TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
1328
1329                         return;
1330                 }
1331         }
1332
1333         if (__isSaved)
1334         {
1335                 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
1336                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
1337         }
1338 }
1339
1340 void
1341 GroupEditorForm::OnForeground(void)
1342 {
1343         if ( File::IsFileExist(__pPresentationModel->GetThumbnailPath()) == false)
1344         {
1345                 __pPresentationModel->SetThumbnailPath(L"");
1346                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1347         }
1348         if (IsEnabled() == false)
1349         {
1350                 SetEnabled(true);
1351                 Invalidate(true);
1352         }
1353 }
1354
1355 void
1356 GroupEditorForm::OnBackground(void)
1357 {
1358 }