예제 #1
0
bool MyWebView::eventFilter(QObject *watched, QEvent *event)
{
	if (!m_boolEnableEvtProcess) { return false; }

	if (event->type() == QEvent::MouseMove)
	{
		QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
		QWebView *view          = dynamic_cast<QWebView*>(watched);
		QPoint pos              = view->mapFromGlobal(mouseEvent->globalPos());
		QWebFrame *frame        = view->page()->frameAt(mouseEvent->pos());
		if (frame!=NULL)
		{
			QWebHitTestResult hitTestResult = frame->hitTestContent(pos);
			// if the hovered elem is not the same as the previously hovered
			if (hitTestResult.element() != m_old_hover_element)
			{
				QWebElement elemCurrent = hitTestResult.element();
				// if dragging, overwrite with closer WContainer
				if (m_boolIsDraggingWidget)
				{
					elemCurrent = FindCloserContainer(elemCurrent);
				}
				if (!elemCurrent.isNull())
				{
					// Change color
					ChangeHoveredElemColor(elemCurrent);
					// Message to print
					m_strCurrentElemId = elemCurrent.attribute("id");
					// Emit message
					QStringList strlistClasses = elemCurrent.classes();
					strlistClasses.removeAll(g_strHighlightClassName);
					Q_EMIT mouseMovedOverElem(m_strCurrentElemId, strlistClasses.join(' '));
				}
			}
		}
	}
	else if (event->type() == QEvent::MouseButtonPress)
	{
		QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
		if (mouseEvent->button() == Qt::LeftButton)
		{
			QWebView *view = dynamic_cast<QWebView*>(watched);
			QPoint pos = view->mapFromGlobal(mouseEvent->globalPos());
			QWebFrame *frame = view->page()->frameAt(mouseEvent->pos());
			if (frame != NULL)
			{
				QWebHitTestResult hitTestResult = frame->hitTestContent(pos);
                QWebElement welemTemp = hitTestResult.element();
                QWebElement elemCurrent = FindCloserWidget(welemTemp);
				// if the clicked elem is not the same as the previously clicked
				if (elemCurrent != m_old_click_element)
				{
					// Change color
					ChangeClickedElemColor(elemCurrent);
					// Message to print
					m_strCurrentElemId = elemCurrent.attribute("id");
					// Emit message
					Q_EMIT mouseLeftClickedOverElem(m_strCurrentElemId);
				}
			}
		}
	}
	return false;
}
예제 #2
0
void BrowserFrame::browserBack()
{
	QWebView *browser = static_cast<QWebView *>(currentWidget());
	if (browser != 0) browser->back();
}
예제 #3
0
void ClickToFlash::findElement()
{
    if (!m_toolButton) {
        return;
    }

    QWidget* parent = parentWidget();
    QWebView* view = 0;
    while (parent) {
        if (QWebView* aView = qobject_cast<QWebView*>(parent)) {
            view = aView;
            break;
        }
        parent = parent->parentWidget();
    }
    if (!view) {
        return;
    }

    QPoint objectPos = view->mapFromGlobal(m_toolButton->mapToGlobal(m_toolButton->pos()));
    QWebFrame* objectFrame = view->page()->frameAt(objectPos);
    QWebHitTestResult hitResult;
    QWebElement hitElement;

    if (objectFrame) {
        hitResult = objectFrame->hitTestContent(objectPos);
        hitElement = hitResult.element();
    }

    if (!hitElement.isNull() && (hitElement.tagName().compare("embed", Qt::CaseInsensitive) == 0 ||
                                 hitElement.tagName().compare("object", Qt::CaseInsensitive) == 0)) {
        m_element = hitElement;
        return;
    }

    // HitTestResult failed, trying to find element by src
    // attribute in elements at all frames on page (less accurate)

    QList<QWebFrame*> frames;
    frames.append(objectFrame);
    m_mainFrame = view->page()->mainFrame();
    frames.append(m_mainFrame);

    while (!frames.isEmpty()) {
        QWebFrame* frame = frames.takeFirst();
        if (!frame) {
            continue;
        }
        QWebElement docElement = frame->documentElement();

        QWebElementCollection elements;
        elements.append(docElement.findAll(QLatin1String("embed")));
        elements.append(docElement.findAll(QLatin1String("object")));

        foreach(const QWebElement & element, elements) {
            if (!checkElement(element) && !checkUrlOnElement(element)) {
                continue;
            }
            m_element = element;
            return;
        }
        frames += frame->childFrames();
    }
}
예제 #4
0
void test2(){
	QWebView *view = new QWebView;
	view->load(QUrl("http://127.0.0.1/user-center.html"));
	view->show();
}
예제 #5
0
void tst_QWebView::renderHints()
{
    QWebView webView;

    // default is only text antialiasing
    QVERIFY(!(webView.renderHints() & QPainter::Antialiasing));
    QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
    QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
    QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));

    webView.setRenderHint(QPainter::Antialiasing, true);
    QVERIFY(webView.renderHints() & QPainter::Antialiasing);
    QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
    QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
    QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));

    webView.setRenderHint(QPainter::Antialiasing, false);
    QVERIFY(!(webView.renderHints() & QPainter::Antialiasing));
    QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
    QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
    QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));

    webView.setRenderHint(QPainter::SmoothPixmapTransform, true);
    QVERIFY(!(webView.renderHints() & QPainter::Antialiasing));
    QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
    QVERIFY(webView.renderHints() & QPainter::SmoothPixmapTransform);
    QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));

    webView.setRenderHint(QPainter::SmoothPixmapTransform, false);
    QVERIFY(webView.renderHints() & QPainter::TextAntialiasing);
    QVERIFY(!(webView.renderHints() & QPainter::SmoothPixmapTransform));
    QVERIFY(!(webView.renderHints() & QPainter::HighQualityAntialiasing));
}
예제 #6
0
void QtMainWindow::GoBack(int index)
{
    QWebView* wv = (index < tabViews.size()) && (index >= 0) ? tabViews[index] : ui->webView;
    if (wv)
        wv->back();
}
예제 #7
0
void MainWindow::on_pushButton_5_clicked() //sql tab
{

    ui->progressBar->setValue(0);
    QString path = QCoreApplication::applicationDirPath() + "/";
    QSettings settings(path+"settings.ini", QSettings::IniFormat);
    QString webhost = settings.value("host").toString();
    QString webtoken = settings.value("token").toString();

    if(!ui->lineEdit_4->text().contains("http"))
    {
        QMessageBox::critical(this,"Error","There are two possible reasons either you need to enter a valid url or the prefix 'http' is missing!");
    }else if(ui->comboBox_3->currentIndex() == 1 && ui->lineEdit_5->text().isEmpty())
    {
        QMessageBox::critical(this,"Error","Please enter the variables in the POST field!");
    }else{
        //sqli scan
        QWebView *addsql = new QWebView; //instancia o pedido http GET
        QString url = ui->lineEdit_4->text();
        QString metodo = ui->comboBox_3->currentText();
        QString postdata2 = QUrl::toPercentEncoding(ui->lineEdit_5->text());

        QFile ficheiro(QApplication::applicationDirPath() + "/strings.txt");
        QStringList strings;
        int numlinhas=0;
        if (ficheiro.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            QTextStream input(&ficheiro);
            while (!input.atEnd()) {
                strings += input.readLine();
                numlinhas++;
        }


         QFile ficheiro2(QApplication::applicationDirPath() + "/erros.txt");
         QStringList erros;
         int totallinhas=0;
         if (ficheiro2.open(QIODevice::ReadOnly | QIODevice::Text))
         {
            QTextStream in(&ficheiro2);
            while (!in.atEnd())
            {
                erros += in.readLine();
                totallinhas++;
            }



        }

        QNetworkRequest request(url);
        request.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("application/x-www-form-urlencoded"));

        for(int i=0;i < numlinhas;i++)
        {
            QByteArray postdata; postdata.append(ui->lineEdit_5->text() + strings[i]);


            if(ui->comboBox_3->currentIndex() == 0){
                ui->webView_3->load(url+strings[i]);
            }else if(ui->comboBox_3->currentIndex() == 1){

                ui->webView_3->load(request,QNetworkAccessManager::PostOperation, postdata);
            }


             // qDebug() << url+strings[i];
               ui->progressBar->setValue(i*(100/numlinhas));

            QTime delay = QTime::currentTime().addSecs(3);
            while( QTime::currentTime() < delay )
            QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

            for(int j=0;j< totallinhas;j++)
            {
                qDebug() << erros[j];
            if(ui->webView_3->page()->mainFrame()->toHtml().contains(erros[j]))
            {

              ui->progressBar->setValue(100);
              QMessageBox::information(this,"Results","This website may be vulnerable to SQL Injection!");

              QUrl url2 = "http://"+webhost+"/vulndb/includes/add.php?add&tabela=sqli&token="+webtoken+"&url="+url+"&metodo="+metodo+"&postdata="+postdata2+"&vuln=1";
              addsql->load(url2);

              return;
            }


            }
        //return;

        }
        ui->progressBar->setValue(100);
        QMessageBox::information(this,"Results","This website does not appear to be vulnerable to SQL Injection!");

        QUrl url2 = "http://"+webhost+"/vulndb/includes/add.php?add&tabela=sqli&token="+webtoken+"&url="+url+"&metodo="+metodo+"&postdata="+postdata2+"&vuln=0";
        addsql->load(url2);
    }
}
}
예제 #8
0
void QWebViewPrivate::update(const QRect & dirtyRect)
{
    view->update(dirtyRect);
}
예제 #9
0
void QWebViewPrivate::setInputMethodEnabled(bool enable)
{
    view->setAttribute(Qt::WA_InputMethodEnabled, enable);
}
예제 #10
0
QPalette QWebViewPrivate::palette() const
{
    return view->palette();
}
예제 #11
0
void QWebViewPrivate::scroll(int dx, int dy, const QRect& rectToScroll)
{
    view->scroll(qreal(dx), qreal(dy), rectToScroll);
}
예제 #12
0
void QWebViewPrivate::updateCursor(const QCursor& cursor)
{
    view->setCursor(cursor);
}
예제 #13
0
void MainWindow::on_pushButton_8_clicked() //fpd
{
    QWebView *addsql = new QWebView; //instancia o pedido http GET
    QString path = QCoreApplication::applicationDirPath() + "/";
    QSettings settings(path+"settings.ini", QSettings::IniFormat);
    QString webhost = settings.value("host").toString();
    QString webtoken = settings.value("token").toString();

    if(!ui->lineEdit_9->text().contains("http"))
    {
        QMessageBox::critical(this,"Error","There are two possible reasons either you need to enter a valid url or the prefix 'http' is missing!");

    }else
    {

        QString url = ui->lineEdit_9->text();
        QString url2 = QUrl::toPercentEncoding(url);
        QString payload = QUrl::toPercentEncoding(ui->comboBox_4->currentText());
        QString urlarray = ui->lineEdit_9->text();
        QString subStr = "=";
        QString novaStr = "[]=";
        QByteArray cookie;
        urlarray.replace(urlarray.indexOf(subStr), subStr.size(), novaStr);

        QNetworkRequest request(url);

        if(ui->comboBox_4->currentIndex() == 1){
            cookie = "PHPSESSID=";
        }else if(ui->comboBox_4->currentIndex() == 2){
            cookie = "PHPSESSID=.";
        }else if(ui->comboBox_4->currentIndex() == 3){
            cookie = "PHPSESSID=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
        }

        request.setRawHeader("Cookie", cookie);
        ui->webView_5->load(request);


        if(ui->comboBox_4->currentIndex() == 0){
            ui->webView_5->load(urlarray);
        }


        QTime delay = QTime::currentTime().addSecs(3);
        while( QTime::currentTime() < delay )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);


        if(ui->webView_5->page()->mainFrame()->toHtml().contains("Warning:") ||
           //ui->webView_5->page()->mainFrame()->toHtml().contains("array") ||
           ui->webView_5->page()->mainFrame()->toHtml().contains("failed to open dir") ||
          // ui->webView_5->page()->mainFrame()->toHtml().contains("[]") ||
           ui->webView_5->page()->mainFrame()->toHtml().contains("on line") ||
           ui->webView_5->page()->mainFrame()->toHtml().contains("opendir") ||
           ui->webView_5->page()->mainFrame()->toHtml().contains("session_start") ||
           ui->webView_5->page()->mainFrame()->toHtml().contains("illegal characters") ||
           ui->webView_5->page()->mainFrame()->toHtml().contains("supplied argument"))

        {
            QMessageBox::information(this,"Results", "This website may be vulnerable to directory revelation!");
            QUrl urly = "http://"+webhost+"/vulndb/includes/add.php?add&tabela=fpd&token="+webtoken+"&url="+url2+"&payload="+payload+"&vuln=1";
            addsql->load(urly);
        }else{
            QMessageBox::information(this,"Results", "This website does not appear to be vulnerable to directory revelation!");
            QUrl urlx = "http://"+webhost+"/vulndb/includes/add.php?add&tabela=fpd&token="+webtoken+"&url="+url2+"&payload="+payload+"&vuln=0";
            addsql->load(urlx);
        }

        ui->webView_5->page()->networkAccessManager()->setCookieJar(new QNetworkCookieJar());
    }
}
예제 #14
0
void MainWindow::on_pushButton_4_clicked()
{
    QString path = QCoreApplication::applicationDirPath() + "/";
    QSettings settings(path+"settings.ini", QSettings::IniFormat);
    QWebView *addsql = new QWebView; //instancia o pedido http GET
    QString webhost = settings.value("host").toString();
    QString webtoken = settings.value("token").toString();

    if(!ui->lineEdit_6->text().contains("http"))
    {
        QMessageBox::critical(this,"Error","There are two possible reasons either you need to enter a valid url or the prefix 'http' is missing!");

    }else
    {
        QString link = ui->lineEdit_6->text();
        QString payload = ui->comboBox_2->currentText();

        QString link2 = QUrl::toPercentEncoding(link);
        QString payload2 = QUrl::toPercentEncoding(payload);

        QString nullbyte = "%00";


        if(ui->checkBox->isChecked())
        {
            ui->webView_2->load(QUrl(link + payload + nullbyte));
        }else{
            ui->webView_2->load(QUrl(link + payload));
        }


        QTime delay = QTime::currentTime().addSecs(3);
        while( QTime::currentTime() < delay )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

        if(ui->webView_2->page()->mainFrame()->toHtml().contains("include()") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("failed to open stream") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("Failed opening") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("include_once()") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("require_once()") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("/bin/bash") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("HTTP_USER_AGENT") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("root") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("for 16-bit app support") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("I love PHP") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("allow_url_fopen") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("allow_url_include") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("HTTP/1.1") ||
           ui->webView_2->page()->mainFrame()->toHtml().contains("require()"))

        {
            QMessageBox::information(this,"Results", "This website may be vulnerable to file inclusion!");

            QUrl urlx = "http://"+webhost+"/vulndb/includes/add.php?add&tabela=inc_fich&token="+webtoken+"&url="+link2+"&tipo=LFI&payload="+payload2+"&vuln=1";
            addsql->load(urlx);

        }else{
            QMessageBox::information(this,"Results", "This website does not appear to be vulnerable to file inclusion!");
            QUrl urly = "http://"+webhost+"/vulndb/includes/add.php?add&tabela=inc_fich&token="+webtoken+"&url="+link2+"&tipo=LFI&payload="+payload2+"&vuln=0";
            addsql->load(urly);
        }

    }

}
예제 #15
0
void QWebViewPrivate::_q_pageDestroyed()
{
    page = 0;
    view->setPage(0);
}
예제 #16
0
QCursor QWebViewPrivate::cursor() const
{
    return view->cursor();
}
예제 #17
0
DumpRenderTree::DumpRenderTree()
    : m_dumpPixels(false)
    , m_stdin(0)
    , m_enableTextOutput(false)
    , m_standAloneMode(false)
    , m_graphicsBased(false)
    , m_persistentStoragePath(QString(getenv("DUMPRENDERTREE_TEMP")))
{

    QByteArray viewMode = getenv("QT_DRT_WEBVIEW_MODE");
    if (viewMode == "graphics")
        setGraphicsBased(true);

    DumpRenderTreeSupportQt::overwritePluginDirectories();
    DumpRenderTreeSupportQt::activeMockDeviceOrientationClient(true);
    QWebSettings::enablePersistentStorage(m_persistentStoragePath);

    m_networkAccessManager = new NetworkAccessManager(this);
    // create our primary testing page/view.
    if (isGraphicsBased()) {
        WebViewGraphicsBased* view = new WebViewGraphicsBased(0);
        m_page = new WebPage(view, this);
        view->setPage(m_page);
        m_mainView = view;
    } else {
        QWebView* view = new QWebView(0);
        m_page = new WebPage(view, this);
        view->setPage(m_page);
        m_mainView = view;
    }
    // Use a frame group name for all pages created by DumpRenderTree to allow
    // testing of cross-page frame lookup.
    DumpRenderTreeSupportQt::webPageSetGroupName(m_page, "org.webkit.qt.DumpRenderTree");

    m_mainView->setContextMenuPolicy(Qt::NoContextMenu);
    m_mainView->resize(QSize(LayoutTestController::maxViewWidth, LayoutTestController::maxViewHeight));

    // clean up cache by resetting quota.
    qint64 quota = webPage()->settings()->offlineWebApplicationCacheQuota();
    webPage()->settings()->setOfflineWebApplicationCacheQuota(quota);

    // create our controllers. This has to be done before connectFrame,
    // as it exports there to the JavaScript DOM window.
    m_controller = new LayoutTestController(this);
    connect(m_controller, SIGNAL(showPage()), this, SLOT(showPage()));
    connect(m_controller, SIGNAL(hidePage()), this, SLOT(hidePage()));

    // async geolocation permission set by controller
    connect(m_controller, SIGNAL(geolocationPermissionSet()), this, SLOT(geolocationPermissionSet()));

    connect(m_controller, SIGNAL(done()), this, SLOT(dump()));
    m_eventSender = new EventSender(m_page);
    m_textInputController = new TextInputController(m_page);
    m_plainTextController = new PlainTextController(m_page);
    m_gcController = new GCController(m_page);

    // now connect our different signals
    connect(m_page, SIGNAL(frameCreated(QWebFrame *)),
            this, SLOT(connectFrame(QWebFrame *)));
    connectFrame(m_page->mainFrame());

    connect(m_page, SIGNAL(loadFinished(bool)),
            m_controller, SLOT(maybeDump(bool)));
    // We need to connect to loadStarted() because notifyDone should only
    // dump results itself when the last page loaded in the test has finished loading.
    connect(m_page, SIGNAL(loadStarted()),
            m_controller, SLOT(resetLoadFinished()));
    connect(m_page, SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested()));
    connect(m_page, SIGNAL(printRequested(QWebFrame*)), this, SLOT(dryRunPrint(QWebFrame*)));

    connect(m_page->mainFrame(), SIGNAL(titleChanged(const QString&)),
            SLOT(titleChanged(const QString&)));
    connect(m_page, SIGNAL(databaseQuotaExceeded(QWebFrame*,QString)),
            this, SLOT(dumpDatabaseQuota(QWebFrame*,QString)));
    connect(m_page, SIGNAL(applicationCacheQuotaExceeded(QWebSecurityOrigin *, quint64)),
            this, SLOT(dumpApplicationCacheQuota(QWebSecurityOrigin *, quint64)));
    connect(m_page, SIGNAL(statusBarMessage(const QString&)),
            this, SLOT(statusBarMessage(const QString&)));

    QObject::connect(this, SIGNAL(quit()), qApp, SLOT(quit()), Qt::QueuedConnection);

    DumpRenderTreeSupportQt::setDumpRenderTreeModeEnabled(true);
    QFocusEvent event(QEvent::FocusIn, Qt::ActiveWindowFocusReason);
    QApplication::sendEvent(m_mainView, &event);
}
QObject* WebPluginFactory::create (const QString& _mimeType, const QUrl& url, const QStringList& argumentNames, const QStringList& argumentValues) const
{
    //kDebug() << _mimeType << url << argumentNames;
    QString mimeType (_mimeType.trimmed());
    if (mimeType.isEmpty()) {
        extractGuessedMimeType (url, &mimeType);
    }

    const bool noPluginHandling = WebKitSettings::self()->isInternalPluginHandlingDisabled();

    if (!noPluginHandling && WebKitSettings::self()->isLoadPluginsOnDemandEnabled()) {
        const uint id = pluginId(url, argumentNames, argumentValues);
        if (!mPluginsLoadedOnDemand.contains(id)) {
            FakePluginWidget* widget = new FakePluginWidget(id, url, mimeType);
            connect(widget, SIGNAL(pluginLoaded(uint)), this, SLOT(loadedPlugin(uint)));
            return widget;
        }
    }

    Q_ASSERT(mPart); // should never happen!!
    KParts::ReadOnlyPart* part = 0;
    QWebView* view = (mPart ? mPart->view() : 0);

    if (noPluginHandling || !excludedMimeType(mimeType)) {
        QWebFrame* frame = (view ? view->page()->currentFrame() : 0);
        if (frame) {
            part = createPartInstanceFrom(mimeType, argumentNames, argumentValues, view, frame);
        }
    }

    kDebug() << "Asked for" << mimeType << "plugin, got" << part;

    if (part) {
        connect (part->browserExtension(), SIGNAL (openUrlNotify()),
                 mPart->browserExtension(), SIGNAL (openUrlNotify()));

        connect (part->browserExtension(), SIGNAL (openUrlRequest (KUrl, KParts::OpenUrlArguments, KParts::BrowserArguments)),
                 mPart->browserExtension(), SIGNAL (openUrlRequest (KUrl, KParts::OpenUrlArguments, KParts::BrowserArguments)));

        // Check if this part is scriptable
        KParts::ScriptableExtension* scriptExt = KParts::ScriptableExtension::childObject(part);
        if (!scriptExt) {
            // Try to fall back to LiveConnectExtension compat
            KParts::LiveConnectExtension* lc = KParts::LiveConnectExtension::childObject(part);
            if (lc) {
                scriptExt = KParts::ScriptableExtension::adapterFromLiveConnect(part, lc);
            }
        }

        if (scriptExt) {
            scriptExt->setHost(KParts::ScriptableExtension::childObject(mPart));
        }

        QMap<QString, QString> metaData = part->arguments().metaData();
        QString urlStr = url.toString (QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment);
        metaData.insert ("PropagateHttpHeader", "true");
        metaData.insert ("referrer", urlStr);
        metaData.insert ("cross-domain", urlStr);
        metaData.insert ("main_frame_request", "TRUE");
        metaData.insert ("ssl_activate_warnings", "TRUE");

        KWebPage *page = (view ? qobject_cast<KWebPage*>(view->page()) : 0);

        if (page) {
            const QString scheme = page->currentFrame()->url().scheme();
            if (page && (QString::compare (scheme, QL1S ("https"), Qt::CaseInsensitive) == 0 ||
                         QString::compare (scheme, QL1S ("webdavs"), Qt::CaseInsensitive) == 0))
                metaData.insert ("ssl_was_in_use", "TRUE");
            else
                metaData.insert ("ssl_was_in_use", "FALSE");
        }

        KParts::OpenUrlArguments openUrlArgs = part->arguments();
        openUrlArgs.metaData() = metaData;
        openUrlArgs.setMimeType(mimeType);
        part->setArguments(openUrlArgs);
        QMetaObject::invokeMethod(part, "openUrl", Qt::QueuedConnection, Q_ARG(KUrl, KUrl(url)));
        return part->widget();
    }

    return 0;
}
예제 #19
0
int main(int argc, char **argv)
{
    // Qt requires that we construct the global QApplication before creating any widgets.
    QApplication app(argc, argv);

    // use an ArgumentParser object to manage the program arguments.
    osg::ArgumentParser arguments(&argc,argv);

    // true = run osgViewer in a separate thread than Qt
    // false = interleave osgViewer and Qt in the main thread
    bool useFrameLoopThread = false;
    if (arguments.read("--no-frame-thread")) useFrameLoopThread = false;
    if (arguments.read("--frame-thread")) useFrameLoopThread = true;

    // true = use QWidgetImage
    // false = use QWebViewImage
    bool useWidgetImage = false;
    if (arguments.read("--useWidgetImage")) useWidgetImage = true;

    // true = use QWebView in a QWidgetImage to compare to QWebViewImage
    // false = make an interesting widget
    bool useBrowser = false;
    if (arguments.read("--useBrowser")) useBrowser = true;

    // true = use a QLabel for text
    // false = use a QTextEdit for text
    // (only applies if useWidgetImage == true and useBrowser == false)
    bool useLabel = false;
    if (arguments.read("--useLabel")) useLabel = true;

    // true = make a Qt window with the same content to compare to
    // QWebViewImage/QWidgetImage
    // false = use QWebViewImage/QWidgetImage (depending on useWidgetImage)
    bool sanityCheck = false;
    if (arguments.read("--sanityCheck")) sanityCheck = true;

    // Add n floating windows inside the QGraphicsScene.
    int numFloatingWindows = 0;
    while (arguments.read("--numFloatingWindows", numFloatingWindows));

    // true = Qt widgets will be displayed on a quad inside the 3D scene
    // false = Qt widgets will be an overlay over the scene (like a HUD)
    bool inScene = true;
    if (arguments.read("--fullscreen")) { inScene = false; }


    osg::ref_ptr<osg::Group> root = new osg::Group;

    if (!useWidgetImage)
    {
        //-------------------------------------------------------------------
        // QWebViewImage test
        //-------------------------------------------------------------------
        // Note: When the last few issues with QWidgetImage are fixed,
        // QWebViewImage and this if() {} section can be removed since
        // QWidgetImage can display a QWebView just like QWebViewImage. Use
        // --useWidgetImage --useBrowser to see that in action.

        if (!sanityCheck)
        {
            osg::ref_ptr<osgQt::QWebViewImage> image = new osgQt::QWebViewImage;

            if (arguments.argc()>1) image->navigateTo((arguments[1]));
            else image->navigateTo("http://www.openscenegraph.org/");

            osgWidget::GeometryHints hints(osg::Vec3(0.0f,0.0f,0.0f),
                                           osg::Vec3(1.0f,0.0f,0.0f),
                                           osg::Vec3(0.0f,0.0f,1.0f),
                                           osg::Vec4(1.0f,1.0f,1.0f,1.0f),
                                           osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO);

            osg::ref_ptr<osgWidget::Browser> browser = new osgWidget::Browser;
            browser->assign(image.get(), hints);

            root->addChild(browser.get());
        }
        else
        {
            // Sanity check, do the same thing as QGraphicsViewAdapter but in
            // a separate Qt window.
            QWebPage* webPage = new QWebPage;
            webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
            webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true);

            QWebView* webView = new QWebView;
            webView->setPage(webPage);

            if (arguments.argc()>1) webView->load(QUrl(arguments[1]));
            else webView->load(QUrl("http://www.openscenegraph.org/"));

            QGraphicsScene* graphicsScene = new QGraphicsScene;
            graphicsScene->addWidget(webView);

            QGraphicsView* graphicsView = new QGraphicsView;
            graphicsView->setScene(graphicsScene);

            QMainWindow* mainWindow = new QMainWindow;
            //mainWindow->setLayout(new QVBoxLayout);
            mainWindow->setCentralWidget(graphicsView);
            mainWindow->setGeometry(50, 50, 1024, 768);
            mainWindow->show();
            mainWindow->raise();
        }
    }
    else
    {
        //-------------------------------------------------------------------
        // QWidgetImage test
        //-------------------------------------------------------------------
        // QWidgetImage still has some issues, some examples are:
        //
        // 1. Editing in the QTextEdit doesn't work. Also when started with
        //    --useBrowser, editing in the search field on YouTube doesn't
        //    work. But that same search field when using QWebViewImage
        //    works... And editing in the text field in the pop-up getInteger
        //    dialog works too. All these cases use QGraphicsViewAdapter
        //    under the hood, so why do some work and others don't?
        //
        //    <<< FIXED, need TextEditorInteraction >>>
        //
        //    a) osgQtBrowser --useWidgetImage [--fullscreen] (optional)
        //    b) Try to click in the QTextEdit and type, or to select text
        //       and drag-and-drop it somewhere else in the QTextEdit. These
        //       don't work.
        //    c) osgQtBrowser --useWidgetImage --sanityCheck
        //    d) Try the operations in b), they all work.
        //    e) osgQtBrowser --useWidgetImage --useBrowser [--fullscreen]
        //    f) Try to click in the search field and type, it doesn't work.
        //    g) osgQtBrowser
        //    h) Try the operation in f), it works.
        //
        // 2. Operations on floating windows (--numFloatingWindows 1 or more).
        //    Moving by dragging the titlebar, clicking the close button,
        //    resizing them, none of these work. I wonder if it's because the
        //    OS manages those functions (they're functions of the window
        //    decorations) so we need to do something special for that? But
        //    in --sanityCheck mode they work.
        //
        //    a) osgQtBrowser --useWidgetImage --numFloatingWindows 1 [--fullscreen]
        //    b) Try to drag the floating window, click the close button, or
        //       drag its sides to resize it. None of these work.
        //    c) osgQtBrowser --useWidgetImage --numFloatingWindows 1 --sanityCheck
        //    d) Try the operations in b), all they work.
        //    e) osgQtBrowser --useWidgetImage [--fullscreen]
        //    f) Click the button so that the getInteger() dialog is
        //       displayed, then try to move that dialog or close it with the
        //       close button, these don't work.
        //    g) osgQtBrowser --useWidgetImage --sanityCheck
        //    h) Try the operation in f), it works.
        //
        // 3. (Minor) The QGraphicsView's scrollbars don't appear when
        //    using QWidgetImage or QWebViewImage. QGraphicsView is a
        //    QAbstractScrollArea and it should display scrollbars as soon as
        //    the scene is too large to fit the view.
        //
        //    <<< FIXED >>>
        //
        //    a) osgQtBrowser --useWidgetImage --fullscreen
        //    b) Resize the OSG window so it's smaller than the QTextEdit.
        //       Scrollbars should appear but don't.
        //    c) osgQtBrowser --useWidgetImage --sanityCheck
        //    d) Try the operation in b), scrollbars appear. Even if you have
        //       floating windows (by clicking the button or by adding
        //       --numFloatingWindows 1) and move them outside the view,
        //       scrollbars appear too. You can't test that case in OSG for
        //       now because of problem 2 above, but that's pretty cool.
        //
        // 4. (Minor) In sanity check mode, the widget added to the
        //    QGraphicsView is centered. With QGraphicsViewAdapter, it is not.
        //
        //    a) osgQtBrowser --useWidgetImage [--fullscreen]
        //    b) The QTextEdit and button are not in the center of the image
        //       generated by the QGraphicsViewAdapter.
        //    c) osgQtBrowser --useWidgetImage --sanityCheck
        //    d) The QTextEdit and button are in the center of the
        //       QGraphicsView.


        QWidget* widget = 0;
        if (useBrowser)
        {
            QWebPage* webPage = new QWebPage;
            webPage->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
            webPage->settings()->setAttribute(QWebSettings::PluginsEnabled, true);

            QWebView* webView = new QWebView;
            webView->setPage(webPage);

            if (arguments.argc()>1) webView->load(QUrl(arguments[1]));
            else webView->load(QUrl("http://www.youtube.com/"));

            widget = webView;
        }
        else
        {
            widget = new QWidget;
            widget->setLayout(new QVBoxLayout);

            QString text("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque velit turpis, euismod ac ultrices et, molestie non nisi. Nullam egestas dignissim enim, quis placerat nulla suscipit sed. Donec molestie elementum risus sit amet sodales. Nunc consectetur congue neque, at viverra massa pharetra fringilla. Integer vitae mi sem. Donec dapibus semper elit nec sollicitudin. Vivamus egestas ultricies felis, in mollis mi facilisis quis. Nam suscipit bibendum eros sed cursus. Suspendisse mollis suscipit hendrerit. Etiam magna eros, convallis non congue vel, faucibus ac augue. Integer ante ante, porta in ornare ullamcorper, congue nec nibh. Etiam congue enim vitae enim sollicitudin fringilla. Mauris mattis, urna in fringilla dapibus, ipsum sem feugiat purus, ac hendrerit felis arcu sed sapien. Integer id velit quam, sit amet dignissim tortor. Sed mi tortor, placerat ac luctus id, tincidunt et urna. Nulla sed nunc ante.Sed ut sodales enim. Ut sollicitudin ultricies magna, vel ultricies ante venenatis id. Cras luctus mi in lectus rhoncus malesuada. Sed ac sollicitudin nisi. Nunc venenatis congue quam, et suscipit diam consectetur id. Donec vel enim ac enim elementum bibendum ut quis augue. Nulla posuere suscipit dolor, id convallis tortor congue eu. Vivamus sagittis consectetur dictum. Duis a ante quis dui varius fermentum. In hac habitasse platea dictumst. Nam dapibus dolor eu felis eleifend in scelerisque dolor ultrices. Donec arcu lectus, fringilla ut interdum non, tristique id dolor. Morbi sagittis sagittis volutpat. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Duis venenatis ultrices euismod.Nam sit amet convallis libero. Integer lectus urna, eleifend et sollicitudin non, porttitor vel erat. Vestibulum pulvinar egestas leo, a porttitor turpis ullamcorper et. Vestibulum in ornare turpis. Ut nec libero a sem mattis iaculis quis id purus. Praesent ante neque, dictum vitae pretium vel, iaculis luctus dui. Etiam luctus tellus vel nunc suscipit a ullamcorper nisl semper. Nunc dapibus, eros in sodales dignissim, orci lectus egestas felis, sit amet vehicula tortor dolor eu quam. Vivamus pellentesque convallis quam aliquet pellentesque. Phasellus facilisis arcu ac orci fringilla aliquet. Donec sed euismod augue. Duis eget orci sit amet neque tempor fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In hac habitasse platea dictumst. Duis sollicitudin, lacus ac pellentesque lacinia, lacus magna pulvinar purus, pulvinar porttitor est nibh quis augue.Duis eleifend, massa sit amet mattis fringilla, elit turpis venenatis libero, sed convallis turpis diam sit amet ligula. Morbi non dictum turpis. Integer porttitor condimentum elit, sit amet sagittis nibh ultrices sit amet. Mauris ac arcu augue, id aliquet mauris. Donec ultricies urna id enim accumsan at pharetra dui adipiscing. Nunc luctus rutrum molestie. Curabitur libero ipsum, viverra at pulvinar ut, porttitor et neque. Aliquam sit amet dolor et purus sagittis adipiscing. Nam sit amet hendrerit sem. Etiam varius, ligula non ultricies dignissim, sapien dui commodo urna, eu vehicula enim nunc molestie augue. Fusce euismod, erat vitae pharetra tempor, quam eros tincidunt lorem, ut iaculis ligula erat vitae nibh. Aenean eu ultricies dolor. Curabitur suscipit viverra bibendum.Sed egestas adipiscing mi in egestas. Proin in neque in nibh blandit consequat nec quis tortor. Vestibulum sed interdum justo. Sed volutpat velit vitae elit pulvinar aliquam egestas elit rutrum. Proin lorem nibh, bibendum vitae sollicitudin condimentum, pulvinar ut turpis. Maecenas iaculis, mauris in consequat ultrices, ante erat blandit mi, vel fermentum lorem turpis eget sem. Integer ultrices tristique erat sit amet volutpat. In sit amet diam et nunc congue pellentesque at in dolor. Mauris eget orci orci. Integer posuere augue ornare tortor tempus elementum. Quisque iaculis, nunc ac cursus fringilla, magna elit cursus eros, id feugiat diam eros et tellus. Etiam consectetur ultrices erat quis rhoncus. Mauris eu lacinia neque. Curabitur suscipit feugiat tellus in dictum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed aliquam tempus ante a tempor. Praesent viverra erat quis sapien pretium rutrum. Praesent dictum scelerisque venenatis.Proin bibendum lectus eget nisl lacinia porta. Morbi eu erat in sapien malesuada vulputate. Cras non elit quam. Ut dictum urna quis nisl feugiat ac sollicitudin libero luctus. Donec leo mauris, varius at luctus eget, placerat quis arcu. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Etiam tristique, mauris ut lacinia elementum, mauris erat consequat massa, ac gravida nisi tellus vitae purus. Curabitur consectetur ultricies commodo. Cras pulvinar orci nec enim adipiscing tristique. Ut ornare orci id est fringilla sit amet blandit libero pellentesque. Vestibulum tincidunt sapien ut enim venenatis vestibulum ultricies ipsum tristique. Mauris tempus eleifend varius. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse vitae dui ac quam gravida semper. In ac enim ac ligula rutrum porttitor.Integer dictum sagittis leo, at convallis sapien facilisis eget. Etiam cursus bibendum tortor, faucibus aliquam lectus ullamcorper sed. Nulla pulvinar posuere quam, ut sagittis ligula tincidunt ut. Nulla convallis velit ut enim condimentum pulvinar. Quisque gravida accumsan scelerisque. Proin pellentesque nisi cursus tortor aliquet dapibus. Duis vel eros orci. Sed eget purus ligula. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec ullamcorper porta congue. Nunc id velit ut neque malesuada consequat in eu nisi. Nulla facilisi. Quisque pellentesque magna vitae nisl euismod ac accumsan tellus feugiat.Nulla facilisi. Integer quis orci lectus, non aliquam nisi. Vivamus varius porta est, ac porttitor orci blandit mattis. Sed dapibus facilisis dapibus. Duis tincidunt leo ac tortor faucibus hendrerit. Morbi sit amet sapien risus, vel luctus enim. Aliquam sagittis nunc id purus aliquam lobortis. Duis posuere viverra dui, sit amet convallis sem vulputate at. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque pellentesque, lectus id imperdiet commodo, diam diam faucibus lectus, sit amet vestibulum tortor lacus viverra eros.Maecenas nec augue lectus. Duis nec arcu eget lorem tempus sollicitudin suscipit vitae arcu. Nullam vitae mauris lectus. Vivamus id risus neque, dignissim vehicula diam. Cras rhoncus velit sed velit iaculis ac dignissim turpis luctus. Suspendisse potenti. Sed vitae ligula a ligula ornare rutrum sit amet ut quam. Duis tincidunt, nibh vitae iaculis adipiscing, dolor orci cursus arcu, vel congue tortor quam eget arcu. Suspendisse tellus felis, blandit ac accumsan vitae, fringilla id lorem. Duis tempor lorem mollis est congue ut imperdiet velit laoreet. Nullam interdum cursus mollis. Pellentesque non mauris accumsan elit laoreet viverra ut at risus. Proin rutrum sollicitudin sem, vitae ultricies augue sagittis vel. Cras quis vehicula neque. Aliquam erat volutpat. Aliquam erat volutpat. Praesent non est erat, accumsan rutrum lacus. Pellentesque tristique molestie aliquet. Cras ullamcorper facilisis faucibus. In non lorem quis velit lobortis pulvinar.Phasellus non sem ipsum. Praesent ut libero quis turpis viverra semper. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In hac habitasse platea dictumst. Donec at velit tellus. Fusce commodo pharetra tincidunt. Proin lacus enim, fringilla a fermentum ut, vestibulum ut nibh. Duis commodo dolor vel felis vehicula at egestas neque bibendum. Phasellus malesuada dictum ante in aliquam. Curabitur interdum semper urna, nec placerat justo gravida in. Praesent quis mauris massa. Pellentesque porttitor lacinia tincidunt. Phasellus egestas viverra elit vel blandit. Sed dapibus nisi et lectus pharetra dignissim. Mauris hendrerit lectus nec purus dapibus condimentum. Sed ac eros nulla. Aenean semper sapien a nibh aliquam lobortis. Aliquam elementum euismod sapien, in dapibus leo dictum et. Pellentesque augue neque, ultricies non viverra eu, tincidunt ac arcu. Morbi ut porttitor lectus.");

            if (useLabel)
            {
                QLabel* label = new QLabel(text);
                label->setWordWrap(true);
                label->setTextInteractionFlags(Qt::TextEditorInteraction);

                QPalette palette = label->palette();
                palette.setColor(QPalette::Highlight, Qt::darkBlue);
                palette.setColor(QPalette::HighlightedText, Qt::white);
                label->setPalette(palette);

                QScrollArea* scrollArea = new QScrollArea;
                scrollArea->setWidget(label);

                widget->layout()->addWidget(scrollArea);
            }
            else
            {
                QTextEdit* textEdit = new QTextEdit(text);
                textEdit->setReadOnly(false);
                textEdit->setTextInteractionFlags(Qt::TextEditorInteraction);

                QPalette palette = textEdit->palette();
                palette.setColor(QPalette::Highlight, Qt::darkBlue);
                palette.setColor(QPalette::HighlightedText, Qt::white);
                textEdit->setPalette(palette);

                widget->layout()->addWidget(textEdit);
            }

            QPushButton* button = new MyPushButton("Button");
            widget->layout()->addWidget(button);

            widget->setGeometry(0, 0, 800, 600);
        }

        QGraphicsScene* graphicsScene = 0;

        if (!sanityCheck)
        {
            osg::ref_ptr<osgQt::QWidgetImage> widgetImage = new osgQt::QWidgetImage(widget);
#if (QT_VERSION >= QT_VERSION_CHECK(4, 5, 0))
            widgetImage->getQWidget()->setAttribute(Qt::WA_TranslucentBackground);
#endif
            widgetImage->getQGraphicsViewAdapter()->setBackgroundColor(QColor(0, 0, 0, 0));
            //widgetImage->getQGraphicsViewAdapter()->resize(800, 600);
            graphicsScene = widgetImage->getQGraphicsViewAdapter()->getQGraphicsScene();

            osg::Camera* camera = 0;        // Will stay NULL in the inScene case.
            osg::Geometry* quad = osg::createTexturedQuadGeometry(osg::Vec3(0,0,0), osg::Vec3(1,0,0), osg::Vec3(0,1,0), 1, 1);
            osg::Geode* geode = new osg::Geode;
            geode->addDrawable(quad);

            osg::MatrixTransform* mt = new osg::MatrixTransform;

            osg::Texture2D* texture = new osg::Texture2D(widgetImage.get());
            texture->setResizeNonPowerOfTwoHint(false);
            texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
            texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
            texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
            mt->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture, osg::StateAttribute::ON);

            osgViewer::InteractiveImageHandler* handler;
            if (inScene)
            {
                mt->setMatrix(osg::Matrix::rotate(osg::Vec3(0,1,0), osg::Vec3(0,0,1)));
                mt->addChild(geode);

                handler = new osgViewer::InteractiveImageHandler(widgetImage.get());
            }
            else    // fullscreen
            {
                // The HUD camera's viewport needs to follow the size of the
                // window. MyInteractiveImageHandler will make sure of this.
                // As for the quad and the camera's projection, setting the
                // projection resize policy to FIXED takes care of them, so
                // they can stay the same: (0,1,0,1) with a quad that fits.

                // Set the HUD camera's projection and viewport to match the screen.
                camera = new osg::Camera;
                camera->setProjectionResizePolicy(osg::Camera::FIXED);
                camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1,0,1));
                camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF);
                camera->setViewMatrix(osg::Matrix::identity());
                camera->setClearMask(GL_DEPTH_BUFFER_BIT);
                camera->setRenderOrder(osg::Camera::POST_RENDER);
                camera->addChild(geode);
                camera->setViewport(0, 0, 1024, 768);

                mt->addChild(camera);

                handler = new osgViewer::InteractiveImageHandler(widgetImage.get(), texture, camera);
            }

            mt->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
            mt->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
            mt->getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
            mt->getOrCreateStateSet()->setAttribute(new osg::Program);

            osg::Group* overlay = new osg::Group;
            overlay->addChild(mt);

            root->addChild(overlay);

            quad->setEventCallback(handler);
            quad->setCullCallback(handler);
        }
        else
        {
            // Sanity check, do the same thing as QWidgetImage and
            // QGraphicsViewAdapter but in a separate Qt window.

            graphicsScene = new QGraphicsScene;
            graphicsScene->addWidget(widget);

            QGraphicsView* graphicsView = new QGraphicsView;
            graphicsView->setScene(graphicsScene);

            QMainWindow* mainWindow = new QMainWindow;
            mainWindow->setCentralWidget(graphicsView);
            mainWindow->setGeometry(50, 50, 1024, 768);
            mainWindow->show();
            mainWindow->raise();
        }

        // Add numFloatingWindows windows to the graphicsScene.
        for (unsigned int i = 0; i < (unsigned int)numFloatingWindows; ++i)
        {
            QWidget* window = new QWidget(0, Qt::Window);
            window->setWindowTitle(QString("Window %1").arg(i));
            window->setLayout(new QVBoxLayout);
            window->layout()->addWidget(new QLabel(QString("This window %1").arg(i)));
            window->layout()->addWidget(new MyPushButton(QString("Button in window %1").arg(i)));
            window->setGeometry(100, 100, 300, 300);

            QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, Qt::Window);
            proxy->setWidget(window);
            proxy->setFlag(QGraphicsItem::ItemIsMovable, true);

            graphicsScene->addItem(proxy);
        }

    }

    root->addChild(osgDB::readNodeFile("cow.osg.(15,0,5).trans.(0.1,0.1,0.1).scale"));

    osg::ref_ptr<osgViewer::Viewer> viewer = new osgViewer::Viewer(arguments);
    viewer->setSceneData(root.get());
    viewer->setCameraManipulator(new osgGA::TrackballManipulator());
    viewer->addEventHandler(new osgGA::StateSetManipulator(root->getOrCreateStateSet()));
    viewer->addEventHandler(new osgViewer::StatsHandler);
    viewer->addEventHandler(new osgViewer::WindowSizeHandler);

    viewer->setUpViewInWindow(50, 50, 1024, 768);
    viewer->getEventQueue()->windowResize(0, 0, 1024, 768);

    if (useFrameLoopThread)
    {
        // create a thread to run the viewer's frame loop
        ViewerFrameThread viewerThread(viewer.get(), true);
        viewerThread.startThread();

        // now start the standard Qt event loop, then exists when the viewerThead sends the QApplication::exit() signal.
        return QApplication::exec();

    }
    else
    {
        // run the frame loop, interleaving Qt and the main OSG frame loop
        while(!viewer->done())
        {
            // process Qt events - this handles both events and paints the browser image
            QCoreApplication::processEvents(QEventLoop::AllEvents, 100);

            viewer->frame();
        }

        return 0;
    }
}
예제 #20
0
void MainWindow::exploit()
{
    int linhas = ui->tableWidget->rowCount();
     QString ip = QUrl::toPercentEncoding(ui->lineEdit->text());

    /*
    //QPixmap redimensionar = found.scaled(17,17, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
    //icon x
    QPixmap notfound(QApplication::applicationDirPath() + "/notfound.png");
    QLabel *vermelho = new QLabel;
    vermelho->setPixmap(notfound);
    vermelho->setAlignment(Qt::AlignCenter);
    //ui->tableWidget->setCellWidget(i, 4, vermelho);

    //icon y
    QPixmap found(QApplication::applicationDirPath() + "/found.png");
    QLabel *verde = new QLabel;
    verde->setPixmap(found);
    verde->setAlignment(Qt::AlignCenter);
    //ui->tableWidget->setCellWidget(0, 4, verde);
    */

    QWebView *pesquisa = new QWebView;
    QString isvuln;

    for(int i=0;i < linhas;i++)
    {
        QString produto = QUrl::toPercentEncoding(ui->tableWidget->item(i,2)->text());
        QString versao = QUrl::toPercentEncoding(ui->tableWidget->item(i,3)->text());
        QString software = produto+" "+versao;
        QString porta = QUrl::toPercentEncoding(ui->tableWidget->item(i,0)->text());
        QString servico = QUrl::toPercentEncoding(ui->tableWidget->item(i,1)->text());

        /*
        if(versao.isEmpty())
        {
            ui->tableWidget->setItem(i,4,new QTableWidgetItem("Não"));
            //qDebug() << produto + " " +versao;
            continue;
        }
        */

        if(!produto.isEmpty() && !versao.isEmpty()){



        pesquisa->load(QUrl("http://www.exploit-db.com/search/?action=search&filter_description="+produto+"%20"+versao));

        //qDebug() << "http://www.exploit-db.com/search/?action=search&filter_description="+produto+"%20"+versao;



        QTime delay = QTime::currentTime().addSecs(3);
        while( QTime::currentTime() < delay )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);


        if(pesquisa->page()->mainFrame()->toHtml().contains("No results"))
        {
            ui->tableWidget->setItem(i,4,new QTableWidgetItem("No"));

        }else{
            ui->tableWidget->setItem(i,4,new QTableWidgetItem("Yes"));

        }


        }else{

            ui->tableWidget->setItem(i,4,new QTableWidgetItem("No"));


        }


        if(ui->tableWidget->item(i,4)->text() == "Yes")
        {
            isvuln="1";
        }else{
            isvuln="0";
        }
        QString path = QCoreApplication::applicationDirPath() + "/";
        QSettings settings(path+"settings.ini", QSettings::IniFormat);
        QString webhost = settings.value("host").toString();
        QString webtoken = settings.value("token").toString();


        QWebView *addsql = new QWebView; //instancia o pedido http GET
        QUrl url = "http://"+webhost+"/vulndb/includes/add.php?add&token="+webtoken+"&tabela=scans&host="+ip+"&porta="+porta+"&software="+software+"&servico="+servico+"&vuln="+isvuln;
        addsql->load(url);

        //qDebug() << isvuln << url;
    }
}