harvester/composerplugins/imagecomposer/src/composerimageplugin.cpp
changeset 0 c53acadfccc6
child 7 3cebc1a84278
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2006-2009 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:  Composer Image Plug-in
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include "mdelogiccondition.h"
       
    22 #include "mdenamespacedef.h"
       
    23 #include "composerimageplugin.h"
       
    24 #include "harvesterlog.h"
       
    25 #include "mdeconstants.h"
       
    26 
       
    27 // ---------------------------------------------------------------------------
       
    28 // NewL
       
    29 // ---------------------------------------------------------------------------
       
    30 //
       
    31 CComposerImagePlugin* CComposerImagePlugin::NewL()
       
    32     {
       
    33     WRITELOG( "CComposerImagePlugin::NewL()" );
       
    34 
       
    35     CComposerImagePlugin* self = new (ELeave) CComposerImagePlugin();
       
    36     CleanupStack::PushL( self );
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop( self );
       
    39     return self;
       
    40     }
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // ~CComposerImagePlugin
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 CComposerImagePlugin::~CComposerImagePlugin() // destruct
       
    47     {   
       
    48     WRITELOG( "CComposerImagePlugin::~CComposerImagePlugin()" );
       
    49 
       
    50     delete iImageComposerAO;
       
    51     delete iLocationRelationObserver;
       
    52     delete iImagePresentObserver;
       
    53     
       
    54     delete iMdEHarvesterSession;
       
    55     }
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // CComposerImagePlugin
       
    59 // ---------------------------------------------------------------------------
       
    60 //
       
    61 CComposerImagePlugin::CComposerImagePlugin() : // first-phase C++ constructor
       
    62     iImageComposerAO( NULL ), iLocationRelationObserver( NULL ),
       
    63     iImagePresentObserver( NULL ), iMdEHarvesterSession( NULL )
       
    64     {
       
    65     WRITELOG( "CComposerImagePlugin::CComposerImagePlugin()" );
       
    66     }
       
    67 
       
    68 // ---------------------------------------------------------------------------
       
    69 // ConstructL
       
    70 // ---------------------------------------------------------------------------
       
    71 //
       
    72 void CComposerImagePlugin::ConstructL() // second-phase constructor
       
    73     {
       
    74     WRITELOG( "CComposerImagePlugin::ConstructL()" );
       
    75     iImageComposerAO = CImageComposerAO::NewL();
       
    76     iLocationRelationObserver = NULL;
       
    77 
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // SetObservers
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void CComposerImagePlugin::SetObservers()
       
    85     {
       
    86     WRITELOG( "CComposerImagePlugin::SetObservers()" );
       
    87 
       
    88     TRAPD( err, SetObserversL() );
       
    89     if ( err != KErrNone )
       
    90         {
       
    91         WRITELOG1( "CComposerImagePlugin::SetObservers Error: %d", err );
       
    92         }
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // SetObserversL
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CComposerImagePlugin::SetObserversL()
       
   100     {
       
   101     if ( iSession )
       
   102         {
       
   103         iImageComposerAO->SetSession( iSession );
       
   104 
       
   105         CMdELogicCondition* condition = CMdELogicCondition::NewL( ELogicConditionOperatorAnd );
       
   106         CleanupStack::PushL( condition );
       
   107 
       
   108         CMdENamespaceDef& defaultNamespace = iSession->GetDefaultNamespaceDefL();
       
   109         CMdEObjectDef& imageDef = 
       
   110         	defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
       
   111         condition->AddObjectConditionL( imageDef );
       
   112 
       
   113         CleanupStack::Pop( condition );
       
   114         iSession->AddObjectObserverL( *this, condition, ENotifyModify, &defaultNamespace );
       
   115 
       
   116         if ( iLocationRelationObserver )
       
   117             {
       
   118             delete iLocationRelationObserver;
       
   119             iLocationRelationObserver = NULL;
       
   120             }
       
   121 
       
   122         iLocationRelationObserver = CLocationRelationObserver::NewL( iSession, this );
       
   123         
       
   124         if ( iMdEHarvesterSession )
       
   125         	{
       
   126         	delete iMdEHarvesterSession;
       
   127         	iMdEHarvesterSession = NULL;
       
   128         	}
       
   129         iMdEHarvesterSession = CMdEHarvesterSession::NewL ( *iSession );
       
   130 
       
   131         if ( iImagePresentObserver )
       
   132         	{
       
   133         	delete iImagePresentObserver;
       
   134         	iImagePresentObserver = NULL;
       
   135         	}
       
   136         
       
   137         iImagePresentObserver = CImagePresentObserver::NewL( iSession, this, iMdEHarvesterSession );
       
   138         }
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // RemoveObservers
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CComposerImagePlugin::RemoveObservers()
       
   146     {
       
   147     if ( iSession )
       
   148         {
       
   149         TRAP_IGNORE( iSession->RemoveObjectObserverL( *this ) );
       
   150 
       
   151         iImageComposerAO->RemoveSession();
       
   152         
       
   153         delete iImagePresentObserver;
       
   154         iImagePresentObserver = NULL;
       
   155         
       
   156         delete iLocationRelationObserver;
       
   157         iLocationRelationObserver = NULL;
       
   158         }
       
   159     }
       
   160 
       
   161 // ---------------------------------------------------------------------------
       
   162 // IsComposingComplete
       
   163 // ---------------------------------------------------------------------------
       
   164 //
       
   165 TBool CComposerImagePlugin::IsComposingComplete()
       
   166     {
       
   167     WRITELOG( "CComposerImagePlugin::IsComposingComplete()" );
       
   168     
       
   169     return iImageComposerAO->IsComposingComplete();
       
   170     }
       
   171 
       
   172 /** 
       
   173  * Handle object modifications
       
   174  */
       
   175 void CComposerImagePlugin::HandleObjectNotification(CMdESession& /*aSession*/, 
       
   176 		TObserverNotificationType aType,
       
   177 		const RArray<TItemId>& aObjectIdArray)
       
   178 	{
       
   179     if ( aType == ENotifyModify )
       
   180     	{
       
   181 #ifdef _DEBUG
       
   182         WRITELOG1( "CComposerImagePlugin::HandleObjectNotification() objects: %d", aObjectIdArray.Count() );
       
   183 #endif
       
   184         TRAP_IGNORE( iMdEHarvesterSession->SetPendingL( aObjectIdArray ) );
       
   185     	iImageComposerAO->AddToQueue( aObjectIdArray, EFalse );
       
   186     	}
       
   187 	}
       
   188 
       
   189 void CComposerImagePlugin::WriteGPSTagsL( TItemId aObjectId, TItemId locationId )
       
   190 	{
       
   191 	RArray<TItemId> objectId;
       
   192 	CleanupClosePushL( objectId );
       
   193 	objectId.Append( aObjectId );
       
   194 	iMdEHarvesterSession->SetPendingL( objectId );
       
   195 	
       
   196 	CMdENamespaceDef& defaultNamespace = iSession->GetDefaultNamespaceDefL();
       
   197     CMdEObjectDef& imageObjDef = defaultNamespace.GetObjectDefL( MdeConstants::Image::KImageObject );
       
   198     CMdEObjectDef& locationObjDef = defaultNamespace.GetObjectDefL( MdeConstants::Location::KLocationObject );
       
   199 	CMdEObject* object = iSession->GetObjectL( aObjectId, imageObjDef );
       
   200 	CMdEObject* location = iSession->GetObjectL( locationId, locationObjDef );
       
   201 	
       
   202 	if( object && location )
       
   203 		{
       
   204 		TRAPD( err, iImageComposerAO->DoWriteExifL( object, location ) );
       
   205 	
       
   206 		if ( err == KErrNone )
       
   207 			{
       
   208 			iMdEHarvesterSession->ResetPendingL( objectId );
       
   209 			}
       
   210 		}
       
   211 	CleanupStack::PopAndDestroy( &objectId );
       
   212 	}
       
   213 
       
   214 void CComposerImagePlugin::HandlePendingObjects( const RArray<TItemId>& aObjectIdArray )
       
   215 	{
       
   216 	iImageComposerAO->AddToQueue( aObjectIdArray, ETrue);
       
   217 	}