locationsystemui/locationsysui/locverifier/src/lpdquerylauncherbase.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     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:  Abstract base class for queries.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <locverifierdlg.rsg>
       
    21 #include <StringLoader.h>
       
    22 
       
    23 #include "locverifierdlg.hrh"
       
    24 #include "lpdquerylauncherbase.h"
       
    25 #include "lpdresulthandler.h"
       
    26 #include "locconsts.h"
       
    27 #include "lpdglobalplugindialog.h"
       
    28 #include "lpdmessageplugindialog.h"
       
    29 #include "lpdperiodicprocessor.h"
       
    30 
       
    31 
       
    32 // CONSTANTS
       
    33 
       
    34 // Unnamed namespace for local definitions
       
    35 
       
    36 const TUint KSelectionArrayGranularity = 5;
       
    37 const TInt KVerDlgTimeout = 900000000; // == 15 minutes
       
    38 
       
    39 #ifdef _DEBUG
       
    40 _LIT( KPanicText, "CLpdQueryLauncherBase" );
       
    41 enum TPanicCode
       
    42     {
       
    43     KLpdErrGeneral = 1
       
    44     };
       
    45 #endif
       
    46 
       
    47 // INCLUDE FILES
       
    48 #include <s32mem.h>
       
    49 #include <AknMediatorFacade.h>
       
    50 #include "locverifiercoverui.h"
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CLpdQueryLauncherBase::CLpdQueryLauncherBase
       
    56 // C++ default constructor can NOT contain any code, that
       
    57 // might leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 CLpdQueryLauncherBase::CLpdQueryLauncherBase( MLpdResultHandler& aHandler )
       
    61     : iHandler( aHandler ),
       
    62       iResult( KErrArgument ),
       
    63       iCurrentIndex( -1 ),
       
    64       iExitReason( KErrNone ),
       
    65       iOwnsQueryDlg( EFalse ),
       
    66       iOwnsMsgQueryDlg( EFalse )   
       
    67     {
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CLpdQueryLauncherBase::BaseConstructL
       
    72 // Symbian 2nd phase constructor can leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void CLpdQueryLauncherBase::BaseConstructL()
       
    76     {
       
    77     // In current implementation timer is not used. If needed, take timer 
       
    78     // into use by uncommenting the following line:
       
    79     // iTimer = CPeriodic::NewL( CActive::EPriorityStandard )
       
    80     }
       
    81 
       
    82 // Destructor
       
    83 CLpdQueryLauncherBase::~CLpdQueryLauncherBase()
       
    84     {
       
    85     // This does cleanup nicely even if dialog was not running:
       
    86     ExitQuery( EFalse ); // no callback from dialog anymore
       
    87     delete iTimer; // ok even if timer is NULL 
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CLpdQueryLauncherBase::PrepareQueryResourcesL
       
    92 // (other items were commented in a header).
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void CLpdQueryLauncherBase::PrepareQueryResourcesL( TInt aResourceId, TInt aSuplNotifRequest)
       
    96     {
       
    97     
       
    98     if( aSuplNotifRequest )
       
    99         {
       
   100         // Cancel deletes dialog resources:
       
   101         Cancel();    
       
   102        __ASSERT_DEBUG( !iMsgQueryDlg,
       
   103                     User::Panic( KPanicText, KLpdErrGeneral ) );
       
   104   
       
   105         iMsgQueryDlg = CLpdMessagePluginDialog::NewL( *this, &iMsgQueryDlg );
       
   106         iMsgQueryDlg->PrepareLC(aResourceId);    
       
   107         CleanupStack::Pop(iMsgQueryDlg); //iMsgQueryDlg, must be pushed back when launching
       
   108         iOwnsMsgQueryDlg = ETrue; 
       
   109  
       
   110         }
       
   111     else
       
   112         {
       
   113        // Cancel deletes dialog resources:
       
   114        Cancel();    
       
   115      __ASSERT_DEBUG( !iSelectionIndex && !iQueryDlg,
       
   116                     User::Panic( KPanicText, KLpdErrGeneral ) );
       
   117         iSelectionIndex =
       
   118             new( ELeave ) CArrayFixFlat<TInt>( KSelectionArrayGranularity );
       
   119         iQueryDlg = CLpdGlobalPluginDialog::NewL( *this, &iQueryDlg, iSelectionIndex );
       
   120         iQueryDlg->PrepareLC( aResourceId );
       
   121         CleanupStack::Pop(iQueryDlg); //iQueryDlg, must be pushed back when launching
       
   122         iOwnsQueryDlg = ETrue; 
       
   123             
       
   124         }
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CLpdQueryLauncherBase::SetQueryTextArray
       
   129 // (other items were commented in a header).
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 void CLpdQueryLauncherBase::SetQueryTextArray( MDesCArray* aArray )
       
   133     {
       
   134     __ASSERT_DEBUG( iQueryDlg, User::Panic( KPanicText, KLpdErrGeneral ) );
       
   135     iQueryDlg->SetItemTextArray( aArray );
       
   136     // ownership of array is transferred:
       
   137     iQueryDlg->SetOwnershipType( ELbmOwnsItemArray );
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // CLpdQueryLauncherBase::SetMessageQueryTextL
       
   142 // (other items were commented in a header).
       
   143 // -----------------------------------------------------------------------------
       
   144 //
       
   145 void CLpdQueryLauncherBase::SetMessageQueryTextL( const TDesC& aString, TCallBack aCallBack )
       
   146     {
       
   147     __ASSERT_DEBUG( iMsgQueryDlg, User::Panic( KPanicText, KLpdErrGeneral ) );
       
   148     
       
   149     HBufC* dialogTitle = NULL;
       
   150     // set title text
       
   151     dialogTitle = StringLoader::LoadLC( R_LOC_SUPL_PERIODIC_DIALOG_TITLE );  
       
   152     iMsgQueryDlg->QueryHeading()->SetTextL( *dialogTitle ); 
       
   153     // set message text                  
       
   154 	  iMsgQueryDlg->SetMessageTextL( aString );
       
   155 	  iMsgQueryDlg->SetLink( aCallBack );
       
   156 	
       
   157 	  CleanupStack::PopAndDestroy( dialogTitle );
       
   158     }
       
   159     
       
   160 // -----------------------------------------------------------------------------
       
   161 // CLpdQueryLauncherBase::StartQueryL
       
   162 // (other items were commented in a header).
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 void CLpdQueryLauncherBase::StartQueryL()
       
   166     {
       
   167     User::LeaveIfNull( iQueryDlg );
       
   168 
       
   169     iExitReason = KErrNone;
       
   170     
       
   171     CLpdGlobalPluginDialog* queryDialog = iQueryDlg;
       
   172     
       
   173     // Publish the dialog to Cover UI  
       
   174     PublishDialogtoCoverL();
       
   175        
       
   176     CleanupStack::PushL( queryDialog ); // RunLD() requires this
       
   177     iOwnsQueryDlg = EFalse; // ownership transferred to RunLD
       
   178     queryDialog->RunLD();
       
   179 
       
   180     if ( iTimer )
       
   181         {
       
   182         TCallBack callback( HandleTimeoutCallback, this );
       
   183         TTimeIntervalMicroSeconds32 timeout( KVerDlgTimeout );
       
   184         // This timer will not expire periodically, so the second
       
   185         // parameter is not so important in this case.
       
   186         
       
   187 		    iTimer->Cancel();
       
   188         iTimer->Start( timeout, timeout, callback );
       
   189         }
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // CLpdQueryLauncherBase::StartSuplPeriodicQueryL
       
   194 // (other items were commented in a header).
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CLpdQueryLauncherBase::StartSuplPeriodicQueryL()
       
   198     {
       
   199     User::LeaveIfNull( iMsgQueryDlg );
       
   200     
       
   201     iExitReason = KErrNone;
       
   202     CLpdMessagePluginDialog* queryDialog = iMsgQueryDlg;
       
   203     
       
   204     // Publish the dialog to Cover UI  
       
   205     PublishDialogtoCoverL();
       
   206        
       
   207     CleanupStack::PushL( queryDialog ); // RunLD() requires this
       
   208     iOwnsMsgQueryDlg = EFalse; // ownership transferred to RunLD
       
   209     queryDialog->RunLD();
       
   210     
       
   211     if ( iTimer )
       
   212         {
       
   213         TCallBack callback( HandleTimeoutCallback, this );
       
   214         TTimeIntervalMicroSeconds32 timeout( KVerDlgTimeout );
       
   215         // This timer will not expire periodically, so the second
       
   216         // parameter is not so important in this case.
       
   217         
       
   218         iTimer->Cancel();
       
   219         iTimer->Start( timeout, timeout, callback );
       
   220         }
       
   221          
       
   222     }
       
   223 
       
   224 // -----------------------------------------------------------------------------
       
   225 // CLpdQueryLauncherBase::SelectionIndexes
       
   226 // (other items were commented in a header).
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 const CListBoxView::CSelectionIndexArray* CLpdQueryLauncherBase::SelectionIndexes() const
       
   230     {
       
   231     return iSelectionIndex;
       
   232     }
       
   233 
       
   234 // -----------------------------------------------------------------------------
       
   235 // CLpdQueryLauncherBase::HandleTimeoutCallback
       
   236 // (other items were commented in a header).
       
   237 // -----------------------------------------------------------------------------
       
   238 //
       
   239 TInt CLpdQueryLauncherBase::HandleTimeoutCallback( TAny* aThis )
       
   240     {
       
   241 	  static_cast<CLpdQueryLauncherBase*>( aThis )->HandleTimeout();
       
   242     return KErrNone; // Return value is unimportant in this case
       
   243     }
       
   244 
       
   245 // -----------------------------------------------------------------------------
       
   246 // CLpdQueryLauncherBase::Cancel
       
   247 // (other items were commented in a header).
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 void CLpdQueryLauncherBase::Cancel()
       
   251     {
       
   252     iExitReason = KErrCancel;
       
   253     ExitQuery( ETrue );
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CLpdQueryLauncherBase::CancelQuietly
       
   258 // (other items were commented in a header).
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 void CLpdQueryLauncherBase::CancelQuietly()
       
   262     {
       
   263     iExitReason = KErrCancel;
       
   264     ExitQuery( EFalse );
       
   265     }
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CLpdQueryLauncherBase::ListBoxL
       
   269 // (other items were commented in a header).
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 CEikFormattedCellListBox& CLpdQueryLauncherBase::ListBoxL()
       
   273     {
       
   274 	__ASSERT_DEBUG( iQueryDlg, User::Panic( KPanicText, KLpdErrGeneral ) );
       
   275     CEikFormattedCellListBox* listbox = iQueryDlg->ListControl()->Listbox();
       
   276     User::LeaveIfNull( listbox );
       
   277 	  return *listbox;    
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CLpdQueryLauncherBase::SetRequestorBuffer
       
   282 // Sets the requestor buffer array that needs to be published to
       
   283 // Cover UI
       
   284 // @param aRequestorBuffer Flat buffer containing the list of requestors
       
   285 // -----------------------------------------------------------------------------
       
   286 //
       
   287 void CLpdQueryLauncherBase::SetRequestorBuffer( TDes8&     aRequestorBuffer )
       
   288     {
       
   289     iRequestorBuffer.Set( aRequestorBuffer);
       
   290     }
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 // CLpdQueryLauncherBase::SetCoverUICommand
       
   294 // Sets the Cover UI Command ID
       
   295 // @param aCommandId Cover UI Command
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 void CLpdQueryLauncherBase::SetCoverUICommand( TInt        aCommand )
       
   299     {
       
   300     iCoverUiCommand = aCommand;
       
   301     }
       
   302 
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // CLpdQueryLauncherBase::HandleDlgDismissedL
       
   306 // (other items were commented in a header).
       
   307 // -----------------------------------------------------------------------------
       
   308 //
       
   309 void CLpdQueryLauncherBase::HandleDlgDismissedL(    
       
   310     TInt aResult,
       
   311     TInt aCurrentIndex )
       
   312     {
       
   313     // ExtendedHandleDlgDismissedL() implementation probably
       
   314     // makes a callback to the observer of this class, which
       
   315     // might delete this object. Therefore it is important
       
   316     // that members are carefully used.
       
   317 
       
   318     if ( iTimer )
       
   319         {
       
   320         iTimer->Cancel();
       
   321         }
       
   322 
       
   323     iResult = aResult;
       
   324     iCurrentIndex = aCurrentIndex;
       
   325     
       
   326     if(iQueryDlg)
       
   327     {
       
   328     // Cancel the dialog from secondary
       
   329     CAknMediatorFacade* covercl = AknMediatorFacade(iQueryDlg);
       
   330     if( covercl )
       
   331       {
       
   332       covercl->CancelCommand();
       
   333       }
       
   334     }
       
   335     if(iMsgQueryDlg)
       
   336     {
       
   337       // Cancel the dialog from secondary
       
   338     CAknMediatorFacade* coverclmsg = AknMediatorFacade(iMsgQueryDlg);
       
   339     if( coverclmsg )
       
   340         {
       
   341         coverclmsg->CancelCommand();
       
   342         }
       
   343     }
       
   344     // iQueryDlg, which will delete itself, is becoming invalid now
       
   345     iQueryDlg = NULL;
       
   346     iMsgQueryDlg = NULL;
       
   347     TRAPD( err, ExtendedHandleDlgDismissedL() );
       
   348          if ( err )
       
   349              { // Leave occurred in dialog result processing, we must let
       
   350                // plugin handle the situation instead of propagating error to
       
   351                // AVKON, which would mean that dialog would not be exited and
       
   352                // user could alter his decision --> risk of conflicts.
       
   353              iHandler.HandleLeave( err );
       
   354              }
       
   355       
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CLpdQueryLauncherBase::HandleTimeout
       
   360 // (other items were commented in a header).
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 void CLpdQueryLauncherBase::HandleTimeout()
       
   364     {
       
   365     iExitReason = KErrTimedOut;
       
   366     ExitQuery( ETrue );
       
   367     }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // CLpdQueryLauncherBase::ExitQuery
       
   371 // (other items were commented in a header).
       
   372 // -----------------------------------------------------------------------------
       
   373 //
       
   374 void CLpdQueryLauncherBase::ExitQuery( TBool aCallback )
       
   375     {
       
   376     if ( iTimer )
       
   377         {
       
   378         iTimer->Cancel();
       
   379         }
       
   380     if ( iQueryDlg )
       
   381         {
       
   382         if ( iOwnsQueryDlg )
       
   383             { // Dialog not running yet --> must be explicitely deleted
       
   384             delete iQueryDlg;
       
   385             }
       
   386         else
       
   387             { // Dialog running --> exit
       
   388             TInt err = KErrNone;
       
   389             if ( aCallback )
       
   390                 {
       
   391                 TRAP( err, iQueryDlg->ExitDialogL() );
       
   392                 }
       
   393             else
       
   394                 {
       
   395                 TRAP( err, iQueryDlg->ExitDialogQuietlyL() );
       
   396                 }
       
   397             if ( err )
       
   398                 {
       
   399                 CEikonEnv::Static()->HandleError( err );
       
   400                 }
       
   401             }
       
   402         iQueryDlg = NULL;
       
   403         }
       
   404     if ( iMsgQueryDlg )
       
   405         {
       
   406         if ( iOwnsQueryDlg )
       
   407             { // Dialog not running yet --> must be explicitely deleted
       
   408             delete iMsgQueryDlg;
       
   409             }
       
   410         else
       
   411             { // Dialog running --> exit
       
   412             TInt err = KErrNone;
       
   413             if ( aCallback )
       
   414                 {
       
   415                 TRAP( err, iMsgQueryDlg->ExitDialogL() );
       
   416                 }
       
   417             else
       
   418                 {
       
   419                 TRAP( err, iMsgQueryDlg->ExitDialogQuietlyL() );
       
   420                 }
       
   421             if ( err )
       
   422                 {
       
   423                 CEikonEnv::Static()->HandleError( err );
       
   424                 }
       
   425             }
       
   426         iMsgQueryDlg = NULL;
       
   427         }
       
   428         iResult = KErrArgument;
       
   429         iCurrentIndex = -1;
       
   430         if( iSelectionIndex )
       
   431            {
       
   432            delete iSelectionIndex;
       
   433            iSelectionIndex = NULL;
       
   434            }
       
   435  }
       
   436 
       
   437 // -----------------------------------------------------------------------------
       
   438 // CLpdQueryLauncherBase::PublishDialogtoCoverL
       
   439 // Prepare the requestor buffers and Publish the dialog to the 
       
   440 // Cover UI
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 void CLpdQueryLauncherBase::PublishDialogtoCoverL()
       
   444     {
       
   445     
       
   446     CAknMediatorFacade* covercl = NULL;
       
   447 	if( iQueryDlg )
       
   448 		{
       
   449 	    // Publish the Dialog to Cover UI
       
   450 	    iQueryDlg->PublishDialogL( iCoverUiCommand, KCatUidLocationVerifierDlgs );
       
   451 		
       
   452    		// Send the requestor buffer to the Cover UI
       
   453 		covercl = AknMediatorFacade( iQueryDlg );
       
   454 		}
       
   455 	else if( iMsgQueryDlg )
       
   456 		{
       
   457 	    // Publish the Dialog to Cover UI
       
   458 	    iMsgQueryDlg->PublishDialogL( iCoverUiCommand, KCatUidLocationVerifierDlgs );
       
   459 		
       
   460    		// Send the requestor buffer to the Cover UI
       
   461 		covercl = AknMediatorFacade( iMsgQueryDlg );
       
   462 		}
       
   463 		
       
   464     if (covercl)
       
   465         {
       
   466         RBufWriteStream& writeStream = covercl->BufStream();
       
   467         
       
   468         TUint8* ptr = const_cast<TUint8 *>(iRequestorBuffer.Ptr());
       
   469         writeStream.WriteL( ptr, iRequestorBuffer.Length());
       
   470         writeStream.CommitL();
       
   471         }
       
   472     }
       
   473 
       
   474 //  End of File