mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/inc/mpxdbalbum.h
branchRCL_3
changeset 53 3de6c4cf6b67
child 56 2cbbefa9af78
equal deleted inserted replaced
52:14979e23cb5e 53:3de6c4cf6b67
       
     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).
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef MPXDBALBUM_H
       
    22 #define MPXDBALBUM_H
       
    23 
       
    24 // INCLUDES
       
    25 #include "mpxdbcategory.h"
       
    26 
       
    27 // CLASS DECLARATION
       
    28 
       
    29 class MMPXDbAlbumObserver
       
    30     {
       
    31     public:
       
    32         virtual TInt HandleIsUnknownArtistL(TUint32 aId) = 0;
       
    33         virtual HBufC* HandleArtistForAlbumL( const TUint32 aId ) = 0;
       
    34         /**
       
    35         * HandleAlbumartForAlbumL.
       
    36         * @param aId, The album ID.
       
    37         * @param aArt, The albumart uri.
       
    38         * @returns alternative albumart retrieved in the specified Album.
       
    39         */
       
    40         virtual HBufC* HandleAlbumartForAlbumL( const TUint32 aId, TPtrC aArt ) = 0;
       
    41     };
       
    42 /**
       
    43 * Responsible for managing all music databases
       
    44 *
       
    45 * @lib MPXDbPlugin.lib
       
    46 */
       
    47 
       
    48 class CMPXDbAlbum :
       
    49     public CMPXDbCategory
       
    50     {
       
    51     public:
       
    52 
       
    53         /**
       
    54         * Two-phased constructor.
       
    55         * @param aDbManager database manager to use for database interactions
       
    56         * @param aCategory identifies the category
       
    57         * @return New CMPXDbCategory instance.
       
    58         */
       
    59         static CMPXDbAlbum* NewL(CMPXDbManager& aDbManager,
       
    60             TMPXGeneralCategory aCategory, MMPXDbAlbumObserver& aObserver);
       
    61 
       
    62         /**
       
    63         * Two-phased constructor.
       
    64         * @param aDbManager database manager to use for database interactions
       
    65         * @param aCategory identifies the category
       
    66         * @return New CMPXDbCategory instance on the cleanup stack.
       
    67         */
       
    68         static CMPXDbAlbum* NewLC(CMPXDbManager& aDbManager,
       
    69             TMPXGeneralCategory aCategory, MMPXDbAlbumObserver& aObserver);
       
    70 
       
    71         /**
       
    72         * Destructor
       
    73         */
       
    74         virtual ~CMPXDbAlbum();
       
    75 
       
    76     public:
       
    77 
       
    78         /**
       
    79         * Add a category item. If the record already exists, its counter will
       
    80         * be incremented.
       
    81         * @param aName: This is the name to be entered into the row
       
    82         * @param aDriveId: The Drive Id the name (category) belongs
       
    83         * @param aNewRecord: indicates to the caller if a new record is created.
       
    84         *        ETrue if a new row is created in the table; otherwise EFalse.
       
    85         * @param aCaseSensitive indicates whether case sensitivity should be taken
       
    86         *        into consideration when generating the unique row id
       
    87         * @return The unique id of the row added.
       
    88         */
       
    89         TUint32 AddItemL(const TDesC& aName, const TDesC& aArtistName, const TDesC& aArt, TInt aDriveId, TBool& aNewRecord,
       
    90             TBool aCaseSensitive = ETrue);
       
    91 
       
    92         /**
       
    93         * Decrement the number of songs for the item. If the count gets to 0, remove
       
    94         * the item.
       
    95         * @param aId: The ID of the category to delete.
       
    96         * @param aDriveId: The drive Id the name (category) belongs to. Songs on different
       
    97         *                  drives may belong to the same album or artist; consequently, one
       
    98         *                  row for each artist/album id and drive ID pair will exist in the
       
    99         *                  lookup table with a count existing for each row that tracks the
       
   100         *                  number number of songs on that drive with that album/artist.
       
   101         * @param aItemChangedMessages if valid on return contains a deleted message if the
       
   102         *                  category was deleted
       
   103         * @param aItemExist Out parameter, ETrue if the category is not deleted after the delete,
       
   104         *        EFalse otherwise
       
   105         * @param aArtist: The ID of the artist
       
   106         * @param aArt: The albumart uri
       
   107         */
       
   108         void DecrementSongsForCategoryL(TUint32 aId, TInt aDriveId,
       
   109             CMPXMessageArray* aItemChangedMessages, TBool& aItemExist, const TUint32 aArtist, const TDesC& aArt );
       
   110 
       
   111         /**
       
   112     * Gets the details for all category items.
       
   113     * @param aAttrs attributes to be returned
       
   114     * @param aMediaArray returns the requested attributes for all items
       
   115     */
       
   116         void GetAllCategoryItemsL(const TArray<TMPXAttribute>& aAttrs,
       
   117             CMPXMediaArray& aMediaArray);
       
   118 
       
   119     /**
       
   120     * Update a category item.
       
   121     * @param aId: The ID of the category to update
       
   122     * @param aMedia: The media data
       
   123     * @param aDriveId: The Drive Id the name (category) belongs
       
   124     * @param aItemChangedMessages: if valid on return contains a updated message if the
       
   125     *        category was updated
       
   126     */
       
   127         void UpdateItemL(TUint32 aId, const CMPXMedia& aMedia, TInt aDriveId, CMPXMessageArray* aItemChangedMessages);
       
   128 
       
   129     public:
       
   130         /**
       
   131     * Get albums count for a specified artist
       
   132     * @param aId: The ID of the artist
       
   133     */
       
   134         TInt GetAlbumsCountForArtistL(TUint32 aArtistId);
       
   135 
       
   136         /**
       
   137     * Get songs count for a specified album and a specified artist
       
   138     * @param aArtistId: The ID of the artist
       
   139     * @param aAlbumId: The ID of the album
       
   140     */
       
   141         TInt GetSongsCountInAlbumMatchingArtistL(TUint32 aArtistId, TUint32 aAlbumId);
       
   142 
       
   143     private:
       
   144         /**
       
   145         * Updates the media with information from the table
       
   146         * @param aRecord record containing the source fields
       
   147         * @param aAttrs attributes to be returned
       
   148         * @param aMedia returns the requested attributes
       
   149         */
       
   150         void UpdateMediaL(RSqlStatement& aRecord, const TArray<TMPXAttribute>& aAttrs,
       
   151             CMPXMedia& aMedia);
       
   152 
       
   153          /**
       
   154         * Generate searching criteria for album table from the given criteria
       
   155         * @param aMedia media data
       
   156         * @param aFields fields of Album table
       
   157         * @param aValues values of each field of Album table
       
   158         * @return a string containing the selection criteria. The ownership is passed to the caller.
       
   159         */
       
   160         void GenerateAlbumFieldsValuesL(const CMPXMedia& aMedia,
       
   161             CDesCArray& aFields, CDesCArray& aValues);
       
   162 
       
   163 
       
   164         TBool IsUnknownArtistL(TUint32 aId);
       
   165 
       
   166         /**
       
   167         * Get the ArtistName of song which belongs to the specified Album.
       
   168         * @param aId The ID of the album
       
   169         * @returns alternative artistname retrieved in the specified Album.
       
   170         */
       
   171         HBufC* ArtistForAlbumL(const TUint32 aId);
       
   172         /**
       
   173         * Get the Albumart of song which belongs to the specified Album.
       
   174         * @param aId The ID of the album
       
   175         * @param aArt albumart with the song is deleted.
       
   176         * @returns alternative albumart retrieved in the specified Album.
       
   177         */
       
   178         HBufC* AlbumartForAlbumL(const TUint32 aId, TPtrC aArt);
       
   179         
       
   180         /**
       
   181         * Processes a recordset by constructing media instances and adding them
       
   182         * to the specified array.
       
   183         * @param aAttrs attributes to be returned
       
   184         * @param aRecordset recordset to be processed
       
   185         * @param aMediaArray returns the media instances
       
   186         */
       
   187         void ProcessAlbumRecordSetL(const TArray<TMPXAttribute>& aAttrs,
       
   188             RSqlStatement& aRecordset, CMPXMediaArray& aMediaArray);
       
   189 
       
   190     private:    // from MMPXTable
       
   191 
       
   192         /**
       
   193         * @see MMPXTable
       
   194         */
       
   195         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   196 
       
   197         /**
       
   198         * @see MMPXTable
       
   199         */
       
   200         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   201 
       
   202     private:
       
   203 
       
   204         /**
       
   205         * C++ constructor.
       
   206         * @param aDbManager database manager to use for database interactions
       
   207         * @param aCategory identifies the category
       
   208         */
       
   209         CMPXDbAlbum(CMPXDbManager& aDbManager, TMPXGeneralCategory aCategory, MMPXDbAlbumObserver& aObserver);
       
   210 
       
   211         /**
       
   212         * Second phase constructor.
       
   213         */
       
   214         void ConstructL();
       
   215 
       
   216     public:
       
   217 
       
   218         /**
       
   219         * Column indexes in the category tables
       
   220         */
       
   221         enum TAlbumColumns
       
   222             {
       
   223             EAlbumUniqueId = KMPXTableDefaultIndex,
       
   224             EAlbumArtistName,
       
   225             EAlbumName,
       
   226             EAlbumSongCount,      
       
   227             EAlbumArt,
       
   228             EAlbumFieldCount
       
   229             };
       
   230 
       
   231     private:    // Data
       
   232         MMPXDbAlbumObserver& iObserver;
       
   233     };
       
   234 #endif // MPXDBALBUM_H
       
   235 
       
   236 // End of File