File indexing completed on 2024-05-19 04:50:17

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Shane King <kde@dontletsstart.com>                                *
0003  * Copyright (c) 2008 Leo Franchi <lfranchi@kde.org>                                    *
0004  * Copyright (c) 2013 Vedant Agarwala <vedant.kota@gmail.com>                           *
0005  *                                                                                      *
0006  * This program is free software; you can redistribute it and/or modify it under        *
0007  * the terms of the GNU General Public License as published by the Free Software        *
0008  * Foundation; either version 2 of the License, or (at your option) any later           *
0009  * version.                                                                             *
0010  *                                                                                      *
0011  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0012  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0013  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0014  *                                                                                      *
0015  * You should have received a copy of the GNU General Public License along with         *
0016  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0017  ****************************************************************************************/
0018 
0019 #ifndef LASTFMSCROBBLERADAPTER_H
0020 #define LASTFMSCROBBLERADAPTER_H
0021 
0022 #include "core/meta/forward_declarations.h"
0023 #include "services/lastfm/LastFmServiceConfig.h"
0024 #include "statsyncing/ScrobblingService.h"
0025 
0026 #include <QTimer>
0027 
0028 #include <Audioscrobbler.h>
0029 #include <Track.h>
0030 
0031 class LastFmServiceConfig;
0032 
0033 class ScrobblerAdapter : public QObject, public StatSyncing::ScrobblingService
0034 {
0035     Q_OBJECT
0036 
0037     public:
0038         ScrobblerAdapter( const QString &clientId, const LastFmServiceConfigPtr &config );
0039         ~ScrobblerAdapter() override;
0040 
0041     public:
0042         // ScrobblingService methods:
0043         QString prettyName() const override;
0044         ScrobbleError scrobble( const Meta::TrackPtr &track, double playedFraction = 1.0,
0045                                 const QDateTime &time = QDateTime() ) override;
0046         void updateNowPlaying( const Meta::TrackPtr &track ) override;
0047 
0048     public Q_SLOTS:
0049         // own methods
0050         void loveTrack( const Meta::TrackPtr &track );
0051         void banTrack( const Meta::TrackPtr &track );
0052 
0053     private Q_SLOTS:
0054         void slotScrobblesSubmitted( const QList<lastfm::Track> &tracks );
0055         void slotNowPlayingError( int code, const QString &message );
0056 
0057     private:
0058         /**
0059          * Copies metadata from @param from to @param to.
0060          */
0061         void copyTrackMetadata( lastfm::MutableTrack& to, const Meta::TrackPtr &from );
0062 
0063         /**
0064          * Announces Last.fm suggested @param track corrections to Amarok pop-up log.
0065          */
0066         void announceTrackCorrections( const lastfm::Track &track );
0067 
0068          /**
0069          * Checks whether the @param track contains the m_config->skipLabel
0070          * Also, returns false if "filterByLabel" is unchecked by user.
0071          */
0072         bool isToBeSkipped( const Meta::TrackPtr &track ) const;
0073 
0074         lastfm::Audioscrobbler m_scrobbler;
0075         LastFmServiceConfigPtr m_config;
0076 };
0077 
0078 #endif // LASTFMSCROBBLERADAPTER_H