Initialize Tizen 2.3
[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                         pEditField->SetText(categoryName);
579                 }
580
581                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
582                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
583
584                 pItem->AddControl(pEditField);
585                 pItem->SetIndividualSelectionEnabled(pEditField, true);
586         }
587         else if (itemIndex == 2)
588         {
589                 Panel* pGroupStyle = new (std::nothrow) Panel();
590                 pGroupStyle->Construct(Rectangle(0, 0, itemWidth , itemHeight), GROUP_STYLE_NONE);
591                 pGroupStyle->SetName(GROUP_EDITOR_STYLE_PANEL);
592                 pGroupStyle->SetBackgroundColor(COLOR_THUMBNAIL);
593                 pGroupStyle->AddTouchEventListener(*this);
594                 pItem->AddKeyEventListener(*this);
595                 pItem->AddControl(pGroupStyle);
596
597                 pSubjectLabel = new (std::nothrow) Label();
598                 pSubjectLabel->Construct(Rectangle(X_RINGTONE_TEXT, Y_RINGTONE_TITLE, W_RINGTONE_TEXT, H_RINGTONE_TITLE),
599                                                                                                         ResourceManager::GetString(L"IDS_PB_BODY_RINGTONE"));
600                 pSubjectLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
601                 pSubjectLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
602                 pSubjectLabel->SetTextColor(Color(COLOR_RINGTONE_TITLE));
603                 pSubjectLabel->SetTextConfig(FONT_SIZE_RINGTONE_TITLE, LABEL_TEXT_STYLE_BOLD);
604                 pSubjectLabel->SetName(GROUP_EDITOR_LABEL_TITLE);
605                 pSubjectLabel->AddTouchEventListener(*this);
606                 pGroupStyle->AddControl(pSubjectLabel);
607
608                 int index = 0;
609                 String ringtonePath = __pPresentationModel->GetRingtone();
610                 String trimmedPath;
611
612                 if (ringtonePath.IsEmpty() == true)
613                 {
614                         trimmedPath = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT");
615                 }
616                 else
617                 {
618                         ringtonePath.LastIndexOf(L"/", ringtonePath.GetLength() - 1, index);
619                         if (index != 0)
620                         {
621                                 ringtonePath.SubString(index + 1, trimmedPath);
622                         }
623                 }
624
625                 pContentLabel = new (std::nothrow) Label();
626                 pContentLabel->Construct(Rectangle(X_RINGTONE_TEXT, Y_RINGTONE_NAME, W_RINGTONE_TEXT, H_RINGTONE_NAME + pContactsApp->GetFontHeightOffset()), trimmedPath);
627                 pContentLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
628                 pContentLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
629                 pContentLabel->SetTextConfig(pContactsApp->GetFontSize(), LABEL_TEXT_STYLE_NORMAL);
630                 pContentLabel->SetName(GROUP_EDITOR_LABEL_VALUE);
631                 pContentLabel->AddTouchEventListener(*this);
632                 pGroupStyle->AddControl(pContentLabel);
633
634                 Button* pClearButton = new (std::nothrow) Button();
635                 pClearButton->Construct(Rectangle(itemWidth - X_REFRESH_BUTTON_MARGIN, (pItem->GetHeight() - H_ICON_BUTTON) / 2, H_ICON_BUTTON, H_ICON_BUTTON));
636                 pClearButton->SetActionId(IDA_BUTTON_RINGTONE_CLEAR);
637                 pClearButton->AddActionEventListener(*this);
638
639                 Bitmap* pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_NORMAL);
640                 if (pReset != null)
641                 {
642                         pClearButton->SetNormalBitmap(Point(0, 0), *pReset);
643                         delete pReset;
644                 }
645                 pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_PRESSED);
646                 if (pReset != null)
647                 {
648                         pClearButton->SetPressedBitmap(Point(0, 0), *pReset);
649                         delete pReset;
650                 }
651
652                 pItem->AddControl(pClearButton);
653                 pItem->SetIndividualSelectionEnabled(pClearButton, true);
654
655                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
656         }
657
658         return pItem;
659 }
660
661 bool
662 GroupEditorForm::DeleteItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
663 {
664         delete pItem;
665         return true;
666 }
667
668 void
669 GroupEditorForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
670 {
671         if (pItem == null)
672         {
673                 return;
674         }
675
676         if (itemIndex == 0)
677         {
678                 Button* pRemoveButton = static_cast<Button*>(pItem->GetControl(REMOVE_BUTTON, false));
679                 Button* pAddButton = static_cast<Button*>(pItem->GetControl(ADD_BUTTON, false));
680                 Label* pThumbnailLabel = static_cast<Label*>(pItem->GetControl(THUMBNAIL_LABEL, false));
681                 Label* pThumbnailEmptyLabel = static_cast<Label*>(pItem->GetControl(THUMBNAIL_EMPTY_LABEL, false));
682                 if (pRemoveButton == null || pAddButton == null ||
683                         pThumbnailLabel == null || pThumbnailEmptyLabel == null)
684                 {
685                         return;
686                 }
687
688                 if (__pPresentationModel->GetThumbnailPath().IsEmpty() == true)
689                 {
690                         pRemoveButton->SetShowState(false);
691                         pThumbnailLabel->SetShowState(false);
692                         pThumbnailEmptyLabel->SetShowState(true);
693                         pAddButton->SetShowState(true);
694                 }
695                 else
696                 {
697                         pAddButton->SetShowState(false);
698                         pThumbnailEmptyLabel->SetShowState(false);
699                         pThumbnailLabel->SetShowState(true);
700                         pRemoveButton->SetShowState(true);
701
702                         Bitmap* pThumbnail = null;
703                         ImageBuffer thumbnailImageBuffer;
704                         result r = thumbnailImageBuffer.Construct(__pPresentationModel->GetThumbnailPath());
705                         if (r == E_SUCCESS)
706                         {
707                                 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
708                         }
709                         pThumbnailLabel->SetBackgroundBitmap(*pThumbnail);
710                         delete pThumbnail;
711
712                         pThumbnailLabel->Invalidate(false);
713                 }
714         }
715         else if (itemIndex == 1)
716         {
717                 EditField* pEditField = static_cast<EditField*>(pItem->GetControl(0));
718                 if (pEditField == null)
719                 {
720                         return;
721                 }
722
723                 String groupName = pEditField->GetText();
724                 groupName.Trim();
725
726                 if (groupName.GetLength() > 0)
727                 {
728                         Footer* pFooter = GetFooter();
729                         pFooter->SetItemEnabled(0, true);
730                         pFooter->Invalidate(true);
731                 }
732
733                 if (__pPresentationModel->IsDefaultCategory() == false && __pPresentationModel->IsDuplicatedCategory() == true)
734                 {
735                         pEditField->SetEnabled(true);
736                         pEditField->Clear();
737                         pEditField->SetGuideTextColor(Color(COLOR_GUIDE_TEXT));
738                         pEditField->SetGuideText(ResourceManager::GetString(L"IDS_PB_POP_GROUP_ALREADY_IN_USE"));
739                         pEditField->SetFocus();
740                         pEditField->Invalidate(false);
741                 }
742         }
743         else if (itemIndex == 2)
744         {
745                 int index = 0;
746                 String ringtonePath = __pPresentationModel->GetRingtone();
747                 String trimmedPath;
748
749                 if (ringtonePath.IsEmpty() == true)
750                 {
751                         trimmedPath = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT");
752                 }
753                 else
754                 {
755                         ringtonePath.LastIndexOf(L"/", ringtonePath.GetLength() - 1, index);
756                         if (index != 0)
757                         {
758                                 ringtonePath.SubString(index + 1, trimmedPath);
759                         }
760                 }
761
762                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
763
764                 if (pPanel == null)
765                 {
766                         return;
767                 }
768
769                 Label* pRingtoneName = static_cast<Label*>(pPanel->GetControl(1));
770
771                 if (pRingtoneName == null)
772                 {
773                         return;
774                 }
775
776                 if (pRingtoneName != null)
777                 {
778                         pRingtoneName->SetText(trimmedPath);
779                         pRingtoneName->Invalidate(true);
780                 }
781         }
782 }
783
784 int
785 GroupEditorForm::GetDefaultItemHeight(void)
786 {
787         return H_ITEM;
788 }
789
790 void
791 GroupEditorForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
792 {
793         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED && itemIndex == 2)
794         {
795                 LaunchAppControl(PROVIDER_ID_FILEMANAGER, OPERATION_ID_PICK);
796         }
797 }
798
799 void
800 GroupEditorForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
801 {
802 }
803
804 void
805 GroupEditorForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView, int itemIndexFrom, int itemIndexTo)
806 {
807 }
808
809 void
810 GroupEditorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
811 {
812         EditField* pEditField = const_cast<EditField *>(static_cast<const EditField *>(&source));
813         if (pEditField == null)
814         {
815                 return;
816         }
817
818         String existingCategoryName = __pPresentationModel->GetCategoryName();
819         String name = pEditField->GetText();
820
821         if (name.IsEmpty())
822         {
823                 pEditField->SetGuideText(String(CHARACTER_SPACE));
824                 pEditField->Invalidate(false);
825
826                 Footer* pFooter = GetFooter();
827                 pFooter->SetItemEnabled(0, false);
828                 pFooter->Invalidate(true);
829                 return;
830         }
831         name.Trim();
832         __pPresentationModel->SetCategoryName(name);
833
834         bool isSaveEnabled = false;
835         wchar_t ch;
836         __isGroupsChanged = false;
837
838         for (int index = 0; index < name.GetLength(); index++)
839         {
840                 name.GetCharAt(index, ch);
841
842                 if (ch != L' ')
843                 {
844                         isSaveEnabled = true;
845                         __isGroupsChanged = true;
846                         break;
847                 }
848         }
849
850         Footer* pFooter = GetFooter();
851
852         pFooter->SetItemEnabled(0, isSaveEnabled);
853         pFooter->Invalidate(true);
854 }
855
856 void
857 GroupEditorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
858 {
859 }
860
861 void
862 GroupEditorForm::OnTouchPressed(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
863 {
864         Panel* pPanel = null;
865
866         if (source.GetName().Equals(GROUP_EDITOR_STYLE_PANEL, true))
867         {
868                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
869         }
870         else if (source.GetName().Equals(GROUP_EDITOR_LABEL_TITLE, true) || source.GetName().Equals(GROUP_EDITOR_LABEL_VALUE, true))
871         {
872                 pPanel = static_cast<Panel*>(source.GetParent());
873         }
874
875         if (pPanel != null)
876         {
877                 pPanel->SetBackgroundColor(COLOR_PRESSED);
878
879                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
880                 pLabelValue->SetTextColor(Color(COLOR_ITEM_PRESSED));
881
882                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
883                 pLabelTitle->SetTextColor(COLOR_ITEM_PRESSED);
884
885                 pPanel->Invalidate(true);
886         }
887 }
888
889 void
890 GroupEditorForm::OnTouchReleased(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
891 {
892         Panel* pPanel = null;
893
894         if (source.GetName().Equals(GROUP_EDITOR_STYLE_PANEL, true))
895         {
896                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
897         }
898         else if (source.GetName().Equals(GROUP_EDITOR_LABEL_TITLE, true) || source.GetName().Equals(GROUP_EDITOR_LABEL_VALUE, true))
899         {
900                 pPanel = static_cast<Panel*>(source.GetParent());
901         }
902
903         if (pPanel != null)
904         {
905                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL);
906
907                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
908                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
909
910                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
911                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
912
913                 pPanel->Invalidate(true);
914         }
915
916 }
917
918 void
919 GroupEditorForm::OnTouchMoved(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
920 {
921         Panel* pPanel = null;
922
923         if (source.GetName().Equals(GROUP_EDITOR_STYLE_PANEL, true))
924         {
925                 pPanel = static_cast<Panel*>(&(const_cast<Control&>(source)));
926         }
927         else if (source.GetName().Equals(GROUP_EDITOR_LABEL_TITLE, true) || source.GetName().Equals(GROUP_EDITOR_LABEL_VALUE, true))
928         {
929                 pPanel = static_cast<Panel*>(source.GetParent());
930         }
931
932         if (pPanel != null)
933         {
934                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL);
935
936                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
937                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
938
939                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
940                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
941
942                 pPanel->Invalidate(true);
943         }
944 }
945
946 void
947 GroupEditorForm::OnTouchFocusIn(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
948 {
949 }
950
951 void
952 GroupEditorForm::OnTouchFocusOut(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
953 {
954 }
955
956 void
957 GroupEditorForm::OnTouchCanceled(const Tizen::Ui::Control& source, const Tizen::Graphics::Point& currentPosition, const Tizen::Ui::TouchEventInfo& touchInfo)
958 {
959 }
960
961 void
962 GroupEditorForm::OnKeyPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
963 {
964         if (keyCode == KEY_ENTER )
965         {
966                 TableViewItem* pItem = static_cast<TableViewItem*>(&(const_cast<Control&>(source)));
967                 String valueString;
968                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
969
970                 if (pPanel == null)
971                 {
972                         return;
973                 }
974
975                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
976
977                 if (pLabelValue == null)
978                 {
979                         return;
980                 }
981
982                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
983
984                 if (pLabelTitle == null)
985                 {
986                         return;
987                 }
988
989                 pPanel->SetBackgroundColor(COLOR_PRESSED);
990                 pLabelValue->SetTextColor(Color(COLOR_ITEM_PRESSED));
991                 pLabelTitle->SetTextColor(COLOR_ITEM_PRESSED);
992                 pPanel->Invalidate(true);
993         }
994 }
995
996 void
997 GroupEditorForm::OnKeyReleased(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
998 {
999         if (keyCode == KEY_ENTER )
1000         {
1001
1002                 TableViewItem* pItem = static_cast<TableViewItem*>(&(const_cast<Control&>(source)));
1003                 String valueString;
1004                 Panel* pPanel = static_cast<Panel*>(pItem->GetControl(0));
1005
1006                 if (pPanel == null)
1007                 {
1008                         return;
1009                 }
1010
1011                 Label* pLabelValue = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_VALUE, true));
1012
1013                 if (pLabelValue == null)
1014                 {
1015                         return;
1016                 }
1017
1018                 Label* pLabelTitle = static_cast<Label*>(pPanel->GetControl(GROUP_EDITOR_LABEL_TITLE, true));
1019
1020                 if (pLabelTitle == null)
1021                 {
1022                         return;
1023                 }
1024
1025                 pPanel->SetBackgroundColor(COLOR_THUMBNAIL);
1026                 pLabelValue->SetTextColor(Color(COLOR_ITEM_VALUE));
1027                 pLabelTitle->SetTextColor(COLOR_ITEM_TITLE);
1028                 pPanel->Invalidate(true);
1029         }
1030 }
1031
1032 void
1033 GroupEditorForm::OnKeyLongPressed(const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode)
1034 {
1035
1036 }
1037
1038 bool
1039 GroupEditorForm::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1040 {
1041         return false;
1042 }
1043
1044 bool
1045 GroupEditorForm::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
1046 {
1047         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
1048         {
1049                 if (__pDiscardChangesPopup && __pDiscardChangesPopup->GetShowState() == true)
1050                 {
1051                         HideDiscardChangesPopup();
1052                         return true;
1053                 }
1054         }
1055         return false;
1056 }
1057
1058 bool
1059 GroupEditorForm::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
1060 {
1061         return false;
1062 }
1063
1064 bool
1065 GroupEditorForm::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
1066 {
1067         return false;
1068 }
1069
1070 void
1071 GroupEditorForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
1072 {
1073 }
1074
1075 void
1076 GroupEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
1077 {
1078         Rectangle clientBounds = GetClientAreaBounds();
1079
1080         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1081 }
1082
1083 void
1084 GroupEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
1085 {
1086 }
1087
1088 void
1089 GroupEditorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
1090 {
1091 }
1092
1093 void
1094 GroupEditorForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
1095 {
1096         Rectangle clientBounds = GetClientAreaBounds();
1097
1098         __pTableView->SetSize(clientBounds.width, clientBounds.height);
1099 }
1100
1101 void
1102 GroupEditorForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
1103 {
1104         AppLogDebug("ENTER");
1105
1106         SetEnabled(true);
1107         Invalidate(true);
1108
1109         TryReturnVoid(appControlResult == APP_CTRL_RESULT_SUCCEEDED, "[E_FAILURE] The result of an appcontrol is not succeeded.");
1110         TryReturnVoid(pExtraData != null, "[E_FAILURE] The extra data is null.");
1111
1112         const String *pResultString = null;
1113         const ArrayList* pResultList = dynamic_cast<const ArrayList*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
1114         if (pResultList != null)
1115         {
1116                 pResultString = static_cast<const String*>(pResultList->GetAt(0));
1117         }
1118         else
1119         {
1120                 pResultString = static_cast<const String*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
1121         }
1122         TryReturnVoid(pResultString != null, "[E_FAILURE] Unable to get file path.");
1123
1124         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
1125         {
1126                 __pPresentationModel->SetThumbnailPath(*pResultString);
1127                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1128
1129                 if (__pFileEventManager == null)
1130                 {
1131                         __pFileEventManager = new (std::nothrow) FileEventManager();
1132                         __pFileEventManager->Construct(*this);
1133                 }
1134                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
1135                 __isGroupsChanged = true;
1136         }
1137         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
1138         {
1139                 int width = 0;
1140                 int height = 0;
1141                 ImageFormat imageFormat;
1142                 result r = ImageBuffer::GetImageInfo(*pResultString, imageFormat, width, height);
1143
1144                 if (appControlResult == APP_CTRL_RESULT_FAILED || r != E_SUCCESS)
1145                 {
1146                         int modalResult = 0;
1147                         MessageBox unsupportedMessageBox;
1148                         unsupportedMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_MP_POP_INVALID_FILE"), MSGBOX_STYLE_NONE, 3000);
1149                         unsupportedMessageBox.ShowAndWait(modalResult);
1150
1151                         return;
1152                 }
1153
1154                 __pPresentationModel->SetThumbnailPath(*pResultString);
1155                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1156
1157                 if (__pFileEventManager == null)
1158                 {
1159                         __pFileEventManager = new (std::nothrow) FileEventManager();
1160                         __pFileEventManager->Construct(*this);
1161                 }
1162                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
1163                 __isGroupsChanged = true;
1164         }
1165         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
1166         {
1167                 __pPresentationModel->SetRingtone(*pResultString);
1168                 __pTableView->RefreshItem(2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1169
1170                 if (__pFileEventManager == null)
1171                 {
1172                         __pFileEventManager = new (std::nothrow) FileEventManager();
1173                         __pFileEventManager->Construct(*this);
1174                 }
1175                 __pFileEventManager->AddPath(*pResultString, FILE_EVENT_TYPE_DELETE | FILE_EVENT_TYPE_DELETE_SELF | FILE_EVENT_TYPE_MODIFY | FILE_EVENT_TYPE_MOVE_SELF);
1176                 __isGroupsChanged = true;
1177         }
1178
1179         AppLogDebug("EXIT");
1180 }
1181
1182 result
1183 GroupEditorForm::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId)
1184 {
1185         result r = E_SUCCESS;
1186
1187         SetFocus();
1188
1189         String uri;
1190         String mimeType;
1191         HashMap extraData;
1192         extraData.Construct();
1193
1194         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
1195         {
1196                 mimeType.Append(INPUT_MIME_TYPE_CAMERA);
1197                 extraData.Add(new (std::nothrow) String(INPUT_KEY_ALLOW_SWITCH), new (std::nothrow) String(INPUT_VALUE_FALSE));
1198         }
1199         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
1200         {
1201                 mimeType.Append(INPUT_MIME_TYPE_GALLERY);
1202                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
1203                 extraData.Add(new (std::nothrow) String(INPUT_KEY_IMAGEVIEWER_MODE), new (std::nothrow) String(INPUT_VALUE_IMAGEVIEWER_TYPE));
1204         }
1205         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
1206         {
1207                 mimeType.Append(INPUT_MIME_TYPE_AUDIO);
1208                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
1209         }
1210
1211         AppControl* pAppControl = AppManager::FindAppControlN(appId, operationId);
1212
1213         if (pAppControl != null)
1214         {
1215                 r = pAppControl->Start(&uri, &mimeType, &extraData, this);
1216                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control", GetErrorMessage(r));
1217
1218                 SetEnabled(false);
1219                 Invalidate(true);
1220         }
1221
1222 CATCH:
1223         extraData.RemoveAll(true);
1224         delete pAppControl;
1225
1226         return r;
1227 }
1228
1229 void
1230 GroupEditorForm::OnContactsChanged(void)
1231 {
1232 }
1233
1234 void
1235 GroupEditorForm::OnCategoriesChanged(void)
1236 {
1237         result r = E_SUCCESS;
1238
1239         SceneManager* pSceneManager = SceneManager::GetInstance();
1240
1241         SceneId previousSceneId;
1242         IListT<SceneId>* pHistoryList = pSceneManager->GetSceneHistoryN();
1243         if (pHistoryList != null)
1244         {
1245                 int count = pHistoryList->GetCount();
1246                 r = pHistoryList->GetAt(count - 1, previousSceneId);
1247                 delete pHistoryList;
1248                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to get previous scene id", GetErrorMessage(r));
1249         }
1250
1251         if (previousSceneId.Equals(IDSCN_CONTACT_DETAILS, true) || previousSceneId.Equals(IDSCN_CONTACT_EDITOR, true))
1252         {
1253                 if (__pPresentationModel->GetCategoryCount() > 0)
1254                 {
1255                         ArrayList* pArg = new (std::nothrow) ArrayList();
1256                         pArg->Construct();
1257                         pArg->Add(new (std::nothrow) Integer(__pPresentationModel->GetCategoryId()));
1258
1259                         r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArg);
1260                         TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
1261
1262                         return;
1263                 }
1264         }
1265
1266         if (__isSaved)
1267         {
1268                 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
1269                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
1270         }
1271 }
1272
1273 void
1274 GroupEditorForm::OnForeground(void)
1275 {
1276         if ( File::IsFileExist(__pPresentationModel->GetThumbnailPath()) == false)
1277         {
1278                 __pPresentationModel->SetThumbnailPath(L"");
1279                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
1280         }
1281         if (IsEnabled() == false)
1282         {
1283                 result r = SetEnabled(true);
1284                 AppLogDebug("Form Enabled = %s", GetErrorMessage(r));
1285                 Invalidate(true);
1286         }
1287 }
1288
1289 void
1290 GroupEditorForm::OnBackground(void)
1291 {
1292 }