|
|
@ -122,6 +122,104 @@ namespace |
|
|
|
#ifndef DISABLE_GUI |
|
|
|
#ifndef DISABLE_GUI |
|
|
|
const int PIXMAP_CACHE_SIZE = 64 * 1024 * 1024; // 64MiB
|
|
|
|
const int PIXMAP_CACHE_SIZE = 64 * 1024 * 1024; // 64MiB
|
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QString serializeParams(const QBtCommandLineParameters ¶ms) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QStringList result; |
|
|
|
|
|
|
|
// Because we're passing a string list to the currently running
|
|
|
|
|
|
|
|
// qBittorrent process, we need some way of passing along the options
|
|
|
|
|
|
|
|
// the user has specified. Here we place special strings that are
|
|
|
|
|
|
|
|
// almost certainly not going to collide with a file path or URL
|
|
|
|
|
|
|
|
// specified by the user, and placing them at the beginning of the
|
|
|
|
|
|
|
|
// string list so that they will be processed before the list of
|
|
|
|
|
|
|
|
// torrent paths or URLs.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const BitTorrent::AddTorrentParams &addTorrentParams = params.addTorrentParams; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!addTorrentParams.savePath.isEmpty()) |
|
|
|
|
|
|
|
result.append(u"@savePath=" + addTorrentParams.savePath.data()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (addTorrentParams.addPaused.has_value()) |
|
|
|
|
|
|
|
result.append(*addTorrentParams.addPaused ? u"@addPaused=1"_qs : u"@addPaused=0"_qs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (addTorrentParams.skipChecking) |
|
|
|
|
|
|
|
result.append(u"@skipChecking"_qs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!addTorrentParams.category.isEmpty()) |
|
|
|
|
|
|
|
result.append(u"@category=" + addTorrentParams.category); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (addTorrentParams.sequential) |
|
|
|
|
|
|
|
result.append(u"@sequential"_qs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (addTorrentParams.firstLastPiecePriority) |
|
|
|
|
|
|
|
result.append(u"@firstLastPiecePriority"_qs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (params.skipDialog.has_value()) |
|
|
|
|
|
|
|
result.append(*params.skipDialog ? u"@skipDialog=1"_qs : u"@skipDialog=0"_qs); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result += params.torrentSources; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return result.join(PARAMS_SEPARATOR); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QBtCommandLineParameters parseParams(const QString &str) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QBtCommandLineParameters parsedParams; |
|
|
|
|
|
|
|
BitTorrent::AddTorrentParams &addTorrentParams = parsedParams.addTorrentParams; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (QString param : asConst(str.split(PARAMS_SEPARATOR, Qt::SkipEmptyParts))) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
param = param.trimmed(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Process strings indicating options specified by the user.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@savePath=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
addTorrentParams.savePath = Path(param.mid(10)); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@addPaused=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
addTorrentParams.addPaused = (QStringView(param).mid(11).toInt() != 0); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param == u"@skipChecking") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
addTorrentParams.skipChecking = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@category=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
addTorrentParams.category = param.mid(10); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param == u"@sequential") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
addTorrentParams.sequential = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param == u"@firstLastPiecePriority") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
addTorrentParams.firstLastPiecePriority = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@skipDialog=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
parsedParams.skipDialog = (QStringView(param).mid(12).toInt() != 0); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parsedParams.torrentSources.append(param); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return parsedParams; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Application::Application(int &argc, char **argv) |
|
|
|
Application::Application(int &argc, char **argv) |
|
|
@ -390,7 +488,7 @@ void Application::processMessage(const QString &message) |
|
|
|
} |
|
|
|
} |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
const AddTorrentParams params = parseParams(message.split(PARAMS_SEPARATOR, Qt::SkipEmptyParts)); |
|
|
|
const QBtCommandLineParameters params = parseParams(message); |
|
|
|
// If Application is not allowed to process params immediately
|
|
|
|
// If Application is not allowed to process params immediately
|
|
|
|
// (i.e., other components are not ready) store params
|
|
|
|
// (i.e., other components are not ready) store params
|
|
|
|
if (m_isProcessingParamsAllowed) |
|
|
|
if (m_isProcessingParamsAllowed) |
|
|
@ -625,71 +723,12 @@ void Application::allTorrentsFinished() |
|
|
|
exit(); |
|
|
|
exit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Application::sendParams(const QStringList ¶ms) |
|
|
|
bool Application::callMainInstance() |
|
|
|
{ |
|
|
|
|
|
|
|
return m_instanceManager->sendMessage(params.join(PARAMS_SEPARATOR)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Application::AddTorrentParams Application::parseParams(const QStringList ¶ms) const |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
AddTorrentParams parsedParams; |
|
|
|
return m_instanceManager->sendMessage(serializeParams(commandLineArgs())); |
|
|
|
BitTorrent::AddTorrentParams &torrentParams = parsedParams.torrentParams; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (QString param : params) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
param = param.trimmed(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Process strings indicating options specified by the user.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@savePath=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
torrentParams.savePath = Path(param.mid(10)); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@addPaused=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
torrentParams.addPaused = (QStringView(param).mid(11).toInt() != 0); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param == u"@skipChecking") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
torrentParams.skipChecking = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@category=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
torrentParams.category = param.mid(10); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param == u"@sequential") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
torrentParams.sequential = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param == u"@firstLastPiecePriority") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
torrentParams.firstLastPiecePriority = true; |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (param.startsWith(u"@skipDialog=")) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
parsedParams.skipTorrentDialog = (QStringView(param).mid(12).toInt() != 0); |
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parsedParams.torrentSources.append(param); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return parsedParams; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Application::processParams(const AddTorrentParams ¶ms) |
|
|
|
void Application::processParams(const QBtCommandLineParameters ¶ms) |
|
|
|
{ |
|
|
|
{ |
|
|
|
#ifndef DISABLE_GUI |
|
|
|
#ifndef DISABLE_GUI |
|
|
|
// There are two circumstances in which we want to show the torrent
|
|
|
|
// There are two circumstances in which we want to show the torrent
|
|
|
@ -697,21 +736,21 @@ void Application::processParams(const AddTorrentParams ¶ms) |
|
|
|
// be shown and skipTorrentDialog is undefined. The other is when
|
|
|
|
// be shown and skipTorrentDialog is undefined. The other is when
|
|
|
|
// skipTorrentDialog is false, meaning that the application setting
|
|
|
|
// skipTorrentDialog is false, meaning that the application setting
|
|
|
|
// should be overridden.
|
|
|
|
// should be overridden.
|
|
|
|
const bool showDialogForThisTorrent = !params.skipTorrentDialog.value_or(!AddNewTorrentDialog::isEnabled()); |
|
|
|
const bool showDialog = !params.skipDialog.value_or(!AddNewTorrentDialog::isEnabled()); |
|
|
|
if (showDialogForThisTorrent) |
|
|
|
if (showDialog) |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (const QString &torrentSource : params.torrentSources) |
|
|
|
for (const QString &torrentSource : params.torrentSources) |
|
|
|
AddNewTorrentDialog::show(torrentSource, params.torrentParams, m_window); |
|
|
|
AddNewTorrentDialog::show(torrentSource, params.addTorrentParams, m_window); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
{ |
|
|
|
{ |
|
|
|
for (const QString &torrentSource : params.torrentSources) |
|
|
|
for (const QString &torrentSource : params.torrentSources) |
|
|
|
BitTorrent::Session::instance()->addTorrent(torrentSource, params.torrentParams); |
|
|
|
BitTorrent::Session::instance()->addTorrent(torrentSource, params.addTorrentParams); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int Application::exec(const QStringList ¶ms) |
|
|
|
int Application::exec() |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
#if !defined(DISABLE_WEBUI) && defined(DISABLE_GUI) |
|
|
|
#if !defined(DISABLE_WEBUI) && defined(DISABLE_GUI) |
|
|
@ -870,13 +909,14 @@ try |
|
|
|
#endif // DISABLE_WEBUI
|
|
|
|
#endif // DISABLE_WEBUI
|
|
|
|
|
|
|
|
|
|
|
|
m_isProcessingParamsAllowed = true; |
|
|
|
m_isProcessingParamsAllowed = true; |
|
|
|
for (const AddTorrentParams ¶ms : m_paramsQueue) |
|
|
|
for (const QBtCommandLineParameters ¶ms : m_paramsQueue) |
|
|
|
processParams(params); |
|
|
|
processParams(params); |
|
|
|
m_paramsQueue.clear(); |
|
|
|
m_paramsQueue.clear(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (!params.isEmpty()) |
|
|
|
const QBtCommandLineParameters params = commandLineArgs(); |
|
|
|
m_paramsQueue.append(parseParams(params)); |
|
|
|
if (!params.torrentSources.isEmpty()) |
|
|
|
|
|
|
|
m_paramsQueue.append(params); |
|
|
|
|
|
|
|
|
|
|
|
return BaseApplication::exec(); |
|
|
|
return BaseApplication::exec(); |
|
|
|
} |
|
|
|
} |
|
|
@ -962,7 +1002,8 @@ bool Application::event(QEvent *ev) |
|
|
|
path = static_cast<QFileOpenEvent *>(ev)->url().toString(); |
|
|
|
path = static_cast<QFileOpenEvent *>(ev)->url().toString(); |
|
|
|
qDebug("Received a mac file open event: %s", qUtf8Printable(path)); |
|
|
|
qDebug("Received a mac file open event: %s", qUtf8Printable(path)); |
|
|
|
|
|
|
|
|
|
|
|
const AddTorrentParams params = parseParams({path}); |
|
|
|
QBtCommandLineParameters params; |
|
|
|
|
|
|
|
params.torrentSources.append(path); |
|
|
|
// If Application is not allowed to process params immediately
|
|
|
|
// If Application is not allowed to process params immediately
|
|
|
|
// (i.e., other components are not ready) store params
|
|
|
|
// (i.e., other components are not ready) store params
|
|
|
|
if (m_isProcessingParamsAllowed) |
|
|
|
if (m_isProcessingParamsAllowed) |
|
|
|