File indexing completed on 2024-05-05 04:49:18

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Maximilian Kossick <maximilian.kossick@googlemail.com>            *
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 SERVICESQLREGISTRY_H
0018 #define SERVICESQLREGISTRY_H
0019 
0020 //#include "ServiceSqlCollection.h"
0021 #include "amarok_export.h"
0022 #include "ServiceMetaBase.h"
0023 
0024 #include <QHash>
0025 #include <QMutex>
0026 #include <QObject>
0027 #include <QPair>
0028 #include <QTimer>
0029 #include <QList>
0030 
0031 class SqlCollection;
0032 
0033 typedef QPair<int, QString> TrackId;
0034 
0035 class AMAROK_EXPORT ServiceSqlRegistry : public QObject
0036 {
0037     Q_OBJECT
0038 
0039     public:
0040         explicit ServiceSqlRegistry( ServiceMetaFactory * metaFactory );
0041         ~ServiceSqlRegistry() override;
0042 
0043         void setMetaFactory( ServiceMetaFactory * metaFactory );
0044         ServiceMetaFactory * factory();
0045 
0046         //TrackPtr getTrack( const QString &url );
0047         Meta::TrackPtr getTrack( const QStringList &rowData );
0048 
0049         Meta::ArtistPtr getArtist(  const QStringList &rowData );
0050         Meta::GenrePtr getGenre(  const QStringList &rowData );
0051        // ComposerPtr getComposer( const QString &name, int id = -1 );
0052        // YearPtr getYear( const QString &year, int id = -1 );
0053         Meta::AlbumPtr getAlbum(  const QStringList &rowData ); //TODO fix this
0054 
0055     private:
0056         //we don't care about the ordering so use the faster QHash
0057         QHash<int, Meta::TrackPtr > m_trackMap;
0058         QHash<int, Meta::ArtistPtr > m_artistMap;
0059         QHash<int, Meta::ComposerPtr > m_composerMap;
0060         QHash<int, Meta::GenrePtr > m_genreMap;
0061         QHash<int, Meta::YearPtr > m_yearMap;
0062         QHash<int, Meta::AlbumPtr > m_albumMap;        //TODO: needs improvement
0063 
0064         QMutex m_trackMutex;
0065         QMutex m_artistMutex;
0066         QMutex m_composerMutex;
0067         QMutex m_genreMutex;
0068         QMutex m_yearMutex;
0069         QMutex m_albumMutex;
0070 
0071         QTimer *m_timer;
0072 
0073         //ServiceSqlCollection *m_collection;
0074         ServiceMetaFactory * m_metaFactory;
0075 };
0076 
0077 #endif /* SERVICESQLREGISTRY_H */