1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-27 01:57:52 +00:00
transmission/gtk/FreeSpaceLabel.cc
Mike Gelfand eec93de5ca
Fix issues reported by clang-tidy readability checks (GTK client) (#4127)
* Fix `readability-container-data-pointer` clang-tidy issues

* Fix `readability-container-size-empty` clang-tidy issues

* Fix `readability-isolate-declaration` clang-tidy issues

* Fix `readability-convert-member-functions-to-static` clang-tidy issues

* Fix `readability-else-after-return` clang-tidy issues

* Fix `readability-redundant-member-init` clang-tidy issues

* Fix `readability-uppercase-literal-suffix` clang-tidy issues

* Fix `readability-make-member-function-const` clang-tidy issues

* Fix `readability-simplify-boolean-expr` clang-tidy issues

* Fix `readability-qualified-auto` clang-tidy issues

* Fix `readability-avoid-const-params-in-decls` clang-tidy issues

* Fix `readability-implicit-bool-conversion` clang-tidy issues

* Fix `readability-inconsistent-declaration-parameter-name` clang-tidy issues

* Add initial .clang-tidy configuration

Currently enabling readability checks only, others to follow. Of the
four disabled readability checks, three (function-cognitive-complexity,
identifier-length, magic-numbers) require extensive refactoring and were
left for later, and one (redundant-access-specifiers) is not planned to
be fixed due to the current coding style - using extra sections to
separate methods from variables of the same visibility.
2022-11-09 16:58:36 +00:00

93 lines
2.2 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 <string_view>
#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)
: impl_(std::make_unique<Impl>(*this, core, dir))
{
}
FreeSpaceLabel::FreeSpaceLabel(
BaseObjectType* cast_item,
Glib::RefPtr<Gtk::Builder> const& /*builder*/,
Glib::RefPtr<Session> const& core,
std::string_view dir)
: Gtk::Label(cast_item)
, 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();
}