NABI issues fixed: 41292, 41263, 41256, 41241, 41231, 41183, 41160, 41515, 41363...
[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
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Io;
36 using namespace Tizen::Media;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39 using namespace Tizen::Social;
40 using namespace Tizen::System;
41
42 static const int IDA_HEADER_SAVE = 0;
43 static const int IDA_BUTTON_GALLERY = 10;
44 static const int IDA_BUTTON_TAKE_PHOTO = 11;
45 static const int IDA_BUTTON_REMOVE = 12;
46 static const int IDA_BUTTON_RINGTONE_CLEAR = 13;
47
48 static const wchar_t* IDB_ICON_ADD_NORMAL = L"C02_caller_id_icon_add.png";
49 static const wchar_t* IDB_ICON_ADD_PRESSED = L"C02_caller_id_icon_add_press.png";
50 static const wchar_t* IDB_ICON_CAMERA_NORMAL = L"C02_caller_id_icon_camera.png";
51 static const wchar_t* IDB_ICON_CAMERA_PRESSED = L"C02_caller_id_icon_camera_press.png";
52 static const wchar_t* IDB_ICON_REMOVE_NORMAL = L"00_button_expand_minus_press.png";
53 static const wchar_t* IDB_ICON_REMOVE_PRESSED = L"00_button_expand_minus_press.png";
54 static const wchar_t* IDB_REMOVE_BG_NORMAL = L"00_circle_button_delete.png";
55 static const wchar_t* IDB_REMOVE_BG_PRESSED = L"00_circle_button_delete_press.png";
56 static const wchar_t* IDB_DETAILS_RESET_NORMAL = L"00_button_refresh.png";
57 static const wchar_t* IDB_DETAILS_RESET_PRESSED = L"00_button_refresh_press.png";
58
59 static const int H_ITEM = 128;
60 static const int H_THUMBNAIL = 360;
61 static const int Y_THUMBNAIL = 57;
62 static const int H_ICON_BUTTON = 74;
63 static const int Y_REMOVE_BUTTON = 26;
64 static const int X_REMOVE_BUTTON_MARGIN = 40;
65 static const int X_REFRESH_BUTTON_MARGIN = 88;
66
67 static const int X_RINGTONE_TEXT = 3;
68 static const int Y_RINGTONE_TITLE = 10;
69 static const int Y_RINGTONE_NAME = 68;
70 static const int W_RINGTONE_TEXT = 600;
71 static const int H_RINGTONE_TITLE = 58;
72 static const int H_RINGTONE_NAME = 50;
73
74 static const unsigned int COLOR_GUIDE_TEXT = Color32<255, 0, 0>::Value;
75 static const unsigned int COLOR_RINGTONE = Color32<92, 151, 187>::Value;
76 static const unsigned int COLOR_RINGTONE_TITLE = Color32<128, 128, 128>::Value;
77 static const unsigned int COLOR_THUMBNAIL = Color32<239, 237, 229>::Value;
78 static const unsigned int COLOR_TABLE_BG = Color32<248, 246, 239>::Value;
79
80 static const int ITEM_COUNT = 3;
81
82 static const int FONT_SIZE_RINGTONE_TITLE = 40;
83 static const int FONT_SIZE_RINGTONE = 32;
84
85 static const wchar_t* INPUT_DATA_SELECTION_MODE_SINGLE = L"single";
86 static const wchar_t* INPUT_KEY_SELECTION_MODE = L"http://tizen.org/appcontrol/data/selection_mode";
87 static const wchar_t* INPUT_KEY_ALLOW_SWITCH = L"http://tizen.org/appcontrol/data/camera/allow_switch";
88 static const wchar_t* INPUT_MIME_TYPE_CAMERA = L"image/jpg";
89 static const wchar_t* INPUT_MIME_TYPE_GALLERY = L"image/*";
90 static const wchar_t* INPUT_MIME_TYPE_AUDIO = L"audio/*";
91 static const wchar_t* INPUT_VALUE_FALSE = L"false";
92 static const wchar_t* OUTPUT_KEY_SELECTED = L"http://tizen.org/appcontrol/data/selected";
93 static const wchar_t* THUMBNAIL_LABEL = L"thumbnail";
94 static const wchar_t* THUMBNAIL_EMPTY_LABEL = L"emptyThumbnail";
95 static const wchar_t* ADD_BUTTON = L"add";
96 static const wchar_t* CAMERA_BUTTON = L"camera";
97 static const wchar_t* REMOVE_BUTTON = L"remove";
98 static const wchar_t* SD_CARD_UNMOUNTED = L"Unmounted";
99
100 GroupEditorForm::GroupEditorForm(void)
101  : __pPresentationModel(null)
102  , __pTableView(null)
103  , __isEditMode(false)
104  , __isSaved(false)
105 {
106 }
107
108 GroupEditorForm::~GroupEditorForm(void)
109 {
110 }
111
112 void
113 GroupEditorForm::Initialize(void)
114 {
115         Construct(L"IDL_GROUP_EDITOR_FORM");
116 }
117
118 result
119 GroupEditorForm::OnInitializing(void)
120 {
121         Footer* pFooter = GetFooter();
122         pFooter->AddActionEventListener(*this);
123         SetFormBackEventListener(this);
124         DeviceManager::AddDeviceEventListener(DEVICE_TYPE_STORAGE_CARD, *this);
125
126         __pTableView = new (std::nothrow) TableView();
127         __pTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height), true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
128         __pTableView->SetItemProvider(this);
129         __pTableView->AddTableViewItemEventListener(*this);
130         AddControl(__pTableView);
131
132         return E_SUCCESS;
133 }
134
135 result
136 GroupEditorForm::OnTerminating(void)
137 {
138         __pTableView->SetItemProvider(null);
139
140         delete __pPresentationModel;
141
142         return E_SUCCESS;
143 }
144
145 void
146 GroupEditorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
147 {
148         SceneManager* pSceneManager = SceneManager::GetInstance();
149
150         SetFocus();
151
152         result r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
153         TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
154 }
155
156 void
157 GroupEditorForm::OnFileEventOccured(const unsigned long events, const Tizen::Base::String &path, const unsigned int eventId)
158 {
159         __pPresentationModel->SetThumbnailPath(L"");
160         __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
161 }
162
163 void
164 GroupEditorForm::OnDeviceStateChanged(Tizen::System::DeviceType deviceType, const Tizen::Base::String &state)
165 {
166         if (deviceType != DEVICE_TYPE_STORAGE_CARD || __pPresentationModel->GetThumbnailPath().IsEmpty())
167         {
168                 return;
169         }
170
171         if (state.Equals(SD_CARD_UNMOUNTED, false) && File::IsFileExist(__pPresentationModel->GetThumbnailPath()) == false)
172         {
173                 __pPresentationModel->SetThumbnailPath(L"");
174                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
175         }
176 }
177
178
179 void
180 GroupEditorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
181 {
182         switch (actionId)
183         {
184         case IDA_HEADER_SAVE:
185                 {
186                         long long avialableMemory = 0;
187                         result r = E_SUCCESS;
188
189                         String key(RUNTIMEINFO_INTERNAL_MEMORY_KEY);
190                         r  = RuntimeInfo::GetValue(key, avialableMemory);
191                         if(avialableMemory == 0)
192                         {
193                                 int modalResult = 0;
194                                 MessageBox memoryFullMessageBox;
195                                 memoryFullMessageBox.Construct(L"", ResourceManager::GetString(L"IDS_EMAIL_POP_DEVICE_STORAGE_FULL"), MSGBOX_STYLE_NONE, 1000);
196                                 memoryFullMessageBox.ShowAndWait(modalResult);
197                                 return;
198                         }
199
200                         __pTableView->RefreshItem(1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
201
202                         if (__pPresentationModel->IsDefaultCategory() == false && __pPresentationModel->IsDuplicatedCategory() == true)
203                         {
204                                 Footer* pFooter = GetFooter();
205                                 pFooter->SetItemEnabled(0, false);
206                                 break;
207                         }
208
209                         if (__isEditMode)
210                         {
211                                 r = __pPresentationModel->UpdateCategory();
212                                 if (r == E_FAILURE)
213                                 {
214                                         __isSaved = true;
215                                         OnCategoriesChanged();
216                                 }
217                                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to update category", GetErrorMessage(r));
218                         }
219                         else
220                         {
221                                 r = __pPresentationModel->AddCategory();
222                                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to add category", GetErrorMessage(r));
223                         }
224
225                         SetFocus();
226                         __isSaved = true;
227                 }
228                 break;
229         case IDA_BUTTON_GALLERY:
230                 {
231                         LaunchAppControl(PROVIDER_ID_GALLERY, OPERATION_ID_PICK);
232                 }
233                 break;
234         case IDA_BUTTON_TAKE_PHOTO:
235                 {
236                         LaunchAppControl(PROVIDER_ID_CAMERA, OPERATION_ID_CREATE_CONTENT);
237                 }
238                 break;
239         case IDA_BUTTON_REMOVE:
240                 {
241                         __pPresentationModel->SetThumbnailPath(String());
242                         __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
243                         __pTableView->RefreshItem(1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
244                 }
245                 break;
246         case IDA_BUTTON_RINGTONE_CLEAR:
247                 {
248                         __pPresentationModel->SetRingtone(String());
249                         __pTableView->RefreshItem(2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
250                 }
251                 break;
252         default:
253                 break;
254         }
255 }
256
257 void
258 GroupEditorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
259                                                                    const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
260 {
261         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
262         pContactsApp->AddContactsAppChangeEventListener(*this);
263
264         RecordId categoryId = INVALID_RECORD_ID;
265
266         if (pArgs != null)
267         {
268                 IEnumerator* pEnum = pArgs->GetEnumeratorN();
269                 if (pEnum->MoveNext() == E_SUCCESS)
270                 {
271                         Integer* pCategoryId = static_cast<Integer*>(pEnum->GetCurrent());
272                         if (pCategoryId != null)
273                         {
274                                 categoryId = pCategoryId->ToInt();
275                                 __isEditMode = true;
276                         }
277                 }
278                 delete pEnum;
279
280                 pArgs->RemoveAll(true);
281                 delete pArgs;
282         }
283
284         __pPresentationModel = new (std::nothrow) GroupPresentationModel();
285         __pPresentationModel->Construct(categoryId);
286         __pPresentationModel->AddContactChangeListener(*this);
287
288         Header* pHeader = GetHeader();
289         if (__isEditMode)
290         {
291                 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_PB_OPT2_EDIT_GROUPS"));
292         }
293         else
294         {
295                 pHeader->SetTitleText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
296         }
297
298         Footer* pFooter = GetFooter();
299         if (__isEditMode)
300         {
301                 pFooter->SetItemEnabled(0, true);
302         }
303         else
304         {
305                 pFooter->SetItemEnabled(0, false);
306         }
307
308 }
309
310 void
311 GroupEditorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
312                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
313 {
314         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
315         pContactsApp->RemoveContactsAppChangeEventListener(*this);
316
317         __pPresentationModel->RemoveContactChangeListener(*this);
318 }
319
320 int
321 GroupEditorForm::GetItemCount(void)
322 {
323         return ITEM_COUNT;
324 }
325
326 Tizen::Ui::Controls::TableViewItem*
327 GroupEditorForm::CreateItem(int itemIndex, int itemWidth)
328 {
329         Label* pSubjectLabel = null;
330         Label* pContentLabel = null;
331         int itemHeight = H_ITEM;
332
333         if (itemIndex == 0)
334         {
335                 itemHeight = Y_THUMBNAIL * 2 + H_THUMBNAIL;
336         }
337
338         TableViewItem* pItem = new (std::nothrow) TableViewItem();
339         pItem->Construct(Dimension(itemWidth, itemHeight), TABLE_VIEW_ANNEX_STYLE_NORMAL);
340
341         if (itemIndex == 0)
342         {
343                 Label* pThumbnailLabel = new (std::nothrow) Label();
344                 pThumbnailLabel->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2, Y_THUMBNAIL, H_THUMBNAIL, H_THUMBNAIL), L"");
345                 pThumbnailLabel->SetName(THUMBNAIL_LABEL);
346                 pItem->AddControl(pThumbnailLabel);
347                 Label* pEmptyThumbnailLabel = new (std::nothrow) Label();
348                 pEmptyThumbnailLabel->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2, Y_THUMBNAIL, H_THUMBNAIL, H_THUMBNAIL), L"");
349                 pEmptyThumbnailLabel->SetName(THUMBNAIL_EMPTY_LABEL);
350                 pEmptyThumbnailLabel->SetBackgroundColor(COLOR_THUMBNAIL);
351                 pItem->AddControl(pEmptyThumbnailLabel);
352
353                 if (__pPresentationModel->GetThumbnailPath().IsEmpty() == false)
354                 {
355                         Bitmap* pThumbnail = null;
356                         ImageBuffer thumbnailImageBuffer;
357                         result r = thumbnailImageBuffer.Construct(__pPresentationModel->GetThumbnailPath());
358                         if (r == E_SUCCESS)
359                         {
360                                 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_RGB565, BUFFER_SCALING_NONE);
361                         }
362                         pThumbnailLabel->SetBackgroundBitmap(*pThumbnail);
363                         delete pThumbnail;
364
365                         pEmptyThumbnailLabel->SetShowState(false);
366                 }
367
368                 Button* pButtonAdd = new (std::nothrow) Button();
369                 pButtonAdd->Construct(Rectangle((itemWidth - H_ICON_BUTTON) / 2, (H_THUMBNAIL - H_ICON_BUTTON) / 2 + Y_THUMBNAIL, H_ICON_BUTTON, H_ICON_BUTTON), L"");
370                 pButtonAdd->SetActionId(IDA_BUTTON_GALLERY);
371                 pButtonAdd->AddActionEventListener(*this);
372                 pButtonAdd->SetName(ADD_BUTTON);
373                 Bitmap* pIconNormal = ResourceManager::GetBitmapN(IDB_ICON_ADD_NORMAL);
374                 Bitmap* pIconPressed = ResourceManager::GetBitmapN(IDB_ICON_ADD_PRESSED);
375                 if (pIconNormal != null)
376                 {
377                         pButtonAdd->SetNormalBackgroundBitmap(*pIconNormal);
378                         delete pIconNormal;
379                 }
380                 if (pIconPressed != null)
381                 {
382                         pButtonAdd->SetPressedBackgroundBitmap(*pIconPressed);
383                         delete pIconPressed;
384                 }
385                 pItem->AddControl(pButtonAdd);
386
387                 Button* pButtonCamera = new (std::nothrow) Button();
388                 pButtonCamera->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2 + H_THUMBNAIL, Y_THUMBNAIL + H_THUMBNAIL - H_ICON_BUTTON, H_ICON_BUTTON, H_ICON_BUTTON), L"");
389                 pButtonCamera->SetActionId(IDA_BUTTON_TAKE_PHOTO);
390                 pButtonCamera->AddActionEventListener(*this);
391                 pButtonCamera->SetName(CAMERA_BUTTON);
392                 pIconNormal = ResourceManager::GetBitmapN(IDB_ICON_CAMERA_NORMAL);
393                 pIconPressed = ResourceManager::GetBitmapN(IDB_ICON_CAMERA_PRESSED);
394                 if (pIconNormal != null)
395                 {
396                         pButtonCamera->SetNormalBackgroundBitmap(*pIconNormal);
397                         delete pIconNormal;
398                 }
399                 if (pIconPressed != null)
400                 {
401                         pButtonCamera->SetPressedBackgroundBitmap(*pIconPressed);
402                         delete pIconPressed;
403                 }
404                 pItem->AddControl(pButtonCamera);
405
406                 Button* pButtonRemove = new (std::nothrow) Button();
407                 pButtonRemove->Construct(Rectangle((itemWidth - H_THUMBNAIL) / 2 - X_REMOVE_BUTTON_MARGIN, Y_REMOVE_BUTTON, H_ICON_BUTTON, H_ICON_BUTTON), L"");
408                 pButtonRemove->SetActionId(IDA_BUTTON_REMOVE);
409                 pButtonRemove->AddActionEventListener(*this);
410                 pButtonRemove->SetName(REMOVE_BUTTON);
411                 pIconNormal = ResourceManager::GetBitmapN(IDB_ICON_REMOVE_NORMAL);
412                 pIconPressed = ResourceManager::GetBitmapN(IDB_ICON_REMOVE_PRESSED);
413                 if (pIconNormal != null)
414                 {
415                         pButtonRemove->SetNormalBitmap(Point(0, 0), *pIconNormal);
416                         delete pIconNormal;
417                 }
418                 if (pIconPressed != null)
419                 {
420                         pButtonRemove->SetPressedBitmap(Point(0, 0), *pIconPressed);
421                         delete pIconPressed;
422                 }
423
424                 pIconNormal = ResourceManager::GetBitmapN(IDB_REMOVE_BG_NORMAL);
425                 pIconPressed = ResourceManager::GetBitmapN(IDB_REMOVE_BG_PRESSED);
426                 if (pIconNormal != null)
427                 {
428                         pButtonRemove->SetNormalBackgroundBitmap(*pIconNormal);
429                         delete pIconNormal;
430                 }
431                 if (pIconPressed != null)
432                 {
433                         pButtonRemove->SetPressedBackgroundBitmap(*pIconPressed);
434                         delete pIconPressed;
435                 }
436                 pItem->AddControl(pButtonRemove);
437
438                 if (__pPresentationModel->GetThumbnailPath().IsEmpty() == true)
439                 {
440                         pButtonRemove->SetShowState(false);
441                 }
442                 else
443                 {
444                         pButtonAdd->SetShowState(false);
445                 }
446                 pItem->SetBackgroundColor(COLOR_TABLE_BG, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
447                 pItem->SetBackgroundColor(COLOR_TABLE_BG, TABLE_VIEW_ITEM_DRAWING_STATUS_PRESSED);
448         }
449         else if (itemIndex == 1)
450         {
451                 EditField* pEditField = new (std::nothrow) EditField();
452                 pEditField->Construct(Rectangle(0, 0, itemWidth, H_ITEM), EDIT_FIELD_STYLE_NORMAL, INPUT_STYLE_OVERLAY, EDIT_FIELD_TITLE_STYLE_TOP, !__pPresentationModel->IsDefaultCategory());
453                 pEditField->AddTextEventListener(*this);
454                 pEditField->AddKeypadEventListener(*this);
455                 pEditField->SetText(__pPresentationModel->GetCategoryName());
456                 pEditField->SetTitleText(ResourceManager::GetString(L"IDS_PB_BODY_GROUP_NAME_ABB"));
457                 pEditField->SetEnabled(!__pPresentationModel->IsDefaultCategory());
458
459                 if (__isEditMode == true)
460                 {
461                         String categoryName = __pPresentationModel->GetCategoryName();
462                         if (__pPresentationModel->IsDefaultCategory())
463                         {
464                                 if (categoryName.Equals(DEFAULT_GROUP_FAMILY, false))
465                                 {
466                                         categoryName.Clear();
467                                         categoryName = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT_GROUP_FAMILY");
468                                 }
469                                 else if (categoryName.Equals(DEFAULT_GROUP_FRIENDS, false))
470                                 {
471                                         categoryName.Clear();
472                                         categoryName = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT_GROUP_FRIENDS");
473                                 }
474                                 else if (categoryName.Equals(DEFAULT_GROUP_COWORKERS, false))
475                                 {
476                                         categoryName.Clear();
477                                         categoryName = ResourceManager::GetString(L"IDS_PB_BODY_CO_WORKERS");
478                                 }
479                         }
480                         pEditField->SetText(categoryName);
481                 }
482                 pItem->AddControl(pEditField);
483                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
484         }
485         else if (itemIndex == 2)
486         {
487                 pSubjectLabel = new (std::nothrow) Label();
488                 pSubjectLabel->Construct(Rectangle(X_RINGTONE_TEXT, Y_RINGTONE_TITLE, W_RINGTONE_TEXT, H_RINGTONE_TITLE),
489                                                                                                         ResourceManager::GetString(L"IDS_PB_BODY_RINGTONE"));
490                 pSubjectLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
491                 pSubjectLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
492                 pSubjectLabel->SetTextColor(Color(COLOR_RINGTONE_TITLE));
493                 pSubjectLabel->SetTextConfig(FONT_SIZE_RINGTONE_TITLE, LABEL_TEXT_STYLE_NORMAL);
494                 pItem->AddControl(pSubjectLabel);
495
496                 int index = 0;
497                 String ringtonePath = __pPresentationModel->GetRingtone();
498                 String trimmedPath;
499
500                 if (ringtonePath.IsEmpty() == true)
501                 {
502                         trimmedPath = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT");
503                 }
504                 else
505                 {
506                         ringtonePath.LastIndexOf(L"/", ringtonePath.GetLength() - 1, index);
507                         if (index != 0)
508                         {
509                                 ringtonePath.SubString(index + 1, trimmedPath);
510                         }
511                 }
512
513                 pContentLabel = new (std::nothrow) Label();
514                 pContentLabel->Construct(Rectangle(X_RINGTONE_TEXT, Y_RINGTONE_NAME, W_RINGTONE_TEXT, H_RINGTONE_NAME), trimmedPath);
515                 pContentLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
516                 pContentLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
517                 pContentLabel->SetTextColor(Color(COLOR_RINGTONE));
518                 pContentLabel->SetTextConfig(FONT_SIZE_RINGTONE, LABEL_TEXT_STYLE_BOLD);
519                 pItem->AddControl(pContentLabel);
520
521                 Button* pClearButton = new (std::nothrow) Button();
522                 pClearButton->Construct(Rectangle(itemWidth - X_REFRESH_BUTTON_MARGIN, (pItem->GetHeight() - H_ICON_BUTTON) / 2, H_ICON_BUTTON, H_ICON_BUTTON));
523                 pClearButton->SetActionId(IDA_BUTTON_RINGTONE_CLEAR);
524                 pClearButton->AddActionEventListener(*this);
525
526                 Bitmap* pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_NORMAL);
527                 if (pReset != null)
528                 {
529                         pClearButton->SetNormalBitmap(Point(0, 0), *pReset);
530                         delete pReset;
531                 }
532                 pReset = ResourceManager::GetBitmapN(IDB_DETAILS_RESET_PRESSED);
533                 if (pReset != null)
534                 {
535                         pClearButton->SetPressedBitmap(Point(0, 0), *pReset);
536                         delete pReset;
537                 }
538
539                 pItem->AddControl(pClearButton);
540                 pItem->SetIndividualSelectionEnabled(pClearButton, true);
541
542                 pItem->SetBackgroundColor(COLOR_THUMBNAIL, TABLE_VIEW_ITEM_DRAWING_STATUS_NORMAL);
543         }
544
545         return pItem;
546 }
547
548 bool
549 GroupEditorForm::DeleteItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
550 {
551         delete pItem;
552         return true;
553 }
554
555 void
556 GroupEditorForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
557 {
558         if (pItem == null)
559         {
560                 return;
561         }
562
563         if (itemIndex == 0)
564         {
565                 Button* pRemoveButton = static_cast<Button*>(pItem->GetControl(REMOVE_BUTTON, false));
566                 Button* pAddButton = static_cast<Button*>(pItem->GetControl(ADD_BUTTON, false));
567                 Label* pThumbnailLabel = static_cast<Label*>(pItem->GetControl(THUMBNAIL_LABEL, false));
568                 Label* pThumbnailEmptyLabel = static_cast<Label*>(pItem->GetControl(THUMBNAIL_EMPTY_LABEL, false));
569                 if (pRemoveButton == null || pAddButton == null ||
570                         pThumbnailLabel == null || pThumbnailEmptyLabel == null)
571                 {
572                         return;
573                 }
574
575                 if (__pPresentationModel->GetThumbnailPath().IsEmpty() == true)
576                 {
577                         pRemoveButton->SetShowState(false);
578                         pThumbnailLabel->SetShowState(false);
579                         pThumbnailEmptyLabel->SetShowState(true);
580                         pAddButton->SetShowState(true);
581                 }
582                 else
583                 {
584                         pAddButton->SetShowState(false);
585                         pThumbnailEmptyLabel->SetShowState(false);
586                         pThumbnailLabel->SetShowState(true);
587                         pRemoveButton->SetShowState(true);
588
589                         Bitmap* pThumbnail = null;
590                         ImageBuffer thumbnailImageBuffer;
591                         result r = thumbnailImageBuffer.Construct(__pPresentationModel->GetThumbnailPath());
592                         if (r == E_SUCCESS)
593                         {
594                                 pThumbnail = thumbnailImageBuffer.GetBitmapN(BITMAP_PIXEL_FORMAT_ARGB8888, BUFFER_SCALING_NONE);
595                         }
596                         pThumbnailLabel->SetBackgroundBitmap(*pThumbnail);
597                         delete pThumbnail;
598
599                         pThumbnailLabel->Invalidate(false);
600                 }
601         }
602         else if (itemIndex == 1)
603         {
604                 EditField* pEditField = static_cast<EditField*>(pItem->GetControl(0));
605                 if (pEditField == null)
606                 {
607                         return;
608                 }
609
610                 String groupName = pEditField->GetText();
611                 groupName.Trim();
612
613                 if (groupName.GetLength() > 0)
614                 {
615                         Footer* pFooter = GetFooter();
616                         pFooter->SetItemEnabled(0, true);
617                         pFooter->Invalidate(true);
618                 }
619
620                 if (__pPresentationModel->IsDefaultCategory() == false && __pPresentationModel->IsDuplicatedCategory() == true)
621                 {
622                         pEditField->SetEnabled(true);
623                         pEditField->Clear();
624                         pEditField->SetGuideTextColor(Color(COLOR_GUIDE_TEXT));
625                         pEditField->SetGuideText(ResourceManager::GetString(L"IDS_PB_POP_GROUP_ALREADY_IN_USE"));
626                         pEditField->SetFocus();
627                         pEditField->Invalidate(false);
628                 }
629         }
630         else if (itemIndex == 2)
631         {
632                 int index = 0;
633                 String ringtonePath = __pPresentationModel->GetRingtone();
634                 String trimmedPath;
635
636                 if (ringtonePath.IsEmpty() == true)
637                 {
638                         trimmedPath = ResourceManager::GetString(L"IDS_PB_BODY_DEFAULT");
639                 }
640                 else
641                 {
642                         ringtonePath.LastIndexOf(L"/", ringtonePath.GetLength() - 1, index);
643                         if (index != 0)
644                         {
645                                 ringtonePath.SubString(index + 1, trimmedPath);
646                         }
647                 }
648
649                 Label* pRingtoneName = static_cast<Label*>(pItem->GetControl(1));
650                 if (pRingtoneName != null)
651                 {
652                         pRingtoneName->SetText(trimmedPath);
653                         pRingtoneName->Invalidate(true);
654                 }
655         }
656 }
657
658 int
659 GroupEditorForm::GetDefaultItemHeight(void)
660 {
661         return H_ITEM;
662 }
663
664 void
665 GroupEditorForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem, Tizen::Ui::Controls::TableViewItemStatus status)
666 {
667         if (status == TABLE_VIEW_ITEM_STATUS_SELECTED && itemIndex == 2)
668         {
669                 LaunchAppControl(PROVIDER_ID_FILEMANAGER, OPERATION_ID_PICK);
670         }
671 }
672
673 void
674 GroupEditorForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView, int itemIndex, Tizen::Ui::Controls::TableViewContextItem* pContextItem, bool activated)
675 {
676 }
677
678 void
679 GroupEditorForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView, int itemIndexFrom, int itemIndexTo)
680 {
681 }
682
683 void
684 GroupEditorForm::OnTextValueChanged(const Tizen::Ui::Control& source)
685 {
686         EditField* pEditField = const_cast<EditField *>(static_cast<const EditField *>(&source));
687         if (pEditField == null)
688         {
689                 return;
690         }
691
692         String existingCategoryName = __pPresentationModel->GetCategoryName();
693         String name = pEditField->GetText();
694
695         if (name.IsEmpty())
696         {
697                 pEditField->SetGuideText(String(CHARACTER_SPACE));
698                 pEditField->Invalidate(false);
699
700                 Footer* pFooter = GetFooter();
701                 pFooter->SetItemEnabled(0, false);
702                 pFooter->Invalidate(true);
703                 return;
704         }
705         name.Trim();
706         __pPresentationModel->SetCategoryName(name);
707
708         bool isSaveEnabled = false;
709         wchar_t ch;
710
711         for (int index = 0; index < name.GetLength(); index++)
712         {
713                 name.GetCharAt(index, ch);
714
715                 if (ch != L' ')
716                 {
717                         isSaveEnabled = true;
718                         break;
719                 }
720         }
721
722         Footer* pFooter = GetFooter();
723
724         pFooter->SetItemEnabled(0, isSaveEnabled);
725         pFooter->Invalidate(true);
726 }
727
728 void
729 GroupEditorForm::OnTextValueChangeCanceled(const Tizen::Ui::Control& source)
730 {
731 }
732
733 void
734 GroupEditorForm::OnKeypadWillOpen(Tizen::Ui::Control& source)
735 {
736 }
737
738 void
739 GroupEditorForm::OnKeypadOpened(Tizen::Ui::Control& source)
740 {
741         Rectangle clientBounds = GetClientAreaBounds();
742
743         __pTableView->SetSize(clientBounds.width, clientBounds.height);
744 }
745
746 void
747 GroupEditorForm::OnKeypadClosed(Tizen::Ui::Control& source)
748 {
749 }
750
751 void
752 GroupEditorForm::OnKeypadActionPerformed(Tizen::Ui::Control& source, Tizen::Ui::KeypadAction keypadAction)
753 {
754 }
755
756 void
757 GroupEditorForm::OnKeypadBoundsChanged(Tizen::Ui::Control& source)
758 {
759         Rectangle clientBounds = GetClientAreaBounds();
760
761         __pTableView->SetSize(clientBounds.width, clientBounds.height);
762 }
763
764 void
765 GroupEditorForm::OnAppControlCompleteResponseReceived(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId, Tizen::App::AppCtrlResult appControlResult, const Tizen::Base::Collection::IMap* pExtraData)
766 {
767         AppLogDebug("ENTER");
768
769         SetEnabled(true);
770         Invalidate(true);
771
772         TryReturnVoid(appControlResult == APP_CTRL_RESULT_SUCCEEDED, "[E_FAILURE] The result of an appcontrol is not succeeded.");
773         TryReturnVoid(pExtraData != null, "[E_FAILURE] The extra data is null.");
774
775         const String *pResultString = null;
776         const ArrayList* pResultList = dynamic_cast<const ArrayList*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
777         if (pResultList != null)
778         {
779                 pResultString = static_cast<const String*>(pResultList->GetAt(0));
780         }
781         else
782         {
783                 pResultString = static_cast<const String*>(pExtraData->GetValue(String(OUTPUT_KEY_SELECTED)));
784         }
785         TryReturnVoid(pResultString != null, "[E_FAILURE] Unable to get file path.");
786
787         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
788         {
789                 __pPresentationModel->SetThumbnailPath(*pResultString);
790                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
791         }
792         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
793         {
794                 __pPresentationModel->SetThumbnailPath(*pResultString);
795                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
796         }
797         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
798         {
799                 __pPresentationModel->SetRingtone(*pResultString);
800                 __pTableView->RefreshItem(2, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
801         }
802
803         __pTableView->RefreshItem(1, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
804
805         AppLogDebug("EXIT");
806 }
807
808 result
809 GroupEditorForm::LaunchAppControl(const Tizen::App::AppId& appId, const Tizen::Base::String& operationId)
810 {
811         result r = E_SUCCESS;
812
813         SetFocus();
814
815         String uri;
816         String mimeType;
817         HashMap extraData;
818         extraData.Construct();
819
820         if (appId.Equals(String(PROVIDER_ID_CAMERA)) && operationId.Equals(String(OPERATION_ID_CREATE_CONTENT)))
821         {
822                 mimeType.Append(INPUT_MIME_TYPE_CAMERA);
823                 extraData.Add(new (std::nothrow) String(INPUT_KEY_ALLOW_SWITCH), new (std::nothrow) String(INPUT_VALUE_FALSE));
824         }
825         else if (appId.Equals(String(PROVIDER_ID_GALLERY)) && operationId.Equals(String(OPERATION_ID_PICK)))
826         {
827                 mimeType.Append(INPUT_MIME_TYPE_GALLERY);
828                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
829         }
830         else if (appId.Equals(String(PROVIDER_ID_FILEMANAGER)) && operationId.Equals(String(OPERATION_ID_PICK)))
831         {
832                 mimeType.Append(INPUT_MIME_TYPE_AUDIO);
833                 extraData.Add(new (std::nothrow) String(INPUT_KEY_SELECTION_MODE), new (std::nothrow) String(INPUT_DATA_SELECTION_MODE_SINGLE));
834         }
835
836         AppControl* pAppControl = AppManager::FindAppControlN(appId, operationId);
837
838         if (pAppControl != null)
839         {
840                 r = pAppControl->Start(&uri, &mimeType, &extraData, this);
841                 TryCatch(r == E_SUCCESS, , "[%s] Unable to launch app control", GetErrorMessage(r));
842
843                 SetEnabled(false);
844                 Invalidate(true);
845         }
846
847 CATCH:
848         extraData.RemoveAll(true);
849         delete pAppControl;
850
851         return r;
852 }
853
854 void
855 GroupEditorForm::OnContactsChanged(void)
856 {
857 }
858
859 void
860 GroupEditorForm::OnCategoriesChanged(void)
861 {
862         result r = E_SUCCESS;
863
864         SceneManager* pSceneManager = SceneManager::GetInstance();
865
866         SceneId previousSceneId;
867         IListT<SceneId>* pHistoryList = pSceneManager->GetSceneHistoryN();
868         if (pHistoryList != null)
869         {
870                 int count = pHistoryList->GetCount();
871                 r = pHistoryList->GetAt(count - 1, previousSceneId);
872                 delete pHistoryList;
873                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to get previous scene id", GetErrorMessage(r));
874         }
875
876         if (previousSceneId.Equals(IDSCN_CONTACT_DETAILS, true) || previousSceneId.Equals(IDSCN_CONTACT_EDITOR, true))
877         {
878                 if (__pPresentationModel->GetCategoryCount() > 0)
879                 {
880                         ArrayList* pArg = new (std::nothrow) ArrayList();
881                         pArg->Construct();
882                         pArg->Add(new (std::nothrow) Integer(__pPresentationModel->GetCategoryId()));
883
884                         r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pArg);
885                         TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
886
887                         return;
888                 }
889         }
890
891         if (__isSaved)
892         {
893                 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
894                 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to go backward", GetErrorMessage(r));
895         }
896 }
897
898 void
899 GroupEditorForm::OnForeground(void)
900 {
901         if ( File::IsFileExist(__pPresentationModel->GetThumbnailPath()) == false)
902         {
903                 __pPresentationModel->SetThumbnailPath(L"");
904                 __pTableView->RefreshItem(0, TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
905         }
906         if (IsEnabled() == false)
907         {
908                 SetEnabled(true);
909                 Invalidate(true);
910         }
911 }
912
913 void
914 GroupEditorForm::OnBackground(void)
915 {
916 }