00001 /* 00002 * Copyright (c) 2009 Nokia Corporation. 00003 */ 00004 00005 #include <avkon.hrh> 00006 #include <hlplch.h> 00007 #include <eikmenup.h> 00008 00009 #include <HTTPClientExample.rsg> 00010 #include "Client.pan" 00011 #include "ClientAppUi.h" 00012 #include "ClientAppView.h" 00013 #include "ClientApplication.h" 00014 #include "Client.hrh" 00015 #include "HTTPClientExample_sc.hlp.hrh" 00016 00017 // Schemes for given uris 00018 _LIT(KHttpPrefix, "http://"); 00019 _LIT8(KHttpPrefix8, "http://"); 00020 00021 // HTTPS schemes 00022 _LIT(KHttpsPrefix, "https://"); 00023 _LIT8(KHttpsPrefix8, "https://"); 00024 00025 _LIT8(KMimeType, "text/plain"); 00026 00027 // ---------------------------------------------------------------------------- 00028 // CClientAppUi::ConstructL() 00029 // 00030 // Second phase construction. 00031 // ---------------------------------------------------------------------------- 00032 void CClientAppUi::ConstructL() 00033 { 00034 BaseConstructL(EAknEnableSkin); 00035 00036 iAppView = CClientAppView::NewL(ClientRect()); 00037 AddToStackL(iAppView); 00038 00039 iEngine = CClientEngine::NewL(*iAppView); 00040 } 00041 00042 // ---------------------------------------------------------------------------- 00043 // CClientAppUi::CClientAppUi() 00044 // 00045 // First phase construction. 00046 // ---------------------------------------------------------------------------- 00047 CClientAppUi::CClientAppUi() 00048 { 00049 } 00050 00051 // ---------------------------------------------------------------------------- 00052 // CClientAppUi::~CClientAppUi() 00053 // 00054 // Destructor. 00055 // ---------------------------------------------------------------------------- 00056 CClientAppUi::~CClientAppUi() 00057 { 00058 delete iEngine; 00059 if (iAppView) 00060 { 00061 iEikonEnv->RemoveFromStack(iAppView); 00062 delete iAppView; 00063 } 00064 } 00065 00066 // ---------------------------------------------------------------------------- 00067 // CClientAppUi::HandleCommandL() 00068 // 00069 // Handles user commands. 00070 // ---------------------------------------------------------------------------- 00071 void CClientAppUi::HandleCommandL(TInt aCommand) 00072 { 00073 switch(aCommand) 00074 { 00075 case EEikCmdExit: 00076 case EAknSoftkeyExit: 00077 Exit(); 00078 break; 00079 00080 case EClientGet: 00081 { 00082 // Issue HTTP get to engine; first cancel possible existing transaction 00083 iEngine->CancelTransaction(); 00084 00085 // Query uri 00086 TBuf<KDefaultBufferSize> uri; 00087 CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(uri, 00088 CAknQueryDialog::ENoTone); 00089 00090 if (! dlg->ExecuteLD(R_DIALOG_URI_QUERY)) 00091 break; 00092 00093 iAppView->ResetL(); 00094 00095 // Insert prefix to uri (it must begin with "http://" or "https://") 00096 TBuf8<KDefaultBufferSize> uri8; 00097 uri.LowerCase(); 00098 if(uri.Find(KHttpPrefix) == KErrNotFound 00099 && uri.Find(KHttpsPrefix) == KErrNotFound) 00100 { 00101 // If the uri does not contain http or https, 00102 // use the default, "http://" 00103 uri8.Append(KHttpPrefix8); 00104 uri8.Append(uri); 00105 } 00106 else 00107 { 00108 uri8.Copy(uri); 00109 } 00110 00111 // Start transaction 00112 // TODO: 00113 TRAPD(err, iEngine->IssueHTTPGetL(uri8)); 00114 } 00115 break; 00116 00117 case EClientPost: 00118 { 00119 // Issue HTTP post to engine; first cancel possible existing transaction 00120 iEngine->CancelTransaction(); 00121 00122 // Query uri and data to post 00123 TBuf<KDefaultBufferSize> uri; 00124 TBuf<KDefaultBufferSize> postData; 00125 CAknMultiLineDataQueryDialog* dlg = 00126 CAknMultiLineDataQueryDialog::NewL(uri, postData); 00127 00128 if (!dlg->ExecuteLD(R_DIALOG_URI_POST_QUERY)) 00129 break; 00130 00131 iAppView->ResetL(); 00132 00133 // Insert prefix to uri (it must begin with "http://" or "https://") 00134 TBuf8<KDefaultBufferSize> uri8; 00135 uri.LowerCase(); 00136 if(uri.Find(KHttpPrefix) == KErrNotFound 00137 && uri.Find(KHttpsPrefix) == KErrNotFound) 00138 { 00139 // If uri does not contain http or https, 00140 // use the default, "http://" 00141 uri8.Append(KHttpPrefix8); 00142 uri8.Append(uri); 00143 } 00144 else 00145 { 00146 uri8.Copy(uri); 00147 } 00148 00149 TBuf8<KDefaultBufferSize> postData8; 00150 postData8.Copy(postData); 00151 00152 // Start transaction 00153 TRAPD(err, iEngine->IssueHTTPPostL(uri8, KMimeType, postData8)); 00154 // TODO: Error handling 00155 if (err) 00156 { 00157 } 00158 } 00159 break; 00160 00161 case EClientCancel: 00162 { 00163 // Cancel current transaction 00164 iEngine->CancelTransaction(); 00165 } 00166 break; 00167 00168 // Switch focus to the other rich text editor 00169 case EClientSwitchFocus: 00170 { 00171 iAppView->SwitchFocus(); 00172 } 00173 break; 00174 00175 case EClientHelp: 00176 { 00177 CArrayFix <TCoeHelpContext>* buf = CCoeAppUi::AppHelpContextL(); 00178 HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(), buf ); 00179 } 00180 break; 00181 00182 case EClientAbout: 00183 { 00184 HBufC* title = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TITLE); 00185 HBufC* msg = iEikonEnv->AllocReadResourceLC(R_ABOUT_DIALOG_TEXT); 00186 00187 // Note: CodeScanner gives a false positive of "Neglected to put 00188 // variable on cleanup stack (Id: 35)" on dlg. 00189 CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL(*msg); // CSI: 35 # 00190 dlg->PrepareLC(R_DIALOG_ABOUT); 00191 dlg->SetHeaderTextL(*title); 00192 dlg->RunLD(); 00193 00194 CleanupStack::PopAndDestroy(msg); 00195 CleanupStack::PopAndDestroy(title); 00196 } 00197 break; 00198 00199 default: 00200 { 00201 Panic(EClientUi); 00202 } 00203 break; 00204 } 00205 } 00206 00207 // ----------------------------------------------------------------------------- 00208 // CClientAppUi::HelpContextL() 00209 // 00210 // Return the help context for this application. 00211 // ----------------------------------------------------------------------------- 00212 CArrayFix <TCoeHelpContext>* CClientAppUi::HelpContextL() const 00213 { 00214 CArrayFixFlat <TCoeHelpContext>* array = new (ELeave)CArrayFixFlat <TCoeHelpContext>(1); 00215 CleanupStack::PushL(array); 00216 array->AppendL(TCoeHelpContext(KUidHelpFile, KContextApplication)); 00217 CleanupStack::Pop(array); 00218 return array; 00219 } 00220 00221 // ---------------------------------------------------------------------------- 00222 // CClientAppUi::DynInitMenuPaneL() 00223 // 00224 // Initializes the menu pane when it's activated. 00225 // ---------------------------------------------------------------------------- 00226 void CClientAppUi::DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane) 00227 { 00228 // "Cancel" selection is only available when trasaction running in engine 00229 if (aMenuId == R_EXAMPLECLIENT_MENU) 00230 aMenuPane->SetItemDimmed(EClientCancel, !iEngine->IsRunning()); 00231 } 00232 00233 // end of file
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.