1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-14 02:52:12 +01:00

Show correct default user agent in About dialog

This commit is contained in:
David Rosca 2015-10-15 10:49:11 +02:00
parent 5b82102075
commit 5c40121aa9
3 changed files with 14 additions and 6 deletions

View File

@ -22,6 +22,7 @@
#include "tabbedwebview.h" #include "tabbedwebview.h"
#include "webpage.h" #include "webpage.h"
#include "qtwin.h" #include "qtwin.h"
#include "useragentmanager.h"
#include <QWebEnginePage> #include <QWebEnginePage>
#include <QWebEngineProfile> #include <QWebEngineProfile>
@ -76,7 +77,7 @@ void AboutDialog::showAbout()
m_aboutHtml += QString("<p>&copy; %1 %2<br/>").arg(Qz::COPYRIGHT, Qz::AUTHOR); m_aboutHtml += QString("<p>&copy; %1 %2<br/>").arg(Qz::COPYRIGHT, Qz::AUTHOR);
m_aboutHtml += tr("<small>Build time: %1 </small></p>").arg(Qz::BUILDTIME); m_aboutHtml += tr("<small>Build time: %1 </small></p>").arg(Qz::BUILDTIME);
m_aboutHtml += QString("<p><a href=%1>%1</a></p>").arg(Qz::WWWADDRESS); m_aboutHtml += QString("<p><a href=%1>%1</a></p>").arg(Qz::WWWADDRESS);
m_aboutHtml += "<p>" + mApp->webProfile()->httpUserAgent() + "</p>"; m_aboutHtml += "<p>" + mApp->userAgentManager()->defaultUserAgent() + "</p>";
m_aboutHtml += "</div></center>"; m_aboutHtml += "</div></center>";
} }
ui->textBrowser->setHtml(m_aboutHtml); ui->textBrowser->setHtml(m_aboutHtml);

View File

@ -21,11 +21,14 @@
#include "settings.h" #include "settings.h"
#include <QWebEngineProfile> #include <QWebEngineProfile>
#include <QRegularExpression>
UserAgentManager::UserAgentManager(QObject* parent) UserAgentManager::UserAgentManager(QObject* parent)
: QObject(parent) : QObject(parent)
, m_usePerDomainUserAgent(false) , m_usePerDomainUserAgent(false)
{ {
m_defaultUserAgent = QWebEngineProfile::defaultProfile()->httpUserAgent();
m_defaultUserAgent.replace(QRegularExpression(QSL("QtWebEngine/[^\\s]+")), QSL("QupZilla/%1").arg(Qz::VERSION));
} }
void UserAgentManager::loadSettings() void UserAgentManager::loadSettings()
@ -49,11 +52,7 @@ void UserAgentManager::loadSettings()
} }
} }
QString userAgent = m_globalUserAgent; const QString userAgent = m_globalUserAgent.isEmpty() ? m_defaultUserAgent : m_globalUserAgent;
if (userAgent.isEmpty()) {
userAgent = QWebEngineProfile::defaultProfile()->httpUserAgent();
userAgent.replace(QSL("QtWebEngine/%1").arg(qVersion()), QSL("QupZilla/%1").arg(Qz::VERSION));
}
QWebEngineProfile::defaultProfile()->setHttpUserAgent(userAgent); QWebEngineProfile::defaultProfile()->setHttpUserAgent(userAgent);
} }
@ -79,6 +78,11 @@ QString UserAgentManager::globalUserAgent() const
return m_globalUserAgent; return m_globalUserAgent;
} }
QString UserAgentManager::defaultUserAgent() const
{
return m_defaultUserAgent;
}
bool UserAgentManager::usePerDomainUserAgents() const bool UserAgentManager::usePerDomainUserAgents() const
{ {
return m_usePerDomainUserAgent; return m_usePerDomainUserAgent;

View File

@ -35,13 +35,16 @@ public:
void loadSettings(); void loadSettings();
QString userAgentForUrl(const QUrl &url) const; QString userAgentForUrl(const QUrl &url) const;
QString globalUserAgent() const; QString globalUserAgent() const;
QString defaultUserAgent() const;
bool usePerDomainUserAgents() const; bool usePerDomainUserAgents() const;
QHash<QString, QString> perDomainUserAgentsList() const; QHash<QString, QString> perDomainUserAgentsList() const;
private: private:
QString m_globalUserAgent; QString m_globalUserAgent;
QString m_defaultUserAgent;
bool m_usePerDomainUserAgent; bool m_usePerDomainUserAgent;
QHash<QString, QString> m_userAgentsList; QHash<QString, QString> m_userAgentsList;