omacpadapters/WAPAdapter/Src/CWPWAPItemBAse.cpp
changeset 42 aa33c2cb9a50
child 67 fdbfe0a95492
equal deleted inserted replaced
41:c742e1129640 42:aa33c2cb9a50
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Base class for WAP setting items.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <msvapi.h>
       
    23 #include <mmsclient.h> 
       
    24 #include <mtclreg.h>
       
    25 #include <f32file.h>
       
    26 #include <barsc.h>
       
    27 #include <bautils.h>
       
    28 #include <CWPCharacteristic.h>
       
    29 #include <CWPParameter.h>
       
    30 #include <WPAdapterUtil.h>
       
    31 #include <commdb.h>
       
    32 #include <CWPAdapter.h>
       
    33 #include "CWPWAPItemBAse.h"
       
    34 #include "ProvisioningDebug.h"
       
    35 #include <cmconnectionmethoddef.h>
       
    36 
       
    37 // CONSTANTS
       
    38 const TInt KNamesGranularity = 1;
       
    39 const TInt KNameMaxLength = 50;
       
    40 
       
    41 // ============================ MEMBER FUNCTIONS ===============================
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CWPWAPItemBase::CWPWAPItemBase
       
    45 // C++ default constructor can NOT contain any code, that
       
    46 // might leave.
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CWPWAPItemBase::CWPWAPItemBase(  const TDesC& aTitle,
       
    50                                  const TDesC& aDefaultName, 
       
    51                                  CWPCharacteristic& aCharacteristic, 
       
    52                                  CCommsDatabase*& aCommsDb, 
       
    53                                  RCmManagerExt*& aCmManager)
       
    54                                 : iCharacteristic( aCharacteristic ), 
       
    55                                   iTitle( aTitle ), 
       
    56                                   iDefaultName( aDefaultName ), 
       
    57                                   iCommsDb( aCommsDb ), 
       
    58                                   iCmManager( aCmManager )
       
    59     {
       
    60     
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // CWPWAPItemBase::BaseConstructL
       
    65 // Symbian 2nd phase constructor can leave.
       
    66 // -----------------------------------------------------------------------------
       
    67 //
       
    68 void CWPWAPItemBase::BaseConstructL()
       
    69     {
       
    70     iCharacteristic.AcceptL( *this );
       
    71 
       
    72     if( iName == KNullDesC )
       
    73         {
       
    74         iName.Set( iDefaultName );
       
    75         }
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // Destructor
       
    80 // -----------------------------------------------------------------------------
       
    81 CWPWAPItemBase::~CWPWAPItemBase()
       
    82     {
       
    83     delete iAddr;
       
    84     }
       
    85 
       
    86 // -----------------------------------------------------------------------------
       
    87 // CWPWAPItemBase::VisitL
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 void CWPWAPItemBase::VisitL( CWPCharacteristic& aCharacteristic )
       
    91     {
       
    92     if( aCharacteristic.Type() == KWPResource )
       
    93         {
       
    94         ResourceL( aCharacteristic );
       
    95         }
       
    96     }
       
    97 
       
    98 // -----------------------------------------------------------------------------
       
    99 // CWPWAPItemBase::VisitL
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 void CWPWAPItemBase::VisitL( CWPParameter& aParameter )
       
   103     {
       
   104     switch( aParameter.ID() )
       
   105         {
       
   106         case EWPParameterName:
       
   107             {
       
   108             iName.Set( aParameter.Value() );
       
   109             break;
       
   110             }
       
   111 
       
   112         case EWPParameterAddr:
       
   113             {
       
   114             if( !iAddr )
       
   115                 {
       
   116                 iAddr = aParameter.Value().AllocL();
       
   117                 }
       
   118             break;
       
   119             }
       
   120 
       
   121         default:
       
   122             {
       
   123             break;
       
   124             }
       
   125         }
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CWPWAPItemBase::VisitLinkL
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CWPWAPItemBase::VisitLinkL( CWPCharacteristic& aLink )
       
   133     {
       
   134     if( !iLink )
       
   135         {
       
   136         iLink = &aLink;
       
   137 
       
   138         if( iName == KNullDesC )
       
   139             {
       
   140             // Get the name
       
   141             CArrayFix<TPtrC>* names = new(ELeave) CArrayFixFlat<TPtrC>( KNamesGranularity );
       
   142             CleanupStack::PushL( names );
       
   143             aLink.ParameterL( EWPParameterName, names );
       
   144             if( names->Count() > 0 )
       
   145                 {
       
   146                 iName.Set( names->At(0) );
       
   147                 }
       
   148             CleanupStack::PopAndDestroy(); // names
       
   149             }
       
   150         }
       
   151     }
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 // CWPWAPItemBase::Name
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 const TDesC& CWPWAPItemBase::Name() const
       
   158     {
       
   159     return iName;
       
   160     }
       
   161 
       
   162 // -----------------------------------------------------------------------------
       
   163 // CWPWAPItemBase::Title
       
   164 // -----------------------------------------------------------------------------
       
   165 //
       
   166 const TDesC& CWPWAPItemBase::Title() const
       
   167     {
       
   168     return iTitle;
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CWPWAPItemBase::Address
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 const TDesC& CWPWAPItemBase::Address() const
       
   176     {
       
   177     if( iAddr )
       
   178         {
       
   179         return *iAddr;
       
   180         }
       
   181     else
       
   182         {
       
   183         return KNullDesC;
       
   184         }
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // CWPWAPItemBase::SaveData
       
   189 // -----------------------------------------------------------------------------
       
   190 //
       
   191 const TDesC8& CWPWAPItemBase::SaveData() const
       
   192     {
       
   193     if( iSaveItem().iSaveItemType != KWPWAPItemTypeNone )
       
   194         {
       
   195         return iSaveItem;
       
   196         }
       
   197     else
       
   198         {
       
   199         return KNullDesC8;
       
   200         }
       
   201     }
       
   202 
       
   203 // -----------------------------------------------------------------------------
       
   204 // CWPWAPItemBase::CreateDbL
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void CWPWAPItemBase::CreateDbL()
       
   208     {
       
   209     if( !iCommsDb )
       
   210         {
       
   211         iCommsDb = CCommsDatabase::NewL();
       
   212         }
       
   213 
       
   214     if( !iCmManager )
       
   215         {
       
   216         iCmManager = new RCmManagerExt;
       
   217         iCmManager->OpenL();
       
   218         }
       
   219     }
       
   220 
       
   221 // -----------------------------------------------------------------------------
       
   222 // CWPWAPItemBase::WriteHomePageL
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 void CWPWAPItemBase::WriteHomePageL( RCmConnectionMethodExt& aCmItem )
       
   226     {
       
   227     FLOG( _L( "[Provisioning] CWPWAPItemBase::WriteHomePageL:" ) );
       
   228 
       
   229     if( iAddr )
       
   230     {
       
   231       	HBufC* startPage = aCmItem.GetStringAttributeL(CMManager::ECmStartPage);
       
   232         TInt length = startPage->Length();
       
   233         delete startPage;
       
   234         
       
   235         if( length > 0 )
       
   236             {
       
   237             FLOG( _L( "[Provisioning] CWPWAPItemBase::WriteHomePageL: EApWapStartPage " ) );
       
   238             // Make a copy of the AP
       
   239             RCmConnectionMethodExt cm = aCmItem.CreateCopyL();
       
   240             CleanupClosePushL( cm );
       
   241             
       
   242             // Create a proper name for the copy
       
   243             TBuf<KNameMaxLength> name( iName.Left( KNameMaxLength ) );
       
   244            // MakeValidNameL( name, *iCommsDb );
       
   245             
       
   246             
       
   247             // Write name 
       
   248             cm.SetStringAttributeL(CMManager::ECmName,name);
       
   249             //cm.SetStringAttributeL(CMManager::ENamingUnique,name);
       
   250             
       
   251             // Write MMSC address
       
   252             cm.SetStringAttributeL(CMManager::ECmStartPage,*iAddr);
       
   253             
       
   254             // Create the new access point
       
   255             TRAPD( err, cm.UpdateL() );
       
   256             
       
   257             FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL err (%d)"), err));
       
   258             FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL iUID (%d)"), iUID));
       
   259             
       
   260             if( err == KErrLocked )
       
   261                 {
       
   262                 err = EWPCommsDBLocked;
       
   263                 }
       
   264             User::LeaveIfError( err );
       
   265 
       
   266             iSaveItem().iSaveItemType = KWPWAPItemTypeAccesspoint;
       
   267             iUID = aCmItem.GetIntAttributeL(CMManager::ECmIapId);
       
   268             iSaveItem().iUID = iUID;
       
   269 
       
   270             CleanupStack::PopAndDestroy(); // newItem
       
   271             }
       
   272         else
       
   273             {
       
   274             FLOG( _L( "[Provisioning] CWPWAPItemBase::WriteHomePageL: EApWapStartPage 0 " ) );
       
   275             aCmItem.SetStringAttributeL(CMManager::ECmStartPage,*iAddr);
       
   276             
       
   277             // Update the access point
       
   278             TBool nameChanged( EFalse );
       
   279             TRAPD( err, aCmItem.UpdateL() );
       
   280             FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL err (%d)"), err));
       
   281             if( err == KErrLocked )
       
   282                 {
       
   283                 err = EWPCommsDBLocked;
       
   284                 }
       
   285             User::LeaveIfError( err );
       
   286             iUID = aCmItem.GetIntAttributeL(CMManager::ECmIapId);
       
   287             FTRACE(RDebug::Print(_L("[Provisioning] CWPWAPItemBase::WriteHomePageL: CreateFromDataL iUID (%d)"), iUID));
       
   288             }
       
   289         }
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CWPWAPItemBase::MakeValidNameL
       
   294 // -----------------------------------------------------------------------------
       
   295 //
       
   296 void CWPWAPItemBase::MakeValidNameL( TDes& aName, CCommsDatabase& aDb ) const
       
   297     {
       
   298    /* CApUtils* utils = CApUtils::NewLC( aDb );
       
   299     utils->MakeValidNameL( aName );
       
   300     CleanupStack::PopAndDestroy(); // utils*/
       
   301     }
       
   302 
       
   303 //  End of File