examples/ForumNokia/Document_Handler_Example/HandlerApp/src/handlerDocument.cpp

00001 /* ====================================================================
00002  * File: handlerDocument.cpp
00003  * Created: 09/27/05
00004  * Author:
00005  * Copyright (c): , All rights reserved
00006  * ==================================================================== */
00007 
00008 #include "handlerAppUi.h"
00009 #include "handlerDocument.h"
00010 #include "Common.h"
00011 
00012 #include <f32file.h>
00013 #include <eikenv.h>
00014 #include <eikappui.h>
00015 #include <eikapp.h>
00016 #include <apparc.h>
00017 #include <eikproc.H>
00018 #include <apgwgnam.h> //Link against: apgrfx.lib
00019 #include <avkon.hrh>
00020 #include <aknnotewrappers.h>
00021 
00022 CHandlerDocument* CHandlerDocument::NewL(CEikApplication& aApp)
00023     {
00024     CHandlerDocument* self = NewLC(aApp);
00025     CleanupStack::Pop(self);
00026     return self;
00027     }
00028 
00029 CHandlerDocument* CHandlerDocument::NewLC(CEikApplication& aApp)
00030     {
00031     CHandlerDocument* self = new (ELeave) CHandlerDocument(aApp);
00032     CleanupStack::PushL(self);
00033     self->ConstructL();
00034     return self;
00035     }
00036 
00037 void CHandlerDocument::ConstructL()
00038     {
00039     // no implementation required
00040     }
00041 
00042 CHandlerDocument::CHandlerDocument(CEikApplication& aApp) : CAknDocument(aApp)
00043     {
00044     // no implementation required
00045     }
00046 
00047 CHandlerDocument::~CHandlerDocument()
00048     {
00049     // no implementation required
00050     }
00051 
00052 CEikAppUi* CHandlerDocument::CreateAppUiL()
00053     {
00054     // Create the application user interface, and return a pointer to it,
00055     // the framework takes ownership of this object
00056     iAppUi = new (ELeave) CHandlerAppUi;
00057     return iAppUi;
00058     }
00059 
00060 CFileStore* CHandlerDocument::OpenFileL( TBool aDoOpen, const TDesC& aFilename, RFs& aFs )
00061     {
00062     if (aDoOpen)
00063         {
00064         TFileName name = aFilename;
00065         if( iFileName == name ) //The same file, do nothing
00066             {
00067             return NULL;   
00068             }
00069         iFileName = name;
00070         CHandlerAppUi *appui = static_cast<CHandlerAppUi *> (iAppUi);
00071         TBuf8<KTextLengthToRead> buf;
00072 
00073         RFile file;
00074         
00075         TInt err = file.Open(aFs, aFilename, EFileRead|EFileShareAny); 
00076         if( err == KErrNone )
00077             {
00078             CleanupClosePushL(file);
00079             User::LeaveIfError( file.Read(buf,KTextLengthToRead) );
00080             CleanupStack::PopAndDestroy();//file
00081             }
00082         appui->SetFileData(iFileName, buf);
00083         }
00084     
00085     return NULL;
00086     }
00087 
00088 void CHandlerDocument::OpenFileL(CFileStore*& aFileStore, RFile& aFile)
00089     {
00090     aFileStore = NULL; //So the other OpenFileL version is not called
00091 
00092     TFileName name;
00093     #ifdef __SERIES60_3X__
00094         aFile.Name(name);
00095         //aFile.FullName(name); //If the location is required
00096     #endif
00097     //This function is never used in 1st or 2nd edition,
00098     //so the RFile::Name function is always executed.
00099     //That way we know that name variable contains aFile name.
00100     if( iFileName == name)
00101         {
00102         return;
00103         }
00104     iFileName = name;
00105     
00106     TBuf8<KTextLengthToRead> buf;
00107     User::LeaveIfError( aFile.Read(buf,KTextLengthToRead) );
00108     CHandlerAppUi *appui = static_cast<CHandlerAppUi *> (iAppUi);
00109     appui->SetFileData(iFileName, buf);
00110     }

Generated by  doxygen 1.6.2