예제 #1
0
파일: formextractor.cpp 프로젝트: BGmot/Qt
void FormExtractor::submit()
{
    QWebFrame *frame = ui.webView->page()->mainFrame();

    QWebElement firstName = frame->findFirstElement("#firstname");
    QWebElement lastName = frame->findFirstElement("#lastname");
    QWebElement maleGender = frame->findFirstElement("#genderMale");
    QWebElement femaleGender = frame->findFirstElement("#genderFemale");
    QWebElement updates = frame->findFirstElement("#updates");

    ui.firstNameEdit->setText(firstName.evaluateJavaScript("this.value").toString());
    ui.lastNameEdit->setText(lastName.evaluateJavaScript("this.value").toString());

    if (maleGender.evaluateJavaScript("this.checked").toBool())
        ui.genderEdit->setText(maleGender.evaluateJavaScript("this.value").toString());
    else if (femaleGender.evaluateJavaScript("this.checked").toBool())
        ui.genderEdit->setText(femaleGender.evaluateJavaScript("this.value").toString());

    if (updates.evaluateJavaScript("this.checked").toBool())
        ui.updatesEdit->setText("Yes");
    else
        ui.updatesEdit->setText("No");

    // In mobile devices, change the tab when the data has been submitted
    #if defined Q_OS_SYMBIAN || defined Q_WS_HILDON || defined Q_WS_MAEMO_5 || defined Q_WS_SIMULATOR
        ui.tabWidget->setCurrentWidget(ui.tabData);
    #endif
}
예제 #2
0
void AuthenticationDialog::loadFinished()
{
//     Q_D(AuthenticationDialog);
    QUrl url = d->webView->url();

    if (url.host() == "www.facebook.com" && url.path() == "/login.php") {
        if (d->username.isEmpty() && d->password.isEmpty()) {
            return;
        }

        QWebFrame *frame = d->webView->page()->mainFrame();
        if (!d->username.isEmpty()) {
            QWebElement email = frame->findFirstElement("input#email");
            if (!email.isNull()) {
                email.setAttribute("value", d->username);
            }
        }

        if (!d->password.isEmpty()) {
            QWebElement passd = frame->findFirstElement("input#pass");
            if (!passd.isNull()) {
                passd.setAttribute("value", d->password);
            }
        }
        return;
    }
}
예제 #3
0
void MainWindow::onMessage(IrcPrivateMessage *message) {
    auto messages = read.getMessages(message->target());
    int messageCount = 150; // Subject to change via settings, currently set as twitch default
    PattyIrcMessage* pattyMsg = PattyIrcMessage::fromMessage(message);
    messages->append(pattyMsg);

    if (message->target() == this->currentChannel) {
        QString html;
        QWebFrame* frame = this->ui->baseChatWindow->page()->mainFrame();
        this->scrollValue = frame->scrollBarValue(Qt::Vertical);
        this->autoScroll = (this->scrollValue >= frame->scrollBarMaximum(Qt::Vertical));
        if (this->autoScroll) {
            while (messages->count() > messageCount) {
                delete messages->takeFirst();
                QWebElement message = frame->findFirstElement("div.message");
                message.removeFromDocument();
            }
        }
        addMessage(pattyMsg);
    } else {
        if (messages->count() > messageCount) {
            delete messages->takeFirst();
        }
    }
}
예제 #4
0
//void ArestShopPlugin::SinglePageFound()
//{
//#ifdef USE_WEBKIT
//	QWebFrame * ptrFrame = getWebPage()->mainFrame();
//	parseProductPage(m_stCompData);
//	m_stCompData.strCompURL = ptrFrame->url().toString();
//	emit priceSearchedFinished(m_stCompData);
//	productFoundFinish();
//#endif
//};
void ArestShopPlugin::parseSearchProductPage(SearchResult & stResult,bool & bNextPage)
{
	//run XML search page parse

	bNextPage=false;
#ifdef USE_WEBKIT
	QWebFrame * ptrFrame = getWebPage()->mainFrame();
	//////////////////////////////////////////////////////////////////////////
	QWebElementCollection tableProdRows = ptrFrame->findAllElements("table[class=pricelist]");
	
	for(int iIndex=0;iIndex<tableProdRows.count();++iIndex)
	{
		QWebElement prodNameHeader = tableProdRows.at(iIndex).findFirst("td[class=nazwa]");
		if (prodNameHeader.isNull())
			continue;
		QWebElement productLink = prodNameHeader.findFirst("a");
		QUrl stProductURL = productLink.attribute("href");
		//////////////////////////////////////////////////////////////////////////
		QString strName = productLink.toPlainText();
		stResult.insert(std::make_pair(strName,stProductURL));
	}
	//////////////////////////////////////////////////////////////////////////
	QWebElement tablePageNavi = ptrFrame->findFirstElement("li[class=next]");
	if (tablePageNavi.isNull())
	{
		bNextPage=false;
		return;
	}
	bNextPage=true;
#endif
	stResult.insert(Arest::mSearchResult.begin(),Arest::mSearchResult.end());
	bNextPage=m_bLoadNextPage;
}
예제 #5
0
QWebElement QWebFrameProto::findFirstElement(const QString & selectorQuery) const
{
  scriptDeprecated("QWebFrame will not be available in future versions");
  QWebFrame *item = qscriptvalue_cast<QWebFrame*>(thisObject());
  if (item)
    return item->findFirstElement(selectorQuery);
  return QWebElement();
}
예제 #6
0
void ArestShopPlugin::parseProductPage()
{
#ifdef USE_WEBKIT
	QWebFrame * ptrFrame = getWebPage()->mainFrame();
	printPageContent(ptrFrame->toHtml());
	QWebElement elCompFullName = ptrFrame->findFirstElement("h1[class=nazwatowaru]");
	QWebElement elPrice = ptrFrame->findFirstElement("span[class=price]"); //div class="altFontFace price"
	QString strPrice = elPrice.toPlainText();
	for(int i = 0;i<strPrice.size();i++)
	{
		if (strPrice.at(i).isLetterOrNumber())
			continue;
		strPrice = strPrice.left(i);
		break;
	}
	m_stCompData.dPrice = strPrice.toDouble();
	m_stCompData.eSearchResult = SR_COMPFOUND;
	m_stCompData.strCompURL = getWebPage()->mainFrame()->url().toString();
#endif
#ifdef USE_XML_PARSER
	m_stCompData.dPrice = Arest::dPrice;
	m_stCompData.eSearchResult = SR_COMPFOUND;
#endif
}
예제 #7
0
void AlertWebApp::updateContentRect()
{
    QWebFrame* frame = page()->page()->mainFrame();
    QWebElement el = frame->findFirstElement("[x-palm-popup-content]");
    QRect r;
    if (!el.isNull()) {
        r = el.geometry();
    	r.setLeft(MAX(0, r.left()));
	    r.setRight(MIN(r.right(), (int) m_windowWidth));
    	r.setTop(MAX(0, r.top()));
	    r.setBottom(MIN(r.bottom(), (int) m_windowHeight));
    }

	m_channel->sendAsyncMessage(new ViewHost_Alert_SetContentRect(routingId(),
																  r.left(), r.right(), 
																  r.top(), r.bottom()));
}
예제 #8
0
void KWebKitPart::slotMainFrameLoadFinished (bool ok)
{
    if (!ok || !m_doLoadFinishedActions)
        return;

    m_doLoadFinishedActions = false;

    if (!m_emitOpenUrlNotify) {
        m_emitOpenUrlNotify = true; // Save history once page loading is done.
    }

    // If the document contains no <title> tag, then set it to the current url.
    if (m_webView->title().trimmed().isEmpty()) {
        // If the document title is empty, then set it to the current url
        const QUrl url (m_webView->url());
        const QString caption (url.toString((QUrl::RemoveQuery|QUrl::RemoveFragment)));
        emit setWindowCaption(caption);

        // The urlChanged signal is emitted if and only if the main frame
        // receives the title of the page so we manually invoke the slot as a
        // work around here for pages that do not contain it, such as text
        // documents...
        slotUrlChanged(url);
    }

   QWebFrame* frame = page()->mainFrame();

    if (!frame || frame->url() == *globalBlankUrl)
        return;

    // Set the favicon specified through the <link> tag...
    if (WebKitSettings::self()->favIconsEnabled()
        && !frame->page()->settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) {
        const QWebElement element = frame->findFirstElement(QL1S("head>link[rel=icon], "
                                                                 "head>link[rel=\"shortcut icon\"]"));
        QUrl shortcutIconUrl;
        if (!element.isNull()) {
            shortcutIconUrl = frame->baseUrl().resolved(QUrl(element.attribute("href")));
            //kDebug() << "setting favicon to" << shortcutIconUrl;
            m_browserExtension->setIconUrl(shortcutIconUrl);
        }
    }

    slotFrameLoadFinished(ok);
}
예제 #9
0
void KWebKitPart::slotLoadFinished(bool ok)
{
    bool pending = false;

    if (m_doLoadFinishedActions) {
        updateActions();
        QWebFrame* frame = (page() ? page()->currentFrame() : 0);
        if (ok &&
            frame == page()->mainFrame() &&
            !frame->findFirstElement(QL1S("head>meta[http-equiv=refresh]")).isNull()) {
            if (WebKitSettings::self()->autoPageRefresh()) {
                pending = true;
            } else {
                frame->page()->triggerAction(QWebPage::StopScheduledPageRefresh);
            }
        }
    }

    emit completed ((ok && pending));
}
예제 #10
0
void WebView::Private::showFullScreen()
{
    //normal -> full

    QWebFrame *frame = q->page()->mainFrame();

    //スクロールバー非表示
    QWebElement element = frame->findFirstElement(QStringLiteral("body"));
    if (element.isNull()) {
        qDebug() << "failed find target";
        return;
    }

    QHash<QString, QString> properties;
    properties.insert(QStringLiteral("overflow"), QStringLiteral("hidden"));
    if(body.isEmpty()){
        foreach (const QString &key, properties.keys()) {
            body.insert(key, element.styleProperty(key, QWebElement::InlineStyle));
        }
        qDebug() << element.styleProperty(QStringLiteral("overflow"), QWebElement::InlineStyle);
    }
예제 #11
0
	void UserFiltersModel::blockImage ()
	{
		QAction *blocker = qobject_cast<QAction*> (sender ());
		if (!blocker)
		{
			qWarning () << Q_FUNC_INFO
				<< "sender is not a QAction*"
				<< sender ();
			return;
		}

		QUrl blockUrl = blocker->property ("CleanWeb/URL").value<QUrl> ();
		QWebView *view = qobject_cast<QWebView*> (blocker->
					property ("CleanWeb/View").value<QObject*> ());
		if (InitiateAdd (blockUrl.toString ()) && view)
		{
			QWebFrame *frame = view->page ()->mainFrame ();
			QWebElement elem = frame->findFirstElement ("img[src=\"" + blockUrl.toEncoded () + "\"]");
			if (!elem.isNull ())
				elem.removeFromDocument ();
		}
	}
예제 #12
0
			void ChatTab::AppendMessage (Plugins::IMessage *msg)
			{
				Plugins::ICLEntry *other = qobject_cast<Plugins::ICLEntry*> (msg->OtherPart ());
				if (!other && msg->OtherPart ())
				{
					qWarning () << Q_FUNC_INFO
							<< "message's other part doesn't implement ICLEntry"
							<< msg->GetObject ()
							<< msg->OtherPart ();
					return;
				}

				if (msg->GetDirection () == Plugins::IMessage::DOut &&
						other->GetEntryType () == Plugins::ICLEntry::ETMUC)
					return;

				QWebFrame *frame = Ui_.View_->page ()->mainFrame ();
				bool shouldScrollFurther = (frame->scrollBarMaximum (Qt::Vertical) ==
								frame->scrollBarValue (Qt::Vertical));

				QString body = FormatBody (msg->GetBody (), msg);

				QString string = QString ("%1 ")
						.arg (FormatDate (msg->GetDateTime (), msg));
				string.append (' ');
				switch (msg->GetDirection ())
				{
				case Plugins::IMessage::DIn:
				{
					switch (msg->GetMessageType ())
					{
					case Plugins::IMessage::MTChatMessage:
					case Plugins::IMessage::MTMUCMessage:
					{
						QString entryName = Qt::escape (other->GetEntryName ());
						entryName = FormatNickname (entryName, msg);

						if (body.startsWith ("/me "))
						{
							body = body.mid (3);
							string.append ("*** ");
							string.append (entryName);
							string.append (' ');
						}
						else
						{
							string.append (entryName);
							string.append (": ");
						}
						break;
					}
					case Plugins::IMessage::MTEventMessage:
						string.append ("! ");
						break;
					}
					break;
				}
				case Plugins::IMessage::DOut:
					string.append (FormatNickname ("R", msg));
					string.append (": ");
					break;
				}

				string.append (body);

				QWebElement elem = frame->findFirstElement ("body");
				elem.appendInside (QString ("<div>%1</div").arg (string));

				if (shouldScrollFurther)
					QTimer::singleShot (100,
							this,
							SLOT (scrollToEnd ()));
			}
예제 #13
0
void WebView::Private::showOptionalSize(int width, int height, bool isfull)
{
    //ゲーム画面有るか
    if(!q->gameExists())   return;

    QHash<QString, QString> properties;
    QWebFrame *frame = q->page()->mainFrame();

    ///////////////////////////////////////
    //スクロールバー非表示
    QWebElement element = frame->findFirstElement(QStringLiteral("body"));
    if(!isfull){
        properties.insert(QStringLiteral("overflow"), QStringLiteral(""));
        properties.insert(QStringLiteral("min-width"), QString("%1px").arg(width+188));
    }else{
        //フルスクリーンのみ
        properties.insert(QStringLiteral("overflow"), QStringLiteral("hidden"));
        properties.insert(QStringLiteral("min-width"), QString("%1px").arg(width+188));
    }
    if(!setElementProperty(element, properties, body)){
        qDebug() << "failed find target body";
        return;
    }
    properties.clear();


    /////////////////////////////////////////
    //上のバー消す
    element = frame->findFirstElement(QStringLiteral("#main-ntg"));
    if(!isfull){
        properties.insert(QStringLiteral("position"), QStringLiteral("relative"));
//        properties.insert(QStringLiteral("margin"), QStringLiteral("0 -12px 20px"));
//        properties.insert(QStringLiteral("visibility"), QStringLiteral(""));
        properties.insert(QStringLiteral("top"), QStringLiteral(""));
        properties.insert(QStringLiteral("left"), QStringLiteral(""));
    }else{
        //フルスクリーンのみ
        properties.insert(QStringLiteral("position"), QStringLiteral("absolute"));
//        properties.insert(QStringLiteral("margin"), QStringLiteral("0"));
//        properties.insert(QStringLiteral("visibility"), QStringLiteral("hidden"));
        properties.insert(QStringLiteral("top"), QStringLiteral("0px"));
        properties.insert(QStringLiteral("left"), QStringLiteral("0px"));
    }
    if(!setElementProperty(element, properties, dmmNtgnavi)){
        qDebug() << "failed find target #dmm-ntgnavi";
        return;
    }
    properties.clear();


    /////////////////////////////////////////
    //フレームを最大化
    element = frame->findFirstElement(QStringLiteral("#game_frame"));
    if (element.isNull()) {
        qDebug() << "failed find target #game_frame";
        //            ui.statusBar->showMessage(tr("failed find target"), STATUS_BAR_MSG_TIME);
        return;
    }
    if(!isfull){
        //フルスクリーンじゃない
        properties.insert(QStringLiteral("position"), QStringLiteral(""));
        properties.insert(QStringLiteral("top"), QStringLiteral(""));
        properties.insert(QStringLiteral("left"), QStringLiteral(""));
        properties.insert(QStringLiteral("width"), QString("%1px").arg(width+100));
        properties.insert(QStringLiteral("height"), QString("%1px").arg(height+100));
        properties.insert(QStringLiteral("z-index"), QStringLiteral(""));
    }else{
        properties.insert(QStringLiteral("position"), QStringLiteral("absolute"));
        properties.insert(QStringLiteral("top"), QStringLiteral("0px"));
        properties.insert(QStringLiteral("left"), QStringLiteral("0px"));
        properties.insert(QStringLiteral("width"), QString("%1px").arg(width+100));
        properties.insert(QStringLiteral("height"), QString("%1px").arg(height+100));
        properties.insert(QStringLiteral("z-index"), QStringLiteral("10"));
    }
    if(!setElementProperty(element, properties, gameFrame)){
        qDebug() << "failed find target game_frame tag";
        return;
    }
    properties.clear();


    /////////////////////////////////////////
    //フレームの子供からflashの入ったdivを探して、さらにその中のembedタグを調べる
    frame = searchGameFrame(frame);
    element = frame->findFirstElement(QStringLiteral("#flashWrap"));
    if(!isfull){
        //フルスクリーンじゃない
        properties.insert(QStringLiteral("position"), QStringLiteral(""));
        properties.insert(QStringLiteral("top"), QStringLiteral(""));
        properties.insert(QStringLiteral("left"), QStringLiteral(""));
        properties.insert(QStringLiteral("width"), QString("%1px").arg(width));
        properties.insert(QStringLiteral("height"), QString("%1px").arg(height));
    }else{
        properties.insert(QStringLiteral("position"), QStringLiteral("absolute"));
        properties.insert(QStringLiteral("top"), QStringLiteral("0px"));
        properties.insert(QStringLiteral("left"), QStringLiteral("0px"));
        properties.insert(QStringLiteral("width"), QString("%1px").arg(width));
        properties.insert(QStringLiteral("height"), QString("%1px").arg(height));
    }
    if(!setElementProperty(element, properties, flashWrap)){
        qDebug() << "failed find target flashWrap";
        return;
    }
    properties.clear();

    /////////////////////////////////////////
    //embedタグを探す
    element = element.findFirst(QStringLiteral("embed"));
    if (element.isNull()) {
        qDebug() << "failed find target embed";
        return;
    }
    properties.insert(QStringLiteral("width"), QString::number(width));
    properties.insert(QStringLiteral("height"), QString::number(height));
    if(embed.isEmpty()){
        foreach (const QString &key, properties.keys()) {
            embed.insert(key, element.attribute(key));
        }
        qDebug() << element.attribute(QStringLiteral("width"))
                 << "," << element.attribute(QStringLiteral("height"))
                 << "->" << width << "," << height;
    }
예제 #14
0
void CadastreWrapper::networkFinished(QNetworkReply *reply)
{
    if (m_pendingTiles.contains(reply)) {
        QFile target(m_pendingTiles[reply]);
        QByteArray ba = reply->readAll();

        // white -> transparent
        QImage img;
        img.loadFromData(ba);
        QImage img2 = img.convertToFormat(QImage::Format_ARGB32);
        Q_ASSERT(img2.hasAlphaChannel());
        int w=0;
        for (int y=0; y<img2.height(); ++y) {
            for (int x=0; x<img2.width(); ++x) {
                QColor col = QColor(img2.pixel(x, y));
                if (col == QColor(255, 255, 255)) {
                    col.setAlpha(0);
                    img2.setPixel(x, y, col.rgba());
                    ++w;
               }
            }
        }
        //Full transparent
        if (w == img2.height()*img2.width()) {
            img2 = QImage(1, 1, QImage::Format_ARGB32);
            img2.setPixel(0, 0, QColor(0, 0, 0, 0).rgba());
        }

        target.open(QIODevice::WriteOnly);
//        target.write(reply->readAll());
        img2.save(&target, "PNG");
        target.close();
        m_pendingTiles.remove(reply);
        if (m_progress) {
            m_progress->setValue(m_progress->value()+1);
            if (m_progress->value() > 10) {
                double ms = m_startTime.secsTo(QDateTime::currentDateTime());
                double us = ms/m_progress->value();
                int tot = us*(m_progress->maximum() - m_progress->value());

                if (tot<3600)
                    m_progress->setLabelText(tr("Downloaded: %1/%2\nRemaining time: %3:%4").arg(m_progress->value()).arg(m_progress->maximum()).arg(int(tot/60)).arg(int(tot%60), 2, 10, QChar('0')));
                else
                    m_progress->setLabelText(tr("Downloaded: %1/%2\nRemaining time: %3:%4:%5").arg(m_progress->value()).arg(m_progress->maximum()).arg(int(tot/3600)).arg(int((tot%3600)/60), 2, 10, QChar('0')).arg(int(tot%60), 2, 10, QChar('0')));

            } else
                m_progress->setLabelText(tr("Downloaded: %1/%2").arg(m_progress->value()).arg(m_progress->maximum()));
        }
    } else if (reply->url() == QUrl("http://www.cadastre.gouv.fr/scpc/accueil.do")) {
        qDebug() << "Ok, I've got a cookie... I LOVE COOKIES.";
        reply->readAll();
        m_gotCookie = true;
    } else if (reply->url() == QUrl("http://www.cadastre.gouv.fr/scpc/rechercherPlan.do")) {
        QString pageData = reply->readAll();
        qDebug() << pageData;
        QWebPage parsedPage(this);
        QWebFrame *frame = parsedPage.mainFrame();
        frame->setHtml(pageData);
        QWebElement codeCommune = frame->findFirstElement("#codeCommune");
        QMap<QString, QString> results;
        if (!codeCommune.isNull()) {
            // If there is a codeCommune object in the DOM, it means that the search was not successfull.
            if (codeCommune.tagName().toLower() != "select") {
                qDebug() << "Invalid page ???";
                return;
            }
            QWebElementCollection options = codeCommune.findAll("option");
            foreach (QWebElement option, options) {
                if (!option.attribute("value").isEmpty())
                    results[option.attribute("value")] = option.toPlainText();
            }
        } else {