phonebookui/Phonebook2/CommandsExtension/src/CPbk2ViewImageCmd.cpp
changeset 0 e686773b3f54
child 68 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     1 /*
       
     2 * Copyright (c) 2002-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: 
       
    15 *           View image command event handling class.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "CPbk2ViewImageCmd.h"
       
    22 
       
    23 // Phonebook 2
       
    24 #include "Pbk2DataCaging.hrh"
       
    25 #include <Pbk2UIControls.rsg>
       
    26 #include <MPbk2CommandObserver.h>
       
    27 #include <TPbk2StoreContactAnalyzer.h>
       
    28 #include <Pbk2Commands.rsg>
       
    29 #include <Pbk2CmdExtRes.rsg>
       
    30 
       
    31 // Virtual Phonebook
       
    32 #include <MVPbkStoreContact.h>
       
    33 #include <MVPbkFieldType.h>
       
    34 #include <MVPbkContactFieldTextData.h>
       
    35 
       
    36 // System includes
       
    37 #include <DocumentHandler.h>            // CDocumentHandler
       
    38 #include <apmstd.h>                     // TDataType
       
    39 #include <StringLoader.h>
       
    40 #include <aknnotewrappers.h>
       
    41 
       
    42 // Debugging headers
       
    43 #include <Pbk2Debug.h>
       
    44 
       
    45 
       
    46 // --------------------------------------------------------------------------
       
    47 // CPbk2ViewImageCmd::CPbk2ViewImageCmd
       
    48 // --------------------------------------------------------------------------
       
    49 //
       
    50 CPbk2ViewImageCmd::CPbk2ViewImageCmd( MPbk2ContactUiControl& aUiControl )
       
    51     : CPbk2ImageCmdBase( aUiControl )
       
    52     {
       
    53     }
       
    54 
       
    55 // --------------------------------------------------------------------------
       
    56 // CPbk2ViewImageCmd::ConstructL
       
    57 // --------------------------------------------------------------------------
       
    58 //
       
    59 void CPbk2ViewImageCmd::ConstructL()
       
    60     {
       
    61     CPbk2ImageCmdBase::BaseConstructL();
       
    62     iDocHandler = CDocumentHandler::NewL();
       
    63     iDocHandler->SetExitObserver( this );
       
    64     }
       
    65 
       
    66 // --------------------------------------------------------------------------
       
    67 // CPbk2ViewImageCmd::NewL
       
    68 // --------------------------------------------------------------------------
       
    69 //
       
    70 CPbk2ViewImageCmd* CPbk2ViewImageCmd::NewL(
       
    71         MPbk2ContactUiControl& aUiControl )
       
    72     {
       
    73     CPbk2ViewImageCmd* self =
       
    74         new (ELeave) CPbk2ViewImageCmd( aUiControl );
       
    75     CleanupStack::PushL( self );
       
    76     self->ConstructL();
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // --------------------------------------------------------------------------
       
    82 // CPbk2ViewImageCmd::~CPbk2ViewImageCmd
       
    83 // --------------------------------------------------------------------------
       
    84 //
       
    85 CPbk2ViewImageCmd::~CPbk2ViewImageCmd()
       
    86     {
       
    87     delete iDocHandler;
       
    88     }
       
    89 
       
    90 // --------------------------------------------------------------------------
       
    91 // CPbk2ViewImageCmd::ExecuteCommandL
       
    92 // --------------------------------------------------------------------------
       
    93 //
       
    94 TBool CPbk2ViewImageCmd::ExecuteCommandL()
       
    95     {
       
    96     TBool result = EFalse;
       
    97 
       
    98     // fetch image from contact's image field
       
    99     TInt fieldIndex( KErrNotFound );
       
   100     TPbk2StoreContactAnalyzer analyzer( *iContactManager, iStoreContact );
       
   101     fieldIndex = analyzer.HasFieldL( R_PHONEBOOK2_IMAGE_SELECTOR );
       
   102 
       
   103     if( fieldIndex != KErrNotFound )
       
   104         {
       
   105         // retrieve field pointer and its current text for call
       
   106         MVPbkStoreContactField& field =
       
   107             iStoreContact->Fields().FieldAt( fieldIndex );
       
   108         iFileName.Copy(
       
   109             MVPbkContactFieldTextData::Cast( field.FieldData() ).Text() );
       
   110 
       
   111         // empty datatype for automatic recognization
       
   112         TDataType dataType;
       
   113 
       
   114         // open file using document handler
       
   115         TInt status = KErrGeneral;
       
   116         TRAPD( error, status = iDocHandler->
       
   117             OpenFileEmbeddedL( iFileName, dataType ) );
       
   118         
       
   119         // KErrNotReady, when no mmc inserted
       
   120         // KErrNotFound, when image is deleted
       
   121         if ( error == KErrNotFound || error == KErrUnderflow
       
   122                                    || error == KErrCorrupt 
       
   123                                    || error == KErrNotReady )
       
   124             {
       
   125             // if the image has been deleted from Image Gallery
       
   126             // or it is corrupted, show a note instead of leave
       
   127             ShowImageNotOpenedNoteL();
       
   128             }
       
   129         result = ( status == KErrNone );
       
   130         }
       
   131     else
       
   132         {
       
   133         // When viewing image on the business card, show "can't open" note for it
       
   134         ShowImageNotOpenedNoteL();
       
   135         }
       
   136 
       
   137     return result;
       
   138     }
       
   139 
       
   140 // --------------------------------------------------------------------------
       
   141 // CPbk2ViewImageCmd::HandleServerAppExit
       
   142 // --------------------------------------------------------------------------
       
   143 //
       
   144 void CPbk2ViewImageCmd::HandleServerAppExit( TInt aReason )
       
   145     {
       
   146     // make base call first
       
   147     MAknServerAppExitObserver::HandleServerAppExit( aReason );
       
   148     // finish the command (treat KUserCancel as KErrNone too)
       
   149     ProcessDismissed( KErrNone );
       
   150     }
       
   151 
       
   152 // --------------------------------------------------------------------------
       
   153 // CPbk2ViewImageCmd::ShowImageNotOpenedNoteL
       
   154 // --------------------------------------------------------------------------
       
   155 //
       
   156 void CPbk2ViewImageCmd::ShowImageNotOpenedNoteL()
       
   157     {
       
   158     HBufC* prompt = StringLoader::LoadLC( R_QTN_ALBUM_ERR_FORMAT_UNKNOWN );
       
   159     CAknInformationNote* dlg = new ( ELeave ) CAknInformationNote( ETrue );
       
   160     dlg->ExecuteLD( *prompt );
       
   161     CleanupStack::PopAndDestroy( prompt );
       
   162     }
       
   163 
       
   164 //  End of File