clientprovisioning/cpqtsp/src/CWPSaver.cpp
changeset 42 aa33c2cb9a50
parent 30 d3981f4fe6a4
child 62 03849bd79877
equal deleted inserted replaced
41:c742e1129640 42:aa33c2cb9a50
     1 /*
     1 /*
     2 * ============================================================================
     2 * ============================================================================
     3 *  Name        : CWPSaver.cpp
     3 *  Name        : CWPSaver.cpp
     4 *  Part of     : Provisioning / ProvisioningBC
     4 *  Part of     : Provisioning / ProvisioningBC
     5 *  Description : Helper class for saving Provisioning settings. Provides a progress note.
     5 *  Description : Helper class for saving Provisioning settings. Provides a progress note.
     6 *  Version     : %version: 1 % << Don't touch! Updated by Synergy at check-out.
     6 *  Version     : %version: 2 % << Don't touch! Updated by Synergy at check-out.
     7 *
     7 *
     8 *  Copyright © 2002-2006 Nokia.  All rights reserved.
     8 *  Copyright © 2002-2006 Nokia.  All rights reserved.
     9 *  This material, including documentation and any related computer
     9 *  This material, including documentation and any related computer
    10 *  programs, is protected by copyright controlled by Nokia.  All
    10 *  programs, is protected by copyright controlled by Nokia.  All
    11 *  rights are reserved.  Copying, including reproducing, storing,
    11 *  rights are reserved.  Copying, including reproducing, storing,
    15 *  without the prior written consent of Nokia.
    15 *  without the prior written consent of Nokia.
    16 * ============================================================================
    16 * ============================================================================
    17 */
    17 */
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <aknquerydialog.h>
       
    21 #include <eikprogi.h>
       
    22 //#include <ProvisioningBC.rsg>
       
    23 #include <commdb.h>
    20 #include <commdb.h>
    24 #include <CWPEngine.h>
    21 #include <CWPEngine.h>
    25 #include <CWPAdapter.h>
    22 #include <CWPAdapter.h>
    26 #include <ActiveFavouritesDbNotifier.h>
    23 
    27 #include "CWPSaver.h"
    24 #include "CWPSaver.h"
    28 #include <HbProgressDialog>
    25 #include <HbProgressDialog>
    29 #include <HbAction>
    26 #include <HbAction>
    30 
    27 
    31 // CONSTANTS
    28 // CONSTANTS
    54 //
    51 //
    55 void CWPSaver::PrepareLC()
    52 void CWPSaver::PrepareLC()
    56     {
    53     {
    57     // Assume ownership of this.
    54     // Assume ownership of this.
    58     CleanupStack::PushL( this );
    55     CleanupStack::PushL( this );
    59 
       
    60     iApDbNotifier = CActiveApDb::NewL( EDatabaseTypeIAP );
       
    61     iApDbNotifier->AddObserverL( this );
       
    62     
       
    63     User::LeaveIfError( iSession.Connect() );
       
    64     User::LeaveIfError( iBookmarkDb.Open( iSession, KBrowserBookmarks ) );
       
    65     iFavouritesNotifier = 
       
    66                 new(ELeave) CActiveFavouritesDbNotifier( iBookmarkDb, *this );  
       
    67 
       
    68     iFavouritesNotifier->Start();
       
    69 
       
    70     iRetryTimer = CPeriodic::NewL( EPriorityStandard );
       
    71     iProgress = new HbProgressDialog(HbProgressDialog::WaitDialog);
    56     iProgress = new HbProgressDialog(HbProgressDialog::WaitDialog);
    72     iProgress->setText(hbTrId("txt_device_update_setlabel_saving_settings"));
    57     iProgress->setText(hbTrId("txt_device_update_setlabel_saving_settings"));
    73     //iProgress->setTextAlignment(Qt::AlignCenter);
       
    74     iProgress->clearActions();   
    58     iProgress->clearActions();   
    75     //iProgress->setPrimaryAction(new HbAction(""));
       
    76     //iProgress->setSecondaryAction(new HbAction(""));
       
    77     iProgress->show();
    59     iProgress->show();
    78 
    60 
    79  }
    61  }
    80 
    62 
    81 // ----------------------------------------------------------------------------
    63 // ----------------------------------------------------------------------------
   105 // Destructor
    87 // Destructor
   106 // ----------------------------------------------------------------------------
    88 // ----------------------------------------------------------------------------
   107 CWPSaver::~CWPSaver()
    89 CWPSaver::~CWPSaver()
   108     {
    90     {
   109     Cancel();
    91     Cancel();
   110 
    92   }
   111     delete iApDbNotifier;
       
   112 
       
   113     if( iFavouritesNotifier )
       
   114         {
       
   115         iFavouritesNotifier->Cancel();
       
   116         delete iFavouritesNotifier;
       
   117         }
       
   118 
       
   119     iBookmarkDb.Close();
       
   120     iSession.Close();
       
   121     delete iRetryTimer;
       
   122     }
       
   123 
    93 
   124 // ----------------------------------------------------------------------------
    94 // ----------------------------------------------------------------------------
   125 // CWPSaver::DoCancel
    95 // CWPSaver::DoCancel
   126 // ----------------------------------------------------------------------------
    96 // ----------------------------------------------------------------------------
   127 //
    97 //
   147         }
   117         }
   148     else
   118     else
   149         {
   119         {
   150         TRAP(err, QT_TRYCATCH_LEAVING( iEngine.SaveL( iCurrentItem ) )); 
   120         TRAP(err, QT_TRYCATCH_LEAVING( iEngine.SaveL( iCurrentItem ) )); 
   151         }
   121         }
   152     // If CommsDB or BookmarkDB are locked, schedule a retry
   122     if( err != KErrNone )
   153     if( err == EWPCommsDBLocked || err == KErrLocked)
       
   154         {
       
   155         iWaitCommsDb = ETrue;
       
   156         DelayedCompleteRequestL();
       
   157         return;
       
   158         }
       
   159     else if( err == EWPBookmarksLocked )
       
   160         {
       
   161         iWaitFavourites = ETrue;
       
   162         DelayedCompleteRequestL();
       
   163         return;
       
   164         }
       
   165     else if( err != KErrNone )
       
   166         {
   123         {
   167         // For all other errors, pass them through.
   124         // For all other errors, pass them through.
   168         iValue = iEngine.SummaryText(iCurrentItem);
   125         iValue = iEngine.SummaryText(iCurrentItem);
   169         delete iProgress;
   126         delete iProgress;
   170         iProgress = NULL;
   127         iProgress = NULL;
   203     iWait.AsyncStop();
   160     iWait.AsyncStop();
   204     return KErrNone;
   161     return KErrNone;
   205     }
   162     }
   206 
   163 
   207 // ----------------------------------------------------------------------------
   164 // ----------------------------------------------------------------------------
   208 // CWPSaver::DialogDismissedL
       
   209 // ----------------------------------------------------------------------------
       
   210 //
       
   211 void CWPSaver::DialogDismissedL( TInt aButtonId )
       
   212     {
       
   213     if( aButtonId < 0 )
       
   214         {
       
   215         iResult = KErrCancel;
       
   216         }
       
   217 
       
   218     iWait.AsyncStop();
       
   219     }
       
   220 
       
   221 // ----------------------------------------------------------------------------
       
   222 // CWPSaver::CompleteRequest
   165 // CWPSaver::CompleteRequest
   223 // ----------------------------------------------------------------------------
   166 // ----------------------------------------------------------------------------
   224 //
   167 //
   225 void CWPSaver::CompleteRequest()
   168 void CWPSaver::CompleteRequest()
   226     {
   169     {
   227     // Schedule an immediate complete. Make sure that there
   170     // Schedule an immediate complete. Make sure that there
   228     // is no timer alive first
   171     // is no timer alive first
   229     Cancel();
   172     Cancel();
   230     iRetryTimer->Cancel();
   173     //iRetryTimer->Cancel();
   231 
   174 
   232     SetActive();
   175     SetActive();
   233     TRequestStatus* sp = &iStatus;
   176     TRequestStatus* sp = &iStatus;
   234     User::RequestComplete( sp, KErrNone );
   177     User::RequestComplete( sp, KErrNone );
   235     }
   178     }
   236 
   179 
   237 // ----------------------------------------------------------------------------
       
   238 // CWPSaver::DelayedCompleteRequestL
       
   239 // ----------------------------------------------------------------------------
       
   240 //
       
   241 void CWPSaver::DelayedCompleteRequestL()
       
   242     {
       
   243     if( iRetryCount < KRetryCount )
       
   244         {
       
   245         // Schedule a delayed complete. Cancel first in case
       
   246         // an immediate request was scheduled.
       
   247         iRetryTimer->Cancel();
       
   248         iRetryTimer->Start( KMaxWaitTime, KMaxTInt32, TCallBack( Timeout, this ) );
       
   249         iRetryCount++;
       
   250         }
       
   251     else
       
   252         {
       
   253         User::Leave( KErrTimedOut );
       
   254         }
       
   255     }
       
   256 
       
   257 // ----------------------------------------------------------------------------
       
   258 // CWPSaver::Retry
       
   259 // ----------------------------------------------------------------------------
       
   260 //
       
   261 void CWPSaver::Retry()
       
   262     {
       
   263     // Immediate retry. Mark that we're not waiting
       
   264     // for an event and complete request.
       
   265     iWaitCommsDb = EFalse;
       
   266     iWaitFavourites = EFalse;
       
   267     CompleteRequest();
       
   268     }
       
   269 
       
   270 // ----------------------------------------------------------------------------
       
   271 // CWPSaver::Timeout
       
   272 // ----------------------------------------------------------------------------
       
   273 //
       
   274 TInt CWPSaver::Timeout(TAny* aSelf)
       
   275     {
       
   276     // There was a time-out. Retry saving even though we
       
   277     // didn't get a notify from database.
       
   278     CWPSaver* self = static_cast<CWPSaver*>( aSelf );
       
   279     self->Retry();
       
   280 
       
   281     return KErrNone;
       
   282     }
       
   283 
       
   284 // ----------------------------------------------------------------------------
       
   285 // CWPSaver::HandleApDbEventL
       
   286 // ----------------------------------------------------------------------------
       
   287 //
       
   288 void CWPSaver::HandleApDbEventL( TEvent aEvent )
       
   289     {
       
   290     // We received an event from CommsDB. Retry if we're
       
   291     // waiting for it.
       
   292     if( iWaitCommsDb && aEvent == EDbAvailable )
       
   293         {
       
   294         Retry();
       
   295         }
       
   296     }
       
   297 
       
   298 // ----------------------------------------------------------------------------
       
   299 // CWPSaver::HandleFavouritesDbEventL
       
   300 // ----------------------------------------------------------------------------
       
   301 //
       
   302 void CWPSaver::HandleFavouritesDbEventL( RDbNotifier::TEvent /*aEvent*/ )
       
   303     {
       
   304     // We received an event from BookmarkDB. Retry if we're
       
   305     // waiting for it.
       
   306     if( iWaitFavourites )
       
   307         {
       
   308         Retry();
       
   309         }
       
   310     }
       
   311 
       
   312 //  End of File