1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00
transmission/gtk/FreeSpaceLabel.cc
Charles Kerr a250690f30
fix: sonarcloud (#2860)
* fix: break will never be executed

* fix: rewrite rimraf() to be non-throwing

* fix: conditional operation returns same value whether condition is true or false

* fix: use std::array instead of a C-style array

* fix: remove redundant access specifier

* fix: replace switch with if for readability

* fix: convert integer literal to a bool literal

* fix: replace const std::string reference to std::string_view

* fix: remove redundant access specifier

* fix: replace const std::string reference to std::string_view

* fix: remove unused parameter

* fix: remove redundant access specifier

* fix: use std::array instead of C-style array

* fix: remove redundant access specifier

* fix: replace const std::string reference with std::string_view

* fix: remove redundant access specifier

* fix: use std::array instead of C-style array

* fix: remove redundant access specifier

* fix: replace const std::string reference to std::string_view

* fix: remove redundant access specifier

* fix: merge if statement with enclosing one

* chore: clang-format

* chore: clang-format

* Revert "fix: remove redundant access specifier"

This reverts commit 054e4e7eec.

* Revert "fix: remove redundant access specifier"

This reverts commit 2c92f227e8.

* Revert "fix: remove redundant access specifier"

This reverts commit a0710202a8.

* Revert "fix: remove redundant access specifier"

This reverts commit 54da1d9397.

* Revert "fix: remove redundant access specifier"

This reverts commit f7b1777578.

* Revert "fix: remove redundant access specifier"

This reverts commit ad8e3dfff4.

* chore: revert access specifier change
2022-04-01 14:16:33 -05:00

83 lines
1.9 KiB
C++

// This file Copyright © 2008-2022 Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#include <memory>
#include <string>
#include <glibmm/i18n.h>
#include <fmt/core.h>
#include <libtransmission/utils.h>
#include "FreeSpaceLabel.h"
#include "Session.h"
#include "Utils.h"
class FreeSpaceLabel::Impl
{
public:
Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& core, std::string_view dir);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
void set_dir(std::string_view dir);
private:
bool on_freespace_timer();
FreeSpaceLabel& label_;
Glib::RefPtr<Session> const core_;
std::string dir_;
sigc::connection timer_id_;
};
FreeSpaceLabel::Impl::~Impl()
{
timer_id_.disconnect();
}
bool FreeSpaceLabel::Impl::on_freespace_timer()
{
if (core_->get_session() == nullptr)
{
return false;
}
auto const bytes = tr_dirSpace(dir_).free;
auto const text = bytes < 0 ? _("Error") : fmt::format(_("{disk_space} free"), fmt::arg("disk_space", tr_strlsize(bytes)));
label_.set_markup(fmt::format(FMT_STRING("<i>{:s}</i>"), text));
return true;
}
FreeSpaceLabel::FreeSpaceLabel(Glib::RefPtr<Session> const& core, std::string_view dir)
: Gtk::Label()
, impl_(std::make_unique<Impl>(*this, core, dir))
{
}
FreeSpaceLabel::~FreeSpaceLabel() = default;
FreeSpaceLabel::Impl::Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& core, std::string_view dir)
: label_(label)
, core_(core)
, dir_(dir)
{
timer_id_ = Glib::signal_timeout().connect_seconds(sigc::mem_fun(*this, &Impl::on_freespace_timer), 3);
on_freespace_timer();
}
void FreeSpaceLabel::set_dir(std::string_view dir)
{
impl_->set_dir(dir);
}
void FreeSpaceLabel::Impl::set_dir(std::string_view dir)
{
dir_ = dir;
on_freespace_timer();
}