Tizen 2.0 Release
[apps/osp/Phone.git] / src / PhnSettingsManager.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    PhnSettingsManager.cpp
19  * @brief   Setting Manager class
20  */
21 #include <libintl.h>
22 #include <FApp.h>
23 #include <FSocial.h>
24 #include <FBaseColIList.h>
25 #include "vconf.h"
26 #include "vconf-internal-ciss-keys.h"
27 #include "PhnSettingsManager.h"
28 #include "PhnTypes.h"
29
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Io;
34 using namespace Tizen::Social;
35
36 SettingsManager* SettingsManager::__pInstance = null;
37
38 SettingsManager::SettingsManager(void)
39         : __pTapiHandle(null)
40         , __pSettingsEventListener(null)
41         , __pCallSettingDataService(null)
42 {
43
44 }
45
46 SettingsManager::~SettingsManager(void)
47 {
48         //De-initialize the TAPI Library
49         if(__pTapiHandle != null)
50         {
51                 tel_deinit(__pTapiHandle);
52         }
53         if (__pCallSettingDataService)
54         {
55                 __pCallSettingDataService->CloseDatabase();
56                 delete __pCallSettingDataService;
57         }
58         if (__pSettingsEventListener != null)
59         {
60                 delete __pSettingsEventListener;
61         }
62 }
63
64 void SettingsManager::CreateInstance(void)
65 {
66         __pInstance = new (std::nothrow) SettingsManager();
67         result r = __pInstance->Construct();
68         if(IsFailed(r))
69         {
70                 delete __pInstance;
71                 __pInstance = null;
72                 return;
73         }
74         std::atexit(&(SettingsManager::DestroyInstance));
75 }
76
77 void SettingsManager::DestroyInstance(void)
78 {
79         delete __pInstance;
80 }
81
82 result
83 SettingsManager::Construct(void)
84 {
85         __pCallSettingDataService = CallSettingDataService::CreateInstance();
86         result r = __pCallSettingDataService->OpenDatabase();
87         if(IsFailed(r))
88         {
89                 return E_FAILURE;
90         }
91         //initialize telephony
92         __pTapiHandle = tel_init(null);
93         SetCallState(CALL_STATE__CALL_OFF);
94         return E_SUCCESS;
95 }
96
97 SettingsManager*
98 SettingsManager::GetInstance(void)
99 {
100         if (__pInstance == null)
101         {
102                 CreateInstance();
103         }
104         return __pInstance;
105 }
106
107 void
108 SettingsManager::AddSettingEventListener(ISettingsEventListener* pSettingsEventListener)
109 {
110         if (__pSettingsEventListener == null)
111         {
112                 __pSettingsEventListener = new (std::nothrow) ArrayListT<ISettingsEventListener*>();
113         }
114
115         //Add to listeners, if not already in list.
116         if ( (pSettingsEventListener != null)
117                         && !(__pSettingsEventListener->Contains(pSettingsEventListener)) )
118         {
119                 __pSettingsEventListener->Add(pSettingsEventListener);
120         }
121 }
122
123 void
124 SettingsManager::RemoveSettingEventListener(ISettingsEventListener* pSettingsEventListener)
125 {
126         if ((__pSettingsEventListener != null) && (pSettingsEventListener != null)
127                         && __pSettingsEventListener->Contains(pSettingsEventListener))
128         {
129                 __pSettingsEventListener->Remove(pSettingsEventListener);
130         }
131 }
132
133 void
134 SettingsManager::NotifyForwardingEventListeners(ForwardResponseType responseType, bool isCallSuccessful, CallForwardCondition callFwdCondition, const Tizen::Base::String& callFwdNumber, bool isCallForwardActivated, int noReplyWaitTime)
135 {
136         IEnumeratorT<ISettingsEventListener*>* pListenerEnum = null;
137         result r = E_FAILURE;
138         if (__pSettingsEventListener != null)
139         {
140                 pListenerEnum = __pSettingsEventListener->GetEnumeratorN();
141                 //TryReturn(pListenerEnum != null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
142
143                 while ((r = pListenerEnum->MoveNext()) != E_OUT_OF_RANGE)
144                 {
145                         ISettingsEventListener* pListener;
146                         r = pListenerEnum->GetCurrent(pListener);
147                         //TryCatch(r == E_SUCCESS, , "[%s] Propagated.", GetErrorMessage(r));
148                         if (responseType == SET_CALLFORWARD_RESPONSE)
149                         {
150                                 pListener->HandleSetCallForwardResponse(isCallSuccessful, callFwdCondition, callFwdNumber, isCallForwardActivated, noReplyWaitTime);
151                         }
152                         else
153                         {
154                                 pListener->HandleGetCallForwardResponse(isCallSuccessful, callFwdCondition, callFwdNumber, isCallForwardActivated, noReplyWaitTime);
155                         }
156                 }
157         }
158 }
159
160 void
161 SettingsManager::NotifyBarringEventListeners(BarringResponseType responseType, bool isCallSuccessful, CallBarringType callBarringType, bool isBarringActivated)
162 {
163         IEnumeratorT<ISettingsEventListener*>* pListenerEnum = null;
164         result r = E_FAILURE;
165         if (__pSettingsEventListener != null)
166         {
167                 pListenerEnum = __pSettingsEventListener->GetEnumeratorN();
168                 //TryReturn(pListenerEnum != null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
169
170                 while ((r = pListenerEnum->MoveNext()) != E_OUT_OF_RANGE)
171                 {
172                         ISettingsEventListener* pListener;
173                         r = pListenerEnum->GetCurrent(pListener);
174                         //TryCatch(r == E_SUCCESS, , "[%s] Propagated.", GetErrorMessage(r));
175                         if (responseType == SET_CALLBARRING_RESPONSE)
176                         {
177                                 pListener->HandleSetCallBarringResponse(isCallSuccessful, callBarringType, isBarringActivated);
178                         }
179                         else
180                         {
181                                 pListener->HandleGetCallBarringResponse(isCallSuccessful, callBarringType, isBarringActivated);
182                         }
183                 }
184         }
185 }
186
187 void
188 SettingsManager::NotifyWaitingEventListeners(WaitingResponseType responseType, bool isCallSuccessful, bool isCallWaitingActivated)
189 {
190         IEnumeratorT<ISettingsEventListener*>* pListenerEnum = null;
191         result r = E_FAILURE;
192         if (__pSettingsEventListener != null)
193         {
194                 pListenerEnum = __pSettingsEventListener->GetEnumeratorN();
195                 //TryReturn(pListenerEnum != null, GetLastResult(), "[%s] Propagated.", GetErrorMessage(GetLastResult()));
196
197                 while ((r = pListenerEnum->MoveNext()) != E_OUT_OF_RANGE)
198                 {
199                         ISettingsEventListener* pListener;
200                         r = pListenerEnum->GetCurrent(pListener);
201                         //TryCatch(r == E_SUCCESS, , "[%s] Propagated.", GetErrorMessage(r));
202                         if (responseType == SET_CALLWAITING_RESPONSE)
203                         {
204                                 pListener->HandleSetCallWaitingResponse(isCallSuccessful, isCallWaitingActivated);
205                         }
206                         else
207                         {
208                                 pListener->HandleGetCallWaitingResponse(isCallSuccessful, isCallWaitingActivated);
209                         }
210                 }
211                 delete pListenerEnum;
212         }
213 }
214
215 int
216 SettingsManager::SetCallForwardStatus(const String& phoneNumber, CallForwardCondition callFwdCondition, bool activateFwding, int noReplyTime)
217 {
218         int errorCode = ERROR_NONE;
219         TryReturn(__pTapiHandle != null, ERROR_TAPI_INIT_FAILED, "Telephony initialization failed");
220
221         TelSsForwardInfo_t forwardInfo;
222         memset(&forwardInfo, 0, sizeof(TelSsForwardInfo_t));
223         forwardInfo.Class = TAPI_SS_CLASS_VOICE;
224         if (activateFwding == true)
225         {
226                 forwardInfo.Mode = TAPI_SS_CF_MODE_REGISTRATION_EV;
227         }
228         else
229         {
230                 forwardInfo.Mode = TAPI_SS_CF_MODE_ERASURE_EV;
231         }
232         const wchar_t* pContact = phoneNumber.GetPointer();
233         int len = phoneNumber.GetLength()+1;
234         char* pNumber = new (std::nothrow) char[len];
235         wcstombs(pNumber, pContact, len);
236         strncpy(forwardInfo.szPhoneNumber, pNumber, len);
237         delete []pNumber;
238         pNumber = null;
239         switch (callFwdCondition)
240         {
241         case CALL_FORWARD_ALL:
242         {
243                 forwardInfo.Condition = TAPI_SS_CF_WHEN_CFU;
244         }
245         break;
246
247         case CALL_FORWARD_BUSY:
248         {
249                 forwardInfo.Condition = TAPI_SS_CF_WHEN_CFB;
250         }
251         break;
252
253         case CALL_FORWARD_NO_REPLY:
254         {
255                 forwardInfo.Condition = TAPI_SS_CF_WHEN_CFNRy;
256                 forwardInfo.NoReplyConditionTimer = TelSsNoReplyTime_t(noReplyTime);
257         }
258         break;
259
260         case CALL_FORWARD_NOT_REACHABLE:
261         {
262                 forwardInfo.Condition = TAPI_SS_CF_WHEN_CFNRc;
263         }
264         break;
265
266         default:
267         {
268                 return ERROR_INVALID_INPUT;
269         }
270         break;
271         }
272
273         int retStatus = tel_set_ss_forward(__pTapiHandle, &forwardInfo, &HandleSetForwardResponse, this);
274         if (retStatus != TAPI_API_SUCCESS)
275         {
276                 errorCode = ERROR_TAPI_ERROR;
277         }
278         return errorCode;
279 }
280
281 void
282 SettingsManager::HandleSetForwardResponse(TapiHandle* pHandle, int result, void* pData, void* pUserData)
283 {
284         TelSsForwardResp_t* pResponse = (TelSsForwardResp_t*) pData;
285         SettingsManager* pSettingsManager = (SettingsManager*) pUserData;
286         if (pResponse != null)
287         {
288                 int count = pResponse->record_num;
289                 for (int index = 0; index < count; index++)
290                 {
291                         CallForwardCondition callFwdCondition = CALL_FORWARD_ALL;
292                         bool isActivated = false;
293                         int noReplyWaitTime = 0;
294                         //Check if status is "Active or Quiescent" and forwarding number is available
295                         if ((pResponse->record[index].Status == TAPI_SS_STATUS_ACTIVE
296                                         || pResponse->record[index].Status == TAPI_SS_STATUS_QUIESCENT
297                                         || pResponse->record[index].Status == TAPI_SS_STATUS_REGISTERED)
298                                         && (pResponse->record[index].bCallForwardingNumberPresent != 0))
299                         {
300                                 isActivated = true;
301                         }
302                         switch (pResponse->record[index].ForwardCondition)
303                         {
304                         case TAPI_SS_CF_WHEN_CFU:
305                         {
306                                 callFwdCondition = CALL_FORWARD_ALL;
307                         }
308                         break;
309
310                         case TAPI_SS_CF_WHEN_CFB:
311                         {
312                                 callFwdCondition = CALL_FORWARD_BUSY;
313                         }
314                         break;
315
316                         case TAPI_SS_CF_WHEN_CFNRy:
317                         {
318                                 callFwdCondition = CALL_FORWARD_NO_REPLY;
319                                 //fetch WaitTime
320                                 noReplyWaitTime = (pResponse->record[index].NoReplyWaitTime);
321                         }
322                         break;
323
324                         case TAPI_SS_CF_WHEN_CFNRc:
325                         {
326                                 callFwdCondition = CALL_FORWARD_NOT_REACHABLE;
327                         }
328                         break;
329
330                         default:
331                                 break;
332                         }
333                         //fetch forwarding number
334                         char* pTmpNumberPtr = new (std::nothrow) char[TAPI_CALL_DIALDIGIT_LEN_MAX];
335                         strncpy(pTmpNumberPtr, (char*) (pResponse->record[index].szCallForwardingNumber), TAPI_CALL_DIALDIGIT_LEN_MAX);
336                         String callFwdNumber(pTmpNumberPtr);
337                         delete []pTmpNumberPtr;
338                         pTmpNumberPtr = null;
339
340                         //notify event listeners
341                         pSettingsManager->NotifyForwardingEventListeners(SET_CALLFORWARD_RESPONSE,(result == TAPI_SS_SUCCESS),callFwdCondition, callFwdNumber, isActivated, noReplyWaitTime);
342                 }
343         }
344 }
345
346 int
347 SettingsManager::GetCallForwardStatus(CallForwardCondition callFwdCondition)
348 {
349         int errorCode = ERROR_NONE;
350         TryReturn(__pTapiHandle != null,ERROR_TAPI_INIT_FAILED,"Telephony initialization failed");
351
352         TelSsForwardWhen_t condition;
353         switch (callFwdCondition)
354         {
355         case CALL_FORWARD_ALL:
356         {
357                 condition = TAPI_SS_CF_WHEN_CFU;
358         }
359         break;
360
361         case CALL_FORWARD_BUSY:
362         {
363                 condition = TAPI_SS_CF_WHEN_CFB;
364         }
365         break;
366
367         case CALL_FORWARD_NO_REPLY:
368         {
369                 condition = TAPI_SS_CF_WHEN_CFNRy;
370         }
371         break;
372
373         case CALL_FORWARD_NOT_REACHABLE:
374         {
375                 condition = TAPI_SS_CF_WHEN_CFNRc;
376         }
377         break;
378
379         default:
380         {
381                 return ERROR_INVALID_INPUT;
382         }
383         break;
384         }
385         int retStatus = tel_get_ss_forward_status(__pTapiHandle, TAPI_SS_CLASS_VOICE, condition, &HandleGetForwardResponse, this);
386         if (retStatus != TAPI_API_SUCCESS)
387         {
388                 errorCode = ERROR_TAPI_ERROR;
389         }
390
391         return errorCode;
392 }
393
394 void
395 SettingsManager::HandleGetForwardResponse(TapiHandle* pHandle, int result, void* pData, void* pUserData)
396 {
397         TelSsForwardResp_t* pResponse = (TelSsForwardResp_t*) pData;
398         SettingsManager* pSettingsManager = (SettingsManager*) pUserData;
399         if (pResponse != null)
400         {
401                 int count = pResponse->record_num;
402                 for (int index = 0; index < count; index++)
403                 {
404                         CallForwardCondition callFwdCondition = CALL_FORWARD_ALL;
405                         bool isActivated = false;
406                         int noReplyWaitTime = 0;
407                         //Check if status is "ACTIVE or QUIESCENT or REGISTERED" and forwarding number is available
408                         if ((pResponse->record[index].Status == TAPI_SS_STATUS_ACTIVE
409                                         || pResponse->record[index].Status == TAPI_SS_STATUS_QUIESCENT
410                                         || pResponse->record[index].Status == TAPI_SS_STATUS_REGISTERED)
411                                         && (pResponse->record[index].bCallForwardingNumberPresent != 0))
412                         {
413                                 isActivated = true;
414                         }
415                         switch (pResponse->record[index].ForwardCondition)
416                         {
417                         case TAPI_SS_CF_WHEN_CFU:
418                         {
419                                 callFwdCondition = CALL_FORWARD_ALL;
420                         }
421                         break;
422
423                         case TAPI_SS_CF_WHEN_CFB:
424                         {
425                                 callFwdCondition = CALL_FORWARD_BUSY;
426                         }
427                         break;
428
429                         case TAPI_SS_CF_WHEN_CFNRy:
430                         {
431                                 callFwdCondition = CALL_FORWARD_NO_REPLY;
432                                 noReplyWaitTime = (pResponse->record[index].NoReplyWaitTime);
433                         }
434                         break;
435
436                         case TAPI_SS_CF_WHEN_CFNRc:
437                         {
438                                 callFwdCondition = CALL_FORWARD_NOT_REACHABLE;
439                         }
440                         break;
441
442                         default:
443                                 break;
444                         }
445                         char* pTmpNumberPtr = new (std::nothrow) char[TAPI_CALL_DIALDIGIT_LEN_MAX];
446                         strncpy(pTmpNumberPtr, (char*) (pResponse->record[index].szCallForwardingNumber), TAPI_CALL_DIALDIGIT_LEN_MAX);
447                         String callFwdNumber(pTmpNumberPtr);
448                         //notify event listeners
449                         pSettingsManager->NotifyForwardingEventListeners(GET_CALLFORWARD_RESPONSE, (result == TAPI_SS_SUCCESS), callFwdCondition, callFwdNumber, isActivated, noReplyWaitTime);
450                         delete []pTmpNumberPtr;
451                         pTmpNumberPtr = null;
452                 }
453         }
454 }
455
456 int
457 SettingsManager::SetCallBarringStatus(const String& password, CallBarringType callBarringType, bool activateBarring)
458 {
459         int errorCode = ERROR_NONE;
460         TryReturn(__pTapiHandle != null, ERROR_TAPI_INIT_FAILED, "Telephony initialization failed");
461
462         TelSsBarringInfo_t barringInfo;
463         memset(&barringInfo, 0, sizeof(TelSsBarringInfo_t));
464         barringInfo.Class = TAPI_SS_CLASS_VOICE;
465         if (activateBarring == true)
466         {
467                 barringInfo.Mode = TAPI_SS_CB_MODE_ACTIVATE;
468         }
469         else
470         {
471                 barringInfo.Mode = TAPI_SS_CB_MODE_DEACTIVATE;
472         }
473         const wchar_t* pContact = password.GetPointer();
474         int len = password.GetLength();
475         if (len > 4)
476         {
477                 return ERROR_BARRING_PWD_TOO_LONG;
478         }
479         char* pNumber = new (std::nothrow) char[len];
480         wcstombs(pNumber, pContact, len);
481         strncpy(barringInfo.szPassword, pNumber, len);
482         delete []pNumber;
483         pNumber = null;
484         switch (callBarringType)
485         {
486         case CALL_BARRING_ALL_OUTGOING:
487         {
488                 barringInfo.Type = TAPI_SS_CB_TYPE_BAOC;
489         }
490         break;
491
492         case CALL_BARRING_INTERNATIONAL_OUTGOING:
493         {
494                 barringInfo.Type = TAPI_SS_CB_TYPE_BOIC;
495         }
496         break;
497
498         case CALL_BARRING_INTERNATIONAL_EXCEPT_HOME:
499         {
500                 barringInfo.Type = TAPI_SS_CB_TYPE_BOIC_NOT_HC;
501         }
502         break;
503
504         case CALL_BARRING_ALL_INCOMING:
505         {
506                 barringInfo.Type = TAPI_SS_CB_TYPE_BAIC;
507         }
508         break;
509
510         case CALL_BARRING_INCOMING_ROAMING:
511         {
512                 barringInfo.Type = TAPI_SS_CB_TYPE_BIC_ROAM;
513         }
514         break;
515
516         default:
517         {
518                 return ERROR_INVALID_INPUT;
519         }
520         break;
521         }
522         int retStatus = tel_set_ss_barring(__pTapiHandle, &barringInfo, &HandleSetBarringResponse, this);
523         if (retStatus != TAPI_API_SUCCESS)
524         {
525                 errorCode = ERROR_TAPI_ERROR;
526         }
527
528         return errorCode;
529 }
530
531 void
532 SettingsManager::HandleSetBarringResponse(TapiHandle* pHandle, int result, void* pData, void* pUserData)
533 {
534         TelSsBarringResp_t* pResponse = (TelSsBarringResp_t*) pData;
535         SettingsManager* pSettingsManager = (SettingsManager*) pUserData;
536         if (pResponse != null)
537         {
538                 CallBarringType callBarringType = CALL_BARRING_ALL_OUTGOING;
539                 bool isActivated = false;
540                 int count = pResponse->record_num;
541                 for (int index = 0; index < count; index++)
542                 {
543                         if (pResponse->record[index].Status == TAPI_SS_STATUS_ACTIVE)
544                         {
545                                 isActivated = true;
546                         }
547                         switch (pResponse->record[index].Flavour)
548                         {
549                         case TAPI_SS_CB_TYPE_BAOC:
550                         {
551                                 callBarringType = CALL_BARRING_ALL_OUTGOING;
552                         }
553                         break;
554
555                         case TAPI_SS_CB_TYPE_BOIC:
556                         {
557                                 callBarringType = CALL_BARRING_INTERNATIONAL_OUTGOING;
558                         }
559                         break;
560
561                         case TAPI_SS_CB_TYPE_BOIC_NOT_HC:
562                         {
563                                 callBarringType = CALL_BARRING_INTERNATIONAL_EXCEPT_HOME;
564                         }
565                         break;
566
567                         case TAPI_SS_CB_TYPE_BAIC:
568                         {
569                                 callBarringType = CALL_BARRING_ALL_INCOMING;
570                         }
571                         break;
572
573                         case TAPI_SS_CB_TYPE_BIC_ROAM:
574                         {
575                                 callBarringType = CALL_BARRING_INCOMING_ROAMING;
576                         }
577                         break;
578
579                         default:
580                                 break;
581                         }
582                         //notify event listeners
583                         pSettingsManager->NotifyBarringEventListeners(SET_CALLBARRING_RESPONSE,(result == TAPI_SS_SUCCESS), callBarringType, isActivated);
584                 }
585         }
586 }
587
588 int
589 SettingsManager::GetCallBarringStatus(CallBarringType callBarringType)
590 {
591         int errorCode = ERROR_NONE;
592         TryReturn(__pTapiHandle != null, ERROR_TAPI_INIT_FAILED, "Telephony initialization failed");
593
594         TelSsBarringType_t barringType;
595         switch (callBarringType)
596         {
597         case CALL_BARRING_ALL_OUTGOING:
598         {
599                 barringType = TAPI_SS_CB_TYPE_BAOC;
600         }
601         break;
602
603         case CALL_BARRING_INTERNATIONAL_OUTGOING:
604         {
605                 barringType = TAPI_SS_CB_TYPE_BOIC;
606         }
607         break;
608
609         case CALL_BARRING_INTERNATIONAL_EXCEPT_HOME:
610         {
611                 barringType = TAPI_SS_CB_TYPE_BOIC_NOT_HC;
612         }
613         break;
614
615         case CALL_BARRING_ALL_INCOMING:
616         {
617                 barringType = TAPI_SS_CB_TYPE_BAIC;
618         }
619         break;
620
621         case CALL_BARRING_INCOMING_ROAMING:
622         {
623                 barringType = TAPI_SS_CB_TYPE_BIC_ROAM;
624         }
625         break;
626
627         default:
628         {
629                 return ERROR_INVALID_INPUT;
630         }
631         break;
632         }
633         int retStatus = tel_get_ss_barring_status(__pTapiHandle, TAPI_SS_CLASS_VOICE, barringType, &HandleGetBarringResponse, this);
634         if (retStatus != TAPI_API_SUCCESS)
635         {
636                 errorCode = ERROR_TAPI_ERROR;
637         }
638
639         return errorCode;
640 }
641
642 void
643 SettingsManager::HandleGetBarringResponse(TapiHandle* pHandle, int result, void* pData, void* pUserData)
644 {
645         TelSsBarringResp_t* pResponse = (TelSsBarringResp_t*) pData;
646         SettingsManager* pSettingsManager = (SettingsManager*) pUserData;
647         if (pResponse != null)
648         {
649                 CallBarringType callBarringType = CALL_BARRING_ALL_OUTGOING;
650                 bool isActivated = false;
651                 int count = pResponse->record_num;
652                 for (int index = 0; index < count; index++)
653                 {
654                         if (pResponse->record[index].Status == TAPI_SS_STATUS_ACTIVE)
655                         {
656                                 isActivated = true;
657                         }
658                         switch (pResponse->record[index].Flavour)
659                         {
660                         case TAPI_SS_CB_TYPE_BAOC:
661                         {
662                                 callBarringType = CALL_BARRING_ALL_OUTGOING;
663                         }
664                         break;
665
666                         case TAPI_SS_CB_TYPE_BOIC:
667                         {
668                                 callBarringType = CALL_BARRING_INTERNATIONAL_OUTGOING;
669                         }
670                         break;
671
672                         case TAPI_SS_CB_TYPE_BOIC_NOT_HC:
673                         {
674                                 callBarringType = CALL_BARRING_INTERNATIONAL_EXCEPT_HOME;
675                         }
676                         break;
677
678                         case TAPI_SS_CB_TYPE_BAIC:
679                         {
680                                 callBarringType = CALL_BARRING_ALL_INCOMING;
681                         }
682                         break;
683
684                         case TAPI_SS_CB_TYPE_BIC_ROAM:
685                         {
686                                 callBarringType = CALL_BARRING_INCOMING_ROAMING;
687                         }
688                         break;
689
690                         default:
691                                 break;
692                         }
693                         //notify event listeners
694                         pSettingsManager->NotifyBarringEventListeners(GET_CALLBARRING_RESPONSE,(result == TAPI_SS_SUCCESS), callBarringType, isActivated);
695                 }
696         }
697 }
698
699 int
700 SettingsManager::SetCallWaitingStatus(bool activateWaiting)
701 {
702         int errorCode = ERROR_NONE;
703         TryReturn(__pTapiHandle != null, ERROR_TAPI_INIT_FAILED,"Telephony initialization failed");
704
705         TelSsWaitingInfo_t waitingInfo;
706         memset(&waitingInfo, 0, sizeof(TelSsWaitingInfo_t));
707         waitingInfo.Class = TAPI_SS_CLASS_VOICE;
708         if (activateWaiting == true)
709         {
710                 waitingInfo.Mode = TAPI_SS_CW_MODE_ACTIVATE;
711         }
712         else
713         {
714                 waitingInfo.Mode = TAPI_SS_CW_MODE_DEACTIVATE;
715         }
716         int retStatus = tel_set_ss_waiting(__pTapiHandle, &waitingInfo, &HandleSetWaitingResponse, this);
717         if (retStatus != TAPI_API_SUCCESS)
718         {
719                 errorCode = ERROR_TAPI_ERROR;
720         }
721
722         return errorCode;
723 }
724
725 void
726 SettingsManager::HandleSetWaitingResponse(TapiHandle* pHandle, int result, void* pData, void* pUserData)
727 {
728         TelSsWaitingResp_t* pResponse = (TelSsWaitingResp_t*) pData;
729         SettingsManager* pSettingsManager = (SettingsManager*) pUserData;
730         bool isCallSuccessful = false;
731         if (result == TAPI_SS_SUCCESS)
732         {
733                 isCallSuccessful = true;
734         }
735         if (pResponse != null)
736         {
737
738                 int count = pResponse->record_num;
739                 if (pSettingsManager->__pSettingsEventListener != null)
740                 {
741                         for (int index = 0; index < count; index++)
742                         {
743                                 //notify event listeners
744                                 bool isCallWaitingEnabled = (pResponse->record[index].Status == TAPI_SS_STATUS_ACTIVE);
745                                 pSettingsManager->NotifyWaitingEventListeners(SET_CALLWAITING_RESPONSE, isCallSuccessful, isCallWaitingEnabled);
746                         }
747                 }
748         }
749 }
750
751 int
752 SettingsManager::GetCallWaitingStatus(void)
753 {
754         int errorCode = ERROR_NONE;
755         TryReturn(__pTapiHandle != null, ERROR_TAPI_INIT_FAILED,"Telephony initialization failed");
756
757         int retStatus = tel_get_ss_waiting_status(__pTapiHandle, TAPI_SS_CLASS_VOICE, &HandleGetWaitingResponse, this);
758         if (retStatus != TAPI_API_SUCCESS)
759         {
760                 errorCode = ERROR_TAPI_ERROR;
761         }
762
763         return errorCode;
764 }
765
766 void
767 SettingsManager::HandleGetWaitingResponse(TapiHandle* pHandle, int result, void* pData, void* pUserData)
768 {
769         TelSsWaitingResp_t* pResponse = (TelSsWaitingResp_t*) pData;
770         SettingsManager* pSettingsManager = (SettingsManager*) pUserData;
771         if (pResponse != null)
772         {
773                 bool isCallSuccessful = false;
774                 if (result == TAPI_SS_SUCCESS)
775                 {
776                         isCallSuccessful = true;
777                 }
778                 int count = pResponse->record_num;
779                 if (pSettingsManager->__pSettingsEventListener != null)
780                 {
781                         for (int index = 0; index < count; index++)
782                         {
783                                 //notify event listeners
784                                 bool isCallWaitingEnabled = (pResponse->record[index].Status == TAPI_SS_STATUS_ACTIVE);
785                                 pSettingsManager->NotifyWaitingEventListeners(GET_CALLWAITING_RESPONSE, isCallSuccessful, isCallWaitingEnabled);
786                         }
787                 }
788         }
789 }
790
791 IMapT<int,String>*
792 SettingsManager::GetRejectMessageListN(void)
793 {
794         int messagesCount;
795         char* pMessage = null;
796         HashMapT<int,String> *pMessageMap = null;
797
798         int retval = vconf_get_int(VCONFKEY_CISSAPPL_REJECT_CALL_MSG_INT, &messagesCount);
799         if (retval == 0 && messagesCount > 0)
800         {
801                 pMessageMap = new (std::nothrow) HashMapT<int,String>();
802                 pMessageMap->Construct(messagesCount);
803                 for (int index = 0; index < messagesCount; index++)
804                 {
805                         int keyForMsg = index;
806                         String *pMessageStr = new (std::nothrow) String();
807                         switch (index)
808                         {
809                         case 0:
810                         {
811                                 pMessage = vconf_get_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG1_STR);
812                         }
813                         break;
814
815                         case 1:
816                         {
817                                 pMessage = vconf_get_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG2_STR);
818                         }
819                         break;
820
821                         case 2:
822                         {
823                                 pMessage = vconf_get_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG3_STR);
824                         }
825                         break;
826
827                         case 3:
828                         {
829                                 pMessage = vconf_get_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG4_STR);
830                         }
831                         break;
832
833                         case 4:
834                         {
835                                 pMessage = vconf_get_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG5_STR);
836                         }
837                         break;
838
839                         case 5:
840                         {
841                                 pMessage = vconf_get_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG6_STR);
842                         }
843                         break;
844
845                         default:
846                         {
847                                 delete pMessageMap;
848                                 pMessageMap = null;
849                                 return null;
850                         }
851                         break;
852                         }
853                         //todo:Chk if this is allowed outside the call settings library
854                         bindtextdomain("ug-setting-call-efl", "/usr/ug/res/locale");
855                         pMessageStr->Append(dgettext("ug-setting-call-efl", pMessage));
856                         pMessageMap->Add(keyForMsg, *pMessageStr);
857                 }
858         }
859         return pMessageMap;
860 }
861
862 result
863 SettingsManager::SetRejectMessage(int messageIndex, const String& rejectMessage)
864 {
865         result r = E_FAILURE;
866         int messagesCount = 0;
867         vconf_get_int(VCONFKEY_CISSAPPL_REJECT_CALL_MSG_INT, &messagesCount);
868         //convert to char*
869         const wchar_t* pRejectMessage = rejectMessage.GetPointer();
870         int len = (rejectMessage.GetLength()*sizeof(wchar_t));
871         char* pMessageToBeSet = new (std::nothrow) char[len + 1];
872         memset(pMessageToBeSet, 0, (len + 1) * sizeof(char));
873         wcstombs(pMessageToBeSet, pRejectMessage, len);
874         //save to vconf
875         int retval = -1;
876
877         switch (messageIndex)
878         {
879         case 0:
880         {
881                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG1_STR, pMessageToBeSet);
882         }
883         break;
884
885         case 1:
886         {
887                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG2_STR, pMessageToBeSet);
888         }
889         break;
890
891         case 2:
892         {
893                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG3_STR, pMessageToBeSet);
894         }
895         break;
896
897         case 3:
898         {
899                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG4_STR, pMessageToBeSet);
900         }
901         break;
902
903         case 4:
904         {
905                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG5_STR, pMessageToBeSet);
906         }
907         break;
908
909         case 5:
910         {
911                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG6_STR, pMessageToBeSet);
912         }
913         break;
914
915         default:
916         {
917                 delete []pMessageToBeSet;
918                 pMessageToBeSet = null;
919                 return r;
920         }
921         break;
922         }
923
924         delete []pMessageToBeSet;
925         pMessageToBeSet = null;
926         if (retval == 0)
927         {
928                 //increment the count only in case of new addition
929                 if (messagesCount < 6 && messageIndex >= messagesCount)
930                 {
931                         messagesCount++;
932                 }
933                 vconf_set_int(VCONFKEY_CISSAPPL_REJECT_CALL_MSG_INT, messagesCount);
934                 r = E_SUCCESS;
935         }
936
937         return r;
938 }
939
940 result
941 SettingsManager::RemoveRejectMessage(const IListT<int>& deleteKeyList)
942 {
943         result r = E_FAILURE;
944         int retval = -1;
945         int newMsgCount = 0;
946         //Fetch old message count
947         int oldMsgCount = 0;
948         vconf_get_int(VCONFKEY_CISSAPPL_REJECT_CALL_MSG_INT, &oldMsgCount);
949         //fetch old messages
950         IMapT<int,String> *pRejectMsgMap = GetRejectMessageListN();
951         if(pRejectMsgMap != null)
952         {
953                 //First,remove all messages from vconf
954                 for (int index = 0; index < oldMsgCount; index++)
955                 {
956                         switch (index)
957                         {
958                         case 0:
959                                 retval = vconf_unset(VCONFKEY_CISSAPPL_USER_CREATE_MSG1_STR);
960                                 break;
961
962                         case 1:
963                                 retval = vconf_unset(VCONFKEY_CISSAPPL_USER_CREATE_MSG2_STR);
964                                 break;
965
966                         case 2:
967                                 retval = vconf_unset(VCONFKEY_CISSAPPL_USER_CREATE_MSG3_STR);
968                                 break;
969
970                         case 3:
971                                 retval = vconf_unset(VCONFKEY_CISSAPPL_USER_CREATE_MSG4_STR);
972                                 break;
973
974                         case 4:
975                                 retval = vconf_unset(VCONFKEY_CISSAPPL_USER_CREATE_MSG5_STR);
976                                 break;
977
978                         case 5:
979                                 retval = vconf_unset(VCONFKEY_CISSAPPL_USER_CREATE_MSG6_STR);
980                                 break;
981                         }
982                 }
983
984                 //Check if all messages are deleted
985                 if(oldMsgCount == deleteKeyList.GetCount())
986                 {
987                         vconf_set_int(VCONFKEY_CISSAPPL_REJECT_CALL_MSG_INT, 0);
988                         delete pRejectMsgMap;
989                         return E_SUCCESS;
990                 }
991
992                 //Second, delete messages to be deleted from fetched old Message map
993                 for (int index = 0; index < deleteKeyList.GetCount(); index++)
994                 {
995                         int keyForMsg = -1;
996                         if (deleteKeyList.GetAt(index, keyForMsg) == E_SUCCESS)
997                         {
998                                 pRejectMsgMap->Remove(keyForMsg);
999                         }
1000                 }
1001
1002                 //Third, reset remaining message in vconf with ordered keys
1003                 IListT<String> *pRejectMsgList = pRejectMsgMap->GetValuesN();
1004                 newMsgCount = pRejectMsgList->GetCount();
1005                 for (int index = 0; index < newMsgCount; index++)
1006                 {
1007                         String msg;
1008                         pRejectMsgList->GetAt(index,msg);
1009                         //convert to char*
1010                         const wchar_t* pMsgPtr = msg.GetPointer();
1011                         int len = msg.GetLength()*sizeof(wchar_t);
1012                         char* pMessageToBeSet = new (std::nothrow) char[len + 1];
1013                         memset(pMessageToBeSet, 0, (len + 1) * sizeof(char));
1014                         wcstombs(pMessageToBeSet, pMsgPtr, len);
1015                         switch (index)
1016                         {
1017                         case 0:
1018                         {
1019                                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG1_STR, pMessageToBeSet);
1020                         }
1021                         break;
1022
1023                         case 1:
1024                         {
1025                                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG2_STR, pMessageToBeSet);
1026                         }
1027                         break;
1028
1029                         case 2:
1030                         {
1031                                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG3_STR, pMessageToBeSet);
1032                         }
1033                         break;
1034
1035                         case 3:
1036                         {
1037                                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG4_STR, pMessageToBeSet);
1038                         }
1039                         break;
1040
1041                         case 4:
1042                         {
1043                                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG5_STR, pMessageToBeSet);
1044                         }
1045                         break;
1046
1047                         case 5:
1048                         {
1049                                 retval = vconf_set_str(VCONFKEY_CISSAPPL_USER_CREATE_MSG6_STR, pMessageToBeSet);
1050                         }
1051                         break;
1052
1053                         default:
1054                         break;
1055                         }
1056                         delete []pMessageToBeSet;
1057                         pMessageToBeSet = null;
1058                 }
1059                 delete pRejectMsgMap;
1060                 pRejectMsgMap = null;
1061         }
1062
1063         //todo: retVal from vconf_unset is always -1. to be checked
1064 //      if (retval == 0)
1065         {
1066                 //Update message count in vconf
1067                 vconf_set_int(VCONFKEY_CISSAPPL_REJECT_CALL_MSG_INT, newMsgCount);
1068                 r = E_SUCCESS;
1069         }
1070
1071         return r;
1072 }
1073
1074 IList*
1075 SettingsManager::GetPrefixDialListN(void)
1076 {
1077         int phoneNumberCount;
1078         char* pPhoneNumber = null;
1079         ArrayList* pPhoneNumberList = null;
1080
1081         int retval = vconf_get_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_INT, &phoneNumberCount);
1082         if (retval == 0)
1083         {
1084                 pPhoneNumberList = new (std::nothrow) ArrayList();
1085                 for (int index = 0; index < phoneNumberCount; index++)
1086                 {
1087                         String* phoneNumberStr = new (std::nothrow) String();
1088                         switch (index)
1089                         {
1090                         case 0:
1091                         {
1092                                 pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR);
1093                         }
1094                         break;
1095
1096                         case 1:
1097                         {
1098                                 pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR);
1099                         }
1100                         break;
1101
1102                         case 2:
1103                         {
1104                                 pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR);
1105                         }
1106                         break;
1107
1108                         case 3:
1109                         {
1110                                 pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR);
1111                         }
1112                         break;
1113
1114                         case 4:
1115                         {
1116                                 pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR);
1117                         }
1118                         break;
1119
1120                         default:
1121                         {
1122                                 delete pPhoneNumberList;
1123                                 pPhoneNumberList = null;
1124                                 return null;
1125                         }
1126                         break;
1127                         }
1128                         phoneNumberStr->Append(pPhoneNumber);
1129                         pPhoneNumberList->Add(*phoneNumberStr);
1130                 }
1131         }
1132         else
1133         {
1134                 return null;
1135         }
1136         return pPhoneNumberList;
1137 }
1138
1139 result
1140 SettingsManager::SetPrefixDialNumber(int phoneNumberIndex, const String& phoneNumber)
1141 {
1142         result r = E_FAILURE;
1143         int phoneNumberCount = 0;
1144
1145         int retval = -1;
1146         const wchar_t* pRejectMessage = phoneNumber.GetPointer();
1147         int len = phoneNumber.GetLength();
1148         char* pTmpPhonePtr = new (std::nothrow) char[len + 1];
1149         memset(pTmpPhonePtr, 0, (len + 1) * sizeof(char));
1150         wcstombs(pTmpPhonePtr, pRejectMessage, len);
1151         char* pNumberToBeSet = new (std::nothrow) char[len + 1];
1152         memset(pNumberToBeSet, 0, (len + 1) * sizeof(char));
1153         strncpy(pNumberToBeSet, pTmpPhonePtr, len);
1154         delete []pTmpPhonePtr;
1155         pTmpPhonePtr = null;
1156         vconf_get_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_INT, &phoneNumberCount);
1157         switch (phoneNumberIndex)
1158         {
1159         case 0:
1160         {
1161                 retval = vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR, pNumberToBeSet);
1162         }
1163         break;
1164
1165         case 1:
1166         {
1167                 retval = vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR, pNumberToBeSet);
1168         }
1169         break;
1170
1171         case 2:
1172         {
1173                 retval = vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR, pNumberToBeSet);
1174         }
1175         break;
1176
1177         case 3:
1178         {
1179                 retval = vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR, pNumberToBeSet);
1180         }
1181         break;
1182
1183         case 4:
1184         {
1185                 retval = vconf_set_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR, pNumberToBeSet);
1186         }
1187         break;
1188
1189         default:
1190         {
1191                 delete []pNumberToBeSet;
1192                 pNumberToBeSet = null;
1193                 return r;
1194         }
1195         break;
1196         }
1197
1198         delete []pNumberToBeSet;
1199         pNumberToBeSet = null;
1200
1201         if (retval == 0)
1202         {
1203                 if (phoneNumberCount < 5)
1204                 {
1205                         phoneNumberCount++;
1206                 }
1207                 vconf_set_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_INT, phoneNumberCount);
1208                 //todo: change to adding single area code if its prefix number list is supported
1209
1210                 r = E_SUCCESS;
1211         }
1212
1213         return r;
1214 }
1215
1216 result
1217 SettingsManager::GetPrefixDialNumberAtIndex(int phoneNumberIndex, String& phoneNumber)
1218 {
1219         result r = E_FAILURE;
1220
1221         int phoneNumberCount = 0;
1222         vconf_get_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_INT, &phoneNumberCount);
1223
1224         //check valid index
1225         if(phoneNumberCount > 0 && phoneNumberIndex < phoneNumberCount)
1226         {
1227                 char* pPhoneNumber = null;
1228                 switch (phoneNumberIndex)
1229                 {
1230                 case 0:
1231                 {
1232                         pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR);
1233                 }
1234                 break;
1235
1236                 case 1:
1237                 {
1238                         pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR);
1239                 }
1240                 break;
1241
1242                 case 2:
1243                 {
1244                         pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR);
1245                 }
1246                 break;
1247
1248                 case 3:
1249                 {
1250                         pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR);
1251                 }
1252                 break;
1253
1254                 case 4:
1255                 {
1256                         pPhoneNumber = vconf_get_str(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR);
1257                 }
1258                 break;
1259
1260                 default:
1261                 break;
1262                 }
1263
1264                 if(pPhoneNumber != null)
1265                 {
1266                         r = phoneNumber.Append(pPhoneNumber);
1267                 }
1268         }
1269         return r;
1270 }
1271
1272 result
1273 SettingsManager::RemovePrefixDialNumber(int phoneNumberIndex)
1274 {
1275         result r = E_FAILURE;
1276         int phoneNumberCount = 0;
1277
1278         int retval = -1;
1279         vconf_get_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_INT, &phoneNumberCount);
1280         switch (phoneNumberIndex)
1281         {
1282         case 0:
1283         {
1284                 retval = vconf_unset(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM1_STR);
1285         }
1286         break;
1287
1288         case 1:
1289         {
1290                 retval = vconf_unset(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM2_STR);
1291         }
1292         break;
1293
1294         case 2:
1295         {
1296                 retval = vconf_unset(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM3_STR);
1297         }
1298         break;
1299
1300         case 3:
1301         {
1302                 retval = vconf_unset(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM4_STR);
1303         }
1304         break;
1305
1306         case 4:
1307         {
1308                 retval = vconf_unset(VCONFKEY_CISSAPPL_PREFIX_DIAL_NUM5_STR);
1309         }
1310         break;
1311
1312         default:
1313         {
1314                 return r;
1315         }
1316         break;
1317         }
1318
1319         //todo: retVal from vconf_unset is always -1. to be checked
1320 //      if (retval == 0)
1321         {
1322                 if (phoneNumberCount > 0)
1323                 {
1324                         phoneNumberCount--;
1325                 }
1326                 vconf_set_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_INT, phoneNumberCount);
1327                 r = E_SUCCESS;
1328         }
1329
1330         return r;
1331 }
1332
1333 result
1334 SettingsManager::SetPrefixDialingStatus(bool enablePrefixDialing)
1335 {
1336         result r = E_FAILURE;
1337         int retVal = vconf_set_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, enablePrefixDialing);
1338         if (retVal == 0)
1339         {
1340                 r = E_SUCCESS;
1341         }
1342         return r;
1343 }
1344
1345 result
1346 SettingsManager::SetActivePrefixDialingValue(int prefixDialIndex)
1347 {
1348         result r = E_FAILURE;
1349         int retVal = vconf_set_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_VALUE_INT, prefixDialIndex);
1350         if (retVal == 0)
1351         {
1352                 r = E_SUCCESS;
1353         }
1354         return r;
1355 }
1356
1357 result
1358 SettingsManager::GetActivePrefixDialingValue(int& prefixDialIndex)
1359 {
1360         result r = E_FAILURE;
1361         int indexPos = -1;
1362         int retVal = vconf_get_int(VCONFKEY_CISSAPPL_PREFIX_DIAL_VALUE_INT, &indexPos);
1363         if (retVal == 0)
1364         {
1365                 prefixDialIndex = indexPos;
1366                 r = E_SUCCESS;
1367         }
1368         return r;
1369 }
1370
1371 bool
1372 SettingsManager::GetPrefixDialingStatus(void)
1373 {
1374         int isPrefixDialingEnabled = -1;
1375
1376         vconf_get_bool(VCONFKEY_CISSAPPL_PREFIX_DIAL_BOOL, &isPrefixDialingEnabled);
1377
1378         bool retVal = isPrefixDialingEnabled;
1379         return retVal;
1380 }
1381
1382 result
1383 SettingsManager::SetVideoCallImagePath(const String& imagePath)
1384 {
1385         result r = E_FAILURE;
1386         const wchar_t* pRejectMessage = imagePath.GetPointer();
1387         int len = imagePath.GetLength();
1388         char* pTmpPath = new (std::nothrow) char[len + 1];
1389         memset(pTmpPath, 0, (len + 1) * sizeof(char));
1390         wcstombs(pTmpPath, pRejectMessage, len);
1391         char* pPathToBeSet = new (std::nothrow) char[len + 1];
1392         memset(pPathToBeSet, 0, (len + 1) * sizeof(char));
1393         strncpy(pPathToBeSet, pTmpPath, len);
1394         int retVal = vconf_set_str(VCONFKEY_CISSAPPL_VIDEO_IMAGE_PATH_STR, pPathToBeSet);
1395         if (retVal == 0)
1396         {
1397                 r = E_SUCCESS;
1398         }
1399         delete []pTmpPath;
1400         pTmpPath = null;
1401         delete []pPathToBeSet;
1402         pPathToBeSet = null;
1403         return r;
1404 }
1405
1406 result
1407 SettingsManager::GetVideoCallImagePath(String& imagePath)
1408 {
1409         result r = E_FAILURE;
1410         char* pVideoImagePath = null;
1411         pVideoImagePath = vconf_get_str(VCONFKEY_CISSAPPL_VIDEO_IMAGE_PATH_STR);
1412         if (pVideoImagePath != null)
1413         {
1414                 imagePath.Clear();
1415                 imagePath.Append(pVideoImagePath);
1416                 r = E_SUCCESS;
1417         }
1418         return r;
1419 }
1420
1421 result
1422 SettingsManager::SetCallLineIdentity(CallLineIdentity identity)
1423 {
1424         result r = E_FAILURE;
1425         int retVal = vconf_set_int(VCONFKEY_CISSAPPL_SHOW_MY_NUMBER_INT, identity);
1426         if (retVal == 0)
1427         {
1428                 r = E_SUCCESS;
1429         }
1430         return r;
1431 }
1432
1433 result
1434 SettingsManager::GetCallLineIdentity(CallLineIdentity& identity)
1435 {
1436         result r = E_FAILURE;
1437         int lineIdentity = -1;
1438         int retVal = vconf_get_int(VCONFKEY_CISSAPPL_SHOW_MY_NUMBER_INT, &lineIdentity);
1439         if (retVal == 0)
1440         {
1441                 identity = (CallLineIdentity) lineIdentity;
1442                 r = E_SUCCESS;
1443         }
1444         return r;
1445 }
1446
1447 result
1448 SettingsManager::AddToCallRejectList(const String& phoneNumber, CallRejectMatchCondition rejectCondition)
1449 {
1450         //construct CallRejectInfo.
1451         CallRejectInfo rejInfo;
1452         rejInfo.phoneNumber = phoneNumber;
1453         rejInfo.rejectCondition = rejectCondition;
1454         rejInfo.isActivated = false;
1455
1456         //Fetch call reject list
1457         IListT<CallRejectInfo>* pRejNumbersList = GetCallRejectList();
1458         //Check if this is not already present in database.
1459         bool isDuplicate = false;
1460         if (pRejNumbersList != null)
1461         {
1462                 IEnumeratorT<CallRejectInfo>* pRejectEnum = pRejNumbersList->GetEnumeratorN();
1463                 if (pRejectEnum != null)
1464                 {
1465                         while (pRejectEnum->MoveNext() == E_SUCCESS)
1466                         {
1467                                 CallRejectInfo fetchedInfo;
1468                                 if (( pRejectEnum->GetCurrent(fetchedInfo) == E_SUCCESS) && (fetchedInfo == rejInfo))
1469                                 {
1470                                         isDuplicate = true;
1471                                 }
1472                         }
1473                         delete pRejectEnum;
1474                 }
1475                 delete pRejNumbersList;
1476         }
1477
1478         result r = E_OBJ_ALREADY_EXIST;
1479         if (isDuplicate == false)
1480         {
1481                 r = __pCallSettingDataService->AddCallRejectInfoToDatabase(&rejInfo);
1482         }
1483         return r;
1484 }
1485
1486 IListT<CallRejectInfo>*
1487 SettingsManager::GetCallRejectList(void)
1488 {
1489         int rejectCount = 0;
1490         __pCallSettingDataService->GetCallRejectCount(rejectCount);
1491
1492         if (rejectCount > 0)
1493         {
1494                 ArrayListT<CallRejectInfo>* pCallRejectList = new (std::nothrow) ArrayListT<CallRejectInfo>();
1495                 pCallRejectList->Construct(rejectCount);
1496                 __pCallSettingDataService->GetAllCallRejectInfoFromDatabaseN(*pCallRejectList);
1497                 return pCallRejectList;
1498         }
1499         return null;
1500 }
1501
1502 result
1503 SettingsManager::UpdateCallRejectRow(int rowId, const String& phoneNumber, bool activate, CallRejectMatchCondition rejectCondition)
1504 {
1505         result r = E_FAILURE;
1506         CallRejectInfo* rejInfo = new (std::nothrow) CallRejectInfo();
1507         rejInfo->rowId = rowId;
1508         rejInfo->phoneNumber.Append(phoneNumber);
1509         rejInfo->rejectCondition = rejectCondition;
1510         rejInfo->isActivated = activate;
1511         r = __pCallSettingDataService->UpdateCallRejectInfoDatabase(rowId,rejInfo);
1512         delete rejInfo;
1513         return r;
1514 }
1515
1516 result
1517 SettingsManager::RemoveCallRejectRow(int rowId)
1518 {
1519         return __pCallSettingDataService->DeleteCallRejectInfoFromDatabase(rowId);
1520 }
1521
1522 result
1523 SettingsManager::SetUnknownRejectStatus(bool activate)
1524 {
1525         result r = E_FAILURE;
1526         int retVal = vconf_set_bool(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, activate);
1527         if (retVal == 0)
1528         {
1529                 r = E_SUCCESS;
1530         }
1531         return r;
1532 }
1533
1534 bool
1535 SettingsManager::IsCallToBeRejected(String& phoneNumber)
1536 {
1537         return __pCallSettingDataService->IsCallToBeRejected(phoneNumber);
1538 }
1539
1540 bool
1541 SettingsManager::GetUnknownRejectStatus(void)
1542 {
1543         int unknownRejectStatus = -1;
1544
1545         vconf_get_bool(VCONFKEY_CISSAPPL_AUTO_REJECT_UNKNOWN_BOOL, &unknownRejectStatus);
1546
1547         bool retVal = unknownRejectStatus;
1548         return retVal;
1549 }
1550
1551 result
1552 SettingsManager::SetCallAlertStatus(CallAlertStatus callAlertStatus)
1553 {
1554         result r = E_FAILURE;
1555         int retVal = vconf_set_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, callAlertStatus);
1556         if (retVal == 0)
1557         {
1558                 r = E_SUCCESS;
1559         }
1560         return r;
1561 }
1562
1563 result
1564 SettingsManager::GetCallAlertStatus(CallAlertStatus& callAlertStatus)
1565 {
1566         result r = E_FAILURE;
1567         int alertStatus = -1;
1568         int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
1569         if (retVal == 0)
1570         {
1571                 callAlertStatus = (CallAlertStatus) alertStatus;
1572                 r = E_SUCCESS;
1573         }
1574         return r;
1575 }
1576
1577 result
1578 SettingsManager::SetCallConnectToneStatus(bool activate)
1579 {
1580         result r = E_FAILURE;
1581         int retVal = vconf_set_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, activate);
1582         if (retVal == 0)
1583         {
1584                 r = E_SUCCESS;
1585         }
1586         return r;
1587 }
1588
1589 bool
1590 SettingsManager::GetCallConnectToneStatus(void)
1591 {
1592         int unknownRejectStatus = -1;
1593
1594         vconf_get_bool(VCONFKEY_CISSAPPL_CALL_CONNECT_TONE_BOOL, &unknownRejectStatus);
1595
1596         bool retVal = unknownRejectStatus;
1597         return retVal;
1598 }
1599
1600 result
1601 SettingsManager::SetMinuteMinderToneStatus(bool activate)
1602 {
1603         result r = E_FAILURE;
1604         int retVal = vconf_set_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, activate);
1605         if (retVal == 0)
1606         {
1607                 r = E_SUCCESS;
1608         }
1609         return r;
1610 }
1611
1612 bool
1613 SettingsManager::GetMinuteMinderToneStatus(void)
1614 {
1615         int unknownRejectStatus = -1;
1616
1617         vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
1618
1619         bool retVal = unknownRejectStatus;
1620         return retVal;
1621 }
1622
1623 result
1624 SettingsManager::SetCallEndToneStatus(bool activate)
1625 {
1626         result r = E_FAILURE;
1627         int retVal = vconf_set_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, activate);
1628         if (retVal == 0)
1629         {
1630                 r = E_SUCCESS;
1631         }
1632         return r;
1633 }
1634
1635 bool
1636 SettingsManager::GetCallEndToneStatus(void)
1637 {
1638         int unknownRejectStatus = -1;
1639
1640         vconf_get_bool(VCONFKEY_CISSAPPL_CALL_END_TONE_BOOL, &unknownRejectStatus);
1641
1642         bool retVal = unknownRejectStatus;
1643         return retVal;
1644 }
1645
1646 result
1647 SettingsManager::SetSpeedDialMapping(const String& contactId, int numberToMap)
1648 {
1649         result r = E_FAILURE;
1650         SpeedDialInfo mappingInfo;;
1651         mappingInfo.keyMapping = numberToMap;
1652         mappingInfo.contactId = contactId;
1653         r = __pCallSettingDataService->AddSpeedDialInfoToDatabase(&mappingInfo);
1654         return r;
1655 }
1656
1657 IMapT<int,SpeedDialInfo>*
1658 SettingsManager::GetSpeedDialMappingN(void)
1659 {
1660         return (__pCallSettingDataService->GetAllSpeedDialInfoMapFromDatabaseN());
1661 }
1662
1663 result
1664 SettingsManager::RemoveSpeedDialMapping(int rowId)
1665 {
1666         return __pCallSettingDataService->DeleteSpeedDialInfoFromDatabase(rowId);
1667 }
1668
1669 result
1670 SettingsManager::UpdateSpeedDialMapping(int rowId, const String& contactId, int numberToMap)
1671 {
1672         result r = E_FAILURE;
1673         SpeedDialInfo* mappingInfo = new (std::nothrow) SpeedDialInfo();
1674         mappingInfo->rowId = rowId;
1675         mappingInfo->contactId.Append(contactId);
1676         mappingInfo->keyMapping = numberToMap;
1677         r = __pCallSettingDataService->UpdateSpeedDialInfoDatabase(rowId,mappingInfo);
1678         delete mappingInfo;
1679         return r;
1680 }
1681
1682 String*
1683 SettingsManager::GetMappedSpeedDialNumberN(int aIndex)
1684 {
1685         String* contactNumber = null;
1686
1687         //Fetch contactId for mapped speed dial
1688         String* contactId = __pCallSettingDataService->GetSpeedDialContactN(aIndex);
1689         if(contactId != null && contactId->IsEmpty() == false)
1690         {
1691                 RecordId recordId = INVALID_RECORD_ID;
1692                 Integer::Parse(*contactId, recordId);
1693                 //check if recordId is correct
1694                 if (recordId != Tizen::Social::INVALID_RECORD_ID)
1695                 {
1696                         AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
1697                         Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
1698                         if (pAddressbook != null)
1699                         {
1700                                 Contact* pMappedContact = pAddressbook->GetContactN(recordId);
1701                                 if (pMappedContact != null)
1702                                 {
1703                                         IList* pPhoneNumberList = pMappedContact->GetValuesN(CONTACT_MPROPERTY_ID_PHONE_NUMBERS);
1704                                         if (pPhoneNumberList != null)
1705                                         {
1706                                                 PhoneNumber* pPhoneNumber = static_cast<PhoneNumber*>(pPhoneNumberList->GetAt(0));
1707                                                 if(pPhoneNumber != null)
1708                                                 {
1709                                                         contactNumber = new (std::nothrow) String(pPhoneNumber->GetPhoneNumber());
1710                                                 }
1711                                                 pPhoneNumberList->RemoveAll(true);
1712                                                 delete pPhoneNumberList;
1713                                         }
1714                                         delete pMappedContact;
1715                                 }
1716                                 delete pAddressbook;
1717                         }
1718                 }
1719         }
1720         delete contactId;
1721         contactId = null;
1722         return contactNumber;
1723 }
1724
1725 Contact*
1726 SettingsManager::FetchContactDetailsN(const String& contactId)
1727 {
1728         Contact* pFetchedContact = null;
1729
1730         RecordId recordId = INVALID_RECORD_ID;
1731         Integer::Parse(contactId, recordId);
1732         //check if recordId is correct
1733         if (recordId != Tizen::Social::INVALID_RECORD_ID)
1734         {
1735                 AddressbookManager* pAddressbookManager = AddressbookManager::GetInstance();
1736                 Addressbook* pAddressbook = pAddressbookManager->GetAddressbookN(DEFAULT_ADDRESSBOOK_ID);
1737                 if (pAddressbook != null)
1738                 {
1739                         pFetchedContact = pAddressbook->GetContactN(recordId);
1740                         delete pAddressbook;
1741                 }
1742         }
1743         return pFetchedContact;
1744 }
1745
1746 result
1747 SettingsManager::SetCallState(CallState callState)
1748 {
1749         AppLogDebug("Enter %d",callState);
1750         result r = E_FAILURE;
1751         int retVal = vconf_set_int(VCONFKEY_CALL_STATE, callState);
1752         if (retVal == 0)
1753         {
1754                 r = E_SUCCESS;
1755         }
1756         return r;
1757 }
1758