Nokia N97 SDK
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-2007 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             break;
00104         }
00105     }
00106 
00107 // -----------------------------------------------------------------------------
00108 //  Handles user command Request URL.
00109 //  Called from HandleCommandL()
00110 // -----------------------------------------------------------------------------
00111 //
00112 void CWebClientAppUi::HandleUrlRequestL()
00113     {
00114     // Issue HTTP get to engine; first cancel possible existing transaction
00115     iClient->CancelTransactionL();
00116 
00117     // URL Query
00118     TBuf<KPrefixedUriNameLength> uri;
00119     CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog( uri, 
00120         CAknQueryDialog::ENoTone );
00121 
00122     if ( dlg->ExecuteLD( R_WEBCLIENT_DIALOG_URL_QUERY )) 
00123         {
00124         // Insert prefix to URL (it must begin with "http://" or "https://")
00125         TBuf8<KPrefixedUriNameLength> uri8;
00126         uri.LowerCase();
00127         if(uri.Find( KHttpPrefix) == KErrNotFound
00128             && uri.Find( KHttpsPrefix ) == KErrNotFound )
00129             {
00130             // If the URL does not contain http or https, 
00131             // use the default, "http://"
00132             uri8.Append( KHttpPrefix8 );
00133             uri8.Append( uri );
00134             } else {
00135             uri8.Copy( uri );
00136             }
00137 
00138         // Set requested URL to label and clear application view
00139         uri.Copy(uri8);
00140         iContainer->ResetL( uri );
00141 
00142         // Start transaction
00143         iClient->IssueHTTPGetL( uri8 );
00144 
00145         // Create the waitdialog
00146         iWaitDialog = new ( ELeave )CAknWaitDialog(
00147             reinterpret_cast<CEikDialog**>( &iWaitDialog ), ETrue );
00148         // Set DialogDissmissed callback
00149         iWaitDialog->SetCallback( this ); 
00150         iWaitDialog->ExecuteLD( R_WEBCLIENT_DOWNLOAD_WAIT_NOTE );
00151         }
00152     } 
00153 
00154 // ----------------------------------------------------------------------------
00155 // CWebClientAppUi::HandleResourceChangeL(TInt AType)
00156 // Called by framework when layout is changed.
00157 // ----------------------------------------------------------------------------
00158 //
00159 void CWebClientAppUi::HandleResourceChangeL(TInt aType)
00160     {
00161     CAknAppUi::HandleResourceChangeL(aType);
00162     if ( aType == KEikDynamicLayoutVariantSwitch )
00163         {               
00164         iContainer->SetRect( ClientRect() );
00165         }
00166     }
00167 
00168 // -----------------------------------------------------------------------------
00169 //  Called by the framework when the application status pane
00170 //  size is changed.
00171 // -----------------------------------------------------------------------------
00172 //
00173 void CWebClientAppUi::HandleStatusPaneSizeChange()
00174     {
00175     // no implementation required
00176     } 
00177 
00178 // ----------------------------------------------------------------------------
00179 // CWebClientAppUi::HandleKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
00180 // Takes care of key event handling
00181 // ----------------------------------------------------------------------------
00182 //
00183 TKeyResponse CWebClientAppUi::HandleKeyEventL( const TKeyEvent& /*aKeyEvent*/,
00184                                                TEventCode /*aType*/ )
00185     {
00186     return EKeyWasNotConsumed;
00187     }
00188 
00189 // ----------------------------------------------------------------------------
00190 // CWebClientAppUi::DialogDismissedL( TInt aButtonId )
00191 // Is called when a dialog is dismissed.
00192 // ----------------------------------------------------------------------------
00193 //
00194 void CWebClientAppUi::DialogDismissedL( TInt aButtonId )
00195     {
00196     if ( aButtonId == EAknSoftkeyCancel )
00197         {
00198         // Cancel current transaction
00199         if ( iClient->IsRunning() )
00200             {
00201             iClient->CancelTransactionL();
00202             }
00203         }
00204     }
00205 
00206 // ----------------------------------------------------------------------------
00207 // CWebClientAppUi::RemoveWaitDialogL()
00208 // Called by CWebClientEngine when Http transaction is finished.
00209 // ----------------------------------------------------------------------------
00210 //
00211 void CWebClientAppUi::RemoveWaitDialogL()
00212     {
00213     if ( iWaitDialog )
00214         {
00215         iWaitDialog->ProcessFinishedL();    // deletes the dialog
00216         }
00217     }

© Nokia 2009

Back to top