/***************************************************************************
 *   Copyright (C) 2007-2011 by Vegeta                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef COVERDOWNLOAD_H
#define COVERDOWNLOAD_H

#include <QWidget>

class QNetworkReply;
class QNetworkAccessManager;
class QNetworkReply;
class QDialog;
class QLabel;
class QSlider;
class QTimer;


enum SEARCHENGINE {AMAZON = 0, GOOGLE};

class DownloadJobClass{
public:
    QString DownloadURL;
    QString DownloadFolder;
    QString InterpretInfos;
    QStringList PictureAlternatives;
};

class CoverDownload : public QWidget
{
    Q_OBJECT

public:
    explicit CoverDownload(QWidget *parent = 0);
    ~CoverDownload();

    void cancelAllDownloads(){isCancelAllJobs = true; DownloadJobs.clear();}
    int totalDownloadJobs() const {return DownloadJobs.size();}
    int completedDownloadJobs() const {return currentItem;}
    int skippedDownloadJobs() const {return Skipped;}
    int failedDownloadJobs() const {return Errors;}
    void addDownloadJob(QString DisplayInfo, QString DownloadInfo, QString DownloadFolder, int searchEngine);
    QString currentInterpretInfos() const {return DownloadJobs.isEmpty() ?  "" : DownloadJobs[currentItem].InterpretInfos;}
    void startDownloads();


private:
    QList<DownloadJobClass> DownloadJobs;

    bool isCancelAllJobs;
    bool isDownloadJobRunning;
    bool isSingleDownloadJob;
    int currentItem;
    int Errors;
    int Skipped;
    int searchEngine;
    QNetworkAccessManager *getResults;
    QNetworkAccessManager *DownloaderPicture;
    QNetworkAccessManager *getAmazonPictureURL;
    QNetworkReply *currentNetworkReply;
    QTimer *timeout;

    QDialog *p_Dialog;
    QLabel  *p_CoverInfos;
    QLabel  *p_Picture;
    QSlider *p_horizontalSlider;
    QAction *p_actionLoadAnother;
    void previewCovers();

signals:
    void signal_updateDownloadInfos();
    void signal_allDownloadsFinished();
    void signal_addToErrorlog(QString Error);

private slots:
    void replyFinished(QNetworkReply *reply);
    void replyGetPictureURLfromAmazon(QNetworkReply *reply);
    void replyFinishedPicture(QNetworkReply *reply);
    void setCoverPicture(const int &Nummer);
    void deleteCover();
    void Timeout();
    void LoadAnotherCover();

};

#endif // COVERDOWNLOAD_H



