vmbx/vmbxcpplugin/src/vmbxuiengine.cpp
branchRCL_3
changeset 44 987c9837762f
parent 43 7d48bed6ce0c
child 47 0a6dd2dc9970
equal deleted inserted replaced
43:7d48bed6ce0c 44:987c9837762f
     1 /*
       
     2  * Copyright (c) 2009 - 2010 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 // System includes
       
    19 #include <cvoicemailbox.h>
       
    20 #include <cvoicemailboxentry.h>
       
    21 
       
    22 // User includes
       
    23 #include "vmbxuiengine.h"
       
    24 #include "loggerutil.h"
       
    25 
       
    26 /*!
       
    27     Constructor
       
    28 */
       
    29 VmbxUiEngine::VmbxUiEngine() : mVmbxEngine(NULL),
       
    30     mCsVoiceNumber(""),mCsVideoNumber("")
       
    31 { 
       
    32     _DBGLOG("VmbxUiEngine::VmbxUiEngine >")
       
    33     QT_TRAP_THROWING(mVmbxEngine = CVoiceMailbox::NewL());
       
    34     init();
       
    35     _DBGLOG("VmbxUiEngine::VmbxUiEngine <")
       
    36 }
       
    37 
       
    38 /*!
       
    39     Destructor
       
    40 */
       
    41 VmbxUiEngine::~VmbxUiEngine()
       
    42 {
       
    43     _DBGLOG( "VmbxUiEngine::~VmbxUiEngine >")
       
    44     mVmbxEngine->NotifyVmbxNumberChangeCancel();
       
    45     delete mVmbxEngine;
       
    46     mVmbxEngine = NULL;
       
    47     _DBGLOG( "VmbxUiEngine::~VmbxUiEngine <")
       
    48 }
       
    49 
       
    50 /*!
       
    51     Initialize vmbx ui engine.
       
    52 */
       
    53 void VmbxUiEngine::init()
       
    54 {
       
    55     _DBGLOG("VmbxUiEngine::init >")
       
    56     // Init voice primary line number
       
    57     getCsVoicePrimaryNumber(mCsVoiceNumber);
       
    58     // Init video primary line nubmer
       
    59     if (isVideoSupport()) {
       
    60         getCsVideoPrimaryNumber(mCsVideoNumber);
       
    61     }
       
    62     _DBGLOG("VmbxUiEngine::init <")
       
    63 }
       
    64 
       
    65 /*!
       
    66     Getter method for primary voice number of Voice Mailbox.
       
    67 */
       
    68 void VmbxUiEngine::getCsVoiceNumber(QString &aValue)
       
    69 {
       
    70     _DBGLOG("VmbxUiEngine::getCsVoiceNumber >")
       
    71     aValue = mCsVoiceNumber;
       
    72     _DBGLOG2("VmbxUiEngine::getCsVoiceNumber < , string=", aValue)
       
    73 }
       
    74 
       
    75 /*!
       
    76     Getter method for primary video number of Voice Mailbox.
       
    77 */
       
    78 void VmbxUiEngine::getCsVideoNumber(QString &aValue)
       
    79 {
       
    80     _DBGLOG("VmbxUiEngine::getCsVideoNumber >")
       
    81     aValue = mCsVideoNumber;
       
    82     _DBGLOG2("VmbxUiEngine::getCsVideoNumber < , string=", aValue)
       
    83 }
       
    84 
       
    85 /*!
       
    86     Set number when cs voice number has been edited on UI.
       
    87     @param aValue New value.
       
    88 */
       
    89 void VmbxUiEngine::setCsVoiceNumber(const QString &aValue)
       
    90 {
       
    91     _DBGLOG2("VmbxUiEngine::setCsVoiceNumber >, value=",aValue)
       
    92     TVoiceMailboxParams vmbxParams;
       
    93     vmbxParams.iType = EVmbxVoice;
       
    94     vmbxParams.iLineType = EVmbxAlsLine1;
       
    95     vmbxParams.iServiceId = KVmbxServiceVoice;
       
    96     setNumber(vmbxParams, aValue);
       
    97     mCsVoiceNumber = aValue;
       
    98     _DBGLOG("VmbxUiEngine::setCsVoiceNumber <");
       
    99 }
       
   100 
       
   101 /*!
       
   102     Set number when cs video number has been edited on UI.
       
   103     @param aValue New value.
       
   104 */
       
   105 void VmbxUiEngine::setCsVideoNumber(const QString &aValue)
       
   106 {
       
   107     _DBGLOG2("VmbxUiEngine::setCsVideoNumber >, value=",aValue)
       
   108     TVoiceMailboxParams vmbxParams;
       
   109     vmbxParams.iType = EVmbxVideo;
       
   110     vmbxParams.iLineType = EVmbxAlsLine1;
       
   111     vmbxParams.iServiceId = KVmbxServiceVideo;
       
   112     setNumber(vmbxParams, aValue);
       
   113     mCsVideoNumber = aValue;
       
   114     _DBGLOG("VmbxUiEngine::setCsVideoNumber <");
       
   115 }
       
   116 
       
   117 /*!
       
   118     If video mailbox supported.
       
   119 */
       
   120 bool VmbxUiEngine::isVideoSupport()
       
   121 {
       
   122     _DBGLOG("VmbxUiEngine::isVideoSupport >")
       
   123     // video support
       
   124     bool isVideoSupport(false);
       
   125     TVoiceMailboxParams vmbxParams;
       
   126     vmbxParams.iType = EVmbxVideo;
       
   127     vmbxParams.iLineType = EVmbxAlsLine1;
       
   128     vmbxParams.iServiceId = KVmbxServiceVideo;
       
   129     isVideoSupport = mVmbxEngine->CheckConfiguration(vmbxParams,
       
   130         EVmbxVideoMailboxSupported);
       
   131     _DBGLOG2("VmbxUiEngine::isVideoSupport ", isVideoSupport);
       
   132     return isVideoSupport;
       
   133 }
       
   134 
       
   135 /*!
       
   136     If voice mailbox allow to write.
       
   137 */
       
   138 bool VmbxUiEngine::isVoiceWritable()
       
   139 {
       
   140     _DBGLOG("VmbxUiEngine::isVoiceWritable >")
       
   141     bool isVoiceWritable(false);
       
   142     TVoiceMailboxParams vmbxParams;
       
   143     vmbxParams.iType = EVmbxVoice;
       
   144     vmbxParams.iLineType = EVmbxAlsLine1;
       
   145     vmbxParams.iServiceId = KVmbxServiceVoice;
       
   146     isVoiceWritable = mVmbxEngine->CheckConfiguration(vmbxParams,
       
   147         EVmbxChangeNbrAllowedOnUi);
       
   148     _DBGLOG2("VmbxUiEngine::isVoiceWritable <", isVoiceWritable);
       
   149     return isVoiceWritable;
       
   150 }
       
   151 
       
   152 /*!
       
   153     If video mailbox allow to write.
       
   154 */
       
   155 bool VmbxUiEngine::isVideoWritable()
       
   156 {
       
   157     _DBGLOG( "VmbxUiEngine::isVideoWritable >")
       
   158     bool isVideoWritable(false);
       
   159     TVoiceMailboxParams vmbxParams;
       
   160     vmbxParams.iType = EVmbxVideo;
       
   161     vmbxParams.iLineType = EVmbxAlsLine1;
       
   162     vmbxParams.iServiceId = KVmbxServiceVideo;
       
   163     isVideoWritable = mVmbxEngine->CheckConfiguration(vmbxParams,
       
   164         EVmbxChangeNbrAllowedOnUi);
       
   165     _DBGLOG2("VmbxUiEngine::isVoiceWritable >", isVideoWritable);
       
   166     return isVideoWritable;
       
   167 }
       
   168 
       
   169 /*!
       
   170     queryVoiceNumber
       
   171 */
       
   172 int VmbxUiEngine::queryVoiceNumber(QString &aValue)
       
   173 {
       
   174     _DBGLOG2("VmbxUiEngine::queryVoiceNumber >, value=",aValue)
       
   175     TVoiceMailboxParams vmbxParams;
       
   176     vmbxParams.iType = EVmbxVoice;
       
   177     vmbxParams.iServiceId = KVmbxServiceVoice;
       
   178     int result = queryNumber(vmbxParams, aValue);
       
   179     _DBGLOG2("VmbxUiEngine::queryVoiceNumber <, value=", aValue)
       
   180     return result;
       
   181 }
       
   182 
       
   183 /*!
       
   184     queryVideoNumber
       
   185 */
       
   186 int VmbxUiEngine::queryVideoNumber(QString &aValue)
       
   187 {
       
   188     _DBGLOG2("VmbxUiEngine::queryVideoNumber >, value=", aValue)
       
   189     TVoiceMailboxParams vmbxParams;
       
   190     vmbxParams.iType = EVmbxVideo;
       
   191     vmbxParams.iServiceId = KVmbxServiceVideo;
       
   192     int result = queryNumber(vmbxParams, aValue);
       
   193     _DBGLOG2("VmbxUiEngine::queryVideoNumber <, value=", aValue)
       
   194     return result;
       
   195 }
       
   196 
       
   197 /*!
       
   198     Request notify when VMBX number changed
       
   199  */
       
   200 void VmbxUiEngine::notifyVmbxNumberChange(bool aNotifyOnActiveLineOnly)
       
   201 {
       
   202     _DBGLOG2("VmbxUiEngine::notifyVmbxNumberChange >, OnActiveLineOnly=", 
       
   203              aNotifyOnActiveLineOnly)
       
   204     QT_TRAP_THROWING(mVmbxEngine->NotifyVmbxNumberChangeL
       
   205                                  (*this, aNotifyOnActiveLineOnly));
       
   206     _DBGLOG2("VmbxUiEngine::notifyVmbxNumberChange <, OnActiveLineOnly=", 
       
   207              aNotifyOnActiveLineOnly)
       
   208 }
       
   209 
       
   210 /*!
       
   211     Callback from voice mailbox engine when number has been updated
       
   212     This method notifies the UI to refresh its data.
       
   213 */
       
   214 void VmbxUiEngine::HandleNotifyL(const CVoiceMailboxEntry &aVmbxEntry)
       
   215 {
       
   216     _DBGLOG( "VmbxUiEngine::HandleNotifyL >")
       
   217     TVmbxType type = aVmbxEntry.VoiceMailboxType();
       
   218     TPtrC number(KNullDesC);
       
   219     aVmbxEntry.GetVmbxNumber(number);
       
   220     if (EVmbxVoice == type) {
       
   221         mCsVoiceNumber = QString::fromUtf16(number.Ptr(), number.Length());
       
   222     } else if (EVmbxVideo == type) {
       
   223         mCsVideoNumber = QString::fromUtf16(number.Ptr(), number.Length());
       
   224     }
       
   225     emit voiceMailboxEngineEntriesUpdated(type);
       
   226     _DBGLOG( "VmbxUiEngine::HandleNotifyL <")
       
   227 }
       
   228 
       
   229 /*!
       
   230     Getter method for primary voice number of Voice Mailbox.
       
   231 */
       
   232 void VmbxUiEngine::getCsVoicePrimaryNumber(QString &aValue)
       
   233 {
       
   234     _DBGLOG("VmbxUiEngine::getCsVoicePrimaryNumber >")
       
   235     TVoiceMailboxParams vmbxParams;
       
   236     vmbxParams.iType = EVmbxVoice;
       
   237     vmbxParams.iLineType = EVmbxAlsLine1;
       
   238     vmbxParams.iServiceId = KVmbxServiceVoice;
       
   239     getNumber(vmbxParams, aValue);
       
   240     _DBGLOG2("VmbxUiEngine::getCsVoicePrimaryNumber < , string=", aValue)
       
   241 }
       
   242 
       
   243 /*!
       
   244     Getter method for primary video number of Voice Mailbox.
       
   245 */
       
   246 void VmbxUiEngine::getCsVideoPrimaryNumber(QString &aValue)
       
   247 {
       
   248     _DBGLOG("VmbxUiEngine::getCsVideoPrimaryNumber >")
       
   249     TVoiceMailboxParams vmbxParams;
       
   250     vmbxParams.iType = EVmbxVideo;
       
   251     vmbxParams.iLineType = EVmbxAlsLine1;
       
   252     vmbxParams.iServiceId = KVmbxServiceVideo;
       
   253     getNumber(vmbxParams, aValue);
       
   254     _DBGLOG2("VmbxUiEngine::getCsVideoPrimaryNumber < , string=", aValue)
       
   255 }
       
   256 
       
   257 /*!
       
   258     Private getter method for voice mailbox number.
       
   259 */  
       
   260 void VmbxUiEngine::getNumber(const TVoiceMailboxParams &aParam, 
       
   261                              QString &aValue)
       
   262 {
       
   263     _DBGLOG("VmbxUiEngine::getNumber >")
       
   264     CVoiceMailboxEntry* vmbxEntry = NULL;
       
   265     TInt result = mVmbxEngine->GetStoredEntry( aParam, vmbxEntry );
       
   266     _DBGLOG2("VmbxUiEngine::getNumber, GetStoredEntry result=", result);
       
   267     if ( KErrNone == result && vmbxEntry ){ 
       
   268         TPtrC entryNumber( KNullDesC );
       
   269         result = vmbxEntry->GetVmbxNumber( entryNumber );
       
   270         _DBGLOG3("VmbxUiEngine::getNumber, GetVmbxNumber result=", 
       
   271             result,
       
   272             " but ignore code and allow returning of an empty string to UI");
       
   273         aValue = QString::fromUtf16(entryNumber.Ptr(), entryNumber.Length());
       
   274     }
       
   275     delete vmbxEntry;
       
   276     vmbxEntry = NULL;
       
   277     _DBGLOG2("VmbxUiEngine::getNumber < , string=", aValue)    
       
   278 }
       
   279 
       
   280 /*!
       
   281     Setter method for voice mailbox number.
       
   282 */
       
   283 void VmbxUiEngine::setNumber(const TVoiceMailboxParams &aParam, 
       
   284                              const QString &aValue)
       
   285 {
       
   286     _DBGLOG("VmbxUiEngine::setNumber >")
       
   287         
       
   288     CVoiceMailboxEntry* vmbxEntry = NULL;
       
   289     QT_TRAP_THROWING(vmbxEntry = CVoiceMailboxEntry::NewL());
       
   290     vmbxEntry->SetServiceId(aParam.iServiceId);
       
   291     vmbxEntry->SetVoiceMailboxType(aParam.iType);
       
   292     vmbxEntry->SetVmbxAlsLineType(aParam.iLineType);
       
   293     _DBGLOG2("VmbxUiEngine::setNumber, SetVmbxNumber aValue=", aValue);
       
   294     _DBGLOG( "VmbxUiEngine::setNumber: cast to TPtrC")
       
   295     TPtrC newNumber( 
       
   296         reinterpret_cast<const TUint16*>( aValue.utf16() ),
       
   297         aValue.length() );
       
   298     int result = vmbxEntry->SetVmbxNumber( newNumber );
       
   299     if ( KErrNone == result ) {
       
   300         result = mVmbxEngine->SaveEntry( *vmbxEntry );
       
   301         _DBGLOG2("VmbxUiEngine::setNumber, SaveEntry result=", result);
       
   302     } 
       
   303     delete vmbxEntry;
       
   304     vmbxEntry = 0;
       
   305     _DBGLOG("VmbxUiEngine::setNumber <");
       
   306 }
       
   307 
       
   308 /*!
       
   309     Query method for voice mailbox number.
       
   310 */
       
   311 int VmbxUiEngine::queryNumber(const TVoiceMailboxParams &aParam, 
       
   312     QString &aValue)
       
   313 {
       
   314     _DBGLOG2("VmbxUiEngine::queryNumber >, value=", aValue)
       
   315     getNumber(aParam, aValue);
       
   316     CVoiceMailboxEntry *vmbxEntry = NULL;
       
   317     int result(0);
       
   318     if (aValue.length() > 0) {
       
   319         result = mVmbxEngine->QueryChangeEntry(aParam, vmbxEntry);
       
   320     } else {
       
   321         result = mVmbxEngine->QueryNewEntry(aParam, vmbxEntry);
       
   322     }
       
   323     if (KErrNone == result && vmbxEntry) {
       
   324         TPtrC entryNumber(KNullDesC);
       
   325         result = vmbxEntry->GetVmbxNumber(entryNumber);
       
   326         _DBGLOG3("VmbxUiEngine::queryNumber, GetVmbxNumber result=", 
       
   327             result,
       
   328             " but ignore code and allow returing of an empty string to UI");
       
   329         aValue = QString::fromUtf16(entryNumber.Ptr(), entryNumber.Length());
       
   330     } 
       
   331     delete vmbxEntry;
       
   332     vmbxEntry = NULL;
       
   333     _DBGLOG2("VmbxUiEngine::queryNumber <, value=", aValue)
       
   334     return result;
       
   335 }
       
   336 
       
   337 //End of file