void lmcMessageLog::removeMessageLog(QString divClass) { QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); QWebElement element = body.findFirst("div." + divClass); element.removeFromDocument(); }
void MainWindow::finished_loading(bool ok) { if(!ok) std::cout << "LOAD FINISH NOT OK!\n\n"; QString output; QWebElement body; progress = 100; adjust_title(); QWebFrame *frame = uimw->webView->page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement element = document.firstChild(); while(!element.isNull()) { if(element.tagName() == "BODY") { output = element.toInnerXml(); if(output == "ok\n") { QNetworkCookieJar *cj = uimw->webView->page()->networkAccessManager()->cookieJar(); QList<QNetworkCookie> cookies = cj->cookiesForUrl(testauth); for(QList<QNetworkCookie>::const_iterator i = cookies.begin() ; i != cookies.end() ; i++ ) { std::cout << "Set-Cookie: "; QByteArray ba = i->toRawForm(); std::cout.write(ba.data(), ba.count()); std::cout << "\r\n"; } exit(0); } } element = element.nextSibling(); } this->show(); }
void MainWindow::_loadFinished(bool ok) { if (ok) { QString indexUrl = _appSettings.host(); indexUrl += "index.php"; QString pageUrl = ui->webView->url().toString(); QWebPage* page = ui->webView->page(); QWebFrame* frame = page->currentFrame(); QWebElement root = frame->documentElement(); if (!root.findFirst("#loginForm").isNull()) { QWebElementCollection allInputs = root.findAll("input"); foreach (QWebElement inputElement, allInputs) { if (inputElement.hasAttribute("name")) { QString name = inputElement.attribute("name"); if (name == "username") { inputElement.setAttribute("value", _appSettings.user()); } else if (name == "password") { inputElement.setAttribute("value", _appSettings.password()); } } } root.findFirst("input[type=submit]").evaluateJavaScript("this.click()"); } else if (pageUrl == indexUrl)
QWebElement QWebFrameProto::documentElement() const { scriptDeprecated("QWebFrame will not be available in future versions"); QWebFrame *item = qscriptvalue_cast<QWebFrame*>(thisObject()); if (item) return item->documentElement(); return QWebElement(); }
//! [begin document inspection] void Window::on_webView_loadFinished() { treeWidget->clear(); QWebFrame *frame = webView->page()->mainFrame(); QWebElement document = frame->documentElement(); examineChildElements(document, treeWidget->invisibleRootItem()); }
// --- DIAGNOSE LOAD --- // Verify that the page loaded successfully, else present error message. // If successful, set other data parts and handle filters. void MainWindow::diagnoseLoad(bool ok) { setReloadButton(); if (!ok) { //QMessageBox::critical(this, tr("Error"), tr("Failed to load the URL")); // FIXME: triggers crash with favicon path customized due to QtWebkit bug! // Don't return to the event loop. } else { //QWidget* tab = tabWidget->currentWidget tabWidget->setTabText(tabWidget->currentIndex(), wv->title()); tabWidget->setTabIcon(tabWidget->currentIndex(), wv->icon()); addressBar->setText(wv->url().toString()); QString title = wv->title(); if (title.size() > 200) { title.resize(200); } setWindowTitle(title + " - WildFox"); // check the page URL against the filters if (extFilters.size() < 1) { return; } QWebPage* page = (QWebPage*) sender(); if (page == 0) { return; } QWebFrame* frame = page->mainFrame(); if (frame == 0) { return; } QString url = frame->url().path(); QStringList urlbit = url.split("://"); QDir extension; extension.setPath(manifest.fileName()); if (urlbit.size() > 1) { QString scheme = urlbit[0]; QStringList bits = urlbit[1].split("."); for (int i = 0; i < extFilters.size(); ++i) { if (extFilters[i].scheme != scheme) { continue; } for (int j = 0; extFilters[i].segments.size(); ++j) { if (extFilters[i].segments[j] != bits[j] && extFilters[i].segments[j] != "*") { continue; } } // matched filter, inject associated scripts into the content. QWebElement root = frame->documentElement(); QWebElement head = root.findFirst("head"); head.appendOutside("<script type=\"text/javascript\" src=\"" + extension.absolutePath() + "\" />"); } } } }
void lmcMessageLog::appendPublicMessage(QString* lpszUserId, QString* lpszUserName, QString* lpszMessage, QDateTime *pTime, QFont *pFont, QColor *pColor) { QString html = QString::null; bool localUser = (lpszUserId->compare(localId) == 0); decodeMessage(lpszMessage); QString fontStyle = getFontStyle(pFont, pColor, localUser); if(lpszUserId->compare(lastId) != 0) { outStyle = !outStyle; html = outStyle ? themeData.outMsg : themeData.inMsg; // get the avatar image for this user from the cache folder QString filePath = participantAvatars.value(*lpszUserId); // if image not found, use the default avatar image for this user QString iconPath = QFile::exists(filePath) ? QUrl::fromLocalFile(filePath).toString() : "qrc"AVT_DEFAULT; html.replace("%iconpath%", iconPath); html.replace("%sender%", *lpszUserName); html.replace("%time%", getTimeString(pTime)); html.replace("%style%", fontStyle); html.replace("%message%", *lpszMessage); QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(html); } else { html = outStyle ? themeData.outNextMsg : themeData.inNextMsg; html.replace("%time%", getTimeString(pTime)); html.replace("%style%", fontStyle); html.replace("%message%", *lpszMessage); QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); QWebElement last = body.lastChild(); QWebElement insert = last.findFirst("div#insert"); insert.replace(html); } hasData = true; }
void FakePluginWidget::load (bool loadAll) { QWebView *view = webViewFrom(parentWidget()); if (!view) return; // WORKAROUND: For some reason, when we load on demand plugins the scroll // position gets utterly screwed up and reset to the beginning of the // document. This is an effort to workaround that issue. connect(view->page(), SIGNAL(scrollRequested(int,int,QRect)), this, SLOT(updateScrollPoisition(int,int,QRect)), Qt::QueuedConnection); hide(); m_swapping = true; QList<QWebFrame*> frames; frames.append(view->page()->mainFrame()); QString selector (QLatin1String("applet:not([type]),embed:not([type]),object:not([type]),applet[type=\"")); selector += m_mimeType; selector += QLatin1String("\"],embed[type=\""); selector += m_mimeType; selector += QLatin1String("\"],object[type=\""); selector += m_mimeType; selector += QLatin1String("\"]"); while (!frames.isEmpty()) { bool loaded = false; QWebFrame *frame = frames.takeFirst(); QWebElement docElement = frame->documentElement(); QWebElementCollection elements = docElement.findAll(selector); Q_FOREACH (QWebElement element, elements) { if (loadAll || element.evaluateJavaScript(QLatin1String("this.swapping")).toBool()) { QWebElement substitute = element.clone(); emit pluginLoaded(m_id); m_updateScrollPosition = true; element.replace(substitute); deleteLater(); if (!loadAll) { loaded = true; break; // Found the one plugin we wanted to start so exit loop. } } } if (loaded && !loadAll) { break; // Loading only one item, exit the outer loop as well... } frames += frame->childFrames(); } m_swapping = false; }
//! [return pressed] void Window::on_elementLineEdit_returnPressed() { QWebFrame *frame = webView->page()->mainFrame(); //! [select elements] QWebElement document = frame->documentElement(); QWebElementCollection elements = document.findAll(elementLineEdit->text()); //! [select elements] foreach (QWebElement element, elements) element.setAttribute("style", "background-color: #f0f090"); }
void ClickToFlash::findElement() { if (!loadButton_) return; QPoint objectPos = page_->view()->mapFromGlobal(loadButton_->mapToGlobal(loadButton_->pos())); QWebFrame* objectFrame = 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)) { 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); frames.append(page_->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; } element_ = element; return; } frames += frame->childFrames(); } }
void CWebNewsLoader::on_webPageLoadFinished(bool res) { if (res) { QWebFrame *frame = m_webView->page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElementCollection elements = document.findAll("li a"); QStringList newsList; foreach (QWebElement element, elements) newsList.append(element.toPlainText()); emit newsListLoadFinished(m_webView->url().toString(), newsList); } delete m_webView; }
void downloader::render(QString rawHtml) { currencyLoaded.clear(); rateLoaded.clear(); QWebFrame *mainFrame = webPage.mainFrame(); mainFrame->setHtml(rawHtml); QWebElement documentElement = mainFrame->documentElement(); QWebElementCollection elements = documentElement.findAll("#content > div:nth-child(1) > div > div.col2.pull-right.module.bottomMargin > div.moduleContent > table:nth-child(4) > tbody > tr"); int i = 0; foreach (QWebElement element, elements) { currency.push_back(element.findFirst("td:nth-child(1)").toInnerXml()); rate.push_back(element.findFirst("td:nth-child(3) > a").toInnerXml()); // qDebug()<< currency[i+(elements.count()*downloadCount)]+"\t\t"+rate[i+(elements.count()*downloadCount)]+"\n"; currencyLoaded.push_back(currency[i+(elements.count()*downloadCount)]); rateLoaded.push_back(rate[i+(elements.count()*downloadCount)]); i++; }
void PhpWebView::showXPath() { QWebFrame *frame = page()->frameAt(rightClick); if (frame) { XPathInspector *dlg = new XPathInspector(this, this); if (selectedElements.count() == 0) { QPoint point = frame->scrollPosition(); point += rightClick; QWebElement elem = getElementByCoord(frame->documentElement(), point); dlg->setActiveElement(elem); } else { dlg->setFewActiveElements(selectedElements); } dlg->show(); } }
void WebPage::saveScreenshot(const QString& fileName, const QSize& vpSize) { QSize originalVpSize = viewportSize(); QWebFrame* frame = mainFrame(); if (!vpSize.isNull()) { setViewportSize(vpSize); } QImage image(frame->contentsSize(), QImage::Format_ARGB32_Premultiplied); image.fill(Qt::transparent); QPainter painter(&image); painter.setRenderHint(QPainter::Antialiasing, true); painter.setRenderHint(QPainter::TextAntialiasing, true); painter.setRenderHint(QPainter::SmoothPixmapTransform, true); frame->documentElement().render(&painter); painter.end(); image.save(fileName); setViewportSize(originalVpSize); }
void lmcMessageLog::updateFileMessage(FileMode mode, FileOp op, QString fileId) { QString szMessage = getFileStatusMessage(mode, op); QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); QString selector = "span#"; QString tempId = (mode == FM_Send) ? "send" : "receive"; tempId.append(fileId); selector.append(tempId); QWebElement span = body.findFirst(selector); span.setPlainText(szMessage); // update the entry in message log for(int index = 0; index < messageLog.count(); index++) { SingleMessage msg = messageLog.at(index); if(tempId.compare(msg.id) == 0) { XmlMessage xmlMessage = msg.message; xmlMessage.removeData(XN_FILEOP); xmlMessage.addData(XN_FILEOP, FileOpNames[op]); msg.message = xmlMessage; break; } } }
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(); } }
// This function is called to display a file request message on chat box void lmcMessageLog::appendFileMessage(MessageType type, QString* lpszUserName, XmlMessage* pMessage, bool bReload) { QString htmlMsg; QString caption; QString fileId = pMessage->data(XN_FILEID); QString tempId; QString szStatus; htmlMsg = themeData.reqMsg; htmlMsg.replace("%iconpath%", "qrc"IDR_FILEMSG); FileOp fileOp = (FileOp) Helper::indexOf(FileOpNames, FO_Max, pMessage->data(XN_FILEOP)); if(type == MT_LocalFile) { tempId = "send" + fileId; caption = tr("Sending '%1' to %2."); htmlMsg.replace("%sender%", caption.arg(pMessage->data(XN_FILENAME), *lpszUserName)); htmlMsg.replace("%message%", ""); htmlMsg.replace("%fileid%", tempId); switch(fileOp) { case FO_Request: sendFileMap.insert(fileId, *pMessage); pMessage->addData(XN_TEMPID, tempId); htmlMsg.replace("%links%", "<a href='lmc://filecancel/" + fileId + "'>" + tr("Cancel") + "</a>"); break; case FO_Cancel: case FO_Accept: case FO_Decline: szStatus = getFileStatusMessage(FM_Send, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } else if(type == MT_File) { tempId = "receive" + fileId; if(autoFile) { caption = tr("%1 is sending you a file:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XN_FILENAME) + " (" + Helper::formatSize(pMessage->data(XN_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", ""); } else { caption = tr("%1 sends you a file:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XN_FILENAME) + " (" + Helper::formatSize(pMessage->data(XN_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", tempId); } switch(fileOp) { case FO_Request: receiveFileMap.insert(fileId, *pMessage); pMessage->addData(XN_TEMPID, tempId); if(autoFile) { htmlMsg.replace("%links%", tr("File has been accepted automatically.")); } else { htmlMsg.replace("%links%", "<a href='lmc://fileaccept/" + fileId + "'>" + tr("Accept") + "</a> " + "<a href='lmc://filedecline/" + fileId + "'>" + tr("Decline") + "</a>"); } if(autoFile && !bReload) fileOperation(fileId, "fileaccept"); break; case FO_Cancel: case FO_Accept: case FO_Decline: szStatus = getFileStatusMessage(FM_Receive, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(htmlMsg); }
// This function is called to display a file request message on chat box void wavrMessageLog::appendFileMessage(MessageType type, QString* lpszUserName, wavrXmlMessage* pMessage, bool bReload) { Q_UNUSED(type); QString htmlMsg; QString caption; QString fileId = pMessage->data(XML_FILEID); QString tempId; QString szStatus; QString fileType; switch(type) { case MT_File: fileType = "file"; break; case MT_Folder: fileType = "folder"; break; default: return; break; } htmlMsg = themeData.reqMsg; htmlMsg.replace("%iconpath%", "qrc"IDR_FILEMSG); FileOp fileOp = (FileOp)wavrHelper::indexOf(FileOpNames, FO_Max, pMessage->data(XML_FILEOP)); FileMode fileMode = (FileMode)wavrHelper::indexOf(FileModeNames, FM_Max, pMessage->data(XML_MODE)); if(fileMode == FM_Send) { qDebug() << "inside fmsend message"; tempId = "send" + fileId; caption = tr("Sending '%1' to %2."); htmlMsg.replace("%sender%", caption.arg(pMessage->data(XML_FILENAME), *lpszUserName)); htmlMsg.replace("%message%", ""); htmlMsg.replace("%fileid%", tempId); switch(fileOp) { case FO_Request: sendFileMap.insert(fileId, *pMessage); pMessage->addData(XML_TEMPID, tempId); htmlMsg.replace("%links%", "<a href='wavr://" + fileType + "/" + cancelOp + "/" + fileId + "'>" + tr("Cancel") + "</a>"); break; case FO_Cancel: case FO_Accept: case FO_Decline: case FO_Error: case FO_Abort: case FO_Complete: szStatus = getFileStatusMessage(FM_Send, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } else { tempId = "receive" + fileId; if(autoFile) { if(type == MT_File) caption = tr("%1 is sending you a file:"); else caption = tr("%1 is sending you a folder:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XML_FILENAME) + " (" + wavrHelper::formatSize(pMessage->data(XML_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", ""); } else { if(type == MT_File) caption = tr("%1 sends you a file:"); else caption = tr("%1 sends you a folder:"); htmlMsg.replace("%sender%", caption.arg(*lpszUserName)); htmlMsg.replace("%message%", pMessage->data(XML_FILENAME) + " (" + wavrHelper::formatSize(pMessage->data(XML_FILESIZE).toLongLong()) + ")"); htmlMsg.replace("%fileid%", tempId); } switch(fileOp) { case FO_Request: receiveFileMap.insert(fileId, *pMessage); pMessage->addData(XML_TEMPID, tempId); if(autoFile) { htmlMsg.replace("%links%", tr("Accepted")); if(!bReload) fileOperation(fileId, acceptOp, fileType); } else { htmlMsg.replace("%links%", "<a href='wavr://" + fileType + "/" + acceptOp + "/" + fileId + "'>" + tr("Accept") + "</a> " + "<a href='wavr://" + fileType + "/" + declineOp + "/" + fileId + "'>" + tr("Decline") + "</a>"); } break; case FO_Cancel: case FO_Accept: case FO_Decline: case FO_Error: case FO_Abort: case FO_Complete: szStatus = getFileStatusMessage(FM_Receive, fileOp); htmlMsg.replace("%links%", szStatus); break; default: return; break; } } QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(htmlMsg); }
void lmcMessageLog::appendMessageLog(QString *lpszHtml) { QWebFrame* frame = page()->mainFrame(); QWebElement document = frame->documentElement(); QWebElement body = document.findFirst("body"); body.appendInside(*lpszHtml); }