mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-12-27 08:19:30 +08:00
Web UI code optimization
This commit is contained in:
parent
2036326403
commit
ae692ba9b8
@ -124,7 +124,7 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const {
|
||||
return files;
|
||||
}
|
||||
|
||||
void EventManager::setGlobalPreferences(QVariantMap m) const {
|
||||
void EventManager::setGlobalPreferences(QVariantMap m) {
|
||||
// UI
|
||||
Preferences pref;
|
||||
if(m.contains("locale")) {
|
||||
@ -137,9 +137,10 @@ void EventManager::setGlobalPreferences(QVariantMap m) const {
|
||||
qDebug("%s locale unrecognized, using default (en_GB).", qPrintable(locale));
|
||||
}
|
||||
qApp->installTranslator(translator);
|
||||
}
|
||||
|
||||
pref.setLocale(locale);
|
||||
pref.setLocale(locale);
|
||||
emit localeChanged(locale);
|
||||
}
|
||||
}
|
||||
// Downloads
|
||||
if(m.contains("save_path"))
|
||||
|
@ -54,7 +54,10 @@ public:
|
||||
QList<QVariantMap> getPropTrackersInfo(QString hash) const;
|
||||
QList<QVariantMap> getPropFilesInfo(QString hash) const;
|
||||
QVariantMap getGlobalPreferences() const;
|
||||
void setGlobalPreferences(QVariantMap m) const;
|
||||
void setGlobalPreferences(QVariantMap m);
|
||||
|
||||
signals:
|
||||
void localeChanged(const QString &locale);
|
||||
|
||||
public slots:
|
||||
void addedTorrent(const QTorrentHandle& h);
|
||||
|
@ -56,7 +56,6 @@ using namespace libtorrent;
|
||||
HttpConnection::HttpConnection(QTcpSocket *socket, HttpServer *parent)
|
||||
: QObject(parent), m_socket(socket), m_httpserver(parent)
|
||||
{
|
||||
m_needsTranslation = !Preferences().getLocale().startsWith("en");
|
||||
m_socket->setParent(this);
|
||||
connect(m_socket, SIGNAL(readyRead()), SLOT(read()));
|
||||
connect(m_socket, SIGNAL(disconnected()), SLOT(deleteLater()));
|
||||
@ -121,7 +120,7 @@ void HttpConnection::translateDocument(QString& data) {
|
||||
QByteArray word = regex.cap(1).toLocal8Bit();
|
||||
|
||||
QString translation = word;
|
||||
if (m_needsTranslation) {
|
||||
if (m_httpserver->isTranslationNeeded()) {
|
||||
int context_index = 0;
|
||||
do {
|
||||
translation = qApp->translate(contexts[context_index].c_str(), word.constData(), 0, QCoreApplication::UnicodeUTF8, 1);
|
||||
@ -433,7 +432,6 @@ void HttpConnection::respondCommand(const QString& command) {
|
||||
QString json_str = m_parser.post("json");
|
||||
EventManager* manager = m_httpserver->eventManager();
|
||||
manager->setGlobalPreferences(json::fromJson(json_str));
|
||||
m_needsTranslation = !Preferences().getLocale().startsWith("en");
|
||||
return;
|
||||
}
|
||||
if(command == "setFilePrio") {
|
||||
|
@ -88,7 +88,6 @@ private:
|
||||
HttpServer *m_httpserver;
|
||||
HttpRequestParser m_parser;
|
||||
HttpResponseGenerator m_generator;
|
||||
bool m_needsTranslation;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -97,6 +97,8 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
|
||||
m_username = pref.getWebUiUsername().toLocal8Bit();
|
||||
m_passwordSha1 = pref.getWebUiPassword().toLocal8Bit();
|
||||
m_localAuthEnabled = pref.isWebUiLocalAuthEnabled();
|
||||
m_needsTranslation = !Preferences().getLocale().startsWith("en");
|
||||
connect(m_eventManager, SIGNAL(localeChanged(QString)), SLOT(onLocaleChanged(QString)));
|
||||
|
||||
// HTTPS-related
|
||||
#ifndef QT_NO_OPENSSL
|
||||
@ -337,3 +339,11 @@ void HttpServer::setlocalAuthEnabled(bool enabled) {
|
||||
bool HttpServer::isLocalAuthEnabled() const {
|
||||
return m_localAuthEnabled;
|
||||
}
|
||||
|
||||
bool HttpServer::isTranslationNeeded() {
|
||||
return m_needsTranslation;
|
||||
}
|
||||
|
||||
void HttpServer::onLocaleChanged(const QString &locale) {
|
||||
m_needsTranslation = !locale.startsWith("en");
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ public:
|
||||
int NbFailedAttemptsForIp(const QString& ip) const;
|
||||
void increaseNbFailedAttemptsForIp(const QString& ip);
|
||||
void resetNbFailedAttemptsForIp(const QString& ip);
|
||||
bool isTranslationNeeded();
|
||||
|
||||
#ifndef QT_NO_OPENSSL
|
||||
void enableHttps(const QSslCertificate &certificate, const QSslKey &key);
|
||||
@ -81,6 +82,7 @@ private:
|
||||
private slots:
|
||||
void onTimer();
|
||||
void UnbanTimerEvent();
|
||||
void onLocaleChanged(const QString &locale);
|
||||
|
||||
private:
|
||||
void handleNewConnection(QTcpSocket *socket);
|
||||
@ -92,6 +94,7 @@ private:
|
||||
QTimer m_timer;
|
||||
QHash<QString, int> m_clientFailedAttempts;
|
||||
bool m_localAuthEnabled;
|
||||
bool m_needsTranslation;
|
||||
#ifndef QT_NO_OPENSSL
|
||||
bool m_https;
|
||||
QSslCertificate m_certificate;
|
||||
|
Loading…
Reference in New Issue
Block a user