Browse Source

Change the code to use the Logger class instead.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
087417c8a6
  1. 35
      src/dnsupdater.cpp
  2. 2
      src/headlessloader.h
  3. 4
      src/mainwindow.cpp
  4. 3
      src/properties/peerlistwidget.cpp
  5. 205
      src/qtlibtorrent/qbtsession.cpp
  6. 27
      src/qtlibtorrent/qbtsession.h
  7. 3
      src/rss/rssfeed.cpp
  8. 5
      src/smtp.cpp
  9. 3
      src/statusbar.cpp
  10. 1
      src/webui/prefjson.cpp

35
src/dnsupdater.cpp

@ -31,11 +31,12 @@
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QDebug> #include <QDebug>
#include <QRegExp> #include <QRegExp>
#include <QStringList>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
#include <QUrlQuery> #include <QUrlQuery>
#endif #endif
#include "dnsupdater.h" #include "dnsupdater.h"
#include "qbtsession.h" #include "logger.h"
DNSUpdater::DNSUpdater(QObject *parent) : DNSUpdater::DNSUpdater(QObject *parent) :
QObject(parent), m_state(OK), m_service(DNS::NONE) QObject(parent), m_state(OK), m_service(DNS::NONE)
@ -183,16 +184,16 @@ void DNSUpdater::ipUpdateFinished(QNetworkReply *reply)
void DNSUpdater::processIPUpdateReply(const QString &reply) void DNSUpdater::processIPUpdateReply(const QString &reply)
{ {
Logger* const logger = Logger::instance();
qDebug() << Q_FUNC_INFO << reply; qDebug() << Q_FUNC_INFO << reply;
QString code = reply.split(" ").first(); QString code = reply.split(" ").first();
qDebug() << Q_FUNC_INFO << "Code:" << code; qDebug() << Q_FUNC_INFO << "Code:" << code;
if (code == "good" || code == "nochg") { if (code == "good" || code == "nochg") {
QBtSession::instance()->addConsoleMessage(tr("Your dynamic DNS was successfully updated."), "green"); logger->addMessage(tr("Your dynamic DNS was successfully updated."), Log::INFO);
return; return;
} }
if (code == "911" || code == "dnserr") { if (code == "911" || code == "dnserr") {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: The service is temporarily unavailable, it will be retried in 30 minutes."), logger->addMessage(tr("Dynamic DNS error: The service is temporarily unavailable, it will be retried in 30 minutes."), Log::CRITICAL);
"red");
m_lastIP.clear(); m_lastIP.clear();
// It will retry in 30 minutes because the timer was not stopped // It will retry in 30 minutes because the timer was not stopped
return; return;
@ -201,31 +202,29 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();
m_lastIP.clear(); m_lastIP.clear();
if (code == "nohost") { if (code == "nohost") {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: hostname supplied does not exist under specified account."), logger->addMessage(tr("Dynamic DNS error: hostname supplied does not exist under specified account."), Log::CRITICAL);
"red");
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
return; return;
} }
if (code == "badauth") { if (code == "badauth") {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: Invalid username/password."), "red"); logger->addMessage(tr("Dynamic DNS error: Invalid username/password."), Log::CRITICAL);
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
return; return;
} }
if (code == "badagent") { if (code == "badagent") {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: qBittorrent was blacklisted by the service, please report a bug at http://bugs.qbittorrent.org."), logger->addMessage(tr("Dynamic DNS error: qBittorrent was blacklisted by the service, please report a bug at http://bugs.qbittorrent.org."),
"red"); Log::CRITICAL);
m_state = FATAL; m_state = FATAL;
return; return;
} }
if (code == "!donator") { if (code == "!donator") {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: %1 was returned by the service, please report a bug at http://bugs.qbittorrent.org.").arg("!donator"), logger->addMessage(tr("Dynamic DNS error: %1 was returned by the service, please report a bug at http://bugs.qbittorrent.org.").arg("!donator"),
"red"); Log::CRITICAL);
m_state = FATAL; m_state = FATAL;
return; return;
} }
if (code == "abuse") { if (code == "abuse") {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: Your username was blocked due to abuse."), logger->addMessage(tr("Dynamic DNS error: Your username was blocked due to abuse."), Log::CRITICAL);
"red");
m_state = FATAL; m_state = FATAL;
return; return;
} }
@ -235,6 +234,7 @@ void DNSUpdater::updateCredentials()
{ {
if (m_state == FATAL) return; if (m_state == FATAL) return;
Preferences* const pref = Preferences::instance(); Preferences* const pref = Preferences::instance();
Logger* const logger = Logger::instance();
bool change = false; bool change = false;
// Get DNS service information // Get DNS service information
if (m_service != pref->getDynDNSService()) { if (m_service != pref->getDynDNSService()) {
@ -245,8 +245,7 @@ void DNSUpdater::updateCredentials()
m_domain = pref->getDynDomainName(); m_domain = pref->getDynDomainName();
QRegExp domain_regex("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$"); QRegExp domain_regex("^(?:(?!\\d|-)[a-zA-Z0-9\\-]{1,63}\\.)+[a-zA-Z]{2,}$");
if (domain_regex.indexIn(m_domain) < 0) { if (domain_regex.indexIn(m_domain) < 0) {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: supplied domain name is invalid."), logger->addMessage(tr("Dynamic DNS error: supplied domain name is invalid."), Log::CRITICAL);
"red");
m_lastIP.clear(); m_lastIP.clear();
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
@ -257,8 +256,7 @@ void DNSUpdater::updateCredentials()
if (m_username != pref->getDynDNSUsername()) { if (m_username != pref->getDynDNSUsername()) {
m_username = pref->getDynDNSUsername(); m_username = pref->getDynDNSUsername();
if (m_username.length() < 4) { if (m_username.length() < 4) {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: supplied username is too short."), logger->addMessage(tr("Dynamic DNS error: supplied username is too short."), Log::CRITICAL);
"red");
m_lastIP.clear(); m_lastIP.clear();
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();
m_state = INVALID_CREDS; m_state = INVALID_CREDS;
@ -269,8 +267,7 @@ void DNSUpdater::updateCredentials()
if (m_password != pref->getDynDNSPassword()) { if (m_password != pref->getDynDNSPassword()) {
m_password = pref->getDynDNSPassword(); m_password = pref->getDynDNSPassword();
if (m_password.length() < 4) { if (m_password.length() < 4) {
QBtSession::instance()->addConsoleMessage(tr("Dynamic DNS error: supplied password is too short."), logger->addMessage(tr("Dynamic DNS error: supplied password is too short."), Log::CRITICAL);
"red");
m_lastIP.clear(); m_lastIP.clear();
m_ipCheckTimer.stop(); m_ipCheckTimer.stop();
m_state = INVALID_CREDS; m_state = INVALID_CREDS;

2
src/headlessloader.h

@ -38,6 +38,7 @@
#include "qbtsession.h" #include "qbtsession.h"
#include "fs_utils.h" #include "fs_utils.h"
#include "misc.h" #include "misc.h"
#include "logger.h"
class HeadlessLoader: public QObject { class HeadlessLoader: public QObject {
Q_OBJECT Q_OBJECT
@ -69,6 +70,7 @@ public slots:
void shutdownCleanUp() { void shutdownCleanUp() {
QBtSession::drop(); QBtSession::drop();
Preferences::drop(); Preferences::drop();
Logger::drop();
} }
// Call this function to exit qBittorrent headless loader // Call this function to exit qBittorrent headless loader

4
src/mainwindow.cpp

@ -72,6 +72,7 @@
#include "torrentmodel.h" #include "torrentmodel.h"
#include "executionlog.h" #include "executionlog.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "logger.h"
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include "autoexpandabledialog.h" #include "autoexpandabledialog.h"
#endif #endif
@ -506,6 +507,7 @@ void MainWindow::shutdownCleanUp()
delete toolbarMenu; delete toolbarMenu;
IconProvider::drop(); IconProvider::drop();
Preferences::drop(); Preferences::drop();
Logger::drop();
qDebug("Finished GUI destruction"); qDebug("Finished GUI destruction");
} }
@ -1181,7 +1183,7 @@ void MainWindow::optionsSaved()
// Load program preferences // Load program preferences
void MainWindow::loadPreferences(bool configure_session) void MainWindow::loadPreferences(bool configure_session)
{ {
QBtSession::instance()->addConsoleMessage(tr("Options were saved successfully.")); Logger::instance()->addMessage(tr("Options were saved successfully."));
const Preferences* const pref = Preferences::instance(); const Preferences* const pref = Preferences::instance();
const bool newSystrayIntegration = pref->systrayIntegration(); const bool newSystrayIntegration = pref->systrayIntegration();
actionLock_qBittorrent->setVisible(newSystrayIntegration); actionLock_qBittorrent->setVisible(newSystrayIntegration);

3
src/properties/peerlistwidget.cpp

@ -39,6 +39,7 @@
#include "speedlimitdlg.h" #include "speedlimitdlg.h"
#include "iconprovider.h" #include "iconprovider.h"
#include "qtorrenthandle.h" #include "qtorrenthandle.h"
#include "logger.h"
#include <QStandardItemModel> #include <QStandardItemModel>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QSet> #include <QSet>
@ -232,7 +233,7 @@ void PeerListWidget::banSelectedPeers(const QStringList& peer_ips)
foreach (const QString &ip, peer_ips) { foreach (const QString &ip, peer_ips) {
qDebug("Banning peer %s...", ip.toLocal8Bit().data()); qDebug("Banning peer %s...", ip.toLocal8Bit().data());
QBtSession::instance()->addConsoleMessage(tr("Manually banning peer %1...").arg(ip)); Logger::instance()->addMessage(tr("Manually banning peer %1...").arg(ip));
QBtSession::instance()->banIP(ip); QBtSession::instance()->banIP(ip);
} }
// Refresh list // Refresh list

205
src/qtlibtorrent/qbtsession.cpp

@ -36,6 +36,7 @@
#include <QHostAddress> #include <QHostAddress>
#include <QNetworkAddressEntry> #include <QNetworkAddressEntry>
#include <QProcess> #include <QProcess>
#include <QCoreApplication>
#include "smtp.h" #include "smtp.h"
#include "filesystemwatcher.h" #include "filesystemwatcher.h"
@ -50,6 +51,7 @@
#include "preferences.h" #include "preferences.h"
#include "scannedfoldersmodel.h" #include "scannedfoldersmodel.h"
#include "qtracker.h" #include "qtracker.h"
#include "logger.h"
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
#include "shutdownconfirm.h" #include "shutdownconfirm.h"
#include "geoipmanager.h" #include "geoipmanager.h"
@ -132,7 +134,7 @@ QBtSession::QBtSession()
// Construct session // Construct session
s = new session(fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)), 0); s = new session(fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)), 0);
//std::cout << "Peer ID: " << fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string() << std::endl; //std::cout << "Peer ID: " << fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string() << std::endl;
addConsoleMessage("Peer ID: "+misc::toQString(fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string())); Logger::instance()->addMessage("Peer ID: "+misc::toQString(fingerprint(peer_id.toLocal8Bit().constData(), version.at(0), version.at(1), version.at(2), version.at(3)).to_string()));
// Set severity level of libtorrent session // Set severity level of libtorrent session
s->set_alert_mask(alert::error_notification | alert::peer_notification | alert::port_mapping_notification | alert::storage_notification | alert::tracker_notification | alert::status_notification | alert::ip_block_notification | alert::progress_notification | alert::stats_notification); s->set_alert_mask(alert::error_notification | alert::peer_notification | alert::port_mapping_notification | alert::storage_notification | alert::tracker_notification | alert::status_notification | alert::ip_block_notification | alert::progress_notification | alert::stats_notification);
@ -233,15 +235,16 @@ void QBtSession::processBigRatios() {
qDebug("Ratio: %f (limit: %f)", ratio, ratio_limit); qDebug("Ratio: %f (limit: %f)", ratio, ratio_limit);
Q_ASSERT(ratio_limit >= 0.f); Q_ASSERT(ratio_limit >= 0.f);
if (ratio <= MAX_RATIO && ratio >= ratio_limit) { if (ratio <= MAX_RATIO && ratio >= ratio_limit) {
Logger* const logger = Logger::instance();
if (high_ratio_action == REMOVE_ACTION) { if (high_ratio_action == REMOVE_ACTION) {
addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(h.name())); logger->addMessage(tr("%1 reached the maximum ratio you set.").arg(h.name()));
addConsoleMessage(tr("Removing torrent %1...").arg(h.name())); logger->addMessage(tr("Removing torrent %1...").arg(h.name()));
deleteTorrent(hash); deleteTorrent(hash);
} else { } else {
// Pause it // Pause it
if (!h.is_paused()) { if (!h.is_paused()) {
addConsoleMessage(tr("%1 reached the maximum ratio you set.").arg(h.name())); logger->addMessage(tr("%1 reached the maximum ratio you set.").arg(h.name()));
addConsoleMessage(tr("Pausing torrent %1...").arg(h.name())); logger->addMessage(tr("Pausing torrent %1...").arg(h.name()));
pauseTorrent(hash); pauseTorrent(hash);
} }
} }
@ -408,18 +411,19 @@ void QBtSession::configureSession() {
} }
#endif #endif
// * UPnP / NAT-PMP // * UPnP / NAT-PMP
Logger* const logger = Logger::instance();
if (pref->isUPnPEnabled()) { if (pref->isUPnPEnabled()) {
enableUPnP(true); enableUPnP(true);
addConsoleMessage(tr("UPnP / NAT-PMP support [ON]"), QString::fromUtf8("blue")); logger->addMessage(tr("UPnP / NAT-PMP support [ON]"), Log::INFO);
} else { } else {
enableUPnP(false); enableUPnP(false);
addConsoleMessage(tr("UPnP / NAT-PMP support [OFF]"), QString::fromUtf8("blue")); logger->addMessage(tr("UPnP / NAT-PMP support [OFF]"), Log::INFO);
} }
// * Session settings // * Session settings
session_settings sessionSettings = s->settings(); session_settings sessionSettings = s->settings();
sessionSettings.user_agent = "qBittorrent "VERSION; sessionSettings.user_agent = "qBittorrent "VERSION;
//std::cout << "HTTP user agent is " << sessionSettings.user_agent << std::endl; //std::cout << "HTTP user agent is " << sessionSettings.user_agent << std::endl;
addConsoleMessage(tr("HTTP user agent is %1").arg(misc::toQString(sessionSettings.user_agent))); logger->addMessage(tr("HTTP user agent is %1").arg(misc::toQString(sessionSettings.user_agent)));
sessionSettings.upnp_ignore_nonrouters = true; sessionSettings.upnp_ignore_nonrouters = true;
sessionSettings.use_dht_as_fallback = false; sessionSettings.use_dht_as_fallback = false;
@ -445,9 +449,9 @@ void QBtSession::configureSession() {
resumeDataTimer.setInterval(pref->saveResumeDataInterval() * 60 * 1000); resumeDataTimer.setInterval(pref->saveResumeDataInterval() * 60 * 1000);
sessionSettings.anonymous_mode = pref->isAnonymousModeEnabled(); sessionSettings.anonymous_mode = pref->isAnonymousModeEnabled();
if (sessionSettings.anonymous_mode) { if (sessionSettings.anonymous_mode) {
addConsoleMessage(tr("Anonymous mode [ON]"), "blue"); logger->addMessage(tr("Anonymous mode [ON]"), Log::INFO);
} else { } else {
addConsoleMessage(tr("Anonymous mode [OFF]"), "blue"); logger->addMessage(tr("Anonymous mode [OFF]"), Log::INFO);
} }
// Queueing System // Queueing System
if (pref->isQueueingSystemEnabled()) { if (pref->isQueueingSystemEnabled()) {
@ -530,20 +534,20 @@ void QBtSession::configureSession() {
enableDHT(pref->isDHTEnabled()); enableDHT(pref->isDHTEnabled());
// * PeX // * PeX
if (PeXEnabled) { if (PeXEnabled) {
addConsoleMessage(tr("PeX support [ON]"), QString::fromUtf8("blue")); logger->addMessage(tr("PeX support [ON]"), Log::INFO);
} else { } else {
addConsoleMessage(tr("PeX support [OFF]"), QString::fromUtf8("red")); logger->addMessage(tr("PeX support [OFF]"), Log::CRITICAL);
} }
if (PeXEnabled != pref->isPeXEnabled()) { if (PeXEnabled != pref->isPeXEnabled()) {
addConsoleMessage(tr("Restart is required to toggle PeX support"), QString::fromUtf8("red")); logger->addMessage(tr("Restart is required to toggle PeX support"), Log::CRITICAL);
} }
// * LSD // * LSD
if (pref->isLSDEnabled()) { if (pref->isLSDEnabled()) {
enableLSD(true); enableLSD(true);
addConsoleMessage(tr("Local Peer Discovery support [ON]"), QString::fromUtf8("blue")); logger->addMessage(tr("Local Peer Discovery support [ON]"), Log::INFO);
} else { } else {
enableLSD(false); enableLSD(false);
addConsoleMessage(tr("Local Peer Discovery support [OFF]"), QString::fromUtf8("blue")); logger->addMessage(tr("Local Peer Discovery support [OFF]"), Log::INFO);
} }
// * Encryption // * Encryption
const int encryptionState = pref->getEncryptionSetting(); const int encryptionState = pref->getEncryptionSetting();
@ -555,17 +559,17 @@ void QBtSession::configureSession() {
case 0: //Enabled case 0: //Enabled
encryptionSettings.out_enc_policy = pe_settings::enabled; encryptionSettings.out_enc_policy = pe_settings::enabled;
encryptionSettings.in_enc_policy = pe_settings::enabled; encryptionSettings.in_enc_policy = pe_settings::enabled;
addConsoleMessage(tr("Encryption support [ON]"), QString::fromUtf8("blue")); logger->addMessage(tr("Encryption support [ON]"), Log::INFO);
break; break;
case 1: // Forced case 1: // Forced
encryptionSettings.out_enc_policy = pe_settings::forced; encryptionSettings.out_enc_policy = pe_settings::forced;
encryptionSettings.in_enc_policy = pe_settings::forced; encryptionSettings.in_enc_policy = pe_settings::forced;
addConsoleMessage(tr("Encryption support [FORCED]"), QString::fromUtf8("blue")); logger->addMessage(tr("Encryption support [FORCED]"), Log::INFO);
break; break;
default: // Disabled default: // Disabled
encryptionSettings.out_enc_policy = pe_settings::disabled; encryptionSettings.out_enc_policy = pe_settings::disabled;
encryptionSettings.in_enc_policy = pe_settings::disabled; encryptionSettings.in_enc_policy = pe_settings::disabled;
addConsoleMessage(tr("Encryption support [OFF]"), QString::fromUtf8("blue")); logger->addMessage(tr("Encryption support [OFF]"), Log::INFO);
} }
applyEncryptionSettings(encryptionSettings); applyEncryptionSettings(encryptionSettings);
// * Maximum ratio // * Maximum ratio
@ -627,12 +631,12 @@ void QBtSession::configureSession() {
m_tracker = new QTracker(this); m_tracker = new QTracker(this);
} }
if (m_tracker->start()) { if (m_tracker->start()) {
addConsoleMessage(tr("Embedded Tracker [ON]"), QString::fromUtf8("blue")); logger->addMessage(tr("Embedded Tracker [ON]"), Log::INFO);
} else { } else {
addConsoleMessage(tr("Failed to start the embedded tracker!"), QString::fromUtf8("red")); logger->addMessage(tr("Failed to start the embedded tracker!"), Log::CRITICAL);
} }
} else { } else {
addConsoleMessage(tr("Embedded Tracker [OFF]")); logger->addMessage(tr("Embedded Tracker [OFF]"));
if (m_tracker) if (m_tracker)
delete m_tracker; delete m_tracker;
} }
@ -680,11 +684,12 @@ void QBtSession::initWebUi() {
#endif #endif
if (!httpServer->isListening()) { if (!httpServer->isListening()) {
Logger* const logger = Logger::instance();
bool success = httpServer->listen(QHostAddress::Any, port); bool success = httpServer->listen(QHostAddress::Any, port);
if (success) if (success)
addConsoleMessage(tr("The Web UI is listening on port %1").arg(port)); logger->addMessage(tr("The Web UI is listening on port %1").arg(port));
else else
addConsoleMessage(tr("Web User Interface Error - Unable to bind Web UI to port %1").arg(port), "red"); logger->addMessage(tr("Web User Interface Error - Unable to bind Web UI to port %1").arg(port), Log::CRITICAL);
} }
// DynDNS // DynDNS
if (pref->isDynDNSEnabled()) { if (pref->isDynDNSEnabled()) {
@ -831,9 +836,9 @@ void QBtSession::deleteTorrent(const QString &hash, bool delete_local_files) {
// Remove tracker errors // Remove tracker errors
trackersInfos.remove(hash); trackersInfos.remove(hash);
if (delete_local_files) if (delete_local_files)
addConsoleMessage(tr("'%1' was removed from transfer list and hard disk.", "'xxx.avi' was removed...").arg(fileName)); Logger::instance()->addMessage(tr("'%1' was removed from transfer list and hard disk.", "'xxx.avi' was removed...").arg(fileName));
else else
addConsoleMessage(tr("'%1' was removed from transfer list.", "'xxx.avi' was removed...").arg(fileName)); Logger::instance()->addMessage(tr("'%1' was removed from transfer list.", "'xxx.avi' was removed...").arg(fileName));
qDebug("Torrent deleted."); qDebug("Torrent deleted.");
} }
@ -923,18 +928,19 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
Q_UNUSED(fromScanDir); Q_UNUSED(fromScanDir);
Q_UNUSED(filePath); Q_UNUSED(filePath);
Preferences* const pref = Preferences::instance(); Preferences* const pref = Preferences::instance();
Logger* const logger = Logger::instance();
QTorrentHandle h; QTorrentHandle h;
add_torrent_params p; add_torrent_params p;
libtorrent::error_code ec; libtorrent::error_code ec;
libtorrent::parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec); libtorrent::parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec);
if (ec) { if (ec) {
addConsoleMessage(tr("Couldn't parse this Magnet URI: '%1'").arg(magnet_uri)); logger->addMessage(tr("Couldn't parse this Magnet URI: '%1'").arg(magnet_uri));
return h; return h;
} }
const QString hash(misc::toQString(p.info_hash)); const QString hash(misc::toQString(p.info_hash));
if (hash.isEmpty()) { if (hash.isEmpty()) {
addConsoleMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri)); logger->addMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri));
return h; return h;
} }
const QDir torrentBackup(fsutils::BTBackupLocation()); const QDir torrentBackup(fsutils::BTBackupLocation());
@ -953,7 +959,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
QTorrentHandle h_ex = QTorrentHandle(s->find_torrent(p.info_hash)); QTorrentHandle h_ex = QTorrentHandle(s->find_torrent(p.info_hash));
if (h_ex.is_valid()) { if (h_ex.is_valid()) {
qDebug("/!\\ Torrent is already in download list"); qDebug("/!\\ Torrent is already in download list");
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri)); logger->addMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri));
// Check if the torrent contains trackers or url seeds we don't know about // Check if the torrent contains trackers or url seeds we don't know about
// and add them // and add them
mergeTorrents(h_ex, magnet_uri); mergeTorrents(h_ex, magnet_uri);
@ -1036,7 +1042,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
h.resume(); h.resume();
} }
// Send torrent addition signal // Send torrent addition signal
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(magnet_uri)); logger->addMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(magnet_uri));
if (!HiddenData::hasData(hash)) if (!HiddenData::hasData(hash))
emit addedTorrent(h); emit addedTorrent(h);
@ -1047,6 +1053,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed, bool imported) { QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString from_url, bool resumed, bool imported) {
QTorrentHandle h; QTorrentHandle h;
Preferences* const pref = Preferences::instance(); Preferences* const pref = Preferences::instance();
Logger* const logger = Logger::instance();
// Check if BT_backup directory exists // Check if BT_backup directory exists
const QDir torrentBackup(fsutils::BTBackupLocation()); const QDir torrentBackup(fsutils::BTBackupLocation());
@ -1084,15 +1091,15 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
throw std::exception(); throw std::exception();
} catch(std::exception& e) { } catch(std::exception& e) {
if (!from_url.isNull()) { if (!from_url.isNull()) {
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), QString::fromUtf8("red")); logger->addMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(from_url), Log::CRITICAL);
addConsoleMessage(misc::toQStringU(e.what()), "red"); logger->addMessage(misc::toQStringU(e.what()), Log::CRITICAL);
//emit invalidTorrent(from_url); //emit invalidTorrent(from_url);
fsutils::forceRemove(path); fsutils::forceRemove(path);
}else{ }else{
addConsoleMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(fsutils::toNativePath(path)), QString::fromUtf8("red")); logger->addMessage(tr("Unable to decode torrent file: '%1'", "e.g: Unable to decode torrent file: '/home/y/xxx.torrent'").arg(fsutils::toNativePath(path)), Log::CRITICAL);
//emit invalidTorrent(path); //emit invalidTorrent(path);
} }
addConsoleMessage(tr("This file is either corrupted or this isn't a torrent."),QString::fromUtf8("red")); logger->addMessage(tr("This file is either corrupted or this isn't a torrent."), Log::CRITICAL);
if (fromScanDir) { if (fromScanDir) {
// Remove file // Remove file
fsutils::forceRemove(path); fsutils::forceRemove(path);
@ -1110,9 +1117,9 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
qDebug("/!\\ Torrent is already in download list"); qDebug("/!\\ Torrent is already in download list");
// Update info Bar // Update info Bar
if (!from_url.isNull()) { if (!from_url.isNull()) {
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url)); logger->addMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(from_url));
}else{ }else{
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(fsutils::toNativePath(path))); logger->addMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(fsutils::toNativePath(path)));
} }
// Check if the torrent contains trackers or url seeds we don't know about // Check if the torrent contains trackers or url seeds we don't know about
// and add them // and add them
@ -1127,7 +1134,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
// Check number of files // Check number of files
if (t->num_files() < 1) { if (t->num_files() < 1) {
addConsoleMessage(tr("Error: The torrent %1 does not contain any file.").arg(misc::toQStringU(t->name()))); logger->addMessage(tr("Error: The torrent %1 does not contain any file.").arg(misc::toQStringU(t->name())));
// Delete file if temporary // Delete file if temporary
if (!from_url.isNull() || fromScanDir) if (!from_url.isNull() || fromScanDir)
fsutils::forceRemove(path); fsutils::forceRemove(path);
@ -1232,14 +1239,14 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
// Display console message // Display console message
if (!from_url.isNull()) { if (!from_url.isNull()) {
if (fastResume) if (fastResume)
addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(from_url)); logger->addMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(from_url));
else else
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(from_url)); logger->addMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(from_url));
}else{ }else{
if (fastResume) if (fastResume)
addConsoleMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(fsutils::toNativePath(path))); logger->addMessage(tr("'%1' resumed. (fast resume)", "'/home/y/xxx.torrent' was resumed. (fast resume)").arg(fsutils::toNativePath(path)));
else else
addConsoleMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(fsutils::toNativePath(path))); logger->addMessage(tr("'%1' added to download list.", "'/home/y/xxx.torrent' was added to download list.").arg(fsutils::toNativePath(path)));
} }
// Send torrent addition signal // Send torrent addition signal
@ -1358,7 +1365,7 @@ void QBtSession::mergeTorrents(QTorrentHandle& h_ex, const QString& magnet_uri)
} }
} }
if (trackers_added) if (trackers_added)
addConsoleMessage(tr("Note: new trackers were added to the existing torrent.")); Logger::instance()->addMessage(tr("Note: new trackers were added to the existing torrent."));
} }
void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torrent_info> t) { void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torrent_info> t) {
@ -1385,8 +1392,9 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren
} }
} }
Logger* const logger = Logger::instance();
if (trackers_added) if (trackers_added)
addConsoleMessage(tr("Note: new trackers were added to the existing torrent.")); logger->addMessage(tr("Note: new trackers were added to the existing torrent."));
bool urlseeds_added = false; bool urlseeds_added = false;
const QStringList old_urlseeds = h_ex.url_seeds(); const QStringList old_urlseeds = h_ex.url_seeds();
@ -1402,7 +1410,7 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren
} }
} }
if (urlseeds_added) if (urlseeds_added)
addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent.")); logger->addMessage(tr("Note: new URL seeds were added to the existing torrent."));
} }
void QBtSession::exportTorrentFiles(QString path) { void QBtSession::exportTorrentFiles(QString path) {
@ -1557,6 +1565,7 @@ void QBtSession::saveSessionState() {
// Enable DHT // Enable DHT
void QBtSession::enableDHT(bool b) { void QBtSession::enableDHT(bool b) {
Logger* const logger = Logger::instance();
if (b) { if (b) {
if (!DHTEnabled) { if (!DHTEnabled) {
try { try {
@ -1568,12 +1577,12 @@ void QBtSession::enableDHT(bool b) {
s->add_dht_router(std::make_pair(std::string("dht.transmissionbt.com"), 6881)); s->add_dht_router(std::make_pair(std::string("dht.transmissionbt.com"), 6881));
s->add_dht_router(std::make_pair(std::string("dht.aelitis.com"), 6881)); // Vuze s->add_dht_router(std::make_pair(std::string("dht.aelitis.com"), 6881)); // Vuze
DHTEnabled = true; DHTEnabled = true;
addConsoleMessage(tr("DHT support [ON]"), QString::fromUtf8("blue")); logger->addMessage(tr("DHT support [ON]"), Log::INFO);
qDebug("DHT enabled"); qDebug("DHT enabled");
} }
catch(std::exception &e) { catch(std::exception &e) {
qDebug("Could not enable DHT, reason: %s", e.what()); qDebug("Could not enable DHT, reason: %s", e.what());
addConsoleMessage(tr("DHT support [OFF]. Reason: %1").arg(misc::toQStringU(e.what())), QString::fromUtf8("red")); logger->addMessage(tr("DHT support [OFF]. Reason: %1").arg(misc::toQStringU(e.what())), Log::CRITICAL);
} }
} }
} }
@ -1581,7 +1590,7 @@ void QBtSession::enableDHT(bool b) {
if (DHTEnabled) { if (DHTEnabled) {
DHTEnabled = false; DHTEnabled = false;
s->stop_dht(); s->stop_dht();
addConsoleMessage(tr("DHT support [OFF]"), QString::fromUtf8("blue")); logger->addMessage(tr("DHT support [OFF]"), Log::INFO);
qDebug("DHT disabled"); qDebug("DHT disabled");
} }
} }
@ -1725,42 +1734,6 @@ void QBtSession::saveFastResumeData() {
} }
} }
#ifdef DISABLE_GUI
void QBtSession::addConsoleMessage(QString msg, QString) {
emit newConsoleMessage(QDateTime::currentDateTime().toString("dd/MM/yyyy hh:mm:ss") + " - " + msg);
#else
void QBtSession::addConsoleMessage(QString msg, QColor color) {
if (consoleMessages.size() > MAX_LOG_MESSAGES) {
consoleMessages.removeFirst();
}
msg = "<font color='grey'>"+ QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + "</font> - <font color='" + color.name() + "'>" + msg + "</font>";
consoleMessages.append(msg);
emit newConsoleMessage(msg);
#endif
}
#if LIBTORRENT_VERSION_NUM < 10000
void QBtSession::addPeerBanMessage(const QString& ip, bool blocked)
#else
void QBtSession::addPeerBanMessage(const QString& ip, bool blocked, const QString& blockedReason)
#endif
{
if (peerBanMessages.size() > MAX_LOG_MESSAGES) {
peerBanMessages.removeFirst();
}
QString msg;
if (blocked)
#if LIBTORRENT_VERSION_NUM < 10000
msg = "<font color='grey'>" + QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + "</font> - " + tr("<font color='red'>%1</font> was blocked", "x.y.z.w was blocked").arg(ip);
#else
msg = "<font color='grey'>" + QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + "</font> - " + tr("<font color='red'>%1</font> was blocked %2", "x.y.z.w was blocked").arg(ip).arg(blockedReason);
#endif
else
msg = "<font color='grey'>" + QDateTime::currentDateTime().toString(QString::fromUtf8("dd/MM/yyyy hh:mm:ss")) + "</font> - " + tr("<font color='red'>%1</font> was banned", "x.y.z.w was banned").arg(ip);
peerBanMessages.append(msg);
emit newBanMessage(msg);
}
bool QBtSession::isFilePreviewPossible(const QString &hash) const { bool QBtSession::isFilePreviewPossible(const QString &hash) const {
// See if there are supported files in the torrent // See if there are supported files in the torrent
const QTorrentHandle h = getTorrentHandle(hash); const QTorrentHandle h = getTorrentHandle(hash);
@ -1939,19 +1912,20 @@ void QBtSession::setAppendqBExtension(bool append) {
void QBtSession::setListeningPort(int port) { void QBtSession::setListeningPort(int port) {
qDebug() << Q_FUNC_INFO << port; qDebug() << Q_FUNC_INFO << port;
Preferences* const pref = Preferences::instance(); Preferences* const pref = Preferences::instance();
Logger* const logger = Logger::instance();
std::pair<int,int> ports(port, port); std::pair<int,int> ports(port, port);
libtorrent::error_code ec; libtorrent::error_code ec;
const QString iface_name = pref->getNetworkInterface(); const QString iface_name = pref->getNetworkInterface();
const bool listen_ipv6 = pref->getListenIPv6(); const bool listen_ipv6 = pref->getListenIPv6();
if (iface_name.isEmpty()) { if (iface_name.isEmpty()) {
addConsoleMessage(tr("qBittorrent is trying to listen on any interface port: %1", "e.g: qBittorrent is trying to listen on any interface port: TCP/6881").arg(QString::number(port)), "blue"); logger->addMessage(tr("qBittorrent is trying to listen on any interface port: %1", "e.g: qBittorrent is trying to listen on any interface port: TCP/6881").arg(QString::number(port)), Log::INFO);
if (listen_ipv6) if (listen_ipv6)
s->listen_on(ports, ec, "::", session::listen_no_system_port); s->listen_on(ports, ec, "::", session::listen_no_system_port);
else else
s->listen_on(ports, ec, "0.0.0.0", session::listen_no_system_port); s->listen_on(ports, ec, "0.0.0.0", session::listen_no_system_port);
if (ec) if (ec)
addConsoleMessage(tr("qBittorrent failed to listen on any interface port: %1. Reason: %2", "e.g: qBittorrent failed to listen on any interface port: TCP/6881. Reason: no such interface" ).arg(QString::number(port)).arg(misc::toQStringU(ec.message())), "red"); logger->addMessage(tr("qBittorrent failed to listen on any interface port: %1. Reason: %2", "e.g: qBittorrent failed to listen on any interface port: TCP/6881. Reason: no such interface" ).arg(QString::number(port)).arg(misc::toQStringU(ec.message())), Log::CRITICAL);
return; return;
} }
@ -1959,7 +1933,7 @@ void QBtSession::setListeningPort(int port) {
const QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name); const QNetworkInterface network_iface = QNetworkInterface::interfaceFromName(iface_name);
if (!network_iface.isValid()) { if (!network_iface.isValid()) {
qDebug("Invalid network interface: %s", qPrintable(iface_name)); qDebug("Invalid network interface: %s", qPrintable(iface_name));
addConsoleMessage(tr("The network interface defined is invalid: %1").arg(iface_name), "red"); logger->addMessage(tr("The network interface defined is invalid: %1").arg(iface_name), Log::CRITICAL);
return; return;
} }
QString ip; QString ip;
@ -1972,11 +1946,11 @@ void QBtSession::setListeningPort(int port) {
s->listen_on(ports, ec, entry.ip().toString().toLatin1().constData(), session::listen_no_system_port); s->listen_on(ports, ec, entry.ip().toString().toLatin1().constData(), session::listen_no_system_port);
if (!ec) { if (!ec) {
ip = entry.ip().toString(); ip = entry.ip().toString();
addConsoleMessage(tr("qBittorrent is trying to listen on interface %1 port: %2", "e.g: qBittorrent is trying to listen on interface 192.168.0.1 port: TCP/6881").arg(ip).arg(QString::number(port)), "blue"); logger->addMessage(tr("qBittorrent is trying to listen on interface %1 port: %2", "e.g: qBittorrent is trying to listen on interface 192.168.0.1 port: TCP/6881").arg(ip).arg(QString::number(port)), Log::INFO);
return; return;
} }
} }
addConsoleMessage(tr("qBittorrent didn't find an %1 local address to listen on", "qBittorrent didn't find an IPv4 local address to listen on").arg(listen_ipv6 ? "IPv6" : "IPv4"), "red"); logger->addMessage(tr("qBittorrent didn't find an %1 local address to listen on", "qBittorrent didn't find an IPv4 local address to listen on").arg(listen_ipv6 ? "IPv6" : "IPv4"), Log::CRITICAL);
} }
// Set download rate limit // Set download rate limit
@ -2084,7 +2058,7 @@ void QBtSession::recursiveTorrentDownload(const QTorrentHandle &h)
for (int i=0; i<h.num_files(); ++i) { for (int i=0; i<h.num_files(); ++i) {
const QString torrent_relpath = h.filepath_at(i); const QString torrent_relpath = h.filepath_at(i);
if (torrent_relpath.endsWith(".torrent")) { if (torrent_relpath.endsWith(".torrent")) {
addConsoleMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(fsutils::toNativePath(torrent_relpath)).arg(h.name())); Logger::instance()->addMessage(tr("Recursive download of file %1 embedded in torrent %2", "Recursive download of test.torrent embedded in torrent test2").arg(fsutils::toNativePath(torrent_relpath)).arg(h.name()));
const QString torrent_fullpath = h.save_path()+"/"+torrent_relpath; const QString torrent_fullpath = h.save_path()+"/"+torrent_relpath;
std::vector<char> buffer; std::vector<char> buffer;
@ -2266,7 +2240,7 @@ void QBtSession::handleTorrentFinishedAlert(libtorrent::torrent_finished_alert*
} }
catch(std::exception&) { catch(std::exception&) {
qDebug("Caught error loading torrent"); qDebug("Caught error loading torrent");
addConsoleMessage(tr("Unable to decode %1 torrent file.").arg(fsutils::toNativePath(torrent_fullpath)), QString::fromUtf8("red")); Logger::instance()->addMessage(tr("Unable to decode %1 torrent file.").arg(fsutils::toNativePath(torrent_fullpath)), Log::CRITICAL);
} }
} }
} }
@ -2474,12 +2448,13 @@ void QBtSession::handleStorageMovedFailedAlert(libtorrent::storage_moved_failed_
return; return;
} }
addConsoleMessage(tr("Could not move torrent: '%1'. Reason: %2").arg(h.name()).arg(misc::toQStringU(p->message())), "red"); Logger* const logger = Logger::instance();
logger->addMessage(tr("Could not move torrent: '%1'. Reason: %2").arg(h.name()).arg(misc::toQStringU(p->message())), Log::CRITICAL);
QString queued = TorrentTempData::getQueuedPath(hash); QString queued = TorrentTempData::getQueuedPath(hash);
if (!queued.isEmpty()) { if (!queued.isEmpty()) {
TorrentTempData::finishMove(hash); TorrentTempData::finishMove(hash);
addConsoleMessage(tr("Attempting to move torrent: '%1' to path: '%2'.").arg(h.name()).arg(fsutils::toNativePath(queued))); logger->addMessage(tr("Attempting to move torrent: '%1' to path: '%2'.").arg(h.name()).arg(fsutils::toNativePath(queued)));
h.move_storage(queued); h.move_storage(queued);
} }
else { else {
@ -2541,8 +2516,9 @@ void QBtSession::handleFileErrorAlert(libtorrent::file_error_alert* p) {
if (h.is_valid()) { if (h.is_valid()) {
h.pause(); h.pause();
std::cerr << "File Error: " << p->message().c_str() << std::endl; std::cerr << "File Error: " << p->message().c_str() << std::endl;
addConsoleMessage(tr("An I/O error occurred, '%1' paused.").arg(h.name())); Logger* const logger = Logger::instance();
addConsoleMessage(tr("Reason: %1").arg(misc::toQStringU(p->message()))); logger->addMessage(tr("An I/O error occurred, '%1' paused.").arg(h.name()));
logger->addMessage(tr("Reason: %1").arg(misc::toQStringU(p->message())));
if (h.is_valid()) { if (h.is_valid()) {
emit fullDiskError(h, misc::toQStringU(p->message())); emit fullDiskError(h, misc::toQStringU(p->message()));
//h.pause(); //h.pause();
@ -2626,14 +2602,12 @@ void QBtSession::handleTrackerWarningAlert(libtorrent::tracker_warning_alert* p)
} }
void QBtSession::handlePortmapWarningAlert(libtorrent::portmap_error_alert* p) { void QBtSession::handlePortmapWarningAlert(libtorrent::portmap_error_alert* p) {
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(misc::toQStringU(p->message())), "red"); Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping failure, message: %1").arg(misc::toQStringU(p->message())), Log::CRITICAL);
//emit UPnPError(QString(p->msg().c_str()));
} }
void QBtSession::handlePortmapAlert(libtorrent::portmap_alert* p) { void QBtSession::handlePortmapAlert(libtorrent::portmap_alert* p) {
qDebug("UPnP Success, msg: %s", p->message().c_str()); qDebug("UPnP Success, msg: %s", p->message().c_str());
addConsoleMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(misc::toQStringU(p->message())), "blue"); Logger::instance()->addMessage(tr("UPnP/NAT-PMP: Port mapping successful, message: %1").arg(misc::toQStringU(p->message())), Log::INFO);
//emit UPnPSuccess(QString(p->msg().c_str()));
} }
void QBtSession::handlePeerBlockedAlert(libtorrent::peer_blocked_alert* p) void QBtSession::handlePeerBlockedAlert(libtorrent::peer_blocked_alert* p)
@ -2642,7 +2616,7 @@ void QBtSession::handlePeerBlockedAlert(libtorrent::peer_blocked_alert* p)
string ip = p->ip.to_string(ec); string ip = p->ip.to_string(ec);
#if LIBTORRENT_VERSION_NUM < 10000 #if LIBTORRENT_VERSION_NUM < 10000
if (!ec) if (!ec)
addPeerBanMessage(QString::fromLatin1(ip.c_str()), true); Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), true);
#else #else
QString reason; QString reason;
switch (p->reason) { switch (p->reason) {
@ -2667,39 +2641,37 @@ void QBtSession::handlePeerBlockedAlert(libtorrent::peer_blocked_alert* p)
} }
if (!ec) if (!ec)
addPeerBanMessage(QString::fromLatin1(ip.c_str()), true, reason); Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), true, reason);
#endif #endif
} }
void QBtSession::handlePeerBanAlert(libtorrent::peer_ban_alert* p) { void QBtSession::handlePeerBanAlert(libtorrent::peer_ban_alert* p) {
boost::system::error_code ec; boost::system::error_code ec;
string ip = p->ip.address().to_string(ec); string ip = p->ip.address().to_string(ec);
if (!ec) { if (!ec)
addPeerBanMessage(QString::fromLatin1(ip.c_str()), false); Logger::instance()->addPeer(QString::fromLatin1(ip.c_str()), false);
//emit peerBlocked(QString::fromLatin1(ip.c_str()));
}
} }
void QBtSession::handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_alert* p) { void QBtSession::handleFastResumeRejectedAlert(libtorrent::fastresume_rejected_alert* p) {
Logger* const logger = Logger::instance();
QTorrentHandle h(p->handle); QTorrentHandle h(p->handle);
if (h.is_valid()) { if (h.is_valid()) {
qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str()); qDebug("/!\\ Fast resume failed for %s, reason: %s", qPrintable(h.name()), p->message().c_str());
if (p->error.value() == 134 && TorrentPersistentData::isSeed(h.hash()) && h.has_missing_files()) { if (p->error.value() == 134 && TorrentPersistentData::isSeed(h.hash()) && h.has_missing_files()) {
const QString hash = h.hash(); const QString hash = h.hash();
// Mismatching file size (files were probably moved // Mismatching file size (files were probably moved
addConsoleMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name())); logger->addMessage(tr("File sizes mismatch for torrent %1, pausing it.").arg(h.name()));
TorrentPersistentData::setErrorState(hash, true); TorrentPersistentData::setErrorState(hash, true);
pauseTorrent(hash); pauseTorrent(hash);
} else { } else {
addConsoleMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), QString::fromUtf8("red")); logger->addMessage(tr("Fast resume data was rejected for torrent %1, checking again...").arg(h.name()), Log::CRITICAL);
addConsoleMessage(tr("Reason: %1").arg(misc::toQStringU(p->message()))); logger->addMessage(tr("Reason: %1").arg(misc::toQStringU(p->message())));
} }
} }
} }
void QBtSession::handleUrlSeedAlert(libtorrent::url_seed_alert* p) { void QBtSession::handleUrlSeedAlert(libtorrent::url_seed_alert* p) {
addConsoleMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(misc::toQString(p->url)).arg(misc::toQStringU(p->message())), QString::fromUtf8("red")); Logger::instance()->addMessage(tr("Url seed lookup failed for url: %1, message: %2").arg(misc::toQString(p->url)).arg(misc::toQStringU(p->message())), Log::CRITICAL);
//emit urlSeedProblem(QString::fromUtf8(p->url.c_str()), QString::fromUtf8(p->msg().c_str()));
} }
void QBtSession::handleListenSucceededAlert(libtorrent::listen_succeeded_alert *p) { void QBtSession::handleListenSucceededAlert(libtorrent::listen_succeeded_alert *p) {
@ -2714,7 +2686,7 @@ void QBtSession::handleListenSucceededAlert(libtorrent::listen_succeeded_alert *
proto = "TCP_SSL"; proto = "TCP_SSL";
#endif #endif
qDebug() << "Successfully listening on " << proto << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port(); qDebug() << "Successfully listening on " << proto << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port();
addConsoleMessage(tr("qBittorrent is successfully listening on interface %1 port: %2/%3", "e.g: qBittorrent is successfully listening on interface 192.168.0.1 port: TCP/6881").arg(p->endpoint.address().to_string(ec).c_str()).arg(proto).arg(QString::number(p->endpoint.port())), "blue"); Logger::instance()->addMessage(tr("qBittorrent is successfully listening on interface %1 port: %2/%3", "e.g: qBittorrent is successfully listening on interface 192.168.0.1 port: TCP/6881").arg(p->endpoint.address().to_string(ec).c_str()).arg(proto).arg(QString::number(p->endpoint.port())), Log::INFO);
// Force reannounce on all torrents because some trackers blacklist some ports // Force reannounce on all torrents because some trackers blacklist some ports
std::vector<torrent_handle> torrents = s->get_torrents(); std::vector<torrent_handle> torrents = s->get_torrents();
@ -2741,7 +2713,7 @@ void QBtSession::handleListenFailedAlert(libtorrent::listen_failed_alert *p) {
proto = "SOCKS5"; proto = "SOCKS5";
#endif #endif
qDebug() << "Failed listening on " << proto << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port(); qDebug() << "Failed listening on " << proto << p->endpoint.address().to_string(ec).c_str() << "/" << p->endpoint.port();
addConsoleMessage(tr("qBittorrent failed listening on interface %1 port: %2/%3. Reason: %4", "e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use").arg(p->endpoint.address().to_string(ec).c_str()).arg(proto).arg(QString::number(p->endpoint.port())).arg(misc::toQStringU(p->error.message())), "red"); Logger::instance()->addMessage(tr("qBittorrent failed listening on interface %1 port: %2/%3. Reason: %4", "e.g: qBittorrent failed listening on interface 192.168.0.1 port: TCP/6881. Reason: already in use").arg(p->endpoint.address().to_string(ec).c_str()).arg(proto).arg(QString::number(p->endpoint.port())).arg(misc::toQStringU(p->error.message())), Log::CRITICAL);
} }
@ -2774,7 +2746,7 @@ void QBtSession::handleTorrentCheckedAlert(libtorrent::torrent_checked_alert* p)
void QBtSession::handleExternalIPAlert(libtorrent::external_ip_alert *p) { void QBtSession::handleExternalIPAlert(libtorrent::external_ip_alert *p) {
boost::system::error_code ec; boost::system::error_code ec;
addConsoleMessage(tr("External IP: %1", "e.g. External IP: 192.168.0.1").arg(p->external_address.to_string(ec).c_str()), "blue"); Logger::instance()->addMessage(tr("External IP: %1", "e.g. External IP: 192.168.0.1").arg(p->external_address.to_string(ec).c_str()), Log::INFO);
} }
void QBtSession::handleStateUpdateAlert(libtorrent::state_update_alert *p) { void QBtSession::handleStateUpdateAlert(libtorrent::state_update_alert *p) {
@ -2904,12 +2876,7 @@ QString QBtSession::getSavePath(const QString &hash, bool fromScanDir, QString f
// add it to download list // add it to download list
void QBtSession::downloadFromUrl(const QString &url, const QList<QNetworkCookie>& cookies) void QBtSession::downloadFromUrl(const QString &url, const QList<QNetworkCookie>& cookies)
{ {
addConsoleMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url) Logger::instance()->addMessage(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(url));
#ifndef DISABLE_GUI
, QPalette::WindowText
#endif
);
//emit aboutToDownloadFromUrl(url);
// Launch downloader thread // Launch downloader thread
downloader->downloadTorrentUrl(url, cookies); downloader->downloadTorrentUrl(url, cookies);
} }
@ -3128,13 +3095,13 @@ void QBtSession::postTorrentUpdate() {
void QBtSession::handleIPFilterParsed(int ruleCount) void QBtSession::handleIPFilterParsed(int ruleCount)
{ {
addConsoleMessage(tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount)); Logger::instance()->addMessage(tr("Successfully parsed the provided IP filter: %1 rules were applied.", "%1 is a number").arg(ruleCount));
emit ipFilterParsed(false, ruleCount); emit ipFilterParsed(false, ruleCount);
} }
void QBtSession::handleIPFilterError() void QBtSession::handleIPFilterError()
{ {
addConsoleMessage(tr("Error: Failed to parse the provided IP filter."), "red"); Logger::instance()->addMessage(tr("Error: Failed to parse the provided IP filter."), Log::CRITICAL);
emit ipFilterParsed(true, 0); emit ipFilterParsed(true, 0);
} }

27
src/qtlibtorrent/qbtsession.h

@ -34,12 +34,6 @@
#include <QHash> #include <QHash>
#include <QUrl> #include <QUrl>
#include <QStringList> #include <QStringList>
#ifdef DISABLE_GUI
#include <QCoreApplication>
#else
#include <QApplication>
#include <QPalette>
#endif
#include <QPointer> #include <QPointer>
#include <QTimer> #include <QTimer>
#include <QNetworkCookie> #include <QNetworkCookie>
@ -104,8 +98,6 @@ class TorrentStatistics;
class DNSUpdater; class DNSUpdater;
class QAlertDispatcher; class QAlertDispatcher;
const int MAX_LOG_MESSAGES = 1000;
enum TorrentExportFolder { enum TorrentExportFolder {
RegularTorrentExportFolder, RegularTorrentExportFolder,
FinishedTorrentExportFolder FinishedTorrentExportFolder
@ -141,8 +133,6 @@ public:
bool hasDownloadingTorrents() const; bool hasDownloadingTorrents() const;
//int getMaximumActiveDownloads() const; //int getMaximumActiveDownloads() const;
//int getMaximumActiveTorrents() const; //int getMaximumActiveTorrents() const;
inline QStringList getConsoleMessages() const { return consoleMessages; }
inline QStringList getPeerBanMessages() const { return peerBanMessages; }
inline libtorrent::session* getSession() const { return s; } inline libtorrent::session* getSession() const { return s; }
inline bool useTemporaryFolder() const { return !defaultTempPath.isEmpty(); } inline bool useTemporaryFolder() const { return !defaultTempPath.isEmpty(); }
inline QString getDefaultSavePath() const { return defaultSavePath; } inline QString getDefaultSavePath() const { return defaultSavePath; }
@ -210,18 +200,6 @@ public slots:
void enableUPnP(bool b); void enableUPnP(bool b);
void enableLSD(bool b); void enableLSD(bool b);
void enableDHT(bool b); void enableDHT(bool b);
#ifdef DISABLE_GUI
void addConsoleMessage(QString msg, QString color=QString::null);
#else
void addConsoleMessage(QString msg, QColor color=QApplication::palette().color(QPalette::WindowText));
#endif
#if LIBTORRENT_VERSION_NUM < 10000
void addPeerBanMessage(const QString &msg, bool blocked);
#else
void addPeerBanMessage(const QString &msg, bool blocked, const QString &blockedReason = QString());
#endif
void clearConsoleMessages() { consoleMessages.clear(); }
void clearPeerBanMessages() { peerBanMessages.clear(); }
void processDownloadedFile(QString, QString); void processDownloadedFile(QString, QString);
#ifndef DISABLE_GUI #ifndef DISABLE_GUI
void addMagnetSkipAddDlg(const QString& uri, const QString& save_path = QString(), const QString& label = QString(), void addMagnetSkipAddDlg(const QString& uri, const QString& save_path = QString(), const QString& label = QString(),
@ -307,8 +285,6 @@ signals:
void torrentFinishedChecking(const QTorrentHandle& h); void torrentFinishedChecking(const QTorrentHandle& h);
void metadataReceived(const QTorrentHandle &h); void metadataReceived(const QTorrentHandle &h);
void savePathChanged(const QTorrentHandle &h); void savePathChanged(const QTorrentHandle &h);
void newConsoleMessage(const QString &msg);
void newBanMessage(const QString &msg);
void alternativeSpeedsModeChanged(bool alternative); void alternativeSpeedsModeChanged(bool alternative);
void recursiveTorrentDownloadPossible(const QTorrentHandle &h); void recursiveTorrentDownloadPossible(const QTorrentHandle &h);
void ipFilterParsed(bool error, int ruleCount); void ipFilterParsed(bool error, int ruleCount);
@ -334,9 +310,6 @@ private:
DownloadThread* downloader; DownloadThread* downloader;
// File System // File System
ScanFoldersModel *m_scanFolders; ScanFoldersModel *m_scanFolders;
// Console / Log
QStringList consoleMessages;
QStringList peerBanMessages;
// Settings // Settings
bool preAllocateAll; bool preAllocateAll;
qreal global_ratio_limit; qreal global_ratio_limit;

3
src/rss/rssfeed.cpp

@ -41,6 +41,7 @@
#include "rssdownloadrulelist.h" #include "rssdownloadrulelist.h"
#include "downloadthread.h" #include "downloadthread.h"
#include "fs_utils.h" #include "fs_utils.h"
#include "logger.h"
bool rssArticleDateRecentThan(const RssArticlePtr& left, const RssArticlePtr& right) bool rssArticleDateRecentThan(const RssArticlePtr& left, const RssArticlePtr& right)
{ {
@ -367,7 +368,7 @@ void RssFeed::downloadArticleTorrentIfMatching(RssDownloadRuleList* rules, const
rules->saveRulesToStorage(); rules->saveRulesToStorage();
// Download the torrent // Download the torrent
const QString& torrent_url = article->torrentUrl(); const QString& torrent_url = article->torrentUrl();
QBtSession::instance()->addConsoleMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(article->title()).arg(displayName())); Logger::instance()->addMessage(tr("Automatically downloading %1 torrent from %2 RSS feed...").arg(article->title()).arg(displayName()));
connect(QBtSession::instance(), SIGNAL(newDownloadedTorrentFromRss(QString)), article.data(), SLOT(handleTorrentDownloadSuccess(const QString&)), Qt::UniqueConnection); connect(QBtSession::instance(), SIGNAL(newDownloadedTorrentFromRss(QString)), article.data(), SLOT(handleTorrentDownloadSuccess(const QString&)), Qt::UniqueConnection);
connect(article.data(), SIGNAL(articleWasRead()), SLOT(handleArticleStateChanged()), Qt::UniqueConnection); connect(article.data(), SIGNAL(articleWasRead()), SLOT(handleArticleStateChanged()), Qt::UniqueConnection);
if (torrent_url.startsWith("magnet:", Qt::CaseInsensitive)) if (torrent_url.startsWith("magnet:", Qt::CaseInsensitive))

5
src/smtp.cpp

@ -34,7 +34,7 @@
#include "smtp.h" #include "smtp.h"
#include "preferences.h" #include "preferences.h"
#include "qbtsession.h" #include "logger.h"
#include <QTextStream> #include <QTextStream>
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
@ -48,6 +48,7 @@
#include <QHostInfo> #include <QHostInfo>
#include <QNetworkInterface> #include <QNetworkInterface>
#include <QCryptographicHash> #include <QCryptographicHash>
#include <QStringList>
namespace { namespace {
const short DEFAULT_PORT = 25; const short DEFAULT_PORT = 25;
@ -475,5 +476,5 @@ void Smtp::authLogin()
void Smtp::logError(const QString &msg) void Smtp::logError(const QString &msg)
{ {
qDebug() << "Email Notification Error:" << msg; qDebug() << "Email Notification Error:" << msg;
QBtSession::instance()->addConsoleMessage("Email Notification Error: "+msg, "red"); Logger::instance()->addMessage(tr("Email Notification Error:") + " " + msg, Log::CRITICAL);
} }

3
src/statusbar.cpp

@ -38,6 +38,7 @@
#include "iconprovider.h" #include "iconprovider.h"
#include "preferences.h" #include "preferences.h"
#include "misc.h" #include "misc.h"
#include "logger.h"
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include <libtorrent/session_status.hpp> #include <libtorrent/session_status.hpp>
@ -149,7 +150,7 @@ void StatusBar::showRestartRequired() {
m_bar->insertWidget(1, restartLbl); m_bar->insertWidget(1, restartLbl);
QFontMetrics fm(restartLbl->font()); QFontMetrics fm(restartLbl->font());
restartLbl->setText(fm.elidedText(restart_text, Qt::ElideRight, restartLbl->width())); restartLbl->setText(fm.elidedText(restart_text, Qt::ElideRight, restartLbl->width()));
QBtSession::instance()->addConsoleMessage(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective."), "red"); Logger::instance()->addMessage(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective."), Log::CRITICAL);
} }
void StatusBar::stopTimer() { void StatusBar::stopTimer() {

1
src/webui/prefjson.cpp

@ -40,6 +40,7 @@
#include <QSslKey> #include <QSslKey>
#endif #endif
#include <QTranslator> #include <QTranslator>
#include <QCoreApplication>
#include "jsonutils.h" #include "jsonutils.h"
prefjson::prefjson() prefjson::prefjson()

Loading…
Cancel
Save