mpserviceplugins/mpxsqlitedbhgplugin/inc/mpxdbcategory.h
branchRCL_3
changeset 52 14979e23cb5e
equal deleted inserted replaced
50:26a1709b9fec 52:14979e23cb5e
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class is responsible for all category tables (Artist,
       
    15 *                Album, Genre, Composer).
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 #ifndef MPXDBCATEGORY_H
       
    22 #define MPXDBCATEGORY_H
       
    23 
       
    24 // INCLUDES
       
    25 #include "mpxdbtable.h"
       
    26 #include "mpxmediageneraldefs.h"
       
    27 #include "mpxmessage2.h"
       
    28 
       
    29 // CLASS FORWARDS
       
    30 class CMPXMedia;
       
    31 class CMPXMediaArray;
       
    32 class RSqlStatement;
       
    33 
       
    34 // CLASS DECLARATION
       
    35 
       
    36 /**
       
    37 * Responsible for managing all music databases
       
    38 *
       
    39 * @lib MPXDbPlugin.lib
       
    40 */
       
    41 class CMPXDbCategory :
       
    42     public CMPXDbTable
       
    43     {
       
    44     protected:
       
    45         /**
       
    46         * Destructor
       
    47         */
       
    48         virtual ~CMPXDbCategory();
       
    49 
       
    50 
       
    51     public:
       
    52 
       
    53         /**
       
    54         * Add a category item. If the record already exists, its counter will
       
    55         * be incremented.
       
    56         * @param aCategory category type
       
    57         * @param aMedia: This is the media object to be entered into the row
       
    58         * @param aDriveId: The Drive Id the name (category) belongs
       
    59         * @param aNewRecord: indicates to the caller if a new record is created.
       
    60         *        ETrue if a new row is created in the table; otherwise EFalse.
       
    61         * @param aCaseSensitive indicates whether case sensitivity should be taken
       
    62         *        into consideration when generating the unique row id
       
    63         * @return The unique id of the row added.
       
    64         */
       
    65         virtual TUint32 AddItemL(TMPXGeneralCategory aCategory, const CMPXMedia& aMedia, TInt aDriveId, TBool& aNewRecord,
       
    66             TBool aCaseSensitive = ETrue);
       
    67 
       
    68         /**
       
    69         * Get the name field for a given ID.
       
    70         * @param aId identifies the category item
       
    71         * @return name that matches aId. Ownership is abandoned.
       
    72         */
       
    73         HBufC* GetNameL(TUint32 aId);
       
    74 
       
    75         /**
       
    76         * Gets the total number of items in the category table.
       
    77         * @return number of items
       
    78         */
       
    79         TInt CountL();
       
    80 
       
    81         /**
       
    82         * Find record(s) matching the criteria
       
    83         * @param aCriteria, selection criteria
       
    84         * @param aAttrs, attributes for the matching record(s)
       
    85         * @param aMediaArray returns the matching record(s)
       
    86         */
       
    87         void FindAllL(const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs,
       
    88             CMPXMediaArray& aMediaArray);
       
    89 
       
    90         /**
       
    91         * Decrement the number of songs for the item. If the count gets to 0, remove
       
    92         * the item.
       
    93         * @param aId: The ID of the category to delete.
       
    94         * @param aDriveId: The drive Id the name (category) belongs to. Songs on different
       
    95         *                  drives may belong to the same album or artist; consequently, one
       
    96         *                  row for each artist/album id and drive ID pair will exist in the
       
    97         *                  lookup table with a count existing for each row that tracks the
       
    98         *                  number number of songs on that drive with that album/artist.
       
    99         * @param aItemChangedMessages if valid on return contains a deleted message if the
       
   100         *                  category was deleted
       
   101         * @param aItemExist Out parameter, ETrue if the category is not deleted after the delete,
       
   102         *        EFalse otherwise
       
   103         */
       
   104 #ifdef ABSTRACTAUDIOALBUM_INCLUDED
       
   105         virtual void DecrementSongsForCategoryL(TUint32 aId, TInt aDriveId,
       
   106             CMPXMessageArray* aItemChangedMessages, TBool& aItemExist, TBool aMtpInUse = EFalse);
       
   107 #else
       
   108         virtual void DecrementSongsForCategoryL(TUint32 aId, TInt aDriveId,
       
   109             CMPXMessageArray* aItemChangedMessages, TBool& aItemExist);
       
   110 #endif // ABSTRACTAUDIOALBUM_INCLUDED
       
   111         /**
       
   112         * Deletes a category.
       
   113         * @param aId identifies the category
       
   114         * @param aDriveId category drive
       
   115         */
       
   116         void DeleteCategoryL(TUint32 aId, TInt aDriveId);
       
   117 
       
   118         /**
       
   119         * Gets the details for multiple category items.
       
   120         * @param aAttrs attributes to be returned
       
   121         * @param aMediaArray inout parameter, on input contains the IDs of the
       
   122         *       category items to be returned, on exit contains the requested
       
   123         *       attributes for these items
       
   124         */
       
   125         void GetCategoryItemsL(const TArray<TMPXAttribute>& aAttrs,
       
   126             CMPXMediaArray& aMediaArray);
       
   127 
       
   128         /**
       
   129         * Gets the details for all category items.
       
   130         * @param aAttrs attributes to be returned
       
   131         * @param aMediaArray returns the requested attributes for all items
       
   132         */
       
   133         void GetAllCategoryItemsL(const TArray<TMPXAttribute>& aAttrs,
       
   134             CMPXMediaArray& aMediaArray);
       
   135 
       
   136         /**
       
   137         * Gets details for one category item.
       
   138         * @param aId identifies the category item
       
   139         * @param aAttrs attributes to be returned
       
   140         * @param aMedia returns the requested attributes for te item
       
   141         * @leave KErrCorrupt if there are multiple items with the same ID
       
   142         *        KErrNotFound if there is no item with the specified ID
       
   143         */
       
   144         void GetCategoryItemL(TUint32 aId, const TArray<TMPXAttribute>& aAttrs,
       
   145             CMPXMedia& aMedia);
       
   146 
       
   147         /**
       
   148         * Gets details for the category items under a parent category item.
       
   149         * This applies to albums for a given artist. The method panics if the
       
   150         * category or parent category are invalid.
       
   151         * @param aParentCategory identifies the parent category
       
   152         * @param aParentId identifies the parent item
       
   153         * @param aAttrs attributes to be returned
       
   154         * @param aMediaArray returns the requested attributes for all items
       
   155         */
       
   156         virtual void GetSubCategoryItemsL(TMPXGeneralCategory aParentCategory, TUint32 aParentId,
       
   157             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   158 
       
   159         /**
       
   160         * Checks if the specified category item exists.
       
   161         * @param aDriveId drive to check or KDbManagerAllDrives
       
   162         * @param aId identifies the category item
       
   163         * @return ETrue if it exists, EFalse otherwise
       
   164         */
       
   165         TBool CategoryItemExistsL(TInt aDriveId, TUint32 aId);
       
   166 
       
   167         /**
       
   168         * Gets the CountSongs field for a category item
       
   169         * @param aDriveId drive to check or KDbManagerAllDrives
       
   170         * @param aId identifies the category item
       
   171         * @return value of the CountSongs field.
       
   172         */
       
   173         TInt GetSongsCountL(TInt aDriveId, TUint32 aId);
       
   174 
       
   175         /**
       
   176         * Update a category item.
       
   177         * @param aId: The ID of the category to update
       
   178         * @param aMedia: The media data
       
   179         * @param aDriveId: The Drive Id the name (category) belongs
       
   180         * @param aItemChangedMessages: if valid on return contains a updated message if the
       
   181         * category was updated
       
   182         */       
       
   183         virtual void UpdateItemL(TUint32 aId, const CMPXMedia& aMedia, TInt aDriveId, CMPXMessageArray* aItemChangedMessages);
       
   184 
       
   185     protected:
       
   186 
       
   187         /**
       
   188         * Updates the media with information from the table
       
   189         * @param aRecord record containing the source fields
       
   190         * @param aAttrs attributes to be returned
       
   191         * @param aMedia returns the requested attributes
       
   192         */
       
   193         void UpdateMediaL(RSqlStatement& aRecord, const TArray<TMPXAttribute>& aAttrs,
       
   194             CMPXMedia& aMedia);
       
   195 
       
   196         /**
       
   197         * Returns the category record for a given ID
       
   198         * @param aId identifies the category item
       
   199         * @return rowset
       
   200         */
       
   201         RSqlStatement GetCategoryRecordL(TUint32 aId);
       
   202 
       
   203         /**
       
   204         * Replaces the table placeholder in the string parameter with the
       
   205         * category table name.
       
   206         * @param aQuery raw query string
       
   207         * @return processed query string, ownership is transferred.
       
   208         */
       
   209         HBufC* PreProcessStringLC(const TDesC& aQuery);
       
   210 
       
   211         /**
       
   212         * Processes a recordset by constructing media instances and adding them
       
   213         * to the specified array.
       
   214         * @param aAttrs attributes to be returned
       
   215         * @param aRecordset recordset to be processed
       
   216         * @param aMediaArray returns the media instances
       
   217         */
       
   218         void ProcessRecordsetL(const TArray<TMPXAttribute>& aAttrs,
       
   219             RSqlStatement& aRecordset, CMPXMediaArray& aMediaArray);
       
   220 
       
   221     private:
       
   222         /**
       
   223         * Retrieve name from media object based on category
       
   224         * @param aCategory the category to retrieve name
       
   225         * @param aMedia media object
       
   226         * @return name
       
   227         */
       
   228         TPtrC ItemNameL(TMPXGeneralCategory aCategory, const CMPXMedia& aMedia);
       
   229         
       
   230     private:    // from MMPXTable
       
   231 
       
   232         /**
       
   233         * @see MMPXTable
       
   234         */
       
   235         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   236 
       
   237         /**
       
   238         * @see MMPXTable
       
   239         */
       
   240         virtual void DropTableL(RSqlDatabase& aDatabase);
       
   241 
       
   242         /**
       
   243         * @see MMPXTable
       
   244         */
       
   245         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   246 
       
   247     protected:
       
   248 
       
   249         /**
       
   250         * C++ constructor.
       
   251         * @param aDbManager database manager to use for database interactions
       
   252         * @param aCategory identifies the category
       
   253         */
       
   254         CMPXDbCategory(CMPXDbManager& aDbManager, TMPXGeneralCategory aCategory);
       
   255 
       
   256         /**
       
   257         * Second phase constructor.
       
   258         */
       
   259         void BaseConstructL();
       
   260 
       
   261     private:
       
   262 
       
   263         /**
       
   264         * Column indexes in the category tables
       
   265         */
       
   266         enum TCategoryColumns
       
   267             {
       
   268             ECategoryUniqueId = KMPXTableDefaultIndex,
       
   269             ECategoryName,
       
   270             ECategorySongCount
       
   271             };
       
   272 
       
   273     protected:
       
   274 
       
   275         HBufC* iTableName;              // owned
       
   276         TMPXGeneralCategory iCategory;
       
   277 
       
   278     };
       
   279 
       
   280 #endif // MPXDBCATEGORY_H
       
   281 
       
   282 // End of File