File indexing completed on 2024-05-19 04:50:18
0001 /**************************************************************************************** 0002 * Copyright (c) 2006,2007 Nikolaj Hald Nielsen <nhn@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or modify it under * 0005 * the terms of the GNU General Public License as published by the Free Software * 0006 * Foundation; either version 2 of the License, or (at your option) any later * 0007 * version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, but WITHOUT ANY * 0010 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A * 0011 * PARTICULAR PURPOSE. See the GNU General Public License for more details. * 0012 * * 0013 * You should have received a copy of the GNU General Public License along with * 0014 * this program. If not, see <http://www.gnu.org/licenses/>. * 0015 ****************************************************************************************/ 0016 0017 #ifndef MAGNATUNEDATABASEHANDLER_H 0018 #define MAGNATUNEDATABASEHANDLER_H 0019 0020 #include "MagnatuneMeta.h" 0021 0022 #include <QStringList> 0023 #include <QMap> 0024 0025 /** 0026 * This class wraps the database operations needed by the MagnatuneStore 0027 * Uses the singleton pattern 0028 * 0029 * @author Nikolaj Hald Nielsen <nhn@kde.org> 0030 */ 0031 class MagnatuneDatabaseHandler { 0032 public: 0033 0034 0035 /** 0036 * Private constructor (singleton pattern) 0037 * @return Pointer to new object 0038 */ 0039 MagnatuneDatabaseHandler(); 0040 0041 0042 ~MagnatuneDatabaseHandler(); 0043 0044 /** 0045 * Creates the tables needed to store Magnatune info 0046 */ 0047 void createDatabase(); 0048 0049 /** 0050 * Destroys Magnatune tables 0051 */ 0052 void destroyDatabase(); 0053 0054 /** 0055 * Inserts a new track into the Magnatune database 0056 * @param track pointer to the track to insert 0057 * @return the database id of the newly inserted track 0058 */ 0059 int insertTrack( Meta::ServiceTrack *track ); 0060 0061 /** 0062 * inserts a new album into the Magnatune database 0063 * @param album pointer to the album to insert 0064 * @return the database id of the newly inserted album 0065 */ 0066 int insertAlbum( Meta::ServiceAlbum *album ); 0067 0068 /** 0069 * inserts a new artist into the Magnatune database 0070 * @param artist pointer to the artist to insert 0071 * @return the database id of the newly inserted artist 0072 */ 0073 int insertArtist( Meta::ServiceArtist *artist ); 0074 0075 /** 0076 * inserts a new genre into the Magnatune database 0077 * @param genre pointer to the genre to insert 0078 * @return the database id of the newly inserted genre 0079 */ 0080 int insertGenre( Meta::ServiceGenre *genre ); 0081 0082 0083 void insertMoods(int trackId, const QStringList &moods); 0084 0085 /** 0086 * Retrieves the id of a named artist 0087 * @param name artist name to retrieve 0088 * @return id of artist. -1 if no artist is found 0089 */ 0090 int getArtistIdByExactName(const QString &name); 0091 0092 /** 0093 * Retrieves the id of an album based on its unique album code. 0094 * @param albumcode The album code. 0095 * @return The id of the album, -1 if not foud. 0096 */ 0097 int getAlbumIdByAlbumCode( const QString &albumcode ); 0098 0099 0100 0101 /** 0102 * Begins a database transaction. Must be followed by a later call to commit() 0103 */ 0104 void begin(); 0105 0106 /** 0107 * Completes (executes) a database transaction. Must be preceded by a call to begin() 0108 */ 0109 void commit(); 0110 0111 }; 0112 0113 #endif