bool HistoryChatView::onContextMenu(ChatView *view, QMenu *menu, const QWebHitTestResult &result) { ChatId id(view->id()); if (id.type() != ChatId::ChannelId && id.type() != ChatId::UserId) return false; const QWebElement block = result.enclosingBlockElement(); if (!block.hasClass("blocks") || block.hasClass("removed")) return false; const QWebElement container = block.parent(); const qint64 mdate = container.attribute(LS("data-mdate")).toLongLong(); if (!mdate) return false; id.init(container.attribute(LS("id")).toLatin1()); id.setDate(mdate); if (id.type() != ChatId::MessageId) return false; const int permissions = this->permissions(HistoryDB::get(id)); if (permissions == NoPermissions) return false; if (permissions & Remove) { QVariantList data; data << view->id() << (id.hasOid() ? ChatId::toBase32(id.oid().byteArray()) : id.toString()); menu->insertAction(menu->actions().first(), removeAction(data)); } return true; }
RSSWidget::RSSWidget(WebView* view, QWidget* parent) : LocationBarPopup(parent) , ui(new Ui::RSSWidget) , m_view(view) { ui->setupUi(this); QWebEngineFrame* frame = m_view->page()->mainFrame(); QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]"); // Make sure RSS feeds fit into a window, in case there is a lot of feeds from one page // See #906 int cols = links.count() / 10 == 0 ? 1 : links.count() / 10; int row = 0; for (int i = 0; i < links.count(); i++) { QWebElement element = links.at(i); QString title = element.attribute("title"); const QUrl url = QUrl::fromEncoded(element.attribute("href").toUtf8()); if (url.isEmpty()) { continue; } if (title.isEmpty()) { title = tr("Untitled feed"); } QPushButton* button = new QPushButton(this); button->setIcon(QIcon(":icons/other/feed.png")); button->setStyleSheet("text-align:left"); button->setText(title); button->setProperty("rss-url", url); button->setProperty("rss-title", title); if (!isRssFeedAlreadyStored(url)) { button->setFlat(true); button->setToolTip(url.toString()); } else { button->setFlat(false); button->setEnabled(false); button->setToolTip(tr("You already have this feed.")); } int pos = i % cols > 0 ? (i % cols) * 2 : 0; ui->gridLayout->addWidget(button, row, pos); connect(button, SIGNAL(clicked()), this, SLOT(addRss())); if (i % cols == cols - 1) { row++; } } }
QDateTime HtmlBookmarksImporter::getDateTime(const QWebElement &element, const QString &attribute) { #if QT_VERSION < 0x050800 const uint seconds(element.attribute(attribute).toUInt()); return ((seconds > 0) ? QDateTime::fromTime_t(seconds) : QDateTime()); #else const qint64 seconds(element.attribute(attribute).toLongLong()); return ((seconds != 0) ? QDateTime::fromSecsSinceEpoch(seconds) : QDateTime()); #endif }
RSSDetectionWidget::RSSDetectionWidget(WebView* view, QWidget* parent) : QFrame(parent, Qt::Popup) , view_(view) { setAttribute(Qt::WA_DeleteOnClose); setFrameStyle(QFrame::StyledPanel | QFrame::Plain); setLineWidth(1); setMidLineWidth(2); gridLayout_ = new QGridLayout(this); gridLayout_->setMargin(5); gridLayout_->setSpacing(5); QWebFrame* frame = view_->page()->mainFrame(); QWebElementCollection links = frame->findAllElements("link[type=\"application/rss+xml\"]"); int cols = links.count() / 10 == 0 ? 1 : links.count() / 10; int row = 0; for (int i = 0; i < links.count(); i++) { QWebElement element = links.at(i); QString title = element.attribute("title"); const QUrl url = QUrl::fromEncoded(element.attribute("href").toUtf8()); if (url.isEmpty()) { continue; } if (title.isEmpty()) { title = tr("Untitled feed"); } QPushButton* button = new QPushButton(this); button->setStyleSheet("QPushButton {text-align:left; border: none; padding: 0px;}" "QPushButton:hover {color: #1155CC;}"); button->setCursor(Qt::PointingHandCursor); button->setText(title); button->setToolTip(url.toString()); button->setProperty("rss-url", url); button->setProperty("rss-title", title); int pos = i % cols > 0 ? (i % cols) * 2 : 0; gridLayout_->addWidget(button, row, pos); connect(button, SIGNAL(clicked()), this, SLOT(addRss())); if (i % cols == cols - 1) { row++; } } }
static bool showSpellCheckAction(const QWebElement& element) { if (element.hasAttribute(QL1S("readonly"))) return false; if (element.attribute(QL1S("spellcheck"), QL1S("true")).compare(QL1S("false"), Qt::CaseInsensitive) == 0) return false; if (element.hasAttribute(QL1S("type")) && element.attribute(QL1S("type")).compare(QL1S("text"), Qt::CaseInsensitive) != 0) return false; return true; }
bool ClickToFlash::checkUrlOnElement(QWebElement el) { QString checkString = el.attribute("src"); if (checkString.isEmpty()) { checkString = el.attribute("data"); } if (checkString.isEmpty()) { checkString = el.attribute("value"); } checkString = page_->mainFrame()->url().resolved(QUrl(checkString)).toString(QUrl::RemoveQuery); return url_.toEncoded().contains(checkString.toUtf8()); }
void WebView::addSearchEngine() { QAction *action = qobject_cast<QAction*>(sender()); if (!action) return; QVariant variant = action->data(); if (!variant.canConvert<QWebElement>()) return; QWebElement element = qvariant_cast<QWebElement>(variant); QString elementName = element.attribute(QLatin1String("name")); QWebElement formElement = element; while (formElement.tagName().toLower() != QLatin1String("form")) formElement = formElement.parent(); if (formElement.isNull() || formElement.attribute(QLatin1String("action")).isEmpty()) return; QString method = formElement.attribute(QLatin1String("method"), QLatin1String("get")).toLower(); if (method != QLatin1String("get")) { QMessageBox::warning(this, tr("Method not supported"), tr("%1 method is not supported.").arg(method.toUpper())); return; } QUrl searchUrl(page()->mainFrame()->baseUrl().resolved(QUrl(formElement.attribute(QLatin1String("action"))))); QMap<QString, QString> searchEngines; QWebElementCollection inputFields = formElement.findAll(QLatin1String("input")); foreach (QWebElement inputField, inputFields) { QString type = inputField.attribute(QLatin1String("type"), QLatin1String("text")); QString name = inputField.attribute(QLatin1String("name")); QString value = inputField.evaluateJavaScript(QLatin1String("this.value")).toString(); if (type == QLatin1String("submit")) { searchEngines.insert(value, name); } else if (type == QLatin1String("text")) { if (inputField == element) value = QLatin1String("{searchTerms}"); searchUrl.addQueryItem(name, value); } else if (type == QLatin1String("checkbox") || type == QLatin1String("radio")) { if (inputField.evaluateJavaScript(QLatin1String("this.checked")).toBool()) { searchUrl.addQueryItem(name, value); } } else if (type == QLatin1String("hidden")) { searchUrl.addQueryItem(name, value); } }
//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; }
void dilbert::scrap(bool ok) { if (ok) { ui->progressBar->hide(); QWebElementCollection imgs = view->page()->mainFrame()->findAllElements("img"); QWebElement img; if (comicid == latest || comicid == QDate(1989, 04, 16)) img = imgs.at(1); else img = imgs.at(2); QString imgLink = QString("http://dilbert.com").append(img.attribute("src").toAscii().constData()); ui->webView->setUrl(QUrl(imgLink)); if (comicid == QDate(1989, 04, 16)) { ui->prev->setEnabled(false); } else { ui->prev->setEnabled(true); } if (comicid == latest) { ui->next->setEnabled(false); } else { ui->next->setEnabled(true); } } }
void KinotifyWidget::mousePressEvent (QMouseEvent *event) { const QWebHitTestResult& r = page ()->mainFrame ()->hitTestContent (event->pos ()); if (!r.linkUrl ().isEmpty ()) { QWebView::mousePressEvent (event); return; } QWebElement elem = r.element (); if (elem.isNull () || elem.attribute ("type") != "button") { disconnect (CheckTimer_, SIGNAL (timeout ()), this, SIGNAL (checkNotificationQueue ())); disconnect (&Machine_, SIGNAL (finished ()), this, SLOT (closeNotification ())); emit checkNotificationQueue (); closeNotification (); } else QWebView::mousePressEvent (event); }
foreach (QWebElement link, links) { QString js = link.attribute("onclick"); int pos = linkRE.indexIn(js); if (pos > -1) { results[linkRE.cap(1)] = name; } }
QList<CachedHandler> ChromeDOM::getCachedHandlers(const QString &elementId, const QRectF & ownerArea) { QWebElement snippet = getElementById(elementId); QList <QWebElement> controls = snippet.findAll(".GinebraCached").toList(); QList <CachedHandler> handlers; for (int i = 0; i < controls.size(); i++){ QWebElement elem = controls.at(i); //Element rectangle relative to snippet, so we can handle mouse events relative to snippet //qDebug() << "====> Owner X: " << ownerArea.x() << " Owner Width: " << ownerArea.width() << " Elem X: " << elem.geometry().x() << " Elem Width: " << elem.geometry().width(); QRectF elemRect(elem.geometry().x() - ownerArea.x(), elem.geometry().y() - ownerArea.y(), elem.geometry().width(), elem.geometry().height()); //NB: For now we handle only onclick from cache. Should add at least long-press too. CachedHandler handler(elem.attribute("id"), elem.attribute("data-GinebraOnClick"), elemRect, m_chrome, elem.attribute("data-GinebraTargetView")); //qDebug() << "Cached handler" << handler.elementId() << ": " << handler.script() << ": " << handler.rect(); handlers.append(handler); } return handlers; }
void EnmlFormatter::fixObjectNode(QWebElement &e) { QString type = e.attribute("type", ""); if (type == "application/pdf") { qint32 lid = e.attribute("lid", "0").toInt(); e.removeAttribute("width"); e.removeAttribute("height"); e.removeAttribute("lid"); e.removeAttribute("border"); if (lid>0) { resources.append(lid); e.setOuterXml(e.toOuterXml().replace("<object", "<en-media").replace("</object", "</en-media")); } removeInvalidAttributes(e); } else { e.removeFromDocument(); } }
QWebElement ChromeDOM::findChromeParent(QWebElement element) { while(!(element = element.parent()).isNull()){ if (element.attribute("class") == "GinebraSnippet"){ return element; } } return element; }
bool ClickToFlash::checkElement(QWebElement el) { if (argumentNames_ == el.attributeNames()) { foreach (const QString &name, argumentNames_) { if (argumentValues_.indexOf(el.attribute(name)) == -1) { return false; } } return true; }
foreach (const QWebElement &selectField, selectFields) { QString name = selectField.attribute(QLatin1String("name")); int selectedIndex = selectField.scriptableProperty(QLatin1String("selectedIndex")).toInt(); if (selectedIndex == -1) continue; QList<QWebElement> options = selectField.findAll(QLatin1String("option")); QString value = options.at(selectedIndex).toPlainText(); searchUrl.addQueryItem(name, value); }
foreach (QWebElement selectField, selectFields) { QString name = selectField.attribute(QLatin1String("name")); int selectedIndex = selectField.evaluateJavaScript(QLatin1String("this.selectedIndex")).toInt(); if (selectedIndex == -1) continue; QWebElementCollection options = selectField.findAll(QLatin1String("option")); QString value = options.at(selectedIndex).toPlainText(); searchUrl.addQueryItem(name, value); }
static void parseDetailsUrl(const QWebElement &element, StationScheduleItem &item) { if (!element.isNull()) { QWebElement link = element.findFirst("a"); QString url = link.attribute("href"); item.setDetailsUrl(url); } else { qDebug() << "link not found"; } }
void Browser::loadFinished(bool ok) { QUrl current_url(page->currentFrame()->baseUrl()); // events trottling if (current_url == this->last_url) { qDebug() << this << QString("%1, loadFinished trottled.").arg(QDateTime::currentDateTime().toTime_t()); return; } this->last_url = current_url; qDebug() << this << QString("%1, '%2', %3 ms.").arg(QDateTime::currentDateTime().toTime_t()).arg(current_url.toString()).arg(page_load_time.elapsed()); if (!ok) { emit(errorHappened(page_load_time.elapsed(), page->currentFrame()->baseUrl())); restartTest(QString("its not ok, something wrong happened! (possibly 500) URL: %1").arg(page->currentFrame()->baseUrl().toString())); return; } QWebElement document= page->currentFrame()->documentElement(); if (page->currentFrame()->baseUrl().host() != base_url.host()) { restartTest("We've got outside the test site. Restarting."); return; } QWebElementCollection collection = document.findAll("a[href]"); QWebElement link; QString link_href; if (collection.count() == 0) { restartTest("No links found on page. Restarting."); return; } // Ignoring javascript and empty links do { link = collection.at(qrand()%collection.count()); link_href = link.attribute("href"); } while ((link_href.count() == 0) || (link_href.at(0) == '#') || (link_href.contains("javascript:;"))); emit(pageLoaded(page_load_time.elapsed(), page->currentFrame()->baseUrl())); link.evaluateJavaScript("var evObj = document.createEvent('MouseEvents');evObj.initEvent( 'click', true, true );this.dispatchEvent(evObj);"); page_load_time.start(); timeout_countdown->start(); }
void EnmlFormatter::fixLinkNode(QWebElement e) { QString enTag = e.attribute("en-tag", ""); if (enTag.toLower() == "en-media") { resources.append(e.attribute("lid").toInt()); e.removeAttribute("style"); e.removeAttribute("href"); e.removeAttribute("title"); removeInvalidAttributes(e); e.removeAllChildren(); QString newXml = e.toOuterXml(); newXml.replace("<a", "<en-media"); newXml.replace("</a>", "</en-media>"); e.setOuterXml(newXml); } QString latex = e.attribute("href", ""); if (latex.toLower().startsWith("latex://")) { removeInvalidAttributes(e); e.removeAttribute("title"); e.removeAttribute("href"); e.setOuterXml(e.toInnerXml()); } removeInvalidAttributes(e); }
ChromeSnippet *ChromeDOM::getSnippet(const QString &docElementId, QGraphicsItem* parent) { Q_UNUSED(parent) ChromeSnippet * snippet = 0; QWebElement doc = m_page->mainFrame()->documentElement(); QWebElement element = doc.findFirst("#" + docElementId); QRect rect = element.geometry(); //TODO: This may not be accurate since final heights may not have been computed at this point!! m_height += rect.height(); // qDebug() << "Snippet: ID: " << docElementId << " Owner Area: " << rect << " Element Rect: " << element.geometry(); if (!rect.isNull()) { QString className = element.attribute("data-GinebraNativeClass", "__NO_CLASS__"); if (className == "__NO_CLASS__") { if (element.attribute("data-GinebraContainer", "false") == "true") { snippet = new WebChromeContainerSnippet(docElementId, m_chrome, element); snippet->setChromeWidget(new ChromeItem(snippet)); } else { snippet = new WebChromeSnippet(docElementId, m_chrome, element); m_renderer->addRenderItem((static_cast<WebChromeSnippet*> (snippet))->item()); } } else { snippet = nativeSnippetForClassName(className, docElementId, element); //TODO: Is the following still needed? QGraphicsWidget * widget = snippet->widget(); //Have snippet determine its own size when in anchor layout. Again, these will not //necessarily be accurate at this point. widget->resize(rect.width(), rect.height()); widget->setPreferredSize(rect.width(), rect.height()); widget->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); //Have snippet determine its own location when NOT in anchor layout widget->setPos(rect.x(), rect.y()); } QWebElement parentElem; if (!(parentElem = findChromeParent(element)).isNull()) { snippet->setParentId(parentElem.attribute("id")); } //Set auto-layout attributes snippet->setAnchor(element.attribute("data-GinebraAnchor", "AnchorNone"), false); snippet->setAnchorOffset(element.attribute("data-GinebraAnchorOffset", "0").toInt()); snippet->setInitiallyVisible(element.attribute("data-GinebraVisible", "false") == "true"); snippet->setHidesContent(element.attribute("data-GinebraHidesContent", "false") == "true"); } return snippet; }
// Modify the en-to tag into an input field void NoteFormatter::modifyTodoTags(QWebElement &todo) { todo.setAttribute("type", "checkbox"); // Checks the en-to tag wheter or not the todo-item is checked or not // and sets up the HTML to keep storing the information in value QString checked = todo.attribute("checked"); if (checked.toLower() == "true") todo.setAttribute("checked", "checked"); else todo.removeAttribute("checked"); todo.setAttribute("onClick", "if(!checked) removeAttribute('checked'); else setAttribute('checked', 'checked'); editorWindow.editAlert();"); todo.setAttribute("style", "cursor: hand;"); todo.setOuterXml(todo.toOuterXml().replace("en-todo","input")); }
QWebElement MyWebView::FindCloserWidget(QWebElement &elem) { QString strTemp = elem.attribute("id"); WDomElem * welem = m_pMainWindow->m_treemodel.getElemByName(strTemp); // check if valid parent if (welem) { return elem; } else { QWebElement welemTemp = elem.parent(); return FindCloserWidget(welemTemp); } }
/** * @fn gitreportLoaded */ void GitreportModule::gitreportLoaded(const bool state) { if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]"; if (debug) qDebug() << "[GitreportModule]" << "[gitreportLoaded]" << ":" << "State" << state; if (state) { webView->setHidden(!debug); // captcha QWebElement document = webView->page()->mainFrame()->documentElement(); QWebElement captchaImg = document.findFirst(QString("input#captcha_key")); QString captchaUrl = QString(dynamic[QString("CAPTCHA_URL")]) + captchaImg.attribute(QString("value")); QNetworkRequest request(captchaUrl); manager.get(request); disconnect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(setCaptcha(QNetworkReply *))); connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(setCaptcha(QNetworkReply *))); } else {
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); }
static bool isEditableElement(QWebPage* page) { const QWebFrame* frame = (page ? page->currentFrame() : 0); QWebElement element = (frame ? frame->findFirstElement(QL1S(":focus")) : QWebElement()); if (!element.isNull()) { const QString tagName(element.tagName()); if (tagName.compare(QL1S("textarea"), Qt::CaseInsensitive) == 0) { return true; } const QString type(element.attribute(QL1S("type")).toLower()); if (tagName.compare(QL1S("input"), Qt::CaseInsensitive) == 0 && (type.isEmpty() || type == QL1S("text") || type == QL1S("password"))) { return true; } if (element.evaluateJavaScript("this.isContentEditable").toBool()) { return true; } } return false; }
extern QVariantMap toMap(QWebElement el, QStringList css_attrs) { QVariantMap map; map["isNull"] = false; map["classes"] = QVariant(el.classes()); map["tagName"] = QVariant(el.tagName()); QRect rect = el.geometry(); QVariantMap geo; geo["width"] = rect.width(); geo["height"] = rect.height(); geo["x"] = rect.x(); geo["y"] = rect.y(); map["geometry"] = QVariant(geo); QVariantMap attrs; QStringList attributes = el.attributeNames(); foreach(QString name,attributes) { attrs[name] = el.attribute(name); }
void HtmlExtractor::moveTemplates(const QString &path) { MakeDirectory(path); QDir dir(path); QWebElementCollection elements = getDocument().findAll("[type=\"text/template\"]"); if(elements.count()) { for(QWebElementCollection::iterator it = elements.begin(), end=elements.end(); it!=end; ++it) { QWebElement element = *it; QString filename = element.attribute("id").replace("_tpl",".tpl"); qDebug()<<"moving element : "<<filename; move(element, dir.filePath(filename), false); } } else { qDebug()<<"no element found"; } }
static void parseDelayClass(const QWebElement &element, StationScheduleItem &item) { if (!element.isNull()) { QWebElement image = element.findFirst("img"); if (!image.isNull()) { int delayClass = 42; QString imageName = image.attribute("src"); if (!imageName.isEmpty()) { QRegExp delayClassRegexp("pallinoRit([0-9])\\.png"); int pos = delayClassRegexp.indexIn(imageName); qDebug() << "regexp matched at pos:" << pos << "match:" << delayClassRegexp.cap(0); delayClass = (pos >= 0) ? delayClassRegexp.cap(1).toInt() : 0; } item.setDelayClass(delayClass); } else { qDebug() << "img not found"; } } else { qDebug() << "div.bloccotreno not found"; } }
QString CustomWebView::URLToProperString (const QUrl& url) { QString string = url.toString (); QWebElement equivs = page ()->mainFrame ()-> findFirstElement ("meta[http-equiv=\"Content-Type\"]"); if (!equivs.isNull ()) { QString content = equivs.attribute ("content", "text/html; charset=UTF-8"); const QString charset = "charset="; int pos = content.indexOf (charset); if (pos >= 0) PreviousEncoding_ = content.mid (pos + charset.length ()).toLower (); } if (PreviousEncoding_ != "utf-8" && PreviousEncoding_ != "utf8" && !PreviousEncoding_.isEmpty ()) string = url.toEncoded (); return string; }