Initialize Tizen 2.3
[apps/osp/Contacts.git] / src / CtFavoriteListEditorPanel.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        CtFavoriteListEditorPanel.cpp
19  * @brief       This is the implementation file for the FavoriteListEditorPanel class.
20  */
21
22 #include "CtContactsApp.h"
23 #include "CtCommonUtil.h"
24 #include "CtFavoriteListEditorPanel.h"
25 #include "CtFavoriteListPresentationModel.h"
26 #include "CtMainForm.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::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38
39 static const int IDA_FOOTER_REMOVE_FAVORITE = 0;
40 static const int IDA_FOOTER_CANCEL = 1;
41 static const int IDA_FOOTER_DONE = 2;
42 static const int IDA_HEADER_CONTACTS = 10;
43 static const int IDA_HEADER_GROUPS = 11;
44 static const int IDA_HEADER_FAVORITES = 12;
45 static const int IDA_POPUP_CONTACT_VALUE_CLOSE = 20;
46
47 static const int W_INITAIL_PANEL = 10;
48 static const int H_INITIAL_PANEL = 10;
49 static const int W_ICONLISTVIEW_LEFT_MARGIN = 14;
50 static const int W_ICONLISTVIEW_RIGHT_MARGIN = 10;
51 static const int W_ICONLISTVIEW_ITEM = 216;
52 static const int H_ICONLISTVIEW_ITEM = 216;
53 static const int H_TEXT_BACKGROUND = 64;
54 static const int H_TEXT_SPACE = 96;
55 static const int W_ITEM_SPACE = 24;
56 static const int H_ITEM_SPACE = 24;
57 static const int W_CONTACT_VALUE_POPUP = 688;
58 static const int H_CONTACT_VALUE_POPUP = 532;
59 static const int H_CONTACT_VALUE_POPUP_LIST_VIEW = 338;
60 static const int Y_CLOSE_BUTTON = 358;
61 static const int W_CLOSE_BUTTON = 394;
62 static const int H_CLOSE_BUTTON = 74;
63 static const int X_EMPTY_IMAGE = 220;
64 static const int Y_EMPTY_IMAGE = 300;
65 static const int W_EMPTY_IMAGE = 280;
66 static const int H_EMPTY_IMAGE = 280;
67 static const int Y_EMPTY_COMMENT = 618;
68 static const int H_EMPTY_COMMENT = 38;
69 static const int H_BOTTOM_LABEL = 48;
70 static const int W_NAME_TEXT_MARGIN = 10;
71
72 static const int FONT_SIZE_WITH_THUMBNAIL = 24;
73 static const int FONT_SIZE_EMPTY_COMMENT = 32;
74 static const int FONT_SIZE = 40;
75 static const int FONT_SIZE_BOTTOM_LABEL = 32;
76
77 static const wchar_t* IDB_NO_FAVORITES = L"00_Nocontents_picture.png";
78
79 static const unsigned int COLOR_ITEM_BACKGROUND = Color32<201, 201, 201>::Value;
80 static const unsigned int COLOR_ITEM_TEXT_BACKGROUND = Color32<0, 0, 0, 89>::Value;
81 static const unsigned int COLOR_TEXT_WITH_THUMBNAIL = Color32<249, 249, 249>::Value;
82 static const unsigned int COLOR_TEXT = Color32<255, 255, 255>::Value;
83 static const unsigned int COLOR_LINE = Color32<225, 225, 225, 26>::Value;
84 static const unsigned int COLOR_EMPTY_COMMENT = Color32<102, 102, 102>::Value;
85 static const unsigned int COLOR_BOTTOM_LABEL_BG = Color32<68, 68, 68>::Value;
86 static const unsigned int COLOR_BOTTOM_LABEL_FONT = Color32<255, 255, 255>::Value;
87
88 FavoriteListEditorPanel::FavoriteListEditorPanel(void)
89 : __pFavoriteListView(null)
90 , __pMultipleContactValuePopup(null)
91 , __pEmptyImageLabel(null)
92 , __pEmptyCommentLabel(null)
93 , __pBottomLabel(null)
94 , __pTempContactValueHashMap(null)
95 , __pPresentationModel(null)
96 , __pContactValueListProvider(null)
97 {
98 }
99
100 FavoriteListEditorPanel::~FavoriteListEditorPanel(void)
101 {
102 }
103
104 void
105 FavoriteListEditorPanel::Initialize(void)
106 {
107         Construct(Rectangle(0, 0, W_INITAIL_PANEL, H_INITIAL_PANEL));
108 }
109
110 result
111 FavoriteListEditorPanel::OnInitializing(void)
112 {
113         result r = E_SUCCESS;
114
115         const Form* pForm = dynamic_cast<Form*>(GetParent());
116         AppAssert(pForm);
117
118         FloatRectangle clientBounds = ((MainForm*)pForm)->GetClientBounds();
119
120         SetBounds(FloatRectangle(0, 0, clientBounds.width, clientBounds.height));
121
122         __pPresentationModel = FavoriteListPresentationModel::GetInstance();
123
124         __pFavoriteListView = new (std::nothrow) IconListView();
125         __pFavoriteListView->Construct(Rectangle(0, 0, clientBounds.width, clientBounds.height - H_BOTTOM_LABEL), Dimension(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM), ICON_LIST_VIEW_STYLE_MARK);
126         __pFavoriteListView->SetItemProvider(*this);
127         __pFavoriteListView->AddIconListViewItemEventListener(*this);
128         __pFavoriteListView->SetItemLayoutHorizontalAlignment(ALIGNMENT_LEFT);
129         __pFavoriteListView->SetItemLayoutVerticalAlignment(ALIGNMENT_TOP);
130         __pFavoriteListView->SetItemSpacing(W_ITEM_SPACE, H_ITEM_SPACE);
131         __pFavoriteListView->SetMargin(MARGIN_TYPE_LEFT, W_ICONLISTVIEW_LEFT_MARGIN);
132         __pFavoriteListView->SetMargin(MARGIN_TYPE_RIGHT, W_ICONLISTVIEW_RIGHT_MARGIN);
133         __pFavoriteListView->SetCheckBoxPosition(ICON_LIST_VIEW_CHECK_BOX_POSITION_TOP_LEFT);
134         __pFavoriteListView->SetTouchAnimationEnabled(false);
135
136         AddControl(__pFavoriteListView);
137
138         __pEmptyImageLabel = new (std::nothrow) Label();
139         __pEmptyImageLabel->Construct(Rectangle(X_EMPTY_IMAGE, Y_EMPTY_IMAGE, W_EMPTY_IMAGE, H_EMPTY_IMAGE), L"");
140         Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_NO_FAVORITES);
141         if (pBitmap != null)
142         {
143                 __pEmptyImageLabel->SetBackgroundBitmap(*pBitmap);
144                 delete pBitmap;
145         }
146         __pEmptyImageLabel->SetShowState(false);
147
148         AddControl(__pEmptyImageLabel);
149
150         __pEmptyCommentLabel = new (std::nothrow) Label();
151         __pEmptyCommentLabel->Construct(Rectangle(0, Y_EMPTY_COMMENT, clientBounds.width, H_EMPTY_COMMENT),
152                                                                                                                                 ResourceManager::GetString(L"IDS_PB_BODY_NO_FAVOURITES"));
153         __pEmptyCommentLabel->SetTextConfig(FONT_SIZE_EMPTY_COMMENT, LABEL_TEXT_STYLE_NORMAL);
154         __pEmptyCommentLabel->SetTextColor(Color(COLOR_EMPTY_COMMENT));
155         __pEmptyCommentLabel->SetShowState(false);
156
157         AddControl(__pEmptyCommentLabel);
158
159         __pBottomLabel = new (std::nothrow) Label();
160         __pBottomLabel->Construct(FloatRectangle(0, clientBounds.height - H_BOTTOM_LABEL, clientBounds.width, H_BOTTOM_LABEL),
161                                                                 ResourceManager::GetString(L"IDS_COM_POP_SELECTED") + INITIAL_SELECTED_COUNT);
162         __pBottomLabel->SetBackgroundColor(Color(COLOR_BOTTOM_LABEL_BG));
163         __pBottomLabel->SetTextColor(Color(COLOR_BOTTOM_LABEL_FONT));
164         __pBottomLabel->SetTextConfig(FONT_SIZE_BOTTOM_LABEL, LABEL_TEXT_STYLE_BOLD);
165         __pBottomLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
166         __pBottomLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
167         AddControl(__pBottomLabel);
168
169         __pTempContactValueHashMap = new (std::nothrow) HashMap();
170         __pTempContactValueHashMap->Construct();
171
172         return r;
173 }
174
175 result
176 FavoriteListEditorPanel::OnTerminating(void)
177 {
178         result r = E_SUCCESS;
179
180         if (__pPresentationModel != null)
181         {
182                 __pPresentationModel->RemoveContactChangeListener(*this);
183         }
184
185         if (__pTempContactValueHashMap != null)
186         {
187                 __pTempContactValueHashMap->RemoveAll(true);
188                 delete __pTempContactValueHashMap;
189         }
190
191         delete __pMultipleContactValuePopup;
192
193         return r;
194 }
195
196 void
197 FavoriteListEditorPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
198 {
199         SceneManager* pSceneManager = SceneManager::GetInstance();
200         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
201
202         switch (actionId)
203         {
204         case IDA_HEADER_CONTACTS:
205                 {
206                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
207                         {
208                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
209                                 {
210                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
211                                 }
212                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
213                                 {
214                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
215                                 }
216                         }
217                         else
218                         {
219                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
220                         }
221                 }
222                 break;
223         case IDA_HEADER_GROUPS:
224                 {
225                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
226                 }
227                 break;
228         case IDA_HEADER_FAVORITES:
229                 {
230                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
231                         {
232                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
233                                 {
234                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
235                                 }
236                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
237                                 {
238                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST_EDITOR));
239                                 }
240                         }
241                         else
242                         {
243                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
244                         }
245                 }
246                 break;
247         case IDA_FOOTER_REMOVE_FAVORITE:
248                 {
249                         RemoveFavorites();
250                         pSceneManager->GoBackward(BackwardSceneTransition());
251                 }
252                 break;
253         case IDA_FOOTER_CANCEL:
254                 {
255                         pSceneManager->GoBackward(BackwardSceneTransition());
256                 }
257                 break;
258         case IDA_FOOTER_DONE:
259                 {
260                         ReturnMultipleValues();
261                 }
262                 break;
263         case IDA_POPUP_CONTACT_VALUE_CLOSE:
264                 {
265                         HideContactValuePopup();
266                 }
267                 break;
268         default:
269                 break;
270         }
271 }
272
273 void
274 FavoriteListEditorPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
275 {
276         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
277
278         const Form* pForm = dynamic_cast<Form*>(GetParent());
279         AppAssert(pForm);
280
281         Header* pHeader = pForm->GetHeader();
282         pHeader->AddActionEventListener(*this);
283
284         Footer* pFooter = pForm->GetFooter();
285         pFooter->RemoveAllItems();
286         pFooter->RemoveAllButtons();
287         pFooter->AddActionEventListener(*this);
288
289         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
290         {
291                 FloatRectangle clientBounds = ((MainForm*)pForm)->GetClientBounds();
292
293                 SetBounds(FloatRectangle(0, 0, clientBounds.width, clientBounds.height));
294
295                 pFooter->SetShowState(true);
296
297                 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
298                 __pFavoriteListView->UpdateList();
299
300                 FooterItem footerItemDone;
301                 footerItemDone.Construct(IDA_FOOTER_DONE);
302                 footerItemDone.SetText(ResourceManager::GetString(L"IDS_COM_SK_DONE"));
303                 pFooter->AddItem(footerItemDone);
304
305                 if (__pPresentationModel->GetFavoriteCount() > 0)
306                 {
307                         for (int index = 0; index < __pPresentationModel->GetFavoriteCount(); index++)
308                         {
309                                 __pFavoriteListView->SetItemChecked(index, false);
310                         }
311
312                         pFooter->SetItemEnabled(0, false);
313
314                         __pFavoriteListView->SetShowState(true);
315                         __pEmptyImageLabel->SetShowState(false);
316                         __pEmptyCommentLabel->SetShowState(false);
317                 }
318                 else
319                 {
320                         pFooter->SetItemEnabled(0, false);
321                         __pFavoriteListView->SetShowState(false);
322                         __pEmptyImageLabel->SetShowState(true);
323                         __pEmptyCommentLabel->SetShowState(true);
324                         __pBottomLabel->SetShowState(false);
325                 }
326         }
327         else
328         {
329                 for (int index = 0; index < __pPresentationModel->GetFavoriteCount(); index++)
330                 {
331                         __pFavoriteListView->SetItemChecked(index, false);
332                 }
333
334                 __pPresentationModel->InitializeFavoriteList();
335                 __pFavoriteListView->UpdateList();
336
337                 if (__pPresentationModel->GetFavoriteCount() > 0)
338                 {
339                         __pFavoriteListView->SetShowState(true);
340                         __pEmptyImageLabel->SetShowState(false);
341                         __pEmptyCommentLabel->SetShowState(false);
342                 }
343                 else
344                 {
345                         __pFavoriteListView->SetShowState(false);
346                         __pEmptyImageLabel->SetShowState(true);
347                         __pEmptyCommentLabel->SetShowState(true);
348                 }
349
350                 FooterItem footerItemCancel;
351                 footerItemCancel.Construct(IDA_FOOTER_CANCEL);
352                 footerItemCancel.SetText(ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
353                 pFooter->AddItem(footerItemCancel);
354
355                 FooterItem footerItemRemove;
356                 footerItemRemove.Construct(IDA_FOOTER_REMOVE_FAVORITE);
357                 footerItemRemove.SetText(ResourceManager::GetString(L"IDS_COM_BODY_REMOVE"));
358                 pFooter->AddItem(footerItemRemove);
359                 pFooter->SetItemEnabled(1, false);
360         }
361
362         UpdateBottomLabel();
363
364         __pPresentationModel->AddContactChangeListener(*this);
365
366         delete pArgs;
367 }
368
369 void
370 FavoriteListEditorPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
371 {
372         const Form* pForm = dynamic_cast<Form*>(GetParent());
373         AppAssert(pForm);
374
375         Header* pHeader = pForm->GetHeader();
376         pHeader->RemoveActionEventListener(*this);
377
378         Footer* pFooter = pForm->GetFooter();
379         pFooter->RemoveActionEventListener(*this);
380
381         __pPresentationModel->RemoveContactChangeListener(*this);
382 }
383
384 void
385 FavoriteListEditorPanel::OnContactsChanged(void)
386 {
387         const Form* pForm = dynamic_cast<Form*>(GetParent());
388         AppAssert(pForm);
389
390         HideContactValuePopup();
391
392         Footer* pFooter = pForm->GetFooter();
393
394         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
395
396         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
397         {
398                 int favoriteCount = __pPresentationModel->GetFavoriteCount();
399                 for (int index = 0; index < favoriteCount; index++)
400                 {
401                         __pFavoriteListView->SetItemChecked(index, false);
402                 }
403
404                 __pPresentationModel->InitializeFavoriteList(pContactsApp->GetReturnType());
405
406                 if (__pPresentationModel->GetFavoriteCount() > 0)
407                 {
408                         pFooter->SetItemEnabled(0, false);
409                         pFooter->Invalidate(true);
410
411                         __pFavoriteListView->SetShowState(true);
412                         __pEmptyImageLabel->SetShowState(false);
413                         __pEmptyCommentLabel->SetShowState(false);
414                         __pBottomLabel->SetShowState(true);
415                 }
416                 else
417                 {
418                         pFooter->SetItemEnabled(0, false);
419
420                         __pFavoriteListView->SetShowState(false);
421                         __pEmptyImageLabel->SetShowState(true);
422                         __pEmptyCommentLabel->SetShowState(true);
423                         __pBottomLabel->SetShowState(false);
424                 }
425         }
426         else
427         {
428                 for (int index = 0; index < __pPresentationModel->GetFavoriteCount(); index++)
429                 {
430                         __pFavoriteListView->SetItemChecked(index, false);
431                 }
432
433                 __pPresentationModel->InitializeFavoriteList();
434
435                 if (__pPresentationModel->GetFavoriteCount() > 0)
436                 {
437                         pFooter->SetItemEnabled(1, false);
438                         pFooter->Invalidate(true);
439
440                         __pFavoriteListView->SetShowState(true);
441                         __pEmptyImageLabel->SetShowState(false);
442                         __pEmptyCommentLabel->SetShowState(false);
443                         __pBottomLabel->SetShowState(true);
444                 }
445                 else
446                 {
447                         pFooter->SetItemEnabled(1, false);
448                         __pFavoriteListView->SetShowState(false);
449                         __pEmptyImageLabel->SetShowState(true);
450                         __pEmptyCommentLabel->SetShowState(true);
451                         __pBottomLabel->SetShowState(false);
452                 }
453         }
454
455         __pFavoriteListView->UpdateList();
456
457         UpdateBottomLabel();
458 }
459
460 void
461 FavoriteListEditorPanel::OnCategoriesChanged(void)
462 {
463 }
464
465 void
466 FavoriteListEditorPanel::OnIconListViewItemReordered(Tizen::Ui::Controls::IconListView &iconListView, int indexFrom, int indexTo)
467 {
468 }
469
470 void
471 FavoriteListEditorPanel::OnIconListViewItemStateChanged(Tizen::Ui::Controls::IconListView &iconListView, int index, Tizen::Ui::Controls::IconListViewItemStatus status)
472 {
473         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
474
475         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
476         {
477                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE ||
478                         pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
479                 {
480                         IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), index);
481                         if (pList == null)
482                         {
483                                 HashMap* pReturnValue = new (std::nothrow) HashMap();
484                                 pReturnValue->Construct();
485
486                                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
487
488                                 return;
489                         }
490
491                         if (iconListView.IsItemChecked(index) == true)
492                         {
493                                 if (pList->GetCount() > 1)
494                                 {
495                                         iconListView.SetItemChecked(index, false);
496                                         __pContactValueListProvider = new (std::nothrow) ContactValueListItemProvider(pList);
497                                         ShowContactValuePopup(index);
498                                 }
499                                 else if (pList->GetCount() == 1)
500                                 {
501                                         String* pReturnValue = static_cast<String*>(pList->GetAt(0));
502                                         int blankIndex = 0;
503                                         pReturnValue->IndexOf(CHARACTER_SPACE, 0, blankIndex);
504                                         pReturnValue->Remove(0, blankIndex + 1);
505                                         __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(index)), *(new (std::nothrow) String(*pReturnValue)));
506                                         delete pList;
507                                 }
508
509                         }
510                         else
511                         {
512                                 __pTempContactValueHashMap->Remove(Integer(index), true);
513                         }
514                 }
515         }
516
517         UpdateBottomLabel();
518 }
519
520 void
521 FavoriteListEditorPanel::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
522 {
523 }
524
525 void
526 FavoriteListEditorPanel::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
527 {
528         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
529
530         int selectedIndex = -1;
531         Integer::Parse(listView.GetName(), selectedIndex);
532
533         IList* pList = __pPresentationModel->GetMultiValuesN(pContactsApp->GetReturnType(), selectedIndex);
534         if (pList == null)
535         {
536                 HashMap* pReturnValue = new (std::nothrow) HashMap();
537                 pReturnValue->Construct();
538
539                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
540
541                 return;
542         }
543
544         String* pReturnValueInfo = static_cast<String*>(pList->GetAt(index));
545         int blankIndex = 0;
546         pReturnValueInfo->IndexOf(CHARACTER_SPACE, 0, blankIndex);
547         pReturnValueInfo->Remove(0, blankIndex + 1);
548         __pTempContactValueHashMap->Add(*(new (std::nothrow) Integer(selectedIndex)), *(new (std::nothrow) String(*pReturnValueInfo)));
549
550         delete pList;
551
552         __pFavoriteListView->SetItemChecked(selectedIndex, true);
553         HideContactValuePopup();
554         UpdateBottomLabel();
555 }
556
557 void
558 FavoriteListEditorPanel::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
559 {
560 }
561
562 Tizen::Ui::Controls::IconListViewItem*
563 FavoriteListEditorPanel::CreateItem(int index)
564 {
565         Bitmap* pThumbnail = null;
566         String name;
567         Font textFont;
568         Color textColor;
569         int textHeight;
570         int textY;
571         TextHorizontalAlignment alignment = TEXT_ALIGNMENT_LEFT;
572
573         if (__pPresentationModel->GetFavoriteItemInfo(index, name, pThumbnail) != E_SUCCESS)
574         {
575                 return null;
576         }
577
578         Canvas* pCanvas = new (std::nothrow) Canvas();
579         pCanvas->Construct(Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
580         pCanvas->Clear();
581
582         if (pThumbnail != null)
583         {
584                 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE_WITH_THUMBNAIL);
585                 textY = H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND;
586                 textHeight = H_TEXT_BACKGROUND;
587                 textColor = Color(COLOR_TEXT_WITH_THUMBNAIL);
588
589                 pCanvas->DrawBitmap(pCanvas->GetBounds(), *pThumbnail, Rectangle(0, 0, pThumbnail->GetWidth(), pThumbnail->GetHeight()));
590                 pCanvas->SetForegroundColor(Color(COLOR_LINE));
591                 pCanvas->DrawLine(Point(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND), Point(W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND));
592                 pCanvas->FillRectangle(Color(COLOR_ITEM_TEXT_BACKGROUND), Rectangle(0, H_ICONLISTVIEW_ITEM - H_TEXT_BACKGROUND, W_ICONLISTVIEW_ITEM, H_TEXT_BACKGROUND));
593         }
594         else
595         {
596                 textFont.Construct(FONT_STYLE_BOLD , FONT_SIZE);
597                 textY = (H_ICONLISTVIEW_ITEM / 2) - (H_TEXT_SPACE / 2);
598                 textHeight = H_TEXT_SPACE;
599                 textColor = Color(COLOR_TEXT);
600                 alignment = TEXT_ALIGNMENT_CENTER;
601
602                 pCanvas->FillRectangle(Color(COLOR_ITEM_BACKGROUND), pCanvas->GetBounds());
603         }
604
605         EnrichedText* pEnrichedTextName = new (std::nothrow) EnrichedText();
606         pEnrichedTextName->Construct(Dimension(W_ICONLISTVIEW_ITEM - (W_NAME_TEXT_MARGIN * 2), textHeight));
607         pEnrichedTextName->SetVerticalAlignment(TEXT_ALIGNMENT_MIDDLE);
608         pEnrichedTextName->SetHorizontalAlignment(alignment);
609         pEnrichedTextName->SetTextWrapStyle(TEXT_WRAP_WORD_WRAP);
610         pEnrichedTextName->SetTextAbbreviationEnabled(true);
611
612         TextElement* pTextElementName = new (std::nothrow) TextElement();
613         pTextElementName->Construct(name);
614         pTextElementName->SetFont(textFont);
615         pTextElementName->SetTextColor(textColor);
616
617         pEnrichedTextName->Add(*pTextElementName);
618
619         pCanvas->DrawText(Point(W_NAME_TEXT_MARGIN, textY), *pEnrichedTextName);
620
621         Bitmap* pBitmapItem = new (std::nothrow) Bitmap();
622         pBitmapItem->Construct(*pCanvas, Rectangle(0, 0, W_ICONLISTVIEW_ITEM, H_ICONLISTVIEW_ITEM));
623
624         IconListViewItem* pFavoriteItem = new (std::nothrow) IconListViewItem();
625         pFavoriteItem->Construct(*pBitmapItem);
626
627         delete pThumbnail;
628         delete pCanvas;
629         delete pBitmapItem;
630         delete pEnrichedTextName;
631         delete pTextElementName;
632
633         return pFavoriteItem;
634 }
635
636 bool
637 FavoriteListEditorPanel::DeleteItem(int index, Tizen::Ui::Controls::IconListViewItem *pItem)
638 {
639         delete pItem;
640         pItem = null;
641
642         return true;
643 }
644
645 int
646 FavoriteListEditorPanel::GetItemCount(void)
647 {
648         return __pPresentationModel->GetFavoriteCount();
649 }
650
651 void
652 FavoriteListEditorPanel::RemoveFavorites(void)
653 {
654         result r = E_SUCCESS;
655
656         for (int i = 0; i < __pPresentationModel->GetFavoriteCount(); i++)
657         {
658                 if (__pFavoriteListView->IsItemChecked(i))
659                 {
660                         r = __pPresentationModel->SetAsFavorite(__pPresentationModel->GetContactId(i), false);
661
662                         if (r == E_STORAGE_FULL)
663                         {
664                                 CommonUtil::showMemoryFullMessageBox();
665                                 break;
666                         }
667                 }
668         }
669 }
670
671 void
672 FavoriteListEditorPanel::ReturnValues(RequestId requestId, Tizen::App::AppCtrlResult appCtrlResult, const Tizen::Base::Collection::IMap* pReturnValue)
673 {
674         AppControlProviderManager* pAppManager = AppControlProviderManager::GetInstance();
675
676         result r = pAppManager->SendAppControlResult(requestId, appCtrlResult, pReturnValue);
677         AppLogDebug("[%s] The return result from SendAppControlResult(), AppCtrlResult value : %d.", GetErrorMessage(r), appCtrlResult);
678
679         UiApp::GetInstance()->Terminate();
680 }
681
682 void
683 FavoriteListEditorPanel::ReturnMultipleValues(void)
684 {
685         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
686
687         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
688         {
689                 String keyType;
690                 ArrayList* pValueList = new (std::nothrow) ArrayList();
691                 pValueList->Construct();
692
693                 HashMap* pReturnValue = new (std::nothrow) HashMap();
694                 pReturnValue->Construct();
695
696                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_ITEM_ID)
697                 {
698                         for (int index = 0; index < __pPresentationModel->GetFavoriteCount(); index++)
699                         {
700                                 if (__pFavoriteListView->IsItemChecked(index))
701                                 {
702                                         int contactId = __pPresentationModel->GetContactId(index);
703                                         pValueList->Add(new (std::nothrow) String(Integer::ToString(contactId)));
704                                 }
705                         }
706                         pReturnValue->Add(new (std::nothrow) String(CONTACT_KEY_ITEM_ID), pValueList);
707
708                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
709
710                         return;
711                 }
712
713                 if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_PHONE)
714                 {
715                         keyType.Append(CONTACT_KEY_PHONE);
716                 }
717                 else if (pContactsApp->GetReturnType() == APP_CONTROL_RETURN_TYPE_EMAIL)
718                 {
719                         keyType.Append(CONTACT_KEY_EMAIL);
720                 }
721                 else
722                 {
723                         delete pValueList;
724
725                         ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_FAILED, pReturnValue);
726
727                         return;
728                 }
729
730                 IMapEnumerator* pMapEnum = __pTempContactValueHashMap->GetMapEnumeratorN();
731                 while (pMapEnum->MoveNext() == E_SUCCESS)
732                 {
733                         String* pValue = static_cast<String*> (pMapEnum->GetValue());
734                         pValueList->Add(new (std::nothrow) String(*pValue));
735                 }
736                 delete pMapEnum;
737
738                 pReturnValue->Add(new (std::nothrow) String(keyType), pValueList);
739
740                 ReturnValues(pContactsApp->GetRequestId(), APP_CTRL_RESULT_SUCCEEDED, pReturnValue);
741         }
742 }
743
744 void
745 FavoriteListEditorPanel::ShowContactValuePopup(int index)
746 {
747         String name;
748         Bitmap* pEmpty = null;
749
750         delete __pMultipleContactValuePopup;
751         __pMultipleContactValuePopup = new (std::nothrow) Popup();
752         __pMultipleContactValuePopup->Construct(true, Dimension(W_CONTACT_VALUE_POPUP, H_CONTACT_VALUE_POPUP));
753         __pPresentationModel->GetFavoriteItemInfo(index, name, pEmpty);
754         __pMultipleContactValuePopup->SetTitleText(name);
755         __pMultipleContactValuePopup->SetPropagatedKeyEventListener(this);
756
757         Rectangle popupClientBounds = __pMultipleContactValuePopup->GetClientAreaBounds();
758
759         ListView* pListView = new (std::nothrow) ListView();
760         pListView->Construct(Rectangle(0, 0, popupClientBounds.width, H_CONTACT_VALUE_POPUP_LIST_VIEW));
761         pListView->SetItemProvider(*__pContactValueListProvider);
762         pListView->AddListViewItemEventListener(*this);
763         pListView->SetName(String(Integer::ToString(index)));
764
765         __pMultipleContactValuePopup->AddControl(pListView);
766
767         Button* pCancelButton = new (std::nothrow) Button();
768         pCancelButton->Construct(Rectangle((popupClientBounds.width - W_CLOSE_BUTTON) / 2, Y_CLOSE_BUTTON, W_CLOSE_BUTTON, H_CLOSE_BUTTON), ResourceManager::GetString(L"IDS_COM_POP_CLOSE"));
769         pCancelButton->SetActionId(IDA_POPUP_CONTACT_VALUE_CLOSE);
770         pCancelButton->AddActionEventListener(*this);
771
772         __pMultipleContactValuePopup->AddControl(pCancelButton);
773         __pMultipleContactValuePopup->SetShowState(true);
774         __pMultipleContactValuePopup->Show();
775 }
776
777 void
778 FavoriteListEditorPanel::HideContactValuePopup(void)
779 {
780         if (__pMultipleContactValuePopup)
781         {
782                 __pMultipleContactValuePopup->SetShowState(false);
783                 Invalidate(true);
784         }
785 }
786
787 void
788 FavoriteListEditorPanel::UpdateBottomLabel(void)
789 {
790         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
791
792         int selectedCount = 0;
793         int favoriteCount = __pPresentationModel->GetFavoriteCount();
794         int fotterItemIndex = 1;
795
796         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
797         {
798                 fotterItemIndex = 0;
799         }
800
801         for (int index = 0; index < favoriteCount; index++)
802         {
803                 if (__pFavoriteListView->IsItemChecked(index))
804                 {
805                         selectedCount++;
806                 }
807         }
808
809         String string = ResourceManager::GetString(L"IDS_COM_POP_SELECTED");
810         string.Append(L" (");
811         string.Append(selectedCount);
812         string.Append(L")");
813         __pBottomLabel->SetText(string);
814         Form* pForm = dynamic_cast<Form*>(GetParent());
815         AppAssert(pForm);
816
817         FloatRectangle clientBounds = ((MainForm*)pForm)->GetClientBounds();
818
819         Footer* pFooter = pForm->GetFooter();
820
821         if (selectedCount > 0)
822         {
823                 if(__pBottomLabel->GetShowState() == false)
824                 {
825                         __pBottomLabel->SetShowState(true);
826                         __pFavoriteListView->SetSize(__pFavoriteListView->GetSizeF().width, clientBounds.height - H_BOTTOM_LABEL);
827                 }
828                 pFooter->SetItemEnabled(fotterItemIndex, true);
829         }
830         else if (selectedCount == 0)
831         {
832                 if(__pBottomLabel->GetShowState() == true)
833                 {
834                         __pBottomLabel->SetShowState(false);
835                         __pFavoriteListView->SetSize(__pFavoriteListView->GetSizeF().width, clientBounds.height);
836                 }
837                 pFooter->SetItemEnabled(fotterItemIndex, false);
838         }
839         __pBottomLabel->Invalidate(true);
840         pFooter->Invalidate(true);
841 }
842
843 bool
844 FavoriteListEditorPanel::OnKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
845 {
846         return false;
847 }
848
849 bool
850 FavoriteListEditorPanel::OnKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
851 {
852         if (keyEventInfo.GetKeyCode() == KEY_BACK || keyEventInfo.GetKeyCode() == KEY_ESC)
853         {
854                 if (__pMultipleContactValuePopup && __pMultipleContactValuePopup->GetShowState() == true)
855                 {
856                         HideContactValuePopup();
857                         return true;
858                 }
859         }
860         return false;
861 }
862
863 bool
864 FavoriteListEditorPanel::OnPreviewKeyPressed(Control& source, const KeyEventInfo& keyEventInfo)
865 {
866         return false;
867 }
868
869 bool
870 FavoriteListEditorPanel::OnPreviewKeyReleased(Control& source, const KeyEventInfo& keyEventInfo)
871 {
872         return false;
873 }