Debian Codegraph @

src/services/lastfm/biases/WeeklyTopBias.h

raw
1 /****************************************************************************************
2 * Copyright (c) 2009 Leo Franchi <[email protected]> *
3 * Copyright (c) 2011 Ralf Engels <[email protected]> *
4 * *
5 * This program is free software; you can redistribute it and/or modify it under *
6 * the terms of the GNU General Public License as published by the Free Software *
7 * Foundation; either version 2 of the License, or (at your option) any later *
8 * version. *
9 * *
10 * This program is distributed in the hope that it will be useful, but WITHOUT ANY *
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A *
12 * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU General Public License along with *
15 * this program. If not, see <http://www.gnu.org/licenses/>. *
16 ****************************************************************************************/
17
18 #ifndef WEEKLY_TOP_BIAS_H
19 #define WEEKLY_TOP_BIAS_H
20
21 #include "dynamic/biases/TagMatchBias.h"
22
23 class QNetworkReply;
24
25 namespace Dynamic
26 {
27
28 /**
29 * This is a bias which allows the user to select a range of dates, and then
30 * adds to the playlist tracks/artists/albums that were on their last.fm top
31 * tracks during that time
32 *
33 */
34 class WeeklyTopBias : public SimpleMatchBias
35 {
36 Q_OBJECT
37
38 public:
39 struct DateRange
40 {
41 QDateTime from;
42 QDateTime to;
43 };
44
45 WeeklyTopBias();
46 ~WeeklyTopBias() override;
47
48 void fromXml( QXmlStreamReader *reader ) override;
49 void toXml( QXmlStreamWriter *writer ) const override;
50
51 static QString sName();
52 QString name() const override;
53 QString toString() const override;
54
55 QWidget* widget( QWidget* parent = nullptr ) override;
56
57 bool trackMatches( int position,
58 const Meta::TrackList& playlist,
59 int contextCount ) const override;
60
61
62 DateRange range() const;
63 void setRange( const DateRange &range );
64
65 private Q_SLOTS:
66 void newQuery() override;
67 void newWeeklyTimesQuery();
68 void newWeeklyArtistQuery();
69
70 void weeklyTimesQueryFinished();
71 void weeklyArtistQueryFinished();
72
73 void fromDateChanged( const QDateTime& );
74 void toDateChanged( const QDateTime& );
75
76 private:
77 void loadFromFile();
78 void saveDataToFile() const;
79
80 DateRange m_range;
81
82 // be able to warn the user
83 uint m_earliestDate;
84
85 QList< uint > m_weeklyFromTimes;
86 QList< uint > m_weeklyToTimes;
87 QHash< uint, QStringList > m_weeklyArtistMap;
88
89 QNetworkReply* m_weeklyTimesJob;
90 QHash< uint, QNetworkReply*> m_weeklyArtistJobs;
91 };
92
93 class WeeklyTopBiasFactory : public Dynamic::AbstractBiasFactory
94 {
95 public:
96 QString i18nName() const override;
97 QString name() const override;
98 QString i18nDescription() const override;
99 BiasPtr createBias() override;
100 };
101 }
102
103 #endif