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

00001 /*
00002  * Copyright (c) 2005-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003  *    
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *    
00007  *  * Redistributions of source code must retain the above copyright notice, this
00008  *    list of conditions and the following disclaimer.
00009  *  * Redistributions in binary form must reproduce the above copyright notice,
00010  *    this list of conditions and the following disclaimer in the documentation
00011  *    and/or other materials provided with the distribution.
00012  *  * Neither the name of Nokia Corporation nor the names of its contributors
00013  *    may be used to endorse or promote products derived from this software
00014  *    without specific prior written permission.
00015  *    
00016  *    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  *    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  *    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019  *    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020  *    FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021  *    DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022  *    SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023  *    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024  *    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025  *    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026  *    
00027  *    Description:  
00028  */
00029 
00030 #include "handlerAppUi.h"
00031 #include "handlerDocument.h"
00032 #include "Common.h"
00033 
00034 #include <f32file.h>
00035 #include <eikenv.h>
00036 #include <eikappui.h>
00037 #include <eikapp.h>
00038 #include <apparc.h>
00039 #include <eikproc.H>
00040 #include <apgwgnam.h> //Link against: apgrfx.lib
00041 #include <avkon.hrh>
00042 #include <aknnotewrappers.h>
00043 
00044 CHandlerDocument* CHandlerDocument::NewL(CEikApplication& aApp)
00045     {
00046     CHandlerDocument* self = NewLC(aApp);
00047     CleanupStack::Pop(self);
00048     return self;
00049     }
00050 
00051 CHandlerDocument* CHandlerDocument::NewLC(CEikApplication& aApp)
00052     {
00053     CHandlerDocument* self = new (ELeave) CHandlerDocument(aApp);
00054     CleanupStack::PushL(self);
00055     self->ConstructL();
00056     return self;
00057     }
00058 
00059 void CHandlerDocument::ConstructL()
00060     {
00061     // no implementation required
00062     }
00063 
00064 CHandlerDocument::CHandlerDocument(CEikApplication& aApp) : CAknDocument(aApp)
00065     {
00066     // no implementation required
00067     }
00068 
00069 CHandlerDocument::~CHandlerDocument()
00070     {
00071     // no implementation required
00072     }
00073 
00074 CEikAppUi* CHandlerDocument::CreateAppUiL()
00075     {
00076     // Create the application user interface, and return a pointer to it,
00077     // the framework takes ownership of this object
00078     iAppUi = new (ELeave) CHandlerAppUi;
00079     return iAppUi;
00080     }
00081 
00082 CFileStore* CHandlerDocument::OpenFileL( TBool aDoOpen, const TDesC& aFilename, RFs& aFs )
00083     {
00084     if (aDoOpen)
00085         {
00086         TFileName name = aFilename;
00087         if( iFileName == name ) //The same file, do nothing
00088             {
00089             return NULL;   
00090             }
00091         iFileName = name;
00092         CHandlerAppUi *appui = static_cast<CHandlerAppUi *> (iAppUi);
00093         TBuf8<KTextLengthToRead> buf;
00094 
00095         RFile file;
00096         
00097         TInt err = file.Open(aFs, aFilename, EFileRead|EFileShareAny); 
00098         if( err == KErrNone )
00099             {
00100             CleanupClosePushL(file);
00101             User::LeaveIfError( file.Read(buf,KTextLengthToRead) );
00102             CleanupStack::PopAndDestroy();//file
00103             }
00104         appui->SetFileData(iFileName, buf);
00105         }
00106     
00107     return NULL;
00108     }
00109 
00110 void CHandlerDocument::OpenFileL(CFileStore*& aFileStore, RFile& aFile)
00111     {
00112     aFileStore = NULL; //So the other OpenFileL version is not called
00113 
00114     TFileName name;
00115     #ifdef __SERIES60_3X__
00116         aFile.Name(name);
00117         //aFile.FullName(name); //If the location is required
00118     #endif
00119     //This function is never used in 1st or 2nd edition,
00120     //so the RFile::Name function is always executed.
00121     //That way we know that name variable contains aFile name.
00122     if( iFileName == name)
00123         {
00124         return;
00125         }
00126     iFileName = name;
00127     
00128     TBuf8<KTextLengthToRead> buf;
00129     User::LeaveIfError( aFile.Read(buf,KTextLengthToRead) );
00130     CHandlerAppUi *appui = static_cast<CHandlerAppUi *> (iAppUi);
00131     appui->SetFileData(iFileName, buf);
00132     }

Generated by  doxygen 1.6.2