S60 3rd Edition SDK for Symbian OS
Example Applications Guide

WebClientAppUI.cpp

00001 /*
00002 * ==============================================================================
00003 *  Name        : WebClientAppUI.cpp
00004 *  Part of     : WebClient
00005 *  Interface   : 
00006 *  Description : 
00007 *  Version     : 
00008 *
00009 *  Copyright (c) 2005-2006 Nokia Corporation.
00010 *  This material, including documentation and any related 
00011 *  computer programs, is protected by copyright controlled by 
00012 *  Nokia Corporation.
00013 * ==============================================================================
00014 */
00015 
00016 // INCLUDE FILES
00017 #include <avkon.hrh>
00018 #include <aknnotewrappers.h> 
00019 #include <eikmenup.h>
00020 #include <AknWaitDialog.h> 
00021 #include <WebClient.rsg>
00022 #include "WebClient.pan"
00023 #include "WebClientAppUi.h"
00024 #include "WebClientContainer.h"
00025 #include "WebClient.hrh"
00026 
00027 // ----------------------------------------------------------------------------
00028 // CWebClientAppUi::ConstructL()
00029 // Second phase construction.
00030 // ----------------------------------------------------------------------------
00031 //
00032 void CWebClientAppUi::ConstructL()
00033     {
00034     BaseConstructL( CAknAppUi::EAknEnableSkin );
00035 
00036     iContainer = CWebClientContainer::NewL( ClientRect() );
00037     iContainer->SetMopParent( this );
00038     AddToStackL( iContainer );
00039 
00040     iClient = CWebClientEngine::NewL( *iContainer );
00041     iClient->SetCallBack( this );
00042     iWaitDialog = NULL;
00043     }
00044 
00045 // ----------------------------------------------------------------------------
00046 // CWebClientAppUi::CWebClientAppUi()
00047 // First phase construction.
00048 // ----------------------------------------------------------------------------
00049 //
00050 CWebClientAppUi::CWebClientAppUi()
00051     {
00052     // no implementation required
00053     }
00054 
00055 // ----------------------------------------------------------------------------
00056 // CWebClientAppUi::~CWebClientAppUi()
00057 // Destructor.
00058 // ----------------------------------------------------------------------------
00059 //
00060 CWebClientAppUi::~CWebClientAppUi()
00061     {
00062     if ( iContainer )
00063         {
00064         RemoveFromStack( iContainer );
00065         delete iContainer;
00066         iContainer = NULL;
00067         }
00068     if ( iClient )
00069         {
00070         delete iClient;
00071         iClient = NULL;
00072         }
00073     if ( iWaitDialog )
00074         {
00075         iWaitDialog->ProcessFinishedL();    // deletes the dialog
00076         delete iWaitDialog;
00077         iWaitDialog = NULL;
00078         }
00079     }
00080 
00081 // ----------------------------------------------------------------------------
00082 // CWebClientAppUi::HandleCommandL()
00083 // Handles user commands.
00084 // ----------------------------------------------------------------------------
00085 //
00086 void CWebClientAppUi::HandleCommandL( TInt aCommand )
00087     {
00088     switch( aCommand )
00089         {
00090         case EEikCmdExit:
00091         case EAknSoftkeyExit:
00092             Exit();
00093             break;
00094         case EWebClientCmdReqUrl:
00095             HandleUrlRequestL();
00096             break;
00097         case EWebClientCmdHeader:
00098         case EWebClientCmdSource:
00099         case EWebClientCmdStatus:
00100             iContainer->HandleCommandL( aCommand );
00101             break;
00102         default:
00103             Panic( EClientUi );
00104             break;
00105         }
00106     }
00107 
00108 // -----------------------------------------------------------------------------
00109 //  Handles user command Request URL.
00110 //  Called from HandleCommandL()
00111 // -----------------------------------------------------------------------------
00112 //
00113 void CWebClientAppUi::HandleUrlRequestL()
00114     {
00115     // Issue HTTP get to engine; first cancel possible existing transaction
00116     iClient->CancelTransactionL();
00117 
00118     // URL Query
00119     TBuf<KPrefixedUriNameLength> uri;
00120     CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog( uri, 
00121         CAknQueryDialog::ENoTone );
00122 
00123     if ( dlg->ExecuteLD( R_WEBCLIENT_DIALOG_URL_QUERY )) 
00124         {
00125         // Insert prefix to URL (it must begin with "http://" or "https://")
00126         TBuf8<KPrefixedUriNameLength> uri8;
00127         uri.LowerCase();
00128         if(uri.Find( KHttpPrefix) == KErrNotFound
00129             && uri.Find( KHttpsPrefix ) == KErrNotFound )
00130             {
00131             // If the URL does not contain http or https, 
00132             // use the default, "http://"
00133             uri8.Append( KHttpPrefix8 );
00134             uri8.Append( uri );
00135             } else {
00136             uri8.Copy( uri );
00137             }
00138 
00139         // Set requested URL to label and clear application view
00140         uri.Copy(uri8);
00141         iContainer->ResetL( uri );
00142 
00143         // Start transaction
00144         iClient->IssueHTTPGetL( uri8 );
00145 
00146         // Create the waitdialog
00147         iWaitDialog = new ( ELeave )CAknWaitDialog(
00148             reinterpret_cast<CEikDialog**>( &iWaitDialog ), ETrue );
00149         // Set DialogDissmissed callback
00150         iWaitDialog->SetCallback( this ); 
00151         iWaitDialog->ExecuteLD( R_WEBCLIENT_DOWNLOAD_WAIT_NOTE );
00152         }
00153     } 
00154 
00155 // ----------------------------------------------------------------------------
00156 // CWebClientAppUi::HandleResourceChangeL(TInt AType)
00157 // Called by framework when layout is changed.
00158 // ----------------------------------------------------------------------------
00159 //
00160 void CWebClientAppUi::HandleResourceChangeL(TInt aType)
00161     {
00162     CAknAppUi::HandleResourceChangeL(aType);
00163     if ( aType == KEikDynamicLayoutVariantSwitch )
00164         {               
00165         iContainer->SetRect( ClientRect() );
00166         }
00167     }
00168 
00169 // -----------------------------------------------------------------------------
00170 //  Called by the framework when the application status pane
00171 //  size is changed.
00172 // -----------------------------------------------------------------------------
00173 //
00174 void CWebClientAppUi::HandleStatusPaneSizeChange()
00175     {
00176     // no implementation required
00177     } 
00178 
00179 // ----------------------------------------------------------------------------
00180 // CWebClientAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
00181 // Takes care of key event handling
00182 // ----------------------------------------------------------------------------
00183 //
00184 TKeyResponse CWebClientAppUi::HandleKeyEventL( const TKeyEvent& /*aKeyEvent*/,
00185                                                TEventCode /*aType*/ )
00186     {
00187     return EKeyWasNotConsumed;
00188     }
00189 
00190 // ----------------------------------------------------------------------------
00191 // CWebClientAppUi::DialogDismissedL( TInt aButtonId )
00192 // Is called when a dialog is dismissed.
00193 // ----------------------------------------------------------------------------
00194 //
00195 void CWebClientAppUi::DialogDismissedL( TInt aButtonId )
00196     {
00197     if ( aButtonId == EAknSoftkeyCancel )
00198         {
00199         // Cancel current transaction
00200         if ( iClient->IsRunning() )
00201             {
00202             iClient->CancelTransactionL();
00203             }
00204         }
00205     }
00206 
00207 // ----------------------------------------------------------------------------
00208 // CWebClientAppUi::RemoveWaitDialogL()
00209 // Called by CWebClientEngine when Http transaction is finished.
00210 // ----------------------------------------------------------------------------
00211 //
00212 void CWebClientAppUi::RemoveWaitDialogL()
00213     {
00214     if ( iWaitDialog )
00215         {
00216         iWaitDialog->ProcessFinishedL();    // deletes the dialog
00217         }
00218     }

© Nokia 2006

Back to top