-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqtbrowser.h
132 lines (113 loc) · 4.66 KB
/
qtbrowser.h
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#ifndef QTBROWSER_H
#define QTBROWSER_H
#include <QObject>
#include <QDebug>
#include <QRegExp>
#include <QStringList>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QNetworkCookie>
#include <QEventLoop>
#include <QTime>
#include <QFile>
#include "useragencontainer.h"
class QtBrowser : public QObject
{
Q_OBJECT
protected:
/* Vars */
QNetworkAccessManager *manager;
QNetworkReply *reply;
QNetworkRequest request;
QNetworkCookieJar *cookieJar;
QStringList visitedUrls;
QString filename;
QString page;
QString srcUrl;
QString redirectLocation;
int toWait;
bool followOnRedirect;
QByteArray userAgent;
QString url;
public:
/* Methods */
explicit QtBrowser(QObject *parent = 0);
QtBrowser(QtBrowser &extBr);
void clone(QtBrowser &extBr);
QNetworkRequest getRequest();
QNetworkAccessManager *getManager();
/* Methods. Diff */
int randIt(int low, int high);
int randIt(int high);
/* Methods. Cookies */
QByteArray getCookie(const QNetworkCookieJar &cookieJar, const char *host, const QString &key);
QByteArray getCookie(const char *host, const QString &key);
bool setCookie(QNetworkCookieJar *cookieJar, const QUrl &host, const QString &key, const QString &value);
bool setCookie(QNetworkCookieJar *cookieJar, const char *host, const QString &key, const QString &value);
bool setCookie(const QUrl &host, const QString &key, const QString &value);
bool setCookie(const char *host, const QString &key, const QString &value);
bool syncCookies(QNetworkCookieJar *cookieJar, const QString &src, const QString &dst);
bool syncCookies(const QString &src, const QString &dst);
void clearCookies();
QList<QNetworkCookie> getCookies(QString src);
QNetworkCookieJar *getCookieJar();
/* Methods. Handling text from webpage */
QString regCap(const QString &where, const QString &what, bool setMin = true, int pos = 1);
QString regCap(const QString &what, bool setMin = true, int pos = 1);
QStringList regCapAll(const QString &where, const QString ®exp, int column = 1, bool setMin = true);
QStringList regCapAll(const QString ®exp, int column = 1);
QVector<QVector<QString> > getMatches(const QString ®exp, QString where = "", bool setMin = true);
QString getContent();
void setContent(QString page);
bool contains(QString text, Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive);
bool contains(QRegExp regexp);
QString htmlDecode(QString text);
// QString decodeXML(QString text);
QStringList getHttpLinks(QString text = "", QString url = "");
/* Methods. Receiving data */
void prepareNetworkRequest(QNetworkRequest &networkRequest);
QNetworkReply *getItSync(const QUrl &url, const QByteArray params = QByteArray());
QString getPage(const QUrl url, const QByteArray params = QByteArray());
QString getPage(const char *url, const QByteArray params = QByteArray());
void setFollowRedirects(bool val);
QNetworkReply *head(const QUrl url);
int getResponseCode();
/* Methods. JSON */
QString jsonVal(QString where, QString name);
/* Methods. URL */
void setURL(QString url);
QString getURL();
/* Methods. Tags */
QStringList getSpecifiedTags(const QString &where, const QString &tag);
bool isTagParam(const QString &tag, const QString ¶m);
QString getParamValue(const QString &where, const QString ¶mName);
QString getNameValue(QString where);
QStringList getForms();
QString getFormByProperty(const QString &where, const QString &prop, const QString &value);
QString getFormByProperty(const QString &property, const QString &value);
QString formPutValue(QString form, const QString &name, const QString &value);
QByteArray getFormParams(QString where);
QNetworkReply *submitForm(QString form);
void submit(QString form);
QString getFormByHTML(QString text);
/* Methods. Headers */
void generateUserAgent();
void setUserAgent(QByteArray);
QByteArray getUserAgent();
QString getRedirectLocation();
bool hasHeader(QByteArray headerName);
QByteArray getHeader(QByteArray header);
void setHeader(QByteArray name, QByteArray value);
QtBrowser clearHeader(QByteArray name);
QList<QPair<QByteArray, QByteArray> > headers();
/* Methods. TextEdit */
QString normalization(QString str);
QString decode(QString str);
/* Methods. Files */
bool save(const QString &fileName, QIODevice *data); // Сохранить данные на локальный носитель
bool save(const QString &fileName, const QString &data); // Сохранить текстовые данные на локальный носитель
signals:
public slots:
};
#endif // QTBROWSER_H