Merge pull request #6724 from glassez/libt11

Don't use features, deprecated in libtorrent-1.1
This commit is contained in:
Vladimir Golovnev
2017-05-16 18:54:00 +03:00
committed by GitHub
24 changed files with 578 additions and 437 deletions

View File

@@ -91,7 +91,9 @@
#include "rss/rsswidget.h"
#include "about_imp.h"
#include "optionsdlg.h"
#if LIBTORRENT_VERSION_NUM < 10100
#include "trackerlogin.h"
#endif
#include "lineedit.h"
#include "executionlog.h"
#include "hidabletabwidget.h"
@@ -1317,15 +1319,19 @@ void MainWindow::addUnauthenticatedTracker(const QPair<BitTorrent::TorrentHandle
// Called when a tracker requires authentication
void MainWindow::trackerAuthenticationRequired(BitTorrent::TorrentHandle *const torrent)
{
#if LIBTORRENT_VERSION_NUM < 10100
if (m_unauthenticatedTrackers.indexOf(qMakePair(torrent, torrent->currentTracker())) < 0)
// Tracker login
new trackerLogin(this, torrent);
#else
Q_UNUSED(torrent);
#endif
}
// Check connection status and display right icon
void MainWindow::updateGUI()
{
BitTorrent::SessionStatus status = BitTorrent::Session::instance()->status();
const BitTorrent::SessionStatus &status = BitTorrent::Session::instance()->status();
// update global informations
if (m_systrayIcon) {
@@ -1334,24 +1340,24 @@ void MainWindow::updateGUI()
html += "qBittorrent";
html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/icons/skin/download.png' height='14'/>&nbsp;" + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate(), true));
html += "<img src=':/icons/skin/download.png' height='14'/>&nbsp;" + tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true));
html += "</div>";
html += "<div style='vertical-align: baseline; height: 18px;'>";
html += "<img src=':/icons/skin/seeding.png' height='14'/>&nbsp;" + tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate(), true));
html += "<img src=':/icons/skin/seeding.png' height='14'/>&nbsp;" + tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true));
html += "</div>";
#else
// OSes such as Windows do not support html here
QString html = tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate(), true));
QString html = tr("DL speed: %1", "e.g: Download speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true));
html += "\n";
html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate(), true));
html += tr("UP speed: %1", "e.g: Upload speed: 10 KiB/s").arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true));
#endif
m_systrayIcon->setToolTip(html); // tray icon
}
if (m_displaySpeedInTitle) {
setWindowTitle(tr("[D: %1, U: %2] qBittorrent %3", "D = Download; U = Upload; %3 is qBittorrent version")
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate(), true))
.arg(Utils::Misc::friendlyUnit(status.payloadUploadRate(), true))
.arg(Utils::Misc::friendlyUnit(status.payloadDownloadRate, true))
.arg(Utils::Misc::friendlyUnit(status.payloadUploadRate, true))
.arg(QBT_VERSION));
}
}

View File

@@ -45,7 +45,8 @@
ComboBoxMenuButton::ComboBoxMenuButton(QWidget *parent, QMenu *menu)
: QComboBox(parent)
, m_menu(menu)
{}
{
}
void ComboBoxMenuButton::showPopup()
{
@@ -134,20 +135,20 @@ void SpeedWidget::update()
{
while (m_isUpdating) {
BitTorrent::SessionStatus btStatus = BitTorrent::Session::instance()->status();
const BitTorrent::SessionStatus &btStatus = BitTorrent::Session::instance()->status();
SpeedPlotView::PointData point;
point.x = QDateTime::currentDateTime().toTime_t();
point.y[SpeedPlotView::UP] = btStatus.uploadRate();
point.y[SpeedPlotView::DOWN] = btStatus.downloadRate();
point.y[SpeedPlotView::PAYLOAD_UP] = btStatus.payloadUploadRate();
point.y[SpeedPlotView::PAYLOAD_DOWN] = btStatus.payloadDownloadRate();
point.y[SpeedPlotView::OVERHEAD_UP] = btStatus.ipOverheadUploadRate();
point.y[SpeedPlotView::OVERHEAD_DOWN] = btStatus.ipOverheadDownloadRate();
point.y[SpeedPlotView::DHT_UP] = btStatus.dhtUploadRate();
point.y[SpeedPlotView::DHT_DOWN] = btStatus.dhtDownloadRate();
point.y[SpeedPlotView::TRACKER_UP] = btStatus.trackerUploadRate();
point.y[SpeedPlotView::TRACKER_DOWN] = btStatus.trackerDownloadRate();
point.y[SpeedPlotView::UP] = btStatus.uploadRate;
point.y[SpeedPlotView::DOWN] = btStatus.downloadRate;
point.y[SpeedPlotView::PAYLOAD_UP] = btStatus.payloadUploadRate;
point.y[SpeedPlotView::PAYLOAD_DOWN] = btStatus.payloadDownloadRate;
point.y[SpeedPlotView::OVERHEAD_UP] = btStatus.ipOverheadUploadRate;
point.y[SpeedPlotView::OVERHEAD_DOWN] = btStatus.ipOverheadDownloadRate;
point.y[SpeedPlotView::DHT_UP] = btStatus.dhtUploadRate;
point.y[SpeedPlotView::DHT_DOWN] = btStatus.dhtDownloadRate;
point.y[SpeedPlotView::TRACKER_UP] = btStatus.trackerUploadRate;
point.y[SpeedPlotView::TRACKER_DOWN] = btStatus.trackerDownloadRate;
m_plot->pushPoint(point);

View File

@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2013 Nick Tiskov
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 Nick Tiskov <daymansmail@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,84 +24,82 @@
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : daymansmail@gmail.com
*/
#include "statsdialog.h"
#include "ui_statsdialog.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "base/bittorrent/cachestatus.h"
#include "base/bittorrent/session.h"
#include "base/bittorrent/sessionstatus.h"
#include "base/bittorrent/cachestatus.h"
#include "base/bittorrent/torrenthandle.h"
#include "base/utils/misc.h"
#include "base/utils/string.h"
#include "ui_statsdialog.h"
StatsDialog::StatsDialog(QWidget *parent)
: QDialog(parent)
, ui(new Ui::StatsDialog)
, m_ui(new Ui::StatsDialog)
{
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
connect(ui->buttonBox, SIGNAL(accepted()), SLOT(close()));
updateUI();
t = new QTimer(this);
t->setInterval(1500);
connect(t, SIGNAL(timeout()), SLOT(updateUI()));
t->start();
m_ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
connect(m_ui->buttonBox, &QDialogButtonBox::accepted, this, &StatsDialog::close);
show();
update();
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatsDialog::update);
show();
}
StatsDialog::~StatsDialog() {
t->stop();
delete t;
delete ui;
StatsDialog::~StatsDialog()
{
delete m_ui;
}
void StatsDialog::updateUI() {
BitTorrent::SessionStatus ss = BitTorrent::Session::instance()->status();
BitTorrent::CacheStatus cs = BitTorrent::Session::instance()->cacheStatus();
void StatsDialog::update()
{
const BitTorrent::SessionStatus &ss = BitTorrent::Session::instance()->status();
const BitTorrent::CacheStatus &cs = BitTorrent::Session::instance()->cacheStatus();
// Alltime DL/UL
quint64 atd = BitTorrent::Session::instance()->getAlltimeDL();
quint64 atu = BitTorrent::Session::instance()->getAlltimeUL();
ui->labelAlltimeDL->setText(Utils::Misc::friendlyUnit(atd));
ui->labelAlltimeUL->setText(Utils::Misc::friendlyUnit(atu));
// Total waste (this session)
ui->labelWaste->setText(Utils::Misc::friendlyUnit(ss.totalWasted()));
// Global ratio
ui->labelGlobalRatio->setText(
( atd > 0 && atu > 0 ) ?
Utils::String::fromDouble((qreal)atu / (qreal)atd, 2) :
"-"
);
// Cache hits
qreal readRatio = cs.readRatio();
ui->labelCacheHits->setText((readRatio >= 0) ? Utils::String::fromDouble(100 * readRatio, 2) : "-");
// Buffers size
ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers() * 16 * 1024));
// Disk overload (100%) equivalent
// From lt manual: disk_write_queue and disk_read_queue are the number of peers currently waiting on a disk write or disk read
// to complete before it receives or sends any more data on the socket. It's a metric of how disk bound you are.
// Alltime DL/UL
quint64 atd = BitTorrent::Session::instance()->getAlltimeDL();
quint64 atu = BitTorrent::Session::instance()->getAlltimeUL();
m_ui->labelAlltimeDL->setText(Utils::Misc::friendlyUnit(atd));
m_ui->labelAlltimeUL->setText(Utils::Misc::friendlyUnit(atu));
// Total waste (this session)
m_ui->labelWaste->setText(Utils::Misc::friendlyUnit(ss.totalWasted));
// Global ratio
m_ui->labelGlobalRatio->setText(
((atd > 0) && (atu > 0))
? Utils::String::fromDouble((qreal)atu / (qreal)atd, 2)
: "-");
// Cache hits
qreal readRatio = cs.readRatio;
m_ui->labelCacheHits->setText((readRatio >= 0) ? Utils::String::fromDouble(100 * readRatio, 2) : "-");
// Buffers size
m_ui->labelTotalBuf->setText(Utils::Misc::friendlyUnit(cs.totalUsedBuffers * 16 * 1024));
// Disk overload (100%) equivalent
// From lt manual: disk_write_queue and disk_read_queue are the number of peers currently waiting on a disk write or disk read
// to complete before it receives or sends any more data on the socket. It's a metric of how disk bound you are.
// num_peers is not reliable (adds up peers, which didn't even overcome tcp handshake)
quint32 peers = 0;
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
peers += torrent->peersCount();
// num_peers is not reliable (adds up peers, which didn't even overcome tcp handshake)
quint32 peers = 0;
foreach (BitTorrent::TorrentHandle *const torrent, BitTorrent::Session::instance()->torrents())
peers += torrent->peersCount();
ui->labelWriteStarve->setText(QString("%1%").arg(((ss.diskWriteQueue() > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskWriteQueue()) / peers, 2)
: "0"));
ui->labelReadStarve->setText(QString("%1%").arg(((ss.diskReadQueue() > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskReadQueue()) / peers, 2)
: "0"));
// Disk queues
ui->labelQueuedJobs->setText(QString::number(cs.jobQueueLength()));
ui->labelJobsTime->setText(tr("%1 ms", "18 milliseconds").arg(cs.averageJobTime()));
ui->labelQueuedBytes->setText(Utils::Misc::friendlyUnit(cs.queuedBytes()));
m_ui->labelWriteStarve->setText(QString("%1%")
.arg(((ss.diskWriteQueue > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskWriteQueue) / peers, 2)
: "0"));
m_ui->labelReadStarve->setText(QString("%1%")
.arg(((ss.diskReadQueue > 0) && (peers > 0))
? Utils::String::fromDouble((100. * ss.diskReadQueue) / peers, 2)
: "0"));
// Disk queues
m_ui->labelQueuedJobs->setText(QString::number(cs.jobQueueLength));
m_ui->labelJobsTime->setText(tr("%1 ms", "18 milliseconds").arg(cs.averageJobTime));
m_ui->labelQueuedBytes->setText(Utils::Misc::friendlyUnit(cs.queuedBytes));
// Total connected peers
ui->labelPeers->setText(QString::number(ss.peersCount()));
// Total connected peers
m_ui->labelPeers->setText(QString::number(ss.peersCount));
}

View File

@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2013 Nick Tiskov
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2013 Nick Tiskov <daymansmail@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@@ -24,33 +24,31 @@
* modify file(s), you may extend this exception to your version of the file(s),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : daymansmail@gmail.com
*/
#ifndef STATSDIALOG_H
#define STATSDIALOG_H
#include <QDialog>
#include <QTimer>
namespace Ui {
class StatsDialog;
namespace Ui
{
class StatsDialog;
}
class StatsDialog : public QDialog {
Q_OBJECT
class StatsDialog: public QDialog
{
Q_OBJECT
public:
explicit StatsDialog(QWidget *parent);
~StatsDialog();
~StatsDialog() override;
private slots:
void updateUI();
void update();
private:
Ui::StatsDialog *ui;
QTimer* t;
Ui::StatsDialog *m_ui;
};
#endif // STATSDIALOG_H

View File

@@ -34,7 +34,6 @@
#include <QStatusBar>
#include <QFrame>
#include <QLabel>
#include <QTimer>
#include <QPushButton>
#include <QHBoxLayout>
#include <QFontMetrics>
@@ -135,10 +134,9 @@ StatusBar::StatusBar(QStatusBar *bar)
bar->adjustSize();
// Is DHT enabled
m_DHTLbl->setVisible(session->isDHTEnabled());
m_refreshTimer = new QTimer(bar);
refreshStatusBar();
connect(m_refreshTimer, SIGNAL(timeout()), this, SLOT(refreshStatusBar()));
m_refreshTimer->start(1500);
connect(BitTorrent::Session::instance(), &BitTorrent::Session::statsUpdated
, this, &StatusBar::refreshStatusBar);
}
StatusBar::~StatusBar()
@@ -167,19 +165,16 @@ void StatusBar::showRestartRequired()
Logger::instance()->addMessage(tr("qBittorrent was just updated and needs to be restarted for the changes to be effective."), Log::CRITICAL);
}
void StatusBar::stopTimer()
void StatusBar::updateConnectionStatus()
{
m_refreshTimer->stop();
}
const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status();
void StatusBar::updateConnectionStatus(const BitTorrent::SessionStatus &sessionStatus)
{
if (!BitTorrent::Session::instance()->isListening()) {
m_connecStatusLblIcon->setIcon(QIcon(QLatin1String(":/icons/skin/disconnected.png")));
m_connecStatusLblIcon->setToolTip(QLatin1String("<b>") + tr("Connection Status:") + QLatin1String("</b><br>") + tr("Offline. This usually means that qBittorrent failed to listen on the selected port for incoming connections."));
}
else {
if (sessionStatus.hasIncomingConnections()) {
if (sessionStatus.hasIncomingConnections) {
// Connection OK
m_connecStatusLblIcon->setIcon(QIcon(QLatin1String(":/icons/skin/connected.png")));
m_connecStatusLblIcon->setToolTip(QLatin1String("<b>") + tr("Connection Status:") + QLatin1String("</b><br>") + tr("Online"));
@@ -191,39 +186,41 @@ void StatusBar::updateConnectionStatus(const BitTorrent::SessionStatus &sessionS
}
}
void StatusBar::updateDHTNodesNumber(const BitTorrent::SessionStatus &sessionStatus)
void StatusBar::updateDHTNodesNumber()
{
if (BitTorrent::Session::instance()->isDHTEnabled()) {
m_DHTLbl->setVisible(true);
m_DHTLbl->setText(tr("DHT: %1 nodes").arg(QString::number(sessionStatus.dhtNodes())));
m_DHTLbl->setText(tr("DHT: %1 nodes")
.arg(BitTorrent::Session::instance()->status().dhtNodes));
}
else {
m_DHTLbl->setVisible(false);
}
}
void StatusBar::updateSpeedLabels(const BitTorrent::SessionStatus &sessionStatus)
void StatusBar::updateSpeedLabels()
{
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate(), true);
const BitTorrent::SessionStatus &sessionStatus = BitTorrent::Session::instance()->status();
QString speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadDownloadRate, true);
int speedLimit = BitTorrent::Session::instance()->downloadSpeedLimit();
if (speedLimit)
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + "]";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload()) + ")";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadDownload) + ")";
m_dlSpeedLbl->setText(speedLbl);
speedLimit = BitTorrent::Session::instance()->uploadSpeedLimit();
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate(), true);
speedLbl = Utils::Misc::friendlyUnit(sessionStatus.payloadUploadRate, true);
if (speedLimit)
speedLbl += " [" + Utils::Misc::friendlyUnit(speedLimit, true) + "]";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload()) + ")";
speedLbl += " (" + Utils::Misc::friendlyUnit(sessionStatus.totalPayloadUpload) + ")";
m_upSpeedLbl->setText(speedLbl);
}
void StatusBar::refreshStatusBar()
{
const BitTorrent::SessionStatus sessionStatus = BitTorrent::Session::instance()->status();
updateConnectionStatus(sessionStatus);
updateDHTNodesNumber(sessionStatus);
updateSpeedLabels(sessionStatus);
updateConnectionStatus();
updateDHTNodesNumber();
updateSpeedLabels();
}
void StatusBar::updateAltSpeedsBtn(bool alternative)

View File

@@ -1,6 +1,6 @@
/*
* Bittorrent Client using Qt4 and libtorrent.
* Copyright (C) 2006 Christophe Dumez
* Bittorrent Client using Qt and libtorrent.
* Copyright (C) 2006 Christophe Dumez <chris@qbittorrent.org>
*
* This program is free software; you can redistribute it and/or
* 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),
* but you are not obligated to do so. If you do not wish to do so, delete this
* exception statement from your version.
*
* Contact : chris@qbittorrent.org
*/
#ifndef STATUSBAR_H
@@ -36,13 +34,12 @@
class QStatusBar;
class QFrame;
class QLabel;
class QTimer;
class QPushButton;
class QHBoxLayout;
namespace BitTorrent
{
class SessionStatus;
struct SessionStatus;
}
class StatusBar: public QObject
@@ -57,7 +54,6 @@ public:
public slots:
void showRestartRequired();
void stopTimer();
void refreshStatusBar();
void updateAltSpeedsBtn(bool alternative);
void toggleAlternativeSpeeds();
@@ -65,6 +61,10 @@ public slots:
void capUploadSpeed();
private:
void updateConnectionStatus();
void updateDHTNodesNumber();
void updateSpeedLabels();
QStatusBar *m_bar;
QPushButton *m_dlSpeedLbl;
QPushButton *m_upSpeedLbl;
@@ -75,13 +75,8 @@ private:
QFrame *m_statusSep4;
QPushButton *m_connecStatusLblIcon;
QPushButton *m_altSpeedsBtn;
QTimer *m_refreshTimer;
QWidget *m_container;
QHBoxLayout *m_layout;
void updateConnectionStatus(const BitTorrent::SessionStatus &sessionStatus);
void updateDHTNodesNumber(const BitTorrent::SessionStatus &sessionStatus);
void updateSpeedLabels(const BitTorrent::SessionStatus &sessionStatus);
};
#endif // STATUSBAR_H

View File

@@ -338,7 +338,9 @@ QIcon getIconByState(BitTorrent::TorrentState state)
return getQueuedIcon();
case BitTorrent::TorrentState::CheckingDownloading:
case BitTorrent::TorrentState::CheckingUploading:
#if LIBTORRENT_VERSION_NUM < 10100
case BitTorrent::TorrentState::QueuedForChecking:
#endif
case BitTorrent::TorrentState::CheckingResumeData:
return getCheckingIcon();
case BitTorrent::TorrentState::Unknown:
@@ -391,7 +393,9 @@ QColor getColorByState(BitTorrent::TorrentState state)
case BitTorrent::TorrentState::QueuedUploading:
case BitTorrent::TorrentState::CheckingDownloading:
case BitTorrent::TorrentState::CheckingUploading:
#if LIBTORRENT_VERSION_NUM < 10100
case BitTorrent::TorrentState::QueuedForChecking:
#endif
case BitTorrent::TorrentState::CheckingResumeData:
if (!dark)
return QColor(0, 128, 128); // Teal

View File

@@ -28,9 +28,11 @@
* Contact : chris@qbittorrent.org
*/
#include "base/bittorrent/torrenthandle.h"
#include "trackerlogin.h"
#include <libtorrent/version.hpp>
#include "base/bittorrent/torrenthandle.h"
trackerLogin::trackerLogin(QWidget *parent, BitTorrent::TorrentHandle *const torrent)
: QDialog(parent)
, m_torrent(torrent)
@@ -47,7 +49,9 @@ trackerLogin::~trackerLogin() {}
void trackerLogin::on_loginButton_clicked() {
// login
#if LIBTORRENT_VERSION_NUM < 10100
m_torrent->setTrackerLogin(lineUsername->text(), linePasswd->text());
#endif
close();
}

View File

@@ -258,9 +258,11 @@ QString TransferListDelegate::getStatusString(const int state) const
case BitTorrent::TorrentState::CheckingUploading:
str = tr("Checking", "Torrent local data is being checked");
break;
#if LIBTORRENT_VERSION_NUM < 10100
case BitTorrent::TorrentState::QueuedForChecking:
str = tr("Queued for checking", "i.e. torrent is queued for hash checking");
break;
#endif
case BitTorrent::TorrentState::CheckingResumeData:
str = tr("Checking resume data", "used when loading the torrents from disk after qbt is launched. It checks the correctness of the .fastresume file. Normally it is completed in a fraction of a second, unless loading many many torrents.");
break;