Skip to content
Merged
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
28 changes: 15 additions & 13 deletions src/rpc/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,10 @@ namespace tremotesf {
}

Coroutine<std::optional<qint64>> Rpc::getDownloadDirFreeSpace() {
if (isConnected()) {
if (mServerSettings->data().canShowFreeSpaceForPath()) {
co_return co_await getFreeSpaceForPathImpl(mServerSettings->data().downloadDirectory);
}
co_return co_await getDownloadDirFreeSpaceImpl();
if (mServerSettings->data().canShowFreeSpaceForPath()) {
co_return co_await getFreeSpaceForPathImpl(mServerSettings->data().downloadDirectory);
}
cancelCoroutine();
co_return co_await getDownloadDirFreeSpaceImpl();
}

Coroutine<std::optional<qint64>> Rpc::getDownloadDirFreeSpaceImpl() {
Expand All @@ -597,13 +594,11 @@ namespace tremotesf {
}

Coroutine<std::optional<qint64>> Rpc::getFreeSpaceForPath(QString path) {
if (isConnected()) {
if (mServerSettings->data().canShowFreeSpaceForPath()) {
co_return co_await getFreeSpaceForPathImpl(std::move(path));
}
if (path == mServerSettings->data().downloadDirectory) {
co_return co_await getDownloadDirFreeSpaceImpl();
}
if (mServerSettings->data().canShowFreeSpaceForPath()) {
co_return co_await getFreeSpaceForPathImpl(std::move(path));
}
if (path == mServerSettings->data().downloadDirectory) {
co_return co_await getDownloadDirFreeSpaceImpl();
}
cancelCoroutine();
}
Expand Down Expand Up @@ -922,6 +917,13 @@ namespace tremotesf {
if (response.success) {
mServerStats->update(response.arguments);
}

if (isConnected()) {
const auto freeSpace = co_await getDownloadDirFreeSpace();
if (freeSpace) {
mServerStats->setFreeSpace(*freeSpace);
}
}
}

Coroutine<> Rpc::connectAndPerformDataUpdates() {
Expand Down
2 changes: 2 additions & 0 deletions src/rpc/serverstats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ namespace tremotesf {
mTotal.update(serverStats.value("cumulative-stats"_L1).toObject());
emit updated();
}

void ServerStats::setFreeSpace(const qint64 freeSpace) { mFreeSpace = freeSpace; }
}
3 changes: 3 additions & 0 deletions src/rpc/serverstats.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,18 @@ namespace tremotesf {

[[nodiscard]] qint64 downloadSpeed() const { return mDownloadSpeed; };
[[nodiscard]] qint64 uploadSpeed() const { return mUploadSpeed; };
[[nodiscard]] qint64 freeSpace() const { return mFreeSpace; };

[[nodiscard]] SessionStats currentSession() const { return mCurrentSession; };
[[nodiscard]] SessionStats total() const { return mTotal; };

void update(const QJsonObject& serverStats);
void setFreeSpace(const qint64 freeSpace);

private:
qint64 mDownloadSpeed{};
qint64 mUploadSpeed{};
qint64 mFreeSpace{};
SessionStats mCurrentSession{};
SessionStats mTotal{};
signals:
Expand Down
14 changes: 14 additions & 0 deletions src/ui/screens/mainwindow/mainwindowstatusbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ namespace tremotesf {
mUploadSpeedLabel = new QLabel(this);
layout->addWidget(mUploadSpeedLabel);

mFourthSeparator = new StatusBarSeparator(this);
layout->addWidget(mFourthSeparator);

mFreeSpaceLabel = new QLabel(this);
mFreeSpaceLabel->setContentsMargins(8, 0, 0, 0);
layout->addWidget(mFreeSpaceLabel);

updateLayout();
QObject::connect(mRpc, &Rpc::connectionStateChanged, this, &MainWindowStatusBar::updateLayout);
QObject::connect(Servers::instance(), &Servers::hasServersChanged, this, &MainWindowStatusBar::updateLayout);
Expand All @@ -96,6 +103,8 @@ namespace tremotesf {
QObject::connect(mRpc->serverStats(), &ServerStats::updated, this, [=, this] {
mDownloadSpeedLabel->setText(formatutils::formatByteSpeed(mRpc->serverStats()->downloadSpeed()));
mUploadSpeedLabel->setText(formatutils::formatByteSpeed(mRpc->serverStats()->uploadSpeed()));
mFreeSpaceLabel->setText(qApp->translate("tremotesf", "Free space: %1")
.arg(formatutils::formatByteSize(mRpc->serverStats()->freeSpace())));
});
}

Expand All @@ -112,13 +121,17 @@ namespace tremotesf {
mThirdSeparator->show();
mUploadSpeedImage->show();
mUploadSpeedLabel->show();
mFourthSeparator->show();
mFreeSpaceLabel->show();
} else {
mSecondSeparator->hide();
mDownloadSpeedImage->hide();
mDownloadSpeedLabel->hide();
mThirdSeparator->hide();
mUploadSpeedImage->hide();
mUploadSpeedLabel->hide();
mFourthSeparator->hide();
mFreeSpaceLabel->hide();
}
} else {
mNoServersErrorImage->show();
Expand All @@ -131,6 +144,7 @@ namespace tremotesf {
mThirdSeparator->hide();
mUploadSpeedImage->hide();
mUploadSpeedLabel->hide();
mFreeSpaceLabel->hide();
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/ui/screens/mainwindow/mainwindowstatusbar.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ namespace tremotesf {
StatusBarSeparator* mThirdSeparator{};
QLabel* mUploadSpeedImage{};
QLabel* mUploadSpeedLabel{};
StatusBarSeparator* mFourthSeparator{};
QLabel* mFreeSpaceLabel{};

signals:
void showConnectionSettingsDialog();
Expand Down
Loading