/*! Returns the area of the largest element at position (\a x,\a y) that is no larger than \a maxWidth by \a maxHeight pixels. May return an area larger in the case when no smaller element is at the position. */ QRect QDeclarativeWebView::elementAreaAt(int x, int y, int maxWidth, int maxHeight) const { QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x, y)); QRect hitRect = hit.boundingRect(); QWebElement element = hit.enclosingBlockElement(); if (maxWidth <= 0) maxWidth = INT_MAX; if (maxHeight <= 0) maxHeight = INT_MAX; while (!element.parent().isNull() && element.geometry().width() <= maxWidth && element.geometry().height() <= maxHeight) { hitRect = element.geometry(); element = element.parent(); } return hitRect; }
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; }
QWebElement ChromeDOM::findChromeParent(QWebElement element) { while(!(element = element.parent()).isNull()){ if (element.attribute("class") == "GinebraSnippet"){ return element; } } return element; }
QWebElement MyWebView::FindCloserContainer(QWebElement &elem) { // find by elem id bool bIsContainer = false; QString strTemp = elem.attribute("id"); WDomElem * welem = m_pMainWindow->m_treemodel.getElemByName (strTemp); // check if valid parent if (welem) { QDomElement delem = welem->getElem(); if (delem.attribute(g_strClassAttr).compare("WContainerWidget") == 0 || delem.attribute(g_strClassAttr).compare("WAnchor" ) == 0 || delem.attribute(g_strClassAttr).compare("WGroupBox" ) == 0 || delem.attribute(g_strClassAttr).compare("WPanel" ) == 0 || delem.attribute(g_strClassAttr).compare("WMenuItem" ) == 0 || delem.attribute(g_strClassAttr).compare("WStackedWidget" ) == 0 || delem.attribute(g_strClassAttr).compare("WTabItem" ) == 0) { bIsContainer = true; } } // if container return, else keep looking if (bIsContainer) { return elem; } else { if (!elem.parent().isNull()) { QWebElement welemTemp = elem.parent(); return FindCloserContainer(welemTemp); } else { return QWebElement(); } } }
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); } }
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); } }
WebElementStruct PhpWebView::createWebElementStruct(QWebElement elem, int i) { WebElementStruct we; we.el = elem; we.position = elem.styleProperty("position", QWebElement::ComputedStyle); we.z_index = 0; we.i = i; QWebElement cur = elem; while (!cur.isNull()) { QString z = cur.styleProperty("z-index", QWebElement::ComputedStyle); bool res; int zi = z.toInt(&res); if (res) { we.z_index = zi; break; } cur = cur.parent(); } cur = elem; while (!cur.isNull()) { QString pos = cur.styleProperty("position", QWebElement::ComputedStyle); if (pos != "inherit") { we.position = pos; break; } cur = cur.parent(); } return we; }
void tdRenderer::render(QByteArray ba) { bufreset(m_buffer); QWebElement element = m_body.findFirst(".__tmp__"); const char *data = ba.data(); uint beg = 0; size_t e = ba.size(); int prevsize = 0; int pos = m_fframe; while (beg < e) { const char *offs = data + beg; int n = td_markdown_render(m_buffer, (const uint8_t *) offs, e - beg, m_markdown); QByteArray bytes((const char *) m_buffer->data + prevsize, m_buffer->size - prevsize); m_sizes.insert(pos, n); m_indices.insert(pos++, m_index); if (m_pants) { bufreset(m_tmpbuffer); sdhtml_smartypants(m_tmpbuffer, (const uint8_t *) bytes.constData(), bytes.size()); QByteArray pants((const char *) m_tmpbuffer->data, m_tmpbuffer->size); element.appendInside(pants); } else { element.appendInside(bytes); } QWebElementCollection children = element.findAll("*"); QString klassName = "__" % QString::number(m_index++) % "__"; QWebElementCollection::const_iterator i = children.constBegin(); for (; i != children.constEnd(); ++i) { QWebElement e = *i; e.addClass(klassName); if (!e.parent().hasClass(klassName)) element.prependOutside(e.takeFromDocument()); } if (m_body.findFirst("." % klassName).isNull()) element.prependOutside("<span class=\"" % klassName % "\"></span>"); beg += n; prevsize = m_buffer->size; } element.takeFromDocument(); }
QTreeWidgetItem* XPathInspector::findTreeItemAndSelect(const QWebElement & elem) { QList<QWebElement> patharr; QWebElement current = elem; while (!current.isNull()) { patharr.prepend(current); current = current.parent(); } QTreeWidgetItem *topitem = NULL; for (int i=0; i<tree->topLevelItemCount(); i++) { QTreeWidgetItem *item = tree->topLevelItem(i); QWebElement node = item->data(0, Qt::UserRole).value<QWebElement>(); if (node == patharr.at(0)) { tree->expandItem(item); topitem = item; break; } } for (int i=1; i<patharr.count(); i++) { if (topitem != NULL) { for (int j=0; j<topitem->childCount(); j++) { QWebElement node = topitem->child(j)->data(0, Qt::UserRole).value<QWebElement>(); if (patharr.at(i) == node) { topitem = topitem->child(j); tree->expandItem(topitem); break; } } } } topitem->setSelected(true); return topitem; }
QRectF WebContentAnimationItem::findZoomableRectForPoint(const QPointF& point) { QPointF zoomPoint = m_webView->mapFromParent(point); QWebHitTestResult hitResult = m_webView->page()->mainFrame()->hitTestContent(zoomPoint.toPoint()); QWebElement targetElement = hitResult.enclosingBlockElement(); while (!targetElement.isNull() && targetElement.geometry().width() < MinDoubleClickZoomTargetWidth) targetElement = targetElement.parent(); if (!targetElement.isNull()) { QRectF elementRect = targetElement.geometry(); qreal overMinWidth = elementRect.width() - ZoomableContentMinWidth; if (overMinWidth < 0) elementRect.adjust(overMinWidth / 2, 0, -overMinWidth / 2, 0); zoomPoint.setX(elementRect.x()); QRectF resultRect(zoomPoint, elementRect.size()); return QRectF(m_webView->mapToParent(resultRect.topLeft()), m_webView->mapToParent(resultRect.bottomRight())); } return QRectF(); }
void SearchEnginesManager::addEngineFromForm(const QWebElement &element, WebView* view) { QWebElement formElement = element.parent(); while (!formElement.isNull()) { if (formElement.tagName().toLower() == QLatin1String("form")) { break; } formElement = formElement.parent(); } if (formElement.isNull()) { return; } const QString method = formElement.hasAttribute("method") ? formElement.attribute("method").toUpper() : "GET"; bool isPost = method == QLatin1String("POST"); QUrl actionUrl = QUrl::fromEncoded(formElement.attribute("action").toUtf8()); if (actionUrl.isRelative()) { actionUrl = view->url().resolved(actionUrl); } QUrl parameterUrl = actionUrl; if (isPost) { parameterUrl = QUrl("http://foo.bar"); } #if QT_VERSION >= 0x050000 QUrlQuery query(parameterUrl); query.addQueryItem(element.attribute("name"), "%s"); QWebElementCollection allInputs = formElement.findAll("input"); foreach (QWebElement e, allInputs) { if (element == e || !e.hasAttribute("name")) { continue; } query.addQueryItem(e.attribute("name"), e.evaluateJavaScript("this.value").toString()); } parameterUrl.setQuery(query); #else QList<QPair<QByteArray, QByteArray> > queryItems; QPair<QByteArray, QByteArray> item; item.first = element.attribute("name").toUtf8(); item.second = "%s"; queryItems.append(item); QWebElementCollection allInputs = formElement.findAll("input"); foreach (QWebElement e, allInputs) { if (element == e || !e.hasAttribute("name")) { continue; } QPair<QByteArray, QByteArray> item; item.first = QUrl::toPercentEncoding(e.attribute("name").toUtf8()); item.second = QUrl::toPercentEncoding(e.evaluateJavaScript("this.value").toByteArray()); queryItems.append(item); } parameterUrl.setEncodedQueryItems(parameterUrl.encodedQueryItems() + queryItems); #endif if (!isPost) { actionUrl = parameterUrl; } SearchEngine engine; engine.name = view->title(); engine.icon = view->icon(); engine.url = actionUrl.toEncoded(); if (isPost) { QByteArray data = parameterUrl.toEncoded(QUrl::RemoveScheme); engine.postData = data.contains('?') ? data.mid(data.lastIndexOf('?') + 1) : QByteArray(); } EditSearchEngine dialog(SearchEnginesDialog::tr("Add Search Engine"), view); dialog.setName(engine.name); dialog.setIcon(engine.icon); dialog.setUrl(engine.url); dialog.setPostData(engine.postData); if (dialog.exec() != QDialog::Accepted) { return; } engine.name = dialog.name(); engine.icon = dialog.icon(); engine.url = dialog.url(); engine.shortcut = dialog.shortcut(); engine.postData = dialog.postData().toUtf8(); if (engine.name.isEmpty() || engine.url.isEmpty()) { return; } addEngine(engine); }
void WBWebTrapWebView::highliteElementAtPos ( const QPoint& pos) { mCurrentContentType = Unknown; if(page() && page()->currentFrame()) { QWebHitTestResult htr = page()->currentFrame()->hitTestContent (pos); QRect pageHtr = htr.boundingRect().translated(htr.frame()->pos()); QRect updateRect = mWebViewElementRect.united(pageHtr); updateRect = updateRect.adjusted(-8, -8, 8, 8); mDomElementRect = htr.boundingRect(); if (!htr.pixmap().isNull()) { mCurrentContentType = Image; qDebug() << "found pixmap at " << htr.boundingRect(); } else { QWebElement element = htr.element(); QString tagName = element.tagName().toLower(); if (tagName == "object" || tagName == "embed") { mCurrentContentType = ObjectOrEmbed; } else if ((tagName == "input") || (tagName == "textarea")) { QString ec = potentialEmbedCodeAtPos(pos); if (ec.length() > 0) { qDebug() << "found input data \n\n" << ec; mCurrentContentType = Input; } } else { QString tagName = htr.element().tagName(); QString id = htr.element().attribute("id", ""); QWebElement el = htr.element(); QString idSelector = tagName + "#" + id; bool idSuccess = (el == el.document().findFirst(idSelector)); if (idSuccess) { mElementQuery = idSelector; mCurrentContentType = ElementByQuery; } else { //bool isValid = true; QWebElement elParent = el.parent(); QWebElement currentEl = el; QString path = tagName; QStringList pathElements; do { QWebElement someSibling = elParent.firstChild(); int index = 0; bool foundIndex = false; do { if (someSibling.tagName() == currentEl.tagName()) { if (someSibling == currentEl) { foundIndex = true; } else index++; } someSibling = someSibling.nextSibling(); } while(!someSibling.isNull() && !foundIndex); QString part; if (index > 0) part = QString("%1:nth-child(%2)").arg(currentEl.tagName()).arg(index); else part = currentEl.tagName(); pathElements.insert(0, part); currentEl = elParent; elParent = elParent.parent(); } while(!elParent.isNull()); //QString idSelector = tagName + "#" + id; QString treeSelector = pathElements.join(" > "); mElementQuery = treeSelector; mCurrentContentType = ElementByQuery; //bool treeSuccess = (el == el.document().findFirst(treeSelector)); //qDebug() << "----------------------------"; //qDebug() << idSuccess << idSelector; //qDebug() << treeSuccess << treeSelector; } } } update(updateRect); } }
void tdRenderer::parseMarkdown(int at, int removed, int added) { QTextCursor cursor = m_editor->textCursor(); cursor.beginEditBlock(); int steps = m_editor->document()->availableUndoSteps(); bool undoStepsChanged = (steps != m_undoSteps); m_undoSteps = steps; if (undoStepsChanged && !m_isUndoRedo) m_undoStack->push(new tdRendererCursorCommand(this, at, removed, added)); m_isUndoRedo = false; int start; int end; if (m_sizes.isEmpty()) { start = end = 0; } else { int i = 0, n = 0; while (i < m_fframe) n += m_sizes.at(i++); start = n; while (i <= m_lframe) n += m_sizes.at(i++); end = n; } int diff = added - removed; m_count += diff; if (m_sizes.isEmpty()) end = m_count; else end += diff; cursor.setPosition(start); cursor.setPosition(qMin(end, m_count), QTextCursor::KeepAnchor); int c = m_fframe; int klass = 0; QWebElementCollection collection; while (c++ <= m_lframe && !m_sizes.isEmpty()) { m_sizes.takeAt(m_fframe); klass = m_indices.takeAt(m_fframe); collection.append(m_body.findAll(".__" % QString::number(klass) % "__")); } QList<QWebElement> list = collection.toList(); QWebElement element; if (klass) { QString k = "__" % QString::number(klass) % "__"; element = list.last(); while (element.parent().hasClass(k)) element = element.parent(); list.removeAll(element); element.setOuterXml("<div class=\"__tmp__\"></div>"); QList<QWebElement>::iterator i = list.begin(); for (; i != list.end(); ++i) i->takeFromDocument(); } else { m_body.prependInside("<div class=\"__tmp__\"></div>"); } render(cursor.selection().toPlainText().toAscii()); cursor.endEditBlock(); updateFrameInterval(); emit parsingDone(); }
void QtWebKitWebWidget::showContextMenu(const QPoint &position) { if (position.isNull() && m_webView->selectedText().isEmpty()) { return; } const QPoint hitPosition = (position.isNull() ? m_webView->mapFromGlobal(QCursor::pos()) : position); MenuFlags flags = NoMenu; m_hitResult = m_webView->page()->frameAt(hitPosition)->hitTestContent(hitPosition); if (m_hitResult.element().tagName().toLower() == QLatin1String("textarea") || m_hitResult.element().tagName().toLower() == QLatin1String("select") || (m_hitResult.element().tagName().toLower() == QLatin1String("input") && (m_hitResult.element().attribute(QLatin1String("type")).isEmpty() || m_hitResult.element().attribute(QLatin1String("type")).toLower() == QLatin1String("text")))) { QWebElement parentElement = m_hitResult.element().parent(); while (!parentElement.isNull() && parentElement.tagName().toLower() != QLatin1String("form")) { parentElement = parentElement.parent(); } if (!parentElement.isNull() && parentElement.hasAttribute(QLatin1String("action")) && !parentElement.findFirst(QLatin1String("input[name], select[name], textarea[name]")).isNull()) { flags |= FormMenu; } } if (m_hitResult.pixmap().isNull() && m_hitResult.isContentSelected() && !m_webView->selectedText().isEmpty()) { updateSearchActions(m_searchEngine); flags |= SelectionMenu; } if (m_hitResult.linkUrl().isValid()) { flags |= LinkMenu; } if (!m_hitResult.pixmap().isNull()) { flags |= ImageMenu; const bool isImageOpened = getUrl().matches(m_hitResult.imageUrl(), (QUrl::NormalizePathSegments | QUrl::RemoveFragment | QUrl::StripTrailingSlash)); getAction(OpenImageInNewTabAction)->setEnabled(!isImageOpened); getAction(InspectElementAction)->setEnabled(!isImageOpened); } if (m_hitResult.mediaUrl().isValid()) { flags |= MediaMenu; const bool isVideo = (m_hitResult.element().tagName().toLower() == QLatin1String("video")); const bool isPaused = m_hitResult.element().evaluateJavaScript(QLatin1String("this.paused")).toBool(); const bool isMuted = m_hitResult.element().evaluateJavaScript(QLatin1String("this.muted")).toBool(); getAction(SaveMediaToDiskAction)->setText(isVideo ? tr("Save Video...") : tr("Save Audio...")); getAction(CopyMediaUrlToClipboardAction)->setText(isVideo ? tr("Copy Video Link to Clipboard") : tr("Copy Audio Link to Clipboard")); getAction(ToggleMediaControlsAction)->setText(tr("Show Controls")); getAction(ToggleMediaLoopAction)->setText(tr("Looping")); getAction(ToggleMediaPlayPauseAction)->setIcon(Utils::getIcon(isPaused ? QLatin1String("media-playback-start") : QLatin1String("media-playback-pause"))); getAction(ToggleMediaPlayPauseAction)->setText(isPaused ? tr("Play") : tr("Pause")); getAction(ToggleMediaMuteAction)->setIcon(Utils::getIcon(isMuted ? QLatin1String("audio-volume-medium") : QLatin1String("audio-volume-muted"))); getAction(ToggleMediaMuteAction)->setText(isMuted ? tr("Unmute") : tr("Mute")); } if (m_hitResult.isContentEditable()) { flags |= EditMenu; getAction(ClearAllAction)->setEnabled(getAction(SelectAllAction)->isEnabled()); } if (flags == NoMenu || flags == FormMenu) { flags |= StandardMenu; if (m_hitResult.frame() != m_webView->page()->mainFrame()) { flags |= FrameMenu; } } WebWidget::showContextMenu(hitPosition, flags); }
void QtWebKitWebWidget::triggerAction(WindowAction action, bool checked) { const QWebPage::WebAction webAction = mapAction(action); if (webAction != QWebPage::NoWebAction) { m_webView->triggerPageAction(webAction, checked); return; } switch (action) { case RewindBackAction: m_webView->page()->history()->goToItem(m_webView->page()->history()->itemAt(0)); break; case RewindForwardAction: m_webView->page()->history()->goToItem(m_webView->page()->history()->itemAt(m_webView->page()->history()->count() - 1)); break; case CopyAddressAction: QApplication::clipboard()->setText(getUrl().toString()); break; case ZoomInAction: setZoom(qMin((getZoom() + 10), 10000)); break; case ZoomOutAction: setZoom(qMax((getZoom() - 10), 10)); break; case ZoomOriginalAction: setZoom(100); break; case ReloadOrStopAction: if (isLoading()) { triggerAction(StopAction); } else { triggerAction(ReloadAction); } break; case OpenLinkInNewTabAction: if (m_hitResult.linkUrl().isValid()) { emit requestedOpenUrl(m_hitResult.linkUrl(), false, false); } break; case OpenLinkInNewTabBackgroundAction: if (m_hitResult.linkUrl().isValid()) { emit requestedOpenUrl(m_hitResult.linkUrl(), true, false); } break; case OpenLinkInNewWindowAction: if (m_hitResult.linkUrl().isValid()) { emit requestedOpenUrl(m_hitResult.linkUrl(), false, true); } break; case OpenLinkInNewWindowBackgroundAction: if (m_hitResult.linkUrl().isValid()) { emit requestedOpenUrl(m_hitResult.linkUrl(), true, true); } break; case BookmarkLinkAction: if (m_hitResult.linkUrl().isValid()) { emit requestedAddBookmark(m_hitResult.linkUrl(), m_hitResult.element().attribute(QLatin1String("title"))); } break; case OpenSelectionAsLinkAction: emit requestedOpenUrl(m_webView->selectedText(), false, false); break; case ImagePropertiesAction: { ImagePropertiesDialog dialog(m_hitResult.imageUrl(), m_hitResult.element().attribute(QLatin1String("alt")), m_hitResult.element().attribute(QLatin1String("longdesc")), m_hitResult.pixmap(), (m_networkAccessManager->cache() ? m_networkAccessManager->cache()->data(m_hitResult.imageUrl()) : NULL), this); QEventLoop eventLoop; m_parent->showDialog(&dialog); connect(&dialog, SIGNAL(finished(int)), &eventLoop, SLOT(quit())); connect(this, SIGNAL(destroyed()), &eventLoop, SLOT(quit())); eventLoop.exec(); m_parent->hideDialog(&dialog); } break; case InspectPageAction: if (!m_inspector) { m_inspector = new QWebInspector(this); m_inspector->setPage(m_webView->page()); m_inspector->setContextMenuPolicy(Qt::NoContextMenu); m_inspector->setMinimumHeight(200); m_splitter->addWidget(m_inspector); } m_inspector->setVisible(checked); getAction(InspectPageAction)->setChecked(checked); emit actionsChanged(); emit progressBarGeometryChanged(); break; case SaveLinkToDownloadsAction: TransfersManager::startTransfer(m_hitResult.linkUrl().toString(), QString(), isPrivate(), true); break; case OpenFrameInThisTabAction: if (m_hitResult.frame()) { setUrl(m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()); } break; case OpenFrameInNewTabBackgroundAction: if (m_hitResult.frame()) { emit requestedOpenUrl((m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()), true, false); } break; case CopyFrameLinkToClipboardAction: if (m_hitResult.frame()) { QGuiApplication::clipboard()->setText((m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()).toString()); } break; case ReloadFrameAction: if (m_hitResult.frame()) { const QUrl url = (m_hitResult.frame()->url().isValid() ? m_hitResult.frame()->url() : m_hitResult.frame()->requestedUrl()); m_hitResult.frame()->setUrl(QUrl()); m_hitResult.frame()->setUrl(url); } break; case SearchAction: search(getAction(SearchAction)); break; case CreateSearchAction: { QWebElement parentElement = m_hitResult.element().parent(); while (!parentElement.isNull() && parentElement.tagName().toLower() != "form") { parentElement = parentElement.parent(); } const QWebElementCollection inputs = parentElement.findAll(QLatin1String("input:not([disabled])[name], select:not([disabled])[name], textarea:not([disabled])[name]")); if (!parentElement.isNull() && parentElement.hasAttribute(QLatin1String("action")) && inputs.count() > 0) { QUrlQuery parameters; for (int i = 0; i < inputs.count(); ++i) { QString value; if (inputs.at(i).tagName().toLower() == QLatin1String("textarea")) { value = inputs.at(i).toPlainText(); } else if (inputs.at(i).tagName().toLower() == QLatin1String("select")) { const QWebElementCollection options = inputs.at(i).findAll(QLatin1String("option")); for (int j = 0; j < options.count(); ++j) { if (options.at(j).hasAttribute(QLatin1String("selected"))) { value = options.at(j).attribute(QLatin1String("value"), options.at(j).toPlainText()); break; } } } else { if ((inputs.at(i).attribute(QLatin1String("type")) == QLatin1String("checkbox") || inputs.at(i).attribute(QLatin1String("type")) == QLatin1String("radio")) && !inputs.at(i).hasAttribute(QLatin1String("checked"))) { continue; } value = inputs.at(i).attribute(QLatin1String("value")); } parameters.addQueryItem(inputs.at(i).attribute(QLatin1String("name")), ((inputs.at(i) == m_hitResult.element()) ? QLatin1String("{searchTerms}") : value)); } const QStringList identifiers = SearchesManager::getSearchEngines(); QStringList shortcuts; QList<SearchInformation*> engines; for (int i = 0; i < identifiers.count(); ++i) { SearchInformation *engine = SearchesManager::getSearchEngine(identifiers.at(i)); if (!engine) { continue; } engines.append(engine); const QString shortcut = engine->shortcut; if (!shortcut.isEmpty()) { shortcuts.append(shortcut); } } QString identifier = getUrl().host().toLower().remove(QRegularExpression(QLatin1String("[^a-z0-9]"))); while (identifier.isEmpty() || identifiers.contains(identifier)) { identifier = QInputDialog::getText(this, tr("Select Identifier"), tr("Input Unique Search Engine Identifier:")); if (identifier.isEmpty()) { return; } } const QIcon icon = m_webView->icon(); const QUrl url(parentElement.attribute(QLatin1String("action"))); QVariantHash engineData; engineData[QLatin1String("identifier")] = identifier; engineData[QLatin1String("isDefault")] = false; engineData[QLatin1String("encoding")] = QLatin1String("UTF-8"); engineData[QLatin1String("selfUrl")] = QString(); engineData[QLatin1String("resultsUrl")] = (url.isEmpty() ? getUrl() : (url.isRelative() ? getUrl().resolved(url) : url)).toString(); engineData[QLatin1String("resultsEnctype")] = parentElement.attribute(QLatin1String("enctype")); engineData[QLatin1String("resultsMethod")] = ((parentElement.attribute(QLatin1String("method"), QLatin1String("get")).toLower() == QLatin1String("post")) ? QLatin1String("post") : QLatin1String("get")); engineData[QLatin1String("resultsParameters")] = parameters.toString(QUrl::FullyDecoded); engineData[QLatin1String("suggestionsUrl")] = QString(); engineData[QLatin1String("suggestionsEnctype")] = QString(); engineData[QLatin1String("suggestionsMethod")] = QLatin1String("get"); engineData[QLatin1String("suggestionsParameters")] = QString(); engineData[QLatin1String("shortcut")] = QString(); engineData[QLatin1String("title")] = getTitle(); engineData[QLatin1String("description")] = QString(); engineData[QLatin1String("icon")] = (icon.isNull() ? Utils::getIcon(QLatin1String("edit-find")) : icon); SearchPropertiesDialog dialog(engineData, shortcuts, this); if (dialog.exec() == QDialog::Rejected) { return; } engineData = dialog.getEngineData(); if (shortcuts.contains(engineData[QLatin1String("shortcut")].toString())) { engineData[QLatin1String("shortcut")] = QString(); } SearchInformation *engine = new SearchInformation(); engine->identifier = engineData[QLatin1String("identifier")].toString(); engine->title = engineData[QLatin1String("title")].toString(); engine->description = engineData[QLatin1String("description")].toString(); engine->shortcut = engineData[QLatin1String("shortcut")].toString(); engine->encoding = engineData[QLatin1String("encoding")].toString(); engine->selfUrl = engineData[QLatin1String("selfUrl")].toString(); engine->resultsUrl.url = engineData[QLatin1String("resultsUrl")].toString(); engine->resultsUrl.enctype = engineData[QLatin1String("resultsEnctype")].toString(); engine->resultsUrl.method = engineData[QLatin1String("resultsMethod")].toString(); engine->resultsUrl.parameters = QUrlQuery(engineData[QLatin1String("resultsParameters")].toString()); engine->icon = engineData[QLatin1String("icon")].value<QIcon>(); engines.append(engine); if (SearchesManager::setSearchEngines(engines) && engineData[QLatin1String("isDefault")].toBool()) { SettingsManager::setValue(QLatin1String("Browser/DefaultSearchEngine"), engineData[QLatin1String("identifier")].toString()); } } } break; case ClearAllAction: triggerAction(SelectAllAction); triggerAction(DeleteAction); break; default: break; } }
void HtmlBookmarksImporter::processElement(const QWebElement &element) { if (element.tagName().toLower() == QLatin1String("h3")) { BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::FolderBookmark, QUrl(), element.toPlainText(), getCurrentFolder()); const QString keyword = element.attribute(QLatin1String("SHORTCUTURL")); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty()) { const QDateTime time = QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()); bookmark->setData(time, BookmarksModel::TimeAddedRole); bookmark->setData(time, BookmarksModel::TimeModifiedRole); } setCurrentFolder(bookmark); } else if (element.tagName().toLower() == QLatin1String("a")) { const QUrl url(element.attribute(QLatin1String("href"))); if (!allowDuplicates() && BookmarksManager::hasBookmark(url)) { return; } BookmarksItem *bookmark = BookmarksManager::addBookmark(BookmarksModel::UrlBookmark, url, element.toPlainText(), getCurrentFolder()); const QString keyword = element.attribute(QLatin1String("SHORTCUTURL")); if (!BookmarksManager::hasKeyword(keyword)) { bookmark->setData(keyword, BookmarksModel::KeywordRole); } if (element.parent().nextSibling().tagName().toLower() == QLatin1String("dd")) { bookmark->setData(element.parent().nextSibling().toPlainText(), BookmarksModel::DescriptionRole); } if (!element.attribute(QLatin1String("ADD_DATE")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("ADD_DATE")).toUInt()), BookmarksModel::TimeAddedRole); } if (!element.attribute(QLatin1String("LAST_MODIFIED")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_MODIFIED")).toUInt()), BookmarksModel::TimeModifiedRole); } if (!element.attribute(QLatin1String("LAST_VISITED")).isEmpty()) { bookmark->setData(QDateTime::fromTime_t(element.attribute(QLatin1String("LAST_VISITED")).toUInt()), BookmarksModel::TimeVisitedRole); } } else if (element.tagName().toLower() == QLatin1String("hr")) { BookmarksManager::addBookmark(BookmarksModel::SeparatorBookmark, QUrl(), QString(), getCurrentFolder()); } const QWebElementCollection descendants = element.findAll(QLatin1String("*")); for (int i = 0; i < descendants.count(); ++i) { if (descendants.at(i).parent() == element) { processElement(descendants.at(i)); } } if (element.tagName().toLower() == QLatin1String("dl")) { goToParent(); } }