omadm/lawmo/lawmoplugins/mediaplugin/src/mediaplugin.cpp
branchRCL_3
changeset 55 c4687ff85147
equal deleted inserted replaced
54:9360ca28b668 55:c4687ff85147
       
     1 /*
       
     2 * Copyright (c) 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 the License "Symbian Foundation License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Media plug-in for LAWMO
       
    15 *
       
    16 */
       
    17 
       
    18 #include <f32file.h>
       
    19 #include <data_caging_path_literals.hrh>
       
    20 #include <centralrepository.h>
       
    21 #include "mediaplugin.h"
       
    22 #include "lawmodebug.h"
       
    23 
       
    24 // ----------------------------------------------------------------------------------------
       
    25 // CLAWMOMediaPlugin::NewL
       
    26 // ----------------------------------------------------------------------------------------
       
    27 CLAWMOMediaPlugin* CLAWMOMediaPlugin::NewL(MLawmoPluginWipeObserver* aObserver)
       
    28 	{
       
    29         RDEBUG( "CLAWMOMediaPlugin NewL");
       
    30         CLAWMOMediaPlugin* self=new(ELeave) CLAWMOMediaPlugin();  
       
    31 		CleanupStack::PushL(self);
       
    32 		self->ConstructL(aObserver); 
       
    33 		if(self)
       
    34         RDEBUG( "CLAWMOMediaPlugin NewL self obj created");
       
    35 	    CleanupStack::Pop();
       
    36 		return self;
       
    37 	}
       
    38 
       
    39 // ----------------------------------------------------------------------------------------
       
    40 // CLAWMOMediaPlugin::~CLAWMOMediaPlugin
       
    41 // ----------------------------------------------------------------------------------------
       
    42 CLAWMOMediaPlugin::~CLAWMOMediaPlugin()
       
    43 	{
       
    44     RDEBUG( "CLAWMOMediaPlugin destructor");
       
    45     if(iQuery)
       
    46     	{
       
    47     	delete iQuery;
       
    48     	RDEBUG( "iQuery deleted");
       
    49       }
       
    50     if(iMdeSession)
       
    51     	{
       
    52     	delete iMdeSession;
       
    53     	RDEBUG( "iMdeSession deleted");
       
    54       }
       
    55     iRfs.Close();
       
    56 	}
       
    57 
       
    58 // ----------------------------------------------------------------------------------------
       
    59 // CLAWMOMediaPlugin::CLAWMOMediaPlugin
       
    60 // ----------------------------------------------------------------------------------------
       
    61 CLAWMOMediaPlugin::CLAWMOMediaPlugin()
       
    62 	{
       
    63 	// See ConstructL() for initialisation completion.
       
    64 	}
       
    65 
       
    66 // ----------------------------------------------------------------------------------------
       
    67 // CLAWMOMediaPlugin::ConstructL
       
    68 // ----------------------------------------------------------------------------------------
       
    69 void CLAWMOMediaPlugin::ConstructL(MLawmoPluginWipeObserver* aObserver)
       
    70 {	
       
    71     RDEBUG( "CLAWMOMediaPlugin ConstructL");
       
    72     iState = EUninitialized;
       
    73 	iObserver = aObserver;
       
    74     User::LeaveIfError(iRfs.Connect());
       
    75     RDEBUG( "CLAWMOMediaPlugin ConstructL done");
       
    76 }
       
    77 
       
    78 // Implementation of CLAWMOPluginInterface
       
    79 
       
    80 // ----------------------------------------------------------------------------------------
       
    81 // CLAWMOMediaPlugin::WipeL
       
    82 // Wipes the Media.
       
    83 // ----------------------------------------------------------------------------------------
       
    84 
       
    85 void CLAWMOMediaPlugin::WipeL ()
       
    86 {
       
    87     RDEBUG( "CLAWMOMediaPlugin WipeL()");
       
    88     iMdeSession = CMdESession::NewL( *this ); //MMdESessionObserver
       
    89     RDEBUG( "CLAWMOMediaPlugin WipeL() iMdeSession");
       
    90     iState = EInitialized;  
       
    91 }
       
    92 	
       
    93 void CLAWMOMediaPlugin::HandleSessionOpened( CMdESession& /*aSession*/, TInt aError )
       
    94     {
       
    95 	RDEBUG( "HandleSessionOpened start");
       
    96 	iState = ESession;
       
    97 	if(aError == KErrNone)
       
    98 	    {
       
    99 		TRAPD(err,StartMdsQueryL());
       
   100 		if(err!=KErrNone)
       
   101 		    iObserver->HandleWipeCompleted(KErrGeneral);
       
   102 	    }
       
   103 	else
       
   104 	    iObserver->HandleWipeCompleted(aError);
       
   105     RDEBUG( "HandleSessionOpened done");	
       
   106 	}
       
   107 
       
   108 // ----------------------------------------------------------------------------
       
   109 // CMdsQueryHandler::HandleSessionError
       
   110 // From MMdESessionObserver
       
   111 // ----------------------------------------------------------------------------
       
   112 //
       
   113 void CLAWMOMediaPlugin::HandleSessionError( CMdESession& /*aSession*/, TInt aError )
       
   114     {
       
   115     RDEBUG( "CLAWMOMediaPlugin HandleSessionError()");
       
   116 	iState = EError;
       
   117 	iObserver->HandleWipeCompleted(aError);
       
   118     }
       
   119 	
       
   120 void CLAWMOMediaPlugin::StartMdsQueryL()
       
   121     {
       
   122     RDEBUG( "CLAWMOMediaPlugin StartMdsQuery() start");
       
   123     if(iState == ESession)
       
   124         {
       
   125         iState = ESession;
       
   126         TInt counT = iMdeSession->NamespaceDefCount();
       
   127         RDEBUG_2("NamespaceDefCount  %d", counT);
       
   128 
       
   129         CMdENamespaceDef& defaultNamespaceDef = iMdeSession->GetDefaultNamespaceDefL();
       
   130         RDEBUG( "HandleSessionOpened StartMdsQuery() defaultNamespaceDef");
       
   131         CMdEObjectDef& imageObjDef = defaultNamespaceDef.GetObjectDefL(MdeConstants::Image::KImageObject);
       
   132         RDEBUG( "RunL() imageObjDef");
       
   133 
       
   134         //CMdEPropertyDef& itemProperty = imageObjDef.GetPropertyDefL( MdeConstants::Object::KItemTypeProperty );
       
   135         CMdEPropertyDef& titleProperty = imageObjDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
       
   136 
       
   137         RDEBUG( "RunL() titleProperty");
       
   138         iQuery = iMdeSession->NewObjectQueryL( iMdeSession->GetDefaultNamespaceDefL(),
       
   139                                     imageObjDef,
       
   140                                     this );
       
   141         iQuery->AddPropertyFilterL(&titleProperty);
       
   142         
       
   143         RDEBUG( "RunL() NewObjQuery");                                 
       
   144         //_LIT(KJpegMime, "image/jpeg");
       
   145         //CMdELogicCondition& rootCondition = iQuery->Conditions();
       
   146         //rootCondition.AddPropertyConditionL(itemProperty, ETextPropertyConditionCompareEquals,KJpegMime);
       
   147         //RDEBUG( "RunL()LogicCondition");
       
   148         iState = EImage;
       
   149         iQuery->FindL(); // starts the object query
       
   150         RDEBUG( "RunL() FindL");    
       
   151         }
       
   152     else if(iState == EVideo)
       
   153         {
       
   154         CMdENamespaceDef& defaultNamespaceDef = iMdeSession->GetDefaultNamespaceDefL();
       
   155         RDEBUG( "StartMdsQuery StartVideoL() defaultNamespaceDef");
       
   156         CMdEObjectDef& vidObjDef = defaultNamespaceDef.GetObjectDefL(MdeConstants::Video::KVideoObject);
       
   157         RDEBUG( "StartMdsQuery StartVideoL() imageObjDef");
       
   158         
       
   159         iQuery = iMdeSession->NewObjectQueryL( iMdeSession->GetDefaultNamespaceDefL(),
       
   160                                             vidObjDef,
       
   161                                             this );
       
   162         RDEBUG( "StartMdsQuery StartVideoL() NewObjQuery");                                 
       
   163         CMdEPropertyDef& titleProperty = vidObjDef.GetPropertyDefL( MdeConstants::Object::KTitleProperty );
       
   164         iQuery->AddPropertyFilterL(&titleProperty);
       
   165         RDEBUG( "StartMdsQuery StartVideoL() BeforeFindL");
       
   166         iQuery->FindL(); // starts the object query
       
   167         RDEBUG( "StartMdsQuery StartVideoL() FindL");
       
   168         }
       
   169     RDEBUG( "CLAWMOMediaPlugin StartMdsQuery() done");
       
   170     }
       
   171 
       
   172 void CLAWMOMediaPlugin::HandleQueryCompleted( CMdEQuery& aQuery, TInt aError )
       
   173   {
       
   174     // query is completed
       
   175     RDEBUG( "CLAWMOMediaPlugin HandleQueryCompleted, Begin");
       
   176     RDEBUG_2("CLAWMOMediaPlugin error %d", aError);
       
   177     RDEBUG_2("aQuery.Count %d", aQuery.Count());
       
   178     TBool comp = iQuery->IsComplete();
       
   179     RDEBUG_2("Query complete ? %d",comp);
       
   180     
       
   181     CMdEObjectQuery& query = (CMdEObjectQuery &) aQuery;
       
   182     if( aQuery.Count() > 0 && aError == KErrNone )
       
   183     {
       
   184     // some items were found!
       
   185     RDEBUG( "CLAWMOMediaPlugin HandleQueryCompleted, objects found");
       
   186     for(TInt i=0;i<aQuery.Count();i++)
       
   187         {
       
   188         TBuf<255> uri;
       
   189         CMdEObject* obj = (CMdEObject*)query.TakeOwnershipOfResult(i);
       
   190         RDEBUG( "CLAWMOMediaPlugin HandleQueryCompleted, own one obj");
       
   191         uri.Copy(obj->Uri());
       
   192         RDEBUG_2("HandleQueryCompleted URI %s", uri.PtrZ());
       
   193         if(iRfs.IsValidName(uri))
       
   194             {
       
   195             RDEBUG( "CLAWMOMediaPlugin HandleQueryCompleted file exists");
       
   196             iRfs.Delete ( uri );
       
   197             }
       
   198         delete obj;
       
   199         }
       
   200     }
       
   201 	// After deletion, decide if its video/image and do accordingly
       
   202     if(iState == EVideo)
       
   203         {
       
   204         iObserver->HandleWipeCompleted(aError);
       
   205         }
       
   206     else if(iState == EImage)
       
   207         {
       
   208         iState = EVideo;
       
   209         RDEBUG( "CLAWMOMediaPlugin HandleQueryCompleted() ****reqcomplete");
       
   210         TRAPD(err,StartMdsQueryL());
       
   211         if(err!=KErrNone)
       
   212             iObserver->HandleWipeCompleted(KErrGeneral);
       
   213         }
       
   214     RDEBUG( "CLAWMOMediaPlugin HandleQueryCompleted, out of loop");
       
   215   }
       
   216 
       
   217 void CLAWMOMediaPlugin::HandleQueryNewResults(CMdEQuery& aQuery,
       
   218 						   TInt aFirstNewItemIndex,
       
   219 						   TInt aNewItemCount)
       
   220    {
       
   221     RDEBUG( "CLAWMOMediaPlugin HandleQueryNewResults");    
       
   222    }
       
   223 
       
   224 //