~ubuntu-branches/ubuntu/saucy/clementine/saucy

« back to all changes in this revision

Viewing changes to src/core/albumcoverloader.h

  • Committer: Package Import Robot
  • Author(s): Thomas PIERSON
  • Date: 2012-01-01 20:43:39 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120101204339-lsb6nndwhfy05sde
Tags: 1.0.1+dfsg-1
New upstream release. (Closes: #653926, #651611, #657391)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of Clementine.
2
 
   Copyright 2010, David Sansome <me@davidsansome.com>
3
 
 
4
 
   Clementine is free software: you can redistribute it and/or modify
5
 
   it under the terms of the GNU General Public License as published by
6
 
   the Free Software Foundation, either version 3 of the License, or
7
 
   (at your option) any later version.
8
 
 
9
 
   Clementine is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
   GNU General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU General Public License
15
 
   along with Clementine.  If not, see <http://www.gnu.org/licenses/>.
16
 
*/
17
 
 
18
 
#ifndef ALBUMCOVERLOADER_H
19
 
#define ALBUMCOVERLOADER_H
20
 
 
21
 
#include "backgroundthread.h"
22
 
#include "song.h"
23
 
 
24
 
#include <QObject>
25
 
#include <QImage>
26
 
#include <QMutex>
27
 
#include <QQueue>
28
 
 
29
 
class NetworkAccessManager;
30
 
class QNetworkReply;
31
 
 
32
 
class AlbumCoverLoader : public QObject {
33
 
  Q_OBJECT
34
 
 
35
 
 public:
36
 
  AlbumCoverLoader(QObject* parent = 0);
37
 
 
38
 
  void Stop() { stop_requested_ = true; }
39
 
 
40
 
  static QString ImageCacheDir();
41
 
 
42
 
  void SetDesiredHeight(int height) { height_ = height; }
43
 
  void SetScaleOutputImage(bool scale) { scale_ = scale; }
44
 
  void SetPadOutputImage(bool padding) { padding_ = padding; }
45
 
  void SetDefaultOutputImage(const QImage& image);
46
 
 
47
 
 
48
 
  quint64 LoadImageAsync(const Song& song);
49
 
  virtual quint64 LoadImageAsync(
50
 
      const QString& art_automatic,
51
 
      const QString& art_manual,
52
 
      const QString& song_filename = QString(),
53
 
      const QImage& embedded_image = QImage());
54
 
 
55
 
  void Clear();
56
 
 
57
 
  static QPixmap TryLoadPixmap(const QString& automatic, const QString& manual,
58
 
                               const QString& filename = QString());
59
 
 
60
 
 signals:
61
 
  void ImageLoaded(quint64 id, const QImage& image);
62
 
  void ImageLoaded(quint64 id, const QImage& scaled, const QImage& original);
63
 
 
64
 
 protected slots:
65
 
  void ProcessTasks();
66
 
  void RemoteFetchFinished();
67
 
 
68
 
 protected:
69
 
  enum State {
70
 
    State_TryingManual,
71
 
    State_TryingAuto,
72
 
  };
73
 
 
74
 
  struct Task {
75
 
    Task() : redirects(0) {}
76
 
    quint64 id;
77
 
    QString art_automatic;
78
 
    QString art_manual;
79
 
    QString song_filename;
80
 
    QImage embedded_image;
81
 
    State state;
82
 
    int redirects;
83
 
  };
84
 
 
85
 
  struct TryLoadResult {
86
 
    TryLoadResult(bool async, bool success, const QImage& i)
87
 
      : started_async(async), loaded_success(success), image(i) {}
88
 
 
89
 
    bool started_async;
90
 
    bool loaded_success;
91
 
    QImage image;
92
 
  };
93
 
 
94
 
  void ProcessTask(Task* task);
95
 
  void NextState(Task* task);
96
 
  TryLoadResult TryLoadImage(const Task& task);
97
 
  QImage ScaleAndPad(const QImage& image) const;
98
 
 
99
 
  bool stop_requested_;
100
 
 
101
 
  int height_;
102
 
  bool scale_;
103
 
  bool padding_;
104
 
  QImage default_;
105
 
 
106
 
  QMutex mutex_;
107
 
  QQueue<Task> tasks_;
108
 
  QMap<QNetworkReply*, Task> remote_tasks_;
109
 
  quint64 next_id_;
110
 
 
111
 
  NetworkAccessManager* network_;
112
 
 
113
 
  static const int kMaxRedirects = 3;
114
 
};
115
 
 
116
 
#endif // ALBUMCOVERLOADER_H