Sayonara Player
CoverLookup.h
1 /* CoverLookup.h */
2 
3 /* Copyright (C) 2011-2020 Michael Lugmair (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  * CoverLookup.h
24  *
25  * Created on: Apr 4, 2011
26  * Author: Michael Lugmair (Lucio Carreras)
27  */
28 
29 #ifndef SAYONARA_COVER_LOOKUP_H
30 #define SAYONARA_COVER_LOOKUP_H
31 
32 #include "AbstractCoverLookup.h"
33 #include "Utils/Pimpl.h"
34 #include "Utils/CoverUtils.h"
35 
36 #include <QList>
37 #include <any>
38 
39 class QPixmap;
40 namespace Cover
41 {
42  class Location;
43 
48  class Lookup :
49  public LookupBase
50  {
51  Q_OBJECT
52  PIMPL(Lookup)
53 
54  public:
55  Lookup(const Location& coverLocation, int n_covers, QObject* parent);
56  ~Lookup() override;
57 
58  QList<QPixmap> pixmaps() const;
59  Util::Covers::Source source() const;
60 
61  template<typename T>
62  void setUserData(const T t)
63  {
64  mUserData = t;
65  }
66 
67  template<typename T>
68  auto userData() const -> T
69  {
70  try
71  {
72  return std::any_cast<T>(mUserData);
73  }
74  catch(...)
75  {
76  return T {};
77  }
78  }
79 
80  public slots:
81  void start();
82  void stop() override;
83 
84  private slots:
85  void coverFound(int idx);
86  void threadFinished();
87  void extractorFinished();
88 
89  private:
90  bool fetchFromDatabase();
91  void fetchFromExtractor();
92  bool fetchFromWWW();
93 
94  bool startNewThread(const Location& coverLocation);
95  bool addNewCover(const QPixmap& pixmap, bool save);
96 
97  void done(bool success);
98 
99  std::any mUserData;
100  };
101 }
102 #endif /* SAYONARA_COVER_LOOKUP_H */
Definition: CoverLocation.h:39
The CoverLookupInterface class.
Definition: AbstractCoverLookup.h:39
The CoverLookup class.
Definition: CoverLookup.h:50
Definition: EngineUtils.h:33