Browse Source

Web UI code optimization

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
ae692ba9b8
  1. 5
      src/webui/eventmanager.cpp
  2. 5
      src/webui/eventmanager.h
  3. 4
      src/webui/httpconnection.cpp
  4. 1
      src/webui/httpconnection.h
  5. 10
      src/webui/httpserver.cpp
  6. 3
      src/webui/httpserver.h

5
src/webui/eventmanager.cpp

@ -124,7 +124,7 @@ QList<QVariantMap> EventManager::getPropFilesInfo(QString hash) const { @@ -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 { @@ -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);
emit localeChanged(locale);
}
}
// Downloads
if(m.contains("save_path"))

5
src/webui/eventmanager.h

@ -54,7 +54,10 @@ public: @@ -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);

4
src/webui/httpconnection.cpp

@ -56,7 +56,6 @@ using namespace libtorrent; @@ -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) { @@ -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) { @@ -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") {

1
src/webui/httpconnection.h

@ -88,7 +88,6 @@ private: @@ -88,7 +88,6 @@ private:
HttpServer *m_httpserver;
HttpRequestParser m_parser;
HttpResponseGenerator m_generator;
bool m_needsTranslation;
};
#endif

10
src/webui/httpserver.cpp

@ -97,6 +97,8 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent), @@ -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) { @@ -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");
}

3
src/webui/httpserver.h

@ -69,6 +69,7 @@ public: @@ -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: @@ -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: @@ -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…
Cancel
Save