vmbx/vmbxcpplugin/src/vmbxuiengine.cpp
changeset 13 e32024264ebb
parent 12 ae8abd0db65c
child 19 e44a8c097b15
--- a/vmbx/vmbxcpplugin/src/vmbxuiengine.cpp	Fri Mar 19 09:40:14 2010 +0200
+++ b/vmbx/vmbxcpplugin/src/vmbxuiengine.cpp	Fri Apr 16 15:31:58 2010 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+ * Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
  * All rights reserved.
  * This component and the accompanying materials are made available
  * under the terms of "Eclipse Public License v1.0"
@@ -14,196 +14,169 @@
  * Description:
  *
  */
- 
+
+// System includes
 #include <cvoicemailbox.h>
 #include <cvoicemailboxentry.h>
-#include <QtGlobal>
-#include <QVariant>
+#include <voicemailboxdefs.h>
+
+// User includes
 #include "vmbxuiengine.h"
 #include "loggerutil.h"
 
-
-// -----------------------------------------------------------------------------
-// Comment me!
-// -----------------------------------------------------------------------------
-//
+/*!
+    Constructor
+*/
 VmbxUiEngine::VmbxUiEngine() :
-    mVmbxEngine( 0 )
+    mVmbxEngine(NULL)
 { 
-    _DBGLOG("VmbxUiEngine::VmbxUiEngine>")
-
-    // TODO: test that leave vs thrown exception really works
-    //mVmbxEngine = QT_TRAP_THROWING( CVoiceMailbox::NewL() ); this available in qt 4.6  
-    // TODO: replace all this trapping&throwing using QT_TRAP_THROWING when qt 4.6
-    TRAPD( error, mVmbxEngine = CVoiceMailbox::NewL(); );
-    if ( error || !mVmbxEngine ) {
-        QT_THROW( 0 );
-    }
+    _DBGLOG("VmbxUiEngine::VmbxUiEngine >")
+    QT_TRAP_THROWING(mVmbxEngine = CVoiceMailbox::NewL());
     _DBGLOG("VmbxUiEngine::VmbxUiEngine <")
 }
 
-// -----------------------------------------------------------------------------
-// 
-// -----------------------------------------------------------------------------
-//
+/*!
+    Destructor
+*/
 VmbxUiEngine::~VmbxUiEngine()
 {
     _DBGLOG( "VmbxUiEngine::~VmbxUiEngine >")
     delete mVmbxEngine;
-    // TODO: check cleanup, this is a first draft!
+    mVmbxEngine = NULL;
     _DBGLOG( "VmbxUiEngine::~VmbxUiEngine <")
-    }
+}
 
-// -----------------------------------------------------------------------------
-// 
-// -----------------------------------------------------------------------------
-//
-void VmbxUiEngine::GetCsVoice1Number( QString& aValue )
+/*!
+    Getter method for primary voice number of Voice Mailbox.
+*/
+void VmbxUiEngine::getCsVoice1Number(QString &aValue)
 {
-    _DBGLOG("VmbxUiEngine::GetCsVoice1Number >")
+    _DBGLOG("VmbxUiEngine::getCsVoice1Number >")
 
-    CVoiceMailboxEntry* vmbxEntry = NULL;
     TVoiceMailboxParams vmbxParams;
     vmbxParams.iType = EVmbxVoice;
     vmbxParams.iLineType = EVmbxAlsLine1;
     vmbxParams.iServiceId = KVmbxServiceVoice;
-    TInt result = mVmbxEngine->GetStoredEntry( vmbxParams, vmbxEntry );
-    _DBGLOG2("VmbxUiEngine::GetCsVoice1Number, GetStoredEntry result=", result);
-    if ( KErrNone == result && vmbxEntry )
-        { 
-        TPtrC entryNumber( KNullDesC );
-        result = vmbxEntry->GetVmbxNumber( entryNumber );
-        _DBGLOG3("VmbxUiEngine::GetCsVoice1Number, GetVmbxNumber result=", 
-            result,
-            " but ignore code and allow returing of an empty string to UI");
-        aValue = QString( (QChar*)entryNumber.Ptr(), entryNumber.Length() );
-        }
-
-    _DBGLOG2("VmbxUiEngine::GetCsVoice1Number < , string=", aValue)
+    getNumber(vmbxParams, aValue);
+    _DBGLOG2("VmbxUiEngine::getCsVoice1Number < , string=", aValue)
 }
 
-// -----------------------------------------------------------------------------
-// 
-// -----------------------------------------------------------------------------
-//
-void VmbxUiEngine::GetCsVoice2Number( QString& aValue )
+/*!
+    Getter method for voice ALS number of Voice Mailbox.
+*/
+void VmbxUiEngine::getCsVoice2Number(QString &aValue)
 {
-    _DBGLOG("VmbxUiEngine::GetCsVoice2Number >")
-    CVoiceMailboxEntry* vmbxEntry = NULL;
+    _DBGLOG("VmbxUiEngine::getCsVoice2Number >")
     TVoiceMailboxParams vmbxParams;
     vmbxParams.iType = EVmbxVoice;
     vmbxParams.iLineType = EVmbxAlsLine2;
     vmbxParams.iServiceId = KVmbxServiceVoice;
-    TInt result = mVmbxEngine->GetStoredEntry( vmbxParams, vmbxEntry );
-    _DBGLOG2("VmbxUiEngine::GetCsVoice2Number, GetStoredEntry result=", result);
-    if ( KErrNone == result && vmbxEntry )
-        { 
-        TPtrC entryNumber( KNullDesC );
-        result = vmbxEntry->GetVmbxNumber( entryNumber );
-        _DBGLOG3("VmbxUiEngine::GetCsVoice2Number, GetVmbxNumber result=", 
-            result,
-            " but ignore code and allow returing of an empty string to UI");
-        aValue = QString( (QChar*)entryNumber.Ptr(),entryNumber.Length() );
-        }
-    _DBGLOG2("VmbxUiEngine::GetCsVoice2Number < , string=", aValue)
+    getNumber(vmbxParams, aValue);
+    _DBGLOG2("VmbxUiEngine::getCsVoice2Number < , string=", aValue)
 }
 
-// -----------------------------------------------------------------------------
-// 
-// -----------------------------------------------------------------------------
-//
-void VmbxUiEngine::GetCsVideo1Number( QString& aValue )
+/*!
+    Getter method for primary video number of Voice Mailbox.
+*/
+void VmbxUiEngine::getCsVideo1Number(QString &aValue)
 {
-    _DBGLOG("VmbxUiEngine::GetCsVideo1Number >")
-    CVoiceMailboxEntry* vmbxEntry = NULL;
+    _DBGLOG("VmbxUiEngine::getCsVideo1Number >")
     TVoiceMailboxParams vmbxParams;
     vmbxParams.iType = EVmbxVideo;
     vmbxParams.iLineType = EVmbxAlsLine1;
     vmbxParams.iServiceId = KVmbxServiceVideo;
-    TInt result = mVmbxEngine->GetStoredEntry( vmbxParams, vmbxEntry );
-    _DBGLOG2("VmbxUiEngine::GetCsVideo1Number, GetStoredEntry result=", result);
-    if ( KErrNone == result && vmbxEntry )
-        { 
-        TPtrC entryNumber( KNullDesC );
-        result = vmbxEntry->GetVmbxNumber( entryNumber );
-        _DBGLOG3("VmbxUiEngine::GetCsVideo1Number, GetVmbxNumber result=", 
-            result,
-            " but ignore code and allow returing of an empty string to UI");
-        aValue = QString( (QChar*)entryNumber.Ptr(),entryNumber.Length() );
-        }
-    _DBGLOG2("VmbxUiEngine::GetCsVideo1Number < , string=", aValue)
-}
-
-// -----------------------------------------------------------------------------
-// 
-// -----------------------------------------------------------------------------
-//
-VmbxUiEngine::TUiDefaultVoiceMailboxType VmbxUiEngine::DefaultMailboxType()
-{
-    _DBGLOG( "VmbxUiEngine::DefaultMailboxType")
-    TUiDefaultVoiceMailboxType result = EUiDefaultVmbxNone;
-    // TODO: get type from engine IF AND WHEN THIS FEATURE IS SUPPORTED
-    _DBGLOG2("VmbxUiEngine::GetCsVideo1Number < , string=", result)
-    return result;
+    getNumber(vmbxParams, aValue);
+    _DBGLOG2("VmbxUiEngine::getCsVideo1Number < , string=", aValue)
 }
 
-// -----------------------------------------------------------------------------
-// Callback from voice mailbox engine when number has been updated
-// This method notifies the UI to refresh its data. 
-// -----------------------------------------------------------------------------
-//
-void VmbxUiEngine::HandleNotifyL( const CVoiceMailboxEntry& /*aVmbxEntry*/ )
+/*!
+    Callback from voice mailbox engine when number has been updated
+    This method notifies the UI to refresh its data.
+*/
+void VmbxUiEngine::uiCsVoice1Changed(const QString& aValue)
 {
-    _DBGLOG( "VmbxUiEngine::HandleNotifyL")
-    /* TODO:  consider is there need to pass the actual modified data 
-    and mailbox type enum to slot.
-    
-    TODO: issue the notification request to vmbxengine, that is missing
-    at the moment !
-    */
-    emit voiceMailboxEngineEntriesUpdated();
-}
-
-// -----------------------------------------------------------------------------
-// Callback from voice mailbox engine when number has been updated
-// This method notifies the UI to refresh its data. 
-// -----------------------------------------------------------------------------
-//
-void VmbxUiEngine::uiCsVoice1Changed( const QString& aValue )
-{
-    _DBGLOG2("VmbxUiEngine::uiCsVoice1Changed, value=",aValue)
-    CVoiceMailboxEntry* vmbxEntry = NULL;
+    _DBGLOG2("VmbxUiEngine::uiCsVoice1Changed >, value=",aValue)
     TVoiceMailboxParams vmbxParams;
     vmbxParams.iType = EVmbxVoice;
     vmbxParams.iLineType = EVmbxAlsLine1;
     vmbxParams.iServiceId = KVmbxServiceVoice;
-    TInt result = mVmbxEngine->GetStoredEntry( vmbxParams, vmbxEntry );
-    _DBGLOG2("VmbxUiEngine::uiCsVoice1Changed, GetStoredEntry result=", result);
-    if ( KErrNone != result )
-        {
-        // TODO: test that leave vs thrown exception really works
-        //vmbxEntry = QT_TRAP_THROWING( CVoiceMailboxEntry::NewL() ); this available in qt 4.6  
-        // TODO: replace all this trapping using QT_TRAP_THROWING when qt 4.6
-        TRAP_IGNORE( vmbxEntry = CVoiceMailboxEntry::NewL() );
-        vmbxEntry->SetServiceId( KVmbxServiceVoice );
-        vmbxEntry->SetVoiceMailboxType( EVmbxVoice );
-        vmbxEntry->SetVmbxAlsLineType( EVmbxAlsLine1 );
+    setNumber(vmbxParams, aValue);
+    _DBGLOG("VmbxUiEngine::uiCsVoice1Changed <");
+}
+
+/*!
+    Callback from voice mailbox engine when number has been updated
+    This method notifies the UI to refresh its data.
+*/
+void VmbxUiEngine::HandleNotifyL(const CVoiceMailboxEntry &aVmbxEntry)
+{
+    _DBGLOG( "VmbxUiEngine::HandleNotifyL")
+    Q_UNUSED(aVmbxEntry);
+    // Consider is there need to pass the actual modified data 
+    // and mailbox type enum to slot.
+    //
+    // Issue the notification request to vmbxengine, that is missing
+    // at the moment !
+    emit voiceMailboxEngineEntriesUpdated();
+}
+
+/*!
+    Private getter method for voice mailbox number.
+*/  
+void VmbxUiEngine::getNumber(const TVoiceMailboxParams &aParam, 
+                             QString &aValue)
+{
+    _DBGLOG("VmbxUiEngine::getNumber >")
+    CVoiceMailboxEntry* vmbxEntry = NULL;
+    TInt result = mVmbxEngine->GetStoredEntry( aParam, vmbxEntry );
+    _DBGLOG2("VmbxUiEngine::getNumber, GetStoredEntry result=", result);
+    if ( KErrNone == result && vmbxEntry ){ 
+        TPtrC entryNumber( KNullDesC );
+        result = vmbxEntry->GetVmbxNumber( entryNumber );
+        _DBGLOG3("VmbxUiEngine::getNumber, GetVmbxNumber result=", 
+            result,
+            " but ignore code and allow returing of an empty string to UI");
+        aValue = QString::fromUtf16 (entryNumber.Ptr(), entryNumber.Length());
+    }
+    delete vmbxEntry;
+    vmbxEntry = NULL;
+    _DBGLOG2("VmbxUiEngine::getNumber < , string=", aValue)    
+}
+
+/*!
+    Setter method for voice mailbox number.
+*/
+void VmbxUiEngine::setNumber(const TVoiceMailboxParams &aParam, 
+                             const QString &aValue)
+{
+    _DBGLOG("VmbxUiEngine::setNumber >")
+        
+    CVoiceMailboxEntry* vmbxEntry = NULL;
+    TInt result = mVmbxEngine->GetStoredEntry(aParam, vmbxEntry);    
+    _DBGLOG2("VmbxUiEngine::setNumber, GetStoredEntry result=", result);
+    if ( KErrNone != result ){
+        QT_TRAP_THROWING(vmbxEntry = CVoiceMailboxEntry::NewL());
+        vmbxEntry->SetServiceId(aParam.iServiceId);
+        vmbxEntry->SetVoiceMailboxType(aParam.iType);
+        vmbxEntry->SetVmbxAlsLineType(aParam.iLineType);
         // Service name for cs is basically the one in service table,
         // but in this case it's not used for anything by vmbx.
         // So let's not set anything as name...fix if problems arise
-        }
-    _DBGLOG( "VmbxUiEngine::uiCsVoice1Changed: cast to TPtrC")
+    }
+    _DBGLOG( "VmbxUiEngine::setNumber: cast to TPtrC")
     TPtrC newNumber( 
         reinterpret_cast<const TUint16*>( aValue.utf16() ),
         aValue.length() );
     result = vmbxEntry->SetVmbxNumber( newNumber );
-    _DBGLOG2("VmbxUiEngine::uiCsVoice1Changed, SetVmbxNumber result=", result);
+    _DBGLOG2("VmbxUiEngine::setNumber, SetVmbxNumber result=", result);
 
-    if ( KErrNone == result )
-        {
+    if ( KErrNone == result ){
         result = mVmbxEngine->SaveEntry( *vmbxEntry );
-        } 
+        _DBGLOG2("VmbxUiEngine::setNumber, SaveEntry result=", result);
+    } 
     delete vmbxEntry;
     // TODO: handle error here
-    _DBGLOG2("VmbxUiEngine::uiCsVoice1Changed <, SaveEntry result=", result);
+    _DBGLOG("VmbxUiEngine::setNumber <");
 }
+
+//End of file