mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-14 02:27:09 -07:00
Merge pull request #18909 from glassez/v4.5
Backport changes to v4.5.x branch
This commit is contained in:
commit
fcd38a497e
5 changed files with 50 additions and 59 deletions
|
@ -453,6 +453,7 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
|
|||
};
|
||||
|
||||
const QString logMsg = tr("Running external program. Torrent: \"%1\". Command: `%2`");
|
||||
const QString logMsgError = tr("Failed to run external program. Torrent: \"%1\". Command: `%2`");
|
||||
|
||||
// The processing sequenece is different for Windows and other OS, this is intentional
|
||||
#if defined(Q_OS_WIN)
|
||||
|
@ -472,8 +473,6 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
|
|||
for (int i = 1; i < argCount; ++i)
|
||||
argList += QString::fromWCharArray(args[i]);
|
||||
|
||||
LogMsg(logMsg.arg(torrent->name(), program));
|
||||
|
||||
QProcess proc;
|
||||
proc.setProgram(QString::fromWCharArray(args[0]));
|
||||
proc.setArguments(argList);
|
||||
|
@ -498,7 +497,11 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
|
|||
args->startupInfo->hStdOutput = nullptr;
|
||||
args->startupInfo->hStdError = nullptr;
|
||||
});
|
||||
proc.startDetached();
|
||||
|
||||
if (proc.startDetached())
|
||||
LogMsg(logMsg.arg(torrent->name(), program));
|
||||
else
|
||||
LogMsg(logMsgError.arg(torrent->name(), program));
|
||||
#else // Q_OS_WIN
|
||||
QStringList args = Utils::String::splitCommand(programTemplate);
|
||||
|
||||
|
@ -514,11 +517,21 @@ void Application::runExternalProgram(const QString &programTemplate, const BitTo
|
|||
arg = replaceVariables(arg);
|
||||
}
|
||||
|
||||
// show intended command in log
|
||||
LogMsg(logMsg.arg(torrent->name(), replaceVariables(programTemplate)));
|
||||
|
||||
const QString command = args.takeFirst();
|
||||
QProcess::startDetached(command, args);
|
||||
QProcess proc;
|
||||
proc.setProgram(command);
|
||||
proc.setArguments(args);
|
||||
|
||||
if (proc.startDetached())
|
||||
{
|
||||
// show intended command in log
|
||||
LogMsg(logMsg.arg(torrent->name(), replaceVariables(programTemplate)));
|
||||
}
|
||||
else
|
||||
{
|
||||
// show intended command in log
|
||||
LogMsg(logMsgError.arg(torrent->name(), replaceVariables(programTemplate)));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -732,7 +745,7 @@ try
|
|||
actionExit->setIcon(UIThemeManager::instance()->getIcon(u"application-exit"_qs));
|
||||
actionExit->setMenuRole(QAction::QuitRole);
|
||||
actionExit->setShortcut(Qt::CTRL | Qt::Key_Q);
|
||||
connect(actionExit, &QAction::triggered, this, [this]()
|
||||
connect(actionExit, &QAction::triggered, this, []
|
||||
{
|
||||
QApplication::exit();
|
||||
});
|
||||
|
|
|
@ -35,26 +35,6 @@
|
|||
|
||||
namespace
|
||||
{
|
||||
void handleAddTorrentAlert([[maybe_unused]] const lt::add_torrent_alert *alert)
|
||||
{
|
||||
#ifndef QBT_USES_LIBTORRENT2
|
||||
if (alert->error)
|
||||
return;
|
||||
|
||||
// libtorrent < 2.0.7 has a bug that add_torrent_alert is posted too early
|
||||
// (before torrent is fully initialized and torrent extensions are created)
|
||||
// so we have to fill "extension data" in add_torrent_alert handler
|
||||
|
||||
// NOTE: `data` may not exist if a torrent is added behind the scenes to download metadata
|
||||
auto *data = static_cast<ExtensionData *>(alert->params.userdata);
|
||||
if (data)
|
||||
{
|
||||
data->status = alert->handle.status({});
|
||||
data->trackers = alert->handle.trackers();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void handleFastresumeRejectedAlert(const lt::fastresume_rejected_alert *alert)
|
||||
{
|
||||
alert->handle.unset_flags(lt::torrent_flags::auto_managed);
|
||||
|
@ -76,9 +56,6 @@ void NativeSessionExtension::on_alert(const lt::alert *alert)
|
|||
{
|
||||
switch (alert->type())
|
||||
{
|
||||
case lt::add_torrent_alert::alert_type:
|
||||
handleAddTorrentAlert(static_cast<const lt::add_torrent_alert *>(alert));
|
||||
break;
|
||||
case lt::fastresume_rejected_alert::alert_type:
|
||||
handleFastresumeRejectedAlert(static_cast<const lt::fastresume_rejected_alert *>(alert));
|
||||
break;
|
||||
|
|
|
@ -36,18 +36,11 @@ NativeTorrentExtension::NativeTorrentExtension(const lt::torrent_handle &torrent
|
|||
{
|
||||
// NOTE: `data` may not exist if a torrent is added behind the scenes to download metadata
|
||||
|
||||
#ifdef QBT_USES_LIBTORRENT2
|
||||
// libtorrent < 2.0.7 has a bug that add_torrent_alert is posted too early
|
||||
// (before torrent is fully initialized and torrent extensions are created)
|
||||
// so we have to fill "extension data" in add_torrent_alert handler and
|
||||
// we have it already filled at this point
|
||||
|
||||
if (m_data)
|
||||
{
|
||||
m_data->status = m_torrentHandle.status({});
|
||||
m_data->status = m_torrentHandle.status();
|
||||
m_data->trackers = m_torrentHandle.trackers();
|
||||
}
|
||||
#endif
|
||||
|
||||
on_state(m_data ? m_data->status.state : m_torrentHandle.status({}).state);
|
||||
}
|
||||
|
|
|
@ -1386,27 +1386,29 @@ void SessionImpl::endStartup(ResumeSessionContext *context)
|
|||
}
|
||||
|
||||
context->deleteLater();
|
||||
|
||||
m_nativeSession->resume();
|
||||
if (m_refreshEnqueued)
|
||||
m_refreshEnqueued = false;
|
||||
else
|
||||
enqueueRefresh();
|
||||
|
||||
m_statisticsLastUpdateTimer.start();
|
||||
|
||||
// Regular saving of fastresume data
|
||||
connect(m_resumeDataTimer, &QTimer::timeout, this, &SessionImpl::generateResumeData);
|
||||
const int saveInterval = saveResumeDataInterval();
|
||||
if (saveInterval > 0)
|
||||
connect(context, &QObject::destroyed, this, [this]
|
||||
{
|
||||
m_resumeDataTimer->setInterval(std::chrono::minutes(saveInterval));
|
||||
m_resumeDataTimer->start();
|
||||
}
|
||||
m_nativeSession->resume();
|
||||
if (m_refreshEnqueued)
|
||||
m_refreshEnqueued = false;
|
||||
else
|
||||
enqueueRefresh();
|
||||
|
||||
m_isRestored = true;
|
||||
emit startupProgressUpdated(100);
|
||||
emit restored();
|
||||
m_statisticsLastUpdateTimer.start();
|
||||
|
||||
// Regular saving of fastresume data
|
||||
connect(m_resumeDataTimer, &QTimer::timeout, this, &SessionImpl::generateResumeData);
|
||||
const int saveInterval = saveResumeDataInterval();
|
||||
if (saveInterval > 0)
|
||||
{
|
||||
m_resumeDataTimer->setInterval(std::chrono::minutes(saveInterval));
|
||||
m_resumeDataTimer->start();
|
||||
}
|
||||
|
||||
m_isRestored = true;
|
||||
emit startupProgressUpdated(100);
|
||||
emit restored();
|
||||
});
|
||||
}
|
||||
|
||||
void SessionImpl::initializeNativeSession()
|
||||
|
|
|
@ -734,7 +734,13 @@ qreal TorrentImpl::progress() const
|
|||
return 1.;
|
||||
|
||||
const qreal progress = static_cast<qreal>(m_nativeStatus.total_wanted_done) / m_nativeStatus.total_wanted;
|
||||
Q_ASSERT((progress >= 0.f) && (progress <= 1.f));
|
||||
if ((progress < 0.f) || (progress > 1.f))
|
||||
{
|
||||
LogMsg(tr("Unexpected data detected. Torrent: %1. Data: total_wanted=%2 total_wanted_done=%3.")
|
||||
.arg(name(), QString::number(m_nativeStatus.total_wanted), QString::number(m_nativeStatus.total_wanted_done))
|
||||
, Log::WARNING);
|
||||
}
|
||||
|
||||
return progress;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue