omaprovisioning/provisioning/WAPAdapter/Src/CWPWAPBrowserAdapter.cpp
changeset 0 b497e44ab2fc
child 2 5594fba90824
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002-2006 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:  Handles browser settings in provisioning.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <FavouritesDb.h>
       
    23 #include <CWPAdapter.h>
       
    24 #include <CWPCharacteristic.h>
       
    25 #include <CWPParameter.h>
       
    26 #include <wpwapadapterresource.rsg>
       
    27 #include <ApDataHandler.h>
       
    28 #include "CWPWAPBrowserAdapter.h"
       
    29 #include "MWPWAPItemBase.h"
       
    30 #include "WPWAPItemFactory.h"
       
    31 #include "WPWAPUtil.h"
       
    32 #include "WPWAPDebug.h"
       
    33 
       
    34 // CONSTANTS
       
    35 _LIT( KBrowserAppID, "w2" );
       
    36 
       
    37 // ============================ MEMBER FUNCTIONS ===============================
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // CWPWAPBrowserAdapter::CWPWAPBrowserAdapter
       
    41 // C++ default constructor can NOT contain any code, that
       
    42 // might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CWPWAPBrowserAdapter::CWPWAPBrowserAdapter()
       
    46     {
       
    47     }
       
    48 
       
    49 // -----------------------------------------------------------------------------
       
    50 // CWPWAPBrowserAdapter::ConstructL
       
    51 // Symbian 2nd phase constructor can leave.
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 void CWPWAPBrowserAdapter::ConstructL()
       
    55     {
       
    56     BaseConstructL();
       
    57 
       
    58     iTitle = WPWAPUtil::ReadHBufCL( R_QTN_OP_HEAD_BROWSER );
       
    59     iBookmarkTitle = WPWAPUtil::ReadHBufCL( R_QTN_SM_BOOKMARKS );
       
    60     iDefaultName = WPWAPUtil::ReadHBufCL( R_QTN_SM_WAPAP_NAME );
       
    61     iDefaultBookmarkName = WPWAPUtil::ReadHBufCL( R_QTN_SM_BOOKMARK_NAME );
       
    62     }
       
    63 
       
    64 // -----------------------------------------------------------------------------
       
    65 // CWPWAPBrowserAdapter::NewL
       
    66 // Two-phased constructor.
       
    67 // -----------------------------------------------------------------------------
       
    68 //
       
    69 CWPWAPBrowserAdapter* CWPWAPBrowserAdapter::NewL()
       
    70     {
       
    71     CWPWAPBrowserAdapter* self = new(ELeave) CWPWAPBrowserAdapter; 
       
    72     CleanupStack::PushL(self);
       
    73     self->ConstructL();
       
    74     CleanupStack::Pop(self);
       
    75     return self;
       
    76     }
       
    77 
       
    78 // Destructor
       
    79 CWPWAPBrowserAdapter::~CWPWAPBrowserAdapter()
       
    80     {
       
    81     delete iTitle;
       
    82     delete iBookmarkTitle;
       
    83     delete iDefaultName;
       
    84     delete iDefaultBookmarkName;
       
    85     iFavouritesDb.Close();
       
    86     iSession.Close();
       
    87     }
       
    88 
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CWPWAPBrowserAdapter::ApplicationL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CWPWAPBrowserAdapter::ApplicationL( CWPCharacteristic& aCharacteristic )
       
    95     {
       
    96     if( iAppID == KBrowserAppID )
       
    97         {
       
    98         MWPWAPItemBase* item = WPWAPItemFactory::CreateBrowserLC( !iProcessed, *iTitle, 
       
    99             *iBookmarkTitle, *iDefaultName, *iDefaultBookmarkName, 
       
   100             aCharacteristic, iCommsDb, iAPHandler, iFavouritesDb );
       
   101 
       
   102         if( item->ValidateL() )
       
   103             {
       
   104             iProcessed = ETrue;
       
   105             item->AddL( iItems, iHiddenItems );
       
   106             CleanupStack::Pop(); // item
       
   107             }
       
   108         else
       
   109             {
       
   110             CleanupStack::PopAndDestroy(); // item
       
   111             }
       
   112         }
       
   113     }
       
   114 
       
   115 // -----------------------------------------------------------------------------
       
   116 // CWPWAPBrowserAdapter::DeleteL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CWPWAPBrowserAdapter::DeleteL( const TDesC8& aSaveData )
       
   120     {
       
   121     CreateDbL();
       
   122 
       
   123     TPckgBuf<MWPWAPItemBase::TWPWAPSaveItem> item;
       
   124     item.Copy( aSaveData );
       
   125 
       
   126     switch( item().iSaveItemType )
       
   127         {
       
   128         case KWPWAPItemTypeAccesspoint:
       
   129             {
       
   130             // Access point deletion is handled by the base class
       
   131             CWPWAPAdapterBase::DeleteL( aSaveData );
       
   132             break;
       
   133             }
       
   134 
       
   135         case KWPWAPItemTypeBookmark:
       
   136             {
       
   137             DVA( "DeleteL: Deleting bookmark %08x", item().iUID );
       
   138             TInt err = iFavouritesDb.Begin( ETrue );
       
   139             iFavouritesDb.CleanupRollbackPushL();  // push a rollback
       
   140             
       
   141             DVA( "DeleteL: Transaction, %d", err );
       
   142             if( err == KErrNone )
       
   143                 {
       
   144                 err = iFavouritesDb.Delete( item().iUID );
       
   145                 DVA( "DeleteL: Deleted, %d", err );
       
   146                 iFavouritesDb.Commit();
       
   147                 DEBUG( "DeleteL: Committed" );
       
   148                 }
       
   149             CleanupStack::Pop();    // pop the rollback
       
   150 
       
   151             switch( err )
       
   152                 {
       
   153                 case KErrNotFound:
       
   154                     {
       
   155                     // Item not existing is what we want, so this error is ok
       
   156                     break;
       
   157                     }
       
   158                     
       
   159                 case KErrLocked:
       
   160                     {
       
   161                     User::Leave( EWPBookmarksLocked );
       
   162                     break;
       
   163                     }
       
   164                     
       
   165                 default:
       
   166                     {
       
   167                     User::LeaveIfError( err );
       
   168                     break;
       
   169                     }
       
   170                 }
       
   171             break;
       
   172             }
       
   173 
       
   174         default:
       
   175             {
       
   176             // Don't know how to delete an item of this type. Better
       
   177             // just ignore it.
       
   178             break;
       
   179             }
       
   180         }
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CWPWAPBrowserAdapter::CreateDbL
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 void CWPWAPBrowserAdapter::CreateDbL()
       
   188     {
       
   189     User::LeaveIfError( iSession.Connect() );
       
   190     User::LeaveIfError( iFavouritesDb.Open( iSession, KBrowserBookmarks ) );
       
   191 
       
   192     CWPWAPAdapterBase::CreateDbL();
       
   193     }
       
   194 
       
   195 //  End of File