1 /*
2 
3                           Firewall Builder
4 
5                  Copyright (C) 2008 NetCitadel, LLC
6 
7   Author:  Vadim Kurland <vadim@fwbuilder.org>
8 
9   $Id$
10 
11   This program is free software which we release under the GNU General Public
12   License. You may redistribute and/or modify this program under the terms
13   of that license as published by the Free Software Foundation; either
14   version 2 of the License, or (at your option) any later version.
15 
16   This program is distributed in the hope that it will be useful,
17   but WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   GNU General Public License for more details.
20 
21   To get a copy of the GNU General Public License, write to the Free Software
22   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 
24 */
25 
26 #ifndef HTTPGET_H
27 #define HTTPGET_H
28 
29 #include <QString>
30 #include <QUrl>
31 #include <QObject>
32 
33 #include <qglobal.h>
34 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
35 
36 #include <QBuffer>
37 #include <QHttp>
38 #include <QByteArray>
39 
40 class HttpGet : public QObject
41 {
42     Q_OBJECT;
43 
44 private:
45     QHttp http;
46     QUrl url;
47     QBuffer strm;
48     bool status;
49     QString last_error;
50     QByteArray contents;
51     int request_id;
52 
53 public:
54     HttpGet(QObject *parent = 0);
55 
56     bool get(const QUrl &url);
getLastError()57     QString getLastError() { return last_error; }
getStatus()58     bool getStatus() { return status; }
toString()59     QString toString() { return QString(contents); }
60     void abort();
61 
62 signals:
63     void done(const QString &res);
64 
65 private slots:
66     void httpDone(int id, bool error);
67     void fileDone();
68 };
69 
70 #else // QT_VERSION = 5.0.0+
71 
72 class HttpGet : public QObject
73 {
74     Q_OBJECT;
75 
76 public:
77     HttpGet(QObject *parent = 0);
get(const QUrl & url)78     bool get(const QUrl &url) { Q_UNUSED(url) return false; }
getLastError()79     QString getLastError() { return QString("HttpGet is disabled when compiled with Qt 5"); }
getStatus()80     bool getStatus() { return false; }
toString()81     QString toString() { return QString(); }
abort()82     void abort() {}
83 
84 signals:
85     void done(const QString &res);
86 
87 private slots:
httpDone(int id,bool error)88     void httpDone(int id, bool error) { Q_UNUSED(id) Q_UNUSED(error) }
fileDone()89     void fileDone() {}
90 };
91 
92 #endif // QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
93 
94 #endif
95