Permalink
Browse files

Pass command arguments to the constructor

  • Loading branch information...
1 parent b3b1adf commit 85dcc729ddf04800b7efe6433ca1cca3d0d6e605 @jferris jferris committed Mar 16, 2012
View
@@ -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());
View
@@ -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();
};
View
@@ -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;
+}
+
View
@@ -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;
View
@@ -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();
};
View
@@ -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();
View
@@ -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();
View
@@ -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));
}
View
@@ -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);
View
@@ -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));
View
@@ -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();
};
View
@@ -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();
View
@@ -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();
};
View
@@ -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();
View
@@ -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();
View
@@ -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());
View
@@ -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;
View
@@ -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);
View
@@ -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();
};
View
@@ -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()));
}
View
@@ -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();
};
View
@@ -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();
View
@@ -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();
};
Oops, something went wrong. Retry.

0 comments on commit 85dcc72

Please sign in to comment.