Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnSettingsSpeedDialForm.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.0 (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    PhnSettingsSpeedDialForm.cpp
19  * @brief   Setting Speed dial form
20  */
21 #include <FApp.h>
22 #include <FSocial.h>
23 #include "PhnAppUtility.h"
24 #include "PhnSettingsConstants.h"
25 #include "PhnSettingsSpeedDialForm.h"
26 #include "PhnSceneRegister.h"
27 #include "PhnSpeedDialInfo.h"
28 #include "PhnSettingsPresentationModel.h"
29 #include "PhnTypes.h"
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::App;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Social;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39
40 //constants
41 const int H_DELETE_ICON_BMP = 56;
42 const int W_DELETE_ICON_BMP = 56;
43 const int W_VOICEMAIL_ICON_BG = 213;
44 const int H_VOICEMAIL_ICON_BG = 213;
45 const int W_VOICEMAIL_ICON = 100;
46 const int H_VOICEMAIL_ICON = 100;
47 const int W_SPEED_DIAL_CHECK_ICON = 64;
48 const int H_SPEED_DIAL_CHECK_ICON = 64;
49 const unsigned int COLOR_EMPTY_PHOTO = Color32<103, 103, 103>::Value;
50 //String contants for control name
51 static const wchar_t* IDL_SETTINGS_SPEEDDIAL_FORM = L"IDL_SETTINGS_SPEEDDIAL_FORM";
52 static const wchar_t* IDC_PHOTO_BTN2 = L"IDC_PHOTO_BUTTON2";
53 static const wchar_t* IDC_PHOTO_BTN3 = L"IDC_PHOTO_BUTTON3";
54 static const wchar_t* IDC_PHOTO_BTN4 = L"IDC_PHOTO_BUTTON4";
55 static const wchar_t* IDC_PHOTO_BTN5 = L"IDC_PHOTO_BUTTON5";
56 static const wchar_t* IDC_PHOTO_BTN6 = L"IDC_PHOTO_BUTTON6";
57 static const wchar_t* IDC_PHOTO_BTN7 = L"IDC_PHOTO_BUTTON7";
58 static const wchar_t* IDC_PHOTO_BTN8 = L"IDC_PHOTO_BUTTON8";
59 static const wchar_t* IDC_PHOTO_BTN9 = L"IDC_PHOTO_BUTTON9";
60
61 static const wchar_t* IDC_NAME_LABEL2 = L"IDC_NAME_LABEL2";
62 static const wchar_t* IDC_NAME_LABEL3 = L"IDC_NAME_LABEL3";
63 static const wchar_t* IDC_NAME_LABEL4 = L"IDC_NAME_LABEL4";
64 static const wchar_t* IDC_NAME_LABEL5 = L"IDC_NAME_LABEL5";
65 static const wchar_t* IDC_NAME_LABEL6 = L"IDC_NAME_LABEL6";
66 static const wchar_t* IDC_NAME_LABEL7 = L"IDC_NAME_LABEL7";
67 static const wchar_t* IDC_NAME_LABEL8 = L"IDC_NAME_LABEL8";
68 static const wchar_t* IDC_NAME_LABEL9 = L"IDC_NAME_LABEL9";
69
70 static const wchar_t* IDB_SPEED_DIAL_CHECK = L"C01-5_icon_speeddial_check.png";
71
72 SettingsSpeedDialForm::SettingsSpeedDialForm(void)
73 {
74         __pSpeedDialMappingList = null;
75         __pSettingsPresentor = null;
76         __keyToMap = 0;
77         __isUpdate = false;
78         __isDeleteMode = false;
79         __pAddressbook = null;
80         __pSpeedDialPopup = null;
81         __pDeleteList = null;
82         __pPreviousSceneId = null;
83         __isContactAppControlLaunched = false;
84 }
85
86 SettingsSpeedDialForm::~SettingsSpeedDialForm(void)
87 {
88 //      SettingsPresentationModel::DeleteInstance();
89         if(__pPreviousSceneId != null)
90         {
91                 delete __pPreviousSceneId;
92         }
93 }
94
95 bool
96 SettingsSpeedDialForm::Initialize(void)
97 {
98         Construct(IDL_SETTINGS_SPEEDDIAL_FORM);
99         //Initialise voice mail
100         InitializeVoiceMail();
101         return true;
102 }
103
104 result
105 SettingsSpeedDialForm::OnInitializing(void)
106 {
107         result r = E_SUCCESS;
108
109         // Setup back event listener
110         SetFormBackEventListener(this);
111         __pSettingsPresentor = SettingsPresentationModel::GetInstance();
112         AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
113         __pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
114         if (__pAddressbook == null)
115         {
116                 r = E_FAILURE;
117         }
118         return r;
119 }
120
121 void
122 SettingsSpeedDialForm::InitializeFooter(void)
123 {
124         Footer* pFooter = GetFooter();
125         if (pFooter != null)
126         {
127                 pFooter->RemoveAllButtons();
128                 pFooter->RemoveAllItems();
129                 pFooter->RemoveBackButton();
130
131                 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
132
133                 //Delete footer item
134                 String footerItemName(L"");
135                 footerItemName.Append(AppUtility::GetResourceString(IDS_REMOVE_CONTACT));
136                 FooterItem delFooterItem;
137                 delFooterItem.Construct(IDA_DELETE_FOOTER_ITEMID);
138                 delFooterItem.SetText(footerItemName);
139                 pFooter->AddItem(delFooterItem);
140                 if(__isDeleteMode == false)
141                 {
142                         if(__pSpeedDialMappingList != null)
143                         {
144                                 if(__pSpeedDialMappingList->GetCount() == 0)
145                                 {
146                                         pFooter->SetItemEnabled(0,false);
147                                 }
148                                 else
149                                 {
150                                         pFooter->SetItemEnabled(0,true);
151                                 }
152                         }
153                         else
154                         {
155                                 pFooter->SetItemEnabled(0,false);
156                         }
157
158
159                         //back button
160                         pFooter->SetBackButton();
161                         pFooter->SetButtonColor(BUTTON_ITEM_STATUS_NORMAL, pFooter->GetColor());
162                         pFooter->AddActionEventListener(*this);
163                         pFooter->RequestRedraw(true);
164                 }
165                 else
166                 {
167
168                         if(__pDeleteList != null)
169                         {
170                                 if(__pDeleteList->GetCount() == 0)
171                                 {
172                                         pFooter->SetItemEnabled(0,false);
173                                 }
174                                 else
175                                 {
176                                         pFooter->SetItemEnabled(0,true);
177                                 }
178                         }
179                         else
180                         {
181                                 pFooter->SetItemEnabled(0,false);
182                         }
183
184                         FooterItem cancelFooterItem;
185                         cancelFooterItem.Construct(IDA_CANCEL_FOOTER_ITEMID);
186                         String cancelString = AppUtility::GetResourceString(L"IDS_CANCEL");
187                         cancelFooterItem.SetText(cancelString);
188                         pFooter->AddItem(cancelFooterItem);
189                         pFooter->RequestRedraw(true);
190                 }
191         }
192 }
193
194 void
195 SettingsSpeedDialForm::InitializeVoiceMail(void)
196 {
197         Button* pVoiceMailBtn = static_cast<Button*>(GetControl(IDC_VOICEMAIL_BUTTON));
198         if (pVoiceMailBtn != null)
199         {
200                 Bitmap* pIcon = AppUtility::GetBitmapFromResourcesN(IDB_VOICECALL_ICON, W_VOICEMAIL_ICON, H_VOICEMAIL_ICON);
201                 Point iconPos(((pVoiceMailBtn->GetBounds().width - W_VOICEMAIL_ICON) / 2), ((pVoiceMailBtn->GetBounds().height - H_VOICEMAIL_ICON) / 2));
202                 pVoiceMailBtn->SetNormalBitmap(iconPos, *pIcon);
203                 pVoiceMailBtn->SetPressedBitmap(iconPos, *pIcon);
204                 pVoiceMailBtn->SetColor(BUTTON_STATUS_NORMAL, COLOR_EMPTY_PHOTO);
205                 pVoiceMailBtn->SetActionId(IDA_VOICEMAIL);
206                 pVoiceMailBtn->AddActionEventListener(*this);
207                 delete pIcon;
208                 pIcon = null;
209         }
210 }
211
212 void
213 SettingsSpeedDialForm::InitializePhotoButtons(const String& btnName, const String& lblName, ActionId actionId)
214 {
215         Button* pButton = static_cast<Button*>(GetControl(btnName));
216         Label* pNameLabel = static_cast<Label*>(GetControl(lblName));
217         if (pButton != null && pNameLabel != null)
218         {
219                 String contactId;
220                 RecordId recordId = INVALID_RECORD_ID;
221                 SpeedDialInfo speedDialInfo;
222
223                 if (__pSpeedDialMappingList != null)
224                 {
225                         __pSpeedDialMappingList->GetValue(actionId,speedDialInfo);
226                         if (speedDialInfo.keyMapping == actionId && speedDialInfo.contactId.IsEmpty() == false)
227                         {
228                                 // Convert String value to long long type value
229                                 Integer::Parse(speedDialInfo.contactId, recordId);
230                         }
231                 }
232
233                 //Fetch contacts Photo and name
234                 Bitmap* pContactPhoto = null;
235                 String contactName(L"");
236                 Contact* pMappedContact = null;
237                 if (recordId != Tizen::Social::INVALID_RECORD_ID)
238                 {
239                         pMappedContact = __pAddressbook->GetContactN(recordId);
240                         if(pMappedContact != null)
241                         {
242                                 pContactPhoto = pMappedContact->GetThumbnailN();
243                                 if (pContactPhoto != null)
244                                 {
245                                         Canvas* pCanvas = new (std::nothrow) Canvas;
246                                         Rectangle canvasRect(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
247                                         pCanvas->Construct(canvasRect);
248                                         //draw the contact bitmap
249                                         pCanvas->DrawBitmap(canvasRect,*pContactPhoto);
250                                         delete pContactPhoto;
251                                         pContactPhoto = new Bitmap();
252                                         pContactPhoto->Construct(*pCanvas, pCanvas->GetBounds());
253                                         delete pCanvas;
254
255                                 }
256
257                         }
258                 }
259
260                 if (recordId != Tizen::Social::INVALID_RECORD_ID)
261                 {
262
263                         if (pMappedContact != null)
264                         {
265
266                                 if (pContactPhoto != null)
267                                 {
268                                         if ((__isDeleteMode == true) && (__pDeleteList != null))
269                                         {
270                                                 if(actionId == __keyToMap)
271                                                 {
272                                                         if(__pDeleteList->Contains(__keyToMap) == true)
273                                                         {
274                                                                 __pDeleteList->Remove(__keyToMap);
275                                                         }
276                                                         else
277                                                         {
278                                                                 //update photo bitmap with check icon
279                                                                 Canvas* pCanvas = new (std::nothrow) Canvas;
280                                                                 Rectangle canvasRect(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
281                                                                 pCanvas->Construct(canvasRect);
282                                                                 //draw the contact bitmap
283                                                                 pCanvas->DrawBitmap(canvasRect,*pContactPhoto);
284                                                                 //apply color
285                                                                 pCanvas->DrawRectangle(canvasRect);
286                                                                 pCanvas->FillRectangle(Color(103,103,103,127),canvasRect);
287                                                                 //draw check icon
288                                                                 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(IDB_SPEED_DIAL_CHECK,W_SPEED_DIAL_CHECK_ICON,H_SPEED_DIAL_CHECK_ICON);
289                                                                 pCanvas->DrawBitmap(Point((((canvasRect.width)/2) - (W_SPEED_DIAL_CHECK_ICON/2)),(((canvasRect.height)/2)- (H_SPEED_DIAL_CHECK_ICON/2))),*pBitmap);
290
291                                                                 //construct the final Bitmap to Button
292                                                                 delete pContactPhoto;
293                                                                 pContactPhoto = new Bitmap();
294                                                                 pContactPhoto->Construct(*pCanvas, pCanvas->GetBounds());
295                                                                 delete pCanvas;
296                                                                 delete pBitmap;
297                                                                 __pDeleteList->Add(__keyToMap);
298                                                         }
299                                                 }
300                                         }
301                                 }
302                                 else
303                                 {
304                                         if (__isDeleteMode == false)
305                                         {
306                                                 //Create a new canvas
307                                                 Canvas* pCanvas = new (std::nothrow) Canvas;
308                                                 Rectangle canvasRect(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
309                                                 pCanvas->Construct(canvasRect);
310                                                 pCanvas->DrawRectangle(canvasRect);
311                                                 pCanvas->FillRectangle(COLOR_EMPTY_PHOTO,canvasRect);
312                                                 //create the final Bitmap
313                                                 pContactPhoto = new Bitmap();
314                                                 pContactPhoto->Construct(*pCanvas, pCanvas->GetBounds());
315                                                 delete pCanvas;
316                                         }
317                                         else
318                                         {
319                                                 if ((__pDeleteList != null))
320                                                 {
321                                                         if(__pDeleteList->Contains(__keyToMap) == true)
322                                                         {
323                                                                 //Create a new canvas
324                                                                 Canvas* pCanvas = new (std::nothrow) Canvas;
325                                                                 Rectangle canvasRect(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
326                                                                 pCanvas->Construct(canvasRect);
327                                                                 pCanvas->DrawRectangle(canvasRect);
328                                                                 pCanvas->FillRectangle(COLOR_EMPTY_PHOTO,canvasRect);
329                                                                 //Set the final Bitmap to Button
330                                                                 pContactPhoto = new Bitmap();
331                                                                 pContactPhoto->Construct(*pCanvas, pCanvas->GetBounds());
332                                                                 delete pCanvas;
333                                                                 __pDeleteList->Remove(__keyToMap);
334                                                         }
335                                                         else
336                                                         {
337                                                                 Canvas* pCanvas = new (std::nothrow) Canvas;
338                                                                 Rectangle canvasRect(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
339                                                                 pCanvas->Construct(canvasRect);
340                                                                 //apply color
341                                                                 pCanvas->DrawRectangle(canvasRect);
342                                                                 pCanvas->FillRectangle(Color(103,103,103,127),canvasRect);
343                                                                 //draw check icon
344                                                                 Bitmap* pBitmap = AppUtility::GetBitmapFromResourcesN(IDB_SPEED_DIAL_CHECK,W_SPEED_DIAL_CHECK_ICON,H_SPEED_DIAL_CHECK_ICON);
345                                                                 pCanvas->DrawBitmap(Point((((canvasRect.width)/2) - (W_SPEED_DIAL_CHECK_ICON/2)),(((canvasRect.height)/2)- (H_SPEED_DIAL_CHECK_ICON/2))),*pBitmap);
346                                                                 //Set the final Bitmap to Button
347                                                                 pContactPhoto = new Bitmap();
348                                                                 pContactPhoto->Construct(*pCanvas, pCanvas->GetBounds());
349                                                                 delete pCanvas;
350                                                                 delete pBitmap;
351                                                                 __pDeleteList->Add(__keyToMap);
352                                                         }
353                                                 }
354                                         }
355                                 }
356
357                                 //fetch Display name for selected contact
358                                 pMappedContact->GetValue(CONTACT_PROPERTY_ID_DISPLAY_NAME,contactName);
359                                 if (contactName.IsEmpty() == true)
360                                 {
361                                         String firstName;
362                                         pMappedContact->GetValue(CONTACT_PROPERTY_ID_FIRST_NAME,firstName);
363                                         String lastName;
364                                         pMappedContact->GetValue(CONTACT_PROPERTY_ID_LAST_NAME,lastName);
365                                         contactName.Append(firstName + L" " + lastName);
366                                 }
367                                 delete pMappedContact;
368                         }
369                 }
370                 else
371                 {
372                         //Create a new canvas - invalid record
373                         Canvas* pCanvas = new (std::nothrow) Canvas;
374                         Rectangle canvasRect(Rectangle(0, 0, pButton->GetBounds().width, pButton->GetBounds().height));
375                         pCanvas->Construct(canvasRect);
376                         pCanvas->DrawRectangle(canvasRect);
377                         pCanvas->FillRectangle(COLOR_EMPTY_PHOTO,canvasRect);
378                         //create the final Bitmap
379                         pContactPhoto = new Bitmap();
380                         pContactPhoto->Construct(*pCanvas, pCanvas->GetBounds());
381                         delete pCanvas;
382
383                         //reset display name - invalid record
384                         contactName.Append(actionId);
385                         contactName.Append(AppUtility::GetResourceString(L"IDS_DEFAULT_SPEED_DIAL_TEXT"));
386                 }
387
388                 pButton->SetColor(BUTTON_STATUS_NORMAL, COLOR_EMPTY_PHOTO);
389                 //set contact photo to button
390                 if(pContactPhoto != null)
391                 {
392 //                      pButton->SetNormalBackgroundBitmap(*pContactPhoto);
393                         pButton->SetNormalBitmap(Point(0,0),*pContactPhoto);
394                         pButton->Invalidate(true);
395                         delete pContactPhoto;
396                 }
397                 //update contacts name
398                 if (pNameLabel != null)
399                 {
400                         pNameLabel->SetText(contactName);
401                         pNameLabel->Invalidate(true);
402                 }
403
404                 if(pButton->GetActionId() != actionId)
405                 {
406                         pButton->SetActionId(actionId);
407                         pButton->AddActionEventListener(*this);
408                 }
409         }
410 }
411
412
413 result
414 SettingsSpeedDialForm::OnTerminating(void)
415 {
416         result r = E_SUCCESS;
417
418         if (__pSpeedDialMappingList)
419         {
420                 delete __pSpeedDialMappingList;
421                 __pSpeedDialMappingList = null;
422         }
423
424         __pSettingsPresentor = null;
425         if (__pAddressbook)
426         {
427                 delete __pAddressbook;
428         }
429
430         if (__pDeleteList != null)
431         {
432                 delete __pDeleteList;
433         }
434         return r;
435 }
436
437 void
438 SettingsSpeedDialForm::OnActionPerformed(const Control& source, int actionId)
439 {
440         switch (actionId)
441         {
442         case IDA_CANCEL_FOOTER_ITEMID:
443         {
444                 String titleString = AppUtility::GetResourceString(L"IDS_SPEED_DIAL_TITLE");
445                 Header* pHeader = GetHeader();
446                 pHeader->SetTitleText(titleString);
447                 pHeader->RequestRedraw(true);
448                 if (__pDeleteList != null)
449                 {
450                         __pDeleteList->RemoveAll();
451
452                 }
453                 __isDeleteMode = false;
454                 UpdateAllButtons();
455
456         }
457         break;
458         case IDA_DELETE_FOOTER_ITEMID:
459         {
460                 Header* pHeader = GetHeader();
461                 if (__isDeleteMode == false)
462                 {
463                         __isDeleteMode = true;
464                         String titleString = AppUtility::GetResourceString(L"IDS_SPEED_DIAL_DELETE_TITLE");
465                         pHeader->SetTitleText(titleString);
466                         pHeader->RequestRedraw(true);
467                         InitializeFooter();
468 /*                      Footer* pFooter = GetFooter();
469                         if (pFooter != null)
470                         {
471                                 pFooter->RemoveAllButtons();
472                                 pFooter->RemoveAllItems();
473                                 pFooter->RemoveBackButton();
474                                 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
475
476                                 //Delete footer item
477                                 String footerItemName(L"");
478                                 footerItemName.Append(AppUtility::GetResourceString(IDS_REMOVE_CONTACT));
479                                 FooterItem delFooterItem;
480                                 delFooterItem.Construct(IDA_DELETE_FOOTER_ITEMID);
481                                 delFooterItem.SetText(footerItemName);
482                                 pFooter->AddItem(delFooterItem);
483
484                                 FooterItem cancelFooterItem;
485                                 cancelFooterItem.Construct(IDA_CANCEL_FOOTER_ITEMID);
486                                 String cancelString = AppUtility::GetResourceString(L"IDS_CANCEL");
487                                 cancelFooterItem.SetText(cancelString);
488                                 pFooter->AddItem(cancelFooterItem);
489                                 pFooter->RequestRedraw(true);
490                         }*/
491                 }
492                 else
493                 {
494                         String titleString = AppUtility::GetResourceString(L"IDS_SPEED_DIAL_TITLE");
495                         pHeader->SetTitleText(titleString);
496                         pHeader->RequestRedraw(true);
497                         if (__pDeleteList != null)
498                         {
499                                 for (int index = 0; index < __pDeleteList->GetCount(); index++)
500                                 {
501                                         int keyToDelete;
502                                         __pDeleteList->GetAt(index,keyToDelete);
503                                         SpeedDialInfo speedDialInfo;
504                                         __pSpeedDialMappingList->GetValue(keyToDelete,speedDialInfo);
505                                         __pSettingsPresentor->RemoveSpeedDialMapping(speedDialInfo.rowId);
506                                 }
507                         }
508                         if (__pSpeedDialMappingList)
509                         {
510                                 delete __pSpeedDialMappingList;
511                                 __pSpeedDialMappingList = null;
512                         }
513                         __pSpeedDialMappingList = static_cast<HashMapT<int,SpeedDialInfo>*>(__pSettingsPresentor->GetSpeedDialMappingN());
514                         if (__pDeleteList != null)
515                         {
516                                 __pDeleteList->RemoveAll();
517                         }
518                         __isDeleteMode = false;
519                         UpdateAllButtons();
520
521                 }
522         }
523         break;
524         default:
525         if (actionId > IDA_VOICEMAIL && actionId < IDA_SELECT_CONTACT)
526                 {
527                         __keyToMap = actionId;
528                         if (__isDeleteMode == false)
529                         {
530                                 __isUpdate = false;
531                                 if (__pSpeedDialMappingList != null)
532                                 {
533                                         SpeedDialInfo speedDialInfo;
534                                         result r = __pSpeedDialMappingList->GetValue(actionId,speedDialInfo);
535                                         if (!IsFailed(r))
536                                         {
537                                                 __isUpdate = true;
538                                         }
539                                 }
540                                 if (__isUpdate == true)
541                                 {
542                                         if (__pSpeedDialPopup)
543                                         {
544                                                 delete __pSpeedDialPopup;
545                                                 __pSpeedDialPopup = null;
546                                         }
547                                         __pSpeedDialPopup = new (std::nothrow) SpeedDialPopup(*this);
548                                         __pSpeedDialPopup->Initialize();
549                                         __pSpeedDialPopup->SetShowState(true);
550                                         __pSpeedDialPopup->Draw();
551                                         __pSpeedDialPopup->Show();
552
553                                 }
554                                 else
555                                 {
556                                         LaunchAppControl();
557                                 }
558                         }
559                         else
560                         {
561                                 UpdateButton();
562                                 __keyToMap = 0;
563                         }
564                 }
565                 break;
566         }
567 }
568
569 void
570 SettingsSpeedDialForm::LaunchAppControl(void)
571 {
572         if(__isContactAppControlLaunched == true)
573         {
574                 //app control already launched.
575                 return;
576         }
577         __isContactAppControlLaunched = true;
578         result r = E_SUCCESS;
579         HashMap extraData;
580         extraData.Construct();
581
582         extraData.Add(new (std::nothrow) String(SELECTION_MODE), new (std::nothrow) String(SELECTION_MODE_SINGLE));
583         extraData.Add(new (std::nothrow) String(RETURN_TYPE), new (std::nothrow) String(RETURN_TYPE_CONTACT_ID));
584
585         AppControl* pAc = AppManager::FindAppControlN(PROVIDER_ID_CONTACTS, OPERATION_ID_PICK);
586         if (pAc != null)
587         {
588                 r = pAc->Start(null, null, &extraData, this);
589                 if(r != E_SUCCESS)
590                 {
591                         //app control request failed
592                         __isContactAppControlLaunched = false;
593                 }
594                 delete pAc;
595         }
596         extraData.RemoveAll(true);
597 }
598
599 void
600 SettingsSpeedDialForm::OnAppControlCompleteResponseReceived(const AppId& appId, const String& operationId, AppCtrlResult appControlResult, const IMap* pExtraData)
601 {
602
603         if (appId.Equals(String(PROVIDER_ID_CONTACTS)) && operationId.Equals(String(OPERATION_ID_PICK)))
604         {
605                 //app control request completed
606                 __isContactAppControlLaunched = false;
607                 //check if results are available.
608                 if (appControlResult == APP_CTRL_RESULT_SUCCEEDED)
609                 {
610                         const String* rettype = static_cast<const String *>(pExtraData->GetValue(String(RETURN_TYPE)));
611                         if (rettype->Equals(String(RETURN_TYPE_CONTACT_ID),false))
612                         {
613                                 const String* pPickResult = static_cast<const String *>(pExtraData->GetValue(String(RETURN_KEY_VALUE)));
614                                 if (pPickResult != null && pPickResult->IsEmpty() == false)
615                                 {
616                                         if (__isUpdate == true)
617                                         {
618                                                 SpeedDialInfo speedDialInfo;
619                                                 __pSpeedDialMappingList->GetValue(__keyToMap,speedDialInfo);
620                                                 __pSettingsPresentor->UpdateSpeedDialMapping(speedDialInfo.rowId,*pPickResult,__keyToMap);
621                                                 __isUpdate = false;
622                                         }
623                                         else
624                                         {
625                                                 __pSettingsPresentor->SetSpeedDialMapping(*pPickResult,__keyToMap);
626                                         }
627                                         UpdateButton();
628                                 }
629                         }
630                 }
631                 __keyToMap = 0;
632         }
633 }
634
635 void
636 SettingsSpeedDialForm::UpdateAllButtons(void)
637 {
638         //Initialise photos
639         InitializePhotoButtons(IDC_PHOTO_BTN2, IDC_NAME_LABEL2, IDA_SELECT_PHOTO2);
640         InitializePhotoButtons(IDC_PHOTO_BTN3, IDC_NAME_LABEL3, IDA_SELECT_PHOTO3);
641         InitializePhotoButtons(IDC_PHOTO_BTN4, IDC_NAME_LABEL4, IDA_SELECT_PHOTO4);
642         InitializePhotoButtons(IDC_PHOTO_BTN5, IDC_NAME_LABEL5, IDA_SELECT_PHOTO5);
643         InitializePhotoButtons(IDC_PHOTO_BTN6, IDC_NAME_LABEL6, IDA_SELECT_PHOTO6);
644         InitializePhotoButtons(IDC_PHOTO_BTN7, IDC_NAME_LABEL7, IDA_SELECT_PHOTO7);
645         InitializePhotoButtons(IDC_PHOTO_BTN8, IDC_NAME_LABEL8, IDA_SELECT_PHOTO8);
646         InitializePhotoButtons(IDC_PHOTO_BTN9, IDC_NAME_LABEL9, IDA_SELECT_PHOTO9);
647         InitializeFooter();
648 }
649 void
650 SettingsSpeedDialForm::UpdateButton(void)
651 {
652         if (__pSpeedDialMappingList)
653         {
654                 delete __pSpeedDialMappingList;
655                 __pSpeedDialMappingList = null;
656         }
657         __pSpeedDialMappingList = static_cast<HashMapT<int,SpeedDialInfo>*>(__pSettingsPresentor->GetSpeedDialMappingN());
658         switch (__keyToMap)
659         {
660         case IDA_SELECT_PHOTO2:
661         {
662                 InitializePhotoButtons(IDC_PHOTO_BTN2, IDC_NAME_LABEL2, IDA_SELECT_PHOTO2);
663         }
664         break;
665         case IDA_SELECT_PHOTO3:
666         {
667                 InitializePhotoButtons(IDC_PHOTO_BTN3, IDC_NAME_LABEL3, IDA_SELECT_PHOTO3);
668         }
669         break;
670         case IDA_SELECT_PHOTO4:
671         {
672                 InitializePhotoButtons(IDC_PHOTO_BTN4, IDC_NAME_LABEL4, IDA_SELECT_PHOTO4);
673         }
674         break;
675         case IDA_SELECT_PHOTO5:
676         {
677                 InitializePhotoButtons(IDC_PHOTO_BTN5, IDC_NAME_LABEL5, IDA_SELECT_PHOTO5);
678         }
679         break;
680         case IDA_SELECT_PHOTO6:
681         {
682                 InitializePhotoButtons(IDC_PHOTO_BTN6, IDC_NAME_LABEL6, IDA_SELECT_PHOTO6);
683         }
684         break;
685         case IDA_SELECT_PHOTO7:
686         {
687                 InitializePhotoButtons(IDC_PHOTO_BTN7, IDC_NAME_LABEL7, IDA_SELECT_PHOTO7);
688         }
689         break;
690         case IDA_SELECT_PHOTO8:
691         {
692                 InitializePhotoButtons(IDC_PHOTO_BTN8, IDC_NAME_LABEL8, IDA_SELECT_PHOTO8);
693         }
694         break;
695         case IDA_SELECT_PHOTO9:
696         {
697                 InitializePhotoButtons(IDC_PHOTO_BTN9, IDC_NAME_LABEL9, IDA_SELECT_PHOTO9);
698         }
699         break;
700         default:
701                 break;
702         }
703         InitializeFooter();
704 }
705 void
706 SettingsSpeedDialForm::OnFormBackRequested(Form& source)
707 {
708         SceneManager* pSceneManager = SceneManager::GetInstance();
709         AppAssert(pSceneManager != null);
710         pSceneManager->GoForward(ForwardSceneTransition(*__pPreviousSceneId), null);
711 }
712
713 void
714 SettingsSpeedDialForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
715 {
716         __isDeleteMode = false;
717         __isContactAppControlLaunched = false;
718         //save previous scene id
719         __pPreviousSceneId = new (std::nothrow) SceneId(previousSceneId);
720
721         if (__pSpeedDialMappingList != null)
722         {
723                 delete __pSpeedDialMappingList;
724                 __pSpeedDialMappingList = null;
725         }
726
727         if (__pDeleteList != null)
728         {
729                 delete __pDeleteList;
730                 __pDeleteList = null;
731         }
732
733         __pSpeedDialMappingList = static_cast<HashMapT<int,SpeedDialInfo>*>(__pSettingsPresentor->GetSpeedDialMappingN());
734         //Initialise photos
735         UpdateAllButtons();
736         __pDeleteList = new (std::nothrow) ArrayListT<int>();
737         if(__pAddressbook != null)
738         {
739                 __pAddressbook->SetEventListener(this);
740         }
741 }
742
743 void
744 SettingsSpeedDialForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
745 {
746         if(__pPreviousSceneId != null)
747         {
748                 delete __pPreviousSceneId;
749                 __pPreviousSceneId = null;
750         }
751         if(__pAddressbook != null)
752         {
753                 __pAddressbook->SetEventListener(null);
754         }
755 }
756
757 void
758 SettingsSpeedDialForm::OnItemSelected(int itemIndex)
759 {
760         switch (itemIndex)
761         {
762         case IDA_UPDATE_SPEED_DIAL:
763         {
764                 __isUpdate = true;
765                 LaunchAppControl();
766         }
767         break;
768
769         case IDA_REMOVE_SPEED_DIAL:
770         {
771                 SpeedDialInfo speedDialInfo;
772                 __pSpeedDialMappingList->GetValue(__keyToMap,speedDialInfo);
773                 __pSettingsPresentor->RemoveSpeedDialMapping(speedDialInfo.rowId);
774                 UpdateButton();
775         }
776         break;
777         default:
778                 break;
779         }
780 }
781
782 void
783 SettingsSpeedDialForm::OnContactsChanged(const Tizen::Base::Collection::IList& contactChangeInfoList)
784 {
785         IEnumerator* pEnum = contactChangeInfoList.GetEnumeratorN();
786         while (pEnum->MoveNext() == E_SUCCESS)
787         {
788                  ContactChangeInfo* pInfo = (ContactChangeInfo*) pEnum->GetCurrent();
789                  switch(pInfo->GetChangeType())
790                  {
791                          case RECORD_CHANGE_TYPE_REMOVED:
792                          {
793                                  if(__pSpeedDialMappingList == null || __pSpeedDialMappingList->GetCount() == 0)
794                                  {
795                                          break;
796                                  }
797                                  IListT<SpeedDialInfo>* pSpeedDialList = __pSpeedDialMappingList->GetValuesN();
798                                  IEnumeratorT<SpeedDialInfo> *pSpeedDialListEnum = pSpeedDialList->GetEnumeratorN();
799                                  bool bFound = false;
800                                 while(pSpeedDialListEnum->MoveNext() == E_SUCCESS)
801                                 {
802                                         SpeedDialInfo speeDialInfo;
803                                         RecordId recordId = INVALID_RECORD_ID;
804                                         pSpeedDialListEnum->GetCurrent(speeDialInfo);
805                                         Integer::Parse(speeDialInfo.contactId, recordId);
806                                         if(recordId == pInfo->GetContactId())
807                                         {
808                                                 __pSettingsPresentor->RemoveSpeedDialMapping(speeDialInfo.rowId);
809                                                 bFound = true;
810
811                                         }
812                                 }
813                                 delete pSpeedDialListEnum;
814                                 delete pSpeedDialList;
815                                 if(bFound == true)
816                                 {
817                                         if (__pSpeedDialMappingList)
818                                         {
819                                                 delete __pSpeedDialMappingList;
820                                                 __pSpeedDialMappingList = null;
821                                         }
822                                         __pSpeedDialMappingList = static_cast<HashMapT<int,SpeedDialInfo>*>(__pSettingsPresentor->GetSpeedDialMappingN());
823                                         UpdateAllButtons();
824                                 }
825
826                          }
827                         break;
828                         case RECORD_CHANGE_TYPE_UPDATED:
829                         {
830                                  if(__pSpeedDialMappingList == null || __pSpeedDialMappingList->GetCount() == 0)
831                                  {
832                                          break;
833                                  }
834                                  IListT<SpeedDialInfo>* pSpeedDialList = __pSpeedDialMappingList->GetValuesN();
835                                  IEnumeratorT<SpeedDialInfo> *pSpeedDialListEnum = pSpeedDialList->GetEnumeratorN();
836                                  bool bFound = false;
837                                 while(pSpeedDialListEnum->MoveNext() == E_SUCCESS)
838                                 {
839                                         SpeedDialInfo speeDialInfo;
840                                         RecordId recordId = INVALID_RECORD_ID;
841                                         pSpeedDialListEnum->GetCurrent(speeDialInfo);
842                                         Integer::Parse(speeDialInfo.contactId, recordId);
843                                         if(recordId == pInfo->GetContactId())
844                                         {
845                                                 bFound = true;
846
847                                         }
848                                 }
849                                 delete pSpeedDialListEnum;
850                                 delete pSpeedDialList;
851                                 if(bFound == true)
852                                 {
853                                         UpdateAllButtons();
854                                 }
855
856                         }
857                                  break;
858                         case RECORD_CHANGE_TYPE_ADDED:
859                                 break;
860                         default:
861                                 break;
862                  }
863                  AppLog("Contact changed: type(%d), id(%d), version(%d)", pInfo->GetChangeType(), pInfo->GetContactId(), pInfo->GetVersion());
864         }
865         delete pEnum;
866 }