Sayonara Player
LFMTrackChangedThread.h
1 /* LFMTrackChangedThread.h
2 
3  * Copyright (C) 2012-2016 Lucio Carreras
4  *
5  * This file is part of sayonara-player
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  * created by Lucio Carreras,
21  * Jul 18, 2012
22  *
23  */
24 
25 #ifndef LFMTRACKCHANGEDTHREAD_H_
26 #define LFMTRACKCHANGEDTHREAD_H_
27 
28 #include <QThread>
29 #include <QList>
30 #include <QMap>
31 #include <QHash>
32 #include <QDomDocument>
33 
34 #include "LFMGlobals.h"
35 #include "ArtistMatch.h"
36 
37 #include "Helper/SmartCompare/SmartCompare.h"
38 #include "Helper/MetaData/MetaData.h"
39 #include "Helper/Settings/SayonaraClass.h"
40 
41 #define LFM_THREAD_TASK_UPDATE_TRACK 1<<0
42 #define LFM_THREAD_TASK_SIM_ARTISTS 1<<1
43 
44 
45 class LFMTrackChangedThread : public QObject, protected SayonaraClass {
46 
47  Q_OBJECT
48 
49 
50 signals:
51 
52  void sig_similar_artists_available(const IDList& artist_ids);
53 
54 
55 public:
56  LFMTrackChangedThread(const QString& username=QString(), const QString& session_key=QString(), QObject* parent=nullptr);
58 
59 
60  void set_session_key(const QString& session_key);
61  void set_username(const QString& username);
62 
63 
64  void search_similar_artists(const MetaData& md);
65  void update_now_playing(const MetaData& md);
66 
67 
68 private:
69 
70  /* update track */
71  QString _artist;
72  QString _username;
73  QString _session_key;
74  QHash<QString, ArtistMatch> _sim_artists_cache;
75  MetaData _md;
76  SmartCompare* _smart_comparison=nullptr;
77 
78 
79 
80 private:
81  void evaluate_artist_match(const ArtistMatch& artist_match);
82 
83  QMap<QString, int> filter_available_artists(const ArtistMatch& artist_match, ArtistMatch::Quality quality);
84 
85 
86 private slots:
87  void response_sim_artists(const QByteArray& data);
88  void error_sim_artists(const QString& error);
89 
90  void response_update(const QByteArray& response);
91  void error_update(const QString& error);
92 };
93 
94 #endif /* LFMTRACKCHANGEDTHREAD_H_ */
The SayonaraClass class provides access to Settings and notifications.
Definition: SayonaraClass.h:31
Definition: MetaData.h:49
Quality
The Quality enum used to access the bin of interest. See ArtistMatch::get(Quality q) ...
Definition: ArtistMatch.h:53
Definition: ArtistMatch.h:31
The SmartCompare class.
Definition: SmartCompare.h:51
Definition: LFMTrackChangedThread.h:45
Definition: org_mpris_media_player2_adaptor.h:21