mirror of
https://github.com/transmission/transmission
synced 2025-01-30 10:52:00 +00:00
Fix clang-tidy issues stemming from header files (GTK client) (#4623)
* Fix `readability-avoid-const-params-in-decls` clang-tidy issues * Fix `bugprone-macro-parentheses` clang-tidy issues * Fix `modernize-use-using` clang-tidy issues * Fix `readability-named-parameter` clang-tidy issues * Fix `cppcoreguidelines-owning-memory` clang-tidy issues * Fix `cppcoreguidelines-special-member-functions` clang-tidy issues * Fix `cppcoreguidelines-macro-usage` clang-tidy issues * Fix `modernize-use-nodiscard` clang-tidy issues * Fix `cppcoreguidelines-macro-usage` clang-tidy issues * Add headers filter for /gtk/ subdirectory
This commit is contained in:
parent
8755207dcf
commit
bd72b8c3fc
14 changed files with 59 additions and 34 deletions
|
@ -1,4 +1,6 @@
|
|||
---
|
||||
HeaderFilterRegex: .*/gtk/.*
|
||||
|
||||
Checks: >
|
||||
-*,
|
||||
bugprone-*,
|
||||
|
|
|
@ -363,7 +363,7 @@ void DetailsDialog::Impl::refreshOptions(std::vector<tr_torrent*> const& torrent
|
|||
if (is_uniform)
|
||||
{
|
||||
bandwidth_combo_tag_.block();
|
||||
gtr_priority_combo_set_value(*bandwidth_combo_, baseline);
|
||||
gtr_combo_box_set_active_enum(*bandwidth_combo_, baseline);
|
||||
bandwidth_combo_tag_.unblock();
|
||||
}
|
||||
else
|
||||
|
@ -510,7 +510,7 @@ void DetailsDialog::Impl::options_page_init(Glib::RefPtr<Gtk::Builder> const& /*
|
|||
|
||||
gtr_priority_combo_init(*bandwidth_combo_);
|
||||
bandwidth_combo_tag_ = bandwidth_combo_->signal_changed().connect(
|
||||
[this]() { torrent_set_int(TR_KEY_bandwidthPriority, gtr_priority_combo_get_value(*bandwidth_combo_)); });
|
||||
[this]() { torrent_set_int(TR_KEY_bandwidthPriority, gtr_combo_box_get_active_enum(*bandwidth_combo_)); });
|
||||
|
||||
gtr_combo_box_set_enum(
|
||||
*ratio_combo_,
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "GtkCompat.h"
|
||||
|
||||
#include <libtransmission/tr-macros.h>
|
||||
|
||||
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
||||
#include <gtkmm/filter.h>
|
||||
#else
|
||||
|
@ -26,8 +28,11 @@ public:
|
|||
#endif
|
||||
|
||||
public:
|
||||
FilterBase() = default;
|
||||
~FilterBase() override = default;
|
||||
|
||||
TR_DISABLE_COPY_MOVE(FilterBase)
|
||||
|
||||
virtual bool match(T const& item) const = 0;
|
||||
|
||||
virtual bool matches_all() const;
|
||||
|
|
|
@ -92,5 +92,6 @@ Glib::RefPtr<FilterListModel<ItemT>> FilterListModel<ItemT>::create(
|
|||
Glib::RefPtr<ModelT> const& model,
|
||||
Glib::RefPtr<FilterType> const& filter)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
|
||||
return Glib::make_refptr_for_instance(new FilterListModel(model, filter));
|
||||
}
|
||||
|
|
18
gtk/Flags.h
18
gtk/Flags.h
|
@ -8,12 +8,16 @@
|
|||
#include <initializer_list>
|
||||
#include <type_traits>
|
||||
|
||||
// NOLINTBEGIN(bugprone-macro-parentheses, cppcoreguidelines-macro-usage)
|
||||
|
||||
#define DEFINE_FLAGS_OPERATORS(FlagType) \
|
||||
constexpr inline Flags<FlagType> operator|(FlagType lhs, FlagType rhs) noexcept \
|
||||
{ \
|
||||
return { lhs, rhs }; \
|
||||
}
|
||||
|
||||
// NOLINTEND(bugprone-macro-parentheses, cppcoreguidelines-macro-usage)
|
||||
|
||||
template<typename T>
|
||||
class Flags
|
||||
{
|
||||
|
@ -39,22 +43,22 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
constexpr bool none() const noexcept
|
||||
[[nodiscard]] constexpr bool none() const noexcept
|
||||
{
|
||||
return value_ == 0;
|
||||
}
|
||||
|
||||
constexpr bool any() const noexcept
|
||||
[[nodiscard]] constexpr bool any() const noexcept
|
||||
{
|
||||
return !none();
|
||||
}
|
||||
|
||||
constexpr bool test(FlagType flag) const noexcept
|
||||
[[nodiscard]] constexpr bool test(FlagType flag) const noexcept
|
||||
{
|
||||
return (value_ & get_mask(flag)) != 0;
|
||||
}
|
||||
|
||||
constexpr bool test(Flags rhs) const noexcept
|
||||
[[nodiscard]] constexpr bool test(Flags rhs) const noexcept
|
||||
{
|
||||
return (value_ & rhs.value_) != 0;
|
||||
}
|
||||
|
@ -64,7 +68,7 @@ public:
|
|||
value_ |= get_mask(flag);
|
||||
}
|
||||
|
||||
constexpr Flags operator|(Flags rhs) noexcept
|
||||
[[nodiscard]] constexpr Flags operator|(Flags rhs) noexcept
|
||||
{
|
||||
return Flags(value_ | rhs.value_);
|
||||
}
|
||||
|
@ -75,7 +79,7 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
constexpr Flags operator~() const noexcept
|
||||
[[nodiscard]] constexpr Flags operator~() const noexcept
|
||||
{
|
||||
return Flags(~value_);
|
||||
}
|
||||
|
@ -86,7 +90,7 @@ private:
|
|||
{
|
||||
}
|
||||
|
||||
static constexpr ValueType get_mask(FlagType flag) noexcept
|
||||
[[nodiscard]] static constexpr ValueType get_mask(FlagType flag) noexcept
|
||||
{
|
||||
return ValueType{ 1 } << static_cast<ValueType>(flag);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,8 @@
|
|||
|
||||
#include <cstddef>
|
||||
|
||||
// NOLINTBEGIN(cppcoreguidelines-macro-usage)
|
||||
|
||||
#ifndef GTKMM_CHECK_VERSION
|
||||
#define GTKMM_CHECK_VERSION(major, minor, micro) \
|
||||
(GTKMM_MAJOR_VERSION > (major) || (GTKMM_MAJOR_VERSION == (major) && GTKMM_MINOR_VERSION > (minor)) || \
|
||||
|
@ -103,6 +105,8 @@
|
|||
#define TR_PANGO_ELLIPSIZE_MODE(Code) IF_PANGOMM2_48(Pango::EllipsizeMode::Code, Pango::ELLIPSIZE_##Code)
|
||||
#define TR_PANGO_WEIGHT(Code) IF_PANGOMM2_48(Pango::Weight::Code, Pango::WEIGHT_##Code)
|
||||
|
||||
// NOLINTEND(cppcoreguidelines-macro-usage)
|
||||
|
||||
namespace Glib
|
||||
{
|
||||
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
static Glib::RefPtr<ListModelAdapter> create(Glib::RefPtr<Gio::ListModel> const& adaptee)
|
||||
{
|
||||
return Glib::make_refptr_for_instance(
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
|
||||
new ListModelAdapter(adaptee, T::get_columns(), &T::get_item_id, &T::get_item_value));
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#include "Prefs.h"
|
||||
#include "PrefsDialog.h"
|
||||
#include "Session.h"
|
||||
#include "Utils.h" /* gtr_priority_combo_get_value() */
|
||||
#include "Utils.h"
|
||||
|
||||
#include <libtransmission/transmission.h>
|
||||
#include <libtransmission/file.h> /* tr_sys_path_is_same() */
|
||||
|
@ -118,7 +118,7 @@ void OptionsDialog::Impl::addResponseCB(int response)
|
|||
{
|
||||
if (response == TR_GTK_RESPONSE_TYPE(ACCEPT))
|
||||
{
|
||||
tr_torrentSetPriority(tor_, gtr_priority_combo_get_value(*priority_combo_));
|
||||
tr_torrentSetPriority(tor_, gtr_combo_box_get_active_enum(*priority_combo_));
|
||||
|
||||
if (run_check_->get_active())
|
||||
{
|
||||
|
@ -284,7 +284,7 @@ OptionsDialog::Impl::Impl(
|
|||
dialog.signal_response().connect(sigc::mem_fun(*this, &Impl::addResponseCB));
|
||||
|
||||
gtr_priority_combo_init(*priority_combo_);
|
||||
gtr_priority_combo_set_value(*priority_combo_, TR_PRI_NORMAL);
|
||||
gtr_combo_box_set_active_enum(*priority_combo_, TR_PRI_NORMAL);
|
||||
|
||||
auto* source_chooser = gtr_get_widget_derived<PathButton>(builder, "source_button");
|
||||
addTorrentFilters(source_chooser);
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
#include <memory>
|
||||
|
||||
class Session;
|
||||
typedef struct tr_ctor tr_ctor;
|
||||
|
||||
struct tr_ctor;
|
||||
|
||||
class TorrentUrlChooserDialog : public Gtk::Dialog
|
||||
{
|
||||
|
@ -27,6 +28,7 @@ public:
|
|||
Glib::RefPtr<Gtk::Builder> const& builder,
|
||||
Gtk::Window& parent,
|
||||
Glib::RefPtr<Session> const& core);
|
||||
~TorrentUrlChooserDialog() override = default;
|
||||
|
||||
TR_DISABLE_COPY_MOVE(TorrentUrlChooserDialog)
|
||||
|
||||
|
@ -39,6 +41,8 @@ private:
|
|||
class TorrentFileChooserDialog : public Gtk::FileChooserDialog
|
||||
{
|
||||
public:
|
||||
~TorrentFileChooserDialog() override = default;
|
||||
|
||||
TR_DISABLE_COPY_MOVE(TorrentFileChooserDialog)
|
||||
|
||||
static std::unique_ptr<TorrentFileChooserDialog> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
|
||||
|
|
20
gtk/Prefs.h
20
gtk/Prefs.h
|
@ -14,19 +14,19 @@
|
|||
|
||||
void gtr_pref_init(std::string_view config_dir);
|
||||
|
||||
int64_t gtr_pref_int_get(tr_quark const key);
|
||||
void gtr_pref_int_set(tr_quark const key, int64_t value);
|
||||
int64_t gtr_pref_int_get(tr_quark key);
|
||||
void gtr_pref_int_set(tr_quark key, int64_t value);
|
||||
|
||||
double gtr_pref_double_get(tr_quark const key);
|
||||
void gtr_pref_double_set(tr_quark const key, double value);
|
||||
double gtr_pref_double_get(tr_quark key);
|
||||
void gtr_pref_double_set(tr_quark key, double value);
|
||||
|
||||
bool gtr_pref_flag_get(tr_quark const key);
|
||||
void gtr_pref_flag_set(tr_quark const key, bool value);
|
||||
bool gtr_pref_flag_get(tr_quark key);
|
||||
void gtr_pref_flag_set(tr_quark key, bool value);
|
||||
|
||||
std::vector<std::string> gtr_pref_strv_get(tr_quark const key);
|
||||
std::vector<std::string> gtr_pref_strv_get(tr_quark key);
|
||||
|
||||
std::string gtr_pref_string_get(tr_quark const key);
|
||||
void gtr_pref_string_set(tr_quark const key, std::string_view value);
|
||||
std::string gtr_pref_string_get(tr_quark key);
|
||||
void gtr_pref_string_set(tr_quark key, std::string_view value);
|
||||
|
||||
void gtr_pref_save(tr_session*);
|
||||
void gtr_pref_save(tr_session* /*session*/);
|
||||
tr_variant* gtr_pref_get_all();
|
||||
|
|
|
@ -67,5 +67,6 @@ Glib::RefPtr<SortListModel<ItemT>> SortListModel<ItemT>::create(
|
|||
Glib::RefPtr<ModelT> const& model,
|
||||
Glib::RefPtr<SorterType> const& sorter)
|
||||
{
|
||||
// NOLINTNEXTLINE(cppcoreguidelines-owning-memory)
|
||||
return Glib::make_refptr_for_instance(new SortListModel(model, sorter));
|
||||
}
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
#include "GtkCompat.h"
|
||||
|
||||
#include <libtransmission/tr-macros.h>
|
||||
|
||||
#if GTKMM_CHECK_VERSION(4, 0, 0)
|
||||
#include <gtkmm/sorter.h>
|
||||
#else
|
||||
|
@ -27,8 +29,11 @@ public:
|
|||
#endif
|
||||
|
||||
public:
|
||||
SorterBase() = default;
|
||||
~SorterBase() override = default;
|
||||
|
||||
TR_DISABLE_COPY_MOVE(SorterBase)
|
||||
|
||||
virtual int compare(T const& lhs, T const& rhs) const = 0;
|
||||
|
||||
#if !GTKMM_CHECK_VERSION(4, 0, 0)
|
||||
|
|
12
gtk/Utils.cc
12
gtk/Utils.cc
|
@ -563,12 +563,12 @@ EnumComboModelColumns const enum_combo_cols;
|
|||
|
||||
} // namespace
|
||||
|
||||
void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo_box, int value)
|
||||
void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo, int value)
|
||||
{
|
||||
auto const& column = enum_combo_cols.value;
|
||||
|
||||
/* do the value and current value match? */
|
||||
if (auto const iter = combo_box.get_active(); iter)
|
||||
if (auto const iter = combo.get_active(); iter)
|
||||
{
|
||||
if (iter->get_value(column) == value)
|
||||
{
|
||||
|
@ -577,11 +577,11 @@ void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo_box, int value)
|
|||
}
|
||||
|
||||
/* find the one to select */
|
||||
for (auto const& row : combo_box.get_model()->children())
|
||||
for (auto const& row : combo.get_model()->children())
|
||||
{
|
||||
if (row.get_value(column) == value)
|
||||
{
|
||||
combo_box.set_active(TR_GTK_TREE_MODEL_CHILD_ITER(row));
|
||||
combo.set_active(TR_GTK_TREE_MODEL_CHILD_ITER(row));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -606,11 +606,11 @@ void gtr_combo_box_set_enum(Gtk::ComboBox& combo, std::vector<std::pair<Glib::us
|
|||
combo.add_attribute(r->property_text(), enum_combo_cols.label);
|
||||
}
|
||||
|
||||
int gtr_combo_box_get_active_enum(Gtk::ComboBox const& combo_box)
|
||||
int gtr_combo_box_get_active_enum(Gtk::ComboBox const& combo)
|
||||
{
|
||||
int value = 0;
|
||||
|
||||
if (auto const iter = combo_box.get_active(); iter)
|
||||
if (auto const iter = combo.get_active(); iter)
|
||||
{
|
||||
iter->get_value(0, value);
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ enum class GtrUnicode
|
|||
Bullet
|
||||
};
|
||||
|
||||
Glib::ustring gtr_get_unicode_string(GtrUnicode);
|
||||
Glib::ustring gtr_get_unicode_string(GtrUnicode uni);
|
||||
|
||||
/* return a human-readable string for the size given in bytes. */
|
||||
Glib::ustring tr_strlsize(guint64 size_in_bytes);
|
||||
|
@ -123,12 +123,10 @@ void gtr_window_raise(Gtk::Window& window);
|
|||
***/
|
||||
|
||||
void gtr_priority_combo_init(Gtk::ComboBox& combo);
|
||||
#define gtr_priority_combo_get_value(w) gtr_combo_box_get_active_enum(w)
|
||||
#define gtr_priority_combo_set_value(w, val) gtr_combo_box_set_active_enum(w, val)
|
||||
|
||||
void gtr_combo_box_set_enum(Gtk::ComboBox& combo, std::vector<std::pair<Glib::ustring, int>> const& items);
|
||||
int gtr_combo_box_get_active_enum(Gtk::ComboBox const&);
|
||||
void gtr_combo_box_set_active_enum(Gtk::ComboBox&, int value);
|
||||
int gtr_combo_box_get_active_enum(Gtk::ComboBox const& combo);
|
||||
void gtr_combo_box_set_active_enum(Gtk::ComboBox& combo, int value);
|
||||
|
||||
/***
|
||||
****
|
||||
|
|
Loading…
Reference in a new issue