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