diff --git a/src/core/core.pri b/src/core/core.pri index 8e02c50c2..74dd529ec 100644 --- a/src/core/core.pri +++ b/src/core/core.pri @@ -10,8 +10,6 @@ HEADERS += \ $$PWD/filesystemwatcher.h \ $$PWD/scannedfoldersmodel.h \ $$PWD/qinisettings.h \ - $$PWD/smtp.h \ - $$PWD/dnsupdater.h \ $$PWD/logger.h \ $$PWD/preferences.h \ $$PWD/qtracker.h \ @@ -21,7 +19,10 @@ HEADERS += \ $$PWD/http/responsegenerator.h \ $$PWD/http/server.h \ $$PWD/http/types.h \ - $$PWD/http/responsebuilder.h + $$PWD/http/responsebuilder.h \ + $$PWD/net/dnsupdater.h \ + $$PWD/net/reverseresolution.h \ + $$PWD/net/smtp.h SOURCES += \ $$PWD/downloadthread.cpp \ @@ -29,8 +30,6 @@ SOURCES += \ $$PWD/torrentpersistentdata.cpp \ $$PWD/misc.cpp \ $$PWD/fs_utils.cpp \ - $$PWD/smtp.cpp \ - $$PWD/dnsupdater.cpp \ $$PWD/logger.cpp \ $$PWD/preferences.cpp \ $$PWD/qtracker.cpp \ @@ -38,4 +37,7 @@ SOURCES += \ $$PWD/http/requestparser.cpp \ $$PWD/http/responsegenerator.cpp \ $$PWD/http/server.cpp \ - $$PWD/http/responsebuilder.cpp + $$PWD/http/responsebuilder.cpp \ + $$PWD/net/dnsupdater.cpp \ + $$PWD/net/reverseresolution.cpp \ + $$PWD/net/smtp.cpp diff --git a/src/core/dnsupdater.cpp b/src/core/net/dnsupdater.cpp similarity index 99% rename from src/core/dnsupdater.cpp rename to src/core/net/dnsupdater.cpp index b7d1a0d9c..5d176e733 100644 --- a/src/core/dnsupdater.cpp +++ b/src/core/net/dnsupdater.cpp @@ -38,6 +38,8 @@ #include "dnsupdater.h" #include "logger.h" +using namespace Net; + DNSUpdater::DNSUpdater(QObject *parent) : QObject(parent), m_state(OK), m_service(DNS::NONE) { diff --git a/src/core/dnsupdater.h b/src/core/net/dnsupdater.h similarity index 99% rename from src/core/dnsupdater.h rename to src/core/net/dnsupdater.h index 3ea9a5cd3..a130ef423 100644 --- a/src/core/dnsupdater.h +++ b/src/core/net/dnsupdater.h @@ -38,6 +38,9 @@ #include #include "preferences.h" +namespace Net +{ + /*! * Based on http://www.dyndns.com/developers/specs/ */ @@ -78,4 +81,6 @@ private: enum State { OK, INVALID_CREDS, FATAL }; }; +} + #endif // DNSUPDATER_H diff --git a/src/gui/reverseresolution.h b/src/core/net/reverseresolution.cpp similarity index 59% rename from src/gui/reverseresolution.h rename to src/core/net/reverseresolution.cpp index b7971adc2..d41280f8e 100644 --- a/src/gui/reverseresolution.h +++ b/src/core/net/reverseresolution.cpp @@ -1,5 +1,5 @@ /* - * Bittorrent Client using Qt4 and libtorrent. + * Bittorrent Client using Qt and libtorrent. * Copyright (C) 2006 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -28,14 +28,9 @@ * Contact : chris@qbittorrent.org */ -#ifndef REVERSERESOLUTION_H -#define REVERSERESOLUTION_H - -#include -#include #include #include -#include "misc.h" +#include #include #if BOOST_VERSION < 103500 @@ -44,62 +39,56 @@ #include #endif +#include "reverseresolution.h" + const int CACHE_SIZE = 500; -class ReverseResolution: public QObject { - Q_OBJECT - Q_DISABLE_COPY(ReverseResolution) +using namespace Net; + +static inline bool isUsefulHostName(const QString &hostname, const QString &ip) +{ + return (!hostname.isEmpty() && hostname != ip); +} -public: - explicit ReverseResolution(QObject* parent): QObject(parent) { +ReverseResolution::ReverseResolution(QObject *parent) + : QObject(parent) +{ m_cache.setMaxCost(CACHE_SIZE); - } +} - ~ReverseResolution() { +ReverseResolution::~ReverseResolution() +{ qDebug("Deleting host name resolver..."); - } +} - void resolve(const QString &ip) { +void ReverseResolution::resolve(const QString &ip) +{ if (m_cache.contains(ip)) { - const QString& hostname = *m_cache.object(ip); - qDebug() << "Resolved host name using cache: " << ip << " -> " << hostname; - if (isUsefulHostName(hostname, ip)) - emit ip_resolved(ip, hostname); - return; + const QString &hostname = *m_cache.object(ip); + qDebug() << "Resolved host name using cache: " << ip << " -> " << hostname; + if (isUsefulHostName(hostname, ip)) + emit ipResolved(ip, hostname); } - // Actually resolve the ip - m_lookups.insert(QHostInfo::lookupHost(ip, this, SLOT(hostResolved(QHostInfo))), ip); - } - -signals: - void ip_resolved(const QString &ip, const QString &hostname); + else { + // Actually resolve the ip + m_lookups.insert(QHostInfo::lookupHost(ip, this, SLOT(hostResolved(QHostInfo))), ip); + } +} -private slots: - void hostResolved(const QHostInfo& host) { - const QString& ip = m_lookups.take(host.lookupId()); +void ReverseResolution::hostResolved(const QHostInfo &host) +{ + const QString &ip = m_lookups.take(host.lookupId()); Q_ASSERT(!ip.isNull()); if (host.error() != QHostInfo::NoError) { - qDebug() << "DNS Reverse resolution error: " << host.errorString(); - return; + qDebug() << "DNS Reverse resolution error: " << host.errorString(); + return; } - const QString& hostname = host.hostName(); + const QString &hostname = host.hostName(); qDebug() << Q_FUNC_INFO << ip << QString("->") << hostname; m_cache.insert(ip, new QString(hostname)); if (isUsefulHostName(hostname, ip)) - emit ip_resolved(ip, hostname); - } - -private: - static inline bool isUsefulHostName(const QString& hostname, const QString& ip) { - return (!hostname.isEmpty() && hostname != ip); - } - - QHash m_lookups; - QCache m_cache; -}; - - -#endif // REVERSERESOLUTION_H + emit ipResolved(ip, hostname); +} diff --git a/src/core/net/reverseresolution.h b/src/core/net/reverseresolution.h new file mode 100644 index 000000000..ef181762a --- /dev/null +++ b/src/core/net/reverseresolution.h @@ -0,0 +1,67 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2006 Christophe Dumez + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + * + * Contact : chris@qbittorrent.org + */ + +#ifndef NET_REVERSERESOLUTION_H +#define NET_REVERSERESOLUTION_H + +#include +#include + +QT_BEGIN_NAMESPACE +class QHostInfo; +class QString; +QT_END_NAMESPACE + +namespace Net +{ + class ReverseResolution : public QObject + { + Q_OBJECT + Q_DISABLE_COPY(ReverseResolution) + + public: + explicit ReverseResolution(QObject *parent = 0); + ~ReverseResolution(); + + void resolve(const QString &ip); + + signals: + void ipResolved(const QString &ip, const QString &hostname); + + private slots: + void hostResolved(const QHostInfo &host); + + private: + QHash m_lookups; + QCache m_cache; + }; +} + +#endif // NET_REVERSERESOLUTION_H diff --git a/src/core/smtp.cpp b/src/core/net/smtp.cpp similarity index 99% rename from src/core/smtp.cpp rename to src/core/net/smtp.cpp index f90fcc5a7..f895c1924 100644 --- a/src/core/smtp.cpp +++ b/src/core/net/smtp.cpp @@ -1,5 +1,5 @@ /* - * Bittorrent Client using Qt4 and libtorrent. + * Bittorrent Client using Qt and libtorrent. * Copyright (C) 2011 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -89,6 +89,8 @@ QByteArray determineFQDN() } } // namespace +using namespace Net; + Smtp::Smtp(QObject *parent): QObject(parent), state(Init), use_ssl(false) { #ifndef QT_NO_OPENSSL diff --git a/src/core/smtp.h b/src/core/net/smtp.h similarity index 97% rename from src/core/smtp.h rename to src/core/net/smtp.h index bb80a3a85..9b332416d 100644 --- a/src/core/smtp.h +++ b/src/core/net/smtp.h @@ -1,5 +1,5 @@ /* - * Bittorrent Client using Qt4 and libtorrent. + * Bittorrent Client using Qt and libtorrent. * Copyright (C) 2011 Christophe Dumez * * This program is free software; you can redistribute it and/or @@ -50,6 +50,9 @@ class QTcpSocket; class QTextCodec; QT_END_NAMESPACE +namespace Net +{ + class Smtp : public QObject { Q_OBJECT @@ -96,4 +99,7 @@ private: QString username; QString password; }; + +} + #endif diff --git a/src/core/qtlibtorrent/qbtsession.cpp b/src/core/qtlibtorrent/qbtsession.cpp index fc42aa6da..01ee5076e 100644 --- a/src/core/qtlibtorrent/qbtsession.cpp +++ b/src/core/qtlibtorrent/qbtsession.cpp @@ -38,7 +38,7 @@ #include #include -#include "smtp.h" +#include "core/net/smtp.h" #include "filesystemwatcher.h" #include "torrentspeedmonitor.h" #include "torrentstatistics.h" @@ -2046,7 +2046,7 @@ void QBtSession::sendNotificationEmail(const QTorrentHandle &h) { content += tr("The torrent was downloaded in %1.", "The torrent was downloaded in 1 hour and 20 seconds").arg(misc::userFriendlyDuration(status.active_time)) + "\n\n\n"; content += tr("Thank you for using qBittorrent.") + "\n"; // Send the notification email - Smtp *sender = new Smtp(this); + Net::Smtp *sender = new Net::Smtp(this); sender->sendMail("notification@qbittorrent.org", Preferences::instance()->getMailNotificationEmail(), tr("[qBittorrent] %1 has finished downloading").arg(h.name()), content); } diff --git a/src/gui/gui.pri b/src/gui/gui.pri index 3ba11cd54..9665fe4f2 100644 --- a/src/gui/gui.pri +++ b/src/gui/gui.pri @@ -22,7 +22,6 @@ HEADERS += \ $$PWD/torrentcontenttreeview.h \ $$PWD/deletionconfirmationdlg.h \ $$PWD/statusbar.h \ - $$PWD/reverseresolution.h \ $$PWD/ico.h \ $$PWD/speedlimitdlg.h \ $$PWD/about_imp.h \ diff --git a/src/gui/options_imp.cpp b/src/gui/options_imp.cpp index fdc85d96f..e125ee2dc 100644 --- a/src/gui/options_imp.cpp +++ b/src/gui/options_imp.cpp @@ -48,7 +48,7 @@ #include "scannedfoldersmodel.h" #include "qbtsession.h" #include "iconprovider.h" -#include "dnsupdater.h" +#include "core/net/dnsupdater.h" #ifndef QT_NO_OPENSSL #include @@ -1239,7 +1239,7 @@ void options_imp::on_btnWebUiKey_clicked() { } void options_imp::on_registerDNSBtn_clicked() { - QDesktopServices::openUrl(DNSUpdater::getRegistrationUrl(comboDNSService->currentIndex())); + QDesktopServices::openUrl(Net::DNSUpdater::getRegistrationUrl(comboDNSService->currentIndex())); } void options_imp::on_IpFilterRefreshBtn_clicked() { diff --git a/src/gui/properties/peerlistwidget.cpp b/src/gui/properties/peerlistwidget.cpp index 69ebfd355..ea4c787b0 100644 --- a/src/gui/properties/peerlistwidget.cpp +++ b/src/gui/properties/peerlistwidget.cpp @@ -31,7 +31,7 @@ #include "peerlistwidget.h" #include "peerlistdelegate.h" #include "peerlistsortmodel.h" -#include "reverseresolution.h" +#include "core/net/reverseresolution.h" #include "preferences.h" #include "propertieswidget.h" #include "geoipmanager.h" @@ -126,8 +126,8 @@ void PeerListWidget::updatePeerHostNameResolutionState() { if (Preferences::instance()->resolvePeerHostNames()) { if (!m_resolver) { - m_resolver = new ReverseResolution(this); - connect(m_resolver, SIGNAL(ip_resolved(QString,QString)), SLOT(handleResolved(QString,QString))); + m_resolver = new Net::ReverseResolution(this); + connect(m_resolver, SIGNAL(ipResolved(QString,QString)), SLOT(handleResolved(QString,QString))); loadPeers(m_properties->getCurrentTorrent(), true); } } else { diff --git a/src/gui/properties/peerlistwidget.h b/src/gui/properties/peerlistwidget.h index 0771555c1..fa0652563 100644 --- a/src/gui/properties/peerlistwidget.h +++ b/src/gui/properties/peerlistwidget.h @@ -37,9 +37,13 @@ #include #include +namespace Net +{ + class ReverseResolution; +} + class PeerListDelegate; class PeerListSortModel; -class ReverseResolution; class PropertiesWidget; class QTorrentHandle; @@ -103,7 +107,7 @@ private: QHash m_peerItems; QHash m_peerEndpoints; QSet m_missingFlags; - QPointer m_resolver; + QPointer m_resolver; PropertiesWidget *m_properties; bool m_displayFlags; }; diff --git a/src/webui/webui.cpp b/src/webui/webui.cpp index 6cafe0b4b..723675ab2 100644 --- a/src/webui/webui.cpp +++ b/src/webui/webui.cpp @@ -29,7 +29,7 @@ #include "webui.h" #include "http/server.h" #include "webapplication.h" -#include "dnsupdater.h" +#include "core/net/dnsupdater.h" #include "preferences.h" #include "logger.h" @@ -82,7 +82,7 @@ void WebUI::init() // DynDNS if (pref->isDynDNSEnabled()) { if (!dynDNSUpdater_) - dynDNSUpdater_ = new DNSUpdater(this); + dynDNSUpdater_ = new Net::DNSUpdater(this); else dynDNSUpdater_->updateCredentials(); } diff --git a/src/webui/webui.h b/src/webui/webui.h index 2abc6b924..9e7801af0 100644 --- a/src/webui/webui.h +++ b/src/webui/webui.h @@ -32,8 +32,16 @@ #include #include -namespace Http { class Server; } -class DNSUpdater; +namespace Http +{ + class Server; +} + +namespace Net +{ + class DNSUpdater; +} + class AbstractWebApplication; class WebUI : public QObject @@ -48,7 +56,7 @@ private slots: private: QPointer httpServer_; - QPointer dynDNSUpdater_; + QPointer dynDNSUpdater_; QPointer webapp_; };