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