Pass command arguments to the constructor
This commit is contained in:
parent
b3b1adf63f
commit
85dcc729dd
|
@ -6,7 +6,7 @@ class Body : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Body(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Body(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -3,13 +3,10 @@
|
|||
#include "NetworkCookieJar.h"
|
||||
#include <QNetworkCookie>
|
||||
|
||||
ClearCookies::ClearCookies(WebPage *page, QObject *parent)
|
||||
: Command(page, parent)
|
||||
{ }
|
||||
ClearCookies::ClearCookies(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
|
||||
|
||||
void ClearCookies::start(QStringList &arguments)
|
||||
void ClearCookies::start()
|
||||
{
|
||||
Q_UNUSED(arguments);
|
||||
NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
|
||||
->networkAccessManager()
|
||||
->cookieJar());
|
||||
|
|
|
@ -6,6 +6,6 @@ class ClearCookies : public Command {
|
|||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
ClearCookies(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
ClearCookies(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
#include "Command.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Command::Command(WebPage *page, QObject *parent) : QObject(parent) {
|
||||
Command::Command(WebPage *page, QStringList &arguments, QObject *parent) : QObject(parent) {
|
||||
m_page = page;
|
||||
m_arguments = arguments;
|
||||
}
|
||||
|
||||
void Command::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
void Command::start() {
|
||||
}
|
||||
|
||||
WebPage *Command::page() {
|
||||
return m_page;
|
||||
}
|
||||
|
||||
QStringList &Command::arguments() {
|
||||
return m_arguments;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,17 +11,19 @@ class Command : public QObject {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Command(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Command(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
|
||||
signals:
|
||||
void finished(Response *response);
|
||||
|
||||
protected:
|
||||
WebPage *page();
|
||||
QStringList &arguments();
|
||||
|
||||
private:
|
||||
WebPage *m_page;
|
||||
QStringList m_arguments;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ CommandFactory::CommandFactory(WebPage *page, QObject *parent) : QObject(parent)
|
|||
m_page = page;
|
||||
}
|
||||
|
||||
Command *CommandFactory::createCommand(const char *name) {
|
||||
Command *CommandFactory::createCommand(const char *name, QStringList &arguments) {
|
||||
#include "find_command.h"
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ class CommandFactory : public QObject {
|
|||
|
||||
public:
|
||||
CommandFactory(WebPage *page, QObject *parent = 0);
|
||||
Command *createCommand(const char *name);
|
||||
Command *createCommand(const char *name, QStringList &arguments);
|
||||
|
||||
private:
|
||||
WebPage *m_page;
|
||||
|
|
|
@ -38,14 +38,14 @@ void Connection::commandReady(QString commandName, QStringList arguments) {
|
|||
void Connection::startCommand() {
|
||||
m_commandWaiting = false;
|
||||
if (m_pageSuccess) {
|
||||
m_command = m_commandFactory->createCommand(m_commandName.toAscii().constData());
|
||||
m_command = m_commandFactory->createCommand(m_commandName.toAscii().constData(), m_arguments);
|
||||
if (m_command) {
|
||||
connect(m_page, SIGNAL(loadStarted()), this, SLOT(pageLoadingFromCommand()));
|
||||
connect(m_command,
|
||||
SIGNAL(finished(Response *)),
|
||||
this,
|
||||
SLOT(finishCommand(Response *)));
|
||||
m_command->start(m_arguments);
|
||||
m_command->start();
|
||||
} else {
|
||||
QString failure = QString("[Capybara WebKit] Unknown command: ") + m_commandName + "\n";
|
||||
writeResponse(new Response(false, failure));
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include "ConsoleMessages.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
ConsoleMessages::ConsoleMessages(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
ConsoleMessages::ConsoleMessages(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void ConsoleMessages::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
void ConsoleMessages::start() {
|
||||
emit finished(new Response(true, page()->consoleMessages()));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class ConsoleMessages : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
ConsoleMessages(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
ConsoleMessages(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "CurrentUrl.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
CurrentUrl::CurrentUrl(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
CurrentUrl::CurrentUrl(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -51,9 +51,7 @@ CurrentUrl::CurrentUrl(WebPage *page, QObject *parent) : Command(page, parent) {
|
|||
* redirect w/o pushState, in which case QWebFrame->url() will have the correct
|
||||
* current_url value. In all other cases QWebFrame->requestedUrl() is correct.
|
||||
*/
|
||||
void CurrentUrl::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
|
||||
void CurrentUrl::start() {
|
||||
QUrl humanUrl = wasRedirectedAndNotModifiedByJavascript() ?
|
||||
page()->currentFrame()->url() : page()->currentFrame()->requestedUrl();
|
||||
QByteArray encodedBytes = humanUrl.toEncoded();
|
||||
|
|
|
@ -6,8 +6,8 @@ class CurrentUrl : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
CurrentUrl(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
CurrentUrl(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
|
||||
private:
|
||||
bool wasRegularLoad();
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#include "WebPage.h"
|
||||
#include <iostream>
|
||||
|
||||
Evaluate::Evaluate(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Evaluate::Evaluate(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
m_buffer = "";
|
||||
}
|
||||
|
||||
void Evaluate::start(QStringList &arguments) {
|
||||
QVariant result = page()->currentFrame()->evaluateJavaScript(arguments[0]);
|
||||
void Evaluate::start() {
|
||||
QVariant result = page()->currentFrame()->evaluateJavaScript(arguments()[0]);
|
||||
addVariant(result);
|
||||
emit finished(new Response(true, m_buffer));
|
||||
}
|
||||
|
|
|
@ -8,8 +8,8 @@ class Evaluate : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Evaluate(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Evaluate(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
|
||||
private:
|
||||
void addVariant(QVariant &object);
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "Execute.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Execute::Execute(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Execute::Execute(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Execute::start(QStringList &arguments) {
|
||||
QString script = arguments[0] + QString("; 'success'");
|
||||
void Execute::start() {
|
||||
QString script = arguments()[0] + QString("; 'success'");
|
||||
QVariant result = page()->currentFrame()->evaluateJavaScript(script);
|
||||
if (result.isValid()) {
|
||||
emit finished(new Response(true));
|
||||
|
|
|
@ -6,7 +6,7 @@ class Execute : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Execute(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Execute(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#include "Command.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Find::Find(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Find::Find(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Find::start(QStringList &arguments) {
|
||||
void Find::start() {
|
||||
QString message;
|
||||
QVariant result = page()->invokeCapybaraFunction("find", arguments);
|
||||
QVariant result = page()->invokeCapybaraFunction("find", arguments());
|
||||
|
||||
if (result.isValid()) {
|
||||
message = result.toString();
|
||||
|
|
|
@ -6,8 +6,8 @@ class Find : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Find(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Find(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -2,17 +2,17 @@
|
|||
#include "Command.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
FrameFocus::FrameFocus(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
FrameFocus::FrameFocus(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void FrameFocus::start(QStringList &arguments) {
|
||||
void FrameFocus::start() {
|
||||
findFrames();
|
||||
switch(arguments.length()) {
|
||||
switch(arguments().length()) {
|
||||
case 1:
|
||||
focusId(arguments[0]);
|
||||
focusId(arguments()[0]);
|
||||
break;
|
||||
case 2:
|
||||
focusIndex(arguments[1].toInt());
|
||||
focusIndex(arguments()[1].toInt());
|
||||
break;
|
||||
default:
|
||||
focusParent();
|
||||
|
|
|
@ -7,8 +7,8 @@ class FrameFocus : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FrameFocus(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
FrameFocus(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
|
||||
private:
|
||||
void findFrames();
|
||||
|
|
|
@ -2,15 +2,13 @@
|
|||
#include "WebPage.h"
|
||||
#include "NetworkCookieJar.h"
|
||||
|
||||
GetCookies::GetCookies(WebPage *page, QObject *parent)
|
||||
: Command(page, parent)
|
||||
GetCookies::GetCookies(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent)
|
||||
{
|
||||
m_buffer = "";
|
||||
}
|
||||
|
||||
void GetCookies::start(QStringList &arguments)
|
||||
void GetCookies::start()
|
||||
{
|
||||
Q_UNUSED(arguments);
|
||||
NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
|
||||
->networkAccessManager()
|
||||
->cookieJar());
|
||||
|
|
|
@ -6,8 +6,8 @@ class GetCookies : public Command {
|
|||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
GetCookies(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
GetCookies(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
|
||||
private:
|
||||
QString m_buffer;
|
||||
|
|
|
@ -2,12 +2,12 @@
|
|||
#include "WebPage.h"
|
||||
#include "NetworkAccessManager.h"
|
||||
|
||||
Header::Header(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Header::Header(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Header::start(QStringList &arguments) {
|
||||
QString key = arguments[0];
|
||||
QString value = arguments[1];
|
||||
void Header::start() {
|
||||
QString key = arguments()[0];
|
||||
QString value = arguments()[1];
|
||||
NetworkAccessManager* networkAccessManager = qobject_cast<NetworkAccessManager*>(page()->networkAccessManager());
|
||||
if (key.toLower().replace("-", "_") == "user_agent") {
|
||||
page()->setUserAgent(value);
|
||||
|
|
|
@ -6,6 +6,6 @@ class Header : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Header(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Header(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include "Headers.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Headers::Headers(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Headers::Headers(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Headers::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
void Headers::start() {
|
||||
emit finished(new Response(true, page()->pageHeaders()));
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ class Headers : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Headers(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Headers(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
#include "Node.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Node::Node(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Node::Node(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Node::start(QStringList &arguments) {
|
||||
QStringList functionArguments(arguments);
|
||||
void Node::start() {
|
||||
QStringList functionArguments(arguments());
|
||||
QString functionName = functionArguments.takeFirst();
|
||||
QVariant result = page()->invokeCapybaraFunction(functionName, functionArguments);
|
||||
QString attributeValue = result.toString();
|
||||
|
|
|
@ -7,7 +7,7 @@ class Node : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Node(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Node(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
#include "Render.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Render::Render(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Render::Render(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Render::start(QStringList &arguments) {
|
||||
QStringList functionArguments(arguments);
|
||||
QString imagePath = functionArguments.takeFirst();
|
||||
int width = functionArguments.takeFirst().toInt();
|
||||
int height = functionArguments.takeFirst().toInt();
|
||||
void Render::start() {
|
||||
QString imagePath = arguments()[0];
|
||||
int width = arguments()[1].toInt();
|
||||
int height = arguments()[2].toInt();
|
||||
|
||||
QSize size(width, height);
|
||||
page()->setViewportSize(size);
|
||||
|
|
|
@ -7,6 +7,6 @@ class Render : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Render(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Render(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include "RequestedUrl.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
RequestedUrl::RequestedUrl(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
RequestedUrl::RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void RequestedUrl::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
|
||||
void RequestedUrl::start() {
|
||||
QUrl humanUrl = page()->currentFrame()->requestedUrl();
|
||||
QByteArray encodedBytes = humanUrl.toEncoded();
|
||||
QString urlString = QString(encodedBytes);
|
||||
|
|
|
@ -6,7 +6,7 @@ class RequestedUrl : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
RequestedUrl(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
RequestedUrl(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
#include "NetworkAccessManager.h"
|
||||
#include "NetworkCookieJar.h"
|
||||
|
||||
Reset::Reset(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Reset::Reset(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Reset::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
|
||||
void Reset::start() {
|
||||
page()->triggerAction(QWebPage::Stop);
|
||||
page()->networkAccessManager()->setCookieJar(new NetworkCookieJar());
|
||||
page()->setCustomNetworkAccessManager();
|
||||
|
|
|
@ -6,8 +6,8 @@ class Reset : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Reset(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Reset(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
|
||||
private:
|
||||
void resetHistory();
|
||||
|
|
|
@ -3,13 +3,11 @@
|
|||
#include "NetworkCookieJar.h"
|
||||
#include <QNetworkCookie>
|
||||
|
||||
SetCookie::SetCookie(WebPage *page, QObject *parent)
|
||||
: Command(page, parent)
|
||||
{ }
|
||||
SetCookie::SetCookie(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
|
||||
|
||||
void SetCookie::start(QStringList &arguments)
|
||||
void SetCookie::start()
|
||||
{
|
||||
QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(arguments[0].toAscii());
|
||||
QList<QNetworkCookie> cookies = QNetworkCookie::parseCookies(arguments()[0].toAscii());
|
||||
NetworkCookieJar *jar = qobject_cast<NetworkCookieJar*>(page()
|
||||
->networkAccessManager()
|
||||
->cookieJar());
|
||||
|
|
|
@ -6,6 +6,6 @@ class SetCookie : public Command {
|
|||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
SetCookie(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
SetCookie(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
|
|
@ -3,21 +3,19 @@
|
|||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkProxy>
|
||||
|
||||
SetProxy::SetProxy(WebPage *page, QObject *parent)
|
||||
: Command(page, parent)
|
||||
{ }
|
||||
SetProxy::SetProxy(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {}
|
||||
|
||||
void SetProxy::start(QStringList &arguments)
|
||||
void SetProxy::start()
|
||||
{
|
||||
// default to empty proxy
|
||||
QNetworkProxy proxy;
|
||||
|
||||
if (arguments.size() > 0)
|
||||
if (arguments().size() > 0)
|
||||
proxy = QNetworkProxy(QNetworkProxy::HttpProxy,
|
||||
arguments[0],
|
||||
(quint16)(arguments[1].toInt()),
|
||||
arguments[2],
|
||||
arguments[3]);
|
||||
arguments()[0],
|
||||
(quint16)(arguments()[1].toInt()),
|
||||
arguments()[2],
|
||||
arguments()[3]);
|
||||
|
||||
page()->networkAccessManager()->setProxy(proxy);
|
||||
emit finished(new Response(true));
|
||||
|
|
|
@ -6,6 +6,6 @@ class SetProxy : public Command {
|
|||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
SetProxy(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
SetProxy(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include "Source.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Source::Source(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Source::Source(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Source::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments)
|
||||
|
||||
void Source::start() {
|
||||
QNetworkAccessManager* accessManager = page()->networkAccessManager();
|
||||
QNetworkRequest request(page()->currentFrame()->url());
|
||||
reply = accessManager->get(request);
|
||||
|
|
|
@ -7,8 +7,8 @@ class Source : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Source(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Source(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
|
||||
public slots:
|
||||
void sourceLoaded();
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
#include "WebPage.h"
|
||||
#include <sstream>
|
||||
|
||||
Status::Status(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Status::Status(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Status::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
void Status::start() {
|
||||
int status = page()->getLastStatus();
|
||||
emit finished(new Response(true, QString::number(status)));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ class Status : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Status(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Status(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
#include "Url.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Url::Url(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Url::Url(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Url::start(QStringList &argments) {
|
||||
Q_UNUSED(argments);
|
||||
|
||||
void Url::start() {
|
||||
QUrl humanUrl = page()->currentFrame()->url();
|
||||
QByteArray encodedBytes = humanUrl.toEncoded();
|
||||
QString urlString = QString(encodedBytes);
|
||||
|
|
|
@ -6,7 +6,7 @@ class Url : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Url(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &argments);
|
||||
Url(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
#include "Command.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Visit::Visit(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Visit::Visit(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Visit::start(QStringList &arguments) {
|
||||
QUrl requestedUrl = QUrl::fromEncoded(arguments[0].toUtf8(), QUrl::StrictMode);
|
||||
void Visit::start() {
|
||||
QUrl requestedUrl = QUrl::fromEncoded(arguments()[0].toUtf8(), QUrl::StrictMode);
|
||||
page()->currentFrame()->load(QUrl(requestedUrl));
|
||||
emit finished(new Response(true));
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ class Visit : public Command {
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Visit(WebPage *page, QObject *parent = 0);
|
||||
virtual void start(QStringList &arguments);
|
||||
Visit(WebPage *page, QStringList &arguments, QObject *parent = 0);
|
||||
virtual void start();
|
||||
};
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
#include "Body.h"
|
||||
#include "WebPage.h"
|
||||
|
||||
Body::Body(WebPage *page, QObject *parent) : Command(page, parent) {
|
||||
Body::Body(WebPage *page, QStringList &arguments, QObject *parent) : Command(page, arguments, parent) {
|
||||
}
|
||||
|
||||
void Body::start(QStringList &arguments) {
|
||||
Q_UNUSED(arguments);
|
||||
void Body::start() {
|
||||
QString result = page()->currentFrame()->toHtml();
|
||||
emit finished(new Response(true, result));
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#define CHECK_COMMAND(expectedName) \
|
||||
if (strcmp(#expectedName, name) == 0) { \
|
||||
return new expectedName(m_page, this); \
|
||||
return new expectedName(m_page, arguments, this); \
|
||||
}
|
||||
|
||||
CHECK_COMMAND(Visit)
|
||||
|
|
Loading…
Reference in New Issue