mpserviceplugins/mpxsqlitedbhgplugin/inc/mpxdbabstractalbum.h
branchRCL_3
changeset 52 14979e23cb5e
equal deleted inserted replaced
50:26a1709b9fec 52:14979e23cb5e
       
     1 /*
       
     2 * Copyright (c) 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:  This class is responsible for all category tables (Artist,
       
    15 *                Album, Genre, Composer, AbstractAlbum).
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef MPXDBABSTRACTALBUM_H
       
    22 #define MPXDBABSTRACTALBUM_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <thumbnailmanager.h>
       
    26 #include <thumbnailmanagerobserver.h>
       
    27 #include "mpxdbcategory.h"
       
    28 
       
    29 
       
    30 // CLASS FORWARDS
       
    31 
       
    32 // CLASS DECLARATION
       
    33 
       
    34 /**
       
    35 * Responsible for managing all music databases
       
    36 *
       
    37 * @lib MPXDbPlugin.lib
       
    38 */
       
    39 
       
    40 class CMPXDbAbstractAlbum :
       
    41     public CMPXDbCategory,
       
    42     public MThumbnailManagerObserver
       
    43     {
       
    44     public:
       
    45 
       
    46         /**
       
    47         * Two-phased constructor.
       
    48         * @param aDbManager database manager to use for database interactions
       
    49         * @param aCategory identifies the category
       
    50         * @return New CMPXDbCategory instance.
       
    51         */
       
    52         static CMPXDbAbstractAlbum* NewL(CMPXDbManager& aDbManager,
       
    53             TMPXGeneralCategory aCategory, RFs& aFs);
       
    54 
       
    55         /**
       
    56         * Two-phased constructor.
       
    57         * @param aDbManager database manager to use for database interactions
       
    58         * @param aCategory identifies the category
       
    59         * @return New CMPXDbCategory instance on the cleanup stack.
       
    60         */
       
    61         static CMPXDbAbstractAlbum* NewLC(CMPXDbManager& aDbManager,
       
    62             TMPXGeneralCategory aCategory, RFs& aFs);
       
    63 
       
    64         /**
       
    65         * Destructor
       
    66         */
       
    67         virtual ~CMPXDbAbstractAlbum();
       
    68 
       
    69         /**
       
    70         * Find the drive Id for a abstractalbum
       
    71         * @param aAbstractAlbumId identifies the abstractalbum
       
    72         * @return corresponding drive id
       
    73         */
       
    74         TInt GetDriveIdL(TUint32 aAbstractAlbumId);
       
    75 
       
    76         /**
       
    77         * Add a category item. If the record already exists, its counter will
       
    78         * be incremented.
       
    79         * @param aName: This is the name to be entered into the row
       
    80         * @param aDriveId: The Drive Id the name (category) belongs
       
    81         * @param aNewRecord: indicates to the caller if a new record is created.
       
    82         *        ETrue if a new row is created in the table; otherwise EFalse.
       
    83         * @param aCaseSensitive indicates whether case sensitivity should be taken
       
    84         *        into consideration when generating the unique row id
       
    85         * @return The unique id of the row added.
       
    86         */
       
    87         TUint32 AddItemL( const TDesC& aUri, const TDesC& aName, const TDesC& aAlbumArtist, TInt aDriveId, TBool& aNewRecord,
       
    88             TBool aCaseSensitive = EFalse);
       
    89 
       
    90         /**
       
    91         *  Add existing item to table with same entry fields values except new Uri.
       
    92         * @param aOldId: existing item Id
       
    93         * @param newUri: new Uri
       
    94         * @return The unique id of the row added.
       
    95         */      
       
    96         TUint32 AddUpdatedItemL(TUint32 aOldId, const TDesC& newUri);
       
    97 
       
    98         /**
       
    99         * Decrement the number of songs for the item. If the count gets to 0, remove
       
   100         * the item.
       
   101         * @param aId: The ID of the category to delete.
       
   102         * @param aDriveId: The drive Id the name (category) belongs to. Songs on different
       
   103         *                  drives may belong to the same album or artist; consequently, one
       
   104         *                  row for each artist/album id and drive ID pair will exist in the
       
   105         *                  lookup table with a count existing for each row that tracks the
       
   106         *                  number number of songs on that drive with that album/artist.
       
   107         * @param aItemChangedMessages if valid on return contains a deleted message if the
       
   108         *                  category was deleted
       
   109         * @param aItemExist Out parameter, ETrue if the category is not deleted after the delete,
       
   110         *        EFalse otherwise
       
   111         */
       
   112         void DecrementSongsForCategoryL(TUint32 aId, TInt aDriveId,
       
   113             CMPXMessageArray* aItemChangedMessages, TBool& aItemExist, TBool aMtpInUse);
       
   114         
       
   115         /**
       
   116         * Remove a abstractalbum, remove entry from AbstractAlbum table, 
       
   117         * Thumbnail table, corresponding alb from file system
       
   118         * @param aAbstractAlbumId ID of the abstractalbum to remove
       
   119         * @param aItemChangedMessages a list of change events as a result of the
       
   120         *        abstractalbum removal
       
   121         * @param aFileDeleted indicate if alb file already deleted from file system
       
   122         */
       
   123         void RemoveAbstractAlbumL(TUint32 aAbstractalbumId, 
       
   124             CMPXMessageArray& aItemChangedMessages, TBool aFileDeleted);
       
   125         
       
   126         /**
       
   127         * Update a category item.
       
   128         * @param aId: The ID of the category to update
       
   129         * @param aMedia: The media data
       
   130         * @param aDriveId: The Drive Id the name (category) belongs
       
   131         * @param aItemChangedMessages: if valid on return contains a updated message if the
       
   132         *        category was updated
       
   133         */
       
   134         void UpdateItemL(TUint32 aId, const CMPXMedia& aMedia, TInt aDriveId, CMPXMessageArray* aItemChangedMessages);
       
   135           
       
   136         /**
       
   137         * Delete or Rename Thumbnail from TN DB by calling Thumbnail manager
       
   138         * Rename Thumbnail if aNewPath is not NULL, otherwise Delete Thumbnail
       
   139         * @param aOldPath: old Uri
       
   140         * @param aNewPath: new Uri
       
   141         * @param aPriority: priority pass to Thumbnail manager
       
   142         */
       
   143         void HandleTNL( const TDesC& aOldPath, const TDesC& aNewPath = KNullDesC, TInt aPriority =0 );
       
   144 
       
   145         /**
       
   146         * Get the uri field for a given ID.
       
   147         * @param aId identifies the abstractalbum item
       
   148         * @return uri that matches aId. Ownership is abandoned.
       
   149         */
       
   150         HBufC* GetUriL(TUint32 aId);
       
   151 
       
   152         /**
       
   153         * Get Ids of albstractalbum with no song associated.
       
   154         * Rename Thumbnail if aNewPath is not NULL, otherwise Delete Thumbnail
       
   155         * @param aItemsIds: array of Ids for abstractalbums which have no song associated.
       
   156         */
       
   157         void GetAllItemsWithNoSongL(RArray<TUint32>& aItemsIds);
       
   158 
       
   159         /**
       
   160         * Create Thumbnail Manager session.
       
   161         * Create Thumbnail Manager session when needed: rename/delete entries in Thumbnail table.
       
   162         */
       
   163         void CreateTNMSessionL();
       
   164         
       
   165         /**
       
   166         * Remove all abstractalbum items with no songs associated,
       
   167         * TN entry and .alb files also removed.
       
   168         *
       
   169         */
       
   170         void RemoveAbstractAlbumsWithNoSongL();
       
   171         
       
   172         /**
       
   173         /* When refresh library, Remove .alb entry from AbstractAlnum table, TN table if .alb files already deleted 
       
   174         /* from file system via file manager.
       
   175         */
       
   176         void AbstractAlbumCleanUpL();
       
   177        
       
   178     private:
       
   179 
       
   180 
       
   181         /**
       
   182         * Updates the media with information from the table
       
   183         * @param aRecord record containing the source fields
       
   184         * @param aAttrs attributes to be returned
       
   185         * @param aMedia returns the requested attributes
       
   186         */
       
   187         void UpdateMediaL(RSqlStatement& aRecord, const TArray<TMPXAttribute>& aAttrs,
       
   188             CMPXMedia& aMedia);
       
   189 
       
   190         /**
       
   191         * Generate searching criteria for album table from the given criteria
       
   192         * @param aMedia media data
       
   193         * @param aFields fields of Album table
       
   194         * @param aValues values of each field of Album table
       
   195         * @return a string containing the selection criteria. The ownership is passed to the caller.
       
   196         */
       
   197         void GenerateAbstractAlbumFieldsValuesL(const CMPXMedia& aMedia,
       
   198             CDesCArray& aFields, CDesCArray& aValues);
       
   199         
       
   200         /**
       
   201         * Remove a abstractalbum from AbstractAlbum table
       
   202         * @param aAbstractAlbumId identifies the abstractalbum
       
   203         * @param aDriveId drive Id
       
   204         */
       
   205         void DeleteAbstractAlbumEntryL(TUint32 aAbstractAlbumId,  TInt aDriveId = 0);
       
   206         
       
   207 
       
   208         /**
       
   209         * @see MMPXTable
       
   210         */
       
   211         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   212 
       
   213         /**
       
   214         * @see MMPXTable
       
   215         */
       
   216         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   217 
       
   218         /**
       
   219         * C++ constructor.
       
   220         * @param aDbManager database manager to use for database interactions
       
   221         * @param aCategory identifies the category
       
   222         */
       
   223         CMPXDbAbstractAlbum(CMPXDbManager& aDbManager, TMPXGeneralCategory aCategory, RFs& aFs);
       
   224 
       
   225         /**
       
   226         * Second phase constructor.
       
   227         */
       
   228         void ConstructL();
       
   229 
       
   230         /**
       
   231         * MThumbnailManagerObserver
       
   232         */
       
   233         void ThumbnailPreviewReady(
       
   234             MThumbnailData& aThumbnail, TThumbnailRequestId aId );
       
   235         /**
       
   236         * MThumbnailManagerObserver
       
   237         */
       
   238         void ThumbnailReady(
       
   239             TInt aError,
       
   240             MThumbnailData& aThumbnail, TThumbnailRequestId aId );
       
   241 
       
   242     public:
       
   243 
       
   244         /**
       
   245         * Column indexes in the category tables
       
   246         */
       
   247         enum TAbstractAlbumColumns
       
   248             {
       
   249             EAbstractAlbumUniqueId = KMPXTableDefaultIndex,
       
   250             EAbstractAlbumUri,
       
   251             EAbstractAlbumName,
       
   252             EAbstractAlbumArtist,
       
   253             EAbstractAlbumSongCount,
       
   254             EAbstractAlbumVolumeId,
       
   255             EAbstractAlbumFieldCount
       
   256             };
       
   257 
       
   258     private:    // Data
       
   259         CThumbnailManager*        iTNManager;
       
   260         TBool                     iRenameTN;
       
   261         RFs&                      iFs;
       
   262 
       
   263     };
       
   264 #endif // MPXDBAbstractAlbum_H
       
   265 
       
   266 // End of File