Browse Source

Coding style, use nullptr and other minor things

adaptive-webui-19844
thalieht 7 years ago
parent
commit
525fdd6c2b
  1. 2
      src/base/bittorrent/infohash.h
  2. 2
      src/base/bittorrent/magneturi.h
  3. 48
      src/base/bittorrent/peerinfo.cpp
  4. 6
      src/base/bittorrent/peerinfo.h
  5. 8
      src/base/bittorrent/private/filterparserthread.cpp
  6. 6
      src/base/bittorrent/private/filterparserthread.h
  7. 4
      src/base/bittorrent/private/resumedatasavingmanager.h
  8. 2
      src/base/bittorrent/private/statistics.cpp
  9. 5
      src/base/bittorrent/private/statistics.h
  10. 18
      src/base/bittorrent/session.cpp
  11. 19
      src/base/bittorrent/torrenthandle.cpp
  12. 7
      src/base/bittorrent/tracker.cpp
  13. 11
      src/base/bittorrent/tracker.h
  14. 4
      src/base/filesystemwatcher.cpp
  15. 8
      src/base/filesystemwatcher.h
  16. 75
      src/base/http/requestparser.cpp
  17. 4
      src/base/http/requestparser.h
  18. 2
      src/base/http/responsebuilder.h
  19. 6
      src/base/http/responsegenerator.cpp
  20. 4
      src/base/http/responsegenerator.h
  21. 9
      src/base/http/server.cpp
  22. 8
      src/base/http/server.h
  23. 13
      src/base/net/dnsupdater.cpp
  24. 14
      src/base/net/dnsupdater.h
  25. 17
      src/base/net/downloadhandler.cpp
  26. 2
      src/base/net/downloadhandler.h
  27. 19
      src/base/net/geoipmanager.cpp
  28. 2
      src/base/net/geoipmanager.h
  29. 4
      src/base/net/portforwarder.cpp
  30. 4
      src/base/net/portforwarder.h
  31. 23
      src/base/net/smtp.cpp
  32. 18
      src/base/net/smtp.h
  33. 4
      src/gui/banlistoptions.cpp
  34. 4
      src/gui/banlistoptions.h
  35. 4
      src/gui/cookiesdialog.cpp
  36. 2
      src/gui/cookiesdialog.h
  37. 6
      src/gui/cookiesmodel.cpp
  38. 2
      src/gui/cookiesmodel.h
  39. 95
      src/gui/previewlistdelegate.h
  40. 37
      src/gui/properties/peerlistdelegate.h
  41. 4
      src/gui/properties/peerlistsortmodel.h
  42. 30
      src/gui/properties/peerlistwidget.cpp
  43. 12
      src/gui/properties/peerlistwidget.h
  44. 5
      src/gui/properties/speedplotview.h
  45. 2
      src/gui/properties/trackerlist.h
  46. 28
      src/gui/rss/htmlbrowser.cpp
  47. 6
      src/gui/rss/htmlbrowser.h
  48. 2
      src/gui/shutdownconfirmdlg.h
  49. 8
      src/gui/speedlimitdlg.cpp
  50. 15
      src/gui/speedlimitdlg.h
  51. 62
      src/gui/updownratiodlg.cpp
  52. 21
      src/gui/updownratiodlg.h
  53. 25
      src/webui/webapplication.cpp
  54. 4
      src/webui/webapplication.h

2
src/base/bittorrent/infohash.h

@ -29,8 +29,8 @@
#ifndef BITTORRENT_INFOHASH_H #ifndef BITTORRENT_INFOHASH_H
#define BITTORRENT_INFOHASH_H #define BITTORRENT_INFOHASH_H
#include <libtorrent/sha1_hash.hpp>
#include <QString> #include <QString>
#include <libtorrent/sha1_hash.hpp>
namespace BitTorrent namespace BitTorrent
{ {

2
src/base/bittorrent/magneturi.h

@ -29,8 +29,8 @@
#ifndef BITTORRENT_MAGNETURI_H #ifndef BITTORRENT_MAGNETURI_H
#define BITTORRENT_MAGNETURI_H #define BITTORRENT_MAGNETURI_H
#include <QString>
#include <QList> #include <QList>
#include <QString>
#include <QUrl> #include <QUrl>
#include <libtorrent/add_torrent_params.hpp> #include <libtorrent/add_torrent_params.hpp>

48
src/base/bittorrent/peerinfo.cpp

@ -26,11 +26,12 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "peerinfo.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/net/geoipmanager.h" #include "base/net/geoipmanager.h"
#include "base/utils/string.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "base/bittorrent/torrenthandle.h" #include "base/utils/string.h"
#include "peerinfo.h"
namespace libt = libtorrent; namespace libt = libtorrent;
using namespace BitTorrent; using namespace BitTorrent;
@ -99,7 +100,6 @@ bool PeerInfo::isRemoteChocked() const
return (m_nativeInfo.flags & libt::peer_info::remote_choked); return (m_nativeInfo.flags & libt::peer_info::remote_choked);
} }
bool PeerInfo::isSupportsExtensions() const bool PeerInfo::isSupportsExtensions() const
{ {
return (m_nativeInfo.flags & libt::peer_info::supports_extensions); return (m_nativeInfo.flags & libt::peer_info::supports_extensions);
@ -115,7 +115,6 @@ bool PeerInfo::isHandshake() const
return (m_nativeInfo.flags & libt::peer_info::handshake); return (m_nativeInfo.flags & libt::peer_info::handshake);
} }
bool PeerInfo::isConnecting() const bool PeerInfo::isConnecting() const
{ {
return (m_nativeInfo.flags & libt::peer_info::connecting); return (m_nativeInfo.flags & libt::peer_info::connecting);
@ -136,7 +135,6 @@ bool PeerInfo::optimisticUnchoke() const
return (m_nativeInfo.flags & libt::peer_info::optimistic_unchoke); return (m_nativeInfo.flags & libt::peer_info::optimistic_unchoke);
} }
bool PeerInfo::isSnubbed() const bool PeerInfo::isSnubbed() const
{ {
return (m_nativeInfo.flags & libt::peer_info::snubbed); return (m_nativeInfo.flags & libt::peer_info::snubbed);
@ -152,7 +150,6 @@ bool PeerInfo::isEndgameMode() const
return (m_nativeInfo.flags & libt::peer_info::endgame_mode); return (m_nativeInfo.flags & libt::peer_info::endgame_mode);
} }
bool PeerInfo::isHolepunched() const bool PeerInfo::isHolepunched() const
{ {
return (m_nativeInfo.flags & libt::peer_info::holepunched); return (m_nativeInfo.flags & libt::peer_info::holepunched);
@ -183,7 +180,6 @@ bool PeerInfo::isPlaintextEncrypted() const
return (m_nativeInfo.flags & libt::peer_info::plaintext_encrypted); return (m_nativeInfo.flags & libt::peer_info::plaintext_encrypted);
} }
PeerAddress PeerInfo::address() const PeerAddress PeerInfo::address() const
{ {
return PeerAddress(QHostAddress(QString::fromStdString(m_nativeInfo.ip.address().to_string())), return PeerAddress(QHostAddress(QString::fromStdString(m_nativeInfo.ip.address().to_string())),
@ -195,7 +191,6 @@ QString PeerInfo::client() const
return QString::fromStdString(m_nativeInfo.client); return QString::fromStdString(m_nativeInfo.client);
} }
qreal PeerInfo::progress() const qreal PeerInfo::progress() const
{ {
return m_nativeInfo.progress; return m_nativeInfo.progress;
@ -206,7 +201,6 @@ int PeerInfo::payloadUpSpeed() const
return m_nativeInfo.payload_up_speed; return m_nativeInfo.payload_up_speed;
} }
int PeerInfo::payloadDownSpeed() const int PeerInfo::payloadDownSpeed() const
{ {
return m_nativeInfo.payload_down_speed; return m_nativeInfo.payload_down_speed;
@ -217,7 +211,6 @@ qlonglong PeerInfo::totalUpload() const
return m_nativeInfo.total_upload; return m_nativeInfo.total_upload;
} }
qlonglong PeerInfo::totalDownload() const qlonglong PeerInfo::totalDownload() const
{ {
return m_nativeInfo.total_download; return m_nativeInfo.total_download;
@ -239,7 +232,7 @@ QString PeerInfo::connectionType() const
return QString::fromUtf8(C_UTP); return QString::fromUtf8(C_UTP);
QString connection; QString connection;
switch(m_nativeInfo.connection_type) { switch (m_nativeInfo.connection_type) {
case libt::peer_info::http_seed: case libt::peer_info::http_seed:
case libt::peer_info::web_seed: case libt::peer_info::web_seed:
connection = "Web"; connection = "Web";
@ -281,14 +274,14 @@ qreal PeerInfo::relevance() const
void PeerInfo::determineFlags() void PeerInfo::determineFlags()
{ {
if (isInteresting()) { if (isInteresting()) {
//d = Your client wants to download, but peer doesn't want to send (interested and choked) // d = Your client wants to download, but peer doesn't want to send (interested and choked)
if (isRemoteChocked()) { if (isRemoteChocked()) {
m_flags += "d "; m_flags += "d ";
m_flagsDescription += tr("interested(local) and choked(peer)"); m_flagsDescription += tr("interested(local) and choked(peer)");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
else { else {
//D = Currently downloading (interested and not choked) // D = Currently downloading (interested and not choked)
m_flags += "D "; m_flags += "D ";
m_flagsDescription += tr("interested(local) and unchoked(peer)"); m_flagsDescription += tr("interested(local) and unchoked(peer)");
m_flagsDescription += ", "; m_flagsDescription += ", ";
@ -296,92 +289,91 @@ void PeerInfo::determineFlags()
} }
if (isRemoteInterested()) { if (isRemoteInterested()) {
//u = Peer wants your client to upload, but your client doesn't want to (interested and choked) // u = Peer wants your client to upload, but your client doesn't want to (interested and choked)
if (isChocked()) { if (isChocked()) {
m_flags += "u "; m_flags += "u ";
m_flagsDescription += tr("interested(peer) and choked(local)"); m_flagsDescription += tr("interested(peer) and choked(local)");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
else { else {
//U = Currently uploading (interested and not choked) // U = Currently uploading (interested and not choked)
m_flags += "U "; m_flags += "U ";
m_flagsDescription += tr("interested(peer) and unchoked(local)"); m_flagsDescription += tr("interested(peer) and unchoked(local)");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
} }
//O = Optimistic unchoke // O = Optimistic unchoke
if (optimisticUnchoke()) { if (optimisticUnchoke()) {
m_flags += "O "; m_flags += "O ";
m_flagsDescription += tr("optimistic unchoke"); m_flagsDescription += tr("optimistic unchoke");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//S = Peer is snubbed // S = Peer is snubbed
if (isSnubbed()) { if (isSnubbed()) {
m_flags += "S "; m_flags += "S ";
m_flagsDescription += tr("peer snubbed"); m_flagsDescription += tr("peer snubbed");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//I = Peer is an incoming connection // I = Peer is an incoming connection
if (!isLocalConnection()) { if (!isLocalConnection()) {
m_flags += "I "; m_flags += "I ";
m_flagsDescription += tr("incoming connection"); m_flagsDescription += tr("incoming connection");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//K = Peer is unchoking your client, but your client is not interested // K = Peer is unchoking your client, but your client is not interested
if (!isRemoteChocked() && !isInteresting()) { if (!isRemoteChocked() && !isInteresting()) {
m_flags += "K "; m_flags += "K ";
m_flagsDescription += tr("not interested(local) and unchoked(peer)"); m_flagsDescription += tr("not interested(local) and unchoked(peer)");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//? = Your client unchoked the peer but the peer is not interested // ? = Your client unchoked the peer but the peer is not interested
if (!isChocked() && !isRemoteInterested()) { if (!isChocked() && !isRemoteInterested()) {
m_flags += "? "; m_flags += "? ";
m_flagsDescription += tr("not interested(peer) and unchoked(local)"); m_flagsDescription += tr("not interested(peer) and unchoked(local)");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//X = Peer was included in peerlists obtained through Peer Exchange (PEX) // X = Peer was included in peerlists obtained through Peer Exchange (PEX)
if (fromPeX()) { if (fromPeX()) {
m_flags += "X "; m_flags += "X ";
m_flagsDescription += tr("peer from PEX"); m_flagsDescription += tr("peer from PEX");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//H = Peer was obtained through DHT // H = Peer was obtained through DHT
if (fromDHT()) { if (fromDHT()) {
m_flags += "H "; m_flags += "H ";
m_flagsDescription += tr("peer from DHT"); m_flagsDescription += tr("peer from DHT");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//E = Peer is using Protocol Encryption (all traffic) // E = Peer is using Protocol Encryption (all traffic)
if (isRC4Encrypted()) { if (isRC4Encrypted()) {
m_flags += "E "; m_flags += "E ";
m_flagsDescription += tr("encrypted traffic"); m_flagsDescription += tr("encrypted traffic");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//e = Peer is using Protocol Encryption (handshake) // e = Peer is using Protocol Encryption (handshake)
if (isPlaintextEncrypted()) { if (isPlaintextEncrypted()) {
m_flags += "e "; m_flags += "e ";
m_flagsDescription += tr("encrypted handshake"); m_flagsDescription += tr("encrypted handshake");
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//P = Peer is using uTorrent uTP // P = Peer is using uTorrent uTP
if (useUTPSocket()) { if (useUTPSocket()) {
m_flags += "P "; m_flags += "P ";
m_flagsDescription += QString::fromUtf8(C_UTP); m_flagsDescription += QString::fromUtf8(C_UTP);
m_flagsDescription += ", "; m_flagsDescription += ", ";
} }
//L = Peer is local // L = Peer is local
if (fromLSD()) { if (fromLSD()) {
m_flags += "L"; m_flags += "L";
m_flagsDescription += tr("peer from LSD"); m_flagsDescription += tr("peer from LSD");

6
src/base/bittorrent/peerinfo.h

@ -29,11 +29,11 @@
#ifndef BITTORRENT_PEERINFO_H #ifndef BITTORRENT_PEERINFO_H
#define BITTORRENT_PEERINFO_H #define BITTORRENT_PEERINFO_H
#include <libtorrent/peer_info.hpp>
#include <QHostAddress>
#include <QBitArray> #include <QBitArray>
#include <QCoreApplication> #include <QCoreApplication>
#include <QHostAddress>
#include <libtorrent/peer_info.hpp>
namespace BitTorrent namespace BitTorrent
{ {

8
src/base/bittorrent/private/filterparserthread.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libt. * Bittorrent Client using Qt and libt.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,17 +24,15 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "filterparserthread.h" #include "filterparserthread.h"
#include <cctype>
#include <QDataStream> #include <QDataStream>
#include <QFile> #include <QFile>
#include <cctype>
#include "base/logger.h" #include "base/logger.h"
namespace libt = libtorrent; namespace libt = libtorrent;

6
src/base/bittorrent/private/filterparserthread.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef FILTERPARSERTHREAD_H #ifndef FILTERPARSERTHREAD_H
@ -42,7 +40,7 @@ class FilterParserThread : public QThread
Q_OBJECT Q_OBJECT
public: public:
FilterParserThread(QObject *parent = 0); FilterParserThread(QObject *parent = nullptr);
~FilterParserThread(); ~FilterParserThread();
void processFilterFile(const QString &filePath); void processFilterFile(const QString &filePath);
libtorrent::ip_filter IPfilter(); libtorrent::ip_filter IPfilter();

4
src/base/bittorrent/private/resumedatasavingmanager.h

@ -29,11 +29,11 @@
#ifndef RESUMEDATASAVINGMANAGER_H #ifndef RESUMEDATASAVINGMANAGER_H
#define RESUMEDATASAVINGMANAGER_H #define RESUMEDATASAVINGMANAGER_H
#include <QObject>
#include <QByteArray> #include <QByteArray>
#include <QDir> #include <QDir>
#include <QObject>
class ResumeDataSavingManager: public QObject class ResumeDataSavingManager : public QObject
{ {
Q_OBJECT Q_OBJECT

2
src/base/bittorrent/private/statistics.cpp

@ -4,9 +4,9 @@
#include <libtorrent/session.hpp> #include <libtorrent/session.hpp>
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h" #include "base/bittorrent/sessionstatus.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/bittorrent/session.h"
static const qint64 SAVE_INTERVAL = 15 * 60 * 1000; static const qint64 SAVE_INTERVAL = 15 * 60 * 1000;

5
src/base/bittorrent/private/statistics.h

@ -4,7 +4,10 @@
#include <QObject> #include <QObject>
#include <QTimer> #include <QTimer>
namespace BitTorrent { class Session; } namespace BitTorrent
{
class Session;
}
class Statistics : QObject class Statistics : QObject
{ {

18
src/base/bittorrent/session.cpp

@ -29,6 +29,10 @@
#include "session.h" #include "session.h"
#include <cstdlib>
#include <queue>
#include <vector>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDateTime> #include <QDateTime>
#include <QDebug> #include <QDebug>
@ -43,10 +47,6 @@
#include <QTimer> #include <QTimer>
#include <QUuid> #include <QUuid>
#include <cstdlib>
#include <queue>
#include <vector>
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
#if LIBTORRENT_VERSION_NUM >= 10100 #if LIBTORRENT_VERSION_NUM >= 10100
#include <libtorrent/bdecode.hpp> #include <libtorrent/bdecode.hpp>
@ -71,24 +71,24 @@
#include <libtorrent/torrent_info.hpp> #include <libtorrent/torrent_info.hpp>
#include "base/logger.h" #include "base/logger.h"
#include "base/profile.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "base/net/portforwarder.h" #include "base/net/portforwarder.h"
#include "base/net/proxyconfigurationmanager.h" #include "base/net/proxyconfigurationmanager.h"
#include "base/profile.h"
#include "base/torrentfileguard.h" #include "base/torrentfileguard.h"
#include "base/torrentfilter.h" #include "base/torrentfilter.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "base/utils/net.h"
#include "base/utils/misc.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h"
#include "base/utils/net.h"
#include "base/utils/random.h" #include "base/utils/random.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "magneturi.h" #include "magneturi.h"
#include "private/filterparserthread.h"
#include "private/statistics.h"
#include "private/bandwidthscheduler.h" #include "private/bandwidthscheduler.h"
#include "private/filterparserthread.h"
#include "private/resumedatasavingmanager.h" #include "private/resumedatasavingmanager.h"
#include "private/statistics.h"
#include "torrenthandle.h" #include "torrenthandle.h"
#include "tracker.h" #include "tracker.h"
#include "trackerentry.h" #include "trackerentry.h"

19
src/base/bittorrent/torrenthandle.cpp

@ -27,21 +27,23 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "torrenthandle.h"
#include <algorithm> #include <algorithm>
#include <type_traits> #include <type_traits>
#include <QBitArray>
#include <QByteArray>
#include <QDebug> #include <QDebug>
#include <QStringList>
#include <QFile>
#include <QDir> #include <QDir>
#include <QByteArray> #include <QFile>
#include <QBitArray> #include <QStringList>
#include <libtorrent/entry.hpp>
#include <libtorrent/bencode.hpp>
#include <libtorrent/address.hpp> #include <libtorrent/address.hpp>
#include <libtorrent/alert_types.hpp> #include <libtorrent/alert_types.hpp>
#include <libtorrent/bencode.hpp>
#include <libtorrent/create_torrent.hpp> #include <libtorrent/create_torrent.hpp>
#include <libtorrent/entry.hpp>
#include <libtorrent/magnet_uri.hpp> #include <libtorrent/magnet_uri.hpp>
#if LIBTORRENT_VERSION_NUM >= 10100 #if LIBTORRENT_VERSION_NUM >= 10100
#include <libtorrent/time.hpp> #include <libtorrent/time.hpp>
@ -56,13 +58,12 @@
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/string.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "session.h" #include "base/utils/string.h"
#include "peerinfo.h" #include "peerinfo.h"
#include "session.h"
#include "trackerentry.h" #include "trackerentry.h"
#include "torrenthandle.h"
const QString QB_EXT {".!qB"}; const QString QB_EXT {".!qB"};

7
src/base/bittorrent/tracker.cpp

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,16 +25,15 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include <vector> #include <vector>
#include <libtorrent/bencode.hpp> #include <libtorrent/bencode.hpp>
#include <libtorrent/entry.hpp> #include <libtorrent/entry.hpp>
#include "base/preferences.h"
#include "base/http/server.h" #include "base/http/server.h"
#include "base/preferences.h"
#include "base/utils/string.h" #include "base/utils/string.h"
#include "tracker.h" #include "tracker.h"

11
src/base/bittorrent/tracker.h

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2015 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2010 Christophe Dumez * Copyright (C) 2010 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,17 +25,16 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef BITTORRENT_TRACKER_H #ifndef BITTORRENT_TRACKER_H
#define BITTORRENT_TRACKER_H #define BITTORRENT_TRACKER_H
#include <QHash> #include <QHash>
#include "base/http/types.h"
#include "base/http/responsebuilder.h"
#include "base/http/irequesthandler.h" #include "base/http/irequesthandler.h"
#include "base/http/responsebuilder.h"
#include "base/http/types.h"
namespace libtorrent namespace libtorrent
{ {
@ -82,7 +81,7 @@ namespace BitTorrent
Q_DISABLE_COPY(Tracker) Q_DISABLE_COPY(Tracker)
public: public:
explicit Tracker(QObject *parent = 0); explicit Tracker(QObject *parent = nullptr);
~Tracker(); ~Tracker();
bool start(); bool start();

4
src/base/filesystemwatcher.cpp

@ -12,9 +12,9 @@
#endif #endif
#endif #endif
#include "base/preferences.h"
#include "base/bittorrent/torrentinfo.h"
#include "base/bittorrent/magneturi.h" #include "base/bittorrent/magneturi.h"
#include "base/bittorrent/torrentinfo.h"
#include "base/preferences.h"
#include "filesystemwatcher.h" #include "filesystemwatcher.h"
#ifndef CIFS_MAGIC_NUMBER #ifndef CIFS_MAGIC_NUMBER

8
src/base/filesystemwatcher.h

@ -1,12 +1,12 @@
#ifndef FILESYSTEMWATCHER_H #ifndef FILESYSTEMWATCHER_H
#define FILESYSTEMWATCHER_H #define FILESYSTEMWATCHER_H
#include <QFileSystemWatcher>
#include <QDir> #include <QDir>
#include <QTimer> #include <QFileSystemWatcher>
#include <QHash>
#include <QPointer> #include <QPointer>
#include <QStringList> #include <QStringList>
#include <QHash> #include <QTimer>
/* /*
* Subclassing QFileSystemWatcher in order to support Network File * Subclassing QFileSystemWatcher in order to support Network File
@ -17,7 +17,7 @@ class FileSystemWatcher : public QFileSystemWatcher
Q_OBJECT Q_OBJECT
public: public:
explicit FileSystemWatcher(QObject *parent = 0); explicit FileSystemWatcher(QObject *parent = nullptr);
~FileSystemWatcher(); ~FileSystemWatcher();
QStringList directories() const; QStringList directories() const;

75
src/base/http/requestparser.cpp

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Ishan Arora and Christophe Dumez * Copyright (C) 2006 Ishan Arora and Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,21 +25,20 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "requestparser.h"
#include <QDebug>
#include <QDir>
#include <QStringList> #include <QStringList>
#include <QUrl> #include <QUrl>
#include <QUrlQuery> #include <QUrlQuery>
#include <QDir>
#include <QDebug>
#include "requestparser.h"
const QByteArray EOL("\r\n"); const QByteArray EOL("\r\n");
const QByteArray EOH("\r\n\r\n"); const QByteArray EOH("\r\n\r\n");
inline QString unquoted(const QString& str) inline QString unquoted(const QString &str)
{ {
if ((str[0] == '\"') && (str[str.length() - 1] == '\"')) if ((str[0] == '\"') && (str[str.length() - 1] == '\"'))
return str.mid(1, str.length() - 2); return str.mid(1, str.length() - 2);
@ -49,7 +48,7 @@ inline QString unquoted(const QString& str)
using namespace Http; using namespace Http;
RequestParser::ErrorCode RequestParser::parse(const QByteArray& data, Request& request, uint maxContentLength) RequestParser::ErrorCode RequestParser::parse(const QByteArray &data, Request &request, uint maxContentLength)
{ {
return RequestParser(maxContentLength).parseHttpRequest(data, request); return RequestParser(maxContentLength).parseHttpRequest(data, request);
} }
@ -59,42 +58,42 @@ RequestParser::RequestParser(uint maxContentLength)
{ {
} }
RequestParser::ErrorCode RequestParser::parseHttpRequest(const QByteArray& data, Request& request) RequestParser::ErrorCode RequestParser::parseHttpRequest(const QByteArray &data, Request &request)
{ {
m_request = Request(); m_request = Request();
// Parse HTTP request header // Parse HTTP request header
const int header_end = data.indexOf(EOH); const int headerEnd = data.indexOf(EOH);
if (header_end < 0) { if (headerEnd < 0) {
qDebug() << Q_FUNC_INFO << "incomplete request"; qDebug() << Q_FUNC_INFO << "incomplete request";
return IncompleteRequest; return IncompleteRequest;
} }
if (!parseHttpHeader(data.left(header_end))) { if (!parseHttpHeader(data.left(headerEnd))) {
qWarning() << Q_FUNC_INFO << "header parsing error"; qWarning() << Q_FUNC_INFO << "header parsing error";
return BadRequest; return BadRequest;
} }
// Parse HTTP request message // Parse HTTP request message
if (m_request.headers.contains("content-length")) { if (m_request.headers.contains("content-length")) {
int content_length = m_request.headers["content-length"].toInt(); int contentLength = m_request.headers["content-length"].toInt();
if (content_length < 0) { if (contentLength < 0) {
qWarning() << Q_FUNC_INFO << "bad request: content-length negative"; qWarning() << Q_FUNC_INFO << "bad request: content-length is negative";
return BadRequest; return BadRequest;
} }
if (content_length > static_cast<int>(m_maxContentLength)) { if (contentLength > static_cast<int>(m_maxContentLength)) {
qWarning() << Q_FUNC_INFO << "bad request: message too long"; qWarning() << Q_FUNC_INFO << "bad request: message too long";
return BadRequest; return BadRequest;
} }
QByteArray content = data.mid(header_end + EOH.length(), content_length); QByteArray content = data.mid(headerEnd + EOH.length(), contentLength);
if (content.length() < content_length) { if (content.length() < contentLength) {
qDebug() << Q_FUNC_INFO << "incomplete request"; qDebug() << Q_FUNC_INFO << "incomplete request";
return IncompleteRequest; return IncompleteRequest;
} }
if ((content_length > 0) && !parseContent(content)) { if ((contentLength > 0) && !parseContent(content)) {
qWarning() << Q_FUNC_INFO << "message parsing error"; qWarning() << Q_FUNC_INFO << "message parsing error";
return BadRequest; return BadRequest;
} }
@ -102,7 +101,7 @@ RequestParser::ErrorCode RequestParser::parseHttpRequest(const QByteArray& data,
// qDebug() << Q_FUNC_INFO; // qDebug() << Q_FUNC_INFO;
// qDebug() << "HTTP Request header:"; // qDebug() << "HTTP Request header:";
// qDebug() << data.left(header_end) << "\n"; // qDebug() << data.left(headerEnd) << "\n";
request = m_request; request = m_request;
return NoError; return NoError;
@ -132,7 +131,7 @@ bool RequestParser::parseStartingLine(const QString &line)
return false; return false;
} }
bool RequestParser::parseHeaderLine(const QString &line, QPair<QString, QString>& out) bool RequestParser::parseHeaderLine(const QString &line, QPair<QString, QString> &out)
{ {
int i = line.indexOf(QLatin1Char(':')); int i = line.indexOf(QLatin1Char(':'));
if (i == -1) { if (i == -1) {
@ -150,7 +149,7 @@ bool RequestParser::parseHttpHeader(const QByteArray &data)
QStringList lines = str.trimmed().split(EOL); QStringList lines = str.trimmed().split(EOL);
QStringList headerLines; QStringList headerLines;
foreach (const QString& line, lines) { foreach (const QString &line, lines) {
if (line[0].isSpace()) { // header line continuation if (line[0].isSpace()) { // header line continuation
if (!headerLines.isEmpty()) { // really continuation if (!headerLines.isEmpty()) { // really continuation
headerLines.last() += QLatin1Char(' '); headerLines.last() += QLatin1Char(' ');
@ -181,7 +180,7 @@ bool RequestParser::parseHttpHeader(const QByteArray &data)
return true; return true;
} }
QList<QByteArray> RequestParser::splitMultipartData(const QByteArray& data, const QByteArray& boundary) QList<QByteArray> RequestParser::splitMultipartData(const QByteArray &data, const QByteArray &boundary)
{ {
QList<QByteArray> ret; QList<QByteArray> ret;
QByteArray sep = boundary + EOL; QByteArray sep = boundary + EOL;
@ -205,7 +204,7 @@ QList<QByteArray> RequestParser::splitMultipartData(const QByteArray& data, cons
return ret; return ret;
} }
bool RequestParser::parseContent(const QByteArray& data) bool RequestParser::parseContent(const QByteArray &data)
{ {
// Parse message content // Parse message content
qDebug() << Q_FUNC_INFO << "Content-Length: " << m_request.headers["content-length"]; qDebug() << Q_FUNC_INFO << "Content-Length: " << m_request.headers["content-length"];
@ -243,14 +242,14 @@ Content-Disposition: form-data; name=\"Upload\"
Submit Query Submit Query
--cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5-- --cH2ae0GI3KM7GI3Ij5ae0ei4Ij5Ij5--
**/ **/
QString content_type = m_request.headers["content-type"]; QString contentType = m_request.headers["content-type"];
if (content_type.startsWith("multipart/form-data")) { if (contentType.startsWith("multipart/form-data")) {
const QRegExp boundaryRegexQuoted("boundary=\"([ \\w'()+,-\\./:=\\?]+)\""); const QRegExp boundaryRegexQuoted("boundary=\"([ \\w'()+,-\\./:=\\?]+)\"");
const QRegExp boundaryRegexNotQuoted("boundary=([\\w'()+,-\\./:=\\?]+)"); const QRegExp boundaryRegexNotQuoted("boundary=([\\w'()+,-\\./:=\\?]+)");
QByteArray boundary; QByteArray boundary;
if (boundaryRegexQuoted.indexIn(content_type) < 0) { if (boundaryRegexQuoted.indexIn(contentType) < 0) {
if (boundaryRegexNotQuoted.indexIn(content_type) < 0) { if (boundaryRegexNotQuoted.indexIn(contentType) < 0) {
qWarning() << "Could not find boundary in multipart/form-data header!"; qWarning() << "Could not find boundary in multipart/form-data header!";
return false; return false;
} }
@ -274,21 +273,21 @@ Submit Query
return true; return true;
} }
qWarning() << Q_FUNC_INFO << "unknown content type:" << qPrintable(content_type); qWarning() << Q_FUNC_INFO << "unknown content type:" << qPrintable(contentType);
return false; return false;
} }
bool RequestParser::parseFormData(const QByteArray& data) bool RequestParser::parseFormData(const QByteArray &data)
{ {
// Parse form data header // Parse form data header
const int header_end = data.indexOf(EOH); const int headerEnd = data.indexOf(EOH);
if (header_end < 0) { if (headerEnd < 0) {
qDebug() << "Invalid form data: \n" << data; qDebug() << "Invalid form data: \n" << data;
return false; return false;
} }
QString header_str = QString::fromUtf8(data.left(header_end)); QString headerStr = QString::fromUtf8(data.left(headerEnd));
QStringList lines = header_str.trimmed().split(EOL); QStringList lines = headerStr.trimmed().split(EOL);
QStringMap headers; QStringMap headers;
foreach (const QString& line, lines) { foreach (const QString& line, lines) {
QPair<QString, QString> header; QPair<QString, QString> header;
@ -302,7 +301,7 @@ bool RequestParser::parseFormData(const QByteArray& data)
if (!headers.contains("content-disposition") if (!headers.contains("content-disposition")
|| !parseHeaderValue(headers["content-disposition"], disposition) || !parseHeaderValue(headers["content-disposition"], disposition)
|| !disposition.contains("name")) { || !disposition.contains("name")) {
qDebug() << "Invalid form data header: \n" << header_str; qDebug() << "Invalid form data header: \n" << headerStr;
return false; return false;
} }
@ -310,18 +309,18 @@ bool RequestParser::parseFormData(const QByteArray& data)
UploadedFile ufile; UploadedFile ufile;
ufile.filename = disposition["filename"]; ufile.filename = disposition["filename"];
ufile.type = disposition["content-type"]; ufile.type = disposition["content-type"];
ufile.data = data.mid(header_end + EOH.length()); ufile.data = data.mid(headerEnd + EOH.length());
m_request.files.append(ufile); m_request.files.append(ufile);
} }
else { else {
m_request.posts[disposition["name"]] = QString::fromUtf8(data.mid(header_end + EOH.length())); m_request.posts[disposition["name"]] = QString::fromUtf8(data.mid(headerEnd + EOH.length()));
} }
return true; return true;
} }
bool RequestParser::parseHeaderValue(const QString& value, QStringMap& out) bool RequestParser::parseHeaderValue(const QString &value, QStringMap &out)
{ {
int pos = value.indexOf(QLatin1Char(';')); int pos = value.indexOf(QLatin1Char(';'));
if (pos == -1) { if (pos == -1) {

4
src/base/http/requestparser.h

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Ishan Arora and Christophe Dumez * Copyright (C) 2006 Ishan Arora and Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef HTTP_REQUESTPARSER_H #ifndef HTTP_REQUESTPARSER_H

2
src/base/http/responsebuilder.h

@ -37,7 +37,7 @@ namespace Http
class ResponseBuilder : public QObject class ResponseBuilder : public QObject
{ {
public: public:
explicit ResponseBuilder(QObject *parent = 0); explicit ResponseBuilder(QObject *parent = nullptr);
protected: protected:
void status(uint code = 200, const QString &text = QLatin1String("OK")); void status(uint code = 200, const QString &text = QLatin1String("OK"));

6
src/base/http/responsegenerator.cpp

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Ishan Arora and Christophe Dumez * Copyright (C) 2006 Ishan Arora and Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "responsegenerator.h" #include "responsegenerator.h"
@ -69,7 +67,7 @@ QByteArray Http::toByteArray(Response response)
QString Http::httpDate() QString Http::httpDate()
{ {
// [RFC 7231] 7.1.1.1. Date/Time Formats // [RFC 7231] 7.1.1.1. Date/Time Formats
// example: "Sun, 06 Nov 1994 08:49:37 GMT" // example: "Sun, 06 Nov 1994 08:49:37 GMT"
return QLocale::c().toString(QDateTime::currentDateTimeUtc(), QLatin1String("ddd, dd MMM yyyy HH:mm:ss")) return QLocale::c().toString(QDateTime::currentDateTimeUtc(), QLatin1String("ddd, dd MMM yyyy HH:mm:ss"))
.append(QLatin1String(" GMT")); .append(QLatin1String(" GMT"));

4
src/base/http/responsegenerator.h

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru> * Copyright (C) 2014 Vladimir Golovnev <glassez@yandex.ru>
* Copyright (C) 2006 Ishan Arora and Christophe Dumez * Copyright (C) 2006 Ishan Arora and Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -25,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */

9
src/base/http/server.cpp

@ -34,7 +34,6 @@
#include <QNetworkProxy> #include <QNetworkProxy>
#include <QStringList> #include <QStringList>
#include <QTimer> #include <QTimer>
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
#include <QSslSocket> #include <QSslSocket>
#else #else
@ -123,15 +122,13 @@ bool Server::setupHttps(const QByteArray &certificates, const QByteArray &key)
const QList<QSslCertificate> certs = QSslCertificate::fromData(certificates); const QList<QSslCertificate> certs = QSslCertificate::fromData(certificates);
const bool areCertsValid = !certs.empty() && std::all_of(certs.begin(), certs.end(), [](const QSslCertificate &c) { return !c.isNull(); }); const bool areCertsValid = !certs.empty() && std::all_of(certs.begin(), certs.end(), [](const QSslCertificate &c) { return !c.isNull(); });
if (!sslKey.isNull() && areCertsValid) if (!sslKey.isNull() && areCertsValid) {
{
m_key = sslKey; m_key = sslKey;
m_certificates = certs; m_certificates = certs;
m_https = true; m_https = true;
return true; return true;
} }
else else {
{
disableHttps(); disableHttps();
return false; return false;
} }
@ -164,4 +161,4 @@ QList<QSslCipher> Server::safeCipherList() const
return safeCiphers; return safeCiphers;
} }
#endif #endif // QT_NO_OPENSSL

8
src/base/http/server.h

@ -25,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
@ -46,13 +44,13 @@ namespace Http
class IRequestHandler; class IRequestHandler;
class Connection; class Connection;
class Server: public QTcpServer class Server : public QTcpServer
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(Server) Q_DISABLE_COPY(Server)
public: public:
Server(IRequestHandler *requestHandler, QObject *parent = 0); Server(IRequestHandler *requestHandler, QObject *parent = nullptr);
~Server(); ~Server();
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
@ -67,7 +65,7 @@ namespace Http
void incomingConnection(qintptr socketDescriptor); void incomingConnection(qintptr socketDescriptor);
IRequestHandler *m_requestHandler; IRequestHandler *m_requestHandler;
QList<Connection *> m_connections; // for tracking persistence connections QList<Connection *> m_connections; // for tracking persistent connections
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
QList<QSslCipher> safeCipherList() const; QList<QSslCipher> safeCipherList() const;

13
src/base/net/dnsupdater.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include <QDebug> #include <QDebug>
@ -34,8 +32,8 @@
#include <QUrlQuery> #include <QUrlQuery>
#include "base/logger.h" #include "base/logger.h"
#include "base/net/downloadmanager.h"
#include "base/net/downloadhandler.h" #include "base/net/downloadhandler.h"
#include "base/net/downloadmanager.h"
#include "dnsupdater.h" #include "dnsupdater.h"
using namespace Net; using namespace Net;
@ -143,7 +141,7 @@ QString DNSUpdater::getUpdateUrl() const
Q_ASSERT(!m_lastIP.isNull()); Q_ASSERT(!m_lastIP.isNull());
// Service specific // Service specific
switch(m_service) { switch (m_service) {
case DNS::DYNDNS: case DNS::DYNDNS:
url.setHost("members.dyndns.org"); url.setHost("members.dyndns.org");
break; break;
@ -230,7 +228,6 @@ void DNSUpdater::processIPUpdateReply(const QString &reply)
if (code == "abuse") { if (code == "abuse") {
logger->addMessage(tr("Dynamic DNS error: Your username was blocked due to abuse."), Log::CRITICAL); logger->addMessage(tr("Dynamic DNS error: Your username was blocked due to abuse."), Log::CRITICAL);
m_state = FATAL; m_state = FATAL;
return;
} }
} }
@ -289,7 +286,7 @@ void DNSUpdater::updateCredentials()
QUrl DNSUpdater::getRegistrationUrl(int service) QUrl DNSUpdater::getRegistrationUrl(int service)
{ {
switch(service) { switch (service) {
case DNS::DYNDNS: case DNS::DYNDNS:
return QUrl("https://www.dyndns.com/account/services/hosts/add.html"); return QUrl("https://www.dyndns.com/account/services/hosts/add.html");
case DNS::NOIP: case DNS::NOIP:

14
src/base/net/dnsupdater.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,16 +24,14 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef DNSUPDATER_H #ifndef DNSUPDATER_H
#define DNSUPDATER_H #define DNSUPDATER_H
#include <QObject>
#include <QHostAddress>
#include <QDateTime> #include <QDateTime>
#include <QHostAddress>
#include <QObject>
#include <QTimer> #include <QTimer>
#include "base/preferences.h" #include "base/preferences.h"
@ -41,12 +39,12 @@
namespace Net namespace Net
{ {
// Based on http://www.dyndns.com/developers/specs/ // Based on http://www.dyndns.com/developers/specs/
class DNSUpdater: public QObject class DNSUpdater : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit DNSUpdater(QObject *parent = 0); explicit DNSUpdater(QObject *parent = nullptr);
~DNSUpdater(); ~DNSUpdater();
static QUrl getRegistrationUrl(int service); static QUrl getRegistrationUrl(int service);

17
src/base/net/downloadhandler.cpp

@ -27,20 +27,21 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include <QTemporaryFile> #include "downloadhandler.h"
#include <QDebug>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkProxy>
#include <QNetworkCookie> #include <QNetworkCookie>
#include <QNetworkProxy>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QTemporaryFile>
#include <QUrl> #include <QUrl>
#include <QDebug>
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/gzip.h" #include "base/utils/gzip.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "downloadmanager.h" #include "downloadmanager.h"
#include "downloadhandler.h"
static QString errorCodeToString(QNetworkReply::NetworkError status); static QString errorCodeToString(QNetworkReply::NetworkError status);
@ -192,14 +193,14 @@ void DownloadHandler::handleRedirection(QUrl newUrl)
m_reply->deleteLater(); m_reply->deleteLater();
m_reply = tmp->m_reply; m_reply = tmp->m_reply;
init(); init();
tmp->m_reply = 0; tmp->m_reply = nullptr;
delete tmp; delete tmp;
} }
} }
QString errorCodeToString(QNetworkReply::NetworkError status) QString errorCodeToString(QNetworkReply::NetworkError status)
{ {
switch(status) { switch (status) {
case QNetworkReply::HostNotFoundError: case QNetworkReply::HostNotFoundError:
return QObject::tr("The remote host name was not found (invalid hostname)"); return QObject::tr("The remote host name was not found (invalid hostname)");
case QNetworkReply::OperationCanceledError: case QNetworkReply::OperationCanceledError:

2
src/base/net/downloadhandler.h

@ -32,11 +32,9 @@
#include <QObject> #include <QObject>
QT_BEGIN_NAMESPACE
class QNetworkAccessManager; class QNetworkAccessManager;
class QNetworkReply; class QNetworkReply;
class QUrl; class QUrl;
QT_END_NAMESPACE
namespace Net namespace Net
{ {

19
src/base/net/geoipmanager.cpp

@ -27,21 +27,22 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include "geoipmanager.h"
#include <QDateTime>
#include <QDebug> #include <QDebug>
#include <QFile>
#include <QDir> #include <QDir>
#include <QFile>
#include <QHostAddress> #include <QHostAddress>
#include <QDateTime>
#include "base/logger.h" #include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/profile.h" #include "base/profile.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/gzip.h" #include "base/utils/gzip.h"
#include "downloadmanager.h"
#include "downloadhandler.h" #include "downloadhandler.h"
#include "downloadmanager.h"
#include "private/geoipdatabase.h" #include "private/geoipdatabase.h"
#include "geoipmanager.h"
static const char DATABASE_URL[] = "https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz"; static const char DATABASE_URL[] = "https://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz";
static const char GEOIP_FOLDER[] = "GeoIP"; static const char GEOIP_FOLDER[] = "GeoIP";
@ -52,11 +53,11 @@ using namespace Net;
// GeoIPManager // GeoIPManager
GeoIPManager *GeoIPManager::m_instance = 0; GeoIPManager *GeoIPManager::m_instance = nullptr;
GeoIPManager::GeoIPManager() GeoIPManager::GeoIPManager()
: m_enabled(false) : m_enabled(false)
, m_geoIPDatabase(0) , m_geoIPDatabase(nullptr)
{ {
configure(); configure();
connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure())); connect(Preferences::instance(), SIGNAL(changed()), SLOT(configure()));
@ -78,7 +79,7 @@ void GeoIPManager::freeInstance()
{ {
if (m_instance) { if (m_instance) {
delete m_instance; delete m_instance;
m_instance = 0; m_instance = nullptr;
} }
} }
@ -91,7 +92,7 @@ void GeoIPManager::loadDatabase()
{ {
if (m_geoIPDatabase) { if (m_geoIPDatabase) {
delete m_geoIPDatabase; delete m_geoIPDatabase;
m_geoIPDatabase = 0; m_geoIPDatabase = nullptr;
} }
QString filepath = Utils::Fs::expandPathAbs( QString filepath = Utils::Fs::expandPathAbs(
@ -407,7 +408,7 @@ void GeoIPManager::configure()
} }
else if (!m_enabled && m_geoIPDatabase) { else if (!m_enabled && m_geoIPDatabase) {
delete m_geoIPDatabase; delete m_geoIPDatabase;
m_geoIPDatabase = 0; m_geoIPDatabase = nullptr;
} }
} }
} }

2
src/base/net/geoipmanager.h

@ -30,8 +30,8 @@
#ifndef NET_GEOIPMANAGER_H #ifndef NET_GEOIPMANAGER_H
#define NET_GEOIPMANAGER_H #define NET_GEOIPMANAGER_H
#include <QObject>
#include <QCache> #include <QCache>
#include <QObject>
class QHostAddress; class QHostAddress;
class QString; class QString;

4
src/base/net/portforwarder.cpp

@ -65,7 +65,7 @@ void PortForwarder::freeInstance()
{ {
if (m_instance) { if (m_instance) {
delete m_instance; delete m_instance;
m_instance = 0; m_instance = nullptr;
} }
} }
@ -143,4 +143,4 @@ void PortForwarder::stop()
Logger::instance()->addMessage(tr("UPnP / NAT-PMP support [OFF]"), Log::INFO); Logger::instance()->addMessage(tr("UPnP / NAT-PMP support [OFF]"), Log::INFO);
} }
PortForwarder *PortForwarder::m_instance = 0; PortForwarder *PortForwarder::m_instance = nullptr;

4
src/base/net/portforwarder.h

@ -29,8 +29,8 @@
#ifndef NET_PORTFORWARDER_H #ifndef NET_PORTFORWARDER_H
#define NET_PORTFORWARDER_H #define NET_PORTFORWARDER_H
#include <QObject>
#include <QHash> #include <QHash>
#include <QObject>
namespace libtorrent namespace libtorrent
{ {
@ -56,7 +56,7 @@ namespace Net
void deletePort(quint16 port); void deletePort(quint16 port);
private: private:
explicit PortForwarder(libtorrent::session *const provider, QObject *parent = 0); explicit PortForwarder(libtorrent::session *const provider, QObject *parent = nullptr);
~PortForwarder(); ~PortForwarder();
void start(); void start();

23
src/base/net/smtp.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
/* /*
@ -33,22 +31,23 @@
*/ */
#include "smtp.h" #include "smtp.h"
#include "base/preferences.h"
#include "base/logger.h"
#include <QCryptographicHash>
#include <QDebug>
#include <QHostAddress>
#include <QHostInfo>
#include <QNetworkInterface>
#include <QStringList>
#include <QTextCodec>
#include <QTextStream> #include <QTextStream>
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
#include <QSslSocket> #include <QSslSocket>
#else #else
#include <QTcpSocket> #include <QTcpSocket>
#endif #endif
#include <QTextCodec>
#include <QDebug> #include "base/logger.h"
#include <QHostAddress> #include "base/preferences.h"
#include <QHostInfo>
#include <QNetworkInterface>
#include <QCryptographicHash>
#include <QStringList>
namespace namespace
{ {

18
src/base/net/smtp.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christophe Dumez * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
/* /*
@ -35,22 +33,20 @@
#ifndef SMTP_H #ifndef SMTP_H
#define SMTP_H #define SMTP_H
#include <QString> #include <QAbstractSocket>
#include <QObject>
#include <QByteArray> #include <QByteArray>
#include <QHash> #include <QHash>
#include <QAbstractSocket>
#include <QMetaType> #include <QMetaType>
#include <QObject>
#include <QString>
QT_BEGIN_NAMESPACE
class QTextStream;
#ifndef QT_NO_OPENSSL #ifndef QT_NO_OPENSSL
class QSslSocket; class QSslSocket;
#else #else
class QTcpSocket; class QTcpSocket;
#endif #endif
class QTextCodec; class QTextCodec;
QT_END_NAMESPACE class QTextStream;
namespace Net namespace Net
{ {
@ -59,7 +55,7 @@ namespace Net
Q_OBJECT Q_OBJECT
public: public:
Smtp(QObject *parent = 0); Smtp(QObject *parent = nullptr);
~Smtp(); ~Smtp();
void sendMail(const QString &from, const QString &to, const QString &subject, const QString &body); void sendMail(const QString &from, const QString &to, const QString &subject, const QString &body);
@ -126,4 +122,4 @@ namespace Net
}; };
} }
#endif #endif // SMTP_H

4
src/gui/banlistoptions.cpp

@ -27,15 +27,15 @@
*/ */
#include "banlistoptions.h" #include "banlistoptions.h"
#include "ui_banlistoptions.h"
#include <QMessageBox>
#include <QHostAddress> #include <QHostAddress>
#include <QMessageBox>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QStringListModel> #include <QStringListModel>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/utils/net.h" #include "base/utils/net.h"
#include "ui_banlistoptions.h"
BanListOptions::BanListOptions(QWidget *parent) BanListOptions::BanListOptions(QWidget *parent)
: QDialog(parent) : QDialog(parent)

4
src/gui/banlistoptions.h

@ -39,12 +39,12 @@ namespace Ui
class BanListOptions; class BanListOptions;
} }
class BanListOptions: public QDialog class BanListOptions : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit BanListOptions(QWidget *parent = 0); explicit BanListOptions(QWidget *parent = nullptr);
~BanListOptions(); ~BanListOptions();
private slots: private slots:

4
src/gui/cookiesdialog.cpp

@ -30,10 +30,10 @@
#include <algorithm> #include <algorithm>
#include "base/settingsstorage.h"
#include "base/net/downloadmanager.h" #include "base/net/downloadmanager.h"
#include "guiiconprovider.h" #include "base/settingsstorage.h"
#include "cookiesmodel.h" #include "cookiesmodel.h"
#include "guiiconprovider.h"
#include "ui_cookiesdialog.h" #include "ui_cookiesdialog.h"
#define SETTINGS_KEY(name) "CookiesDialog/" name #define SETTINGS_KEY(name) "CookiesDialog/" name

2
src/gui/cookiesdialog.h

@ -43,7 +43,7 @@ class CookiesDialog : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit CookiesDialog(QWidget *parent = 0); explicit CookiesDialog(QWidget *parent = nullptr);
~CookiesDialog(); ~CookiesDialog();
public slots: public slots:

6
src/gui/cookiesmodel.cpp

@ -26,9 +26,10 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include <QDateTime>
#include "cookiesmodel.h" #include "cookiesmodel.h"
#include <QDateTime>
CookiesModel::CookiesModel(const QList<QNetworkCookie> &cookies, QObject *parent) CookiesModel::CookiesModel(const QList<QNetworkCookie> &cookies, QObject *parent)
: QAbstractItemModel(parent) : QAbstractItemModel(parent)
, m_cookies(cookies) , m_cookies(cookies)
@ -43,8 +44,7 @@ QList<QNetworkCookie> CookiesModel::cookies() const
QVariant CookiesModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant CookiesModel::headerData(int section, Qt::Orientation orientation, int role) const
{ {
if ((role == Qt::DisplayRole) && (orientation == Qt::Horizontal)) { if ((role == Qt::DisplayRole) && (orientation == Qt::Horizontal)) {
switch (section) switch (section) {
{
case COL_DOMAIN: case COL_DOMAIN:
return tr("Domain"); return tr("Domain");
case COL_PATH: case COL_PATH:

2
src/gui/cookiesmodel.h

@ -49,7 +49,7 @@ public:
NB_COLUMNS NB_COLUMNS
}; };
explicit CookiesModel(const QList<QNetworkCookie> &cookies, QObject *parent = 0); explicit CookiesModel(const QList<QNetworkCookie> &cookies, QObject *parent = nullptr);
QList<QNetworkCookie> cookies() const; QList<QNetworkCookie> cookies() const;

95
src/gui/previewlistdelegate.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,73 +24,78 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef PREVIEWLISTDELEGATE_H #ifndef PREVIEWLISTDELEGATE_H
#define PREVIEWLISTDELEGATE_H #define PREVIEWLISTDELEGATE_H
#include <QApplication>
#include <QItemDelegate> #include <QItemDelegate>
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#include <QModelIndex> #include <QModelIndex>
#include <QPainter> #include <QPainter>
#include <QApplication>
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "previewselectdialog.h"
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <QProxyStyle> #include <QProxyStyle>
#endif #endif
#include <QStyleOptionProgressBar>
#include <QStyleOptionViewItem>
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "previewselectdialog.h"
class PreviewListDelegate: public QItemDelegate { class PreviewListDelegate : public QItemDelegate
Q_OBJECT {
Q_OBJECT
public: public:
PreviewListDelegate(QObject *parent=0) : QItemDelegate(parent) {} PreviewListDelegate(QObject *parent = nullptr)
: QItemDelegate(parent)
{
}
~PreviewListDelegate() {} ~PreviewListDelegate() {}
void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const { void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
painter->save(); {
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option); painter->save();
QStyleOptionViewItem opt = QItemDelegate::setOptions(index, option);
switch(index.column()) { switch (index.column()) {
case PreviewSelectDialog::SIZE: case PreviewSelectDialog::SIZE:
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong())); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(index.data().toLongLong()));
break; break;
case PreviewSelectDialog::PROGRESS:{ case PreviewSelectDialog::PROGRESS: {
QStyleOptionProgressBar newopt; QStyleOptionProgressBar newopt;
qreal progress = index.data().toDouble()*100.; qreal progress = index.data().toDouble() * 100.;
newopt.rect = opt.rect; newopt.rect = opt.rect;
newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%"); newopt.text = ((progress == 100.0) ? QString("100%") : Utils::String::fromDouble(progress, 1) + "%");
newopt.progress = static_cast<int>(progress); newopt.progress = static_cast<int>(progress);
newopt.maximum = 100; newopt.maximum = 100;
newopt.minimum = 0; newopt.minimum = 0;
newopt.state |= QStyle::State_Enabled; newopt.state |= QStyle::State_Enabled;
newopt.textVisible = true; newopt.textVisible = true;
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter); QApplication::style()->drawControl(QStyle::CE_ProgressBar, &newopt, painter);
#else #else
// XXX: To avoid having the progress text on the right of the bar // XXX: To avoid having the progress text on the right of the bar
QProxyStyle st("fusion"); QProxyStyle st("fusion");
st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0); st.drawControl(QStyle::CE_ProgressBar, &newopt, painter, 0);
#endif #endif
break; }
} break;
default: default:
QItemDelegate::paint(painter, option, index); QItemDelegate::paint(painter, option, index);
} }
painter->restore();
painter->restore();
} }
QWidget* createEditor(QWidget*, const QStyleOptionViewItem &, const QModelIndex &) const { QWidget *createEditor(QWidget *, const QStyleOptionViewItem &, const QModelIndex &) const
// No editor here {
return 0; // No editor here
return nullptr;
} }
}; };
#endif #endif // PREVIEWLISTDELEGATE_H

37
src/gui/properties/peerlistdelegate.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef PEERLISTDELEGATE_H #ifndef PEERLISTDELEGATE_H
@ -38,7 +36,7 @@
#include "base/utils/misc.h" #include "base/utils/misc.h"
#include "base/utils/string.h" #include "base/utils/string.h"
class PeerListDelegate: public QItemDelegate class PeerListDelegate : public QItemDelegate
{ {
Q_OBJECT Q_OBJECT
@ -77,34 +75,33 @@ public:
QItemDelegate::drawBackground(painter, opt, index); QItemDelegate::drawBackground(painter, opt, index);
switch (index.column()) { switch (index.column()) {
case PORT: { case PORT:
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString()); QItemDelegate::drawDisplay(painter, opt, option.rect, index.data().toString());
}
break; break;
case TOT_DOWN: case TOT_DOWN:
case TOT_UP: { case TOT_UP: {
qlonglong size = index.data().toLongLong(); qlonglong size = index.data().toLongLong();
if (hideValues && (size <= 0)) if (hideValues && (size <= 0))
break; break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size)); QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::friendlyUnit(size));
} }
break; break;
case DOWN_SPEED: case DOWN_SPEED:
case UP_SPEED: { case UP_SPEED: {
qreal speed = index.data().toDouble(); qreal speed = index.data().toDouble();
if (speed <= 0.0) if (speed <= 0.0)
break; break;
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true)); QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::Misc::friendlyUnit(speed, true));
} }
break; break;
case PROGRESS: case PROGRESS:
case RELEVANCE: { case RELEVANCE: {
qreal progress = index.data().toDouble(); qreal progress = index.data().toDouble();
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + "%"); QItemDelegate::drawDisplay(painter, opt, opt.rect, Utils::String::fromDouble(progress * 100.0, 1) + "%");
} }
break; break;
default: default:

4
src/gui/properties/peerlistsortmodel.h

@ -34,12 +34,12 @@
#include "peerlistdelegate.h" #include "peerlistdelegate.h"
class PeerListSortModel: public QSortFilterProxyModel class PeerListSortModel : public QSortFilterProxyModel
{ {
Q_OBJECT Q_OBJECT
public: public:
PeerListSortModel(QObject *parent = 0) PeerListSortModel(QObject *parent = nullptr)
: QSortFilterProxyModel(parent) : QSortFilterProxyModel(parent)
{ {
} }

30
src/gui/properties/peerlistwidget.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,36 +24,34 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "peerlistwidget.h" #include "peerlistwidget.h"
#include <QApplication> #include <QApplication>
#include <QStandardItemModel> #include <QClipboard>
#include <QSortFilterProxyModel>
#include <QSet>
#include <QHeaderView> #include <QHeaderView>
#include <QMenu> #include <QMenu>
#include <QClipboard>
#include <QMessageBox> #include <QMessageBox>
#include <QWheelEvent> #include <QSet>
#include <QSortFilterProxyModel>
#include <QStandardItemModel>
#include <QTableView> #include <QTableView>
#include <QWheelEvent>
#include "base/net/reverseresolution.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/peerinfo.h" #include "base/bittorrent/peerinfo.h"
#include "base/preferences.h" #include "base/bittorrent/torrenthandle.h"
#include "base/logger.h" #include "base/logger.h"
#include "base/unicodestrings.h"
#include "propertieswidget.h"
#include "base/net/geoipmanager.h" #include "base/net/geoipmanager.h"
#include "peersadditiondlg.h" #include "base/net/reverseresolution.h"
#include "speedlimitdlg.h" #include "base/preferences.h"
#include "base/unicodestrings.h"
#include "guiiconprovider.h" #include "guiiconprovider.h"
#include "peerlistdelegate.h" #include "peerlistdelegate.h"
#include "peerlistsortmodel.h" #include "peerlistsortmodel.h"
#include "peersadditiondlg.h"
#include "propertieswidget.h"
#include "speedlimitdlg.h"
PeerListWidget::PeerListWidget(PropertiesWidget *parent) PeerListWidget::PeerListWidget(PropertiesWidget *parent)
: QTreeView(parent) : QTreeView(parent)

12
src/gui/properties/peerlistwidget.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,18 +24,16 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef PEERLISTWIDGET_H #ifndef PEERLISTWIDGET_H
#define PEERLISTWIDGET_H #define PEERLISTWIDGET_H
#include <QTreeView>
#include <QHash> #include <QHash>
#include <QPointer> #include <QPointer>
#include <QSet> #include <QSet>
#include <QShortcut> #include <QShortcut>
#include <QTreeView>
namespace Net namespace Net
{ {
@ -46,11 +44,9 @@ class PeerListDelegate;
class PeerListSortModel; class PeerListSortModel;
class PropertiesWidget; class PropertiesWidget;
QT_BEGIN_NAMESPACE
class QSortFilterProxyModel; class QSortFilterProxyModel;
class QStandardItem; class QStandardItem;
class QStandardItemModel; class QStandardItemModel;
QT_END_NAMESPACE
namespace BitTorrent namespace BitTorrent
{ {
@ -59,7 +55,7 @@ namespace BitTorrent
struct PeerAddress; struct PeerAddress;
} }
class PeerListWidget: public QTreeView class PeerListWidget : public QTreeView
{ {
Q_OBJECT Q_OBJECT

5
src/gui/properties/speedplotview.h

@ -35,9 +35,10 @@
#include <QGraphicsView> #include <QGraphicsView>
#include <QMap> #include <QMap>
class QPen; class QPen;
class SpeedPlotView: public QGraphicsView class SpeedPlotView : public QGraphicsView
{ {
Q_OBJECT Q_OBJECT
@ -71,7 +72,7 @@ public:
int y[NB_GRAPHS]; int y[NB_GRAPHS];
}; };
explicit SpeedPlotView(QWidget *parent = 0); explicit SpeedPlotView(QWidget *parent = nullptr);
void setGraphEnable(GraphID id, bool enable); void setGraphEnable(GraphID id, bool enable);
void setViewableLastPoints(TimePeriod period); void setViewableLastPoints(TimePeriod period);

2
src/gui/properties/trackerlist.h

@ -43,7 +43,7 @@ namespace BitTorrent
class TorrentHandle; class TorrentHandle;
} }
class TrackerList: public QTreeWidget class TrackerList : public QTreeWidget
{ {
Q_OBJECT Q_OBJECT
Q_DISABLE_COPY(TrackerList) Q_DISABLE_COPY(TrackerList)

28
src/gui/rss/htmlbrowser.cpp

@ -1,18 +1,18 @@
#include "htmlbrowser.h" #include "htmlbrowser.h"
#include <QDebug>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkDiskCache>
#include <QStyle>
#include <QApplication> #include <QApplication>
#include <QDir>
#include <QDateTime> #include <QDateTime>
#include <QDir>
#include <QDebug>
#include <QNetworkDiskCache>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QScrollBar> #include <QScrollBar>
#include <QStyle>
#include "base/profile.h" #include "base/profile.h"
HtmlBrowser::HtmlBrowser(QWidget* parent) HtmlBrowser::HtmlBrowser(QWidget *parent)
: QTextBrowser(parent) : QTextBrowser(parent)
{ {
m_netManager = new QNetworkAccessManager(this); m_netManager = new QNetworkAccessManager(this);
@ -31,20 +31,20 @@ HtmlBrowser::~HtmlBrowser()
QVariant HtmlBrowser::loadResource(int type, const QUrl &name) QVariant HtmlBrowser::loadResource(int type, const QUrl &name)
{ {
if(type == QTextDocument::ImageResource) { if (type == QTextDocument::ImageResource) {
QUrl url(name); QUrl url(name);
if(url.scheme().isEmpty()) if (url.scheme().isEmpty())
url.setScheme("http"); url.setScheme("http");
QIODevice *dev = m_diskCache->data(url); QIODevice *dev = m_diskCache->data(url);
if(dev != 0) { if (dev != nullptr) {
qDebug() << "HtmlBrowser::loadResource() cache " << url.toString(); qDebug() << "HtmlBrowser::loadResource() cache " << url.toString();
QByteArray res = dev->readAll(); QByteArray res = dev->readAll();
delete dev; delete dev;
return res; return res;
} }
if(!m_activeRequests.contains(url)) { if (!m_activeRequests.contains(url)) {
m_activeRequests.insert(url, true); m_activeRequests.insert(url, true);
qDebug() << "HtmlBrowser::loadResource() get " << url.toString(); qDebug() << "HtmlBrowser::loadResource() get " << url.toString();
QNetworkRequest req(url); QNetworkRequest req(url);
@ -62,7 +62,7 @@ void HtmlBrowser::resourceLoaded(QNetworkReply *reply)
{ {
m_activeRequests.remove(reply->request().url()); m_activeRequests.remove(reply->request().url());
if(reply->error() == QNetworkReply::NoError && reply->size() > 0) { if ((reply->error() == QNetworkReply::NoError) && (reply->size() > 0)) {
qDebug() << "HtmlBrowser::resourceLoaded() save " << reply->request().url().toString(); qDebug() << "HtmlBrowser::resourceLoaded() save " << reply->request().url().toString();
} }
else { else {
@ -79,8 +79,8 @@ void HtmlBrowser::resourceLoaded(QNetworkReply *reply)
metaData.setLastModified(QDateTime::currentDateTime()); metaData.setLastModified(QDateTime::currentDateTime());
metaData.setExpirationDate(QDateTime::currentDateTime().addDays(1)); metaData.setExpirationDate(QDateTime::currentDateTime().addDays(1));
QIODevice *dev = m_diskCache->prepare(metaData); QIODevice *dev = m_diskCache->prepare(metaData);
if(!dev) if (!dev) return;
return;
QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(32, 32).save(dev, "PNG"); QApplication::style()->standardIcon(QStyle::SP_MessageBoxWarning).pixmap(32, 32).save(dev, "PNG");
m_diskCache->insert(dev); m_diskCache->insert(dev);
} }

6
src/gui/rss/htmlbrowser.h

@ -1,19 +1,19 @@
#ifndef HTMLBROWSER_H #ifndef HTMLBROWSER_H
#define HTMLBROWSER_H #define HTMLBROWSER_H
#include <QTextBrowser>
#include <QHash> #include <QHash>
#include <QTextBrowser>
class QNetworkAccessManager; class QNetworkAccessManager;
class QNetworkDiskCache; class QNetworkDiskCache;
class QNetworkReply; class QNetworkReply;
class HtmlBrowser: public QTextBrowser class HtmlBrowser : public QTextBrowser
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit HtmlBrowser(QWidget* parent = 0); explicit HtmlBrowser(QWidget* parent = nullptr);
~HtmlBrowser(); ~HtmlBrowser();
virtual QVariant loadResource(int type, const QUrl &name); virtual QVariant loadResource(int type, const QUrl &name);

2
src/gui/shutdownconfirmdlg.h

@ -39,7 +39,7 @@ namespace Ui
class confirmShutdownDlg; class confirmShutdownDlg;
} }
class ShutdownConfirmDlg: public QDialog class ShutdownConfirmDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT

8
src/gui/speedlimitdlg.cpp

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,14 +24,12 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "speedlimitdlg.h" #include "speedlimitdlg.h"
#include "ui_bandwidth_limit.h"
#include "base/unicodestrings.h" #include "base/unicodestrings.h"
#include "ui_bandwidth_limit.h"
SpeedLimitDialog::SpeedLimitDialog(QWidget *parent) SpeedLimitDialog::SpeedLimitDialog(QWidget *parent)
: QDialog(parent) : QDialog(parent)

15
src/gui/speedlimitdlg.h

@ -1,6 +1,6 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez * Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef BANDWIDTH_ALLOCATION_H #ifndef BANDWIDTH_ALLOCATION_H
@ -33,16 +31,19 @@
#include <QDialog> #include <QDialog>
#include <QList> #include <QList>
#include "base/utils/misc.h"
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/utils/misc.h"
namespace Ui namespace Ui
{ {
class bandwidth_dlg; class bandwidth_dlg;
} }
class SpeedLimitDialog : public QDialog { class SpeedLimitDialog : public QDialog
{
Q_OBJECT Q_OBJECT
public: public:
explicit SpeedLimitDialog(QWidget *parent); explicit SpeedLimitDialog(QWidget *parent);
~SpeedLimitDialog(); ~SpeedLimitDialog();
@ -58,4 +59,4 @@ private:
Ui::bandwidth_dlg *m_ui; Ui::bandwidth_dlg *m_ui;
}; };
#endif #endif // BANDWIDTH_ALLOCATION_H

62
src/gui/updownratiodlg.cpp

@ -1,6 +1,7 @@
/* /*
* Bittorrent Client using Qt and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christian Kandeler, Christophe Dumez * Copyright (C) 2011 Christian Kandeler
* Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
@ -24,8 +25,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#include "updownratiodlg.h" #include "updownratiodlg.h"
@ -33,53 +32,52 @@
#include <QMessageBox> #include <QMessageBox>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "ui_updownratiodlg.h" #include "ui_updownratiodlg.h"
UpDownRatioDlg::UpDownRatioDlg(bool useDefault, qreal initialRatioValue, UpDownRatioDlg::UpDownRatioDlg(bool useDefault, qreal initialRatioValue,
qreal maxRatioValue, int initialTimeValue, qreal maxRatioValue, int initialTimeValue,
int maxTimeValue, QWidget *parent) int maxTimeValue, QWidget *parent)
: QDialog(parent) : QDialog(parent)
, ui(new Ui::UpDownRatioDlg) , m_ui(new Ui::UpDownRatioDlg)
{ {
ui->setupUi(this); m_ui->setupUi(this);
if (useDefault) { if (useDefault) {
ui->useDefaultButton->setChecked(true); m_ui->useDefaultButton->setChecked(true);
} }
else if ((initialRatioValue == -1) && (initialTimeValue == -1)) { else if ((initialRatioValue == -1.) && (initialTimeValue == -1)) {
ui->noLimitButton->setChecked(true); m_ui->noLimitButton->setChecked(true);
initialRatioValue = BitTorrent::Session::instance()->globalMaxRatio(); initialRatioValue = BitTorrent::Session::instance()->globalMaxRatio();
initialTimeValue = BitTorrent::Session::instance()->globalMaxSeedingMinutes(); initialTimeValue = BitTorrent::Session::instance()->globalMaxSeedingMinutes();
} }
else { else {
ui->torrentLimitButton->setChecked(true); m_ui->torrentLimitButton->setChecked(true);
if (initialRatioValue >= 0) if (initialRatioValue >= 0)
ui->checkMaxRatio->setChecked(true); m_ui->checkMaxRatio->setChecked(true);
if (initialTimeValue >= 0) if (initialTimeValue >= 0)
ui->checkMaxTime->setChecked(true); m_ui->checkMaxTime->setChecked(true);
} }
ui->ratioSpinBox->setMinimum(0); m_ui->ratioSpinBox->setMinimum(0);
ui->ratioSpinBox->setMaximum(maxRatioValue); m_ui->ratioSpinBox->setMaximum(maxRatioValue);
ui->ratioSpinBox->setValue(initialRatioValue); m_ui->ratioSpinBox->setValue(initialRatioValue);
ui->timeSpinBox->setMinimum(0); m_ui->timeSpinBox->setMinimum(0);
ui->timeSpinBox->setMaximum(maxTimeValue); m_ui->timeSpinBox->setMaximum(maxTimeValue);
ui->timeSpinBox->setValue(initialTimeValue); m_ui->timeSpinBox->setValue(initialTimeValue);
connect(ui->buttonGroup, SIGNAL(buttonClicked(int)), SLOT(handleRatioTypeChanged())); connect(m_ui->buttonGroup, SIGNAL(buttonClicked(int)), SLOT(handleRatioTypeChanged()));
connect(ui->checkMaxRatio, SIGNAL(toggled(bool)), this, SLOT(enableRatioSpin())); connect(m_ui->checkMaxRatio, SIGNAL(toggled(bool)), this, SLOT(enableRatioSpin()));
connect(ui->checkMaxTime, SIGNAL(toggled(bool)), this, SLOT(enableTimeSpin())); connect(m_ui->checkMaxTime, SIGNAL(toggled(bool)), this, SLOT(enableTimeSpin()));
handleRatioTypeChanged(); handleRatioTypeChanged();
} }
void UpDownRatioDlg::accept() void UpDownRatioDlg::accept()
{ {
if (ui->torrentLimitButton->isChecked() && !ui->checkMaxRatio->isChecked() && !ui->checkMaxTime->isChecked()) if (m_ui->torrentLimitButton->isChecked() && !m_ui->checkMaxRatio->isChecked() && !m_ui->checkMaxTime->isChecked())
QMessageBox::critical(this, tr("No share limit method selected"), QMessageBox::critical(this, tr("No share limit method selected"),
tr("Please select a limit method first")); tr("Please select a limit method first"));
else else
@ -88,40 +86,40 @@ void UpDownRatioDlg::accept()
bool UpDownRatioDlg::useDefault() const bool UpDownRatioDlg::useDefault() const
{ {
return ui->useDefaultButton->isChecked(); return m_ui->useDefaultButton->isChecked();
} }
qreal UpDownRatioDlg::ratio() const qreal UpDownRatioDlg::ratio() const
{ {
return (ui->noLimitButton->isChecked() || !ui->checkMaxRatio->isChecked()) ? -1 : ui->ratioSpinBox->value(); return (m_ui->noLimitButton->isChecked() || !m_ui->checkMaxRatio->isChecked()) ? -1. : m_ui->ratioSpinBox->value();
} }
int UpDownRatioDlg::seedingTime() const int UpDownRatioDlg::seedingTime() const
{ {
return (ui->noLimitButton->isChecked() || !ui->checkMaxTime->isChecked()) ? -1 : ui->timeSpinBox->value(); return (m_ui->noLimitButton->isChecked() || !m_ui->checkMaxTime->isChecked()) ? -1 : m_ui->timeSpinBox->value();
} }
void UpDownRatioDlg::handleRatioTypeChanged() void UpDownRatioDlg::handleRatioTypeChanged()
{ {
// ui->ratioSpinBox->setEnabled(ui->torrentLimitButton->isChecked()); // ui->ratioSpinBox->setEnabled(ui->torrentLimitButton->isChecked());
ui->checkMaxRatio->setEnabled(ui->torrentLimitButton->isChecked()); m_ui->checkMaxRatio->setEnabled(m_ui->torrentLimitButton->isChecked());
ui->checkMaxTime->setEnabled(ui->torrentLimitButton->isChecked()); m_ui->checkMaxTime->setEnabled(m_ui->torrentLimitButton->isChecked());
ui->ratioSpinBox->setEnabled(ui->torrentLimitButton->isChecked() && ui->checkMaxRatio->isChecked()); m_ui->ratioSpinBox->setEnabled(m_ui->torrentLimitButton->isChecked() && m_ui->checkMaxRatio->isChecked());
ui->timeSpinBox->setEnabled(ui->torrentLimitButton->isChecked() && ui->checkMaxTime->isChecked()); m_ui->timeSpinBox->setEnabled(m_ui->torrentLimitButton->isChecked() && m_ui->checkMaxTime->isChecked());
} }
void UpDownRatioDlg::enableRatioSpin() void UpDownRatioDlg::enableRatioSpin()
{ {
ui->ratioSpinBox->setEnabled(ui->checkMaxRatio->isChecked()); m_ui->ratioSpinBox->setEnabled(m_ui->checkMaxRatio->isChecked());
} }
void UpDownRatioDlg::enableTimeSpin() void UpDownRatioDlg::enableTimeSpin()
{ {
ui->timeSpinBox->setEnabled(ui->checkMaxTime->isChecked()); m_ui->timeSpinBox->setEnabled(m_ui->checkMaxTime->isChecked());
} }
UpDownRatioDlg::~UpDownRatioDlg() UpDownRatioDlg::~UpDownRatioDlg()
{ {
delete ui; delete m_ui;
} }

21
src/gui/updownratiodlg.h

@ -1,7 +1,7 @@
/* /*
* Bittorrent Client using Qt4 and libtorrent. * Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2011 Christian Kandeler, Christophe Dumez * Copyright (C) 2011 Christian Kandeler
* * Copyright (C) 2011 Christophe Dumez <chris@qbittorrent.org>
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
@ -24,8 +24,6 @@
* modify file(s), you may extend this exception to your version of the file(s), * 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 * but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version. * exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/ */
#ifndef UPDOWNRATIODLG_H #ifndef UPDOWNRATIODLG_H
@ -33,20 +31,19 @@
#include <QDialog> #include <QDialog>
QT_BEGIN_NAMESPACE namespace Ui
namespace Ui { {
class UpDownRatioDlg; class UpDownRatioDlg;
} }
QT_END_NAMESPACE
class UpDownRatioDlg : public QDialog class UpDownRatioDlg : public QDialog
{ {
Q_OBJECT Q_OBJECT
public: public:
explicit UpDownRatioDlg(bool useDefault, qreal initialValue, qreal maxValue, UpDownRatioDlg(bool useDefault, qreal initialValue, qreal maxValue,
int initialTimeValue, int maxTimeValue, int initialTimeValue, int maxTimeValue,
QWidget *parent = 0); QWidget *parent = nullptr);
~UpDownRatioDlg(); ~UpDownRatioDlg();
bool useDefault() const; bool useDefault() const;
@ -62,7 +59,7 @@ private slots:
void enableTimeSpin(); void enableTimeSpin();
private: private:
Ui::UpDownRatioDlg *ui; Ui::UpDownRatioDlg *m_ui;
}; };
#endif // UPDOWNRATIODLG_H #endif // UPDOWNRATIODLG_H

25
src/webui/webapplication.cpp

@ -26,15 +26,17 @@
* exception statement from your version. * exception statement from your version.
*/ */
#include <QDebug> #include "webapplication.h"
#include <QCoreApplication>
#include <QTimer>
#include <QCryptographicHash>
#include <QRegularExpression>
#include <queue> #include <queue>
#include <vector> #include <vector>
#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDebug>
#include <QRegularExpression>
#include <QTimer>
#include "base/bittorrent/session.h" #include "base/bittorrent/session.h"
#include "base/bittorrent/torrenthandle.h" #include "base/bittorrent/torrenthandle.h"
#include "base/bittorrent/torrentinfo.h" #include "base/bittorrent/torrentinfo.h"
@ -50,7 +52,6 @@
#include "btjson.h" #include "btjson.h"
#include "jsonutils.h" #include "jsonutils.h"
#include "prefjson.h" #include "prefjson.h"
#include "webapplication.h"
#include "websessiondata.h" #include "websessiondata.h"
static const int API_VERSION = 15; static const int API_VERSION = 15;
@ -203,7 +204,7 @@ void WebApplication::action_public_login()
return; return;
} }
const Preferences* const pref = Preferences::instance(); const Preferences *const pref = Preferences::instance();
QCryptographicHash md5(QCryptographicHash::Md5); QCryptographicHash md5(QCryptographicHash::Md5);
md5.addData(request().posts["password"].toLocal8Bit()); md5.addData(request().posts["password"].toLocal8Bit());
@ -565,12 +566,12 @@ void WebApplication::action_command_setFilePrio()
CHECK_URI(0); CHECK_URI(0);
CHECK_PARAMETERS("hash" << "id" << "priority"); CHECK_PARAMETERS("hash" << "id" << "priority");
QString hash = request().posts["hash"]; QString hash = request().posts["hash"];
int file_id = request().posts["id"].toInt(); int fileID = request().posts["id"].toInt();
int priority = request().posts["priority"].toInt(); int priority = request().posts["priority"].toInt();
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent && torrent->hasMetadata()) if (torrent && torrent->hasMetadata())
torrent->setFilePriority(file_id, priority); torrent->setFilePriority(fileID, priority);
} }
void WebApplication::action_command_getGlobalUpLimit() void WebApplication::action_command_getGlobalUpLimit()
@ -801,15 +802,13 @@ void WebApplication::action_command_setLocation()
QStringList hashes = request().posts["hashes"].split("|"); QStringList hashes = request().posts["hashes"].split("|");
QString newLocation = request().posts["location"].trimmed(); QString newLocation = request().posts["location"].trimmed();
// check location exists // check if the location exists
if (newLocation.isEmpty() || !QDir(newLocation).exists()) if (newLocation.isEmpty() || !QDir(newLocation).exists())
return; return;
foreach (const QString &hash, hashes) { foreach (const QString &hash, hashes) {
BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash); BitTorrent::TorrentHandle *const torrent = BitTorrent::Session::instance()->findTorrent(hash);
if (torrent) { if (torrent) {
// get old location
const QString oldLocation = torrent->savePath();
Logger::instance()->addMessage(tr("WebUI Set location: moving \"%1\", from \"%2\" to \"%3\"").arg(torrent->name()).arg(torrent->savePath()).arg(newLocation)); Logger::instance()->addMessage(tr("WebUI Set location: moving \"%1\", from \"%2\" to \"%3\"").arg(torrent->name()).arg(torrent->savePath()).arg(newLocation));
torrent->move(Utils::Fs::expandPathAbs(newLocation)); torrent->move(Utils::Fs::expandPathAbs(newLocation));
@ -945,7 +944,7 @@ void WebApplication::doProcessRequest()
void WebApplication::parsePath() void WebApplication::parsePath()
{ {
if(request().path == "/") action_ = WEBUI_ACTION; if (request().path == "/") action_ = WEBUI_ACTION;
// check action for requested path // check action for requested path
QStringList pathItems = request().path.split('/', QString::SkipEmptyParts); QStringList pathItems = request().path.split('/', QString::SkipEmptyParts);

4
src/webui/webapplication.h

@ -32,12 +32,12 @@
#include <QStringList> #include <QStringList>
#include "abstractwebapplication.h" #include "abstractwebapplication.h"
class WebApplication: public AbstractWebApplication class WebApplication : public AbstractWebApplication
{ {
Q_DISABLE_COPY(WebApplication) Q_DISABLE_COPY(WebApplication)
public: public:
explicit WebApplication(QObject* parent = 0); explicit WebApplication(QObject *parent = nullptr);
private: private:
// Actions // Actions

Loading…
Cancel
Save