Sayonara Player
CoverFetchThread.h
1 /* CoverFetchThread.h */
2 
3 /* Copyright (C) 2011-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 
21 
22 /*
23  * CoverFetchThread.h
24  *
25  * Created on: Jun 28, 2011
26  * Author: Lucio Carreras
27  */
28 
29 #ifndef COVERFETCHTHREAD_H_
30 #define COVERFETCHTHREAD_H_
31 
32 #include <QImage>
33 #include <QStringList>
34 #include "CoverLocation.h"
35 
36 class AsyncWebAccess;
41 class CoverFetchThread : public QObject {
42 
43  Q_OBJECT
44 
45 
46 signals:
51  void sig_finished(bool b);
52 
57  void sig_cover_found(const CoverLocation& cl);
58 
59 
60 public:
61  CoverFetchThread(QObject* parent, const CoverLocation& cl, const int n_covers);
62  virtual ~CoverFetchThread();
63 
69  bool start();
70 
75  bool more();
76 
77 
78 private:
79 
80  AsyncWebAccess* _single_img_fetcher=nullptr;
81  AsyncWebAccess* _multi_img_fetcher=nullptr;
82  AsyncWebAccess* _content_fetcher=nullptr;
83 
84  QString _url;
85  QString _target_file;
86  QStringList _addresses;
87 
91  int _n_covers;
92 
96  int _covers_found;
97 
98 
106  QStringList calc_addresses(int num,
107  const QByteArray& website,
108  const QString& regex) const;
109 
116  QStringList calc_addresses_from_google(int num,
117  const QByteArray& website) const;
118 
125  void save_and_emit_image(const QString& filepath,
126  const QImage& img,
127  const QString& url);
128 
129 
130 private slots:
136  void single_image_fetched(bool success);
137 
143  void multi_image_fetched(bool success);
144 
149  void content_fetched(bool success);
150 
151 };
152 
153 #endif /* COVERFETCHTHREAD_H_ */
The CoverFetchThread class, This is not a real QThread class, but behaves like one because of AsyncWe...
Definition: CoverFetchThread.h:41
void sig_cover_found(const CoverLocation &cl)
emitted, when covers has been found
The CoverLocation class.
Definition: CoverLocation.h:37
bool start()
start fetching covers, if the url does not contain "google", a direct link to an image is assumed and...
bool more()
fetch next cover
void sig_finished(bool b)
emitted, when thread has finished
Asynchgronous web access class.
Definition: AsyncWebAccess.h:37