homesync/contentmanager/cmserver/cmfillmanager/src/cmfmmpxduplicatedetector.cpp
changeset 0 7f85d04be362
equal deleted inserted replaced
-1:000000000000 0:7f85d04be362
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Dublicate detector for music
       
    15 *
       
    16 */
       
    17 
       
    18 #include <mpxcollectionutility.h>
       
    19 #include <mpxmediageneraldefs.h> // commonly used attribute keys
       
    20 #include <mpxmediacontainerdefs.h> // container-specific attribute keys
       
    21 #include <mpxcollectionplugin.hrh> // collection plugin types
       
    22 #include "cmfilllistitem.h"
       
    23 #include "cmfmitemhandlerobserver.h"
       
    24 #include "cmfmmpxduplicatedetector.h"
       
    25 #include "msdebug.h"    
       
    26 
       
    27 const TUid KMpxLocalCollectionUid = { 0x101FFC3A };
       
    28 const TUid KCmServerUid = { 0x10281FA7 };
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CCmFmMpxDuplicateDetector::NewL
       
    32 // ---------------------------------------------------------------------------
       
    33 // 
       
    34 CCmFmMpxDuplicateDetector* CCmFmMpxDuplicateDetector::NewL( 
       
    35     MCmFmItemHandlerObserver& aObserver )
       
    36     {
       
    37     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::NewL() start"));    
       
    38     CCmFmMpxDuplicateDetector* self = 
       
    39         CCmFmMpxDuplicateDetector::NewLC( aObserver );
       
    40     CleanupStack::Pop( self );
       
    41     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::NewL() end"));
       
    42     return self;
       
    43     }
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CCmFmMpxDuplicateDetector::NewLC
       
    47 // ---------------------------------------------------------------------------
       
    48 //    
       
    49 CCmFmMpxDuplicateDetector* CCmFmMpxDuplicateDetector::NewLC( 
       
    50     MCmFmItemHandlerObserver& aObserver )
       
    51     {
       
    52     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::NewLC() start"));    
       
    53     CCmFmMpxDuplicateDetector* self = 
       
    54         new ( ELeave ) CCmFmMpxDuplicateDetector( aObserver );
       
    55     CleanupStack::PushL( self );
       
    56     self->ConstructL();
       
    57     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::NewLC() end"));
       
    58     return self;  
       
    59     }    
       
    60 
       
    61 // ---------------------------------------------------------------------------
       
    62 // CCmFmMpxDuplicateDetector::~CCmFmMpxDuplicateDetector
       
    63 // ---------------------------------------------------------------------------
       
    64 // 
       
    65 CCmFmMpxDuplicateDetector::~CCmFmMpxDuplicateDetector()
       
    66     {
       
    67     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::\
       
    68     ~CCmFmMpxDuplicateDetector()"));
       
    69     CloseCollectionPlugin();         
       
    70     }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CCmFmMpxDuplicateDetector::CCmFmMpxDuplicateDetector
       
    74 // ---------------------------------------------------------------------------
       
    75 // 
       
    76 CCmFmMpxDuplicateDetector::CCmFmMpxDuplicateDetector( 
       
    77     MCmFmItemHandlerObserver& aObserver )
       
    78     : iObserver( aObserver )
       
    79     {
       
    80     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::\
       
    81     CCmFmMpxDuplicateDetector()"));
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CCmFmMpxDuplicateDetector::ConstructL
       
    86 // ---------------------------------------------------------------------------
       
    87 //     
       
    88 void CCmFmMpxDuplicateDetector::ConstructL()
       
    89     {
       
    90     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::ConstructL()"));
       
    91 
       
    92     OpenCollectionPluginL(); 
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CCmFmMpxDuplicateDetector::CheckMusicL
       
    97 // ---------------------------------------------------------------------------
       
    98 //    
       
    99 void CCmFmMpxDuplicateDetector::CheckMusicL( const CCmFillListItem& aItem )
       
   100     {
       
   101     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::CheckMusicL()"));
       
   102     
       
   103     CMPXMedia* criteria = CMPXMedia::NewL();
       
   104     CleanupStack::PushL( criteria );
       
   105     criteria->SetTObjectValueL<TUid>(
       
   106         KMPXMediaGeneralCollectionId, KMpxLocalCollectionUid );
       
   107     criteria->SetTObjectValueL<TMPXGeneralType>(
       
   108         KMPXMediaGeneralType, EMPXItem );
       
   109 
       
   110     criteria->SetTObjectValueL<TMPXGeneralCategory>(
       
   111             KMPXMediaGeneralCategory, EMPXSong );
       
   112     
       
   113     // Set title, size and date to criteria
       
   114     criteria->SetTextValueL( 
       
   115                 KMPXMediaGeneralTitle, aItem.PrimaryText() );
       
   116                 
       
   117     criteria->SetTObjectValueL<TInt32>(
       
   118                 KMPXMediaGeneralSize, aItem.Size() );
       
   119                 
       
   120     criteria->SetTObjectValueL<TInt64>(
       
   121                 KMPXMediaGeneralDate, aItem.Date().Int64() );
       
   122 
       
   123     // define attributes fetched
       
   124     RArray<TMPXAttribute> attributes;
       
   125     CleanupClosePushL( attributes );
       
   126     // add a dummy attribute because the query will fail if
       
   127     // there are no attributes
       
   128     attributes.AppendL( KMPXMediaGeneralId );
       
   129 
       
   130     // now find
       
   131     iCollectionUtility->Collection()
       
   132         .FindAllL( *criteria , attributes.Array(), *this );
       
   133     CleanupStack::PopAndDestroy(); // attributes
       
   134     CleanupStack::PopAndDestroy( criteria );
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CCmFmMpxDuplicateDetector::OpenCollectionPluginL
       
   139 // ---------------------------------------------------------------------------
       
   140 // 
       
   141 void CCmFmMpxDuplicateDetector::OpenCollectionPluginL( )
       
   142     {
       
   143     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::\
       
   144     OpenCollectionPluginL()"));
       
   145     
       
   146     iCollectionUtility = MMPXCollectionUtility::NewL(
       
   147         (MMPXCollectionObserver*)this, KCmServerUid );
       
   148     // Fetch mpx/gallery collection collection UID
       
   149     RArray<TUid> uid;
       
   150     CleanupClosePushL( uid );
       
   151     uid.AppendL( TUid::Uid( EMPXCollectionPluginMusic ) );
       
   152     TInt err = KErrNone;
       
   153     TUid collection = iCollectionUtility->CollectionIDL( uid.Array() );
       
   154     TRAP( err,iCollectionUtility->Collection().CommandL(
       
   155         EMcCmdCollectionInit,  collection.iUid ) );        
       
   156     CleanupStack::PopAndDestroy( &uid );    
       
   157     }
       
   158 
       
   159 // ---------------------------------------------------------------------------
       
   160 // CCmFmMpxDuplicateDetector::CloseCollectionPlugin
       
   161 // ---------------------------------------------------------------------------
       
   162 //
       
   163 void CCmFmMpxDuplicateDetector::CloseCollectionPlugin()
       
   164     {
       
   165     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::\
       
   166     CloseCollectionPlugin()"));
       
   167     
       
   168     if( iCollectionUtility )
       
   169         {
       
   170         iCollectionUtility->Close();
       
   171         iCollectionUtility = NULL;        
       
   172         }    
       
   173     }      
       
   174 
       
   175 // --------------------------------------------------------------------------
       
   176 // CCmFmMpxDuplicateDetector::HandleCollectionMessage
       
   177 // --------------------------------------------------------------------------
       
   178 // 
       
   179 void CCmFmMpxDuplicateDetector::HandleCollectionMessage( CMPXMessage* /*aMsg*/,
       
   180     TInt /*aErr*/ )
       
   181     {
       
   182     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::\
       
   183     HandleCollectionMessage()"));    
       
   184     }
       
   185 
       
   186 // --------------------------------------------------------------------------
       
   187 // CCmFmMpxDuplicateDetector::HandleCollectionMediaL
       
   188 // --------------------------------------------------------------------------
       
   189 // 
       
   190 void CCmFmMpxDuplicateDetector::HandleCollectionMediaL( const CMPXMedia& /*aMedia*/,
       
   191     TInt /*aError*/ )
       
   192     {
       
   193     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::\
       
   194     HandleCollectionMediaL()"));    
       
   195     }
       
   196 
       
   197 // --------------------------------------------------------------------------
       
   198 // CCmFmMpxDuplicateDetector::HandleOpenL
       
   199 // --------------------------------------------------------------------------
       
   200 // 
       
   201 void CCmFmMpxDuplicateDetector::HandleOpenL( const CMPXMedia& /*aEntries*/,
       
   202     TInt /*aIndex*/, TBool /*aComplete*/, TInt /*aError*/ )
       
   203     {
       
   204     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::HandleOpenL()"));    
       
   205     }
       
   206 
       
   207 // --------------------------------------------------------------------------
       
   208 // CCmFmMpxDuplicateDetector::HandleOpenL
       
   209 // --------------------------------------------------------------------------
       
   210 // 
       
   211 void CCmFmMpxDuplicateDetector::HandleOpenL( 
       
   212     const CMPXCollectionPlaylist& /*aPlaylist*/, TInt /*aError*/ )
       
   213     {
       
   214     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::HandleOpenL()"));
       
   215     }
       
   216 
       
   217 // --------------------------------------------------------------------------
       
   218 // CCmFmMpxDuplicateDetector::HandleFindAllL
       
   219 // Async find
       
   220 // --------------------------------------------------------------------------
       
   221 // 
       
   222 void CCmFmMpxDuplicateDetector::HandleFindAllL( const CMPXMedia& aResults,
       
   223     TBool /*aComplete*/, TInt /*aError*/ )
       
   224     {
       
   225     LOG(_L("[FILL MNGR]\t CCmFmMpxDuplicateDetector::HandleFindAllL()"));    
       
   226     
       
   227     if( &aResults )
       
   228         {
       
   229         if( !aResults.Value<CMPXMediaArray>( 
       
   230             KMPXMediaArrayContents )->Count() )
       
   231             {
       
   232             // No results => Not duplicate
       
   233             iObserver.DuplicateL( EFalse );
       
   234             }
       
   235         else
       
   236             {
       
   237             iObserver.DuplicateL( ETrue );
       
   238             }                                
       
   239         }
       
   240     }
       
   241     
       
   242 // End of file
       
   243