mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-22 01:06:03 +03:00
commit
183db3475a
12 changed files with 99 additions and 85 deletions
|
@ -362,7 +362,6 @@ Session::Session(QObject *parent)
|
|||
, m_wasPexEnabled(m_isPeXEnabled)
|
||||
, m_numResumeData(0)
|
||||
, m_extraLimit(0)
|
||||
, m_useProxy(false)
|
||||
, m_recentErroredTorrentsTimer(new QTimer(this))
|
||||
{
|
||||
Logger *const logger = Logger::instance();
|
||||
|
@ -1211,42 +1210,44 @@ void Session::configure(lt::settings_pack &settingsPack)
|
|||
settingsPack.set_int(lt::settings_pack::in_enc_policy, lt::settings_pack::pe_disabled);
|
||||
}
|
||||
|
||||
// proxy
|
||||
const auto proxyManager = Net::ProxyConfigurationManager::instance();
|
||||
const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration();
|
||||
if (m_useProxy || (proxyConfig.type != Net::ProxyType::None)) {
|
||||
if (proxyConfig.type != Net::ProxyType::None) {
|
||||
settingsPack.set_str(lt::settings_pack::proxy_hostname, proxyConfig.ip.toStdString());
|
||||
settingsPack.set_int(lt::settings_pack::proxy_port, proxyConfig.port);
|
||||
if (proxyManager->isAuthenticationRequired()) {
|
||||
settingsPack.set_str(lt::settings_pack::proxy_username, proxyConfig.username.toStdString());
|
||||
settingsPack.set_str(lt::settings_pack::proxy_password, proxyConfig.password.toStdString());
|
||||
}
|
||||
settingsPack.set_bool(lt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled());
|
||||
}
|
||||
|
||||
switch (proxyConfig.type) {
|
||||
case Net::ProxyType::HTTP:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http);
|
||||
break;
|
||||
case Net::ProxyType::HTTP_PW:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http_pw);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS4:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks4);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5_PW:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5_pw);
|
||||
break;
|
||||
default:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none);
|
||||
}
|
||||
|
||||
m_useProxy = (proxyConfig.type != Net::ProxyType::None);
|
||||
switch (proxyConfig.type) {
|
||||
case Net::ProxyType::HTTP:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http);
|
||||
break;
|
||||
case Net::ProxyType::HTTP_PW:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http_pw);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS4:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks4);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5);
|
||||
break;
|
||||
case Net::ProxyType::SOCKS5_PW:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5_pw);
|
||||
break;
|
||||
case Net::ProxyType::None:
|
||||
default:
|
||||
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none);
|
||||
}
|
||||
settingsPack.set_bool(lt::settings_pack::force_proxy, m_useProxy ? isForceProxyEnabled() : false);
|
||||
|
||||
if (proxyConfig.type != Net::ProxyType::None) {
|
||||
settingsPack.set_str(lt::settings_pack::proxy_hostname, proxyConfig.ip.toStdString());
|
||||
settingsPack.set_int(lt::settings_pack::proxy_port, proxyConfig.port);
|
||||
|
||||
if (proxyManager->isAuthenticationRequired()) {
|
||||
settingsPack.set_str(lt::settings_pack::proxy_username, proxyConfig.username.toStdString());
|
||||
settingsPack.set_str(lt::settings_pack::proxy_password, proxyConfig.password.toStdString());
|
||||
}
|
||||
|
||||
settingsPack.set_bool(lt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled());
|
||||
}
|
||||
settingsPack.set_bool(lt::settings_pack::force_proxy
|
||||
, ((proxyConfig.type == Net::ProxyType::None) ? false : isForceProxyEnabled()));
|
||||
|
||||
settingsPack.set_bool(lt::settings_pack::announce_to_all_trackers, announceToAllTrackers());
|
||||
settingsPack.set_bool(lt::settings_pack::announce_to_all_tiers, announceToAllTiers());
|
||||
|
@ -1531,7 +1532,7 @@ void Session::processShareLimits()
|
|||
}
|
||||
|
||||
if (torrent->seedingTimeLimit() != TorrentHandle::NO_SEEDING_TIME_LIMIT) {
|
||||
const int seedingTimeInMinutes = torrent->seedingTime() / 60;
|
||||
const qlonglong seedingTimeInMinutes = torrent->seedingTime() / 60;
|
||||
int seedingTimeLimit = torrent->seedingTimeLimit();
|
||||
if (seedingTimeLimit == TorrentHandle::USE_GLOBAL_SEEDING_TIME)
|
||||
// If Global Seeding Time Limit is really set...
|
||||
|
@ -4002,20 +4003,23 @@ void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p)
|
|||
|
||||
void Session::handleFileErrorAlert(const lt::file_error_alert *p)
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
// NOTE: Check this function!
|
||||
TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash());
|
||||
if (torrent) {
|
||||
const InfoHash hash = torrent->hash();
|
||||
if (!m_recentErroredTorrents.contains(hash)) {
|
||||
m_recentErroredTorrents.insert(hash);
|
||||
const QString msg = QString::fromStdString(p->message());
|
||||
LogMsg(tr("An I/O error occurred, '%1' paused. %2").arg(torrent->name(), msg));
|
||||
emit fullDiskError(torrent, msg);
|
||||
}
|
||||
if (!torrent)
|
||||
return;
|
||||
|
||||
m_recentErroredTorrentsTimer->start();
|
||||
const InfoHash hash = torrent->hash();
|
||||
|
||||
if (!m_recentErroredTorrents.contains(hash)) {
|
||||
m_recentErroredTorrents.insert(hash);
|
||||
|
||||
const QString msg = QString::fromStdString(p->message());
|
||||
LogMsg(tr("File error alert. Torrent: \"%1\". File: \"%2\". Reason: %3")
|
||||
.arg(torrent->name(), p->filename(), msg)
|
||||
, Log::WARNING);
|
||||
emit fullDiskError(torrent, msg);
|
||||
}
|
||||
|
||||
m_recentErroredTorrentsTimer->start();
|
||||
}
|
||||
|
||||
void Session::handlePortmapWarningAlert(const lt::portmap_error_alert *p)
|
||||
|
|
|
@ -671,7 +671,6 @@ namespace BitTorrent
|
|||
QVector<BitTorrent::TrackerEntry> m_additionalTrackerList;
|
||||
QString m_resumeFolderPath;
|
||||
QFile m_resumeFolderLock;
|
||||
bool m_useProxy;
|
||||
|
||||
QTimer *m_refreshTimer;
|
||||
QTimer *m_seedingLimitTimer;
|
||||
|
|
|
@ -41,15 +41,20 @@ const QString KEY_PASSWORD = SETTINGS_KEY("Password");
|
|||
namespace
|
||||
{
|
||||
inline SettingsStorage *settings() { return SettingsStorage::instance(); }
|
||||
}
|
||||
|
||||
inline bool isSameConfig(const Net::ProxyConfiguration &conf1, const Net::ProxyConfiguration &conf2)
|
||||
{
|
||||
return conf1.type == conf2.type
|
||||
&& conf1.ip == conf2.ip
|
||||
&& conf1.port == conf2.port
|
||||
&& conf1.username == conf2.username
|
||||
&& conf1.password == conf2.password;
|
||||
}
|
||||
bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &right)
|
||||
{
|
||||
return (left.type == right.type)
|
||||
&& (left.ip == right.ip)
|
||||
&& (left.port == right.port)
|
||||
&& (left.username == right.username)
|
||||
&& (left.password == right.password);
|
||||
}
|
||||
|
||||
bool Net::operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right)
|
||||
{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
using namespace Net;
|
||||
|
@ -97,7 +102,7 @@ ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const
|
|||
|
||||
void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config)
|
||||
{
|
||||
if (!isSameConfig(config, m_config)) {
|
||||
if (config != m_config) {
|
||||
m_config = config;
|
||||
settings()->storeValue(KEY_TYPE, static_cast<int>(config.type));
|
||||
settings()->storeValue(KEY_IP, config.ip);
|
||||
|
|
|
@ -51,6 +51,8 @@ namespace Net
|
|||
QString username;
|
||||
QString password;
|
||||
};
|
||||
bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right);
|
||||
bool operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right);
|
||||
|
||||
class ProxyConfigurationManager : public QObject
|
||||
{
|
||||
|
|
|
@ -323,11 +323,11 @@ bool Utils::Misc::isPreviewable(const QString &extension)
|
|||
return multimediaExtensions.contains(extension.toUpper());
|
||||
}
|
||||
|
||||
// Take a number of seconds and return an user-friendly
|
||||
// time duration like "1d 2h 10m".
|
||||
QString Utils::Misc::userFriendlyDuration(const qlonglong seconds)
|
||||
QString Utils::Misc::userFriendlyDuration(const qlonglong seconds, const qlonglong maxCap)
|
||||
{
|
||||
if ((seconds < 0) || (seconds >= MAX_ETA))
|
||||
if (seconds < 0)
|
||||
return QString::fromUtf8(C_INFINITY);
|
||||
if ((maxCap >= 0) && (seconds >= maxCap))
|
||||
return QString::fromUtf8(C_INFINITY);
|
||||
|
||||
if (seconds == 0)
|
||||
|
@ -336,21 +336,25 @@ QString Utils::Misc::userFriendlyDuration(const qlonglong seconds)
|
|||
if (seconds < 60)
|
||||
return QCoreApplication::translate("misc", "< 1m", "< 1 minute");
|
||||
|
||||
qlonglong minutes = seconds / 60;
|
||||
qlonglong minutes = (seconds / 60);
|
||||
if (minutes < 60)
|
||||
return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes));
|
||||
|
||||
qlonglong hours = minutes / 60;
|
||||
minutes -= hours * 60;
|
||||
if (hours < 24)
|
||||
qlonglong hours = (minutes / 60);
|
||||
if (hours < 24) {
|
||||
minutes -= (hours * 60);
|
||||
return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours), QString::number(minutes));
|
||||
}
|
||||
|
||||
qlonglong days = hours / 24;
|
||||
hours -= days * 24;
|
||||
if (days < 100)
|
||||
qlonglong days = (hours / 24);
|
||||
if (days < 365) {
|
||||
hours -= (days * 24);
|
||||
return QCoreApplication::translate("misc", "%1d %2h", "e.g: 2days 10hours").arg(QString::number(days), QString::number(hours));
|
||||
}
|
||||
|
||||
return QString::fromUtf8(C_INFINITY);
|
||||
qlonglong years = (days / 365);
|
||||
days -= (years * 365);
|
||||
return QCoreApplication::translate("misc", "%1y %2d", "e.g: 2years 10days").arg(QString::number(years), QString::number(days));
|
||||
}
|
||||
|
||||
QString Utils::Misc::getUserIDString()
|
||||
|
|
|
@ -84,7 +84,7 @@ namespace Utils
|
|||
|
||||
// Take a number of seconds and return a user-friendly
|
||||
// time duration like "1d 2h 10m".
|
||||
QString userFriendlyDuration(qlonglong seconds);
|
||||
QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap = -1);
|
||||
QString getUserIDString();
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
|
|
@ -455,10 +455,10 @@ void PeerListWidget::handleSortColumnChanged(int col)
|
|||
|
||||
void PeerListWidget::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
if (event->modifiers() & Qt::ShiftModifier) {
|
||||
// Shift + scroll = horizontal scroll
|
||||
event->accept();
|
||||
|
||||
QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal);
|
||||
QTreeView::wheelEvent(&scrollHEvent);
|
||||
return;
|
||||
|
|
|
@ -420,7 +420,7 @@ void PropertiesWidget::loadDynamicData()
|
|||
.arg(m_torrent->connectionsCount())
|
||||
.arg(m_torrent->connectionsLimit() < 0 ? QString::fromUtf8(C_INFINITY) : QString::number(m_torrent->connectionsLimit())));
|
||||
|
||||
m_ui->labelETAVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->eta()));
|
||||
m_ui->labelETAVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->eta(), MAX_ETA));
|
||||
|
||||
// Update next announce time
|
||||
m_ui->labelReannounceInVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->nextAnnounce()));
|
||||
|
@ -437,12 +437,12 @@ void PropertiesWidget::loadDynamicData()
|
|||
.arg(QString::number(m_torrent->leechsCount())
|
||||
, QString::number(m_torrent->totalLeechersCount())));
|
||||
|
||||
const int dlDuration = m_torrent->activeTime() - m_torrent->finishedTime();
|
||||
const qlonglong dlDuration = m_torrent->activeTime() - m_torrent->finishedTime();
|
||||
const QString dlAvg = Utils::Misc::friendlyUnit((m_torrent->totalDownload() / ((dlDuration == 0) ? -1 : dlDuration)), true);
|
||||
m_ui->labelDlSpeedVal->setText(tr("%1 (%2 avg.)", "%1 and %2 are speed rates, e.g. 200KiB/s (100KiB/s avg.)")
|
||||
.arg(Utils::Misc::friendlyUnit(m_torrent->downloadPayloadRate(), true), dlAvg));
|
||||
|
||||
const int ulDuration = m_torrent->activeTime();
|
||||
const qlonglong ulDuration = m_torrent->activeTime();
|
||||
const QString ulAvg = Utils::Misc::friendlyUnit((m_torrent->totalUpload() / ((ulDuration == 0) ? -1 : ulDuration)), true);
|
||||
m_ui->labelUpSpeedVal->setText(tr("%1 (%2 avg.)", "%1 and %2 are speed rates, e.g. 200KiB/s (100KiB/s avg.)")
|
||||
.arg(Utils::Misc::friendlyUnit(m_torrent->uploadPayloadRate(), true), ulAvg));
|
||||
|
|
|
@ -216,15 +216,15 @@ void TagFilterModel::torrentTagAdded(BitTorrent::TorrentHandle *const torrent, c
|
|||
|
||||
void TagFilterModel::torrentTagRemoved(BitTorrent::TorrentHandle *const torrent, const QString &tag)
|
||||
{
|
||||
Q_ASSERT(torrent->tags().count() >= 0);
|
||||
if (torrent->tags().count() == 0)
|
||||
if (torrent->tags().empty())
|
||||
untaggedItem()->increaseTorrentsCount();
|
||||
|
||||
const int row = findRow(tag);
|
||||
Q_ASSERT(isValidRow(row));
|
||||
TagModelItem &item = m_tagItems[row];
|
||||
if (row < 0)
|
||||
return;
|
||||
|
||||
m_tagItems[row].decreaseTorrentsCount();
|
||||
|
||||
item.decreaseTorrentsCount();
|
||||
const QModelIndex i = index(row, 0, QModelIndex());
|
||||
emit dataChanged(i, i);
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
|||
break;
|
||||
case TransferListModel::TR_ETA: {
|
||||
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter;
|
||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong()));
|
||||
QItemDelegate::drawDisplay(painter, opt, option.rect, Utils::Misc::userFriendlyDuration(index.data().toLongLong(), MAX_ETA));
|
||||
break;
|
||||
}
|
||||
case TransferListModel::TR_SEEDS:
|
||||
|
@ -121,8 +121,8 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
|
|||
}
|
||||
break;
|
||||
case TransferListModel::TR_TIME_ELAPSED: {
|
||||
const int elapsedTime = index.data().toInt();
|
||||
const int seedingTime = index.data(Qt::UserRole).toInt();
|
||||
const qlonglong elapsedTime = index.data().toLongLong();
|
||||
const qlonglong seedingTime = index.data(Qt::UserRole).toLongLong();
|
||||
const QString txt = (seedingTime > 0)
|
||||
? tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
|
||||
.arg(Utils::Misc::userFriendlyDuration(elapsedTime)
|
||||
|
|
|
@ -1226,10 +1226,10 @@ bool TransferListWidget::loadSettings()
|
|||
|
||||
void TransferListWidget::wheelEvent(QWheelEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
|
||||
if (event->modifiers() & Qt::ShiftModifier) {
|
||||
// Shift + scroll = horizontal scroll
|
||||
event->accept();
|
||||
|
||||
QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal);
|
||||
QTreeView::wheelEvent(&scrollHEvent);
|
||||
return;
|
||||
|
|
|
@ -324,10 +324,10 @@ void TorrentsController::propertiesAction()
|
|||
dataDict[KEY_PROP_UPLOADED] = torrent->totalUpload();
|
||||
dataDict[KEY_PROP_UPLOADED_SESSION] = torrent->totalPayloadUpload();
|
||||
dataDict[KEY_PROP_DL_SPEED] = torrent->downloadPayloadRate();
|
||||
const int dlDuration = torrent->activeTime() - torrent->finishedTime();
|
||||
const qlonglong dlDuration = torrent->activeTime() - torrent->finishedTime();
|
||||
dataDict[KEY_PROP_DL_SPEED_AVG] = torrent->totalDownload() / ((dlDuration == 0) ? -1 : dlDuration);
|
||||
dataDict[KEY_PROP_UP_SPEED] = torrent->uploadPayloadRate();
|
||||
const int ulDuration = torrent->activeTime();
|
||||
const qlonglong ulDuration = torrent->activeTime();
|
||||
dataDict[KEY_PROP_UP_SPEED_AVG] = torrent->totalUpload() / ((ulDuration == 0) ? -1 : ulDuration);
|
||||
dataDict[KEY_PROP_DL_LIMIT] = torrent->downloadLimit() <= 0 ? -1 : torrent->downloadLimit();
|
||||
dataDict[KEY_PROP_UP_LIMIT] = torrent->uploadLimit() <= 0 ? -1 : torrent->uploadLimit();
|
||||
|
|
Loading…
Reference in a new issue