File indexing completed on 2025-01-05 04:26:56
0001 /**************************************************************************************** 0002 * Copyright (c) 2009 Leo Franchi <lfranchi@kde.org> * 0003 * Copyright (c) 2011 Ralf Engels <ralf-engels@gmx.de> * 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 WEEKLY_TOP_BIAS_H 0019 #define WEEKLY_TOP_BIAS_H 0020 0021 #include "dynamic/biases/TagMatchBias.h" 0022 0023 class QNetworkReply; 0024 0025 namespace Dynamic 0026 { 0027 0028 /** 0029 * This is a bias which allows the user to select a range of dates, and then 0030 * adds to the playlist tracks/artists/albums that were on their last.fm top 0031 * tracks during that time 0032 * 0033 */ 0034 class WeeklyTopBias : public SimpleMatchBias 0035 { 0036 Q_OBJECT 0037 0038 public: 0039 struct DateRange 0040 { 0041 QDateTime from; 0042 QDateTime to; 0043 }; 0044 0045 WeeklyTopBias(); 0046 ~WeeklyTopBias() override; 0047 0048 void fromXml( QXmlStreamReader *reader ) override; 0049 void toXml( QXmlStreamWriter *writer ) const override; 0050 0051 static QString sName(); 0052 QString name() const override; 0053 QString toString() const override; 0054 0055 QWidget* widget( QWidget* parent = nullptr ) override; 0056 0057 bool trackMatches( int position, 0058 const Meta::TrackList& playlist, 0059 int contextCount ) const override; 0060 0061 0062 DateRange range() const; 0063 void setRange( const DateRange &range ); 0064 0065 private Q_SLOTS: 0066 void newQuery() override; 0067 void newWeeklyTimesQuery(); 0068 void newWeeklyArtistQuery(); 0069 0070 void weeklyTimesQueryFinished(); 0071 void weeklyArtistQueryFinished(); 0072 0073 void fromDateChanged( const QDateTime& ); 0074 void toDateChanged( const QDateTime& ); 0075 0076 private: 0077 void loadFromFile(); 0078 void saveDataToFile() const; 0079 0080 DateRange m_range; 0081 0082 // be able to warn the user 0083 uint m_earliestDate; 0084 0085 QList< uint > m_weeklyFromTimes; 0086 QList< uint > m_weeklyToTimes; 0087 QHash< uint, QStringList > m_weeklyArtistMap; 0088 0089 QNetworkReply* m_weeklyTimesJob; 0090 QHash< uint, QNetworkReply*> m_weeklyArtistJobs; 0091 }; 0092 0093 class WeeklyTopBiasFactory : public Dynamic::AbstractBiasFactory 0094 { 0095 public: 0096 QString i18nName() const override; 0097 QString name() const override; 0098 QString i18nDescription() const override; 0099 BiasPtr createBias() override; 0100 }; 0101 } 0102 0103 #endif