vmbx/vmbxengine/src/vmbxcenrephandler.cpp
branchRCL_3
changeset 20 987c9837762f
parent 19 7d48bed6ce0c
child 21 0a6dd2dc9970
equal deleted inserted replaced
19:7d48bed6ce0c 20: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:  Implementation of the CVmbxCenRepHandler class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <centralrepository.h>
       
    21 #include <cvoicemailboxentry.h>
       
    22 
       
    23 #include "voicemailboxdomaincrkeys.h"
       
    24 #include "voicemailboxprivatecrkeys.h"
       
    25 #include "vmbxlogger.h"
       
    26 #include "vmbxcenrephandler.h"
       
    27 
       
    28 // CONSTANTS
       
    29 const TUint32 KUnknownCenRepKey( 0xffffffff );
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS =============================
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // CVmbxCenRepHandler::CVmbxCenRepHandler
       
    35 // C++ default constructor can NOT contain any code, that
       
    36 // might leave.
       
    37 // ---------------------------------------------------------------------------
       
    38 //
       
    39 CVmbxCenRepHandler::CVmbxCenRepHandler()
       
    40     {
       
    41     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::CVmbxCenRepHandler <=>" );
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // CVmbxCenRepHandler::ConstructL
       
    46 // Symbian 2nd phase constructor can leave.
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 void CVmbxCenRepHandler::ConstructL()
       
    50     {
       
    51     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::ConstructL =>" );
       
    52     iCRSession = CRepository::NewL( KCRUidVoiceMailbox );
       
    53     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::ConstructL <=" );
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // CVmbxCenRepHandler::NewL
       
    58 // Two-phased constructor.
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CVmbxCenRepHandler* CVmbxCenRepHandler::NewL()
       
    62     {
       
    63     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::NewL =>" );
       
    64     CVmbxCenRepHandler* self = new( ELeave ) CVmbxCenRepHandler();
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     CleanupStack::Pop( self );
       
    68     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::NewL <=" );
       
    69     return self;
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CVmbxCenRepHandler::~CVmbxCenRepHandler
       
    74 // Destructor
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CVmbxCenRepHandler::~CVmbxCenRepHandler()
       
    78     {
       
    79     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::~CVmbxCenRepHandler =>" );
       
    80     delete iCRSession;
       
    81     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::~CVmbxCenRepHandler <=" );
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CVmbxCenRepHandler::GetVmbxNumber
       
    86 // Get saved entry number
       
    87 // ---------------------------------------------------------------------------
       
    88 //
       
    89 TInt CVmbxCenRepHandler::GetVmbxNumber( CVoiceMailboxEntry& aEntry )
       
    90     {
       
    91     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::GetVmbxNumber =>" );
       
    92     TInt result( KErrNotFound );
       
    93     // get right cenrep key
       
    94     TUint32 cenRepKey = ResolveKeyByEntry( aEntry );
       
    95     if ( KUnknownCenRepKey != cenRepKey )
       
    96         {
       
    97         HBufC* cenRepEntry = HBufC::New( KVmbxMaxNumberLength );
       
    98         TPtr ptr( cenRepEntry->Des() );
       
    99         VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::GetVmbxNumber: CenRep Get" );
       
   100         result = iCRSession->Get( cenRepKey, ptr );
       
   101         // get cenrep value
       
   102         if ( KErrNone == result )
       
   103             {
       
   104             if ( ptr.Length() )
       
   105                 {
       
   106                 result = aEntry.SetVmbxNumber( ptr );
       
   107                 VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::GetVmbxNumber:\
       
   108                  Set Entry" ); 
       
   109                 }
       
   110             else
       
   111                 {
       
   112                 result = KErrNotFound;
       
   113                 }
       
   114             }
       
   115         delete cenRepEntry;
       
   116         cenRepEntry = NULL;
       
   117         }
       
   118     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::GetVmbxNumber: result%d <=",
       
   119                                  result );
       
   120     return result;
       
   121     }
       
   122 
       
   123 // ---------------------------------------------------------------------------
       
   124 // CVmbxCenRepHandler::Save
       
   125 // Saves the mailbox number
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 TInt CVmbxCenRepHandler::Save( const CVoiceMailboxEntry& aEntry )
       
   129     {
       
   130     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::Save =>" );
       
   131     TInt result( KErrNone );
       
   132     // get right cenrep key
       
   133     TUint32 cenRepKey = ResolveKeyByEntry( aEntry );
       
   134 
       
   135     if ( KUnknownCenRepKey != cenRepKey )
       
   136         {
       
   137         // set cenrep value
       
   138         TPtrC vmbxNumber( KNullDesC );
       
   139         aEntry.GetVmbxNumber( vmbxNumber );
       
   140         result = iCRSession->Set( cenRepKey, vmbxNumber );
       
   141         }
       
   142     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::Save result=%d <=", result );
       
   143     return result;
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CVmbxCenRepHandler::ResolveKeyByEntry
       
   148 // Resolve CenRep key by entry
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 TUint32 CVmbxCenRepHandler::ResolveKeyByEntry(
       
   152                                        const CVoiceMailboxEntry& aEntry  )
       
   153     {
       
   154     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::ResolveKeyByEntry =>" );
       
   155     TVmbxAlsLineType alsLine = aEntry.VmbxAlsLineType();
       
   156     TVmbxType entryType = aEntry.VoiceMailboxType();
       
   157 
       
   158     TUint32 cenRepKey( KUnknownCenRepKey );
       
   159     switch ( entryType )
       
   160         {
       
   161         // Voice mailbox
       
   162         case EVmbxVoice:
       
   163             {
       
   164             cenRepKey = VoiceCenRepKey( alsLine );
       
   165             break;
       
   166             }
       
   167         // Video mailbox
       
   168         case EVmbxVideo:
       
   169             {
       
   170             cenRepKey = VideoCenRepKey( alsLine );
       
   171             break;
       
   172             }
       
   173         default:
       
   174             break;
       
   175         }
       
   176     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::ResolveKeyByEntry <=" );
       
   177     return cenRepKey;
       
   178     }
       
   179 
       
   180 // ---------------------------------------------------------------------------
       
   181 // CVmbxCenRepHandler::VoiceCenRepKey
       
   182 // Voice mailbox cenntral repository key value
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 TUint32 CVmbxCenRepHandler::VoiceCenRepKey(
       
   186                                        const TVmbxAlsLineType& aLine )
       
   187     {
       
   188     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VoiceCenRepKey =>" );
       
   189     TUint32 cenRepKey( KUnknownCenRepKey );
       
   190     if ( EVmbxAlsLine2 == aLine )
       
   191         {
       
   192         cenRepKey = KVmbxNumberLineAlternate;
       
   193         VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VoiceCenRepKey:Line2" );
       
   194         }
       
   195     else
       
   196         {
       
   197         cenRepKey = KVmbxNumberLinePrimary;
       
   198         VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VoiceCenRepKey:Line1" );
       
   199         }
       
   200     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VoiceCenRepKey <=" );
       
   201     return cenRepKey;
       
   202     }
       
   203 
       
   204 // ---------------------------------------------------------------------------
       
   205 // CVmbxCenRepHandler::VideoCenRepKey
       
   206 // Video mailbox cenntral repository key value
       
   207 // ---------------------------------------------------------------------------
       
   208 //
       
   209 TUint32 CVmbxCenRepHandler::VideoCenRepKey(
       
   210                                        const TVmbxAlsLineType& aLine )
       
   211     {
       
   212     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VideoCenRepKey =>" );
       
   213     TUint32 cenRepKey( KUnknownCenRepKey );
       
   214     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::VideoCenRepKey: aLine = %d",
       
   215          aLine );
       
   216     if ( EVmbxAlsLine2 == aLine )
       
   217         {
       
   218         cenRepKey = KVmbxVideoNmbrLineAlternate;
       
   219         VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VideoCenRepKey:Line2" );
       
   220         }
       
   221     else
       
   222         {
       
   223         cenRepKey = KVmbxVideoNmbrLinePrimary;
       
   224         VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VideoCenRepKey:Line1" );
       
   225         }
       
   226     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VideoCenRepKey <=" );
       
   227     return cenRepKey;
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CVmbxCenRepHandler::StoreType
       
   232 // Fetches active store type
       
   233 // ---------------------------------------------------------------------------
       
   234 //
       
   235 TVmbxMemoryLocation CVmbxCenRepHandler::StoreType()
       
   236     {
       
   237     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::StoreType =>" );
       
   238     TVmbxMemoryLocation memoryLocation( EVmbxPhoneMemory );
       
   239     TInt location;
       
   240     TInt result = iCRSession->Get( KVmbxUsesSimMemory, location );
       
   241     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::StoreType: result = %d",
       
   242              result );
       
   243 
       
   244     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::StoreType: location = %d<=",
       
   245              location );
       
   246 
       
   247     if ( KErrNone == result && EVmbxSimMemory == location )
       
   248         {
       
   249         memoryLocation = EVmbxSimMemory;
       
   250         }
       
   251 #ifdef __WINS__
       
   252     memoryLocation = EVmbxPhoneMemory;
       
   253 #endif
       
   254     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::StoreType: memory = %d<=",
       
   255              memoryLocation );
       
   256     return memoryLocation;
       
   257     }
       
   258 
       
   259 // ---------------------------------------------------------------------------
       
   260 // CVmbxCenRepHandler::VideoSupported
       
   261 // Returns ETrue if supported
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 TBool CVmbxCenRepHandler::VideoSupported()
       
   265     {
       
   266     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VideoSupported =>" );
       
   267     TBool supported( EFalse);
       
   268 
       
   269     TInt res = iCRSession->Get( KVmbxVideoMbxSupport, supported );
       
   270 
       
   271     if ( KErrNone != res )
       
   272         {
       
   273         supported = EFalse;
       
   274         }
       
   275     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::VideoSupported: result %d",
       
   276          supported );
       
   277     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::VideoSupported <=" );
       
   278     return supported;
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CVmbxCenRepHandler::IsSimReadOnly
       
   283 // ETrue if CenRep setting Sim read only
       
   284 // ---------------------------------------------------------------------------
       
   285 //
       
   286 TBool CVmbxCenRepHandler::IsSimReadOnly()
       
   287     {
       
   288     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::IsSimReadOnly =>" );
       
   289     TBool result( EFalse );
       
   290     TInt  res = iCRSession->Get( KVmbxNoSimWriting, result );
       
   291 
       
   292     if ( KErrNone != res )
       
   293         {
       
   294         result = EFalse;
       
   295         }
       
   296     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::IsSimReadOnly: result %I <=",
       
   297          result );
       
   298     return result;
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // CVmbxCenRepHandler::IsAllowedUserEdit
       
   303 // ETrue if number Allowed to edit
       
   304 // ---------------------------------------------------------------------------
       
   305 //
       
   306 TBool CVmbxCenRepHandler::IsAllowedUserEdit()
       
   307     {
       
   308     VMBLOGSTRING( "VMBX: CVmbxCenRepHandler::IsAllowedUserEdit =>" );
       
   309     TBool result( EFalse );
       
   310     TInt temp( 0 );
       
   311     TInt  res = iCRSession->Get( KVmbxUiCaps, temp );
       
   312     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::IsAllowedUserEdit: res %d",
       
   313          res );
       
   314 
       
   315     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::IsAllowedUserEdit: temp %d",
       
   316          temp );
       
   317 
       
   318     if ( ( KErrNone == res ) && !( KVmbxUiUserEditNotAllowed & temp ) )
       
   319         {
       
   320         result = ETrue;
       
   321         }
       
   322     VMBLOGSTRING2( "VMBX: CVmbxCenRepHandler::IsAllowedUserEdit: result %d <=",
       
   323          result );
       
   324     return result;
       
   325     }
       
   326 
       
   327 // End of file