omaprovisioning/provisioning/WAPAdapter/Src/CWPWAPBrowserItem.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:  One browser setting item.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <msvapi.h>
       
    23 #include <ApDataHandler.h>
       
    24 #include <ApAccessPointItem.h>
       
    25 #include <CWPCharacteristic.h>
       
    26 #include <CWPParameter.h>
       
    27 #include <CWPAdapter.h>
       
    28 #include <centralrepository.h>
       
    29 #include <BrowserUiSDKCRKeys.h>
       
    30 #include "CWPWAPBrowserItem.h"
       
    31 #include "WPWAPItemFactory.h"
       
    32 #include "ProvisioningDebug.h"
       
    33 
       
    34 // CONSTANTS
       
    35 /// Delay to wait for WmlBrowser to catch up with changes in CommsDb. Microseconds.
       
    36 const TInt KWmlDelay = 4*500000;
       
    37 // Force browser to use User Defined AP
       
    38 const TInt KUserDefined = 0;
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CWPWAPBrowserItem::CWPWAPBrowserItem
       
    42 // C++ default constructor can NOT contain any code, that
       
    43 // might leave.
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CWPWAPBrowserItem::CWPWAPBrowserItem( TBool aFirst,
       
    47                                       const TDesC& aTitle,
       
    48                                       const TDesC& aBookmarkTitle,
       
    49                                       const TDesC& aDefaultName, 
       
    50                                       const TDesC& aDefaultBookmarkName,
       
    51                                       CWPCharacteristic& aCharacteristic, 
       
    52                                       CCommsDatabase*& aCommsDb, 
       
    53                                       CApDataHandler*& aAPHandler,
       
    54                                       RFavouritesDb aBookmarkDb 
       
    55                                     )
       
    56                                     : CWPWAPItemBase( aTitle,
       
    57                                                       aDefaultName, 
       
    58                                                       aCharacteristic, 
       
    59                                                       aCommsDb, 
       
    60                                                       aAPHandler ), 
       
    61                                     iDefaultBookmarkName( aDefaultBookmarkName ),
       
    62                                     iBookmarkTitle( aBookmarkTitle ), 
       
    63                                     iDb( aBookmarkDb ),
       
    64                                     iFirst( aFirst )
       
    65     {
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CWPWAPBrowserItem::ConstructL
       
    70 // Symbian 2nd phase constructor can leave.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 void CWPWAPBrowserItem::ConstructL()
       
    74     {
       
    75     BaseConstructL();
       
    76     }
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CWPWAPBrowserItem::NewL
       
    80 // Two-phased constructor.
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CWPWAPBrowserItem* CWPWAPBrowserItem::NewL( TBool aFirst,
       
    84                                             const TDesC& aTitle, 
       
    85                                             const TDesC& aBookmarkTitle,
       
    86                                             const TDesC& aDefaultName,  
       
    87                                             const TDesC& aDefaultBookmarkName,
       
    88                                             CWPCharacteristic& aCharacteristic, 
       
    89                                             CCommsDatabase*& aCommsDb, 
       
    90                                             CApDataHandler*& aAPHandler,
       
    91                                             RFavouritesDb aBookmarkDb
       
    92                                             )
       
    93     {
       
    94     CWPWAPBrowserItem* self = new(ELeave) CWPWAPBrowserItem( aFirst,
       
    95                                                              aTitle, 
       
    96                                                              aBookmarkTitle, 
       
    97                                                              aDefaultName, 
       
    98                                                              aDefaultBookmarkName,
       
    99                                                              aCharacteristic, 
       
   100                                                              aCommsDb, 
       
   101                                                              aAPHandler, 
       
   102                                                              aBookmarkDb ); 
       
   103     CleanupStack::PushL(self);
       
   104     self->ConstructL();
       
   105     CleanupStack::Pop(self);
       
   106     return self;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // Destructor
       
   111 // -----------------------------------------------------------------------------
       
   112 CWPWAPBrowserItem::~CWPWAPBrowserItem()
       
   113     {
       
   114     iBookmarks.ResetAndDestroy();
       
   115     }
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CWPWAPBrowserItem::SaveL
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CWPWAPBrowserItem::SaveL()
       
   122     {
       
   123     CreateDbL();
       
   124 
       
   125     TPckg<TUint32> uid( iUID );
       
   126     // Check if the iLink->Data() contains an item of the same size as uid. 
       
   127     // This is an extra check to ensure that iLink->Data() contains a packaged
       
   128     // TUin32.
       
   129     if( iLink && iLink->Data().Length() == uid.MaxLength() )
       
   130         {
       
   131         uid.Copy( iLink->Data() );
       
   132         }
       
   133     
       
   134     CApAccessPointItem* apItem = CApAccessPointItem::NewLC();
       
   135     // will leave if AP does not exists
       
   136     iAPHandler->AccessPointDataL( iUID, *apItem );
       
   137     if( iAddr )
       
   138         {
       
   139         // Update the access point startpage
       
   140         WriteHomePageL( *apItem );
       
   141         }
       
   142     CleanupStack::PopAndDestroy(); // apItem
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CWPWAPBrowserItem::CanSetAsDefault
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 TBool CWPWAPBrowserItem::CanSetAsDefault() const
       
   150     {
       
   151     return iUID != KWPWAPNoUID;
       
   152     }
       
   153 
       
   154 // -----------------------------------------------------------------------------
       
   155 // CWPWAPBrowserItem::SetAsDefaultL
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CWPWAPBrowserItem::SetAsDefaultL()
       
   159     {
       
   160     FLOG( _L( "[Provisioning] CWPWAPBrowserItem::SetAsDefaultL:" ) );
       
   161     
       
   162     CreateDbL();
       
   163     TRAPD( err, iAPHandler->SetAsDefaultL( (TInt)iUID, EIspTypeWAPOnly) );
       
   164     if( err == KErrLocked )
       
   165         {
       
   166         err = EWPCommsDBLocked;
       
   167         }
       
   168     // This function need to leave at the end of the function
       
   169     // otherwise we dont set the default AP when db is locked
       
   170     //User::LeaveIfError( err );
       
   171     
       
   172     // There's some delay before the WmlBrowser can find the stored 
       
   173     // accesspoint from CommsDb so therefore we wait for a while before
       
   174     // telling the WmlBrowser that default accesspoint should be changed.
       
   175     // The value 500000 is chosen just by trying out.
       
   176     User::After( KWmlDelay );
       
   177 
       
   178     CRepository* repository = CRepository::NewLC( KCRUidBrowser );
       
   179     FTRACE(RDebug::Print(
       
   180                 _L("[Provisioning] CWPWAPBrowserItem::SetAsDefaultL: AP:(%d)"),
       
   181                                                                   (TInt)iUID));
       
   182     
       
   183     // Force the browser to use the User Defined AP selection mode.
       
   184     User::LeaveIfError( repository->Set( KBrowserAccessPointSelectionMode,
       
   185                                          KUserDefined ) );
       
   186     // This sets the accesspoint default for browser.
       
   187     User::LeaveIfError( repository->Set( KBrowserDefaultAccessPoint,
       
   188                                          (TInt)iUID ) );
       
   189 
       
   190     //Set the HomePage to default
       
   191     if(iUID)
       
   192         {
       
   193         User::LeaveIfError( repository->Set( KBrowserNGHomepageType, EBrowserCenRepAccessPoint) );
       
   194         }
       
   195 
       
   196     CleanupStack::PopAndDestroy(); // repository
       
   197     FLOG( _L( "[Provisioning] CWPWAPBrowserItem::SetAsDefaultL: Set Done" ) );
       
   198 
       
   199     User::LeaveIfError( err );
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // CWPWAPBrowserItem::ValidateL
       
   204 // -----------------------------------------------------------------------------
       
   205 //
       
   206 TBool CWPWAPBrowserItem::ValidateL()
       
   207     {
       
   208     return iLink != NULL;
       
   209     }
       
   210 
       
   211 // -----------------------------------------------------------------------------
       
   212 // CWPWAPBrowserItem::ResourceL
       
   213 // -----------------------------------------------------------------------------
       
   214 //
       
   215 void CWPWAPBrowserItem::ResourceL( CWPCharacteristic& aResource )
       
   216     {
       
   217     MWPWAPItemBase* item = WPWAPItemFactory::CreateBookmarkLC( 
       
   218                                                           iBookmarkTitle, 
       
   219                                                           iDefaultBookmarkName,
       
   220                                                           aResource, 
       
   221                                                           iLink, 
       
   222                                                           iDb );
       
   223 
       
   224     if( item->CanSetAsDefault() && !iAddr )
       
   225         {
       
   226         iAddr = item->Address().AllocL();
       
   227         CleanupStack::PopAndDestroy(); // item
       
   228         }
       
   229     else
       
   230         {
       
   231         User::LeaveIfError( iBookmarks.Append( item ) );
       
   232         CleanupStack::Pop(); // item
       
   233         }
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CWPWAPBrowserItem::AddL
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void CWPWAPBrowserItem::AddL( RPointerArray<MWPWAPItemBase>& aShownItems,
       
   241                               RPointerArray<MWPWAPItemBase>& aHiddenItems )
       
   242     {
       
   243     for( TInt i( iBookmarks.Count()-1 ); i >= 0 ; i-- )
       
   244         {
       
   245         MWPWAPItemBase* item = iBookmarks[i];
       
   246 
       
   247         if( item->ValidateL() )
       
   248             {
       
   249             // Transfer ownership of iBookmarks[i] to aItems
       
   250             iBookmarks[i]->AddL( aShownItems, aHiddenItems );
       
   251             }
       
   252         else
       
   253             {
       
   254             // invalid items get deleted
       
   255             delete item;
       
   256             }
       
   257         iBookmarks.Remove( i );
       
   258         }
       
   259 
       
   260     // Only first browser item is shown to the user.
       
   261     if( iFirst )
       
   262         {
       
   263         User::LeaveIfError( aShownItems.Append( this ) );
       
   264         }
       
   265     else
       
   266         {
       
   267         User::LeaveIfError( aHiddenItems.Append( this ) );
       
   268         }
       
   269     }
       
   270 
       
   271 //  End of File