mpserviceplugins/mpxsqlitedbhgplugin/inc/mpxdbmusic.h
changeset 22 ecf06a08d4d9
child 25 3ec52facab4d
equal deleted inserted replaced
20:82baf59ce8dd 22:ecf06a08d4d9
       
     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 music table functionality.
       
    15 *                The Music table contains one record for each song on the database
       
    16 *                drive.
       
    17 *
       
    18 *
       
    19 */
       
    20 
       
    21 
       
    22 #ifndef MPXDBMUSIC_H
       
    23 #define MPXDBMUSIC_H
       
    24 
       
    25 // INCLUDES
       
    26 #include "mpxdbtable.h"
       
    27 #include "mpxdbcommonstd.h"
       
    28 #include "mpxdbactivetask.h"
       
    29 
       
    30 // CLASS FORWARDS
       
    31 class CMPXMedia;
       
    32 class CMPXMediaArray;
       
    33 
       
    34 // CLASS DECLARATION
       
    35 
       
    36 /**
       
    37 * Observer interface for handling the category ID functionality.
       
    38 * This is needed because the incoming CMPXMedia parameters in Add and Update methods
       
    39 * contain the names for the category items and the music table has to use IDs linking
       
    40 * to the category tables. Using this interface removes the dependency to the category
       
    41 * class.
       
    42 *
       
    43 * Note that this interface is only used when information is written to the Music table,
       
    44 * when information is retrieved the query takes care of also retrieving the names from
       
    45 * the corresponding category tables so the outgoing CMPXMedia will contain the correct
       
    46 * information.
       
    47 */
       
    48 class MMPXDbMusicObserver
       
    49     {
       
    50     public:
       
    51 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
    52         /**
       
    53         * Called when a new category item has to be added to a category table.
       
    54         * @param aCategory category type
       
    55         * @param aName name string
       
    56         * @param aDrive drive to add the category to
       
    57         * @param aItemChangedMessages changed mesages array to be updated or NULL
       
    58         * @param aItemExist Out parameter, ETrue if the item already exist before the add,
       
    59         *        EFalse otherwise
       
    60         * @param aAlbumArtist AlbumArtist string
       
    61         * @param aGenre Genre string
       
    62         * @return the ID of the category item (new or existing)
       
    63         */
       
    64         virtual TUint32 AddCategoryItemL(TMPXGeneralCategory aCategory, const TDesC& aName,
       
    65             TInt aDrive, CMPXMessageArray* aItemChangedMessages, TBool& aItemExist, const TDesC& aAlbumArtist=KNullDesC,
       
    66             const TDesC& aGenre=KNullDesC) = 0;
       
    67 #else
       
    68         /**
       
    69         * Called when a new category item has to be added to a category table.
       
    70         * @param aCategory category type
       
    71         * @param aName name string
       
    72         * @param aDrive drive to add the category to
       
    73         * @param aItemChangedMessages changed mesages array to be updated or NULL
       
    74         * @param aItemExist Out parameter, ETrue if the item already exist before the add,
       
    75         *        EFalse otherwise
       
    76         * @return the ID of the category item (new or existing)
       
    77         */
       
    78         virtual TUint32 AddCategoryItemL(TMPXGeneralCategory aCategory, const TDesC& aName,
       
    79             TInt aDrive, CMPXMessageArray* aItemChangedMessages, TBool& aItemExist) = 0;
       
    80 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
    81        // for Album and Artist table
       
    82         virtual TUint32 AddCategoryItemL(TMPXGeneralCategory aCategory, const TDesC& aName,
       
    83             TUint32 aArtistId, const TDesC& aArt,
       
    84             TInt aDrive, CMPXMessageArray* aItemChangedMessages, TBool& aItemExist) = 0;
       
    85         /**
       
    86         * Called when the ID of a category item changed for a Music record, for example when
       
    87         * the artist name changed for a song. The implementation is supposed to update the
       
    88         * category record and add corresponding item changed messages to the array parameter.
       
    89         * @param aCategory category type
       
    90         * @param aCategoryId old category item ID
       
    91         * @param aDrive drive the category item is on
       
    92         * @param aItemChangedMessages changed mesages array to be updated or NULL
       
    93         * @param aItemExist Out parameter, ETrue if the category is not deleted after the delete,
       
    94         *        EFalse otherwise
       
    95         */
       
    96         virtual void DeleteSongForCategoryL(TMPXGeneralCategory aCategory, TUint32 aCategoryId,
       
    97             TInt aDrive, CMPXMessageArray* aItemChangedMessages, TBool& aItemExist) = 0;
       
    98 
       
    99         /**
       
   100         * Called when the play count attribute of a song is changed. Should add an item changed
       
   101         * message to the array.
       
   102         * @param aItemChangedMessages array of item changed messages to add to
       
   103         */
       
   104         virtual void HandlePlayCountModifiedL(CMPXMessageArray& aItemChangedMessages) = 0;
       
   105 
       
   106         /**
       
   107         * Called when the playback time attribute of a song is changed. Should add an item changed
       
   108         * message to the array.
       
   109         * @param aItemChangedMessages array of item changed messages to add to
       
   110         */
       
   111         virtual void HandlePlaybackTimeModifiedL(CMPXMessageArray& aItemChangedMessages) = 0;
       
   112 
       
   113         /**
       
   114          * Called when category item is changed. Should add an item changed
       
   115          * message to the array.
       
   116          * @param aCategory category type
       
   117          * @param aCategoryId old category item ID
       
   118          * @param aDrive drive the category item is on
       
   119          * @param aMedia media data
       
   120          * @param aItemChangedMessages changed mesages array to be updated or NULL
       
   121          */
       
   122         virtual void UpdateCategoryItemL(TMPXGeneralCategory aCategory, TUint32 aCategoryId,
       
   123              const CMPXMedia& aMedia, TInt aDrive, CMPXMessageArray* aItemChangedMessages) = 0;
       
   124 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
   125         /**
       
   126         * Get title from the Id
       
   127         * @param Id to search for
       
   128         * @return name matching the ID
       
   129         */
       
   130         virtual HBufC* HandleGetAlbumNameFromIdL( TUint32 aId ) = 0;
       
   131 #endif // ABSTRACTAUDIOALBUM_INCLUDED    
       
   132 	};
       
   133 
       
   134 /**
       
   135 * Responsible for managing the Music table
       
   136 *
       
   137 * @lib MPXDbPlugin.lib
       
   138 */
       
   139 class CMPXDbMusic :
       
   140     public CMPXDbTable
       
   141     {
       
   142     public:
       
   143 
       
   144         /**
       
   145         * Two-phased constructor.
       
   146         * @param aDbManager database manager to use for database interactions
       
   147         * @param aObserver observer reference
       
   148         * @return New CMPXDbMusic instance.
       
   149         */
       
   150         static CMPXDbMusic* NewL(CMPXDbManager& aDbManager, CMPXResource& aResource,
       
   151             MMPXDbMusicObserver& aObserver);
       
   152 
       
   153         /**
       
   154         * Two-phased constructor.
       
   155         * @param aDbManager database manager to use for database interactions
       
   156         * @param aObserver observer reference
       
   157         * @return New CMPXDbMusic instance on the cleanup stack.
       
   158         */
       
   159         static CMPXDbMusic* NewLC(CMPXDbManager& aDbManager, CMPXResource& aResource,
       
   160             MMPXDbMusicObserver& aObserver);
       
   161 
       
   162         /**
       
   163         * Destructor
       
   164         */
       
   165         virtual ~CMPXDbMusic();
       
   166 
       
   167     public:
       
   168 
       
   169         /**
       
   170         * Add a song to the music table
       
   171         * @param aMedia contains the song details
       
   172         * @param aDrive drive to add the song to
       
   173         * @param aMessageArray change event message to notify client of the changes
       
   174         * @return The unique ID of the song added.
       
   175         */
       
   176         TUint32 AddSongL(const CMPXMedia& aMedia, TInt aDrive, CMPXMessageArray* aMessageArray=NULL);
       
   177 
       
   178         /**
       
   179         * Remove a song from the music table
       
   180         * @param aSongId the ID of the song to be removed
       
   181         * @param aDrive song drive
       
   182         * @param aDeleteRecord indicates whether the client has explictly requested
       
   183         *                to delete the records from the database. If ETrue, records
       
   184         *                associated with the media will be deleted from the database;
       
   185         *                if EFalse, whether to mark the records as deleted or to delete
       
   186         *                the records will be based on other deciding factors.
       
   187         */
       
   188         void DeleteSongL(TUint32 aSongId, TInt aDrive, TBool aDeleteRecord = EFalse);
       
   189 
       
   190         /**
       
   191         * Remove songs matching a category from the music table
       
   192         * @param aCategory the category to remove
       
   193         * @param aCategoryId ID of the category to remove
       
   194         * @param aUriArray on return will be filled with all the paths that were removed
       
   195         * @param aItemChangedMessages a list of change events as a result of the song removal
       
   196         * @param aDrive drive the category record is on
       
   197         */
       
   198         void DeleteCategoryL(TMPXGeneralCategory aCategory, TUint32 aCategoryId,
       
   199             CDesCArray& aUriArray, CMPXMessageArray& aItemChangedMessages, TInt aDrive);
       
   200 
       
   201         /**
       
   202         * Deletes all songs marked as deleted
       
   203         */
       
   204         void CleanupL();
       
   205 
       
   206         /**
       
   207         * Update song info for a song in the music table
       
   208         * @param aSongId song ID
       
   209         * @param aMedia media object which contains file path,
       
   210         *                artist, composer, name(title), track, etc...
       
   211         * @param aItemChangedMessages a list of change events as a result of the song removal
       
   212         * @return ETrue if the change is visible in the UI
       
   213         */
       
   214         CMPXDbActiveTask::TChangeVisibility UpdateSongL(TUint32 aSongId, const CMPXMedia& aMedia,
       
   215             CMPXMessageArray& aItemChangedMessages);
       
   216 
       
   217         /**
       
   218         * Get the name of the song that matches the given song ID
       
   219         * @param aSongId ID of the song
       
   220         * @return Song name, ownership is transferred to the caller.
       
   221         */
       
   222         HBufC* GetNameL(TUint32 aSongId);
       
   223 
       
   224         /**
       
   225         * Get URI of the song
       
   226         * @param aSongId ID of the song
       
   227         * @return Song URI, ownership is transferred to the caller.
       
   228         */
       
   229         HBufC* GetUriL(TUint32 aSongId);
       
   230 
       
   231         /**
       
   232         * Get the drive of the song
       
   233         * @param aSongId ID of the song
       
   234         * @return Song drive
       
   235         */
       
   236         TInt GetDriveL(TUint32 aSongId);
       
   237 
       
   238 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
   239         /**
       
   240         * Get the drive and category IDs for a specified song
       
   241         * @param aSongId song to be retrieved
       
   242         * @param aArtistId returns the artist ID
       
   243         * @param aAlbumId returns the artist ID
       
   244         * @param aGenreId returns the artist ID
       
   245         * @param aComposerId returns the artist ID
       
   246         * @param aAbstractAlbumId returns the AbstractAlbum ID
       
   247         * @param aDriveId returns the song drive
       
   248         * @return song URI. The ownership is transferred.
       
   249         */
       
   250         HBufC* GetSongInfoL(TUint32 aSongId, TUint32& aArtistId, TUint32& aAlbumId,
       
   251             TUint32& aGenreId, TUint32& aComposerId, TUint32& aAbstractAlbumId, TInt& aDriveId);
       
   252 #else 
       
   253         /**
       
   254         * Get the drive and category IDs for a specified song
       
   255         * @param aSongId song to be retrieved
       
   256         * @param aArtistId returns the artist ID
       
   257         * @param aAlbumId returns the artist ID
       
   258         * @param aGenreId returns the artist ID
       
   259         * @param aComposerId returns the artist ID
       
   260         * @param aDriveId returns the song drive
       
   261         * @return song URI. The ownership is transferred.
       
   262         */
       
   263         HBufC* GetSongInfoL(TUint32 aSongId, TUint32& aArtistId, TUint32& aAlbumId,
       
   264             TUint32& aGenreId, TUint32& aComposerId, TInt& aDriveId);
       
   265 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
   266         /**
       
   267         * Get the song Id, title, URI, and general flags from the given song Id and/or URI
       
   268         * @param aCriteria search the media by song Id and/or URI
       
   269         * @param aMedia returns the song details
       
   270         * @return error code KErrNotFound if unable to find the specified song in the
       
   271         *          collection; otherwise KErrNone
       
   272         */
       
   273         TInt GetSongL(const CMPXMedia& aCriteria, CMPXMedia*& aMedia);
       
   274 
       
   275         /**
       
   276         * Get the most recently played songs. Returns a maximum of KMPXMaxRecentlyPlayedSongs
       
   277         * songs.
       
   278         * @param aAttrs attributes to include
       
   279         * @param aMediaArray returns the songs' info
       
   280         */
       
   281         void GetRecentlyPlayedSongsL(const TArray<TMPXAttribute>& aAttrs,
       
   282             CMPXMediaArray& aMediaArray);
       
   283 
       
   284         /**
       
   285         * Get the most played songs from the music table. Returns a maximum of
       
   286         * KMPXMaxMostPlayedSongs songs.
       
   287         * @param aAttrs attributes to include
       
   288         * @param aMediaArray returns the songs' info
       
   289         */
       
   290         void GetMostPlayedSongsL(const TArray<TMPXAttribute>& aAttrs,
       
   291             CMPXMediaArray& aMediaArray);
       
   292 
       
   293         /**
       
   294         * Get the recently added songs from the music table (7 days)
       
   295         * @param aAttrs attributes to include
       
   296         * @param aMediaArray returns the songs' info
       
   297         */
       
   298         void GetRecentlyAddedSongsL(const TArray<TMPXAttribute>& aAttrs,
       
   299             CMPXMediaArray& aMediaArray);
       
   300 
       
   301        /**
       
   302         * Get the total number of songs
       
   303         * @return total number of songs
       
   304         */
       
   305         TInt CountL();
       
   306 
       
   307         /**
       
   308         * Get all the albums for a specified artist
       
   309         * @param aArtistId artist ID
       
   310         * @param aMediaArray returns the album(s) matching the artist
       
   311         */
       
   312         void GetAlbumsForArtistL(TUint32 aArtistId, CMPXMediaArray& aMediaArray);
       
   313 
       
   314         /**
       
   315         * Returns details about the specified song.
       
   316         * @param aSongId identifies the song
       
   317         * @param aAttrs attributes to be retrieved
       
   318         * @param aMedia returns the song information
       
   319         */
       
   320         void GetSongL(TInt aSongId, const TArray<TMPXAttribute>& aAttrs, CMPXMedia& aMedia);
       
   321         
       
   322         /**
       
   323         * Returns all songs in the playlist.
       
   324         * @param aDrive identifies in db
       
   325         * @param aPlaylistId identifies the playlist
       
   326         * @param aAttrs attributes to be retrieved
       
   327         * @param aMediaArray returns the song attributes.
       
   328         */
       
   329         void GetAllSongsL(TInt aDrive,TInt aPlaylistId,const TArray<TMPXAttribute>& aAttrs,
       
   330             CMPXMediaArray& aMediaArray);
       
   331 
       
   332         /**
       
   333         * Returns all songs in the database.
       
   334         * @param aAttrs attributes to be retrieved
       
   335         * @param aMediaArray returns the song attributes.
       
   336         */
       
   337         void GetAllSongsL(const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   338 
       
   339         /**
       
   340         * Get from all songs with a limit (first N items)
       
   341         * @param aAttrs attributes to be retrieved
       
   342         * @param aMediaArray returns the song attributes.
       
   343         * @param aLimit maximum number of songs to retrieve
       
   344         */
       
   345         void GetAllSongsLimitedL(const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray, TInt aLimit);
       
   346 
       
   347         /**
       
   348         * Returns a block of songs as specified
       
   349         * @param aAttrs attributes to be retrieved
       
   350         * @param aMediaArray returns the song attributes.
       
   351         * @param aTitle title of the song that marks the beginning of the block
       
   352         * @param aNumOfSongs the number of songs in the block
       
   353         * @param aAsc
       
   354         */
       
   355         void GetSongsInBlockL( const TArray<TMPXAttribute>& aAttrs,
       
   356                                CMPXMediaArray& aMediaArray,
       
   357                                TPtrC aTitle,
       
   358                                TUint aNumOfSongs,
       
   359                                TBool aAsc);
       
   360 
       
   361 
       
   362         /**
       
   363         * Get songs from the music collection starting at a particular offset
       
   364         * ONLY use this as the first query to locate particular item. Should use
       
   365         * GetSongsInBlockL() to fetch in blocks with a particular index
       
   366         * @param aMediaArray Array to store the results
       
   367         * @param aAttrs attributes to fetch
       
   368         * @param aOffset offset to start reading
       
   369         * @param aCount number of items to get
       
   370         */
       
   371         void GetSongsAtOffsetL( CMPXMediaArray& aMediaArray,
       
   372                                 const TArray<TMPXAttribute>& aAttrs,
       
   373                                 TInt aOffset,
       
   374                                 TInt aCount );
       
   375 
       
   376         /**
       
   377         * Returns all songs for a given artist.
       
   378         * @param aArtistId artist to get the songs for
       
   379         * @param aAttrs attributes to be retrieved
       
   380         * @param aMediaArray returns the song attributes.
       
   381         */
       
   382         void GetSongsForArtistL(TUint aArtistId, const TArray<TMPXAttribute>& aAttrs,
       
   383             CMPXMediaArray& aMediaArray);
       
   384 
       
   385         /**
       
   386         * Returns all songs for a given album.
       
   387         * @param aAlbumId album to get the songs for
       
   388         * @param aAttrs attributes to be retrieved
       
   389         * @param aMediaArray returns the song attributes.
       
   390         */
       
   391         void GetSongsForAlbumL(TUint aAlbumId, const TArray<TMPXAttribute>& aAttrs,
       
   392             CMPXMediaArray& aMediaArray);
       
   393 
       
   394         /**
       
   395         * Returns all songs for a given artist and album.
       
   396         * @param aArtistId artist to get the songs for
       
   397         * @param aAlbumId album to get the songs for
       
   398         * @param aAttrs attributes to be retrieved
       
   399         * @param aMediaArray returns the song attributes.
       
   400         */
       
   401         void GetSongsForArtistAndAlbumL(TUint aArtistId, TUint aAlbumId,
       
   402             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   403 
       
   404         /**
       
   405         * Returns all songs for a given genre.
       
   406         * @param aGenreId genre to get the songs for
       
   407         * @param aAttrs attributes to be retrieved
       
   408         * @param aMediaArray returns the song attributes.
       
   409         */
       
   410         void GetSongsForGenreL(TUint aGenreId, const TArray<TMPXAttribute>& aAttrs,
       
   411             CMPXMediaArray& aMediaArray);
       
   412 
       
   413         /**
       
   414         * Returns all songs for a given composer.
       
   415         * @param aComposerId composer to get the songs for
       
   416         * @param aAttrs attributes to be retrieved
       
   417         * @param aMediaArray returns the song attributes.
       
   418         */
       
   419         void GetSongsForComposerL(TUint aComposerId, const TArray<TMPXAttribute>& aAttrs,
       
   420             CMPXMediaArray& aMediaArray);
       
   421 
       
   422 
       
   423 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
   424 	    /**
       
   425         * Returns all songs for a given abstractalbum.
       
   426         * @param aDrive drive ID AbstractAlbum stored
       
   427         * @param aAbstractAlbumId abstractalbum to get the songs for
       
   428         * @param aAttrs attributes to be retrieved
       
   429         * @param aMediaArray returns the song attributes.
       
   430         */
       
   431         void GetAllSongsForAbstractAlbumL(TInt aDrive, TInt aAbstractAlbumId,
       
   432             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   433 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
   434         /**
       
   435         * Returns the duration of all songs.
       
   436         * @return the duration value
       
   437         */
       
   438         TInt AllSongsDurationL();
       
   439 
       
   440         /**
       
   441         * Returns the duration for a specified artist.
       
   442         * @param aArtistId artist to get the duration for
       
   443         * @return the duration value
       
   444         */
       
   445         TInt ArtistDurationL(TUint aArtistId);
       
   446 
       
   447         /**
       
   448         * Returns the duration for a specified album.
       
   449         * @param aAlbumId album to get the duration for
       
   450         * @return the duration value
       
   451         */
       
   452         TInt AlbumDurationL(TUint aAlbumId);
       
   453 
       
   454         /**
       
   455         * Returns the duration for a specified artist and album.
       
   456         * @param aArtistId artist to get the duration for
       
   457         * @param aAlbumId album to get the duration for
       
   458         * @return the duration value
       
   459         */
       
   460         TInt ArtistAlbumDurationL(TUint aArtistId, TUint aAlbumId);
       
   461 
       
   462         /**
       
   463         * Returns the duration for a specified genre.
       
   464         * @param aGenreId genre to get the duration for
       
   465         * @return the duration value
       
   466         */
       
   467         TInt GenreDurationL(TUint aGenreId);
       
   468 
       
   469         /**
       
   470         * Returns the duration for a specified composer.
       
   471         * @param aComposerId composer to get the duration for
       
   472         * @return the duration value
       
   473         */
       
   474         TInt ComposerDurationL(TUint aComposerId);
       
   475 
       
   476         /**
       
   477         * Returns the duration for the recently played songs.
       
   478         * @return the duration value
       
   479         */
       
   480         TInt RecentlyPlayedDurationL();
       
   481 
       
   482         /**
       
   483         * Returns the duration for the most played songs.
       
   484         * @return the duration value
       
   485         */
       
   486         TInt MostPlayedDurationL();
       
   487 
       
   488         /**
       
   489         * Returns the duration for the recently added songs.
       
   490         * @return the duration value
       
   491         */
       
   492         TInt RecentlyAddedDurationL();
       
   493 
       
   494         /**
       
   495         * Find the songs for the selection criteria
       
   496         * @param aGeneralId selection criteria (could be song/album/artist/genre/composer ID)
       
   497         * @param aContainerId selection criteria (could be artist/album id)
       
   498         * @param aType criteria type (EMPXItem or EMPXGroup)
       
   499         * @param aCriteria selection criteria
       
   500         * @param aAttrs the attributes to include for the artist(s) matching the
       
   501         *        selection criteria
       
   502         * @param aMediaArray returns the songs
       
   503         */
       
   504         void FindSongsL(TUint32 aGeneralId, TUint32 aContainerId, TMPXGeneralType aType,
       
   505             const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs,
       
   506             CMPXMediaArray& aMediaArray);
       
   507 
       
   508         /**
       
   509         * Returns the track count for a given drive
       
   510         * @param aDrive drive
       
   511         * @return the count
       
   512         */
       
   513         TUint GetDriveTrackCountL(TInt aDrive);
       
   514 
       
   515         /**
       
   516         * Get URIs for a given number of tracks
       
   517         * @param aDrive, specifies drive number for db selection
       
   518         * @param aFromID, specifies unique ID of last record retrieved
       
   519         * @param aRecords, specifies the number of records to get
       
   520         * @param aUriArr, will contain all URIs on return
       
   521         * @param aLastID, will contain unique ID of a last record in the array
       
   522         */
       
   523         void GetMusicUriArrayL(TInt aDrive, TInt aFromID, TInt aRecords,
       
   524                                CDesCArray& aUriArr, TInt& aLastID);
       
   525 
       
   526         /**
       
   527          * Get the ID of Artist which belongs to the specified Album
       
   528 		 * @param aId, the ID of Album
       
   529          */
       
   530         TUint32 CMPXDbMusic::ArtistForAlbumL(const TUint32 aId);
       
   531         
       
   532         /**
       
   533         * Signals the start of a refresh operation
       
   534         */
       
   535         void RefreshStartL();
       
   536 
       
   537         /**
       
   538         * Signals the end of a refresh operation
       
   539         */
       
   540         void RefreshEndL();
       
   541 
       
   542         /*
       
   543         * Refresh music basic table
       
   544         */
       
   545         void RefreshBasicTableL();
       
   546 
       
   547         /*
       
   548         * Check the integrity of the music basic table
       
   549         */
       
   550         void CheckMusicBasicTableL();
       
   551 
       
   552     private:
       
   553 
       
   554         /**
       
   555         * Checks if the specified song exists.
       
   556         * @param aId identifies the song
       
   557         * @return ETrue if it exists, EFalse otherwise
       
   558         */
       
   559         TBool SongExistsL(TUint32 aSongId);
       
   560 
       
   561         /**
       
   562         * Update the media with information found in the Music table
       
   563         * @param aMusicTable music table record
       
   564         * @param aAttrs the attributes to include
       
   565         * @param aMedia returns the song details
       
   566         */
       
   567         void UpdateMediaL(RSqlStatement& aMusicTable, const TArray<TMPXAttribute>& aAttrs,
       
   568             CMPXMedia& aMedia);
       
   569 
       
   570         /**
       
   571         * Update the media general attributes from the Music table
       
   572         * @param aMusicTable music table view
       
   573         * @param aAttrId the required attributes
       
   574         * @param aMedia the media object to set
       
   575         */
       
   576         void UpdateMediaGeneralL(RSqlStatement& aMusicTable, const TUint aAttrId,
       
   577             CMPXMedia& aMedia);
       
   578 
       
   579         /**
       
   580         * Update the media music attributes from the Music table
       
   581         * @param aMusicTable music table view
       
   582         * @param aAttrId the required attributes
       
   583         * @param aMedia the media object to set
       
   584         */
       
   585         void UpdateMediaMusicL(RSqlStatement& aMusicTable, const TUint aAttrId,
       
   586             CMPXMedia& aMedia);
       
   587 
       
   588         /**
       
   589         * Update the media audio attributes from the Music table
       
   590         * @param aMusicTable music table view
       
   591         * @param aAttrId the required attributes
       
   592         * @param aMedia the media object to set
       
   593         */
       
   594         void UpdateMediaAudioL(RSqlStatement& aMusicTable, const TUint aAttrId,
       
   595             CMPXMedia& aMedia);
       
   596 
       
   597         /**
       
   598         * Update the media MTP attributes from the Music table
       
   599         * @param aMusicTable music table view
       
   600         * @param aAttrId the required attributes
       
   601         * @param aMedia the media object to set
       
   602         */
       
   603         void UpdateMediaMTPL(RSqlStatement& aMusicTable, const TUint aAttrId,
       
   604             CMPXMedia& aMedia);
       
   605 
       
   606         /**
       
   607         * Adds a song to the Music table
       
   608         * @param aSongId identifies the song
       
   609         * @param aMedia contains the song attributes
       
   610         * @param aDrive drive to add the song to
       
   611         * @param aItemChangedMessages item changed messages to update
       
   612         */
       
   613         TBool DoAddSongL(TUint32 aSongId, const CMPXMedia& aMedia, TInt aDrive,
       
   614             CMPXMessageArray* aItemChangedMessages);
       
   615 
       
   616         /**
       
   617         * Updates a song in the Music table
       
   618         * @param aSongId identifies the song
       
   619         * @param aMedia contains the song attributes
       
   620         * @param aItemChangedMessages item changed messages to update or NULL
       
   621         */
       
   622         CMPXDbActiveTask::TChangeVisibility DoUpdateSongL(TUint32 aSongId, const CMPXMedia& aMedia,
       
   623             CMPXMessageArray* aItemChangedMessages);
       
   624 
       
   625         /**
       
   626         * Updates a song in the Music table
       
   627         * @param aSongId identifies the song
       
   628         * @param aMedia contains the song attributes
       
   629         * @param aDrive drive to add the song to
       
   630         * @param aItemChangedMessages item changed messages to update
       
   631         * @param aRecordset current song record in the Music table.
       
   632         *       Required to detect any field changes.
       
   633         */
       
   634         CMPXDbActiveTask::TChangeVisibility DoUpdateSongL(TUint32 aSongId, const CMPXMedia& aMedia, TInt aDrive,
       
   635             CMPXMessageArray* aItemChangedMessages, RSqlStatement& aRecordset);
       
   636 
       
   637         /**
       
   638         * Get the DRM type of the given file
       
   639         * @param aFile file
       
   640         * @return DRM type.
       
   641         */
       
   642         TMCDrmType DRMTypeL(const TDesC& aFile);
       
   643 
       
   644         /**
       
   645         * Generate searching criteria for music table from the given criteria
       
   646         * @param aGeneralId selection criteria (could be song/album/artist/genre/composer Id)
       
   647         * @param aContainerId selection criteria (could be artist/album id)
       
   648         * @param aType criteria type (EMPXItem or EMPXGroup)
       
   649         * @param aCriteria input criteria
       
   650         * @return a string containing the selection criteria. The ownership is passed to the caller.
       
   651         */
       
   652         HBufC* GenerateMusicMatchingCriteriaLC(TUint32 aGeneralId, TUint32 aContainerId,
       
   653             TMPXGeneralType aType, const CMPXMedia& aCriteria);
       
   654 
       
   655         /**
       
   656         * Constructs the fields and corresponding values to be written into the music
       
   657         * table for update and insert statements.
       
   658         * @param aSongId identifies the song
       
   659         * @param aMedia contains the new song attributes
       
   660         * @param aItemChangedMessages item changed mesages to add to
       
   661         * @param aMusicTable points to the existing record in the Music table for updates or NULL
       
   662         *       for inserts
       
   663         * @param aFields returns the field names to be updated
       
   664         * @param aValues returns the field values to be updated
       
   665         * @param aDrive drive the song is on
       
   666         * @return ETrue if the change is visible in the UI
       
   667         */
       
   668         CMPXDbActiveTask::TChangeVisibility GenerateMusicFieldsValuesL(TUint32 aSongId, const CMPXMedia& aMedia,
       
   669             CMPXMessageArray* aItemChangedMessages, RSqlStatement* aMusicTable,
       
   670             CDesCArray& aFields, CDesCArray& aValues, TInt aDrive);
       
   671 
       
   672         /**
       
   673         * Generates the full URI from a music record.
       
   674         * @param aMusicTable music table record
       
   675         * @return Full URI string. The ownership is passed to the caller.
       
   676         */
       
   677         HBufC* ConstructUriL(RSqlStatement& aMusicTable, TUint32 aMediaId);
       
   678 
       
   679         /**
       
   680         * Checks if the specified category field (artist/album/genre/composer)
       
   681         * will change and notifies the observer if so.
       
   682         * @param aCategory identifies the category
       
   683         * @param aMedia contains the new record attributes
       
   684         * @param aAttribute corresponding attribute in the media parameter
       
   685         * @param aColumnIndex column index in the recordset
       
   686         * @param aMusicTable current record in the music table or NULL if this is an insert
       
   687         * @param aDriveId drive ID the update is for
       
   688         * @param aItemChangedMessages item changed messages to append to
       
   689         * @param aItemId returns the category item ID
       
   690         * @return ETrue if the field was modified
       
   691         */
       
   692         TBool UpdateCategoryFieldL(TMPXGeneralCategory aCategory, const CMPXMedia& aMedia,
       
   693             const TMPXAttribute& aAttribute, TUint32 aOldId, TInt aDriveId,
       
   694             CMPXMessageArray* aItemChangedMessages, TUint32& aItemId);
       
   695 
       
   696 		TBool UpdateCategoryFieldL(TMPXGeneralCategory aCategory, const CMPXMedia& aMedia,
       
   697 			const TMPXAttribute& aAttribute, TUint32 aOldId, TInt aDriveId,
       
   698 			CMPXMessageArray* aItemChangedMessages, TUint32& aItemId, TUint32 aArtistId);
       
   699         /**
       
   700         * Checks if extra attributes are required. The "standard attribute set includes:
       
   701         * EMPXMediaGeneralId, EMPXMediaGeneralType, EMPXMediaGeneralCategory,
       
   702         * EMPXMediaGeneralTitle, EMPXMediaGeneralUri, and EMPXMediaGeneralFlags
       
   703         * @param aAttrs attributes to be checked
       
   704         * @return ETrue if extra attributes are required
       
   705         */
       
   706         TBool ExtraFieldsRequired(const TArray<TMPXAttribute>& aAttrs);
       
   707 
       
   708         /**
       
   709         * Test whether the given media contains any supported attribute
       
   710         * @param aMedia media to be tested
       
   711         * @return ETrue if the media contains one or more supported attribute;
       
   712         *  otherwise EFalse.
       
   713         */
       
   714 		TBool IsSupported(const CMPXMedia& aMedia);
       
   715 
       
   716     private:    // from MMPXTable
       
   717 
       
   718         /**
       
   719         * @see MMPXTable
       
   720         */
       
   721         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   722 
       
   723         /**
       
   724         * @see MMPXTable
       
   725         */
       
   726         virtual void DropTableL(RSqlDatabase& aDatabase);
       
   727 
       
   728         /**
       
   729         * @see MMPXTable
       
   730         */
       
   731         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   732 
       
   733     private:
       
   734 
       
   735         /**
       
   736         * C++ constructor
       
   737         * @param aDbManager database manager to use for database interactions
       
   738         */
       
   739         CMPXDbMusic(CMPXDbManager& aDbManager, MMPXDbMusicObserver& aObserver);
       
   740 
       
   741         /**
       
   742         * Second phase constructor.
       
   743         */
       
   744         void ConstructL(CMPXResource& aResource);
       
   745 
       
   746     private:
       
   747 
       
   748         /**
       
   749         * Column indexes in the music table
       
   750         */
       
   751         enum TMusicColumns
       
   752         	{
       
   753         	EMusicUniqueId = KMPXTableDefaultIndex,
       
   754             EMusicDbFlag,
       
   755             EMusicVolumeId,
       
   756             EMusicTitle,
       
   757             EMusicArtist,
       
   758             EMusicArt,
       
   759             EMusicDeleted,
       
   760             EMusicLocation,
       
   761             EMusicAlbumTrack,
       
   762             EMusicPlayCount,
       
   763             EMusicTimeAdded,
       
   764             EMusicTimePlayed,
       
   765             EMusicDuration,
       
   766             EMusicSync,
       
   767             EMusicModified,
       
   768             EMusicAlbum,
       
   769             EMusicGenre,
       
   770             EMusicComposer,
       
   771             EMusicReleaseDate,
       
   772             EMusicRating,
       
   773             EMusicComment,
       
   774             EMusicCopyright,
       
   775             EMusicUrl,
       
   776             EMusicDRM,
       
   777             EMusicLastPlayPosition,
       
   778             EMusicSampleRate,
       
   779             EMusicBitRate,
       
   780             EMusicNumChannels,
       
   781             EMusicCodec,
       
   782             EMusicMimeType,
       
   783             EMusicMTPDrmStatus,
       
   784 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
   785             EMusicAlbumArtist,
       
   786             EMusicContainEmbeddedArt,
       
   787             EMusicAbstractAlbum,
       
   788 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
   789             EMusicArtistName,
       
   790             EMusicAlbumName,
       
   791             EMusicGenreName,
       
   792             EMusicComposerName,
       
   793             EMusicFieldCount
       
   794             };
       
   795 
       
   796          /*
       
   797          * Unique ID for Queries with a lifetime
       
   798          */
       
   799          enum TMusicStatements
       
   800              {
       
   801              EOffsetQueryBasic = 0xabcd0001,
       
   802              EAscQueryBasic = 0xabcd0002,
       
   803              EDscQueryBasic = 0xabcd0003,
       
   804              EOffSetQuery = 0xabcd0004,
       
   805              EAscQuery = 0xabcd0005,
       
   806              EDscQuery = 0xabcd0006
       
   807              };
       
   808 
       
   809     private:    // Data
       
   810 
       
   811         // file extensions to check DRM type, owned
       
   812         CDesCArrayFlat* iExtensionsDrm;
       
   813         MMPXDbMusicObserver& iObserver;
       
   814         TBool iRefresh;
       
   815     };
       
   816 
       
   817 #endif // MPXDBMUSIC_H
       
   818 
       
   819 // End of File