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

0001 /****************************************************************************************
0002  * Copyright (c) 2007 Shane King <kde@dontletsstart.com>                                *
0003  * Copyright (c) 2008 Leo Franchi <lfranchi@kde.org>                                    *
0004  *                                                                                      *
0005  * This program is free software; you can redistribute it and/or modify it under        *
0006  * the terms of the GNU General Public License as published by the Free Software        *
0007  * Foundation; either version 2 of the License, or (at your option) any later           *
0008  * version.                                                                             *
0009  *                                                                                      *
0010  * This program is distributed in the hope that it will be useful, but WITHOUT ANY      *
0011  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A      *
0012  * PARTICULAR PURPOSE. See the GNU General Public License for more details.             *
0013  *                                                                                      *
0014  * You should have received a copy of the GNU General Public License along with         *
0015  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
0016  ****************************************************************************************/
0017 
0018 #ifndef LASTFMSERVICE_H
0019 #define LASTFMSERVICE_H
0020 
0021 #include "services/ServiceBase.h"
0022 #include "services/lastfm/LastFmServiceConfig.h"
0023 #include "statsyncing/Provider.h"
0024 
0025 #include <QSharedPointer>
0026 
0027 namespace Collections {
0028     class LastFmServiceCollection;
0029 }
0030 namespace Dynamic {
0031     class AbstractBiasFactory;
0032 }
0033 class ScrobblerAdapter;
0034 class QLineEdit;
0035 class QComboBox;
0036 class QLabel;
0037 class QNetworkReply;
0038 class QPixmap;
0039 
0040 class LastFmServiceFactory : public ServiceFactory
0041 {
0042     Q_PLUGIN_METADATA(IID AmarokPluginFactory_iid FILE "amarok_service_lastfm.json")
0043     Q_INTERFACES(Plugins::PluginFactory)
0044     Q_OBJECT
0045 
0046 public:
0047     LastFmServiceFactory();
0048 
0049     void init() override;
0050     QString name() override;
0051     KConfigGroup config() override;
0052 
0053     bool possiblyContainsTrack( const QUrl &url ) const override;
0054 };
0055 
0056 class LastFmService : public ServiceBase
0057 {
0058     Q_OBJECT
0059 
0060 public:
0061     LastFmService( LastFmServiceFactory* parent, const QString &name );
0062     ~LastFmService() override;
0063 
0064     void polish() override;
0065 
0066     Collections::Collection * collection() override;
0067 
0068     void love( Meta::TrackPtr track );
0069 
0070 private Q_SLOTS:
0071     void loveCurrentTrack();
0072 
0073     void playCustomStation();
0074     void updateEditHint( int index );
0075 
0076     void slotReconfigure();
0077     void onAuthenticated();
0078     void onGetUserInfo();
0079     void onAvatarDownloaded( const QString& username, QPixmap avatar );
0080 
0081 private:
0082     void continueReconfiguring();
0083     void playLastFmStation( const QUrl &url );
0084     void updateProfileInfo();
0085 
0086     QSharedPointer<ScrobblerAdapter> m_scrobbler;
0087     StatSyncing::ProviderPtr m_synchronizationAdapter;
0088     Collections::LastFmServiceCollection *m_collection;
0089     QList<Dynamic::AbstractBiasFactory *> m_biasFactories;
0090 
0091     bool m_polished;
0092     QWidget *m_profileBox;
0093     QLabel *m_avatarLabel;
0094     QLabel *m_profile;
0095     QLabel *m_userinfo;
0096     QComboBox *m_globalComboBox;
0097     QLineEdit *m_customStationEdit;
0098     QPushButton *m_customStationButton;
0099     QComboBox *m_customStationCombo;
0100 
0101     QString m_station;
0102     QString m_age;
0103     QString m_gender;
0104     QString m_country;
0105     QString m_playcount;
0106     QPixmap m_avatar;
0107     bool m_subscriber;
0108 
0109     QNetworkReply *m_authenticateReply;
0110     LastFmServiceConfigPtr m_config;
0111 };
0112 
0113 #endif // LASTFMSERVICE_H