-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathcurlexecutor.cpp
122 lines (88 loc) · 2.32 KB
/
curlexecutor.cpp
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
#include "curlexecutor.h"
#include "every_cpp.h"
namespace BrowserAutomationStudioFramework
{
CurlExecutor::CurlExecutor(QObject *parent) :
QObject(parent)
{
Curl = 0;
Thread = 0;
Result = false;
Data = "Not Run";
UseExternalThread = false;
}
void CurlExecutor::SetThread(QThread *Thread)
{
this->Thread = Thread;
UseExternalThread = true;
}
CurlExecutor::~CurlExecutor()
{
Stop();
}
void CurlExecutor::Stop()
{
if(Curl)
{
emit StopCurl();
Curl = 0;
}
}
void CurlExecutor::SetFilename(const QString& FileName)
{
this->FileName = FileName;
}
void CurlExecutor::Execute()
{
if(!UseExternalThread)
{
Thread = new QThread();
}
Curl = new CurlWrapper();
Curl->SetFileName(FileName);
Curl->SetOptions(Options);
Curl->SetFilter(Filter);
Curl->moveToThread(Thread);
connect(this, SIGNAL(StartCurl()), Curl, SLOT(Start()));
connect(this, SIGNAL(StopCurl()), Curl, SLOT(Stop()));
connect(Curl, SIGNAL(Done(bool,QByteArray,QByteArray)), this, SLOT(DoneWrapper(bool,QByteArray,QByteArray)));
connect(Curl, SIGNAL(Done(bool,QByteArray,QByteArray)), Curl, SLOT(deleteLater()));
if(!UseExternalThread)
{
connect(Curl, SIGNAL(Done(bool,QByteArray,QByteArray)), Thread, SLOT(quit()));
connect(Thread, SIGNAL(finished()), Thread, SLOT(deleteLater()));
}
Thread->start();
emit StartCurl();
}
void CurlExecutor::DoneWrapper(bool Result,const QByteArray& Data,const QByteArray& Log)
{
this->Result = Result;
this->Data = Data;
this->Log = Log;
Curl = 0;
Options.clear();
Filter.clear();
emit Done();
}
QtCUrl::Options* CurlExecutor::GetOptions()
{
return &Options;
}
bool CurlExecutor::GetResult()
{
return Result;
}
QByteArray CurlExecutor::GetDataByteArray()
{
return Data;
}
void CurlExecutor::SetFilter(const QString& Filter)
{
this->Filter = Filter;
}
QByteArray CurlExecutor::GetLogByteArray()
{
return this->Log;
}
}