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