00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "GUIApp.h"
00023 #include <stdlib.h>
00024 #include <eikstart.h>
00025
00026 CExampleChecksumDialog::CExampleChecksumDialog(TDes* aFileName,TInt aTitleId)
00027 : iFileName(aFileName),iTitleId(aTitleId)
00028 {}
00029
00030 void CExampleChecksumDialog::PreLayoutDynInitL()
00031 {
00032 CEikFileNameSelector* fileNameSelector = (CEikFileNameSelector*)
00033 (Control(EEikCidFileNameSel));
00034 CEikFolderNameSelector* folderNameSelector = (CEikFolderNameSelector*)
00035 (Control(EEikCidFolderNameSel));
00036 CEikDriveNameSelector* driveNameSelector = (CEikDriveNameSelector*)
00037 (Control(EEikCidDriveNameSel));
00038 folderNameSelector->SetFileSelectionObserver(fileNameSelector);
00039 driveNameSelector->SetFileSelectionObserver(folderNameSelector);
00040 User::LeaveIfError(EikFileUtils::Parse(*iFileName));
00041 TParsePtr parse(*iFileName);
00042 driveNameSelector->SetFullNameL(parse.FullName());
00043 if (iTitleId)
00044 SetTitleL(iTitleId);
00045 }
00046
00047 TBool CExampleChecksumDialog::OkToExitL(TInt )
00048 {
00049 _LIT(KSpace," ");
00050
00051 CEikFileNameSelector* fileNameSelector = (CEikFileNameSelector*)
00052 (Control(EEikCidFileNameSel));
00053 fileNameSelector->ValidateStateL();
00054
00055 *iFileName = fileNameSelector->FullName();
00056
00057 TUint32 checksum, filesize;
00058 const TUint16* fn=iFileName->PtrZ();
00059 int fd = wopen((const wchar_t*)fn, O_RDONLY, 0);
00060 if (fd < 0)
00061
00062 {
00063 iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_ERROR,iFileName);
00064 return EFalse;
00065 }
00066 TInt err=crc(fd, &checksum, &filesize);
00067 if (err==0)
00068 {
00069
00070 iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_CKSUM,checksum);
00071
00072 TDes* fileNameAndCksum=iFileName;
00073
00074 fileNameAndCksum->Append(KSpace);
00075
00076 fileNameAndCksum->AppendNum(checksum,EDecimal);
00077 }
00078 else iEikonEnv->InfoMsg(R_EXAMPLE_TEXT_CKSUM_ERROR);
00079
00080 close(fd);
00081 return ETrue;
00082 }
00083
00084 CExampleListBoxDialog::CExampleListBoxDialog(CDesCArrayFlat* aCksumArray)
00085 : iCksumArray(aCksumArray)
00086 {
00087 }
00088
00089 void CExampleListBoxDialog::PreLayoutDynInitL()
00090 {
00091 CEikTextListBox* listbox=(CEikTextListBox*)Control(EExampleChecksumListBox);
00092 CDesCArray* listboxArray=((CDesCArray*)listbox->Model()->ItemTextArray());
00093 if (iCksumArray!=NULL)
00094 {
00095
00096 for (TInt i=0; i<iCksumArray->Count(); i++)
00097 listboxArray->AppendL(iCksumArray->operator[](i));
00098 }
00099 CEikScrollBarFrame* scrollbarFrame = listbox->CreateScrollBarFrameL();
00100
00101 scrollbarFrame->SetScrollBarVisibilityL(CEikScrollBarFrame::EAuto,
00102 CEikScrollBarFrame::EAuto);
00103 }
00104
00105 void CExampleListBoxDialog::SetSizeAndPositionL(const TSize& aSize)
00106 {
00107
00108 TSize dialogSize(((aSize.iWidth)*2), aSize.iHeight);
00109 SetCornerAndSize(EHCenterVCenter,dialogSize);
00110 }
00111
00112 TBool CExampleListBoxDialog::OkToExitL(TInt )
00113 {
00114 return(ETrue);
00115 }
00116
00117
00119
00120
00121
00123 CExampleContainer::CExampleContainer()
00124 {}
00125
00126
00127 CExampleContainer::~CExampleContainer()
00128 {
00129 delete iChecksumArray;
00130 }
00131
00132 void CExampleContainer::ConstructL(const TRect& aRect)
00133 {
00134
00135 CreateWindowL();
00136
00137
00138 iChecksumArray = new (ELeave) CDesCArrayFlat(3);
00139
00140
00141
00142 SetRect(aRect);
00143
00144
00145 ActivateL();
00146 }
00147
00148
00149 void CExampleContainer::Draw(const TRect&) const
00150 {
00151
00152 CWindowGc& gc=SystemGc();
00153 gc.SetPenStyle(CGraphicsContext::ENullPen);
00154 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
00155 gc.SetBrushColor(KRgbWhite);
00156 gc.DrawRect(Rect());
00157 }
00158
00159
00160 void CExampleContainer::AppendChecksumL(const TDesC& aFilename)
00161 {
00162
00163
00164 TInt pos;
00165 if (iChecksumArray->Find(aFilename,pos,ECmpNormal))
00166 {
00167 TRAPD(error,iChecksumArray->AppendL(aFilename));
00168 if (error)
00169 {
00170 iChecksumArray->Reset();
00171 delete iChecksumArray;
00172 iChecksumArray=0;
00173 User::Leave(error);
00174 }
00175 }
00176 }
00177
00178 CDesCArrayFlat* CExampleContainer::GetChecksumArray() const
00179 {
00180 return iChecksumArray;
00181 }
00182
00183 void CExampleContainer::HandleControlEventL(CCoeControl* ,
00184 TCoeEvent
00185 )
00186 {
00187 }
00188
00189
00191
00192
00193
00195 void CExampleAppUi::ConstructL()
00196 {
00197
00198
00199 iCoeEnv->DisableExitChecks(ETrue);
00200
00201
00202 BaseConstructL();
00203
00204
00205
00206
00207 iContainer = new(ELeave) CExampleContainer;
00208 iContainer->ConstructL(ClientRect());
00209
00210
00211
00212 AddToStackL(iContainer);
00213 }
00214
00215
00216 CExampleAppUi::~CExampleAppUi()
00217 {
00218 RemoveFromStack(iContainer);
00219
00220 delete iContainer;
00221 }
00222
00223 void CExampleAppUi::HandleCommandL(TInt aCommand)
00224 {
00225
00226
00227
00228
00229 switch (aCommand)
00230 {
00231 case EExampleCmdChecksum:
00232 OnCmdChecksumL();
00233 break;
00234 case EExampleCmdViewChecksums:
00235 OnCmdViewChecksumsL();
00236 break;
00237
00238 case EEikCmdExit:
00239 OnCmdExit();
00240 break;
00241 default :
00242 break;
00243 }
00244 }
00245
00246 void CExampleAppUi::OnCmdChecksumL()
00247 {
00248
00249
00250
00251 TDriveUnit sysDrive (RFs::GetSystemDrive());
00252 TDriveName sysDriveName (sysDrive.Name());
00253 _LIT(KM,"\\Documents\\");
00254 TBuf<KMaxFileName+KMaxChecksumLength> fileName(sysDriveName);
00255 fileName.Append(KM);
00256
00257 CEikDialog* dialog = new (ELeave) CExampleChecksumDialog(&fileName);
00258 if (dialog->ExecuteLD(R_EXAMPLE_CHECKSUM_DIALOG))
00259 {
00260
00261
00262 iContainer->AppendChecksumL(fileName);
00263 }
00264 }
00265
00266 void CExampleAppUi::OnCmdViewChecksumsL()
00267 {
00268 CEikDialog* dialog = new(ELeave) CExampleListBoxDialog
00269 (iContainer->GetChecksumArray());
00270 dialog->ExecuteLD(R_EXAMPLE_CHECKSUM_INFO_DIALOG);
00271 }
00272
00273 void CExampleAppUi::OnCmdExit()
00274 {
00275 CBaActiveScheduler::Exit();
00276 }
00277
00278 void CExampleAppUi::DrawViewL()
00279 {
00280 iContainer->SetRect(ClientRect());
00281 iContainer->DrawNow();
00282 }
00283
00285
00286
00287
00289 CExampleDocument::CExampleDocument(CEikApplication& aApp)
00290 : CEikDocument(aApp)
00291 {}
00292
00293 CExampleDocument::~CExampleDocument()
00294 {
00295
00296
00297
00298 CloseSTDLIB();
00299 }
00300
00301 CExampleDocument* CExampleDocument::NewL(CEikApplication& aApp)
00302 {
00303 CExampleDocument* self=new(ELeave) CExampleDocument(aApp);
00304 return self;
00305 }
00306
00307
00308 CEikAppUi* CExampleDocument::CreateAppUiL()
00309 {
00310 return(new(ELeave) CExampleAppUi);
00311 }
00312
00313
00315
00316
00317
00319 TUid CExampleApplication::AppDllUid() const
00320 {
00321 return(KUidCksumApp);
00322 }
00323
00324
00325 CApaDocument* CExampleApplication::CreateDocumentL()
00326 {
00327 return CExampleDocument::NewL(*this);
00328 }
00329
00330
00331
00332
00333
00334 EXPORT_C CApaApplication* NewApplication()
00335 {
00336 return(new CExampleApplication);
00337 }
00338
00339
00340 GLDEF_C TInt E32Main()
00341 {
00342 return EikStart::RunApplication(NewApplication);
00343 }
00344