2007-07-25 20:21:06 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 by Dominik Riebeling
|
2007-08-14 22:47:01 +00:00
|
|
|
* $Id$
|
2007-07-25 20:21:06 +00:00
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* 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.
|
2007-07-25 20:21:06 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef HTTPGET_H
|
|
|
|
#define HTTPGET_H
|
|
|
|
|
2007-08-27 17:40:35 +00:00
|
|
|
#include <QtCore>
|
|
|
|
#include <QtNetwork>
|
2007-07-25 20:21:06 +00:00
|
|
|
|
|
|
|
class QUrl;
|
|
|
|
|
|
|
|
class HttpGet : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
HttpGet(QObject *parent = 0);
|
|
|
|
|
|
|
|
bool getFile(const QUrl &url);
|
|
|
|
void setProxy(const QUrl &url);
|
2008-03-05 21:12:24 +00:00
|
|
|
void setProxy(bool);
|
2007-07-25 20:21:06 +00:00
|
|
|
QHttp::Error error(void);
|
|
|
|
QString errorString(void);
|
|
|
|
void setFile(QFile*);
|
2007-08-27 17:40:35 +00:00
|
|
|
void setCache(QDir);
|
|
|
|
void setCache(bool);
|
2007-07-25 20:21:06 +00:00
|
|
|
int httpResponse(void);
|
2007-08-14 22:47:01 +00:00
|
|
|
QByteArray readAll(void);
|
2008-06-02 19:29:54 +00:00
|
|
|
bool isCached()
|
|
|
|
{ return m_cached; }
|
|
|
|
QDateTime timestamp(void)
|
|
|
|
{ return m_serverTimestamp; }
|
2008-05-17 19:36:54 +00:00
|
|
|
void setDumbCache(bool b) //< disable checking of http header timestamp for caching
|
|
|
|
{ m_dumbCache = b; }
|
2008-03-05 21:12:24 +00:00
|
|
|
static void setGlobalCache(const QDir d) //< set global cache path
|
|
|
|
{ m_globalCache = d; }
|
|
|
|
static void setGlobalProxy(const QUrl p) //< set global proxy value
|
|
|
|
{ m_globalProxy = p; }
|
2008-05-17 19:36:54 +00:00
|
|
|
static void setGlobalDumbCache(bool b) //< set "dumb" (ignore server status) caching mode
|
|
|
|
{ m_globalDumbCache = b; }
|
2007-07-25 20:21:06 +00:00
|
|
|
|
|
|
|
public slots:
|
|
|
|
void abort(void);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void done(bool);
|
|
|
|
void dataReadProgress(int, int);
|
|
|
|
void requestFinished(int, bool);
|
2008-05-13 19:38:17 +00:00
|
|
|
void headerFinished(void);
|
2007-07-25 20:21:06 +00:00
|
|
|
|
|
|
|
private slots:
|
|
|
|
void httpDone(bool error);
|
|
|
|
void httpFinished(int, bool);
|
|
|
|
void httpResponseHeader(const QHttpResponseHeader&);
|
2007-08-14 22:47:01 +00:00
|
|
|
void httpState(int);
|
|
|
|
void httpStarted(int);
|
2008-05-13 19:38:17 +00:00
|
|
|
void getFileFinish(void);
|
2007-07-25 20:21:06 +00:00
|
|
|
|
|
|
|
private:
|
2008-04-06 17:20:13 +00:00
|
|
|
bool initializeCache(const QDir&);
|
2008-03-05 21:12:24 +00:00
|
|
|
QHttp http; //< download object
|
2007-07-25 20:21:06 +00:00
|
|
|
QFile *outputFile;
|
2008-05-13 19:38:17 +00:00
|
|
|
int m_response; //< http response
|
|
|
|
int getRequest; //! get file http request id
|
|
|
|
int headRequest; //! get http header request id
|
2007-08-14 22:47:01 +00:00
|
|
|
QByteArray dataBuffer;
|
2007-08-15 13:28:15 +00:00
|
|
|
bool outputToBuffer;
|
2007-08-27 17:40:35 +00:00
|
|
|
bool m_usecache;
|
|
|
|
QDir m_cachedir;
|
2008-05-13 19:38:17 +00:00
|
|
|
QString m_cachefile; // cached filename
|
|
|
|
bool m_cached;
|
2008-03-05 21:12:24 +00:00
|
|
|
QUrl m_proxy;
|
|
|
|
static QDir m_globalCache; //< global cache path value
|
|
|
|
static QUrl m_globalProxy; //< global proxy value
|
2008-05-17 19:36:54 +00:00
|
|
|
static bool m_globalDumbCache; //< cache "dumb" mode global setting
|
2008-05-13 19:38:17 +00:00
|
|
|
QDateTime m_serverTimestamp; //< timestamp of file on server
|
|
|
|
QString m_query; //< constructed query to pass http getter
|
|
|
|
QString m_path; //< constructed path to pass http getter
|
|
|
|
QString m_hash; //< caching hash
|
2008-05-17 19:36:54 +00:00
|
|
|
bool m_dumbCache; //< true if caching should ignore the server header
|
2007-07-25 20:21:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|