imagehandlingutilities/thumbnailmanager/thumbnailserver/src/thumbnailmdsquerytask.cpp
changeset 0 2014ca87e772
child 5 82749d516180
child 14 2edacbf5d3f9
equal deleted inserted replaced
-1:000000000000 0:2014ca87e772
       
     1 /*
       
     2 * Copyright (c) 2006-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:  Task for making MDS querys
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h>
       
    20 
       
    21 #include <mdeconstants.h>
       
    22 #include <thumbnailmanager.h>
       
    23 
       
    24 #include "thumbnailmdsquerytask.h"
       
    25 #include "thumbnailmanagerconstants.h"
       
    26 #include "thumbnaillog.h"
       
    27 #include "thumbnailserver.h"
       
    28 
       
    29 
       
    30 // ======== MEMBER FUNCTIONS ========
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // CThumbnailMDSQueryTask::CThumbnailMDSQueryTask()
       
    34 // C++ default constructor can NOT contain any code, that might leave.
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 CThumbnailMDSQueryTask::CThumbnailMDSQueryTask(
       
    38         CThumbnailTaskProcessor& aProcessor, TInt aPriority, CMdESession* aMdESession, CThumbnailServer& aServer): 
       
    39         CThumbnailTask( aProcessor, aPriority ), iMdESession( aMdESession ), iServer(aServer), iUpdateToDb(ETrue)
       
    40     {
       
    41     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::CThumbnailMDSQueryTask()", this );
       
    42     }
       
    43 
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CThumbnailMDSQueryTask::~CThumbnailMDSQueryTask()
       
    47 // Destructor.
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 CThumbnailMDSQueryTask::~CThumbnailMDSQueryTask()
       
    51     {
       
    52     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::~CThumbnailMDSQueryTask()", this);
       
    53            
       
    54     if (iQuery)
       
    55         {
       
    56         iQuery->Cancel();
       
    57         delete iQuery;
       
    58         }
       
    59     }
       
    60 
       
    61 
       
    62 // -----------------------------------------------------------------------------
       
    63 // CThumbnailMDSQueryTask::HandleQueryNewResults()
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 void CThumbnailMDSQueryTask::HandleQueryNewResults( CMdEQuery& /*aQuery*/,
       
    67                                                const TInt /*aFirstNewItemIndex*/,
       
    68                                                const TInt /*aNewItemCount*/ )
       
    69     {
       
    70     // No implementation required
       
    71     }
       
    72 
       
    73 // -----------------------------------------------------------------------------
       
    74 // CThumbnailMDSQueryTask::HandleQueryCompleted()
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 void CThumbnailMDSQueryTask::HandleQueryCompleted( CMdEQuery& /*aQuery*/, const TInt aError )
       
    78     {
       
    79     TN_DEBUG3( "CThumbnailMDSQueryTask::HandleQueryCompleted(0x%08x), aError == %d", this, aError );
       
    80     
       
    81     // if no errors in query
       
    82     if (aError == KErrNone && iQuery && iQuery->Count() > 0)
       
    83         {
       
    84         if( iQueryType == EURI )
       
    85             {
       
    86             const CMdEObject* object = &iQuery->Result(0);
       
    87             
       
    88             TN_DEBUG2( "CThumbnailMDSQueryTask::HandleQueryCompleted() - URI = %S", &object->Uri() );
       
    89                             
       
    90             if( iUpdateToDb)
       
    91                 {
       
    92                 //update IDs to database by Path
       
    93                 if (iMessage.Handle())
       
    94                     {
       
    95                     TInt err = iMessage.Read( 0, iRequestParams );
       
    96                     if( err == KErrNone)
       
    97                         {
       
    98                         TThumbnailRequestParams& params = iRequestParams();
       
    99                         TRAP_IGNORE(iServer.UpdateIDL(object->Uri(), params.iThumbnailId));
       
   100                         }                   
       
   101                     }
       
   102                 }
       
   103     
       
   104            // return path to client side            
       
   105             ReturnPath(object->Uri());
       
   106             }
       
   107         else if (iQueryType == EId )
       
   108             {
       
   109             const CMdEObject* object = &iQuery->Result(0);
       
   110             
       
   111             TN_DEBUG2( "CThumbnailMDSQueryTask::HandleQueryCompleted() - Id = %d",  object->Id());
       
   112             
       
   113             if( object->Id() != KNoId)
       
   114                 {
       
   115                 if( iUpdateToDb)
       
   116                     {
       
   117                     TRAP_IGNORE(iServer.UpdateIDL(object->Uri(), object->Id() ));
       
   118                     }
       
   119                 else
       
   120                     {
       
   121                     // add Id to message
       
   122                     if (iMessage.Handle())
       
   123                         {
       
   124                         TInt ret = iMessage.Read( 0, iRequestParams );
       
   125                         if( ret == KErrNone)
       
   126                             {
       
   127                             TThumbnailRequestParams& params = iRequestParams();
       
   128                             params.iThumbnailId = object->Id();
       
   129                             ret = iMessage.Write( 0, iRequestParams );
       
   130                             }
       
   131                         }
       
   132                     }
       
   133                 }
       
   134             
       
   135             // complete the message with a code from which client side
       
   136             // knows to make a new request using the path
       
   137             Complete( KThumbnailErrThumbnailNotFound );
       
   138             ResetMessageData();
       
   139             }
       
   140         else
       
   141             {
       
   142             TN_DEBUG1( "CThumbnailMDSQueryTask::HandleQueryCompleted() - Don't ever come here" );
       
   143             Complete( KErrNotFound );
       
   144             ResetMessageData();
       
   145             }
       
   146         }
       
   147     else
       
   148         {
       
   149         TN_DEBUG1( "CThumbnailMDSQueryTask::HandleQueryCompleted() - No results." );
       
   150         
       
   151 	        if( iQueryType == EId )
       
   152 	            {
       
   153 	               if( iUpdateToDb)
       
   154 	                    {
       
   155 	                    TN_DEBUG2( "CThumbnailMDSQueryTask::HandleQueryCompleted() delete %S", &iUri );
       
   156 	                    TRAP_IGNORE( iServer.DeleteThumbnailsL( iUri ) );
       
   157 	                    }
       
   158 	               
       
   159 	            Complete( KThumbnailErrThumbnailNotFound );
       
   160 	            ResetMessageData();
       
   161 	            }
       
   162 	        else 
       
   163 	            {
       
   164 	            Complete( KErrNotFound );
       
   165 	            ResetMessageData();
       
   166             	}
       
   167         }
       
   168    }
       
   169 
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // CThumbnailMDSQueryTask::StartL()
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 void CThumbnailMDSQueryTask::StartL()
       
   176     {
       
   177     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::StartL()", this );
       
   178 
       
   179     CThumbnailTask::StartL();
       
   180 
       
   181     // start query
       
   182     iQuery->FindL();
       
   183     }
       
   184 
       
   185 
       
   186 // ---------------------------------------------------------------------------
       
   187 // CThumbnailMDSQueryTask::RunL()
       
   188 // ---------------------------------------------------------------------------
       
   189 //
       
   190 void CThumbnailMDSQueryTask::RunL()
       
   191     {
       
   192     // No implementation required
       
   193     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::RunL()", this );
       
   194     }
       
   195 
       
   196 
       
   197 // ---------------------------------------------------------------------------
       
   198 // CThumbnailMDSQueryTask::DoCancel()
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CThumbnailMDSQueryTask::DoCancel()
       
   202     {
       
   203     TN_DEBUG2( "CThumbnailMDSQueryTask(0x%08x)::DoCancel()", this );
       
   204     
       
   205     iQuery->Cancel();
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CThumbnailMDSQueryTask::QueryPathByIdL()
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CThumbnailMDSQueryTask::QueryPathByIdL(TThumbnailId aId)
       
   213     {
       
   214     TN_DEBUG1( "CThumbnailMDSQueryTask()::QueryPathByIdL()");
       
   215     iQueryType = EURI;
       
   216     CMdENamespaceDef* defNamespace = &iMdESession->GetDefaultNamespaceDefL();
       
   217     CMdEObjectDef& objDef = defNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
       
   218     
       
   219     iQuery = iMdESession->NewObjectQueryL( *defNamespace, objDef, this );
       
   220     iQuery->SetResultMode( EQueryResultModeItem );
       
   221 
       
   222     CMdELogicCondition& rootCondition = iQuery->Conditions();
       
   223     rootCondition.SetOperator( ELogicConditionOperatorOr );
       
   224     
       
   225     // add ID condition
       
   226     rootCondition.AddObjectConditionL( aId );
       
   227     }
       
   228 
       
   229 // ---------------------------------------------------------------------------
       
   230 // CThumbnailMDSQueryTask::ReturnPath()
       
   231 // ---------------------------------------------------------------------------
       
   232 //
       
   233 void CThumbnailMDSQueryTask::ReturnPath(const TDesC& aUri)
       
   234     {
       
   235     if ( iMessage.Handle())
       
   236         {
       
   237         // add path to message
       
   238         if (iMessage.Handle())
       
   239             {
       
   240             TInt ret = iMessage.Read( 0, iRequestParams );      
       
   241             if(ret == KErrNone)
       
   242                 {
       
   243                 TThumbnailRequestParams& params = iRequestParams();
       
   244                 params.iFileName = aUri;
       
   245                 ret = iMessage.Write( 0, iRequestParams );
       
   246                 }
       
   247             }
       
   248     
       
   249         // complete the message with a code from which client side
       
   250         // knows to make a new request using the path
       
   251         Complete( KThumbnailErrThumbnailNotFound );
       
   252         ResetMessageData();
       
   253         }
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------------------------
       
   257 // CThumbnailMDSQueryTask::QueryIdByPathL()
       
   258 // ---------------------------------------------------------------------------
       
   259 //
       
   260 void CThumbnailMDSQueryTask::QueryIdByPathL(const TDesC& aUri)
       
   261     {
       
   262     TN_DEBUG1( "CThumbnailMDSQueryTask()::QueryIdByPathL()");
       
   263     iQueryType = EId;
       
   264     iUri = aUri;
       
   265     CMdENamespaceDef* defNamespace = &iMdESession->GetDefaultNamespaceDefL();
       
   266     CMdEObjectDef& objDef = defNamespace->GetObjectDefL( MdeConstants::Object::KBaseObject );
       
   267     
       
   268     iQuery = iMdESession->NewObjectQueryL( *defNamespace, objDef, this );
       
   269     iQuery->SetResultMode( EQueryResultModeItem );
       
   270 
       
   271     CMdELogicCondition& rootCondition = iQuery->Conditions();
       
   272     rootCondition.SetOperator( ELogicConditionOperatorOr );
       
   273     
       
   274     rootCondition.AddObjectConditionL(EObjectConditionCompareUri, aUri);
       
   275     }
       
   276 
       
   277 // ---------------------------------------------------------------------------
       
   278 // CThumbnailMDSQueryTask::SetUpdateToDb()
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CThumbnailMDSQueryTask::SetUpdateToDb(const TBool& aUpdateToDb )
       
   282     {
       
   283     TN_DEBUG2( "CThumbnailMDSQueryTask()::SetCompleteTask() aUpdateToDb == %d", aUpdateToDb);
       
   284     iUpdateToDb = aUpdateToDb;
       
   285     }