Rewrite code for returning information about torrents as JSON (Web UI)

- The new code is simpler, cleaner and more efficient
This commit is contained in:
Christophe Dumez
2012-05-26 20:42:44 +03:00
parent fc4989d738
commit 9a964d871d
19 changed files with 825 additions and 412 deletions

View File

@@ -89,7 +89,7 @@ void HttpServer::resetNbFailedAttemptsForIp(const QString& ip) {
m_clientFailedAttempts.remove(ip);
}
HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
HttpServer::HttpServer(QObject* parent) : QTcpServer(parent),
m_eventManager(new EventManager(this)) {
const Preferences pref;
@@ -109,23 +109,6 @@ HttpServer::HttpServer(int msec, QObject* parent) : QTcpServer(parent),
}
#endif
// Add torrents
std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
std::vector<torrent_handle>::iterator torrentIT;
for (torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
QTorrentHandle h = QTorrentHandle(*torrentIT);
if (h.is_valid())
m_eventManager->addedTorrent(h);
}
//connect QBtSession::instance() to manager
connect(QBtSession::instance(), SIGNAL(addedTorrent(QTorrentHandle)), m_eventManager, SLOT(addedTorrent(QTorrentHandle)));
connect(QBtSession::instance(), SIGNAL(deletedTorrent(QString)), m_eventManager, SLOT(deletedTorrent(QString)));
//set timer
connect(&m_timer, SIGNAL(timeout()), SLOT(onTimer()));
m_timer.start(msec);
// Additional translations for Web UI
QString a = tr("File");
a = tr("Edit");
@@ -214,16 +197,6 @@ void HttpServer::handleNewConnection(QTcpSocket *socket)
connect(connection, SIGNAL(resumeAllTorrents()), QBtSession::instance(), SLOT(resumeAllTorrents()));
}
void HttpServer::onTimer() {
std::vector<torrent_handle> torrents = QBtSession::instance()->getTorrents();
std::vector<torrent_handle>::iterator torrentIT;
for (torrentIT = torrents.begin(); torrentIT != torrents.end(); torrentIT++) {
QTorrentHandle h = QTorrentHandle(*torrentIT);
if (h.is_valid())
m_eventManager->modifiedTorrent(h);
}
}
QString HttpServer::generateNonce() const {
QCryptographicHash md5(QCryptographicHash::Md5);
md5.addData(QTime::currentTime().toString("hhmmsszzz").toLocal8Bit());