pkiutilities/CertSaver/src/CertSaverDocument.cpp
changeset 0 164170e6151a
child 21 09b1ac925e3f
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Document class
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CertSaverDocument.h"
       
    21 #include "CertSaverAppUi.h"
       
    22 
       
    23 // Class CShutterAO
       
    24 // ================= MEMBER FUNCTIONS =======================
       
    25 // Constructor
       
    26 CShutterAO::CShutterAO(): CActive( EPriorityStandard )
       
    27     {
       
    28     CActiveScheduler::Add( this );
       
    29     }
       
    30 
       
    31 // Destructor
       
    32 CShutterAO::~CShutterAO()
       
    33     {
       
    34     Cancel();
       
    35     }
       
    36 
       
    37 //------------------------------------------------------
       
    38 // CShutterAO::Exit()
       
    39 //
       
    40 //------------------------------------------------------
       
    41 //
       
    42 void CShutterAO::Exit()
       
    43     {
       
    44     SetActive();
       
    45     // Complete the AO immediately so that buffer processing can occur in RunL().
       
    46     TRequestStatus* statusPtr = &iStatus;
       
    47     User::RequestComplete( statusPtr, KErrNone );
       
    48     }
       
    49 
       
    50 //------------------------------------------------------
       
    51 // CShutterAO::DoCancel()
       
    52 //
       
    53 //------------------------------------------------------
       
    54 //
       
    55 void CShutterAO::DoCancel()
       
    56     {
       
    57     }
       
    58 
       
    59 //------------------------------------------------------
       
    60 // CShutterAO::RunL()
       
    61 //
       
    62 //------------------------------------------------------
       
    63 //
       
    64 void CShutterAO::RunL()
       
    65     {
       
    66     iAvkonAppUi->Exit();
       
    67     }
       
    68 
       
    69 // class CCertSaverDocument
       
    70 // ================= MEMBER FUNCTIONS =======================
       
    71 // destructor
       
    72 CCertSaverDocument::~CCertSaverDocument()
       
    73     {
       
    74     delete iParser;
       
    75     delete iAO;
       
    76     }
       
    77 
       
    78 // EPOC default constructor can leave.
       
    79 void CCertSaverDocument::ConstructL()
       
    80     {
       
    81     iParser = CCertParser::NewL();
       
    82     }
       
    83 
       
    84 // Two-phased constructor.
       
    85 CCertSaverDocument* CCertSaverDocument::NewL(
       
    86         CEikApplication& aApp )     // CCertSaverApp reference
       
    87     {
       
    88     CCertSaverDocument* self =
       
    89         new (ELeave) CCertSaverDocument( aApp );
       
    90     CleanupStack::PushL( self );
       
    91     self->ConstructL();
       
    92     CleanupStack::Pop(self);
       
    93 
       
    94     return self;
       
    95     }
       
    96 
       
    97 // -----------------------------------------------------------------------------
       
    98 // CCertSaverDocument::OpenFileL
       
    99 // Called by the framework to open a certificate file with file name.
       
   100 // -----------------------------------------------------------------------------
       
   101 //
       
   102 
       
   103 CFileStore* CCertSaverDocument::OpenFileL(TBool /*aDoOpen*/,
       
   104     const TDesC& aFilename, RFs& aFs )
       
   105     {
       
   106     CFileStore* docStore=NULL;
       
   107 
       
   108     RFile file;
       
   109     TInt err = file.Open( aFs, aFilename, EFileRead );
       
   110     User::LeaveIfError( err );
       
   111     CleanupClosePushL<RFile>( file );
       
   112 
       
   113     OpenFileL( docStore, file );
       
   114 
       
   115     CleanupStack::PopAndDestroy(); // Close file
       
   116 
       
   117     return docStore;
       
   118     }
       
   119 
       
   120 // ----------------------------------------------------
       
   121 // CCertSaverDocument::OpenFileL
       
   122 // Since Uikon framework always starts application from
       
   123 // this function, Certificate Saver uses this function
       
   124 // to handle the certificate file. Doc Handler sets
       
   125 // aDoOpen to ETrue.
       
   126 // ----------------------------------------------------
       
   127 //
       
   128 void CCertSaverDocument::OpenFileL(CFileStore*& /*aFileStore*/, RFile& aFile)
       
   129     {
       
   130     TRAPD( err, STATIC_CAST(CCertSaverAppUi*,iAppUi)->RunFileL( aFile ) );
       
   131 
       
   132     if ( err != KErrNone && err != KErrExitApp && err != KErrCancel )
       
   133         {
       
   134         User::Leave( err );
       
   135         }
       
   136 
       
   137     iAO = new (ELeave) CShutterAO;
       
   138     iAO->Exit();
       
   139     #ifdef _DEBUG
       
   140         RDebug::Print( _L("Exiting OpenFileL") );
       
   141     #endif
       
   142     }
       
   143 
       
   144 //------------------------------------------------------
       
   145 // CCertSaverDocument::Parser()
       
   146 //
       
   147 //------------------------------------------------------
       
   148 //
       
   149 CCertParser& CCertSaverDocument::Parser() const
       
   150     {
       
   151     return *iParser;
       
   152     }
       
   153 
       
   154 // ----------------------------------------------------
       
   155 // CCertSaverDocument::CreateAppUiL()
       
   156 // constructs CCertSaverAppUi
       
   157 // ----------------------------------------------------
       
   158 //
       
   159 CEikAppUi* CCertSaverDocument::CreateAppUiL()
       
   160     {
       
   161     return new (ELeave) CCertSaverAppUi;
       
   162     }
       
   163 
       
   164 // End of File