void KWebPage::downloadResponse(QNetworkReply *reply) { Q_ASSERT(reply); if (!reply) return; // Put the job on hold only for the protocols we know about (read: http). KIO::Integration::AccessManager::putReplyOnHold(reply); QString mimeType; KIO::MetaData metaData; if (handleReply(reply, &mimeType, &metaData)) { return; } const KUrl replyUrl (reply->url()); // Ask KRun to handle the response when mimetype is unknown if (mimeType.isEmpty()) { (void)new KRun(replyUrl, d->windowWidget(), 0 , replyUrl.isLocalFile()); return; } // Ask KRun::runUrl to handle the response when mimetype is inode/* if (mimeType.startsWith(QL1S("inode/"), Qt::CaseInsensitive) && KRun::runUrl(replyUrl, mimeType, d->windowWidget(), false, false, metaData.value(QL1S("content-disposition-filename")))) { return; } }
CaBundleUpdater::CaBundleUpdater(NetworkManager* manager, QObject* parent) : QObject(parent) , m_manager(manager) , m_progress(Start) , m_reply(0) , m_latestBundleVersion(0) { m_bundleVersionFileName = DataPaths::path(DataPaths::Config) + QL1S("/certificates/bundle_version"); m_bundleFileName = DataPaths::path(DataPaths::Config) + QL1S("/certificates/ca-bundle.crt"); m_lastUpdateFileName = DataPaths::path(DataPaths::Config) + QL1S("/certificates/last_update"); // Make sure the certificates directory exists QDir certDir(DataPaths::path(DataPaths::Config) + QL1S("/certificates")); if (!certDir.exists()) certDir.mkpath(certDir.absolutePath()); int updateTime = 30 * 1000; // Check immediately on first run if (!QFile(m_lastUpdateFileName).exists()) { updateTime = 0; } QTimer::singleShot(updateTime, this, SLOT(start())); }
bool KWebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) { kDebug(800) << "url:" << request.url() << ", type:" << type << ", frame:" << frame; if (frame && d->wallet && type == QWebPage::NavigationTypeFormSubmitted) d->wallet->saveFormData(frame); // Make sure nothing is cached when private browsing mode is enabled... if (settings()->testAttribute(QWebSettings::PrivateBrowsingEnabled)) { if (!d->inPrivateBrowsingMode) { setDisableCookieJarStorage(networkAccessManager(), true); setSessionMetaData(QL1S("no-cache"), QL1S("true")); d->inPrivateBrowsingMode = true; } } else { if (d->inPrivateBrowsingMode) { setDisableCookieJarStorage(networkAccessManager(), false); removeSessionMetaData(QL1S("no-cache")); d->inPrivateBrowsingMode = false; } } /* If the navigation request is from the main frame, set the cross-domain meta-data value to the current url for proper integration with KCookieJar... */ if (frame == mainFrame() && type != QWebPage::NavigationTypeReload) setSessionMetaData(QL1S("cross-domain"), request.url().toString()); return QWebPage::acceptNavigationRequest(frame, request, type); }
void HistoryManager::updateHistoryEntry(const KUrl &url, const QString &title) { QString urlString = url.url(); urlString.remove(QL1S("www.")); if(urlString.startsWith(QL1S("http")) && urlString.endsWith(QL1C('/'))) urlString.remove(urlString.length()-1,1); for (int i = 0; i < m_history.count(); ++i) { QString itemUrl = m_history.at(i).url; itemUrl.remove(QL1S("www.")); if(itemUrl.startsWith(QL1S("http")) && itemUrl.endsWith(QL1C('/'))) itemUrl.remove(itemUrl.length()-1,1); if (urlString == itemUrl) { m_history[i].title = title; m_history[i].url = url.url(); m_saveTimer->changeOccurred(); if (m_lastSavedUrl.isEmpty()) m_lastSavedUrl = m_history.at(i).url; emit entryUpdated(i); break; } } }
bool SessionManager::restoreYourSession(int index) { const QString & sessionPath = KStandardDirs::locateLocal("appdata" , QL1S("usersessions/")); const QString & sessionName = QL1S("ses") + QString::number(index); QDomDocument document("session"); if (!readSessionDocument(document,sessionPath + sessionName)) return false; // trace the windows to delete RekonqWindowList wList = rApp->rekonqWindowList(); for (unsigned int winNo = 0; winNo < document.elementsByTagName("window").length(); winNo++) { QDomElement window = document.elementsByTagName("window").at(winNo).toElement(); RekonqWindow *tw = rApp->newWindow(); int currentTab = loadTabs(tw, window, true, false); tw->tabWidget()->setCurrentIndex(currentTab); } Q_FOREACH(const QWeakPointer<RekonqWindow> &w, wList) { if (!w.isNull()) w.data()->close(); } return true; }
void msgHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg) { if (msg.startsWith(QL1S("QSslSocket: cannot resolve SSLv2_"))) return; if (msg.startsWith(QL1S("Remote debugging server started successfully."))) return; const QByteArray localMsg = msg.toLocal8Bit(); switch (type) { case QtDebugMsg: case QtWarningMsg: case QtCriticalMsg: std::cerr << localMsg.constData(); if (context.file && context.line && context.function) std::cerr << " (" << context.file << ":" << context.line << ", " << context.function << ")"; std::cerr << std::endl; break; case QtFatalMsg: std::cerr << "Fatal: " << localMsg.constData() << std::endl; if (context.file && context.line && context.function) std::cerr << " (" << context.file << ":" << context.line << ", " << context.function << ")"; std::cerr << std::endl; abort(); default: break; } }
bool AdBlockManager::addSubscriptionFromUrl(const QUrl &url) { const QList<QPair<QString, QString> > queryItems = QUrlQuery(url).queryItems(QUrl::FullyDecoded); QString subscriptionTitle; QString subscriptionUrl; for (int i = 0; i < queryItems.count(); ++i) { QPair<QString, QString> pair = queryItems.at(i); if (pair.first == QL1S("location")) subscriptionUrl = pair.second; else if (pair.first == QL1S("title")) subscriptionTitle = pair.second; } if (subscriptionTitle.isEmpty() || subscriptionUrl.isEmpty()) return false; const QString message = AdBlockManager::tr("Do you want to add <b>%1</b> subscription?").arg(subscriptionTitle); QMessageBox::StandardButton result = QMessageBox::question(0, AdBlockManager::tr("AdBlock Subscription"), message, QMessageBox::Yes | QMessageBox::No); if (result == QMessageBox::Yes) { AdBlockManager::instance()->addSubscription(subscriptionTitle, subscriptionUrl); AdBlockManager::instance()->showDialog(); } return true; }
QString Scripts::completeFormData(const QByteArray &data) { QString source = QL1S("(function() {" "var data = '%1'.split('&');" "var inputs = document.getElementsByTagName('input');" "" "for (var i = 0; i < data.length; ++i) {" " var pair = data[i].split('=');" " if (pair.length != 2)" " continue;" " var key = decodeURIComponent(pair[0]);" " var val = decodeURIComponent(pair[1]);" " for (var j = 0; j < inputs.length; ++j) {" " var input = inputs[j];" " var type = input.type.toLowerCase();" " if (type != 'text' && type != 'password' && type != 'email')" " continue;" " if (input.name == key) {" " input.value = val;" " input.dispatchEvent(new Event('change'));" " }" " }" "}" "" "})()"); QString d = data; d.replace(QL1S("'"), QL1S("\\'")); return source.arg(d); }
void TabBar::setupHistoryActions() { MainWindow *w = Application::instance()->mainWindow(); MainView *mv = qobject_cast<MainView *>(parent()); QAction *openLastClosedTabAction = w->actionByName( QL1S("open_last_closed_tab") ); openLastClosedTabAction->setEnabled( mv->recentlyClosedTabs().size() > 0 ); // update closed tabs menu KActionMenu *am = qobject_cast<KActionMenu *>( w->actionByName( QL1S("closed_tab_menu") )); if (!am) return; bool isEnabled = ( mv->recentlyClosedTabs().size() > 0 ); am->setEnabled(isEnabled); if (am->menu()) am->menu()->clear(); if(!isEnabled) return; Q_FOREACH(const HistoryItem &item, mv->recentlyClosedTabs()) { KAction *a = new KAction(Application::iconManager()->iconForUrl(item.url), item.title, this); a->setData(item.url); connect(a, SIGNAL(triggered()), mv, SLOT(openClosedTab())); am->addAction(a); } }
AdBlockRuleFallbackImpl::AdBlockRuleFallbackImpl(const QString &filter) : AdBlockRuleImpl(filter) { m_regExp.setCaseSensitivity(Qt::CaseInsensitive); m_regExp.setPatternSyntax(QRegExp::RegExp2); QString parsedLine = filter; const int optionsNumber = parsedLine.lastIndexOf(QL1C('$')); if (optionsNumber >= 0 && !isRegExpFilter(parsedLine)) { const QStringList options(parsedLine.mid(optionsNumber + 1).split(QL1C(','))); parsedLine = parsedLine.left(optionsNumber); if (options.contains(QL1S("match-case"))) m_regExp.setCaseSensitivity(Qt::CaseSensitive); foreach (const QString &option, options) { // Domain restricted filter const QString domainKeyword(QL1S("domain=")); if (option.startsWith(domainKeyword)) { QStringList domainList = option.mid(domainKeyword.length()).split(QL1C('|')); foreach (const QString &domain, domainList) { if (domain.startsWith(QL1C('~'))) m_whiteDomains.insert(domain.toLower()); else m_blackDomains.insert(domain.toLower()); } } } }
StandardServiceRoot::StandardServiceRoot(RootItem *parent) : ServiceRoot(parent), m_recycleBin(new RecycleBin(this)), m_actionExportFeeds(nullptr), m_actionImportFeeds(nullptr), m_serviceMenu(QList<QAction*>()), m_feedContextMenu(QList<QAction*>()), m_actionFeedFetchMetadata(nullptr) { setTitle(qApp->system()->getUsername() + QL1S("@") + QL1S(APP_LOW_NAME)); setIcon(StandardServiceEntryPoint().icon()); setDescription(tr("This is obligatory service account for standard RSS/RDF/ATOM feeds.")); }
QString QzTools::escapeSqlString(QString urlString) { const static QString &escapeString = QL1S("!"); urlString.replace(escapeString, escapeString + escapeString); urlString.replace(QL1S("_"), escapeString + QL1S("_")); urlString.replace(QL1S("%"), escapeString + QL1S("%")); return urlString; }
static bool isMultimediaElement(const QWebElement& element) { if (element.tagName().compare(QL1S("video"), Qt::CaseInsensitive) == 0) return true; if (element.tagName().compare(QL1S("audio"), Qt::CaseInsensitive) == 0) return true; return false; }
NetworkAccessManager::NetworkAccessManager(QObject *parent) : AccessManager(parent) { QString c = KGlobal::locale()->country(); if (c == QL1S("C")) c = QL1S("en_US"); if (c != QL1S("en_US")) c.append(QL1S(", en_US")); _acceptLanguage = c.toLatin1(); }
void ThumbUpdater::updateThumb() { // Set loading animation _thumb.findFirst(QL1S(".preview img")).setAttribute(QL1S("src"), QL1S("file:///") + KStandardDirs::locate("appdata", "pics/busywidget.gif")); _thumb.findFirst(QL1S("span a")).setPlainText(i18n("Loading Preview...")); // Load URL QWebFrame *frame = qobject_cast<QWebFrame *>(parent()); WebSnap *snap = new WebSnap(KUrl(_url), frame); connect(snap, SIGNAL(snapDone(bool)), this, SLOT(updateImage(bool)), Qt::UniqueConnection); }
void FormEditTtRssAccount::onUrlChanged() { const QString url = m_ui->m_txtUrl->lineEdit()->text(); if (url.isEmpty()) { m_ui->m_txtUrl->setStatus(WidgetWithStatus::Error, tr("URL cannot be empty.")); } else if (url.endsWith(QL1S("/api/")) || url.endsWith(QL1S("/api"))) { m_ui->m_txtUrl->setStatus(WidgetWithStatus::Warning, tr("URL should NOT end with \"/api/\".")); } else { m_ui->m_txtUrl->setStatus(WidgetWithStatus::Ok, tr("URL is okay.")); } }
void KWebPage::downloadRequest(const QNetworkRequest& request) { KIO::TransferJob* job = KIO::get(request.url()); connect(job, SIGNAL(mimetype(KIO::Job*,QString)), this, SLOT(_k_receivedContentType(KIO::Job*,QString))); connect(job, SIGNAL(result(KJob*)), this, SLOT(_k_receivedContentTypeResult(KJob*))); job->setMetaData(request.attribute(static_cast<QNetworkRequest::Attribute>(KIO::AccessManager::MetaData)).toMap()); job->addMetaData(QL1S("MaxCacheSize"), QL1S("0")); // Don't store in http cache. job->addMetaData(QL1S("cache"), QL1S("cache")); // Use entry from cache if available. job->ui()->setWindow(d->windowWidget()); }
void TabBar::contextMenu(int tab, const QPoint &pos) { KActionMenu *closedTabsMenu = setupHistoryActions(); m_actualIndex = tab; KMenu menu; MainWindow *mainWindow = rApp->mainWindow(); menu.addAction(mainWindow->actionByName(QL1S("new_tab"))); menu.addAction(mainWindow->actionByName(QL1S("clone_tab"))); if (count() > 1) { menu.addAction(mainWindow->actionByName(QL1S("detach_tab"))); } menu.addAction(mainWindow->actionByName(QL1S("open_last_closed_tab"))); menu.addAction(closedTabsMenu); menu.addSeparator(); menu.addAction(mainWindow->actionByName(QL1S("close_tab"))); if (count() > 1) { menu.addAction(mainWindow->actionByName(QL1S("close_other_tabs"))); } menu.addSeparator(); menu.addAction(mainWindow->actionByName(QL1S("reload_tab"))); if (count() > 1) { menu.addAction(mainWindow->actionByName(QL1S("reload_all_tabs"))); } menu.exec(pos); }
static bool excludedMimeType(const QString &type) { if (type.startsWith(QL1S("inode/"), Qt::CaseInsensitive)) return true; if (type.startsWith(QL1S("application/x-java"), Qt::CaseInsensitive)) return true; if (type == QL1S("application/x-shockwave-flash") || type == QL1S("application/futuresplash")) return true; return false; }
void ThumbUpdater::updateImage(bool ok) { KUrl u(_url); QString previewPath = ok ? QL1S("file://") + WebSnap::imagePathFromUrl(u) : IconManager::self()->iconPathForUrl(u) ; _thumb.findFirst(QL1S(".preview img")).setAttribute(QL1S("src"), previewPath); _thumb.findFirst(QL1S("span a")).setPlainText(_title); this->deleteLater(); }
void testSplitQueries_data() { QTest::addColumn<QString>("input"); QTest::addColumn<QStringList>("output"); QTest::newRow("empty") << QString() << QStringList(); QTest::newRow("comment1") << "-- hi there" << (QStringList() << QL1S("-- hi there")); QTest::newRow("comment2") << "-- hi there\n" << (QStringList() << QL1S("-- hi there\n")); QTest::newRow("comment3") << "-- hi there\n\n" << (QStringList() << QL1S("-- hi there\n\n")); QTest::newRow("query1") << "SELECT * FROM tblVersion;" << (QStringList() << QL1S("SELECT * FROM tblVersion;")); QTest::newRow("query2") << "SELECT * FROM tblVersion;\n" << (QStringList() << QL1S("SELECT * FROM tblVersion")); QTest::newRow("query3") << "SELECT * FROM tblVersion\n" << (QStringList() << QL1S("SELECT * FROM tblVersion\n")); QTest::newRow("multi1") << "SELECT a FROM b;\nSELECT c FROM d" << (QStringList() << QL1S("SELECT a FROM b") << QL1S("SELECT c FROM d")); }
QString Scripts::setCss(const QString &css) { QString source = QL1S("(function() {" "var css = document.createElement('style');" "css.setAttribute('type', 'text/css');" "css.appendChild(document.createTextNode('%1'));" "document.getElementsByTagName('head')[0].appendChild(css);" "})()"); QString style = css; style.replace(QL1S("'"), QL1S("\\'")); style.replace(QL1S("\n"), QL1S("\\n")); return source.arg(style); }
QString LocationBar::convertUrlToText(const QUrl &url) { // It was most probably entered by user, so don't urlencode it if (url.scheme().isEmpty()) { return QUrl::fromPercentEncoding(url.toEncoded()); } QString stringUrl = QzTools::urlEncodeQueryString(url); if (stringUrl == QL1S("qupzilla:speeddial") || stringUrl.startsWith(QL1S("qupzilla:adblock")) || stringUrl == QL1S("about:blank")) { stringUrl.clear(); } return stringUrl; }
void KWebKitPart::slotUrlChanged(const QUrl& url) { // Ignore if empty if (url.isEmpty()) return; // Ignore if error url if (url.scheme().compare(QL1S("error"), Qt::CaseInsensitive) == 0) return; const QUrl u (url); // Ignore if url has not changed! if (this->url() == u) return; m_doLoadFinishedActions = true; setUrl(u); // Do not update the location bar with about:blank if (url != *globalBlankUrl) { //kDebug() << "Setting location bar to" << u.prettyUrl() << "current URL:" << this->url(); emit m_browserExtension->setLocationBarUrl(u.toDisplayString()); } }
QStringList NetworkFactory::extractFeedLinksFromHtmlPage(const QUrl &url, const QString &html) { QStringList feeds; const QRegExp rx(FEED_REGEX_MATCHER, Qt::CaseInsensitive); const QRegExp rx_href(FEED_HREF_REGEX_MATCHER, Qt::CaseInsensitive); for (int pos = 0; (pos = rx.indexIn(html, pos)) != -1; pos += rx.matchedLength()) { QString link_element = html.mid(pos, rx.matchedLength()); if (rx_href.indexIn(link_element) != -1) { QString href_attribute = rx_href.capturedTexts().at(0); QString feed_link = href_attribute.mid(6, href_attribute.size() - 7); if (feed_link.startsWith(QL1S("//"))) { feed_link = QString(URI_SCHEME_HTTP) + feed_link.mid(2); } else if (feed_link.startsWith(QL1C('/'))) { feed_link = url.toString(QUrl::RemovePath | QUrl::RemoveQuery | QUrl::StripTrailingSlash) + feed_link; } feeds.append(feed_link); } } return feeds; }
QIcon NavigationBar::iconForPage(const QUrl &url, const QIcon &sIcon) { QIcon icon; icon.addPixmap(url.scheme() == QL1S("qupzilla") ? QIcon(QSL(":icons/qupzilla.png")).pixmap(16, 16) : IconProvider::iconForUrl(url).pixmap(16, 16)); icon.addPixmap(sIcon.pixmap(16, 16), QIcon::Active); return icon; }
int main(int argc, char* argv[]) { QT_REQUIRE_VERSION(argc, argv, "5.6.0"); #ifndef Q_OS_WIN qInstallMessageHandler(&msgHandler); #endif #if defined(Q_OS_LINUX) || defined(__GLIBC__) || defined(__FreeBSD__) signal(SIGSEGV, qupzilla_signal_handler); #endif // Hack to fix QT_STYLE_OVERRIDE with QProxyStyle const QByteArray style = qgetenv("QT_STYLE_OVERRIDE"); if (!style.isEmpty()) { char** args = (char**) malloc(sizeof(char*) * (argc + 1)); for (int i = 0; i < argc; ++i) args[i] = argv[i]; QString stylecmd = QL1S("-style=") + style; args[argc++] = qstrdup(stylecmd.toUtf8().constData()); argv = args; } QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); MainApplication app(argc, argv); if (app.isClosing()) return 0; app.setStyle(new ProxyStyle); return app.exec(); }
void LocationBar::updateSiteIcon() { QIcon icon = m_webView ? m_webView->icon() : IconProvider::emptyWebIcon(); if (m_webView && m_webView->url().scheme() == QL1S("https")) icon = QIcon::fromTheme(QSL("document-encrypted"), icon); m_siteIcon->setIcon(QIcon(icon.pixmap(16))); }
bool PIM_Handler::keyPress(WebView* view, QKeyEvent* event) { if (!view) { return false; } bool isEnter = event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter; bool isControlModifier = event->modifiers() & Qt::ControlModifier; if (!isEnter || !isControlModifier) { return false; } QString source = QL1S("var inputs = document.getElementsByTagName('input');" "var table = %1;" "for (var i = 0; i < inputs.length; ++i) {" " var input = inputs[i];" " if (input.type != 'text' || input.name == '')" " continue;" " for (var key in table) {" " if (!table.hasOwnProperty(key))" " continue;" " if (key == input.name || input.name.indexOf(key) != -1) {" " input.value = table[key];" " break;" " }" " }" "}"); view->page()->runJavaScript(source.arg(matchingJsTable()), WebPage::SafeJsWorld); return true; }
void PIM_Handler::pageLoadFinished() { WebPage* page = qobject_cast<WebPage*>(sender()); if (!page) { return; } if (!m_loaded) { loadSettings(); } QString source = QL1S("var inputs = document.getElementsByTagName('input');" "var table = %1;" "for (var i = 0; i < inputs.length; ++i) {" " var input = inputs[i];" " if (input.type != 'text' || input.name == '')" " continue;" " for (var key in table) {" " if (!table.hasOwnProperty(key) || table[key] == '')" " continue;" " if (key == input.name || input.name.indexOf(key) != -1) {" " input.style['-webkit-appearance'] = 'none';" " input.style['-webkit-box-shadow'] = 'inset 0 0 2px 1px #EEE000';" " break;" " }" " }" "}"); page->runJavaScript(source.arg(matchingJsTable()), WebPage::SafeJsWorld); }