File indexing completed on 2024-05-19 04:49:44
0001 /**************************************************************************************** 0002 * Copyright (c) 2013 Konrad Zemek <konrad.zemek@gmail.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 #include "ClementineProvider.h" 0018 0019 #include "ClementineTrack.h" 0020 #include "importers/ImporterSqlConnection.h" 0021 0022 using namespace StatSyncing; 0023 0024 ClementineProvider::ClementineProvider( const QVariantMap &config, 0025 ImporterManager *importer ) 0026 : ImporterProvider( config, importer ) 0027 , m_connection( new ImporterSqlConnection( config.value( "dbPath" ).toString() ) ) 0028 { 0029 } 0030 0031 ClementineProvider::~ClementineProvider() 0032 { 0033 } 0034 0035 qint64 0036 ClementineProvider::reliableTrackMetaData() const 0037 { 0038 return Meta::valTitle | Meta::valArtist | Meta::valAlbum | Meta::valComposer 0039 | Meta::valYear | Meta::valTrackNr | Meta::valDiscNr; 0040 } 0041 0042 qint64 0043 ClementineProvider::writableTrackStatsData() const 0044 { 0045 return Meta::valLastPlayed | Meta::valRating | Meta::valPlaycount; 0046 } 0047 0048 QSet<QString> 0049 ClementineProvider::artists() 0050 { 0051 m_connection->query( "SELECT DISTINCT(artist) FROM songs" ); 0052 0053 QSet<QString> result; 0054 foreach( const QVariantList &row, 0055 m_connection->query( "SELECT DISTINCT(artist) FROM songs" ) ) 0056 result.insert( row[0].toString() ); 0057 0058 return result; 0059 } 0060 0061 TrackList 0062 ClementineProvider::artistTracks( const QString &artistName ) 0063 { 0064 const QString query = "SELECT filename, title, artist, album, composer, year, track, " 0065 "disc, rating, lastplayed, playcount FROM songs WHERE artist = :artist"; 0066 0067 QVariantMap bindValues; 0068 bindValues.insert( ":artist", artistName ); 0069 0070 const QList<qint64> fields = QList<qint64>() << Meta::valTitle << Meta::valArtist 0071 << Meta::valAlbum << Meta::valComposer << Meta::valYear << Meta::valTrackNr 0072 << Meta::valDiscNr << Meta::valRating << Meta::valLastPlayed 0073 << Meta::valPlaycount; 0074 0075 TrackList result; 0076 foreach( const QVariantList &row, m_connection->query( query, bindValues ) ) 0077 { 0078 const QVariant &filename = row[0]; 0079 0080 Meta::FieldHash metadata; 0081 for( int i = 0; i < fields.size(); ++i ) 0082 metadata.insert( fields[i], row[i + 1] ); 0083 0084 result << TrackPtr( new ClementineTrack( filename, m_connection, metadata ) ); 0085 } 0086 0087 return result; 0088 }