Initialize Tizen 2.3
[apps/osp/Contacts.git] / src / CtContactsApp.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        CtContactsApp.cpp
19  * @brief       This is the implementation file for the ContactsApp class.
20  */
21
22 #include <FIo.h>
23 #include "CtContactsApp.h"
24 #include "CtContactListPresentationModel.h"
25 #include "CtGroupContactListPresentationModel.h"
26 #include "CtGroupListPresentationModel.h"
27 #include "CtIContactsAppStateChangeEventListener.h"
28 #include "CtMainFrame.h"
29 #include "CtResourceManager.h"
30 #include "CtTypes.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Base::Utility;
36 using namespace Tizen::Io;
37 using namespace Tizen::System;
38 using namespace Tizen::Ui;
39 using namespace Tizen::Ui::Controls;
40
41 static const wchar_t* SELECTION_MODE = L"selectionMode";
42 static const wchar_t* SELECTION_MODE_SINGLE = L"single";
43 static const wchar_t* SELECTION_MODE_MULTIPLE = L"multiple";
44 static const wchar_t* RETURN_TYPE = L"returnType";
45 static const wchar_t* PHONE = L"phone";
46 static const wchar_t* EMAIL = L"email";
47 static const wchar_t* URL = L"url";
48 static const wchar_t* VIEW_TYPE = L"viewType";
49 static const wchar_t* CONTACT_ID = L"contactId";
50 static const wchar_t* PATH = L"path";
51 static const wchar_t* VALUE_VIEW_TYPE_CONTACT = L"contact";
52 static const wchar_t* VALUE_VIEW_TYPE_VCF = L"vcf";
53 static const wchar_t* VIEW_MIME_TYPE_VCF = L"text/vcard";
54 static const wchar_t* VIEW_URI_VCF_PREFIX = L"file:///";
55
56 static const wchar_t* FONT_SIZE_STR_NORMAL = L"medium";
57
58 static const int LIST_ITEM_SINGLE_LINE_NORMAL_HEIGHT = 112;
59 static const int FONT_SIZE_NORMAL = 44;
60
61 ContactsApp::ContactsApp(void)
62  : __initialSceneId(IDSCN_CONTACT_LIST)
63  , __pArgs(null)
64  , __operationId(L"")
65  , __selectionMode(APP_CONTROL_SELECTION_MODE_NONE)
66  , __returnType(APP_CONTROL_RETURN_TYPE_NONE)
67  , __requestId(0)
68 {
69         __listenerList.Construct();
70 }
71
72 ContactsApp::~ContactsApp(void)
73 {
74 }
75
76 UiApp*
77 ContactsApp::CreateInstance(void)
78 {
79         static ContactsApp* pContactsAppInstance = null;
80         if (pContactsAppInstance == null)
81         {
82                 pContactsAppInstance = new (std::nothrow) ContactsApp();
83         }
84
85         return pContactsAppInstance;
86 }
87
88 bool
89 ContactsApp::OnAppInitializing(Tizen::App::AppRegistry& appRegistry)
90 {
91         AppControlProviderManager* pProviderManager = AppControlProviderManager::GetInstance();
92         result r = pProviderManager->SetAppControlProviderEventListener(this);
93         TryReturn(r == E_SUCCESS, false, "[%s] Failed to set AppControlProviderEventListener", GetErrorMessage(r));
94
95         r = SettingInfo::AddSettingEventListener(*this);
96         if (IsFailed(r))
97         {
98                 AppLogDebug("[%s] Failed to add SettingEventListener", GetErrorMessage(r));
99         }
100
101         return true;
102 }
103
104 bool
105 ContactsApp::OnAppInitialized(void)
106 {
107         InitializeFontSize();
108
109         MainFrame* pContactFrame = new (std::nothrow) MainFrame();
110         pContactFrame->Construct();
111         pContactFrame->SetName(ResourceManager::GetString(L"IDS_COM_BODY_CONTACTS"));
112         AddFrame(*pContactFrame);
113
114         return true;
115 }
116
117 bool
118 ContactsApp::OnAppWillTerminate(void)
119 {
120         return true;
121 }
122
123 bool
124 ContactsApp::OnAppTerminating(Tizen::App::AppRegistry& appRegistry, bool forcedTermination)
125 {
126         result r = SettingInfo::RemoveSettingEventListener(*this);
127         if (IsFailed(r))
128         {
129                 AppLogDebug("[%s] Failed to remove SettingEventListener", GetErrorMessage(r));
130         }
131
132         return true;
133 }
134
135 void
136 ContactsApp::OnForeground(void)
137 {
138         IEnumerator* pEnum = __listenerList.GetEnumeratorN();
139
140         while (pEnum->MoveNext() == E_SUCCESS)
141         {
142                 IContactsAppStateChangeEventListener* pInterface = static_cast<IContactsAppStateChangeEventListener*>(pEnum->GetCurrent());
143                 if (pInterface == null)
144                 {
145                         delete pEnum;
146
147                         return;
148                 }
149                 pInterface->OnForeground();
150         }
151         delete pEnum;
152 }
153
154 void
155 ContactsApp::OnBackground(void)
156 {
157         IEnumerator* pEnum = __listenerList.GetEnumeratorN();
158         while (pEnum->MoveNext() == E_SUCCESS)
159         {
160                 IContactsAppStateChangeEventListener* pInterface = static_cast<IContactsAppStateChangeEventListener*>(pEnum->GetCurrent());
161                 if (pInterface == null)
162                 {
163                         delete pEnum;
164
165                         return;
166                 }
167                 pInterface->OnBackground();
168         }
169         delete pEnum;
170 }
171
172 void
173 ContactsApp::OnLowMemory(void)
174 {
175 }
176
177 void
178 ContactsApp::OnBatteryLevelChanged(Tizen::System::BatteryLevel batteryLevel)
179 {
180 }
181
182 void
183 ContactsApp::OnScreenOn(void)
184 {
185 }
186
187 void
188 ContactsApp::OnScreenOff(void)
189 {
190 }
191
192 void
193 ContactsApp::OnAppCheckpointing(Tizen::App::AppRegistry& appRegistry)
194 {
195 }
196
197 void
198 ContactsApp::OnSettingChanged(Tizen::Base::String& key)
199 {
200         if (key.Equals(SETTING_KEY_LANGUAGE, false) == true || key.Equals(SETTING_KEY_COUNTRY, false) == true || key.Equals(SETTING_KEY_FONTSIZE, false) == true)
201         {
202                 if (__operationId.Equals(OPERATION_ID_PICK, true))
203                 {
204                         result r = AppControlProviderManager::GetInstance()->SendAppControlResult(__requestId, APP_CTRL_RESULT_TERMINATED, null);
205                         TryReturnVoid(r == E_SUCCESS, "[%s] Unable to return result.", GetErrorMessage(r));
206                 }
207                 Terminate();
208         }
209 }
210
211 void
212 ContactsApp::OnAppControlRequestReceived(RequestId reqId, const Tizen::Base::String& operationId, const Tizen::Base::String* pUriData,
213                                                                                         const Tizen::Base::String* pMimeType, const Tizen::Base::Collection::IMap* pExtraData)
214 {
215         AppLogDebug("reqId : %ld, operationId : %ls", reqId, operationId.GetPointer());
216
217         if (pExtraData != null)
218         {
219                 IMapEnumerator* pEnum = pExtraData->GetMapEnumeratorN();
220                 while (pEnum->MoveNext() == E_SUCCESS)
221                 {
222                         String* pKey = static_cast<String*>(pEnum->GetKey());
223                         String* pValue = static_cast<String*>(pEnum->GetValue());
224
225                         AppLogDebug("extraData : %ls:%ls", pKey->GetPointer(), pValue->GetPointer());
226                 }
227                 delete pEnum;
228         }
229
230         result r = E_SUCCESS;
231
232         ArrayList* pArgs = new (std::nothrow) ArrayList();
233         pArgs->Construct();
234
235         if (operationId.Equals(CONTACT_OPERATION_ID_MAIN, true))
236         {
237                 __operationId = L"";
238         }
239         else if (operationId.Equals(CONTACT_OPERATION_ID_PICK, true))
240         {
241                 if (pExtraData == null)
242                 {
243                         AppLogDebug("To launch AppControl by the pick operation, the (key,value) pairs should be input.");
244                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
245                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
246
247                         Terminate();
248
249                         return;
250                 }
251
252                 const String* pItemType = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_ITEM_TYPE)));
253                 if (pItemType == null || pItemType->Equals(ITEM_TYPE_PERSON, true) == false)
254                 {
255                         AppLogDebug("To launch AppControl by the pick operation, the item type should be input.");
256                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
257                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
258
259                         Terminate();
260
261                         return;
262                 }
263
264                 const String* pValue = null;
265
266                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_SELECTION_MODE)));
267                 if (pValue == null || pValue->GetPointer() == null)
268                 {
269                         AppLogDebug("To launch AppControl by the pick operation, the selection mode should be input.");
270                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
271                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
272
273                         Terminate();
274
275                         return;
276                 }
277
278                 String* pSelectionMode = new (std::nothrow) String(SELECTION_MODE);
279                 pSelectionMode->Append(DELIMITER);
280                 pSelectionMode->Append(*pValue);
281                 pArgs->Add(pSelectionMode);
282
283                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_RESULT_TYPE)));
284                 if (pValue == null ||  pValue->GetPointer() == null)
285                 {
286                         AppLogDebug("To launch AppControl by the pick operation, the selection mode should be input.");
287                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
288                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
289                         Terminate();
290
291                         return;
292                 }
293
294                 String* pReturnType = new (std::nothrow) String(RETURN_TYPE);
295                 pReturnType->Append(DELIMITER);
296                 pReturnType->Append(*pValue);
297                 pArgs->Add(pReturnType);
298
299                 r = InitializeAppControl(pArgs);
300                 if (IsFailed(r))
301                 {
302                         AppLogDebug("[%s] initializing app control failed", GetErrorMessage(r));
303                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
304                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
305
306                         Terminate();
307
308                         return;
309                 }
310
311                 if (__selectionMode == APP_CONTROL_SELECTION_MODE_SINGLE)
312                 {
313                         __initialSceneId = IDSCN_CONTACT_LIST;
314                 }
315                 else if (__selectionMode == APP_CONTROL_SELECTION_MODE_MULTI)
316                 {
317                         __initialSceneId = IDSCN_CONTACT_LIST_EDITOR;
318                 }
319                 __operationId = OPERATION_ID_PICK;
320         }
321         else if (operationId.Equals(CONTACT_OPERATION_ID_ADD, true))
322         {
323                 if (pExtraData == null)
324                 {
325                         AppLogDebug("To launch AppControl by the add operation, the (key,value) pairs should be input.");
326                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
327                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
328
329                         Terminate();
330
331                         return;
332                 }
333
334                 const String* pItemType = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_ITEM_TYPE)));
335                 if (pItemType == null || pItemType->Equals(ITEM_TYPE_CONTACT, true) == false)
336                 {
337                         AppLogDebug("To launch AppControl by the add operation, the item type should be input.");
338                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
339                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
340
341                         Terminate();
342
343                         return;
344                 }
345
346                 String* pKey = null;
347                 const String* pValue = null;
348
349                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_PHONE)));
350                 if (pValue && pValue->GetPointer())
351                 {
352                         pKey = new (std::nothrow) String(PHONE);
353                         pKey->Append(DELIMITER);
354                         pKey->Append(*pValue);
355                         pArgs->Add(pKey);
356                 }
357
358                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_EMAIL)));
359                 if (pValue && pValue->GetPointer())
360                 {
361                         pKey = new (std::nothrow) String(EMAIL);
362                         pKey->Append(DELIMITER);
363                         pKey->Append(*pValue);
364                         pArgs->Add(pKey);
365                 }
366
367                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_URL)));
368                 if (pValue && pValue->GetPointer())
369                 {
370                         pKey = new (std::nothrow) String(URL);
371                         pKey->Append(DELIMITER);
372                         pKey->Append(*pValue);
373                         pArgs->Add(pKey);
374                 }
375
376                 __initialSceneId = IDSCN_CONTACT_EDITOR;
377                 __operationId = OPERATION_ID_ADD;
378         }
379         else if (operationId.Equals(CONTACT_OPERATION_ID_EDIT, true))
380         {
381                 if (pExtraData == null)
382                 {
383                         AppLogDebug("To launch AppControl by the edit operation, the (key,value) pairs should be input.");
384                         Terminate();
385
386                         return;
387                 }
388
389                 const String* pItemType = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_ITEM_TYPE)));
390                 if (pItemType == null || pItemType->Equals(ITEM_TYPE_PERSON, true) == false)
391                 {
392                         AppLogDebug("To launch AppControl by the edit operation, the item type should be input.");
393                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
394                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
395
396                         Terminate();
397
398                         return;
399                 }
400
401                 String* pKey = null;
402                 const String* pValue = null;
403
404                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_ITEM_ID)));
405                 if (pValue == null || pValue->GetPointer() == null)
406                 {
407                         AppLogDebug("To launch AppControl by the edit operation, the item_id should be input.");
408                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
409                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
410
411                         Terminate();
412
413                         return;
414                 }
415
416                 pKey = new (std::nothrow) String(RETURN_TYPE_ITEM_ID);
417                 pKey->Append(DELIMITER);
418                 pKey->Append(*pValue);
419                 pArgs->Add(pKey);
420
421                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_PHONE)));
422                 if (pValue && pValue->GetPointer())
423                 {
424                         pKey = new (std::nothrow) String(PHONE);
425                         pKey->Append(DELIMITER);
426                         pKey->Append(*pValue);
427                         pArgs->Add(pKey);
428                 }
429
430                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_EMAIL)));
431                 if (pValue && pValue->GetPointer())
432                 {
433                         pKey = new (std::nothrow) String(EMAIL);
434                         pKey->Append(DELIMITER);
435                         pKey->Append(*pValue);
436                         pArgs->Add(pKey);
437                 }
438
439                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_URL)));
440                 if (pValue && pValue->GetPointer())
441                 {
442                         pKey = new (std::nothrow) String(URL);
443                         pKey->Append(DELIMITER);
444                         pKey->Append(*pValue);
445                         pArgs->Add(pKey);
446                 }
447
448                 __initialSceneId = IDSCN_CONTACT_EDITOR;
449                 __operationId = OPERATION_ID_EDIT;
450         }
451         else if (operationId.Equals(CONTACT_OPERATION_ID_CHOOSE, true))
452         {
453                 if (pExtraData == null)
454                 {
455                         AppLogDebug("To launch AppControl by the choose operation, the (key,value) pairs should be input.");
456                         Terminate();
457
458                         return;
459                 }
460
461                 const String* pItemType = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_ITEM_TYPE)));
462                 if (pItemType == null || pItemType->Equals(ITEM_TYPE_PERSON, true) == false)
463                 {
464                         AppLogDebug("To launch AppControl by the edit operation, the item type should be input.");
465                         r = AppControlProviderManager::GetInstance()->SendAppControlResult(reqId, APP_CTRL_RESULT_FAILED, null);
466                         AppLogDebug("[%s] The return result from SendAppControlResult().", GetErrorMessage(r));
467
468                         Terminate();
469
470                         return;
471                 }
472
473                 String* pKey = null;
474                 const String* pValue = null;
475
476                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_PHONE)));
477                 if (pValue && pValue->GetPointer())
478                 {
479                         pKey = new (std::nothrow) String(PHONE);
480                         pKey->Append(DELIMITER);
481                         pKey->Append(*pValue);
482                         pArgs->Add(pKey);
483                 }
484
485                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_EMAIL)));
486                 if (pValue && pValue->GetPointer())
487                 {
488                         pKey = new (std::nothrow) String(EMAIL);
489                         pKey->Append(DELIMITER);
490                         pKey->Append(*pValue);
491                         pArgs->Add(pKey);
492                 }
493
494                 pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_URL)));
495                 if (pValue && pValue->GetPointer())
496                 {
497                         pKey = new (std::nothrow) String(URL);
498                         pKey->Append(DELIMITER);
499                         pKey->Append(*pValue);
500                         pArgs->Add(pKey);
501                 }
502
503                 __initialSceneId = IDSCN_CONTACT_LIST;
504                 __operationId = OPERATION_ID_EDIT;
505         }
506         else if (operationId.Equals(CONTACT_OPERATION_ID_VIEW, true))
507         {
508                 String* pErrorType = null;
509                 if (pExtraData == null)
510                 {
511                         AppLogDebug("To launch AppControl by the view operation, the (key,value) pairs should be input.");
512                         Terminate();
513
514                         return;
515                 }
516
517                 const String* pItemType = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_ITEM_TYPE)));
518                 if (pItemType == null || pItemType->Equals(ITEM_TYPE_PERSON, true) == false)
519                 {
520                         AppLogDebug("To launch AppControl by the view operation, the item type should be input.");
521                         pErrorType = new (std::nothrow) String(ResourceManager::GetString(L"IDS_RSSR_BODY_INVALID_FORMAT"));
522                 }
523
524                 String* pViewType = new (std::nothrow) String(VIEW_TYPE);
525                 pViewType->Append(DELIMITER);
526                 pViewType->Append(VALUE_VIEW_TYPE_CONTACT);
527                 pArgs->Add(pViewType);
528
529                 const String* pValue = static_cast<const String*>(pExtraData->GetValue(String(CONTACT_KEY_ITEM_ID)));
530                 if (pValue == null || pValue->GetPointer() == null)
531                 {
532                         AppLogDebug("To launch AppControl by the view operation, the itemId should be input.");
533                         if (pErrorType == null)
534                         {
535                                 pErrorType = new (std::nothrow) String(ResourceManager::GetString(L"IDS_RSSR_BODY_INVALID_FORMAT"));
536                         }
537                 }
538
539                 String* pKey = new (std::nothrow) String(CONTACT_ID);
540                 pKey->Append(DELIMITER);
541                 if (pValue != null)
542                 {
543                         pKey->Append(*pValue);
544                 }
545                 pArgs->Add(pKey);
546                 pArgs->Add(pErrorType);
547
548                 __initialSceneId = IDSCN_CONTACT_DETAILS;
549                 __operationId = OPERATION_ID_VIEW;
550         }
551         else if (operationId.Equals(OPERATION_ID_VIEW, true))
552         {
553                 String* pErrorType = null;
554                 String vcfPrefix(VIEW_URI_VCF_PREFIX);
555                 String path;
556                 String mimeType;
557
558                 if (pUriData == null)
559                 {
560                         AppLogDebug("To launch AppControl by the view operation, the uri data should be input.");
561                         pErrorType = new (std::nothrow) String(ResourceManager::GetString(L"IDS_RSSR_BODY_INVALID_FORMAT"));
562                 }
563                 else
564                 {
565                         if (pMimeType != null)
566                         {
567                                 mimeType.Append(*pMimeType);
568                         }
569
570                         if (pUriData->StartsWith(vcfPrefix, 0))
571                         {
572                                 pUriData->SubString(vcfPrefix.GetLength() - 1, pUriData->GetLength() - vcfPrefix.GetLength() + 1, path);
573                                 mimeType.Clear();
574                                 mimeType.Append(VIEW_MIME_TYPE_VCF);
575                         }
576                         else
577                         {
578                                 path.Append(*pUriData);
579                         }
580
581                         if (mimeType.Equals(VIEW_MIME_TYPE_VCF, true) == false)
582                         {
583                                 AppLogDebug("The MIME type is wrong.");
584                                 pErrorType = new (std::nothrow) String(ResourceManager::GetString(L"IDS_RSSR_BODY_INVALID_FORMAT"));
585                         }
586                         else if (File::IsFileExist(path) == false)
587                         {
588                                 AppLogDebug("The vcf file does not exist.");
589                                 pErrorType = new (std::nothrow) String(ResourceManager::GetString(L"IDS_MP_POP_INVALID_FILE"));
590                         }
591                 }
592
593                 String* pViewType = new (std::nothrow) String(VIEW_TYPE);
594                 pViewType->Append(DELIMITER);
595                 pViewType->Append(VALUE_VIEW_TYPE_VCF);
596
597                 pArgs->Add(pViewType);
598
599                 String* pKey = new (std::nothrow) String(PATH);
600                 pKey->Append(DELIMITER);
601                 pKey->Append(path);
602
603                 pArgs->Add(pKey);
604
605                 pArgs->Add(pErrorType);
606
607                 __initialSceneId = IDSCN_CONTACT_DETAILS;
608                 __operationId = OPERATION_ID_VIEW;
609         }
610         else if (operationId.Equals(OPERATION_ID_CONFIGURE, true))
611         {
612                 __initialSceneId = IDSCN_SETTINGS;
613                 __operationId = OPERATION_ID_CONFIGURE;
614         }
615         else
616         {
617                 AppLogDebug("Invalid OperationId");
618                 __operationId = L"";
619         }
620
621         __pArgs = pArgs;
622         __requestId = reqId;
623 }
624
625 result
626 ContactsApp::InitializeAppControl(Tizen::Base::Collection::IList* pArgs)
627 {
628         TryReturn(pArgs != null, E_INVALID_ARG, "[E_INVALID_ARG] app control argument is invalid");
629
630         String key;
631         String value;
632         String* pArgString = static_cast<String*>(pArgs->GetAt(0));
633         TryReturn(pArgString, E_FAILURE, "[E_FAILURE] Unable to cast argument string");
634         result r = ParseAppControlArgument(*pArgString, key, value);
635         TryReturn(r == E_SUCCESS, r, "[%s] Unable to parse the argument", GetErrorMessage(r));
636
637         if (key.Equals(SELECTION_MODE, true))
638         {
639                 if (value.Equals(SELECTION_MODE_SINGLE, true))
640                 {
641                         __selectionMode = APP_CONTROL_SELECTION_MODE_SINGLE;
642                 }
643                 else if (value.Equals(SELECTION_MODE_MULTIPLE, true))
644                 {
645                         __selectionMode = APP_CONTROL_SELECTION_MODE_MULTI;
646                 }
647                 else
648                 {
649                         AppLogDebug("selectionMode of AppControl[PICK] should be either single or multiple. [%ls] has been input", value.GetPointer());
650                         return E_FAILURE;
651                 }
652         }
653
654         pArgString = static_cast<String*>(pArgs->GetAt(1));
655         TryReturn(pArgString, E_FAILURE, "[E_FAILURE] Unable to cast argument string");
656         r = ParseAppControlArgument(*pArgString, key, value);
657         TryReturn(r == E_SUCCESS, r, "[%s] Unable to parse the argument", GetErrorMessage(r));
658
659         if (key.Equals(RETURN_TYPE, true))
660         {
661                 if (value.Equals(RETURN_TYPE_PHONE, true))
662                 {
663                         __returnType = APP_CONTROL_RETURN_TYPE_PHONE;
664                 }
665                 else if (value.Equals(RETURN_TYPE_EMAIL, true))
666                 {
667                         __returnType = APP_CONTROL_RETURN_TYPE_EMAIL;
668                 }
669                 else if (value.Equals(RETURN_TYPE_ITEM_ID, true))
670                 {
671                         __returnType = APP_CONTROL_RETURN_TYPE_ITEM_ID;
672                 }
673                 else if (value.Equals(RETURN_TYPE_VCARD, true))
674                 {
675                         __returnType = APP_CONTROL_RETURN_TYPE_VCARD;
676                 }
677                 else
678                 {
679                         AppLogDebug("returnType of AppControl[PICK] should be one of {phone, email, contactId, and vcard}. [%ls] has been input", value.GetPointer());
680                         return E_FAILURE;
681                 }
682         }
683
684         if (__returnType == APP_CONTROL_RETURN_TYPE_VCARD && __selectionMode == APP_CONTROL_SELECTION_MODE_MULTI)
685         {
686                 return E_FAILURE;
687         }
688
689         return E_SUCCESS;
690 }
691
692 result
693 ContactsApp::ParseAppControlArgument(const Tizen::Base::String& argument, Tizen::Base::String& type, Tizen::Base::String& content)
694 {
695         result r = E_SUCCESS;
696
697         if (argument.IsEmpty() || argument.Contains(DELIMITER) == false)
698         {
699                 return E_FAILURE;
700         }
701
702         StringTokenizer stringToken(argument, DELIMITER);
703
704         r = stringToken.GetNextToken(type);
705         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get type", GetErrorMessage(r));
706
707         r = stringToken.GetNextToken(content);
708         TryReturn(r == E_SUCCESS, r, "[%s] Unable to get content", GetErrorMessage(r));
709
710         return r;
711 }
712
713 Tizen::Base::String
714 ContactsApp::GetOperationId(void)
715 {
716         return __operationId;
717 }
718
719 AppControlSelectionMode
720 ContactsApp::GetSelectionMode(void)
721 {
722         return __selectionMode;
723 }
724
725 AppControlReturnType
726 ContactsApp::GetReturnType(void)
727 {
728         return __returnType;
729 }
730
731 RequestId
732 ContactsApp::GetRequestId(void)
733 {
734         return __requestId;
735 }
736
737 Tizen::Ui::Scenes::SceneId
738 ContactsApp::GetInitialSceneId(void)
739 {
740         return __initialSceneId;
741 }
742
743 Tizen::Base::Collection::IList*
744 ContactsApp::GetArguments(void)
745 {
746         return __pArgs;
747 }
748
749 void
750 ContactsApp::InitializeFontSize(void)
751 {
752         String fontSizeStr = "";
753         SettingInfo::GetValue("http://tizen.org/setting/font.size", fontSizeStr);
754         __fontSize = Tizen::Ui::UiConfiguration::GetFontSize(fontSizeStr);
755         if (__fontSize <= 0)
756         {
757                 __fontSize = FONT_SIZE_NORMAL;
758         }
759         AppLogDebug("__fontSize = %d", __fontSize);
760 }
761
762 int
763 ContactsApp::GetFontSize(void)
764 {
765         return __fontSize;
766 }
767
768 int
769 ContactsApp::GetListItemSingleLineHeight(void)
770 {
771         int listItemHeight = LIST_ITEM_SINGLE_LINE_NORMAL_HEIGHT;
772         listItemHeight += (__fontSize - Tizen::Ui::UiConfiguration::GetFontSize(FONT_SIZE_STR_NORMAL));
773         return listItemHeight;
774 }
775
776 int
777 ContactsApp::GetFontHeightOffset(void)
778 {
779         return (__fontSize - Tizen::Ui::UiConfiguration::GetFontSize(FONT_SIZE_STR_NORMAL));
780 }
781
782
783 void
784 ContactsApp::AddContactsAppChangeEventListener(const IContactsAppStateChangeEventListener& listener)
785 {
786         __listenerList.Add(listener);
787 }
788
789 void
790 ContactsApp::RemoveContactsAppChangeEventListener(const IContactsAppStateChangeEventListener& listener)
791 {
792         __listenerList.Remove(listener);
793 }