summaryrefslogtreecommitdiffstats
path: root/rbutil/rbutilqt/base/httpget.h
blob: ba4cbc821e9aa4c928eb5d112b00916405b54aec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 *
 *   Copyright (C) 2007 by Dominik Riebeling
 *   $Id$
 *
 * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/


#ifndef HTTPGET_H
#define HTTPGET_H

#include <QtCore>
#include <QtNetwork>

class QUrl;

class HttpGet : public QObject
{
    Q_OBJECT

    public:
        HttpGet(QObject *parent = 0);

        bool getFile(const QUrl &url);
        void setProxy(const QUrl &url);
        void setProxy(bool);
        QHttp::Error error(void);
        QString errorString(void);
        void setFile(QFile*);
        void setCache(QDir);
        void setCache(bool);
        int httpResponse(void);
        QByteArray readAll(void);
        bool isCached()
            { return m_cached; }
        QDateTime timestamp(void)
            { return m_serverTimestamp; }
        void setDumbCache(bool b) //< disable checking of http header timestamp for caching
            { m_dumbCache = b; }
        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; }
        static void setGlobalDumbCache(bool b) //< set "dumb" (ignore server status) caching mode
            { m_globalDumbCache = b; }
        static void setGlobalUserAgent(QString u) //< set global user agent string
            { m_globalUserAgent = u; }

    public slots:
        void abort(void);

    signals:
        void done(bool);
        void dataReadProgress(int, int);
        void requestFinished(int, bool);
        void headerFinished(void);

    private slots:
        void httpDone(bool error);
        void httpFinished(int, bool);
        void httpResponseHeader(const QHttpResponseHeader&);
        void httpState(int);
        void httpStarted(int);
        void getFileFinish(void);

    private:
        bool initializeCache(const QDir&);
        QHttp http; //< download object
        QFile *outputFile;
        int m_response; //< http response
        int getRequest;  //! get file http request id
        int headRequest; //! get http header request id
        QByteArray dataBuffer;
        bool outputToBuffer;
        bool m_usecache;
        QDir m_cachedir;
        QString m_cachefile; // cached filename
        bool m_cached;
        QUrl m_proxy;
        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
        bool m_dumbCache; //< true if caching should ignore the server header
        QHttpRequestHeader m_header;

        static QDir m_globalCache; //< global cache path value
        static QUrl m_globalProxy; //< global proxy value
        static bool m_globalDumbCache; //< cache "dumb" mode global setting
        static QString m_globalUserAgent; //< global user agent string
};

#endif