mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/inc/mpxdbplaylistsongs.h
changeset 0 ff3acec5bc43
child 11 13afc0e517bd
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 the functionality related to
       
    15 *                playlist songs. The class operates on two tables: PlaylistSongs
       
    16 *                and PlaylistSongInfo.
       
    17 *
       
    18 *                The PlaylistSongs table contains records for all song instances in
       
    19 *                playlists. For example if a playlist contains 7 songs, there will be 7
       
    20 *                corresponding records in the PlaylistSongs table, even if one song has
       
    21 *                multiple instances in the playlist.
       
    22 *
       
    23 *                The PlaylistSongInfo table contains one record for each song included
       
    24 *                in at least one playlist. Redundant song information is stored in this
       
    25 *                table to help with songs on different drives than the playlist.
       
    26 *
       
    27 *
       
    28 */
       
    29 
       
    30 
       
    31 #ifndef MPXDBPLAYLISTSONGS_H
       
    32 #define MPXDBPLAYLISTSONGS_H
       
    33 
       
    34 // INCLUDES
       
    35 #include "mpxdbtable.h"
       
    36 
       
    37 // CLASS FORWARDS
       
    38 class CMPXMedia;
       
    39 class CMPXMediaArray;
       
    40 
       
    41 // CLASS DECLARATION
       
    42 
       
    43 /**
       
    44 * Responsible for managing the music table
       
    45 *
       
    46 * @lib MPXDbPlugin.lib
       
    47 */
       
    48 class CMPXDbPlaylistSongs :
       
    49     public CMPXDbTable
       
    50     {
       
    51     public:
       
    52 
       
    53         /**
       
    54         * Two-phased constructor.
       
    55         * @param aDbManager database manager to use for database interactions
       
    56         * @return New CMPXDbPlaylistSongs instance.
       
    57         */
       
    58         static CMPXDbPlaylistSongs* NewL(CMPXDbManager& aDbManager);
       
    59 
       
    60         /**
       
    61         * Two-phased constructor.
       
    62         * @param aDbManager database manager to use for database interactions
       
    63         * @return New CMPXDbPlaylistSongs instance on the cleanup stack.
       
    64         */
       
    65         static CMPXDbPlaylistSongs* NewLC(CMPXDbManager& aDbManager);
       
    66 
       
    67         /**
       
    68         * Destructor
       
    69         */
       
    70         virtual ~CMPXDbPlaylistSongs();
       
    71 
       
    72     public:
       
    73 
       
    74         /**
       
    75         * Add a song/songs to the given playlist
       
    76         * @param aPlaylistId playlist id
       
    77         * @param aMediaArray media array which contains the tracks to be added to the playlist
       
    78         * @param aDriveId Drive Id of corresponding playlist
       
    79         */
       
    80         void AddSongsL(TUint32 aPlaylistId, const CMPXMediaArray& aMediaArray, TInt aDriveId);
       
    81 
       
    82         /**
       
    83         * Add a song to playlist songs table for the given playlist
       
    84         * @param aPlaylistId id of the playlist to add the song to
       
    85         * @param aDriveId drive the song is on
       
    86         * @param aMedia song media to be added to the playlist songs table for the playlist
       
    87         * @return song ID
       
    88         */
       
    89         TUint32 AddSongL(TUint32 aPlaylistId, const CMPXMedia& aMedia, TInt aDriveId);
       
    90 
       
    91         /**
       
    92         * Add a song to playlist songs table for the given playlist
       
    93         * @param aPlaylistId id of the playlist to add the song to
       
    94         * @param aOrdinal ordinal of the song to be added
       
    95         * @param aDriveId drive the song is on
       
    96         * @param aMedia song media to be added to the playlist songs table for the playlist
       
    97         * @return song ID
       
    98         */
       
    99         TUint32 AddSongL(TUint32 aPlaylistId, TInt aOrdinal, const CMPXMedia& aMedia,
       
   100             TInt aDriveId);
       
   101 
       
   102         /**
       
   103         * Update song info for a song in the playlist songs table
       
   104         * @param aSongId identifies the song
       
   105         * @param aMedia song information
       
   106         * @param aResetFlags indicates whether the song db flags should be reset or just updated
       
   107         * @param aUpdated returns ETrue if the song information has changed
       
   108         */
       
   109         TBool UpdateSongL(TUint32 aSongId, const CMPXMedia& aMedia, TBool aResetFlags,
       
   110             TBool& aUpdated);
       
   111 
       
   112         /**
       
   113         * Update songs in a playlist to reflect playlist id change
       
   114         * @param aPlaylistId identifies the songs in the playlist
       
   115         * @param aNewPlaylistId specifies the new playlist id the songs should be associated with
       
   116         */
       
   117         void UpdateSongsL(TUint32 aPlaylistId, TUint32 aNewPlaylistId);
       
   118 
       
   119         /**
       
   120         * Reorder the song in the playlist
       
   121         * @param aPlaylistId id of the playlist which contains the song to be reordered
       
   122         * @param aSongId id of the song to be reordered
       
   123         * @param aOriginalOrdinal the original ordinal of the song within the playlist.
       
   124         *        Ordinal starts from 0.
       
   125         * @param aNewOrdinal the new ordinal of the song within the playlist. Ordinal
       
   126         *        starts from 0.
       
   127         */
       
   128         void ReorderSongL(const TMPXItemId& aPlaylistId, const TMPXItemId& aSongId,
       
   129             TUint aOriginalOrdinal, TUint aNewOrdinal);
       
   130 
       
   131         /**
       
   132         * Remove the given song from all playlists
       
   133         * @param aSongId ID of the song to remove
       
   134         * @param aDriveId identifies the database to be updated
       
   135         */
       
   136         void DeleteSongL(TUint32 aSongId);
       
   137 
       
   138         /**
       
   139         * Remove a song from the playlist.
       
   140         * @param aPlaylistId ID of the playlist to remove the song from
       
   141         * @param aSongId Id of the song in the playlist to be removed
       
   142         * @param aOrdinal the ordinal of the song in the playlist. This uniquely
       
   143         *        identifies which song in the playlist to be removed; whereas song
       
   144         *        ID doesn't because duplicate tracks in the playlist are allowed.
       
   145         *        The position is relative to zero, i.e. zero implies that the song
       
   146         *        at the beginning of the playlist is to be removed.
       
   147         * @param aDriveId identifies the database to be updated
       
   148         */
       
   149         void DeleteSongL(TUint32 aPlaylistId, TUint32 aSongId, TInt aOrdinal, TInt aDriveId);
       
   150 
       
   151         /**
       
   152         * Remove all songs from the specified playlist
       
   153         * @param aPlaylistId ID of the playlist.
       
   154         * @param aDriveId identifies the database.
       
   155         */
       
   156         void DeleteSongsL(TUint32 aPlaylistId, TInt aDriveId);
       
   157 
       
   158         /**
       
   159         * Remove the songs for a given category from all playlists.
       
   160         * @param aCategory identifies the category
       
   161         * @param aCategoryId identifies the category item
       
   162         * @param aDriveId identifies the database to be updated
       
   163         */
       
   164         void DeleteSongsForCategoryL(TMPXGeneralCategory aCategory, TUint32 aCategoryId,
       
   165             TInt aDriveId);
       
   166 
       
   167         /**
       
   168         * Remove the songs for a given category from all playlists.
       
   169         * @param aCategory identifies the category
       
   170         * @param aCategoryId identifies the category item
       
   171         * @param aDriveId identifies the database to be updated
       
   172         */
       
   173         void DeleteSongsForArtistAndAlbumL(TUint32 aArtistId, TUint32 aAlbumId, TInt aDriveId);
       
   174 
       
   175         /**
       
   176         * Remove all songs from the playlist songs table
       
   177         */
       
   178         void DeleteAllSongsL();
       
   179 
       
   180         /**
       
   181         * Get ids of all songs in a playlist
       
   182         * @param aPlaylistId identifies the playlist
       
   183         * @param aMediaArray returns songs' id
       
   184         */
       
   185         void GetSongsL(TUint32 aPlaylistId, CMPXMediaArray& aMediaArray);
       
   186 
       
   187         /**
       
   188         * Get ids of all songs in a playlist
       
   189         * @param aPlaylistId identifies the playlist
       
   190         * @param aAttrs attributes to return
       
   191         * @param aMediaArray returns songs' id
       
   192         */
       
   193         TBool GetSongsL( TUint32 aPlaylistId,
       
   194             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   195 
       
   196         /**
       
   197         * Get information on a song in a playlist
       
   198         * @param aPlaylistId identifies the playlist
       
   199         * @param aSongId identifies the song
       
   200         * @param aAttrs attributes to return
       
   201         * @param aMedia returns song info
       
   202         */
       
   203         TBool GetSongL(TUint32 aPlaylistId, TUint32 aSongId,
       
   204             const TArray<TMPXAttribute>& aAttrs, CMPXMedia& aMedia);
       
   205 
       
   206         /**
       
   207         * Get information on a song
       
   208         * @param aSongId identifies the song
       
   209         * @param aAttrs attributes to return
       
   210         * @param aMedia returns song info
       
   211         */
       
   212         TBool GetSongL(const TMPXItemId& aSongId, const TArray<TMPXAttribute>& aAttrs,
       
   213             CMPXMedia*& aMedia);
       
   214 
       
   215 
       
   216         /**
       
   217         * Get the number of songs for a playlist
       
   218         * @param aPlaylistId identifies the playlist
       
   219         * @return number of songs
       
   220         */
       
   221         TInt CountL(TUint32 aPlaylistId);
       
   222 
       
   223     private:
       
   224 
       
   225         /**
       
   226         * Update the media from the table
       
   227         * @param aRecord playlist table view
       
   228         * @param aAttrs the attributes to return
       
   229         * @param aMedia updated with the playlist song info
       
   230         */
       
   231         void UpdateMediaL(RSqlStatement& aRecord, const TArray<TMPXAttribute>& aAttrs,
       
   232             CMPXMedia& aMedia);
       
   233 
       
   234         /**
       
   235         * Get the number of instances of a song in a playlist
       
   236         * @param aPlaylistId identifies the playlist
       
   237         * @param aSongId identifies the song
       
   238         * @return number of instances
       
   239         */
       
   240         TInt SongInstanceCountL(TUint32 aPlaylistId, TUint32 aSongId);
       
   241 
       
   242         /**
       
   243         * Get the number of instances of a song in the PlaylistSongs table.
       
   244         * @param aSongId identifies the song
       
   245         * @return number of instances
       
   246         */
       
   247         TInt SongCountL(TUint32 aSongId);
       
   248 
       
   249         /**
       
   250         * Checks if the specified song exists in the PlaylisySongInfo table.
       
   251         * @param aDriveId drive to check or KDbManagerAllDrives
       
   252         * @param aSongId identifies the song
       
   253         * @return ETrue if it exists, EFalse otherwise
       
   254         */
       
   255         TBool SongInfoExistsL(TInt aDriveId, TUint32 aSongId);
       
   256 
       
   257         /**
       
   258         * Deletes all orphaned records in the PlaylistSongInfo table
       
   259         * (songs not included in any playlist).
       
   260         * @param aDriveId database to cleanup
       
   261         */
       
   262         void CleanupSongInfoL(TInt aDriveId);
       
   263 
       
   264     private:    // from MMPXTable
       
   265 
       
   266         /**
       
   267         * @see MMPXTable
       
   268         */
       
   269         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   270 
       
   271         /**
       
   272         * @see MMPXTable
       
   273         */
       
   274         virtual void DropTableL(RSqlDatabase& aDatabase);
       
   275 
       
   276         /**
       
   277         * @see MMPXTable
       
   278         */
       
   279         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   280 
       
   281     private:
       
   282 
       
   283         /**
       
   284         * C++ constructor
       
   285         * @param aDbManager database manager to use for database interactions
       
   286         */
       
   287         CMPXDbPlaylistSongs(CMPXDbManager& aDbManager);
       
   288 
       
   289         /**
       
   290         * Safely construct things that can leave
       
   291         */
       
   292         void ConstructL();
       
   293 
       
   294     private:
       
   295 
       
   296         /**
       
   297         * Column indexes in the playlist songs query
       
   298         */
       
   299         enum TPlaylistSongsColumns
       
   300             {
       
   301             EPlaylistSongsUniqueId = KMPXTableDefaultIndex,
       
   302             EPlaylistSongsSongId,
       
   303             EPlaylistSongsPlaylistId,
       
   304             EPlaylistSongsOrdinal,
       
   305             EPlaylistSongsVolumeId,
       
   306             EPlaylistSongsDbFlag,
       
   307             EPlaylistSongsUri,
       
   308             EPlaylistSongsTitle
       
   309             };
       
   310 
       
   311         /**
       
   312         * Column indexes in the playlist song info table
       
   313         */
       
   314         enum TPlaylistSongInfoColumns
       
   315             {
       
   316             EPlaylistSongInfoSongId = KMPXTableDefaultIndex,
       
   317             EPlaylistSongInfoVolumeId,
       
   318             EPlaylistSongInfoDbFlag,
       
   319             EPlaylistSongInfoUri,
       
   320             EPlaylistSongInfoTitle
       
   321             };
       
   322 
       
   323     };
       
   324 
       
   325 #endif // MPXDBPLAYLISTSONGS_H
       
   326 
       
   327 // End of File