Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 13 additions & 25 deletions src/formatutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,35 +166,23 @@ namespace tremotesf::formatutils {
return formatRatio(static_cast<double>(uploaded) / static_cast<double>(downloaded));
}

QString formatEta(int seconds) {
std::optional<QString> formatElapsedTime(int seconds) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should use the same formatting as formatEta (I don't think there is any point in making them different) and formatEta should call this function, transforming nullopt to "\u221E"

if (seconds < 0) {
return "\u221E";
return std::nullopt;
}

const int days = seconds / 86400;
seconds %= 86400;
const int hours = seconds / 3600;
seconds %= 3600;
const int minutes = seconds / 60;
seconds %= 60;

if (days > 0) {
//: Remaining time string. %L1 is days, %L2 is hours, e.g. "2 d 5 h"
return qApp->translate("tremotesf", "%L1 d %L2 h").arg(days).arg(hours);
}

if (hours > 0) {
//: Remaining time string. %L1 is hours, %L2 is minutes, e.g. "2 h 5 m"
return qApp->translate("tremotesf", "%L1 h %L2 m").arg(hours).arg(minutes);
}

if (minutes > 0) {
//: Remaining time string. %L1 is minutes, %L2 is seconds, e.g. "2 m 5 s"
return qApp->translate("tremotesf", "%L1 m %L2 s").arg(minutes).arg(seconds);
}
const auto d = seconds / 86400;
const auto h = (seconds % 86400) / 3600;
const auto m = (seconds % 3600) / 60;
const auto s = seconds % 60;

// Use your existing translation string or the one from the PR
return qApp->translate("tremotesf", "%1d, %2h, %3m, %4s")
.arg(d).arg(h).arg(m).arg(s);
}

//: Remaining time string. %L1 is seconds, "10 s"
return qApp->translate("tremotesf", "%L1 s").arg(seconds);
QString formatEta(int seconds) {
return formatElapsedTime(seconds).value_or(QStringLiteral("\u221E"));
}

namespace {
Expand Down
2 changes: 1 addition & 1 deletion src/formatutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace tremotesf::formatutils {
QString formatProgress(double progress);
QString formatRatio(double ratio);
QString formatRatio(long long downloaded, long long uploaded);

std::optional<QString> formatElapsedTime(int seconds);
QString formatEta(int seconds);

QString formatDateTime(const QDateTime& dateTime, QLocale::FormatType format, bool displayRelativeTime);
Expand Down
6 changes: 6 additions & 0 deletions src/rpc/torrent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ namespace tremotesf {
Error,
ErrorString,
ActivityDate,
SecondsSeeding,
DoneDate,
PeersLimit,
HonorSessionLimits,
Expand Down Expand Up @@ -151,6 +152,8 @@ namespace tremotesf {
return "errorString"_L1;
case TorrentData::UpdateKey::ActivityDate:
return "activityDate"_L1;
case TorrentData::UpdateKey::SecondsSeeding:
return "secondsSeeding"_L1;
case TorrentData::UpdateKey::DoneDate:
return "doneDate"_L1;
case TorrentData::UpdateKey::PeersLimit:
Expand Down Expand Up @@ -357,6 +360,9 @@ namespace tremotesf {
case TorrentData::UpdateKey::TotalUploaded:
setChanged(totalUploaded, value.toInteger(), changed);
return;
case TorrentData::UpdateKey::SecondsSeeding:
setChanged(secondsSeeding, value.toInteger(), changed);
return;
case TorrentData::UpdateKey::Ratio:
setChanged(ratio, value.toDouble(), changed);
return;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/torrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ namespace tremotesf {

qint64 totalDownloaded{};
qint64 totalUploaded{};
qint64 secondsSeeding{};
double ratio{};
double ratioLimit{};
RatioLimitMode ratioLimitMode{};
Expand Down
12 changes: 12 additions & 0 deletions src/ui/screens/mainwindow/torrentsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ namespace tremotesf {
QLocale::ShortFormat,
mUseRelativeTime
);
case Column::SecondsSeeding: {
if (const auto formattedTime = formatutils::formatElapsedTime(torrent->data().secondsSeeding)) {
return *formattedTime;
}
break;
}
default:
break;
}
Expand All @@ -234,6 +240,7 @@ namespace tremotesf {
case Column::AddedDate:
case Column::DoneDate:
case Column::ActivityDate:
case Column::SecondsSeeding:
return data(index, Qt::DisplayRole);
case Column::DownloadDirectory:
return torrent->data().downloadDirectory;
Expand Down Expand Up @@ -294,6 +301,8 @@ namespace tremotesf {
return torrent->data().completedSize;
case Column::ActivityDate:
return torrent->data().activityDate;
case Column::SecondsSeeding:
return torrent->data().secondsSeeding;
default:
return data(index, Qt::DisplayRole);
}
Expand Down Expand Up @@ -386,6 +395,9 @@ namespace tremotesf {
case Column::ActivityDate:
//: Torrents list column name
return qApp->translate("tremotesf", "Last Activity");
case Column::SecondsSeeding:
//: Torrents list column name
return qApp->translate("tremotesf", "Seeding Time");
default:
return {};
}
Expand Down
1 change: 1 addition & 0 deletions src/ui/screens/mainwindow/torrentsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace tremotesf {
LeftUntilDone,
DownloadDirectory,
CompletedSize,
SecondsSeeding,
ActivityDate
};
Q_ENUM(Column)
Expand Down
7 changes: 7 additions & 0 deletions src/ui/screens/torrentproperties/torrentpropertieswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ namespace tremotesf {
);
auto lastActivityLabel = new QLabel(this);
activityGroupBoxLayout->addRow(qApp->translate("tremotesf", "Last activity:"), lastActivityLabel);
auto seedingTimeLabel = new QLabel(this);
activityGroupBoxLayout->addRow(qApp->translate("tremotesf", "Seeding time:"), seedingTimeLabel);
detailsTabLayout->addWidget(activityGroupBox);

//: Torrent's details tab section
Expand Down Expand Up @@ -238,6 +240,10 @@ namespace tremotesf {
lastActivityLabel->setText(
formatutils::formatDateTime(mTorrent->data().activityDate.toLocalTime(), QLocale::LongFormat)
);

seedingTimeLabel->setText(
formatutils::formatElapsedTime(mTorrent->data().secondsSeeding).value_or(QString{})
);

totalSizeLabel->setText(formatutils::formatByteSize(mTorrent->data().totalSize));
locationLabel->setText(
Expand Down Expand Up @@ -267,6 +273,7 @@ namespace tremotesf {
webSeedersSendingToUsLabel->clear();
peersGettingFromUsLabel->clear();
lastActivityLabel->clear();
seedingTimeLabel->clear();
totalSizeLabel->clear();
locationLabel->clear();
hashLabel->clear();
Expand Down