Browse Source

Merge pull request #10816 from Chocobo1/ioerror

Misc. fixes
adaptive-webui-19844
Mike Tzou 5 years ago committed by GitHub
parent
commit
183db3475a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 90
      src/base/bittorrent/session.cpp
  2. 1
      src/base/bittorrent/session.h
  3. 23
      src/base/net/proxyconfigurationmanager.cpp
  4. 2
      src/base/net/proxyconfigurationmanager.h
  5. 28
      src/base/utils/misc.cpp
  6. 2
      src/base/utils/misc.h
  7. 4
      src/gui/properties/peerlistwidget.cpp
  8. 6
      src/gui/properties/propertieswidget.cpp
  9. 10
      src/gui/tagfiltermodel.cpp
  10. 6
      src/gui/transferlistdelegate.cpp
  11. 4
      src/gui/transferlistwidget.cpp
  12. 4
      src/webui/api/torrentscontroller.cpp

90
src/base/bittorrent/session.cpp

@ -362,7 +362,6 @@ Session::Session(QObject *parent)
, m_wasPexEnabled(m_isPeXEnabled) , m_wasPexEnabled(m_isPeXEnabled)
, m_numResumeData(0) , m_numResumeData(0)
, m_extraLimit(0) , m_extraLimit(0)
, m_useProxy(false)
, m_recentErroredTorrentsTimer(new QTimer(this)) , m_recentErroredTorrentsTimer(new QTimer(this))
{ {
Logger *const logger = Logger::instance(); 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); settingsPack.set_int(lt::settings_pack::in_enc_policy, lt::settings_pack::pe_disabled);
} }
// proxy
const auto proxyManager = Net::ProxyConfigurationManager::instance(); const auto proxyManager = Net::ProxyConfigurationManager::instance();
const Net::ProxyConfiguration proxyConfig = proxyManager->proxyConfiguration(); 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) { switch (proxyConfig.type) {
case Net::ProxyType::HTTP: case Net::ProxyType::HTTP:
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http); settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http);
break; break;
case Net::ProxyType::HTTP_PW: case Net::ProxyType::HTTP_PW:
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http_pw); settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::http_pw);
break; break;
case Net::ProxyType::SOCKS4: case Net::ProxyType::SOCKS4:
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks4); settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks4);
break; break;
case Net::ProxyType::SOCKS5: case Net::ProxyType::SOCKS5:
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5); settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5);
break; break;
case Net::ProxyType::SOCKS5_PW: case Net::ProxyType::SOCKS5_PW:
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5_pw); settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::socks5_pw);
break; break;
default: case Net::ProxyType::None:
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::none); default:
settingsPack.set_int(lt::settings_pack::proxy_type, lt::settings_pack::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());
} }
m_useProxy = (proxyConfig.type != Net::ProxyType::None); settingsPack.set_bool(lt::settings_pack::proxy_peer_connections, isProxyPeerConnectionsEnabled());
} }
settingsPack.set_bool(lt::settings_pack::force_proxy, m_useProxy ? isForceProxyEnabled() : false); 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_trackers, announceToAllTrackers());
settingsPack.set_bool(lt::settings_pack::announce_to_all_tiers, announceToAllTiers()); 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) { if (torrent->seedingTimeLimit() != TorrentHandle::NO_SEEDING_TIME_LIMIT) {
const int seedingTimeInMinutes = torrent->seedingTime() / 60; const qlonglong seedingTimeInMinutes = torrent->seedingTime() / 60;
int seedingTimeLimit = torrent->seedingTimeLimit(); int seedingTimeLimit = torrent->seedingTimeLimit();
if (seedingTimeLimit == TorrentHandle::USE_GLOBAL_SEEDING_TIME) if (seedingTimeLimit == TorrentHandle::USE_GLOBAL_SEEDING_TIME)
// If Global Seeding Time Limit is really set... // 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) 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()); TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash());
if (torrent) { if (!torrent)
const InfoHash hash = torrent->hash(); return;
if (!m_recentErroredTorrents.contains(hash)) {
m_recentErroredTorrents.insert(hash); const InfoHash hash = torrent->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);
}
m_recentErroredTorrentsTimer->start(); 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) void Session::handlePortmapWarningAlert(const lt::portmap_error_alert *p)

1
src/base/bittorrent/session.h

@ -671,7 +671,6 @@ namespace BitTorrent
QVector<BitTorrent::TrackerEntry> m_additionalTrackerList; QVector<BitTorrent::TrackerEntry> m_additionalTrackerList;
QString m_resumeFolderPath; QString m_resumeFolderPath;
QFile m_resumeFolderLock; QFile m_resumeFolderLock;
bool m_useProxy;
QTimer *m_refreshTimer; QTimer *m_refreshTimer;
QTimer *m_seedingLimitTimer; QTimer *m_seedingLimitTimer;

23
src/base/net/proxyconfigurationmanager.cpp

@ -41,15 +41,20 @@ const QString KEY_PASSWORD = SETTINGS_KEY("Password");
namespace namespace
{ {
inline SettingsStorage *settings() { return SettingsStorage::instance(); } inline SettingsStorage *settings() { return SettingsStorage::instance(); }
}
inline bool isSameConfig(const Net::ProxyConfiguration &conf1, const Net::ProxyConfiguration &conf2) bool Net::operator==(const ProxyConfiguration &left, const ProxyConfiguration &right)
{ {
return conf1.type == conf2.type return (left.type == right.type)
&& conf1.ip == conf2.ip && (left.ip == right.ip)
&& conf1.port == conf2.port && (left.port == right.port)
&& conf1.username == conf2.username && (left.username == right.username)
&& conf1.password == conf2.password; && (left.password == right.password);
} }
bool Net::operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right)
{
return !(left == right);
} }
using namespace Net; using namespace Net;
@ -97,7 +102,7 @@ ProxyConfiguration ProxyConfigurationManager::proxyConfiguration() const
void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config) void ProxyConfigurationManager::setProxyConfiguration(const ProxyConfiguration &config)
{ {
if (!isSameConfig(config, m_config)) { if (config != m_config) {
m_config = config; m_config = config;
settings()->storeValue(KEY_TYPE, static_cast<int>(config.type)); settings()->storeValue(KEY_TYPE, static_cast<int>(config.type));
settings()->storeValue(KEY_IP, config.ip); settings()->storeValue(KEY_IP, config.ip);

2
src/base/net/proxyconfigurationmanager.h

@ -51,6 +51,8 @@ namespace Net
QString username; QString username;
QString password; QString password;
}; };
bool operator==(const ProxyConfiguration &left, const ProxyConfiguration &right);
bool operator!=(const ProxyConfiguration &left, const ProxyConfiguration &right);
class ProxyConfigurationManager : public QObject class ProxyConfigurationManager : public QObject
{ {

28
src/base/utils/misc.cpp

@ -323,11 +323,11 @@ bool Utils::Misc::isPreviewable(const QString &extension)
return multimediaExtensions.contains(extension.toUpper()); return multimediaExtensions.contains(extension.toUpper());
} }
// Take a number of seconds and return an user-friendly QString Utils::Misc::userFriendlyDuration(const qlonglong seconds, const qlonglong maxCap)
// time duration like "1d 2h 10m".
QString Utils::Misc::userFriendlyDuration(const qlonglong seconds)
{ {
if ((seconds < 0) || (seconds >= MAX_ETA)) if (seconds < 0)
return QString::fromUtf8(C_INFINITY);
if ((maxCap >= 0) && (seconds >= maxCap))
return QString::fromUtf8(C_INFINITY); return QString::fromUtf8(C_INFINITY);
if (seconds == 0) if (seconds == 0)
@ -336,21 +336,25 @@ QString Utils::Misc::userFriendlyDuration(const qlonglong seconds)
if (seconds < 60) if (seconds < 60)
return QCoreApplication::translate("misc", "< 1m", "< 1 minute"); return QCoreApplication::translate("misc", "< 1m", "< 1 minute");
qlonglong minutes = seconds / 60; qlonglong minutes = (seconds / 60);
if (minutes < 60) if (minutes < 60)
return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes)); return QCoreApplication::translate("misc", "%1m", "e.g: 10minutes").arg(QString::number(minutes));
qlonglong hours = minutes / 60; qlonglong hours = (minutes / 60);
minutes -= hours * 60; if (hours < 24) {
if (hours < 24) minutes -= (hours * 60);
return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours), QString::number(minutes)); return QCoreApplication::translate("misc", "%1h %2m", "e.g: 3hours 5minutes").arg(QString::number(hours), QString::number(minutes));
}
qlonglong days = hours / 24; qlonglong days = (hours / 24);
hours -= days * 24; if (days < 365) {
if (days < 100) hours -= (days * 24);
return QCoreApplication::translate("misc", "%1d %2h", "e.g: 2days 10hours").arg(QString::number(days), QString::number(hours)); 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() QString Utils::Misc::getUserIDString()

2
src/base/utils/misc.h

@ -84,7 +84,7 @@ namespace Utils
// Take a number of seconds and return a user-friendly // Take a number of seconds and return a user-friendly
// time duration like "1d 2h 10m". // time duration like "1d 2h 10m".
QString userFriendlyDuration(qlonglong seconds); QString userFriendlyDuration(qlonglong seconds, qlonglong maxCap = -1);
QString getUserIDString(); QString getUserIDString();
#ifdef Q_OS_WIN #ifdef Q_OS_WIN

4
src/gui/properties/peerlistwidget.cpp

@ -455,10 +455,10 @@ void PeerListWidget::handleSortColumnChanged(int col)
void PeerListWidget::wheelEvent(QWheelEvent *event) void PeerListWidget::wheelEvent(QWheelEvent *event)
{ {
event->accept();
if (event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
// Shift + scroll = horizontal scroll // Shift + scroll = horizontal scroll
event->accept();
QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal); QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal);
QTreeView::wheelEvent(&scrollHEvent); QTreeView::wheelEvent(&scrollHEvent);
return; return;

6
src/gui/properties/propertieswidget.cpp

@ -420,7 +420,7 @@ void PropertiesWidget::loadDynamicData()
.arg(m_torrent->connectionsCount()) .arg(m_torrent->connectionsCount())
.arg(m_torrent->connectionsLimit() < 0 ? QString::fromUtf8(C_INFINITY) : QString::number(m_torrent->connectionsLimit()))); .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 // Update next announce time
m_ui->labelReannounceInVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->nextAnnounce())); m_ui->labelReannounceInVal->setText(Utils::Misc::userFriendlyDuration(m_torrent->nextAnnounce()));
@ -437,12 +437,12 @@ void PropertiesWidget::loadDynamicData()
.arg(QString::number(m_torrent->leechsCount()) .arg(QString::number(m_torrent->leechsCount())
, QString::number(m_torrent->totalLeechersCount()))); , 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); 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.)") 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)); .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); 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.)") 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)); .arg(Utils::Misc::friendlyUnit(m_torrent->uploadPayloadRate(), true), ulAvg));

10
src/gui/tagfiltermodel.cpp

@ -216,15 +216,15 @@ void TagFilterModel::torrentTagAdded(BitTorrent::TorrentHandle *const torrent, c
void TagFilterModel::torrentTagRemoved(BitTorrent::TorrentHandle *const torrent, const QString &tag) void TagFilterModel::torrentTagRemoved(BitTorrent::TorrentHandle *const torrent, const QString &tag)
{ {
Q_ASSERT(torrent->tags().count() >= 0); if (torrent->tags().empty())
if (torrent->tags().count() == 0)
untaggedItem()->increaseTorrentsCount(); untaggedItem()->increaseTorrentsCount();
const int row = findRow(tag); const int row = findRow(tag);
Q_ASSERT(isValidRow(row)); if (row < 0)
TagModelItem &item = m_tagItems[row]; return;
m_tagItems[row].decreaseTorrentsCount();
item.decreaseTorrentsCount();
const QModelIndex i = index(row, 0, QModelIndex()); const QModelIndex i = index(row, 0, QModelIndex());
emit dataChanged(i, i); emit dataChanged(i, i);
} }

6
src/gui/transferlistdelegate.cpp

@ -82,7 +82,7 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
break; break;
case TransferListModel::TR_ETA: { case TransferListModel::TR_ETA: {
opt.displayAlignment = Qt::AlignRight | Qt::AlignVCenter; 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; break;
} }
case TransferListModel::TR_SEEDS: case TransferListModel::TR_SEEDS:
@ -121,8 +121,8 @@ void TransferListDelegate::paint(QPainter *painter, const QStyleOptionViewItem &
} }
break; break;
case TransferListModel::TR_TIME_ELAPSED: { case TransferListModel::TR_TIME_ELAPSED: {
const int elapsedTime = index.data().toInt(); const qlonglong elapsedTime = index.data().toLongLong();
const int seedingTime = index.data(Qt::UserRole).toInt(); const qlonglong seedingTime = index.data(Qt::UserRole).toLongLong();
const QString txt = (seedingTime > 0) const QString txt = (seedingTime > 0)
? tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)") ? tr("%1 (seeded for %2)", "e.g. 4m39s (seeded for 3m10s)")
.arg(Utils::Misc::userFriendlyDuration(elapsedTime) .arg(Utils::Misc::userFriendlyDuration(elapsedTime)

4
src/gui/transferlistwidget.cpp

@ -1226,10 +1226,10 @@ bool TransferListWidget::loadSettings()
void TransferListWidget::wheelEvent(QWheelEvent *event) void TransferListWidget::wheelEvent(QWheelEvent *event)
{ {
event->accept();
if (event->modifiers() & Qt::ShiftModifier) { if (event->modifiers() & Qt::ShiftModifier) {
// Shift + scroll = horizontal scroll // Shift + scroll = horizontal scroll
event->accept();
QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal); QWheelEvent scrollHEvent(event->pos(), event->globalPos(), event->delta(), event->buttons(), event->modifiers(), Qt::Horizontal);
QTreeView::wheelEvent(&scrollHEvent); QTreeView::wheelEvent(&scrollHEvent);
return; return;

4
src/webui/api/torrentscontroller.cpp

@ -324,10 +324,10 @@ void TorrentsController::propertiesAction()
dataDict[KEY_PROP_UPLOADED] = torrent->totalUpload(); dataDict[KEY_PROP_UPLOADED] = torrent->totalUpload();
dataDict[KEY_PROP_UPLOADED_SESSION] = torrent->totalPayloadUpload(); dataDict[KEY_PROP_UPLOADED_SESSION] = torrent->totalPayloadUpload();
dataDict[KEY_PROP_DL_SPEED] = torrent->downloadPayloadRate(); 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_DL_SPEED_AVG] = torrent->totalDownload() / ((dlDuration == 0) ? -1 : dlDuration);
dataDict[KEY_PROP_UP_SPEED] = torrent->uploadPayloadRate(); 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_UP_SPEED_AVG] = torrent->totalUpload() / ((ulDuration == 0) ? -1 : ulDuration);
dataDict[KEY_PROP_DL_LIMIT] = torrent->downloadLimit() <= 0 ? -1 : torrent->downloadLimit(); dataDict[KEY_PROP_DL_LIMIT] = torrent->downloadLimit() <= 0 ? -1 : torrent->downloadLimit();
dataDict[KEY_PROP_UP_LIMIT] = torrent->uploadLimit() <= 0 ? -1 : torrent->uploadLimit(); dataDict[KEY_PROP_UP_LIMIT] = torrent->uploadLimit() <= 0 ? -1 : torrent->uploadLimit();

Loading…
Cancel
Save