-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy paththundercore.h
168 lines (134 loc) · 4.31 KB
/
thundercore.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
* CloudClient - A Qt cloud client for lixian.vip.xunlei.com
* Copyright (C) 2012 by Aaron Lewis <[email protected]>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef THUNDERCORE_H
#define THUNDERCORE_H
#include <QObject>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QWebElement>
#include <QWebFrame>
#include <QWebPage>
#include <QNetworkRequest>
#include <QNetworkCookieJar>
#include <QDebug>
#include <QList>
#include <QDateTime>
#include "qjson/parser.h"
#include "CloudObject.h"
#include "util.h"
class ThunderCore : public QObject
{
Q_OBJECT
public:
enum LoginStatus
{
NoError,
CapchaRequired,
Failed
};
enum ErrorCategory
{
// general information
Info,
// neglectable error
Notice,
// error, but not crashing
Warning,
// critical error, must be closed
Critical
};
/*!
* \brief The ChangeType enum are for mainWindow only
*/
enum ChangeType
{
// that getCloudTasks() is ready
TaskChanged,
// that getLoginStatus()
LoginChanged,
// that getCapchaCode()
CapchaReady
};
enum RemoteTaskType
{
// that call getSingleRemoteTask();
SingleTaskReady,
// that call getUploadedBatchTasks();
BatchTaskReady,
// that call getUploadedBTTasks
BitorrentTaskReady
};
explicit ThunderCore(QObject *parent = 0);
void login (const QString & user, const QString & passwd);
LoginStatus getLoginStatus ();
QByteArray getCapchaCode ();
QList<Thunder::Task> getCloudTasks ();
QList<Thunder::Task> getGarbagedTasks ();
void reloadCloudTasks ();
void addCloudTaskPre (const QString & url);
void addCloudTaskPost (const Thunder::RemoteTask & task);
void removeCloudTasks (const QStringList & ids);
void delayCloudTask (const QStringList & ids);
void addBatchTaskPre (const QString & urls);
void addBatchTaskPost (const QStringList & urls);
void uploadBitorrent (const QString & file);
void commitBitorrentTask (const QList<Thunder::BTSubTask> &tasks);
void getContentsOfBTFolder (const Thunder::Task &bt_task);
Thunder::RemoteTask getSingleRemoteTask ();
Thunder::BitorrentTask getUploadedBTTasks();
QList<Thunder::BatchTask> getUploadedBatchTasks ();
void cleanupHistory ();
void loginWithCapcha (const QByteArray & capcha);
signals:
void error (const QString & body, ThunderCore::ErrorCategory category);
/*!
* \brief Something changed, refresh something in UI ..
*/
void StatusChanged (ThunderCore::ChangeType pt);
/*!
* \brief Remote task changed, links ready!
* In use of further notification for UI
* \param rt
*/
void RemoteTaskChanged (ThunderCore::RemoteTaskType rt);
void BTSubTaskReady (const Thunder::BitorrentTask & task);
private:
QList<Thunder::Task> tc_cloudTasks, tc_garbagedTasks;
void parseCloudPage (const QByteArray & body);
bool tmp_cookieIsStored;
Thunder::RemoteTask tmp_singleTask;
Thunder::BitorrentTask tmp_btTask;
QList<Thunder::BatchTask> tmp_batchTasks;
/* passwd should be cleared after use! */
QString tc_userName, tc_passwd;
QHash<QString, QString> tc_session;
LoginStatus tc_loginStatus;
QByteArray tc_capcha;
QNetworkAccessManager *tc_nam;
void get (const QUrl & url);
void post (const QUrl & url, const QByteArray & body);
private slots:
void slotFinished (QNetworkReply *reply);
public slots:
/*!
* \brief Set capcha from user input
* \param code
*/
void setCapcha (const QString & code);
};
#endif // THUNDERCORE_H