refactor: Values pt. 6 - remove deprecated API (#6250)
This commit is contained in:
parent
b26d9a58a6
commit
07d96036d9
|
@ -19,12 +19,14 @@
|
||||||
#include <libtransmission/file.h>
|
#include <libtransmission/file.h>
|
||||||
#include <libtransmission/tr-getopt.h>
|
#include <libtransmission/tr-getopt.h>
|
||||||
#include <libtransmission/utils.h> // _()
|
#include <libtransmission/utils.h> // _()
|
||||||
|
#include <libtransmission/values.h>
|
||||||
#include <libtransmission/variant.h>
|
#include <libtransmission/variant.h>
|
||||||
#include <libtransmission/version.h>
|
#include <libtransmission/version.h>
|
||||||
#include <libtransmission/web-utils.h>
|
#include <libtransmission/web-utils.h>
|
||||||
#include <libtransmission/web.h> // tr_sessionFetch()
|
#include <libtransmission/web.h> // tr_sessionFetch()
|
||||||
|
|
||||||
using namespace std::chrono_literals;
|
using namespace std::chrono_literals;
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
#define SPEED_K_STR "kB/s"
|
#define SPEED_K_STR "kB/s"
|
||||||
|
|
||||||
|
@ -134,9 +136,9 @@ static std::string getStatusStr(tr_stat const* st)
|
||||||
tr_truncd(100 * st->percentDone, 1),
|
tr_truncd(100 * st->percentDone, 1),
|
||||||
st->peersSendingToUs,
|
st->peersSendingToUs,
|
||||||
st->peersConnected,
|
st->peersConnected,
|
||||||
tr_formatter_speed_KBps(st->pieceDownloadSpeed_KBps),
|
Speed{ st->pieceDownloadSpeed_KBps, Speed::Units::KByps }.to_string(),
|
||||||
st->peersGettingFromUs,
|
st->peersGettingFromUs,
|
||||||
tr_formatter_speed_KBps(st->pieceUploadSpeed_KBps),
|
Speed{ st->pieceUploadSpeed_KBps, Speed::Units::KByps }.to_string(),
|
||||||
tr_strlratio(st->ratio));
|
tr_strlratio(st->ratio));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,7 +148,7 @@ static std::string getStatusStr(tr_stat const* st)
|
||||||
FMT_STRING("Seeding, uploading to {:d} of {:d} peer(s), {:s} [{:s}]"),
|
FMT_STRING("Seeding, uploading to {:d} of {:d} peer(s), {:s} [{:s}]"),
|
||||||
st->peersGettingFromUs,
|
st->peersGettingFromUs,
|
||||||
st->peersConnected,
|
st->peersConnected,
|
||||||
tr_formatter_speed_KBps(st->pieceUploadSpeed_KBps),
|
Speed{ st->pieceUploadSpeed_KBps, Speed::Units::KByps }.to_string(),
|
||||||
tr_strlratio(st->ratio));
|
tr_strlratio(st->ratio));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <libtransmission/utils.h>
|
#include <libtransmission/values.h>
|
||||||
#include <libtransmission/web-utils.h>
|
#include <libtransmission/web-utils.h>
|
||||||
|
|
||||||
#include <gdkmm/pixbuf.h>
|
#include <gdkmm/pixbuf.h>
|
||||||
|
@ -71,6 +71,8 @@
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
class DetailsDialog::Impl
|
class DetailsDialog::Impl
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -886,7 +888,7 @@ void DetailsDialog::Impl::refreshInfo(std::vector<tr_torrent*> const& torrents)
|
||||||
"({piece_count} BitTorrent pieces @ {piece_size})",
|
"({piece_count} BitTorrent pieces @ {piece_size})",
|
||||||
piece_count),
|
piece_count),
|
||||||
fmt::arg("piece_count", piece_count),
|
fmt::arg("piece_count", piece_count),
|
||||||
fmt::arg("piece_size", tr_formatter_mem_B(piece_size)));
|
fmt::arg("piece_size", Memory{ piece_size, Memory::Units::Bytes }.to_string()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1230,12 +1232,12 @@ void refreshPeerRow(Gtk::TreeModel::iterator const& iter, tr_peer_stat const* pe
|
||||||
|
|
||||||
if (peer->rateToPeer_KBps > 0.01)
|
if (peer->rateToPeer_KBps > 0.01)
|
||||||
{
|
{
|
||||||
up_speed = tr_formatter_speed_KBps(peer->rateToPeer_KBps);
|
up_speed = Speed{ peer->rateToPeer_KBps, Speed::Units::KByps }.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer->rateToClient_KBps > 0)
|
if (peer->rateToClient_KBps > 0)
|
||||||
{
|
{
|
||||||
down_speed = tr_formatter_speed_KBps(peer->rateToClient_KBps);
|
down_speed = Speed{ peer->rateToClient_KBps, Speed::Units::KByps }.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer->activeReqsToPeer > 0)
|
if (peer->activeReqsToPeer > 0)
|
||||||
|
@ -1424,7 +1426,7 @@ void DetailsDialog::Impl::refreshWebseedList(std::vector<tr_torrent*> const& tor
|
||||||
auto const iter = store->get_iter(hash.at(key).get_path());
|
auto const iter = store->get_iter(hash.at(key).get_path());
|
||||||
|
|
||||||
auto const KBps = double(webseed.download_bytes_per_second) / speed_K;
|
auto const KBps = double(webseed.download_bytes_per_second) / speed_K;
|
||||||
auto const buf = webseed.is_downloading ? tr_formatter_speed_KBps(KBps) : std::string();
|
auto const buf = webseed.is_downloading ? Speed{ KBps, Speed::Units::KByps }.to_string() : std::string{};
|
||||||
|
|
||||||
(*iter)[webseed_cols.download_rate_double] = KBps;
|
(*iter)[webseed_cols.download_rate_double] = KBps;
|
||||||
(*iter)[webseed_cols.download_rate_string] = buf;
|
(*iter)[webseed_cols.download_rate_string] = buf;
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
#include <libtransmission/utils.h> // tr_formatter_speed_KBps()
|
#include <libtransmission/values.h>
|
||||||
|
|
||||||
#include <gdkmm/cursor.h>
|
#include <gdkmm/cursor.h>
|
||||||
#include <gdkmm/rectangle.h>
|
#include <gdkmm/rectangle.h>
|
||||||
|
@ -61,6 +61,7 @@
|
||||||
|
|
||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
using namespace std::string_view_literals;
|
using namespace std::string_view_literals;
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
using VariantInt = Glib::Variant<int>;
|
using VariantInt = Glib::Variant<int>;
|
||||||
using VariantDouble = Glib::Variant<double>;
|
using VariantDouble = Glib::Variant<double>;
|
||||||
|
@ -379,8 +380,8 @@ void MainWindow::Impl::syncAltSpeedButton()
|
||||||
alt_speed_button_->set_tooltip_text(fmt::format(
|
alt_speed_button_->set_tooltip_text(fmt::format(
|
||||||
b ? _("Click to disable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)") :
|
b ? _("Click to disable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)") :
|
||||||
_("Click to enable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)"),
|
_("Click to enable Alternative Speed Limits\n ({download_speed} down, {upload_speed} up)"),
|
||||||
fmt::arg("download_speed", tr_formatter_speed_KBps(gtr_pref_int_get(TR_KEY_alt_speed_down))),
|
fmt::arg("download_speed", Speed{ gtr_pref_int_get(TR_KEY_alt_speed_down), Speed::Units::KByps }.to_string()),
|
||||||
fmt::arg("upload_speed", tr_formatter_speed_KBps(gtr_pref_int_get(TR_KEY_alt_speed_up)))));
|
fmt::arg("upload_speed", Speed{ gtr_pref_int_get(TR_KEY_alt_speed_up), Speed::Units::KByps }.to_string())));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::Impl::alt_speed_toggled_cb()
|
void MainWindow::Impl::alt_speed_toggled_cb()
|
||||||
|
@ -451,7 +452,7 @@ Glib::RefPtr<Gio::MenuModel> MainWindow::Impl::createSpeedMenu(
|
||||||
|
|
||||||
for (auto const KBps : { 50, 100, 250, 500, 1000, 2500, 5000, 10000 })
|
for (auto const KBps : { 50, 100, 250, 500, 1000, 2500, 5000, 10000 })
|
||||||
{
|
{
|
||||||
auto item = Gio::MenuItem::create(tr_formatter_speed_KBps(KBps), full_stock_action_name);
|
auto item = Gio::MenuItem::create(Speed{ KBps, Speed::Units::KByps }.to_string(), full_stock_action_name);
|
||||||
item->set_action_and_target(full_stock_action_name, VariantInt::create(KBps));
|
item->set_action_and_target(full_stock_action_name, VariantInt::create(KBps));
|
||||||
section->append_item(item);
|
section->append_item(item);
|
||||||
}
|
}
|
||||||
|
@ -566,12 +567,12 @@ void MainWindow::Impl::onOptionsClicked()
|
||||||
|
|
||||||
update_menu(
|
update_menu(
|
||||||
speed_menu_info_[TR_DOWN],
|
speed_menu_info_[TR_DOWN],
|
||||||
tr_formatter_speed_KBps(gtr_pref_int_get(TR_KEY_speed_limit_down)),
|
Speed{ gtr_pref_int_get(TR_KEY_speed_limit_down), Speed::Units::KByps }.to_string(),
|
||||||
TR_KEY_speed_limit_down_enabled);
|
TR_KEY_speed_limit_down_enabled);
|
||||||
|
|
||||||
update_menu(
|
update_menu(
|
||||||
speed_menu_info_[TR_UP],
|
speed_menu_info_[TR_UP],
|
||||||
tr_formatter_speed_KBps(gtr_pref_int_get(TR_KEY_speed_limit_up)),
|
Speed{ gtr_pref_int_get(TR_KEY_speed_limit_up), Speed::Units::KByps }.to_string(),
|
||||||
TR_KEY_speed_limit_up_enabled);
|
TR_KEY_speed_limit_up_enabled);
|
||||||
|
|
||||||
update_menu(
|
update_menu(
|
||||||
|
@ -805,10 +806,13 @@ void MainWindow::Impl::updateSpeeds()
|
||||||
up_speed += torrent->get_speed_up();
|
up_speed += torrent->get_speed_up();
|
||||||
}
|
}
|
||||||
|
|
||||||
dl_lb_->set_text(fmt::format(_("{download_speed} ▼"), fmt::arg("download_speed", tr_formatter_speed_KBps(dn_speed))));
|
dl_lb_->set_text(fmt::format(
|
||||||
|
_("{download_speed} ▼"),
|
||||||
|
fmt::arg("download_speed", Speed{ dn_speed, Speed::Units::KByps }.to_string())));
|
||||||
dl_lb_->set_visible(dn_count > 0);
|
dl_lb_->set_visible(dn_count > 0);
|
||||||
|
|
||||||
ul_lb_->set_text(fmt::format(_("{upload_speed} ▲"), fmt::arg("upload_speed", tr_formatter_speed_KBps(up_speed))));
|
ul_lb_->set_text(
|
||||||
|
fmt::format(_("{upload_speed} ▲"), fmt::arg("upload_speed", Speed{ up_speed, Speed::Units::KByps }.to_string())));
|
||||||
ul_lb_->set_visible(dn_count > 0 || up_count > 0);
|
ul_lb_->set_visible(dn_count > 0 || up_count > 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
#include <libtransmission/error.h>
|
#include <libtransmission/error.h>
|
||||||
#include <libtransmission/makemeta.h>
|
#include <libtransmission/makemeta.h>
|
||||||
#include <libtransmission/utils.h> /* tr_formatter_mem_B() */
|
#include <libtransmission/values.h>
|
||||||
|
|
||||||
#include <giomm/file.h>
|
#include <giomm/file.h>
|
||||||
#include <glibmm/convert.h>
|
#include <glibmm/convert.h>
|
||||||
|
@ -51,6 +51,7 @@
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
||||||
using FileListValue = Glib::Value<GSList*>;
|
using FileListValue = Glib::Value<GSList*>;
|
||||||
|
@ -394,7 +395,7 @@ void MakeDialog::Impl::updatePiecesLabel()
|
||||||
"({piece_count} BitTorrent pieces @ {piece_size})",
|
"({piece_count} BitTorrent pieces @ {piece_size})",
|
||||||
builder_->piece_count()),
|
builder_->piece_count()),
|
||||||
fmt::arg("piece_count", builder_->piece_count()),
|
fmt::arg("piece_count", builder_->piece_count()),
|
||||||
fmt::arg("piece_size", tr_formatter_mem_B(builder_->piece_size())));
|
fmt::arg("piece_size", Memory{ builder_->piece_size(), Memory::Units::Bytes }.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pieces_lb_->set_text(gstr);
|
pieces_lb_->set_text(gstr);
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -214,6 +215,6 @@ std::string SystemTrayIcon::Impl::make_tooltip_text() const
|
||||||
auto const* const session = core_->get_session();
|
auto const* const session = core_->get_session();
|
||||||
return fmt::format(
|
return fmt::format(
|
||||||
_("{upload_speed} ▲ {download_speed} ▼"),
|
_("{upload_speed} ▲ {download_speed} ▼"),
|
||||||
fmt::arg("upload_speed", tr_formatter_speed_KBps(tr_sessionGetRawSpeed_KBps(session, TR_UP))),
|
fmt::arg("upload_speed", Speed{ tr_sessionGetRawSpeed_KBps(session, TR_UP), Speed::Units::KByps }.to_string()),
|
||||||
fmt::arg("download_speed", tr_formatter_speed_KBps(tr_sessionGetRawSpeed_KBps(session, TR_DOWN))));
|
fmt::arg("download_speed", Speed{ tr_sessionGetRawSpeed_KBps(session, TR_DOWN), Speed::Units::KByps }.to_string()));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
#include <libtransmission/utils.h>
|
#include <libtransmission/utils.h>
|
||||||
|
#include <libtransmission/values.h>
|
||||||
|
|
||||||
#include <glibmm/i18n.h>
|
#include <glibmm/i18n.h>
|
||||||
#include <glibmm/value.h>
|
#include <glibmm/value.h>
|
||||||
|
@ -24,6 +25,8 @@
|
||||||
|
|
||||||
using namespace std::string_view_literals;
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -583,13 +586,15 @@ Glib::ustring Torrent::Impl::get_short_transfer_text() const
|
||||||
{
|
{
|
||||||
return fmt::format(
|
return fmt::format(
|
||||||
_("{download_speed} ▼ {upload_speed} ▲"),
|
_("{download_speed} ▼ {upload_speed} ▲"),
|
||||||
fmt::arg("upload_speed", tr_formatter_speed_KBps(cache_.speed_up)),
|
fmt::arg("upload_speed", Speed{ cache_.speed_up, Speed::Units::KByps }.to_string()),
|
||||||
fmt::arg("download_speed", tr_formatter_speed_KBps(cache_.speed_down)));
|
fmt::arg("download_speed", Speed{ cache_.speed_down, Speed::Units::KByps }.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache_.has_metadata && cache_.active_peers_up > 0)
|
if (cache_.has_metadata && cache_.active_peers_up > 0)
|
||||||
{
|
{
|
||||||
return fmt::format(_("{upload_speed} ▲"), fmt::arg("upload_speed", tr_formatter_speed_KBps(cache_.speed_up)));
|
return fmt::format(
|
||||||
|
_("{upload_speed} ▲"),
|
||||||
|
fmt::arg("upload_speed", Speed{ cache_.speed_up, Speed::Units::KByps }.to_string()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cache_.stalled)
|
if (cache_.stalled)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <libtransmission/error.h>
|
#include <libtransmission/error.h>
|
||||||
#include <libtransmission/torrent-metainfo.h>
|
#include <libtransmission/torrent-metainfo.h>
|
||||||
#include <libtransmission/utils.h> /* tr_strratio() */
|
#include <libtransmission/utils.h> /* tr_strratio() */
|
||||||
|
#include <libtransmission/values.h>
|
||||||
#include <libtransmission/version.h> /* SHORT_VERSION_STRING */
|
#include <libtransmission/version.h> /* SHORT_VERSION_STRING */
|
||||||
#include <libtransmission/web-utils.h>
|
#include <libtransmission/web-utils.h>
|
||||||
|
|
||||||
|
@ -58,6 +59,8 @@
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
**** UNITS
|
**** UNITS
|
||||||
***/
|
***/
|
||||||
|
@ -132,9 +135,9 @@ Glib::ustring tr_strlratio(double ratio)
|
||||||
return tr_strratio(ratio, gtr_get_unicode_string(GtrUnicode::Inf).c_str());
|
return tr_strratio(ratio, gtr_get_unicode_string(GtrUnicode::Inf).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
Glib::ustring tr_strlsize(guint64 size_in_bytes)
|
Glib::ustring tr_strlsize(guint64 n_bytes)
|
||||||
{
|
{
|
||||||
return size_in_bytes == 0 ? Q_("None") : tr_formatter_size_B(size_in_bytes);
|
return n_bytes == 0 ? Q_("None") : Storage{ n_bytes, Storage::Units::Bytes }.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
|
|
@ -115,24 +115,19 @@ int Cache::write_contiguous(CIter const begin, CIter const end) const
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Cache::get_max_blocks(size_t max_bytes) noexcept
|
int Cache::set_limit(Memory const max_size)
|
||||||
{
|
|
||||||
return max_bytes / tr_block_info::BlockSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Cache::set_limit(size_t new_limit)
|
|
||||||
{
|
{
|
||||||
auto const lock = std::lock_guard{ mutex_ };
|
auto const lock = std::lock_guard{ mutex_ };
|
||||||
|
|
||||||
max_blocks_ = get_max_blocks(new_limit);
|
max_blocks_ = get_max_blocks(max_size);
|
||||||
tr_logAddDebug(fmt::format("Maximum cache size set to {} ({} blocks)", tr_formatter_mem_B(new_limit), max_blocks_));
|
tr_logAddDebug(fmt::format("Maximum cache size set to {} ({} blocks)", max_size.to_string(), max_blocks_));
|
||||||
|
|
||||||
return cache_trim();
|
return cache_trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
Cache::Cache(tr_torrents const& torrents, size_t max_bytes)
|
Cache::Cache(tr_torrents const& torrents, Memory const max_size)
|
||||||
: torrents_{ torrents }
|
: torrents_{ torrents }
|
||||||
, max_blocks_(get_max_blocks(max_bytes))
|
, max_blocks_{ get_max_blocks(max_size) }
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "libtransmission/transmission.h"
|
#include "libtransmission/transmission.h"
|
||||||
|
|
||||||
#include "libtransmission/block-info.h"
|
#include "libtransmission/block-info.h"
|
||||||
|
#include "libtransmission/values.h"
|
||||||
|
|
||||||
class tr_torrents;
|
class tr_torrents;
|
||||||
struct tr_torrent;
|
struct tr_torrent;
|
||||||
|
@ -29,10 +30,11 @@ class Cache
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
using BlockData = small::max_size_vector<uint8_t, tr_block_info::BlockSize>;
|
using BlockData = small::max_size_vector<uint8_t, tr_block_info::BlockSize>;
|
||||||
|
using Memory = libtransmission::Values::Memory;
|
||||||
|
|
||||||
Cache(tr_torrents const& torrents, size_t max_bytes);
|
Cache(tr_torrents const& torrents, Memory max_size);
|
||||||
|
|
||||||
int set_limit(size_t new_limit);
|
int set_limit(Memory max_size);
|
||||||
|
|
||||||
// @return any error code from cacheTrim()
|
// @return any error code from cacheTrim()
|
||||||
int write_block(tr_torrent_id_t tor, tr_block_index_t block, std::unique_ptr<BlockData> writeme);
|
int write_block(tr_torrent_id_t tor, tr_block_index_t block, std::unique_ptr<BlockData> writeme);
|
||||||
|
@ -72,7 +74,10 @@ private:
|
||||||
// @return any error code from writeContiguous()
|
// @return any error code from writeContiguous()
|
||||||
[[nodiscard]] int cache_trim();
|
[[nodiscard]] int cache_trim();
|
||||||
|
|
||||||
[[nodiscard]] static size_t get_max_blocks(size_t max_bytes) noexcept;
|
[[nodiscard]] static constexpr size_t get_max_blocks(Memory const max_size) noexcept
|
||||||
|
{
|
||||||
|
return max_size.base_quantity() / tr_block_info::BlockSize;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] CIter get_block(tr_torrent const* torrent, tr_block_info::Location const& loc) noexcept;
|
[[nodiscard]] CIter get_block(tr_torrent const* torrent, tr_block_info::Location const& loc) noexcept;
|
||||||
|
|
||||||
|
|
|
@ -1966,6 +1966,35 @@ constexpr std::string_view getEncryptionModeString(tr_encryption_mode mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] auto values_get_units()
|
||||||
|
{
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
|
auto const make_units_vec = [](auto const& units)
|
||||||
|
{
|
||||||
|
auto units_vec = tr_variant::Vector{};
|
||||||
|
for (size_t i = 0;; ++i)
|
||||||
|
{
|
||||||
|
auto const display_name = units.display_name(i);
|
||||||
|
if (std::empty(display_name))
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
units_vec.emplace_back(display_name);
|
||||||
|
}
|
||||||
|
return units_vec;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto units_map = tr_variant::Map{ 6U };
|
||||||
|
units_map.try_emplace(TR_KEY_memory_bytes, Memory::units().base());
|
||||||
|
units_map.try_emplace(TR_KEY_memory_units, make_units_vec(Memory::units()));
|
||||||
|
units_map.try_emplace(TR_KEY_size_bytes, Storage::units().base());
|
||||||
|
units_map.try_emplace(TR_KEY_size_units, make_units_vec(Storage::units()));
|
||||||
|
units_map.try_emplace(TR_KEY_speed_bytes, Speed::units().base());
|
||||||
|
units_map.try_emplace(TR_KEY_speed_units, make_units_vec(Speed::units()));
|
||||||
|
return tr_variant{ std::move(units_map) };
|
||||||
|
}
|
||||||
|
|
||||||
void addSessionField(tr_session const* s, tr_variant* d, tr_quark key)
|
void addSessionField(tr_session const* s, tr_variant* d, tr_quark key)
|
||||||
{
|
{
|
||||||
switch (key)
|
switch (key)
|
||||||
|
@ -2198,7 +2227,7 @@ void addSessionField(tr_session const* s, tr_variant* d, tr_quark key)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TR_KEY_units:
|
case TR_KEY_units:
|
||||||
*tr_variantDictAdd(d, key) = tr_formatter_get_units();
|
*tr_variantDictAdd(d, key) = values_get_units();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TR_KEY_version:
|
case TR_KEY_version:
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct tr_variant;
|
||||||
V(TR_KEY_bind_address_ipv6, bind_address_ipv6, std::string, "::", "") \
|
V(TR_KEY_bind_address_ipv6, bind_address_ipv6, std::string, "::", "") \
|
||||||
V(TR_KEY_blocklist_enabled, blocklist_enabled, bool, false, "") \
|
V(TR_KEY_blocklist_enabled, blocklist_enabled, bool, false, "") \
|
||||||
V(TR_KEY_blocklist_url, blocklist_url, std::string, "http://www.example.com/blocklist", "") \
|
V(TR_KEY_blocklist_url, blocklist_url, std::string, "http://www.example.com/blocklist", "") \
|
||||||
V(TR_KEY_cache_size_mb, cache_size_mb, size_t, 4U, "") \
|
V(TR_KEY_cache_size_mb, cache_size_mbytes, size_t, 4U, "") \
|
||||||
V(TR_KEY_default_trackers, default_trackers_str, std::string, "", "") \
|
V(TR_KEY_default_trackers, default_trackers_str, std::string, "", "") \
|
||||||
V(TR_KEY_dht_enabled, dht_enabled, bool, true, "") \
|
V(TR_KEY_dht_enabled, dht_enabled, bool, true, "") \
|
||||||
V(TR_KEY_download_dir, download_dir, std::string, tr_getDefaultDownloadDir(), "") \
|
V(TR_KEY_download_dir, download_dir, std::string, tr_getDefaultDownloadDir(), "") \
|
||||||
|
|
|
@ -773,7 +773,7 @@ void tr_session::setSettings(tr_session_settings&& settings_in, bool force)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (auto const& val = new_settings.cache_size_mb; force || val != old_settings.cache_size_mb)
|
if (auto const& val = new_settings.cache_size_mbytes; force || val != old_settings.cache_size_mbytes)
|
||||||
{
|
{
|
||||||
tr_sessionSetCacheLimit_MB(this, val);
|
tr_sessionSetCacheLimit_MB(this, val);
|
||||||
}
|
}
|
||||||
|
@ -1162,7 +1162,7 @@ bool tr_sessionIsSpeedLimited(tr_session const* session, tr_direction const dir)
|
||||||
|
|
||||||
// --- Session alt speed limits
|
// --- Session alt speed limits
|
||||||
|
|
||||||
void tr_sessionSetAltSpeed_KBps(tr_session* session, tr_direction const dir, size_t limit_kbyps)
|
void tr_sessionSetAltSpeed_KBps(tr_session* const session, tr_direction const dir, size_t const limit_kbyps)
|
||||||
{
|
{
|
||||||
TR_ASSERT(session != nullptr);
|
TR_ASSERT(session != nullptr);
|
||||||
TR_ASSERT(tr_isDirection(dir));
|
TR_ASSERT(tr_isDirection(dir));
|
||||||
|
@ -1591,19 +1591,19 @@ bool tr_sessionIsLPDEnabled(tr_session const* session)
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
void tr_sessionSetCacheLimit_MB(tr_session* session, size_t mb)
|
void tr_sessionSetCacheLimit_MB(tr_session* session, size_t mbytes)
|
||||||
{
|
{
|
||||||
TR_ASSERT(session != nullptr);
|
TR_ASSERT(session != nullptr);
|
||||||
|
|
||||||
session->settings_.cache_size_mb = mb;
|
session->settings_.cache_size_mbytes = mbytes;
|
||||||
session->cache->set_limit(tr_toMemBytes(mb));
|
session->cache->set_limit(Memory{ mbytes, Memory::Units::MBytes });
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t tr_sessionGetCacheLimit_MB(tr_session const* session)
|
size_t tr_sessionGetCacheLimit_MB(tr_session const* session)
|
||||||
{
|
{
|
||||||
TR_ASSERT(session != nullptr);
|
TR_ASSERT(session != nullptr);
|
||||||
|
|
||||||
return session->settings_.cache_size_mb;
|
return session->settings_.cache_size_mbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
|
@ -83,6 +83,7 @@ class SessionTest;
|
||||||
/** @brief handle to an active libtransmission session */
|
/** @brief handle to an active libtransmission session */
|
||||||
struct tr_session
|
struct tr_session
|
||||||
{
|
{
|
||||||
|
using Memory = libtransmission::Values::Memory;
|
||||||
using Speed = libtransmission::Values::Speed;
|
using Speed = libtransmission::Values::Speed;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -1000,7 +1001,7 @@ private:
|
||||||
friend void tr_sessionSetAltSpeed_KBps(tr_session* session, tr_direction dir, size_t limit_kbyps);
|
friend void tr_sessionSetAltSpeed_KBps(tr_session* session, tr_direction dir, size_t limit_kbyps);
|
||||||
friend void tr_sessionSetAntiBruteForceEnabled(tr_session* session, bool is_enabled);
|
friend void tr_sessionSetAntiBruteForceEnabled(tr_session* session, bool is_enabled);
|
||||||
friend void tr_sessionSetAntiBruteForceThreshold(tr_session* session, int max_bad_requests);
|
friend void tr_sessionSetAntiBruteForceThreshold(tr_session* session, int max_bad_requests);
|
||||||
friend void tr_sessionSetCacheLimit_MB(tr_session* session, size_t mb);
|
friend void tr_sessionSetCacheLimit_MB(tr_session* session, size_t mbytes);
|
||||||
friend void tr_sessionSetDHTEnabled(tr_session* session, bool enabled);
|
friend void tr_sessionSetDHTEnabled(tr_session* session, bool enabled);
|
||||||
friend void tr_sessionSetDeleteSource(tr_session* session, bool delete_source);
|
friend void tr_sessionSetDeleteSource(tr_session* session, bool delete_source);
|
||||||
friend void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode);
|
friend void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode);
|
||||||
|
@ -1156,7 +1157,7 @@ private:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// depends-on: settings_, open_files_, torrents_
|
// depends-on: settings_, open_files_, torrents_
|
||||||
std::unique_ptr<Cache> cache = std::make_unique<Cache>(torrents_, 1024 * 1024 * 2);
|
std::unique_ptr<Cache> cache = std::make_unique<Cache>(torrents_, Memory{ 2U, Memory::Units::MBytes });
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// depends-on: timer_maker_, blocklists_, top_bandwidth_, utp_context, torrents_, web_
|
// depends-on: timer_maker_, blocklists_, top_bandwidth_, utp_context, torrents_, web_
|
||||||
|
|
|
@ -448,7 +448,7 @@ bool tr_sessionIsLPDEnabled(tr_session const* session);
|
||||||
void tr_sessionSetLPDEnabled(tr_session* session, bool is_enabled);
|
void tr_sessionSetLPDEnabled(tr_session* session, bool is_enabled);
|
||||||
|
|
||||||
size_t tr_sessionGetCacheLimit_MB(tr_session const* session);
|
size_t tr_sessionGetCacheLimit_MB(tr_session const* session);
|
||||||
void tr_sessionSetCacheLimit_MB(tr_session* session, size_t mb);
|
void tr_sessionSetCacheLimit_MB(tr_session* session, size_t mbytes);
|
||||||
|
|
||||||
tr_encryption_mode tr_sessionGetEncryption(tr_session const* session);
|
tr_encryption_mode tr_sessionGetEncryption(tr_session const* session);
|
||||||
void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode);
|
void tr_sessionSetEncryption(tr_session* session, tr_encryption_mode mode);
|
||||||
|
|
|
@ -678,35 +678,6 @@ Config::Units<StorageUnits> Config::Storage{ Config::Base::Kilo, "B"sv, "kB"sv,
|
||||||
|
|
||||||
} // namespace libtransmission::Values
|
} // namespace libtransmission::Values
|
||||||
|
|
||||||
tr_variant tr_formatter_get_units()
|
|
||||||
{
|
|
||||||
auto const make_units_vec = [](auto const& units)
|
|
||||||
{
|
|
||||||
auto units_vec = tr_variant::Vector{};
|
|
||||||
for (size_t i = 0;; ++i)
|
|
||||||
{
|
|
||||||
auto const display_name = units.display_name(i);
|
|
||||||
if (std::empty(display_name))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
units_vec.emplace_back(display_name);
|
|
||||||
}
|
|
||||||
return units_vec;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto units_map = tr_variant::Map{ 6U };
|
|
||||||
units_map.try_emplace(TR_KEY_memory_bytes, Memory::units().base());
|
|
||||||
units_map.try_emplace(TR_KEY_memory_units, make_units_vec(Memory::units()));
|
|
||||||
units_map.try_emplace(TR_KEY_size_bytes, Storage::units().base());
|
|
||||||
units_map.try_emplace(TR_KEY_size_units, make_units_vec(Storage::units()));
|
|
||||||
units_map.try_emplace(TR_KEY_speed_bytes, Speed::units().base());
|
|
||||||
units_map.try_emplace(TR_KEY_speed_units, make_units_vec(Speed::units()));
|
|
||||||
return tr_variant{ std::move(units_map) };
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- formatters: storage
|
|
||||||
|
|
||||||
void tr_formatter_size_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb)
|
void tr_formatter_size_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb)
|
||||||
{
|
{
|
||||||
namespace Values = libtransmission::Values;
|
namespace Values = libtransmission::Values;
|
||||||
|
@ -715,55 +686,20 @@ void tr_formatter_size_init(size_t base, char const* kb, char const* mb, char co
|
||||||
Values::Config::Storage = { kval, "B", kb, mb, gb, tb };
|
Values::Config::Storage = { kval, "B", kb, mb, gb, tb };
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tr_formatter_size_B(uint64_t bytes)
|
|
||||||
{
|
|
||||||
return Storage{ bytes, Storage::Units::Bytes }.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- formatters: speed
|
|
||||||
|
|
||||||
size_t tr_speed_K = 0;
|
|
||||||
|
|
||||||
void tr_formatter_speed_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb)
|
void tr_formatter_speed_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb)
|
||||||
{
|
{
|
||||||
namespace Values = libtransmission::Values;
|
namespace Values = libtransmission::Values;
|
||||||
|
|
||||||
auto const kval = base == 1000U ? Values::Config::Base::Kilo : Values::Config::Base::Kibi;
|
auto const kval = base == 1000U ? Values::Config::Base::Kilo : Values::Config::Base::Kibi;
|
||||||
Values::Config::Speed = { kval, "B/s", kb, mb, gb, tb };
|
Values::Config::Speed = { kval, "B/s", kb, mb, gb, tb };
|
||||||
tr_speed_K = base;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string tr_formatter_speed_KBps(double kbyps)
|
|
||||||
{
|
|
||||||
return Speed{ kbyps, Speed::Units::KByps }.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
// --- formatters: memory
|
|
||||||
|
|
||||||
size_t tr_mem_K = 0;
|
|
||||||
|
|
||||||
void tr_formatter_mem_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb)
|
void tr_formatter_mem_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb)
|
||||||
{
|
{
|
||||||
namespace Values = libtransmission::Values;
|
namespace Values = libtransmission::Values;
|
||||||
|
|
||||||
auto const kval = base == 1000U ? Values::Config::Base::Kilo : Values::Config::Base::Kibi;
|
auto const kval = base == 1000U ? Values::Config::Base::Kilo : Values::Config::Base::Kibi;
|
||||||
Values::Config::Memory = { kval, "B", kb, mb, gb, tb };
|
Values::Config::Memory = { kval, "B", kb, mb, gb, tb };
|
||||||
tr_mem_K = base;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string tr_formatter_mem_B(uint64_t bytes)
|
|
||||||
{
|
|
||||||
return Memory{ bytes, Memory::Units::Bytes }.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string tr_formatter_mem_MB(double mbytes)
|
|
||||||
{
|
|
||||||
return Memory{ mbytes, Memory::Units::MBytes }.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t tr_toMemBytes(size_t mbytes)
|
|
||||||
{
|
|
||||||
return Memory{ mbytes, Memory::Units::MBytes }.base_quantity();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --- ENVIRONMENT
|
// --- ENVIRONMENT
|
||||||
|
|
|
@ -305,18 +305,6 @@ void tr_formatter_size_init(size_t base, char const* kb, char const* mb, char co
|
||||||
void tr_formatter_speed_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb);
|
void tr_formatter_speed_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb);
|
||||||
void tr_formatter_mem_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb);
|
void tr_formatter_mem_init(size_t base, char const* kb, char const* mb, char const* gb, char const* tb);
|
||||||
|
|
||||||
extern size_t tr_speed_K;
|
|
||||||
extern size_t tr_mem_K;
|
|
||||||
|
|
||||||
[[nodiscard]] uint64_t tr_toMemBytes(size_t mbytes);
|
|
||||||
|
|
||||||
[[nodiscard]] std::string tr_formatter_mem_B(uint64_t bytes);
|
|
||||||
[[nodiscard]] std::string tr_formatter_mem_MB(double mbytes);
|
|
||||||
[[nodiscard]] std::string tr_formatter_size_B(uint64_t bytes);
|
|
||||||
[[nodiscard]] std::string tr_formatter_speed_KBps(double kbyps);
|
|
||||||
|
|
||||||
[[nodiscard]] struct tr_variant tr_formatter_get_units();
|
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
||||||
/** @brief Check if environment variable exists. */
|
/** @brief Check if environment variable exists. */
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
// License text can be found in the licenses/ folder.
|
// License text can be found in the licenses/ folder.
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
#include <libtransmission/utils.h> // tr_formatter
|
|
||||||
#include <libtransmission/values.h> // tr_formatter
|
#include <libtransmission/values.h>
|
||||||
|
|
||||||
#include "Formatter.h"
|
#include "Formatter.h"
|
||||||
#include "Speed.h"
|
#include "Speed.h"
|
||||||
|
@ -14,6 +14,8 @@
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
Formatter& Formatter::get()
|
Formatter& Formatter::get()
|
||||||
{
|
{
|
||||||
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables)
|
||||||
|
@ -69,7 +71,7 @@ QString Formatter::memToString(int64_t bytes) const
|
||||||
return tr("None");
|
return tr("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString::fromStdString(tr_formatter_mem_B(bytes));
|
return QString::fromStdString(Memory{ bytes, Memory::Units::Bytes }.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Formatter::sizeToString(uint64_t bytes) const
|
QString Formatter::sizeToString(uint64_t bytes) const
|
||||||
|
@ -79,7 +81,7 @@ QString Formatter::sizeToString(uint64_t bytes) const
|
||||||
return tr("None");
|
return tr("None");
|
||||||
}
|
}
|
||||||
|
|
||||||
return QString::fromStdString(tr_formatter_size_B(bytes));
|
return QString::fromStdString(Storage{ bytes, Storage::Units::Bytes }.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
QString Formatter::sizeToString(int64_t bytes) const
|
QString Formatter::sizeToString(int64_t bytes) const
|
||||||
|
|
|
@ -16,7 +16,7 @@ using ValuesTest = ::testing::Test;
|
||||||
|
|
||||||
TEST_F(ValuesTest, baseQuantity)
|
TEST_F(ValuesTest, baseQuantity)
|
||||||
{
|
{
|
||||||
auto val = Speed{ 1, Speed::Units::MByps };
|
auto const val = Speed{ 1, Speed::Units::MByps };
|
||||||
EXPECT_EQ(1000000UL, val.base_quantity());
|
EXPECT_EQ(1000000UL, val.base_quantity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit f5e54359df4c26b6230fc61d38aa294581393084
|
Subproject commit a0b8a92e3d1532361c2f7feb63babc5c18d00ef2
|
|
@ -27,10 +27,13 @@
|
||||||
#include <libtransmission/torrent-files.h>
|
#include <libtransmission/torrent-files.h>
|
||||||
#include <libtransmission/tr-getopt.h>
|
#include <libtransmission/tr-getopt.h>
|
||||||
#include <libtransmission/utils.h>
|
#include <libtransmission/utils.h>
|
||||||
|
#include <libtransmission/values.h>
|
||||||
#include <libtransmission/version.h>
|
#include <libtransmission/version.h>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -231,7 +234,7 @@ int tr_main(int argc, char* argv[])
|
||||||
fmt::print(
|
fmt::print(
|
||||||
tr_ngettext("{file_count:L} file, {total_size}\n", "{file_count:L} files, {total_size}\n", builder.file_count()),
|
tr_ngettext("{file_count:L} file, {total_size}\n", "{file_count:L} files, {total_size}\n", builder.file_count()),
|
||||||
fmt::arg("file_count", builder.file_count()),
|
fmt::arg("file_count", builder.file_count()),
|
||||||
fmt::arg("total_size", tr_formatter_size_B(builder.total_size())));
|
fmt::arg("total_size", Storage{ builder.total_size(), Storage::Units::Bytes }.to_string()));
|
||||||
|
|
||||||
fmt::print(
|
fmt::print(
|
||||||
tr_ngettext(
|
tr_ngettext(
|
||||||
|
@ -239,7 +242,7 @@ int tr_main(int argc, char* argv[])
|
||||||
"{piece_count:L} pieces, {piece_size} each\n",
|
"{piece_count:L} pieces, {piece_size} each\n",
|
||||||
builder.piece_count()),
|
builder.piece_count()),
|
||||||
fmt::arg("piece_count", builder.piece_count()),
|
fmt::arg("piece_count", builder.piece_count()),
|
||||||
fmt::arg("piece_size", tr_formatter_size_B(builder.piece_size())));
|
fmt::arg("piece_size", Memory{ builder.piece_size(), Memory::Units::Bytes }.to_string()));
|
||||||
|
|
||||||
if (!std::empty(options.comment))
|
if (!std::empty(options.comment))
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <fmt/core.h>
|
#include <fmt/core.h>
|
||||||
|
|
||||||
#include <libtransmission/transmission.h>
|
#include <libtransmission/transmission.h>
|
||||||
|
|
||||||
#include <libtransmission/crypto-utils.h>
|
#include <libtransmission/crypto-utils.h>
|
||||||
#include <libtransmission/file.h>
|
#include <libtransmission/file.h>
|
||||||
#include <libtransmission/log.h>
|
#include <libtransmission/log.h>
|
||||||
|
@ -34,11 +35,14 @@
|
||||||
#include <libtransmission/rpcimpl.h>
|
#include <libtransmission/rpcimpl.h>
|
||||||
#include <libtransmission/tr-getopt.h>
|
#include <libtransmission/tr-getopt.h>
|
||||||
#include <libtransmission/utils.h>
|
#include <libtransmission/utils.h>
|
||||||
|
#include <libtransmission/values.h>
|
||||||
#include <libtransmission/variant.h>
|
#include <libtransmission/variant.h>
|
||||||
#include <libtransmission/version.h>
|
#include <libtransmission/version.h>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
#define SPEED_K_STR "kB/s"
|
#define SPEED_K_STR "kB/s"
|
||||||
#define MEM_M_STR "MiB"
|
#define MEM_M_STR "MiB"
|
||||||
|
|
||||||
|
@ -61,7 +65,7 @@ static char constexpr Usage[] = "transmission-remote " LONG_VERSION_STRING
|
||||||
|
|
||||||
static auto constexpr Arguments = TR_KEY_arguments;
|
static auto constexpr Arguments = TR_KEY_arguments;
|
||||||
|
|
||||||
struct Config
|
struct RemoteConfig
|
||||||
{
|
{
|
||||||
std::string auth;
|
std::string auth;
|
||||||
std::string filter;
|
std::string filter;
|
||||||
|
@ -177,11 +181,6 @@ static std::string strlratio(int64_t numerator, int64_t denominator)
|
||||||
return strlratio2(tr_getRatio(numerator, denominator));
|
return strlratio2(tr_getRatio(numerator, denominator));
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string strlmem(int64_t bytes)
|
|
||||||
{
|
|
||||||
return bytes == 0 ? "None"s : tr_formatter_mem_B(bytes);
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string strlsize(int64_t bytes)
|
static std::string strlsize(int64_t bytes)
|
||||||
{
|
{
|
||||||
if (bytes < 0)
|
if (bytes < 0)
|
||||||
|
@ -194,7 +193,7 @@ static std::string strlsize(int64_t bytes)
|
||||||
return "None"s;
|
return "None"s;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tr_formatter_size_B(bytes);
|
return Storage{ bytes, Storage::Units::Bytes }.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
@ -594,7 +593,7 @@ static void addIdArg(tr_variant* args, std::string_view id_str, std::string_view
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void addIdArg(tr_variant* args, Config const& config, std::string_view fallback = "")
|
static void addIdArg(tr_variant* args, RemoteConfig const& config, std::string_view fallback = "")
|
||||||
{
|
{
|
||||||
return addIdArg(args, config.torrent_ids, fallback);
|
return addIdArg(args, config.torrent_ids, fallback);
|
||||||
}
|
}
|
||||||
|
@ -794,7 +793,7 @@ static size_t writeFunc(void* ptr, size_t size, size_t nmemb, void* vbuf)
|
||||||
/* look for a session id in the header in case the server gives back a 409 */
|
/* look for a session id in the header in case the server gives back a 409 */
|
||||||
static size_t parseResponseHeader(void* ptr, size_t size, size_t nmemb, void* vconfig)
|
static size_t parseResponseHeader(void* ptr, size_t size, size_t nmemb, void* vconfig)
|
||||||
{
|
{
|
||||||
auto& config = *static_cast<Config*>(vconfig);
|
auto& config = *static_cast<RemoteConfig*>(vconfig);
|
||||||
auto const* const line = static_cast<char const*>(ptr);
|
auto const* const line = static_cast<char const*>(ptr);
|
||||||
size_t const line_len = size * nmemb;
|
size_t const line_len = size * nmemb;
|
||||||
char const* key = TR_RPC_SESSION_ID_HEADER ": ";
|
char const* key = TR_RPC_SESSION_ID_HEADER ": ";
|
||||||
|
@ -993,12 +992,12 @@ static void printDetails(tr_variant* top)
|
||||||
|
|
||||||
if (tr_variantDictFindInt(t, TR_KEY_rateDownload, &i))
|
if (tr_variantDictFindInt(t, TR_KEY_rateDownload, &i))
|
||||||
{
|
{
|
||||||
fmt::print(" Download Speed: {:s}\n", tr_formatter_speed_KBps(i / (double)tr_speed_K));
|
fmt::print(" Download Speed: {:s}\n", Speed{ i, Speed::Units::KByps }.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tr_variantDictFindInt(t, TR_KEY_rateUpload, &i))
|
if (tr_variantDictFindInt(t, TR_KEY_rateUpload, &i))
|
||||||
{
|
{
|
||||||
fmt::print(" Upload Speed: {:s}\n", tr_formatter_speed_KBps(i / (double)tr_speed_K));
|
fmt::print(" Upload Speed: {:s}\n", Speed{ i, Speed::Units::KByps }.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tr_variantDictFindInt(t, TR_KEY_haveUnchecked, &i) && tr_variantDictFindInt(t, TR_KEY_haveValid, &j))
|
if (tr_variantDictFindInt(t, TR_KEY_haveUnchecked, &i) && tr_variantDictFindInt(t, TR_KEY_haveValid, &j))
|
||||||
|
@ -1156,7 +1155,7 @@ static void printDetails(tr_variant* top)
|
||||||
|
|
||||||
if (tr_variantDictFindInt(t, TR_KEY_pieceSize, &i))
|
if (tr_variantDictFindInt(t, TR_KEY_pieceSize, &i))
|
||||||
{
|
{
|
||||||
fmt::print(" Piece Size: {:s}\n", strlmem(i));
|
fmt::print(" Piece Size: {:s}\n", Memory{ i, Memory::Units::Bytes }.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::print("\n");
|
fmt::print("\n");
|
||||||
|
@ -1170,7 +1169,7 @@ static void printDetails(tr_variant* top)
|
||||||
|
|
||||||
if (boolVal)
|
if (boolVal)
|
||||||
{
|
{
|
||||||
fmt::print("{:s}\n", tr_formatter_speed_KBps(i));
|
fmt::print("{:s}\n", Speed{ i, Speed::Units::KByps }.to_string());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1184,7 +1183,7 @@ static void printDetails(tr_variant* top)
|
||||||
|
|
||||||
if (boolVal)
|
if (boolVal)
|
||||||
{
|
{
|
||||||
fmt::print("{:s}\n", tr_formatter_speed_KBps(i));
|
fmt::print("{:s}\n", Speed{ i, Speed::Units::KByps }.to_string());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1333,8 +1332,8 @@ static void printPeersImpl(tr_variant* peers)
|
||||||
address,
|
address,
|
||||||
flagstr,
|
flagstr,
|
||||||
progress * 100.0,
|
progress * 100.0,
|
||||||
rateToClient / static_cast<double>(tr_speed_K),
|
Speed{ rateToClient, Speed::Units::KByps }.count(Speed::Units::KByps),
|
||||||
rateToPeer / static_cast<double>(tr_speed_K),
|
Speed{ rateToPeer, Speed::Units::KByps }.count(Speed::Units::KByps),
|
||||||
client);
|
client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1513,8 +1512,8 @@ static void printTorrentList(tr_variant* top)
|
||||||
done_str,
|
done_str,
|
||||||
strlsize(sizeWhenDone - leftUntilDone),
|
strlsize(sizeWhenDone - leftUntilDone),
|
||||||
eta_str,
|
eta_str,
|
||||||
up / static_cast<double>(tr_speed_K),
|
Speed{ up, Speed::Units::Byps }.count(Speed::Units::KByps),
|
||||||
down / static_cast<double>(tr_speed_K),
|
Speed{ down, Speed::Units::Byps }.count(Speed::Units::KByps),
|
||||||
strlratio2(ratio),
|
strlratio2(ratio),
|
||||||
getStatusString(d),
|
getStatusString(d),
|
||||||
name);
|
name);
|
||||||
|
@ -1528,8 +1527,8 @@ static void printTorrentList(tr_variant* top)
|
||||||
fmt::print(
|
fmt::print(
|
||||||
FMT_STRING("Sum: {:>9s} {:6.1f} {:6.1f}\n"),
|
FMT_STRING("Sum: {:>9s} {:6.1f} {:6.1f}\n"),
|
||||||
strlsize(total_size).c_str(),
|
strlsize(total_size).c_str(),
|
||||||
total_up / static_cast<double>(tr_speed_K),
|
Speed{ total_up, Speed::Units::Byps }.count(Speed::Units::KByps),
|
||||||
total_down / static_cast<double>(tr_speed_K));
|
Speed{ total_down, Speed::Units::Byps }.count(Speed::Units::KByps));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1786,7 +1785,7 @@ static void printSession(tr_variant* top)
|
||||||
|
|
||||||
if (tr_variantDictFindInt(args, TR_KEY_cache_size_mb, &i))
|
if (tr_variantDictFindInt(args, TR_KEY_cache_size_mb, &i))
|
||||||
{
|
{
|
||||||
fmt::print(" Maximum memory cache size: {:s}\n", tr_formatter_mem_MB(i));
|
fmt::print(" Maximum memory cache size: {:s}\n", Memory{ i, Memory::Units::MBytes }.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::print("\n");
|
fmt::print("\n");
|
||||||
|
@ -1831,11 +1830,11 @@ static void printSession(tr_variant* top)
|
||||||
|
|
||||||
if (altEnabled)
|
if (altEnabled)
|
||||||
{
|
{
|
||||||
effective_up_limit = tr_formatter_speed_KBps(altUp);
|
effective_up_limit = Speed{ altUp, Speed::Units::KByps }.to_string();
|
||||||
}
|
}
|
||||||
else if (upEnabled)
|
else if (upEnabled)
|
||||||
{
|
{
|
||||||
effective_up_limit = tr_formatter_speed_KBps(upLimit);
|
effective_up_limit = Speed{ upLimit, Speed::Units::KByps }.to_string();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1846,19 +1845,19 @@ static void printSession(tr_variant* top)
|
||||||
FMT_STRING(" Upload speed limit: {:s} ({:s} limit: {:s}; {:s} turtle limit: {:s})\n"),
|
FMT_STRING(" Upload speed limit: {:s} ({:s} limit: {:s}; {:s} turtle limit: {:s})\n"),
|
||||||
effective_up_limit,
|
effective_up_limit,
|
||||||
upEnabled ? "Enabled" : "Disabled",
|
upEnabled ? "Enabled" : "Disabled",
|
||||||
tr_formatter_speed_KBps(upLimit),
|
Speed{ upLimit, Speed::Units::KByps }.to_string(),
|
||||||
altEnabled ? "Enabled" : "Disabled",
|
altEnabled ? "Enabled" : "Disabled",
|
||||||
tr_formatter_speed_KBps(altUp));
|
Speed{ altUp, Speed::Units::KByps }.to_string());
|
||||||
|
|
||||||
std::string effective_down_limit;
|
std::string effective_down_limit;
|
||||||
|
|
||||||
if (altEnabled)
|
if (altEnabled)
|
||||||
{
|
{
|
||||||
effective_down_limit = tr_formatter_speed_KBps(altDown);
|
effective_down_limit = Speed{ altDown, Speed::Units::KByps }.to_string();
|
||||||
}
|
}
|
||||||
else if (downEnabled)
|
else if (downEnabled)
|
||||||
{
|
{
|
||||||
effective_down_limit = tr_formatter_speed_KBps(downLimit);
|
effective_down_limit = Speed{ downLimit, Speed::Units::KByps }.to_string();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1869,9 +1868,9 @@ static void printSession(tr_variant* top)
|
||||||
FMT_STRING(" Download speed limit: {:s} ({:s} limit: {:s}; {:s} turtle limit: {:s})\n"),
|
FMT_STRING(" Download speed limit: {:s} ({:s} limit: {:s}; {:s} turtle limit: {:s})\n"),
|
||||||
effective_down_limit,
|
effective_down_limit,
|
||||||
downEnabled ? "Enabled" : "Disabled",
|
downEnabled ? "Enabled" : "Disabled",
|
||||||
tr_formatter_speed_KBps(downLimit),
|
Speed{ downLimit, Speed::Units::KByps }.to_string(),
|
||||||
altEnabled ? "Enabled" : "Disabled",
|
altEnabled ? "Enabled" : "Disabled",
|
||||||
tr_formatter_speed_KBps(altDown));
|
Speed{ altDown, Speed::Units::KByps }.to_string());
|
||||||
|
|
||||||
if (altTimeEnabled)
|
if (altTimeEnabled)
|
||||||
{
|
{
|
||||||
|
@ -2000,15 +1999,15 @@ static void printGroups(tr_variant* top)
|
||||||
fmt::print("{:s}: ", name);
|
fmt::print("{:s}: ", name);
|
||||||
fmt::print(
|
fmt::print(
|
||||||
FMT_STRING("Upload speed limit: {:s}, Download speed limit: {:s}, {:s} session bandwidth limits\n"),
|
FMT_STRING("Upload speed limit: {:s}, Download speed limit: {:s}, {:s} session bandwidth limits\n"),
|
||||||
upEnabled ? tr_formatter_speed_KBps(upLimit).c_str() : "unlimited",
|
upEnabled ? Speed{ upLimit, Speed::Units::KByps }.to_string() : "unlimited"s,
|
||||||
downEnabled ? tr_formatter_speed_KBps(downLimit).c_str() : "unlimited",
|
downEnabled ? Speed{ downLimit, Speed::Units::KByps }.to_string() : "unlimited"s,
|
||||||
honors ? "honors" : "does not honor");
|
honors ? "honors" : "does not honor");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void filterIds(tr_variant* top, Config& config)
|
static void filterIds(tr_variant* top, RemoteConfig& config)
|
||||||
{
|
{
|
||||||
tr_variant* args;
|
tr_variant* args;
|
||||||
tr_variant* list;
|
tr_variant* list;
|
||||||
|
@ -2129,7 +2128,7 @@ static void filterIds(tr_variant* top, Config& config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static int processResponse(char const* rpcurl, std::string_view response, Config& config)
|
static int processResponse(char const* rpcurl, std::string_view response, RemoteConfig& config)
|
||||||
{
|
{
|
||||||
auto status = int{ EXIT_SUCCESS };
|
auto status = int{ EXIT_SUCCESS };
|
||||||
|
|
||||||
|
@ -2250,7 +2249,7 @@ static int processResponse(char const* rpcurl, std::string_view response, Config
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
static CURL* tr_curl_easy_init(struct evbuffer* writebuf, Config& config)
|
static CURL* tr_curl_easy_init(struct evbuffer* writebuf, RemoteConfig& config)
|
||||||
{
|
{
|
||||||
CURL* curl = curl_easy_init();
|
CURL* curl = curl_easy_init();
|
||||||
(void)curl_easy_setopt(curl, CURLOPT_USERAGENT, fmt::format(FMT_STRING("{:s}/{:s}"), MyName, LONG_VERSION_STRING).c_str());
|
(void)curl_easy_setopt(curl, CURLOPT_USERAGENT, fmt::format(FMT_STRING("{:s}/{:s}"), MyName, LONG_VERSION_STRING).c_str());
|
||||||
|
@ -2316,7 +2315,7 @@ static void tr_curl_easy_cleanup(CURL* curl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int flush(char const* rpcurl, tr_variant* benc, Config& config)
|
static int flush(char const* rpcurl, tr_variant* benc, RemoteConfig& config)
|
||||||
{
|
{
|
||||||
auto const json = tr_variant_serde::json().compact().to_string(*benc);
|
auto const json = tr_variant_serde::json().compact().to_string(*benc);
|
||||||
auto const scheme = config.use_ssl ? "https"sv : "http"sv;
|
auto const scheme = config.use_ssl ? "https"sv : "http"sv;
|
||||||
|
@ -2407,7 +2406,7 @@ static tr_variant* ensure_tset(tr_variant& tset)
|
||||||
return tr_variantDictAddDict(&tset, Arguments, 1);
|
return tr_variantDictAddDict(&tset, Arguments, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int processArgs(char const* rpcurl, int argc, char const* const* argv, Config& config)
|
static int processArgs(char const* rpcurl, int argc, char const* const* argv, RemoteConfig& config)
|
||||||
{
|
{
|
||||||
int status = EXIT_SUCCESS;
|
int status = EXIT_SUCCESS;
|
||||||
char const* optarg;
|
char const* optarg;
|
||||||
|
@ -3238,7 +3237,13 @@ static bool parsePortString(char const* s, int* port)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* [host:port] or [host] or [port] or [http(s?)://host:port/transmission/] */
|
/* [host:port] or [host] or [port] or [http(s?)://host:port/transmission/] */
|
||||||
static void getHostAndPortAndRpcUrl(int* argc, char** argv, std::string* host, int* port, std::string* rpcurl, Config& config)
|
static void getHostAndPortAndRpcUrl(
|
||||||
|
int* argc,
|
||||||
|
char** argv,
|
||||||
|
std::string* host,
|
||||||
|
int* port,
|
||||||
|
std::string* rpcurl,
|
||||||
|
RemoteConfig& config)
|
||||||
{
|
{
|
||||||
if (*argv[1] == '-')
|
if (*argv[1] == '-')
|
||||||
{
|
{
|
||||||
|
@ -3300,7 +3305,7 @@ int tr_main(int argc, char* argv[])
|
||||||
|
|
||||||
tr_locale_set_global("");
|
tr_locale_set_global("");
|
||||||
|
|
||||||
auto config = Config{};
|
auto config = RemoteConfig{};
|
||||||
auto port = DefaultPort;
|
auto port = DefaultPort;
|
||||||
auto host = std::string{};
|
auto host = std::string{};
|
||||||
auto rpcurl = std::string{};
|
auto rpcurl = std::string{};
|
||||||
|
|
|
@ -30,12 +30,14 @@
|
||||||
#include <libtransmission/tr-getopt.h>
|
#include <libtransmission/tr-getopt.h>
|
||||||
#include <libtransmission/tr-strbuf.h>
|
#include <libtransmission/tr-strbuf.h>
|
||||||
#include <libtransmission/utils.h>
|
#include <libtransmission/utils.h>
|
||||||
|
#include <libtransmission/values.h>
|
||||||
#include <libtransmission/variant.h>
|
#include <libtransmission/variant.h>
|
||||||
#include <libtransmission/version.h>
|
#include <libtransmission/version.h>
|
||||||
#include <libtransmission/web.h>
|
#include <libtransmission/web.h>
|
||||||
#include <libtransmission/web-utils.h>
|
#include <libtransmission/web-utils.h>
|
||||||
|
|
||||||
using namespace std::literals;
|
using namespace std::literals;
|
||||||
|
using namespace libtransmission::Values;
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
@ -214,8 +216,8 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt::print(" Piece Count: {:d}\n", metainfo.piece_count());
|
fmt::print(" Piece Count: {:d}\n", metainfo.piece_count());
|
||||||
fmt::print(" Piece Size: {:s}\n", tr_formatter_mem_B(metainfo.piece_size()));
|
fmt::print(" Piece Size: {:s}\n", Memory{ metainfo.piece_size(), Memory::Units::Bytes }.to_string());
|
||||||
fmt::print(" Total Size: {:s}\n", tr_formatter_size_B(metainfo.total_size()));
|
fmt::print(" Total Size: {:s}\n", Storage{ metainfo.total_size(), Storage::Units::Bytes }.to_string());
|
||||||
fmt::print(" Privacy: {:s}\n", metainfo.is_private() ? "Private torrent" : "Public torrent");
|
fmt::print(" Privacy: {:s}\n", metainfo.is_private() ? "Private torrent" : "Public torrent");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +283,7 @@ void showInfo(app_opts const& opts, tr_torrent_metainfo const& metainfo)
|
||||||
filename = " ";
|
filename = " ";
|
||||||
filename += metainfo.file_subpath(i);
|
filename += metainfo.file_subpath(i);
|
||||||
filename += " (";
|
filename += " (";
|
||||||
filename += tr_formatter_size_B(metainfo.file_size(i));
|
filename += Storage{ metainfo.file_size(i), Storage::Units::Bytes }.to_string();
|
||||||
filename += ')';
|
filename += ')';
|
||||||
}
|
}
|
||||||
filenames.emplace_back(filename);
|
filenames.emplace_back(filename);
|
||||||
|
|
Loading…
Reference in New Issue