Sha256: ba666f0fc8455169ebfb707ccc84701902b700633827af559c63c8c5f0e46204
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
#include <QApplication> #include <QWebPage> #include <QWebFrame> #include "sunscraperworker.h" #include "sunscraperproxy.h" #include <QtDebug> SunscraperWorker::SunscraperWorker(QObject *parent) : QObject(parent) { } void SunscraperWorker::loadHtml(unsigned queryId, QString html) { QWebPage *webPage = initializeWebPage(queryId); webPage->mainFrame()->setHtml(html); } void SunscraperWorker::loadUrl(unsigned queryId, QString url) { QWebPage *webPage = initializeWebPage(queryId); webPage->mainFrame()->load(url); } void SunscraperWorker::finalize(unsigned queryId) { Q_ASSERT(_webPages[queryId] != NULL); _webPages[queryId]->deleteLater(); _webPages.remove(queryId); } QWebPage *SunscraperWorker::initializeWebPage(unsigned queryId) { Q_ASSERT(_webPages[queryId] == NULL); QWebPage *webPage = new QWebPage(this); webPage->settings()->setAttribute(QWebSettings::LocalStorageEnabled, true); connect(webPage->mainFrame(), SIGNAL(javaScriptWindowObjectCleared()), this, SLOT(attachAPI())); _webPages[queryId] = webPage; return webPage; } void SunscraperWorker::attachAPI() { QWebFrame *origin = static_cast<QWebFrame *>(QObject::sender()); QWebPage *page = origin->page(); unsigned queryId = _webPages.key(page, 0); Q_ASSERT(queryId != 0); SunscraperProxy *proxy = new SunscraperProxy(page, queryId); connect(proxy, SIGNAL(finished(uint,QString)), this, SIGNAL(finished(uint,QString))); origin->addToJavaScriptWindowObject("Sunscraper", proxy, QScriptEngine::QtOwnership); }
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
sunscraper-1.1.0.beta3 | ext/standalone/sunscraperworker.cpp |