mpxplugins/serviceplugins/collectionplugins/mpxsqlitedbhgplugin/inc/mpxdbcategory.h
changeset 0 ff3acec5bc43
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 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 aName: This is the name to be entered into the row
       
    57         * @param aDriveId: The Drive Id the name (category) belongs
       
    58         * @param aNewRecord: indicates to the caller if a new record is created.
       
    59         *        ETrue if a new row is created in the table; otherwise EFalse.
       
    60         * @param aCaseSensitive indicates whether case sensitivity should be taken
       
    61         *        into consideration when generating the unique row id
       
    62         * @return The unique id of the row added.
       
    63         */
       
    64         TUint32 AddItemL(const TDesC& aName, TInt aDriveId, TBool& aNewRecord,
       
    65             TBool aCaseSensitive = ETrue);
       
    66 
       
    67         /**
       
    68         * Get the name field for a given ID.
       
    69         * @param aId identifies the category item
       
    70         * @return name that matches aId. Ownership is abandoned.
       
    71         */
       
    72         HBufC* GetNameL(TUint32 aId);
       
    73 
       
    74         /**
       
    75         * Gets the total number of items in the category table.
       
    76         * @return number of items
       
    77         */
       
    78         TInt CountL();
       
    79 
       
    80         /**
       
    81         * Find record(s) matching the criteria
       
    82         * @param aCriteria, selection criteria
       
    83         * @param aAttrs, attributes for the matching record(s)
       
    84         * @param aMediaArray returns the matching record(s)
       
    85         */
       
    86         void FindAllL(const CMPXMedia& aCriteria, const TArray<TMPXAttribute>& aAttrs,
       
    87             CMPXMediaArray& aMediaArray);
       
    88 
       
    89         /**
       
    90         * Decrement the number of songs for the item. If the count gets to 0, remove
       
    91         * the item.
       
    92         * @param aId: The ID of the category to delete.
       
    93         * @param aDriveId: The drive Id the name (category) belongs to. Songs on different
       
    94         *                  drives may belong to the same album or artist; consequently, one
       
    95         *                  row for each artist/album id and drive ID pair will exist in the
       
    96         *                  lookup table with a count existing for each row that tracks the
       
    97         *                  number number of songs on that drive with that album/artist.
       
    98         * @param aItemChangedMessages if valid on return contains a deleted message if the
       
    99         *                  category was deleted
       
   100         * @param aItemExist Out parameter, ETrue if the category is not deleted after the delete,
       
   101         *        EFalse otherwise
       
   102         */
       
   103         void DecrementSongsForCategoryL(TUint32 aId, TInt aDriveId,
       
   104             CMPXMessageArray* aItemChangedMessages, TBool& aItemExist);
       
   105 
       
   106         /**
       
   107         * Deletes a category.
       
   108         * @param aId identifies the category
       
   109         * @param aDriveId category drive
       
   110         */
       
   111         void DeleteCategoryL(TUint32 aId, TInt aDriveId);
       
   112 
       
   113         /**
       
   114         * Gets the details for multiple category items.
       
   115         * @param aAttrs attributes to be returned
       
   116         * @param aMediaArray inout parameter, on input contains the IDs of the
       
   117         *       category items to be returned, on exit contains the requested
       
   118         *       attributes for these items
       
   119         */
       
   120         void GetCategoryItemsL(const TArray<TMPXAttribute>& aAttrs,
       
   121             CMPXMediaArray& aMediaArray);
       
   122 
       
   123         /**
       
   124         * Gets the details for all category items.
       
   125         * @param aAttrs attributes to be returned
       
   126         * @param aMediaArray returns the requested attributes for all items
       
   127         */
       
   128         void GetAllCategoryItemsL(const TArray<TMPXAttribute>& aAttrs,
       
   129             CMPXMediaArray& aMediaArray);
       
   130 
       
   131         /**
       
   132         * Gets details for one category item.
       
   133         * @param aId identifies the category item
       
   134         * @param aAttrs attributes to be returned
       
   135         * @param aMedia returns the requested attributes for te item
       
   136         * @leave KErrCorrupt if there are multiple items with the same ID
       
   137         *        KErrNotFound if there is no item with the specified ID
       
   138         */
       
   139         void GetCategoryItemL(TUint32 aId, const TArray<TMPXAttribute>& aAttrs,
       
   140             CMPXMedia& aMedia);
       
   141 
       
   142         /**
       
   143         * Gets details for the category items under a parent category item.
       
   144         * This applies to albums for a given artist. The method panics if the
       
   145         * category or parent category are invalid.
       
   146         * @param aParentCategory identifies the parent category
       
   147         * @param aParentId identifies the parent item
       
   148         * @param aAttrs attributes to be returned
       
   149         * @param aMediaArray returns the requested attributes for all items
       
   150         */
       
   151         void GetSubCategoryItemsL(TMPXGeneralCategory aParentCategory, TUint32 aParentId,
       
   152             const TArray<TMPXAttribute>& aAttrs, CMPXMediaArray& aMediaArray);
       
   153 
       
   154         /**
       
   155         * Checks if the specified category item exists.
       
   156         * @param aDriveId drive to check or KDbManagerAllDrives
       
   157         * @param aId identifies the category item
       
   158         * @return ETrue if it exists, EFalse otherwise
       
   159         */
       
   160         TBool CategoryItemExistsL(TInt aDriveId, TUint32 aId);
       
   161 
       
   162         /**
       
   163         * Gets the CountSongs field for a category item
       
   164         * @param aDriveId drive to check or KDbManagerAllDrives
       
   165         * @param aId identifies the category item
       
   166         * @return value of the CountSongs field.
       
   167         */
       
   168         TInt GetSongsCountL(TInt aDriveId, TUint32 aId);
       
   169 
       
   170 		/**
       
   171 	    * Update a category item.
       
   172 	    * @param aId: The ID of the category to update
       
   173 	    * @param aMedia: The media data
       
   174 	    * @param aDriveId: The Drive Id the name (category) belongs
       
   175 	    * @param aItemChangedMessages: if valid on return contains a updated message if the
       
   176         * category was updated
       
   177         */
       
   178 		void UpdateItemL(TUint32 aId, const CMPXMedia& aMedia, TInt aDriveId, CMPXMessageArray* aItemChangedMessages);
       
   179 
       
   180     protected:
       
   181 
       
   182         /**
       
   183         * Updates the media with information from the table
       
   184         * @param aRecord record containing the source fields
       
   185         * @param aAttrs attributes to be returned
       
   186         * @param aMedia returns the requested attributes
       
   187         */
       
   188         void UpdateMediaL(RSqlStatement& aRecord, const TArray<TMPXAttribute>& aAttrs,
       
   189             CMPXMedia& aMedia);
       
   190 
       
   191         /**
       
   192         * Returns the category record for a given ID
       
   193         * @param aId identifies the category item
       
   194         * @return rowset
       
   195         */
       
   196         RSqlStatement GetCategoryRecordL(TUint32 aId);
       
   197 
       
   198         /**
       
   199         * Replaces the table placeholder in the string parameter with the
       
   200         * category table name.
       
   201         * @param aQuery raw query string
       
   202         * @return processed query string, ownership is transferred.
       
   203         */
       
   204         HBufC* PreProcessStringLC(const TDesC& aQuery);
       
   205 
       
   206         /**
       
   207         * Processes a recordset by constructing media instances and adding them
       
   208         * to the specified array.
       
   209         * @param aAttrs attributes to be returned
       
   210         * @param aRecordset recordset to be processed
       
   211         * @param aMediaArray returns the media instances
       
   212         */
       
   213         void ProcessRecordsetL(const TArray<TMPXAttribute>& aAttrs,
       
   214             RSqlStatement& aRecordset, CMPXMediaArray& aMediaArray);
       
   215 
       
   216     private:    // from MMPXTable
       
   217 
       
   218         /**
       
   219         * @see MMPXTable
       
   220         */
       
   221         virtual void CreateTableL(RSqlDatabase& aDatabase, TBool aCorruptTable);
       
   222 
       
   223         /**
       
   224         * @see MMPXTable
       
   225         */
       
   226         virtual void DropTableL(RSqlDatabase& aDatabase);
       
   227 
       
   228         /**
       
   229         * @see MMPXTable
       
   230         */
       
   231         virtual TBool CheckTableL(RSqlDatabase& aDatabase);
       
   232 
       
   233     protected:
       
   234 
       
   235         /**
       
   236         * C++ constructor.
       
   237         * @param aDbManager database manager to use for database interactions
       
   238         * @param aCategory identifies the category
       
   239         */
       
   240         CMPXDbCategory(CMPXDbManager& aDbManager, TMPXGeneralCategory aCategory);
       
   241 
       
   242         /**
       
   243         * Second phase constructor.
       
   244         */
       
   245         void BaseConstructL();
       
   246 
       
   247     private:
       
   248 
       
   249         /**
       
   250         * Column indexes in the category tables
       
   251         */
       
   252         enum TCategoryColumns
       
   253             {
       
   254             ECategoryUniqueId = KMPXTableDefaultIndex,
       
   255             ECategoryName,
       
   256             ECategorySongCount
       
   257             };
       
   258 
       
   259     protected:
       
   260 
       
   261         HBufC* iTableName;              // owned
       
   262         TMPXGeneralCategory iCategory;
       
   263 
       
   264     };
       
   265 
       
   266 #endif // MPXDBCATEGORY_H
       
   267 
       
   268 // End of File