2009-04-09 18:55:47 +00:00
|
|
|
/*
|
2016-04-19 20:41:59 +00:00
|
|
|
* This file Copyright (C) 2009-2016 Mnemosyne LLC
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
2014-12-21 23:49:39 +00:00
|
|
|
* It may be used under the GNU GPL versions 2 or 3
|
2014-01-19 01:09:44 +00:00
|
|
|
* or any future license endorsed by Mnemosyne LLC.
|
2009-04-09 18:55:47 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
#include <QByteArray>
|
2009-12-03 15:23:43 +00:00
|
|
|
#include <QClipboard>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QCoreApplication>
|
2014-12-27 20:08:10 +00:00
|
|
|
#include <QDebug>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QDesktopServices>
|
2014-12-01 19:24:07 +00:00
|
|
|
#include <QFile>
|
2014-12-22 00:02:27 +00:00
|
|
|
#include <QFileInfo>
|
2009-04-09 18:55:47 +00:00
|
|
|
#include <QMessageBox>
|
|
|
|
#include <QStyle>
|
2009-04-12 21:15:35 +00:00
|
|
|
#include <QTextStream>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
#include <libtransmission/transmission.h>
|
2016-10-03 18:26:28 +00:00
|
|
|
#include <libtransmission/session-id.h>
|
2010-12-11 21:27:15 +00:00
|
|
|
#include <libtransmission/utils.h> // tr_free
|
2012-12-14 04:34:42 +00:00
|
|
|
#include <libtransmission/variant.h>
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "AddData.h"
|
2020-05-19 23:42:17 +00:00
|
|
|
#include "CustomVariantType.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Prefs.h"
|
2016-04-19 20:41:59 +00:00
|
|
|
#include "RpcQueue.h"
|
2015-06-10 21:27:11 +00:00
|
|
|
#include "Session.h"
|
|
|
|
#include "SessionDialog.h"
|
|
|
|
#include "Torrent.h"
|
|
|
|
#include "Utils.h"
|
2009-04-09 18:55:47 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
using KeyList = Torrent::KeyList;
|
2014-12-01 19:24:07 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void addList(tr_variant* list, KeyList const& keys)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantListReserve(list, keys.size());
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (tr_quark const key : keys)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantListAddQuark(list, key);
|
|
|
|
}
|
2014-12-01 19:24:07 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// If this object is passed as "ids" (compared by address), then recently active torrents are queried.
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const recently_active_ids = torrent_ids_t{ -1 };
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
// If this object is passed as "ids" (compared by being empty), then all torrents are queried.
|
2020-05-27 21:53:12 +00:00
|
|
|
auto const all_ids = torrent_ids_t{};
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
void Session::sessionSet(tr_quark const key, QVariant const& value)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 1);
|
|
|
|
|
|
|
|
switch (value.type())
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case QVariant::Bool:
|
|
|
|
tr_variantDictAddBool(&args, key, value.toBool());
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case QVariant::Int:
|
|
|
|
tr_variantDictAddInt(&args, key, value.toInt());
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case QVariant::Double:
|
|
|
|
tr_variantDictAddReal(&args, key, value.toDouble());
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case QVariant::String:
|
|
|
|
tr_variantDictAddStr(&args, key, value.toString().toUtf8().constData());
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
|
|
|
assert(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
exec("session-set", &args);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::portTest()
|
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
q->add([this]()
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return exec("port-test", nullptr);
|
|
|
|
});
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
q->add([this](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
bool is_open = false;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
if (r.success)
|
2010-06-17 02:50:50 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
(void)tr_variantDictFindBool(r.args.get(), TR_KEY_port_is_open, &is_open);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
emit portTested(is_open);
|
2017-04-19 12:04:45 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
q->run();
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void Session::copyMagnetLinkToClipboard(int torrent_id)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantListAddInt(tr_variantDictAddList(&args, TR_KEY_ids, 1), torrent_id);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantListAddStr(tr_variantDictAddList(&args, TR_KEY_fields, 1), "magnetLink");
|
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
q->add([this, &args]()
|
|
|
|
{
|
|
|
|
return exec(TR_KEY_torrent_get, &args);
|
|
|
|
});
|
|
|
|
|
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings
* fix: implicit fallthrough warning
* fixup! fix: implicit fallthrough warning
* fix: disable warnings for 3rd party code
Since we want to leave upstream code as-is
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: disable warnings for 3rd party code
* silence spurious alignment warning
Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: https://pagure.io/SSSD/sssd/blob/90ac46f71068d131391492360a8553bdd005b5a7/f/src/util/util_safealign.h#_35
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: implicit fallthrough warning
* make uncrustify happy
* remove uncrustify-test.sh
that's probably off-topic for this PR
* fixup! fix: __attribute__(__printf__) warnings
* Update libtransmission/CMakeLists.txt
Co-Authored-By: ckerr <ckerr@github.com>
* fixup! silence spurious alignment warning
* use -w for DISABLE_WARNINGS in Clang
* refactor: fix libtransmission deprecation warnings
* fix: pthread_create's start_routine's return value
This was defined as `void` on non-Windows but should have been `void*`
* chore: uncrustify
* fix: add DISABLE_WARNINGS option for SunPro Studio
* fix "unused in lambda capture" warnings by clang++
* fix 'increases required alignment' warning
Caused from storing int16_t's in a char array.
* fix net.c 'increases required alignment' warning
The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.
* make building quieter so warnings are more visible
* fixup! fix 'increases required alignment' warning
* Fix -Wcast-function-type warnings in GTK+ app code
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.
GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.
Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.
In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).
* fixup! fix "unused in lambda capture" warnings by clang++
* fixup! fix "unused in lambda capture" warnings by clang++
* fix two more libtransmission compiler warnings
* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 17:27:03 +00:00
|
|
|
q->add([](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variant* torrents;
|
2019-02-10 11:05:16 +00:00
|
|
|
|
|
|
|
if (!tr_variantDictFindList(r.args.get(), TR_KEY_torrents, &torrents))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tr_variant* const child = tr_variantListChild(torrents, 0);
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* str;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2019-02-10 11:05:16 +00:00
|
|
|
if (child != nullptr && tr_variantDictFindStr(child, TR_KEY_magnetLink, &str, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
qApp->clipboard()->setText(QString::fromUtf8(str));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
q->run();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::updatePref(int key)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (prefs_.isCore(key))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
switch (key)
|
|
|
|
{
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_DOWN:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_ENABLED:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_TIME_BEGIN:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_TIME_DAY:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_TIME_ENABLED:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_TIME_END:
|
|
|
|
case Prefs::ALT_SPEED_LIMIT_UP:
|
|
|
|
case Prefs::BLOCKLIST_DATE:
|
|
|
|
case Prefs::BLOCKLIST_ENABLED:
|
|
|
|
case Prefs::BLOCKLIST_URL:
|
|
|
|
case Prefs::DHT_ENABLED:
|
|
|
|
case Prefs::DOWNLOAD_QUEUE_ENABLED:
|
|
|
|
case Prefs::DOWNLOAD_QUEUE_SIZE:
|
|
|
|
case Prefs::DSPEED:
|
|
|
|
case Prefs::DSPEED_ENABLED:
|
|
|
|
case Prefs::IDLE_LIMIT:
|
|
|
|
case Prefs::IDLE_LIMIT_ENABLED:
|
|
|
|
case Prefs::INCOMPLETE_DIR:
|
|
|
|
case Prefs::INCOMPLETE_DIR_ENABLED:
|
|
|
|
case Prefs::LPD_ENABLED:
|
|
|
|
case Prefs::PEER_LIMIT_GLOBAL:
|
|
|
|
case Prefs::PEER_LIMIT_TORRENT:
|
|
|
|
case Prefs::PEER_PORT:
|
|
|
|
case Prefs::PEER_PORT_RANDOM_ON_START:
|
|
|
|
case Prefs::QUEUE_STALLED_MINUTES:
|
|
|
|
case Prefs::PEX_ENABLED:
|
|
|
|
case Prefs::PORT_FORWARDING:
|
|
|
|
case Prefs::RENAME_PARTIAL_FILES:
|
|
|
|
case Prefs::SCRIPT_TORRENT_DONE_ENABLED:
|
|
|
|
case Prefs::SCRIPT_TORRENT_DONE_FILENAME:
|
|
|
|
case Prefs::START:
|
|
|
|
case Prefs::TRASH_ORIGINAL:
|
|
|
|
case Prefs::USPEED:
|
|
|
|
case Prefs::USPEED_ENABLED:
|
|
|
|
case Prefs::UTP_ENABLED:
|
2020-05-27 21:53:12 +00:00
|
|
|
sessionSet(prefs_.getKey(key), prefs_.variant(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::DOWNLOAD_DIR:
|
2020-05-27 21:53:12 +00:00
|
|
|
sessionSet(prefs_.getKey(key), prefs_.variant(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
/* this will change the 'freespace' argument, so refresh */
|
|
|
|
refreshSessionInfo();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::RATIO:
|
2020-05-27 21:53:12 +00:00
|
|
|
sessionSet(TR_KEY_seedRatioLimit, prefs_.variant(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::RATIO_ENABLED:
|
2020-05-27 21:53:12 +00:00
|
|
|
sessionSet(TR_KEY_seedRatioLimited, prefs_.variant(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::ENCRYPTION:
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
int const i = prefs_.variant(key).toInt();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
switch (i)
|
|
|
|
{
|
|
|
|
case 0:
|
2020-05-29 17:40:07 +00:00
|
|
|
sessionSet(prefs_.getKey(key), QStringLiteral("tolerated"));
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2020-05-29 17:40:07 +00:00
|
|
|
sessionSet(prefs_.getKey(key), QStringLiteral("preferred"));
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2020-05-29 17:40:07 +00:00
|
|
|
sessionSet(prefs_.getKey(key), QStringLiteral("required"));
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-17 02:50:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RPC_AUTH_REQUIRED:
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionSetRPCPasswordEnabled(session_, prefs_.getBool(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RPC_ENABLED:
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionSetRPCEnabled(session_, prefs_.getBool(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RPC_PASSWORD:
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionSetRPCPassword(session_, prefs_.getString(key).toUtf8().constData());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case Prefs::RPC_PORT:
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionSetRPCPort(session_, prefs_.getInt(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::RPC_USERNAME:
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionSetRPCUsername(session_, prefs_.getString(key).toUtf8().constData());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::RPC_WHITELIST_ENABLED:
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionSetRPCWhitelistEnabled(session_, prefs_.getBool(key));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Prefs::RPC_WHITELIST:
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionSetRPCWhitelist(session_, prefs_.getString(key).toUtf8().constData());
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
std::cerr << "unhandled pref: " << key << std::endl;
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
Session::Session(QString const& config_dir, Prefs& prefs) :
|
|
|
|
config_dir_(config_dir),
|
|
|
|
prefs_(prefs)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
stats_.ratio = TR_RATIO_NA;
|
|
|
|
stats_.uploadedBytes = 0;
|
|
|
|
stats_.downloadedBytes = 0;
|
|
|
|
stats_.filesAdded = 0;
|
|
|
|
stats_.sessionCount = 0;
|
|
|
|
stats_.secondsActive = 0;
|
|
|
|
cumulative_stats_ = stats_;
|
|
|
|
|
|
|
|
connect(&prefs_, SIGNAL(changed(int)), this, SLOT(updatePref(int)));
|
|
|
|
connect(&rpc_, SIGNAL(httpAuthenticationRequired()), this, SIGNAL(httpAuthenticationRequired()));
|
|
|
|
connect(&rpc_, SIGNAL(dataReadProgress()), this, SIGNAL(dataReadProgress()));
|
|
|
|
connect(&rpc_, SIGNAL(dataSendProgress()), this, SIGNAL(dataSendProgress()));
|
|
|
|
connect(&rpc_, SIGNAL(networkResponse(QNetworkReply::NetworkError, QString)), this,
|
2017-04-19 12:04:45 +00:00
|
|
|
SIGNAL(networkResponse(QNetworkReply::NetworkError, QString)));
|
2009-05-03 17:37:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
Session::~Session()
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
stop();
|
2009-05-03 17:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::stop()
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
rpc_.stop();
|
2009-05-03 17:37:39 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionClose(session_);
|
|
|
|
session_ = nullptr;
|
2009-05-03 17:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::restart()
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
stop();
|
|
|
|
start();
|
2009-05-03 17:37:39 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::start()
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (prefs_.get<bool>(Prefs::SESSION_IS_REMOTE))
|
2009-05-03 17:37:39 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QUrl url;
|
2020-05-29 17:40:07 +00:00
|
|
|
url.setScheme(QStringLiteral("http"));
|
2020-05-27 21:53:12 +00:00
|
|
|
url.setHost(prefs_.get<QString>(Prefs::SESSION_REMOTE_HOST));
|
|
|
|
url.setPort(prefs_.get<int>(Prefs::SESSION_REMOTE_PORT));
|
2020-05-29 17:40:07 +00:00
|
|
|
url.setPath(QStringLiteral("/transmission/rpc"));
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (prefs_.get<bool>(Prefs::SESSION_REMOTE_AUTH))
|
2010-08-04 13:56:52 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
url.setUserName(prefs_.get<QString>(Prefs::SESSION_REMOTE_USERNAME));
|
|
|
|
url.setPassword(prefs_.get<QString>(Prefs::SESSION_REMOTE_PASSWORD));
|
2009-05-03 17:37:39 +00:00
|
|
|
}
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
rpc_.start(url);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant settings;
|
|
|
|
tr_variantInitDict(&settings, 0);
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_sessionLoadSettings(&settings, config_dir_.toUtf8().constData(), "qt");
|
|
|
|
session_ = tr_sessionInit(config_dir_.toUtf8().constData(), true, &settings);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantFree(&settings);
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
rpc_.start(session_);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_ctor* ctor = tr_ctorNew(session_);
|
|
|
|
int torrent_count;
|
|
|
|
tr_torrent** torrents = tr_sessionLoadTorrents(session_, ctor, &torrent_count);
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_free(torrents);
|
|
|
|
tr_ctorFree(ctor);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
emit sourceChanged();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool Session::isServer() const
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return session_ != nullptr;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool Session::isLocal() const
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (!session_id_.isEmpty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return is_definitely_local_session_;
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
return rpc_.isLocal();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void addOptionalIds(tr_variant* args, torrent_ids_t const& ids)
|
2009-04-12 21:15:35 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
if (&ids == &recently_active_ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantDictAddStr(args, TR_KEY_ids, "recently-active");
|
|
|
|
}
|
2019-11-12 01:37:05 +00:00
|
|
|
else if (!ids.empty())
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variant* id_list(tr_variantDictAddList(args, TR_KEY_ids, ids.size()));
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (int const i : ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantListAddInt(id_list, i);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-12 21:15:35 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
} // namespace
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, double value)
|
2009-04-12 21:15:35 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
tr_variantDictAddReal(&args, key, value);
|
|
|
|
addOptionalIds(&args, ids);
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec(TR_KEY_torrent_set, &args);
|
2009-04-12 21:15:35 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, int value)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
tr_variantDictAddInt(&args, key, value);
|
|
|
|
addOptionalIds(&args, ids);
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec(TR_KEY_torrent_set, &args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, bool value)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
tr_variantDictAddBool(&args, key, value);
|
|
|
|
addOptionalIds(&args, ids);
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec(TR_KEY_torrent_set, &args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, QStringList const& value)
|
2010-06-30 05:55:46 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
addOptionalIds(&args, ids);
|
|
|
|
tr_variant* list(tr_variantDictAddList(&args, key, value.size()));
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (QString const& str : value)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantListAddStr(list, str.toUtf8().constData());
|
|
|
|
}
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec(TR_KEY_torrent_set, &args);
|
2010-06-30 05:55:46 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, QList<int> const& value)
|
2010-09-14 06:23:48 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
addOptionalIds(&args, ids);
|
|
|
|
tr_variant* list(tr_variantDictAddList(&args, key, value.size()));
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
for (int const i : value)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variantListAddInt(list, i);
|
|
|
|
}
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec(TR_KEY_torrent_set, &args);
|
2010-09-14 06:23:48 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::torrentSet(torrent_ids_t const& ids, tr_quark const key, QPair<int, QString> const& value)
|
2009-05-13 15:54:04 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
addOptionalIds(&args, ids);
|
|
|
|
tr_variant* list(tr_variantDictAddList(&args, key, 2));
|
|
|
|
tr_variantListAddInt(list, value.first);
|
|
|
|
tr_variantListAddStr(list, value.second.toUtf8().constData());
|
|
|
|
|
|
|
|
exec(TR_KEY_torrent_set, &args);
|
2009-05-13 15:54:04 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void Session::torrentSetLocation(torrent_ids_t const& ids, QString const& location, bool do_move)
|
2013-01-20 01:31:58 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 3);
|
|
|
|
addOptionalIds(&args, ids);
|
|
|
|
tr_variantDictAddStr(&args, TR_KEY_location, location.toUtf8().constData());
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantDictAddBool(&args, TR_KEY_move, do_move);
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec(TR_KEY_torrent_set_location, &args);
|
|
|
|
}
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::torrentRenamePath(torrent_ids_t const& ids, QString const& oldpath, QString const& newname)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
addOptionalIds(&args, ids);
|
|
|
|
tr_variantDictAddStr(&args, TR_KEY_path, oldpath.toUtf8().constData());
|
|
|
|
tr_variantDictAddStr(&args, TR_KEY_name, newname.toUtf8().constData());
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this, &args]()
|
|
|
|
{
|
|
|
|
return exec("torrent-rename-path", &args);
|
|
|
|
},
|
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings
* fix: implicit fallthrough warning
* fixup! fix: implicit fallthrough warning
* fix: disable warnings for 3rd party code
Since we want to leave upstream code as-is
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: disable warnings for 3rd party code
* silence spurious alignment warning
Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: https://pagure.io/SSSD/sssd/blob/90ac46f71068d131391492360a8553bdd005b5a7/f/src/util/util_safealign.h#_35
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: implicit fallthrough warning
* make uncrustify happy
* remove uncrustify-test.sh
that's probably off-topic for this PR
* fixup! fix: __attribute__(__printf__) warnings
* Update libtransmission/CMakeLists.txt
Co-Authored-By: ckerr <ckerr@github.com>
* fixup! silence spurious alignment warning
* use -w for DISABLE_WARNINGS in Clang
* refactor: fix libtransmission deprecation warnings
* fix: pthread_create's start_routine's return value
This was defined as `void` on non-Windows but should have been `void*`
* chore: uncrustify
* fix: add DISABLE_WARNINGS option for SunPro Studio
* fix "unused in lambda capture" warnings by clang++
* fix 'increases required alignment' warning
Caused from storing int16_t's in a char array.
* fix net.c 'increases required alignment' warning
The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.
* make building quieter so warnings are more visible
* fixup! fix 'increases required alignment' warning
* Fix -Wcast-function-type warnings in GTK+ app code
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.
GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.
Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.
In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).
* fixup! fix "unused in lambda capture" warnings by clang++
* fixup! fix "unused in lambda capture" warnings by clang++
* fix two more libtransmission compiler warnings
* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 17:27:03 +00:00
|
|
|
[](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* path = "(unknown)";
|
|
|
|
char const* name = "(unknown)";
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictFindStr(r.args.get(), TR_KEY_path, &path, nullptr);
|
|
|
|
tr_variantDictFindStr(r.args.get(), TR_KEY_name, &name, nullptr);
|
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* d = new QMessageBox(QMessageBox::Information, tr("Error Renaming Path"),
|
2017-04-19 12:04:45 +00:00
|
|
|
tr("<p><b>Unable to rename \"%1\" as \"%2\": %3.</b></p><p>Please correct the errors and try again.</p>").
|
|
|
|
arg(QString::fromUtf8(path)).arg(QString::fromUtf8(name)).arg(r.result), QMessageBox::Close,
|
|
|
|
qApp->activeWindow());
|
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings
* fix: implicit fallthrough warning
* fixup! fix: implicit fallthrough warning
* fix: disable warnings for 3rd party code
Since we want to leave upstream code as-is
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: disable warnings for 3rd party code
* silence spurious alignment warning
Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: https://pagure.io/SSSD/sssd/blob/90ac46f71068d131391492360a8553bdd005b5a7/f/src/util/util_safealign.h#_35
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: implicit fallthrough warning
* make uncrustify happy
* remove uncrustify-test.sh
that's probably off-topic for this PR
* fixup! fix: __attribute__(__printf__) warnings
* Update libtransmission/CMakeLists.txt
Co-Authored-By: ckerr <ckerr@github.com>
* fixup! silence spurious alignment warning
* use -w for DISABLE_WARNINGS in Clang
* refactor: fix libtransmission deprecation warnings
* fix: pthread_create's start_routine's return value
This was defined as `void` on non-Windows but should have been `void*`
* chore: uncrustify
* fix: add DISABLE_WARNINGS option for SunPro Studio
* fix "unused in lambda capture" warnings by clang++
* fix 'increases required alignment' warning
Caused from storing int16_t's in a char array.
* fix net.c 'increases required alignment' warning
The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.
* make building quieter so warnings are more visible
* fixup! fix 'increases required alignment' warning
* Fix -Wcast-function-type warnings in GTK+ app code
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.
GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.
Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.
In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).
* fixup! fix "unused in lambda capture" warnings by clang++
* fixup! fix "unused in lambda capture" warnings by clang++
* fix two more libtransmission compiler warnings
* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 17:27:03 +00:00
|
|
|
QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
2017-04-19 12:04:45 +00:00
|
|
|
d->show();
|
|
|
|
});
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
q->add([this, ids](RpcResponse const& /*r*/)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
refreshTorrents(ids, { TR_KEY_fileStats, TR_KEY_files, TR_KEY_id, TR_KEY_name });
|
2017-04-19 12:04:45 +00:00
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->run();
|
2013-01-20 01:31:58 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::refreshTorrents(torrent_ids_t const& ids, KeyList const& keys)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
2019-11-09 23:02:23 +00:00
|
|
|
tr_variantInitDict(&args, 3);
|
|
|
|
tr_variantDictAddStr(&args, TR_KEY_format, "table");
|
2017-04-19 12:04:45 +00:00
|
|
|
addList(tr_variantDictAddList(&args, TR_KEY_fields, 0), keys);
|
|
|
|
addOptionalIds(&args, ids);
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this, &args]()
|
|
|
|
{
|
|
|
|
return exec(TR_KEY_torrent_get, &args);
|
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
bool const all_torrents = ids.empty();
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
q->add([this, all_torrents](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variant* torrents;
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindList(r.args.get(), TR_KEY_torrents, &torrents))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
emit torrentsUpdated(torrents, all_torrents);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tr_variantDictFindList(r.args.get(), TR_KEY_removed, &torrents))
|
|
|
|
{
|
|
|
|
emit torrentsRemoved(torrents);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
q->run();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::refreshDetailInfo(torrent_ids_t const& ids)
|
2019-11-09 14:44:40 +00:00
|
|
|
{
|
|
|
|
refreshTorrents(ids, Torrent::detailInfoKeys);
|
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::refreshExtraStats(torrent_ids_t const& ids)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2019-11-09 14:44:40 +00:00
|
|
|
refreshTorrents(ids, Torrent::mainStatKeys + Torrent::detailStatKeys);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::sendTorrentRequest(char const* request, torrent_ids_t const& ids)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 1);
|
|
|
|
addOptionalIds(&args, ids);
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this, request, &args]()
|
|
|
|
{
|
|
|
|
return exec(request, &args);
|
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this, ids]()
|
|
|
|
{
|
2019-11-09 14:44:40 +00:00
|
|
|
refreshTorrents(ids, Torrent::mainStatKeys);
|
2017-04-19 12:04:45 +00:00
|
|
|
});
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->run();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::pauseTorrents(torrent_ids_t const& ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
sendTorrentRequest("torrent-stop", ids);
|
|
|
|
}
|
2017-04-20 16:02:19 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::startTorrents(torrent_ids_t const& ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
sendTorrentRequest("torrent-start", ids);
|
|
|
|
}
|
2017-04-20 16:02:19 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::startTorrentsNow(torrent_ids_t const& ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
sendTorrentRequest("torrent-start-now", ids);
|
|
|
|
}
|
2017-04-20 16:02:19 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::queueMoveTop(torrent_ids_t const& ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
sendTorrentRequest("queue-move-top", ids);
|
|
|
|
}
|
2017-04-20 16:02:19 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::queueMoveUp(torrent_ids_t const& ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
sendTorrentRequest("queue-move-up", ids);
|
|
|
|
}
|
2017-04-20 16:02:19 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::queueMoveDown(torrent_ids_t const& ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
sendTorrentRequest("queue-move-down", ids);
|
|
|
|
}
|
2017-04-20 16:02:19 +00:00
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::queueMoveBottom(torrent_ids_t const& ids)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
sendTorrentRequest("queue-move-bottom", ids);
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::refreshActiveTorrents()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
refreshTorrents(recently_active_ids, Torrent::mainStatKeys);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::refreshAllTorrents()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
refreshTorrents(all_ids, Torrent::mainStatKeys);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::initTorrents(torrent_ids_t const& ids)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2019-11-09 14:44:40 +00:00
|
|
|
refreshTorrents(ids, Torrent::allMainKeys);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::refreshSessionStats()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this]()
|
|
|
|
{
|
|
|
|
return exec("session-stats", nullptr);
|
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
q->add([this](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
updateStats(r.args.get());
|
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->run();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::refreshSessionInfo()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this]()
|
|
|
|
{
|
|
|
|
return exec("session-get", nullptr);
|
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
q->add([this](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
updateInfo(r.args.get());
|
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->run();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::updateBlocklist()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this]()
|
|
|
|
{
|
|
|
|
return exec("blocklist-update", nullptr);
|
|
|
|
});
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
q->add([this](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
int64_t blocklist_size;
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (tr_variantDictFindInt(r.args.get(), TR_KEY_blocklist_size, &blocklist_size))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
setBlocklistSize(blocklist_size);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
q->run();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
RpcResponseFuture Session::exec(tr_quark method, tr_variant* args)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return rpc_.exec(method, args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
RpcResponseFuture Session::exec(char const* method, tr_variant* args)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
return rpc_.exec(method, args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::updateStats(tr_variant* d, tr_session_stats* stats)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int64_t i;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindInt(d, TR_KEY_uploadedBytes, &i))
|
|
|
|
{
|
|
|
|
stats->uploadedBytes = i;
|
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindInt(d, TR_KEY_downloadedBytes, &i))
|
|
|
|
{
|
|
|
|
stats->downloadedBytes = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tr_variantDictFindInt(d, TR_KEY_filesAdded, &i))
|
|
|
|
{
|
|
|
|
stats->filesAdded = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tr_variantDictFindInt(d, TR_KEY_sessionCount, &i))
|
|
|
|
{
|
|
|
|
stats->sessionCount = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tr_variantDictFindInt(d, TR_KEY_secondsActive, &i))
|
|
|
|
{
|
|
|
|
stats->secondsActive = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
stats->ratio = tr_getRatio(stats->uploadedBytes, stats->downloadedBytes);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::updateStats(tr_variant* d)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant* c;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindDict(d, TR_KEY_current_stats, &c))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
updateStats(c, &stats_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindDict(d, TR_KEY_cumulative_stats, &c))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
updateStats(c, &cumulative_stats_);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
emit statsUpdated();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::updateInfo(tr_variant* d)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int64_t i;
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* str;
|
2012-12-22 20:35:19 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
disconnect(&prefs_, SIGNAL(changed(int)), this, SLOT(updatePref(int)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
for (int i = Prefs::FIRST_CORE_PREF; i <= Prefs::LAST_CORE_PREF; ++i)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variant const* b(tr_variantDictFind(d, prefs_.getKey(i)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-30 16:25:26 +00:00
|
|
|
if (b == nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (i == Prefs::ENCRYPTION)
|
2010-06-17 02:50:50 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* val;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
if (tr_variantGetStr(b, &val, nullptr))
|
2010-06-17 02:50:50 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
if (qstrcmp(val, "required") == 0)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(i, 2);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else if (qstrcmp(val, "preferred") == 0)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(i, 1);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
else if (qstrcmp(val, "tolerated") == 0)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(i, 0);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2010-06-17 02:50:50 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
continue;
|
2010-06-17 02:50:50 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
switch (prefs_.type(i))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case QVariant::Int:
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
int64_t val;
|
|
|
|
|
|
|
|
if (tr_variantGetInt(b, &val))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(i, static_cast<int>(val));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case QVariant::Double:
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
double val;
|
|
|
|
|
|
|
|
if (tr_variantGetReal(b, &val))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(i, val);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case QVariant::Bool:
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
bool val;
|
|
|
|
|
|
|
|
if (tr_variantGetBool(b, &val))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(i, val);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
case CustomVariantType::FilterModeType:
|
|
|
|
case CustomVariantType::SortModeType:
|
|
|
|
case QVariant::String:
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* val;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
if (tr_variantGetStr(b, &val, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(i, QString::fromUtf8(val));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
|
|
|
|
default:
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
bool b;
|
|
|
|
double x;
|
2010-06-08 17:37:29 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindBool(d, TR_KEY_seedRatioLimited, &b))
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::RATIO_ENABLED, b);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindReal(d, TR_KEY_seedRatioLimit, &x))
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::RATIO, x);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
/* Use the C API to get settings that, for security reasons, aren't supported by RPC */
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ != nullptr)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
prefs_.set(Prefs::RPC_ENABLED, tr_sessionIsRPCEnabled(session_));
|
|
|
|
prefs_.set(Prefs::RPC_AUTH_REQUIRED, tr_sessionIsRPCPasswordEnabled(session_));
|
|
|
|
prefs_.set(Prefs::RPC_PASSWORD, QString::fromUtf8(tr_sessionGetRPCPassword(session_)));
|
|
|
|
prefs_.set(Prefs::RPC_PORT, tr_sessionGetRPCPort(session_));
|
|
|
|
prefs_.set(Prefs::RPC_USERNAME, QString::fromUtf8(tr_sessionGetRPCUsername(session_)));
|
|
|
|
prefs_.set(Prefs::RPC_WHITELIST_ENABLED, tr_sessionGetRPCWhitelistEnabled(session_));
|
|
|
|
prefs_.set(Prefs::RPC_WHITELIST, QString::fromUtf8(tr_sessionGetRPCWhitelist(session_)));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFindInt(d, TR_KEY_blocklist_size, &i) && i != blocklistSize())
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
setBlocklistSize(i);
|
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (tr_variantDictFindStr(d, TR_KEY_version, &str, nullptr) && session_version_ != QString::fromUtf8(str))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_version_ = QString::fromUtf8(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
|
|
|
|
2017-04-30 09:29:58 +00:00
|
|
|
if (tr_variantDictFindStr(d, TR_KEY_session_id, &str, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QString const session_id = QString::fromUtf8(str);
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_id_ != session_id)
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_id_ = session_id;
|
|
|
|
is_definitely_local_session_ = tr_session_id_is_local(str);
|
2016-10-03 18:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else
|
2016-10-03 18:26:28 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
session_id_.clear();
|
2016-10-03 18:26:28 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
// std::cerr << "Session::updateInfo end" << std::endl;
|
2020-05-27 21:53:12 +00:00
|
|
|
connect(&prefs_, SIGNAL(changed(int)), this, SLOT(updatePref(int)));
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
emit sessionUpdated();
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::setBlocklistSize(int64_t i)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
blocklist_size_ = i;
|
2009-04-09 18:55:47 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
emit blocklistUpdated(i);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void Session::addTorrent(AddData const& add_me, tr_variant* args, bool trash_original)
|
2009-10-05 19:53:38 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
assert(tr_variantDictFind(args, TR_KEY_filename) == nullptr);
|
|
|
|
assert(tr_variantDictFind(args, TR_KEY_metainfo) == nullptr);
|
2014-12-01 19:24:07 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
if (tr_variantDictFind(args, TR_KEY_paused) == nullptr)
|
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantDictAddBool(args, TR_KEY_paused, !prefs_.getBool(Prefs::START));
|
2017-04-19 12:04:45 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
switch (add_me.type)
|
2013-02-03 19:40:20 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
case AddData::MAGNET:
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantDictAddStr(args, TR_KEY_filename, add_me.magnet.toUtf8().constData());
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case AddData::URL:
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantDictAddStr(args, TR_KEY_filename, add_me.url.toString().toUtf8().constData());
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
case AddData::FILENAME: /* fall-through */
|
|
|
|
case AddData::METAINFO:
|
2014-12-01 19:24:07 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QByteArray const b64 = add_me.toBase64();
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddRaw(args, TR_KEY_metainfo, b64.constData(), b64.size());
|
|
|
|
break;
|
2014-12-01 19:24:07 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
default:
|
2020-05-27 21:53:12 +00:00
|
|
|
qWarning() << "Unhandled AddData type: " << add_me.type;
|
2013-02-03 19:40:20 +00:00
|
|
|
break;
|
2010-04-27 03:10:32 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* q = new RpcQueue();
|
2016-04-19 20:41:59 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->add([this, args]()
|
2016-04-19 20:41:59 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
return exec("torrent-add", args);
|
|
|
|
},
|
2020-05-27 21:53:12 +00:00
|
|
|
[add_me](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* d = new QMessageBox(QMessageBox::Warning, tr("Error Adding Torrent"),
|
2020-05-29 17:40:07 +00:00
|
|
|
QStringLiteral("<p><b>%1</b></p><p>%2</p>").arg(r.result).arg(add_me.readableName()), QMessageBox::Close,
|
2017-04-19 12:04:45 +00:00
|
|
|
qApp->activeWindow());
|
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings
* fix: implicit fallthrough warning
* fixup! fix: implicit fallthrough warning
* fix: disable warnings for 3rd party code
Since we want to leave upstream code as-is
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: disable warnings for 3rd party code
* silence spurious alignment warning
Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: https://pagure.io/SSSD/sssd/blob/90ac46f71068d131391492360a8553bdd005b5a7/f/src/util/util_safealign.h#_35
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: implicit fallthrough warning
* make uncrustify happy
* remove uncrustify-test.sh
that's probably off-topic for this PR
* fixup! fix: __attribute__(__printf__) warnings
* Update libtransmission/CMakeLists.txt
Co-Authored-By: ckerr <ckerr@github.com>
* fixup! silence spurious alignment warning
* use -w for DISABLE_WARNINGS in Clang
* refactor: fix libtransmission deprecation warnings
* fix: pthread_create's start_routine's return value
This was defined as `void` on non-Windows but should have been `void*`
* chore: uncrustify
* fix: add DISABLE_WARNINGS option for SunPro Studio
* fix "unused in lambda capture" warnings by clang++
* fix 'increases required alignment' warning
Caused from storing int16_t's in a char array.
* fix net.c 'increases required alignment' warning
The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.
* make building quieter so warnings are more visible
* fixup! fix 'increases required alignment' warning
* Fix -Wcast-function-type warnings in GTK+ app code
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.
GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.
Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.
In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).
* fixup! fix "unused in lambda capture" warnings by clang++
* fixup! fix "unused in lambda capture" warnings by clang++
* fix two more libtransmission compiler warnings
* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 17:27:03 +00:00
|
|
|
QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
2017-04-19 12:04:45 +00:00
|
|
|
d->show();
|
|
|
|
});
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
q->add([add_me](RpcResponse const& r)
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
|
|
|
tr_variant* dup;
|
2019-02-10 11:05:16 +00:00
|
|
|
|
|
|
|
if (!tr_variantDictFindDict(r.args.get(), TR_KEY_torrent_duplicate, &dup))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-04-20 16:02:19 +00:00
|
|
|
char const* str;
|
2017-04-19 12:04:45 +00:00
|
|
|
|
2019-02-10 11:05:16 +00:00
|
|
|
if (tr_variantDictFindStr(dup, TR_KEY_name, &str, nullptr))
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QString const name = QString::fromUtf8(str);
|
2020-05-20 01:32:51 +00:00
|
|
|
auto* d = new QMessageBox(QMessageBox::Warning, tr("Add Torrent"),
|
2017-04-19 12:04:45 +00:00
|
|
|
tr("<p><b>Unable to add \"%1\".</b></p><p>It is a duplicate of \"%2\" which is already added.</p>").
|
2020-05-27 21:53:12 +00:00
|
|
|
arg(add_me.readableShortName()).arg(name), QMessageBox::Close, qApp->activeWindow());
|
fix: gcc warnings in libtransmission/ and utils/ (#843)
* fix: __attribute__(__printf__) warnings
* fix: implicit fallthrough warning
* fixup! fix: implicit fallthrough warning
* fix: disable warnings for 3rd party code
Since we want to leave upstream code as-is
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: disable warnings for 3rd party code
* silence spurious alignment warning
Xrefs
Discussion: https://stackoverflow.com/a/35554349
Macro inspiration: https://pagure.io/SSSD/sssd/blob/90ac46f71068d131391492360a8553bdd005b5a7/f/src/util/util_safealign.h#_35
* fixup! fix: disable warnings for 3rd party code
* fixup! fix: implicit fallthrough warning
* make uncrustify happy
* remove uncrustify-test.sh
that's probably off-topic for this PR
* fixup! fix: __attribute__(__printf__) warnings
* Update libtransmission/CMakeLists.txt
Co-Authored-By: ckerr <ckerr@github.com>
* fixup! silence spurious alignment warning
* use -w for DISABLE_WARNINGS in Clang
* refactor: fix libtransmission deprecation warnings
* fix: pthread_create's start_routine's return value
This was defined as `void` on non-Windows but should have been `void*`
* chore: uncrustify
* fix: add DISABLE_WARNINGS option for SunPro Studio
* fix "unused in lambda capture" warnings by clang++
* fix 'increases required alignment' warning
Caused from storing int16_t's in a char array.
* fix net.c 'increases required alignment' warning
The code passes in a `struct sockaddr_storage*` which is a padded struct
large enough for the necessary alignment. Unfortunately it was recast as
a `struct sockaddr*` which has less padding and a smaller alignment. The
warning occrred because of these differing alignments.
* make building quieter so warnings are more visible
* fixup! fix 'increases required alignment' warning
* Fix -Wcast-function-type warnings in GTK+ app code
https://gitlab.gnome.org/GNOME/gnome-terminal/issues/96 talks about both
the issue and its solution.
GCC 8's -Wcast-function-type, enabled by -Wextra, is problematic in glib
applications because it's idiomatic there to recast function signatures,
e.g. `g_slist_free(list, (GFunc)g_free, NULL);`.
Disabling the warning with pragmas causes "unrecognized pragma" warnings
on clang and older versions of gcc, and disabling the warning could miss
actual bugs. GCC defines `void (*)(void)` as a special case that matches
anything so we can silence warnings by double-casting through GCallback.
In the previous example, the warning is silenced by changing the code to
read `g_slist_free(list, (GFunc)(GCallback)g_free, NULL);`).
* fixup! fix "unused in lambda capture" warnings by clang++
* fixup! fix "unused in lambda capture" warnings by clang++
* fix two more libtransmission compiler warnings
* fix: in watchdir, use TR_ENABLE_ASSERTS not NDEBUG
2019-11-06 17:27:03 +00:00
|
|
|
QObject::connect(d, &QMessageBox::rejected, d, &QMessageBox::deleteLater);
|
2017-04-19 12:04:45 +00:00
|
|
|
d->show();
|
|
|
|
}
|
2017-07-15 05:46:31 +00:00
|
|
|
});
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (trash_original && add_me.type == AddData::FILENAME)
|
2017-07-15 05:46:31 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
q->add([add_me]()
|
2017-04-19 12:04:45 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
QFile original(add_me.filename);
|
2017-04-19 12:04:45 +00:00
|
|
|
original.setPermissions(QFile::ReadOwner | QFile::WriteOwner);
|
|
|
|
original.remove();
|
2017-07-15 05:46:31 +00:00
|
|
|
});
|
|
|
|
}
|
2014-12-01 19:24:07 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
q->run();
|
2014-12-01 19:24:07 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void Session::addTorrent(AddData const& add_me)
|
2014-12-01 19:24:07 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 3);
|
2014-12-01 19:24:07 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
addTorrent(add_me, &args, prefs_.getBool(Prefs::TRASH_ORIGINAL));
|
2010-04-27 03:10:32 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void Session::addNewlyCreatedTorrent(QString const& filename, QString const& local_path)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-20 16:02:19 +00:00
|
|
|
QByteArray const b64 = AddData(filename).toBase64();
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 3);
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantDictAddStr(&args, TR_KEY_download_dir, local_path.toUtf8().constData());
|
|
|
|
tr_variantDictAddBool(&args, TR_KEY_paused, !prefs_.getBool(Prefs::START));
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variantDictAddRaw(&args, TR_KEY_metainfo, b64.constData(), b64.size());
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec("torrent-add", &args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
void Session::removeTorrents(torrent_ids_t const& ids, bool delete_files)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
if (!ids.empty())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 2);
|
|
|
|
addOptionalIds(&args, ids);
|
2020-05-27 21:53:12 +00:00
|
|
|
tr_variantDictAddInt(&args, TR_KEY_delete_local_data, delete_files);
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec("torrent-remove", &args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::verifyTorrents(torrent_ids_t const& ids)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
if (!ids.empty())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 1);
|
|
|
|
addOptionalIds(&args, ids);
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec("torrent-verify", &args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-12 01:37:05 +00:00
|
|
|
void Session::reannounceTorrents(torrent_ids_t const& ids)
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2019-11-12 01:37:05 +00:00
|
|
|
if (!ids.empty())
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
tr_variant args;
|
|
|
|
tr_variantInitDict(&args, 1);
|
|
|
|
addOptionalIds(&args, ids);
|
2014-12-27 20:03:10 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
exec("torrent-reannounce", &args);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/***
|
|
|
|
****
|
|
|
|
***/
|
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
void Session::launchWebInterface()
|
2009-04-09 18:55:47 +00:00
|
|
|
{
|
2017-04-19 12:04:45 +00:00
|
|
|
QUrl url;
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2020-05-27 21:53:12 +00:00
|
|
|
if (session_ == nullptr) // remote session
|
2012-07-22 15:18:52 +00:00
|
|
|
{
|
2020-05-27 21:53:12 +00:00
|
|
|
url = rpc_.url();
|
2020-05-29 17:40:07 +00:00
|
|
|
url.setPath(QStringLiteral("/transmission/web/"));
|
2012-07-22 15:18:52 +00:00
|
|
|
}
|
2017-04-19 12:04:45 +00:00
|
|
|
else // local session
|
2012-07-22 15:18:52 +00:00
|
|
|
{
|
2020-05-29 17:40:07 +00:00
|
|
|
url.setScheme(QStringLiteral("http"));
|
|
|
|
url.setHost(QStringLiteral("localhost"));
|
2020-05-27 21:53:12 +00:00
|
|
|
url.setPort(prefs_.getInt(Prefs::RPC_PORT));
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|
2013-02-03 19:40:20 +00:00
|
|
|
|
2017-04-19 12:04:45 +00:00
|
|
|
QDesktopServices::openUrl(url);
|
2009-04-09 18:55:47 +00:00
|
|
|
}
|