cellular/telephonysettings/xqbindings/psetwrapper/src/psetcalldivertingwrapper.cpp
changeset 12 ae8abd0db65c
child 13 e32024264ebb
equal deleted inserted replaced
0:ff3b6d0fd310 12:ae8abd0db65c
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  *
       
    16  */
       
    17 
       
    18 #include <QtGlobal>
       
    19 #include <rsssettings.h>
       
    20 #include <PsetContainer.h>
       
    21 #include <PsetCallDiverting.h>
       
    22 #include <mmlist.h>
       
    23 #include <cphcltemergencycall.h>
       
    24 #include <badesca.h>
       
    25 #include <cvoicemailbox.h>
       
    26 #include <cvoicemailboxentry.h>
       
    27 #include "psetcalldivertingwrapper.h"
       
    28 #include "psetcalldivertingwrapper_p.h"
       
    29 #include "logging.h"
       
    30 
       
    31 //Constant
       
    32 _LIT(KCFInvalidChars,"*#pw");
       
    33 _LIT(KCFPlusSign,"+");
       
    34 
       
    35 /*!
       
    36   PSetCallDivertingWrapper::PSetCallDivertingWrapper
       
    37  */
       
    38 PSetCallDivertingWrapper::PSetCallDivertingWrapper(
       
    39         CPsetContainer &psetContainer, QObject *parent) :
       
    40     QObject(parent), m_psetCallDiverting(NULL), m_emergencyCall(NULL), 
       
    41     m_DefaultNumberListCDes(NULL), m_Priv(NULL)
       
    42 {
       
    43     DPRINT << ": IN";
       
    44     
       
    45     m_Priv = new PSetCallDivertingWrapperPrivate(*this);
       
    46     QScopedPointer<PSetCallDivertingWrapperPrivate> privateImplGuard(m_Priv);
       
    47     
       
    48     QT_TRAP_THROWING(
       
    49         m_psetCallDiverting = psetContainer.CreateCFObjectL( *m_Priv ));
       
    50     m_psetCallDiverting->SetRequestObserver(m_Priv);
       
    51 	QScopedPointer<CPsetCallDiverting> pSetCallDivertingGuard(m_psetCallDiverting);
       
    52     
       
    53     QT_TRAP_THROWING(m_emergencyCall = CPhCltEmergencyCall::NewL( m_Priv ));
       
    54     QScopedPointer<CPhCltEmergencyCall> emergencyCallGuard(m_emergencyCall);
       
    55     
       
    56     privateImplGuard.take();
       
    57     pSetCallDivertingGuard.take();
       
    58     emergencyCallGuard.take();
       
    59     
       
    60     DPRINT << ": OUT";
       
    61 }
       
    62 
       
    63 /*!
       
    64   PSetCallDivertingWrapper::~PSetCallDivertingWrapper
       
    65  */
       
    66 PSetCallDivertingWrapper::~PSetCallDivertingWrapper()
       
    67 {
       
    68     DPRINT << ": IN";
       
    69     
       
    70     delete m_psetCallDiverting;
       
    71     delete m_emergencyCall;
       
    72     
       
    73     if (m_DefaultNumberListCDes) {
       
    74         m_DefaultNumberListCDes->Reset();
       
    75         delete m_DefaultNumberListCDes;
       
    76     }
       
    77     
       
    78     delete m_Priv;
       
    79     
       
    80     DPRINT << ": OUT";
       
    81 }
       
    82 
       
    83 // --------  Wrapper interface  --------- // 
       
    84 /*!
       
    85   PSetCallDivertingWrapper::setCallDiverting
       
    86  */
       
    87 int PSetCallDivertingWrapper::setCallDiverting(
       
    88         PSCallDivertingCommand& aSetting, int aBasicServiceGroup)
       
    89 {
       
    90     DPRINT << ": IN";
       
    91 
       
    92     TCallDivertSetting param;
       
    93     param.iCondition = m_Priv->convert(aSetting.iCondition);
       
    94     param.iSetting = m_Priv->convert(aSetting.iSetting);
       
    95     param.iStatus = m_Priv->convert(aSetting.iStatus);
       
    96     param.iServiceGroup = m_Priv->convert(aSetting.iServiceGroup);
       
    97     param.iNumber = TPtrC16(aSetting.iNumber.utf16());
       
    98     param.iNoReplyTimer = aSetting.iNoReplyTimer;
       
    99     
       
   100     int result = validateDivertNumber(param.iNumber);
       
   101     if (0 == result) {
       
   102         QT_TRAP_THROWING(
       
   103             m_psetCallDiverting->SetDivertingL(
       
   104                 param,
       
   105                 static_cast<TBasicServiceGroups>(aBasicServiceGroup)));
       
   106     } 
       
   107     
       
   108     DPRINT << ": OUT";
       
   109     return result;
       
   110 }
       
   111 
       
   112 /*!
       
   113   PSetCallDivertingWrapper::getCallDivertingStatus
       
   114  */
       
   115 void PSetCallDivertingWrapper::getCallDivertingStatus(
       
   116         const PsServiceGroup aServiceGroup, 
       
   117         const PsCallDivertingCondition aCondition,
       
   118         int aBsc)
       
   119 {
       
   120     DPRINT << ": IN";
       
   121     DPRINT << "aServiceGroup : " << aServiceGroup;
       
   122     DPRINT << "aCondition : " << aCondition;
       
   123     
       
   124     QT_TRAP_THROWING(
       
   125         m_psetCallDiverting->GetDivertingStatusL(
       
   126             m_Priv->convert(aServiceGroup),
       
   127             m_Priv->convert(aCondition),
       
   128             (TBasicServiceGroups)aBsc));
       
   129 
       
   130     DPRINT << ": OUT";
       
   131 }
       
   132 
       
   133 /*!
       
   134   PSetCallDivertingWrapper::cancelProcess
       
   135  */
       
   136 void PSetCallDivertingWrapper::cancelProcess()
       
   137 {
       
   138     DPRINT << ": IN";
       
   139     
       
   140     m_psetCallDiverting->CancelCurrentRequest();
       
   141     
       
   142     DPRINT << ": OUT";
       
   143 }
       
   144 
       
   145 /*!
       
   146   PSetCallDivertingWrapper::getDefaultNumbers
       
   147  */
       
   148 void PSetCallDivertingWrapper::getDefaultNumbers(QStringList &aDefNumbers)
       
   149 {
       
   150     // QStringList?, max 3 numbers to retrieve.
       
   151 
       
   152     DPRINT << ": IN";
       
   153 
       
   154     while (!m_DefaultnumberListQSList.empty()) {
       
   155         m_DefaultnumberListQSList.removeFirst();
       
   156     }
       
   157     m_DefaultNumberListCDes = new CDesC16ArrayFlat(3);
       
   158     QT_TRAP_THROWING(
       
   159         m_psetCallDiverting->GetDefaultNumbersL(*m_DefaultNumberListCDes));
       
   160     int count = m_DefaultNumberListCDes->Count();
       
   161     for (int i = 0; i < count; i++) {
       
   162         m_DefaultnumberListQSList.append(QString::fromUtf16(
       
   163             m_DefaultNumberListCDes->MdcaPoint(i).Ptr(),
       
   164             m_DefaultNumberListCDes->MdcaPoint(i).Length()));
       
   165     }
       
   166     aDefNumbers = m_DefaultnumberListQSList;
       
   167     m_DefaultNumberListCDes->Reset();
       
   168     delete m_DefaultNumberListCDes;
       
   169     m_DefaultNumberListCDes = NULL;
       
   170 
       
   171     DPRINT << ": OUT";
       
   172 }
       
   173 
       
   174 /*!
       
   175   PSetCallDivertingWrapper::setNewDefaultNumber
       
   176  */
       
   177 void PSetCallDivertingWrapper::setNewDefaultNumber(QString aNumber)
       
   178 {
       
   179     DPRINT << ": IN";
       
   180     
       
   181     TBuf<KPsetPhoneNumberLength> bufNumber(aNumber.utf16());
       
   182     TInt found(KErrNotFound);
       
   183     TInt loc(KErrNotFound);
       
   184     m_DefaultNumberListCDes = new CDesC16ArrayFlat(3);
       
   185     QT_TRAP_THROWING(
       
   186         m_psetCallDiverting->GetDefaultNumbersL(*m_DefaultNumberListCDes));
       
   187     found = m_DefaultNumberListCDes->Find(bufNumber, loc);
       
   188     m_DefaultNumberListCDes->Reset();
       
   189     delete m_DefaultNumberListCDes;
       
   190     m_DefaultNumberListCDes = NULL;
       
   191     if (found != KErrNone) { //number is not part of current def.numbers
       
   192         QT_TRAP_THROWING(
       
   193             m_psetCallDiverting->SetNewDefaultNumberL(bufNumber));
       
   194     } else {
       
   195         QT_TRAP_THROWING(
       
   196             m_psetCallDiverting->SwapDefaultNumberL(loc+1));
       
   197     }
       
   198     
       
   199     DPRINT << ": OUT";
       
   200 }
       
   201 
       
   202 /*!
       
   203   PSetCallDivertingWrapper::getVoiceMailBoxNumber
       
   204  */
       
   205 void PSetCallDivertingWrapper::getVoiceMailBoxNumber(QString &aVmbxNumber)
       
   206 {
       
   207     DPRINT << ": IN";
       
   208 
       
   209     CVoiceMailboxEntry* psetVoiceMailboxEntry = NULL;
       
   210     CVoiceMailbox* psetVoiceMailBoxScoped = NULL;
       
   211     QT_TRAP_THROWING(psetVoiceMailBoxScoped = CVoiceMailbox::NewL());
       
   212     QScopedPointer<CVoiceMailbox> psetVoiceMailBox(psetVoiceMailBoxScoped);
       
   213 
       
   214     TVoiceMailboxParams psetVoiceMailboxParams;
       
   215     // Selected mailbox type is voice
       
   216     psetVoiceMailboxParams.iType = EVmbxVoice;
       
   217     psetVoiceMailboxEntry = 0;
       
   218     TInt error = psetVoiceMailBox->GetStoredEntry( psetVoiceMailboxParams, psetVoiceMailboxEntry );
       
   219     if ( KErrNone == error ) {
       
   220         // Entry ok, check the number
       
   221         TPtrC ptrNumber( KNullDesC );
       
   222         if ( KErrNone == psetVoiceMailboxEntry->GetVmbxNumber( ptrNumber )) {
       
   223             // number ok
       
   224             aVmbxNumber = QString::fromUtf16(ptrNumber.Ptr(),
       
   225                     ptrNumber.Length());
       
   226             }
       
   227         }
       
   228       else if ( KErrNotFound == error ) {
       
   229         // No number defined, query new entry from user
       
   230         error = psetVoiceMailBox->QueryNewEntry( psetVoiceMailboxParams, psetVoiceMailboxEntry );
       
   231 
       
   232         if ( KErrNone == error ) {
       
   233             // Save new entry and get the number.
       
   234             error = psetVoiceMailBox->SaveEntry( *psetVoiceMailboxEntry );
       
   235             TPtrC ptrNumber( KNullDesC );
       
   236             if ( KErrNone == psetVoiceMailboxEntry->GetVmbxNumber( ptrNumber )) {
       
   237                 // New number ok.
       
   238                 aVmbxNumber = QString::fromUtf16(ptrNumber.Ptr(),
       
   239                         ptrNumber.Length());
       
   240                 }
       
   241             } else {
       
   242                 // New number not given.
       
   243                 DPRINT << "New number error: " << error;
       
   244             }
       
   245         }
       
   246     else {
       
   247         // illegal argument 
       
   248         DPRINT << "error: " << error;
       
   249         }
       
   250 
       
   251     delete psetVoiceMailboxEntry; // Entry ownership was transferred
       
   252     psetVoiceMailboxEntry = NULL;
       
   253 
       
   254     DPRINT << "aVmbxNumber: " << aVmbxNumber;
       
   255     DPRINT << ": OUT";
       
   256 }
       
   257 
       
   258 /*!
       
   259   PSetCallDivertingWrapper::validateDivertNumber
       
   260  */
       
   261 int PSetCallDivertingWrapper::validateDivertNumber(
       
   262         const TDesC16& aDivertTo) const
       
   263 {
       
   264     DPRINT << ": IN ";
       
   265     
       
   266     int result = 0;
       
   267     
       
   268     QString diverto = QString::fromUtf16(aDivertTo.Ptr(),aDivertTo.Length());
       
   269     DPRINT << "aDivertTo: " << diverto;
       
   270     TInt noOfInvalidChars = KCFInvalidChars().Length();
       
   271     TBool isEmergency(EFalse);
       
   272     TTelNumber number;
       
   273     TInt error = m_emergencyCall->IsEmergencyPhoneNumber(aDivertTo, number,
       
   274             isEmergency);
       
   275     if ((error == KErrNone) && isEmergency) {
       
   276         result = KErrGsmSSIllegalOperation;
       
   277         DPRINT << ": emergency number.";
       
   278     } else {
       
   279         // Plus is a special case, as it is accepted as first character.
       
   280         if (findPlus(aDivertTo)) {
       
   281             result = KErrGsmSSUnknownAlphabet;
       
   282         }
       
   283         for (int index = 0; index < noOfInvalidChars; index++) {
       
   284             if (aDivertTo.Find(KCFInvalidChars().Mid(index, 1)) == KErrNone) {
       
   285                 result = KErrGsmSSUnknownAlphabet;
       
   286                 DPRINT << ": Invalid divert number. ";
       
   287             }
       
   288         }
       
   289     }
       
   290 
       
   291     DPRINT << ": OUT : result " << result;
       
   292     return result;
       
   293 }
       
   294 
       
   295 /*!
       
   296   PSetCallDivertingWrapper::findPlus
       
   297   Seeks '+' from given number. If '+' is first character, it is ignored.
       
   298  */
       
   299 bool PSetCallDivertingWrapper::findPlus(const TDesC16& aDivertTo) const
       
   300 {
       
   301     DPRINT << ": IN ";
       
   302 
       
   303     bool plusFound(false);
       
   304     if (!(aDivertTo.Find(KCFPlusSign) == KErrNotFound)) {
       
   305         //first char '+', but there can additional '+'s
       
   306         //ignore first '+'
       
   307         TPtrC concat = aDivertTo.Right(aDivertTo.Length() - 1);
       
   308         if (concat.Find(KCFPlusSign) == KErrNone) {
       
   309             plusFound = true;
       
   310             DPRINT << ": Invalid divert number. ";
       
   311         }
       
   312     }
       
   313 
       
   314     DPRINT << ": OUT : plusFound " << plusFound;
       
   315     return plusFound;
       
   316 }
       
   317 
       
   318 // End of File.