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 commit054e4e7eec
. * Revert "fix: remove redundant access specifier" This reverts commit2c92f227e8
. * Revert "fix: remove redundant access specifier" This reverts commita0710202a8
. * Revert "fix: remove redundant access specifier" This reverts commit54da1d9397
. * Revert "fix: remove redundant access specifier" This reverts commitf7b1777578
. * Revert "fix: remove redundant access specifier" This reverts commitad8e3dfff4
. * chore: revert access specifier change
This commit is contained in:
parent
6da591fe57
commit
a250690f30
|
@ -321,7 +321,7 @@ int tr_main(int argc, char* argv[])
|
|||
{
|
||||
char line[LineWidth];
|
||||
tr_stat const* st;
|
||||
char const* messageName[] = {
|
||||
static auto constexpr messageName = std::array<char const*, 4>{
|
||||
nullptr,
|
||||
"Tracker gave a warning:",
|
||||
"Tracker gave an error:",
|
||||
|
|
|
@ -720,14 +720,13 @@ void Application::Impl::app_setup()
|
|||
w.add_button(_("I _Agree"), Gtk::RESPONSE_ACCEPT);
|
||||
w.set_default_response(Gtk::RESPONSE_ACCEPT);
|
||||
|
||||
switch (w.run())
|
||||
if (w.run() == Gtk::RESPONSE_ACCEPT)
|
||||
{
|
||||
case Gtk::RESPONSE_ACCEPT:
|
||||
/* only show it once */
|
||||
// only show it once
|
||||
gtr_pref_flag_set(TR_KEY_user_has_given_informed_consent, true);
|
||||
break;
|
||||
|
||||
default:
|
||||
}
|
||||
else
|
||||
{
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -463,7 +463,7 @@ Gtk::Widget* DetailsDialog::Impl::options_page_new()
|
|||
auto* t = Gtk::make_managed<HigWorkarea>();
|
||||
t->add_section_title(row, _("Speed"));
|
||||
|
||||
honor_limits_check_ = t->add_wide_checkbutton(row, _("Honor global _limits"), 0);
|
||||
honor_limits_check_ = t->add_wide_checkbutton(row, _("Honor global _limits"), false);
|
||||
honor_limits_check_tag_ = honor_limits_check_->signal_toggled().connect(
|
||||
[this]() { torrent_set_bool(TR_KEY_honorsSessionLimits, honor_limits_check_->get_active()); });
|
||||
|
||||
|
@ -1251,7 +1251,7 @@ public:
|
|||
|
||||
PeerModelColumns const peer_cols;
|
||||
|
||||
void initPeerRow(Gtk::TreeIter const& iter, std::string const& key, std::string const& torrentName, tr_peer_stat const* peer)
|
||||
void initPeerRow(Gtk::TreeIter const& iter, std::string_view key, std::string_view torrent_name, tr_peer_stat const* peer)
|
||||
{
|
||||
g_return_if_fail(peer != nullptr);
|
||||
|
||||
|
@ -1261,23 +1261,17 @@ void initPeerRow(Gtk::TreeIter const& iter, std::string const& key, std::string
|
|||
client = "";
|
||||
}
|
||||
|
||||
int q[4];
|
||||
Glib::ustring collated_name;
|
||||
if (sscanf(peer->addr, "%d.%d.%d.%d", q, q + 1, q + 2, q + 3) != 4)
|
||||
{
|
||||
collated_name = peer->addr;
|
||||
}
|
||||
else
|
||||
{
|
||||
collated_name = gtr_sprintf("%03d.%03d.%03d.%03d", q[0], q[1], q[2], q[3]);
|
||||
}
|
||||
auto q = std::array<int, 4>{};
|
||||
auto const collated_name = sscanf(peer->addr, "%d.%d.%d.%d", &q[0], &q[1], &q[2], &q[3]) != 4 ?
|
||||
peer->addr :
|
||||
fmt::format(FMT_STRING("{:03d}.{:03d}.{:03d}.{:03d}"), q[0], q[1], q[2], q[3]);
|
||||
|
||||
(*iter)[peer_cols.address] = peer->addr;
|
||||
(*iter)[peer_cols.address_collated] = collated_name;
|
||||
(*iter)[peer_cols.client] = client;
|
||||
(*iter)[peer_cols.encryption_stock_id] = peer->isEncrypted ? "lock" : "";
|
||||
(*iter)[peer_cols.key] = key;
|
||||
(*iter)[peer_cols.torrent_name] = torrentName;
|
||||
(*iter)[peer_cols.key] = Glib::ustring{ std::data(key), std::size(key) };
|
||||
(*iter)[peer_cols.torrent_name] = Glib::ustring{ std::data(torrent_name), std::size(torrent_name) };
|
||||
}
|
||||
|
||||
void refreshPeerRow(Gtk::TreeIter const& iter, tr_peer_stat const* peer)
|
||||
|
|
|
@ -19,17 +19,16 @@
|
|||
class FreeSpaceLabel::Impl
|
||||
{
|
||||
public:
|
||||
Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& core, std::string const& dir);
|
||||
Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& core, std::string_view dir);
|
||||
~Impl();
|
||||
|
||||
TR_DISABLE_COPY_MOVE(Impl)
|
||||
|
||||
void set_dir(std::string const& dir);
|
||||
void set_dir(std::string_view dir);
|
||||
|
||||
private:
|
||||
bool on_freespace_timer();
|
||||
|
||||
private:
|
||||
FreeSpaceLabel& label_;
|
||||
Glib::RefPtr<Session> const core_;
|
||||
std::string dir_;
|
||||
|
@ -55,7 +54,7 @@ bool FreeSpaceLabel::Impl::on_freespace_timer()
|
|||
return true;
|
||||
}
|
||||
|
||||
FreeSpaceLabel::FreeSpaceLabel(Glib::RefPtr<Session> const& core, std::string const& dir)
|
||||
FreeSpaceLabel::FreeSpaceLabel(Glib::RefPtr<Session> const& core, std::string_view dir)
|
||||
: Gtk::Label()
|
||||
, impl_(std::make_unique<Impl>(*this, core, dir))
|
||||
{
|
||||
|
@ -63,7 +62,7 @@ FreeSpaceLabel::FreeSpaceLabel(Glib::RefPtr<Session> const& core, std::string co
|
|||
|
||||
FreeSpaceLabel::~FreeSpaceLabel() = default;
|
||||
|
||||
FreeSpaceLabel::Impl::Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& core, std::string const& dir)
|
||||
FreeSpaceLabel::Impl::Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& core, std::string_view dir)
|
||||
: label_(label)
|
||||
, core_(core)
|
||||
, dir_(dir)
|
||||
|
@ -72,12 +71,12 @@ FreeSpaceLabel::Impl::Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& c
|
|||
on_freespace_timer();
|
||||
}
|
||||
|
||||
void FreeSpaceLabel::set_dir(std::string const& dir)
|
||||
void FreeSpaceLabel::set_dir(std::string_view dir)
|
||||
{
|
||||
impl_->set_dir(dir);
|
||||
}
|
||||
|
||||
void FreeSpaceLabel::Impl::set_dir(std::string const& dir)
|
||||
void FreeSpaceLabel::Impl::set_dir(std::string_view dir)
|
||||
{
|
||||
dir_ = dir;
|
||||
on_freespace_timer();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
// License text can be found in the licenses/ folder.
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <glibmm.h>
|
||||
#include <gtkmm.h>
|
||||
|
@ -16,12 +16,12 @@ class Session;
|
|||
class FreeSpaceLabel : public Gtk::Label
|
||||
{
|
||||
public:
|
||||
FreeSpaceLabel(Glib::RefPtr<Session> const& core, std::string const& dir = {});
|
||||
FreeSpaceLabel(Glib::RefPtr<Session> const& core, std::string_view dir = {});
|
||||
~FreeSpaceLabel() override;
|
||||
|
||||
TR_DISABLE_COPY_MOVE(FreeSpaceLabel)
|
||||
|
||||
void set_dir(std::string const& dir);
|
||||
void set_dir(std::string_view dir);
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
|
|
|
@ -108,7 +108,7 @@ Glib::RefPtr<Gdk::Pixbuf> get_file_icon_pixbuf(Gio::FileIcon& icon, int size)
|
|||
{
|
||||
return Gdk::Pixbuf::create_from_file(icon.get_file()->get_path(), size, -1, false);
|
||||
}
|
||||
catch (Glib::Error const& e)
|
||||
catch (Glib::Error const&)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
// This file Copyright © 2005-2021 Transmission authors and contributors.
|
||||
// This file Copyright © 2005-2022 Transmission authors and contributors.
|
||||
// It may be used under the MIT (SPDX: MIT) license.
|
||||
// License text can be found in the licenses/ folder.
|
||||
|
||||
#include <array>
|
||||
#include <string>
|
||||
|
||||
#include <glibmm/i18n.h>
|
||||
|
@ -62,8 +63,8 @@ private:
|
|||
private:
|
||||
MainWindow& window_;
|
||||
|
||||
Gtk::RadioMenuItem* speedlimit_on_item_[2] = { nullptr, nullptr };
|
||||
Gtk::RadioMenuItem* speedlimit_off_item_[2] = { nullptr, nullptr };
|
||||
std::array<Gtk::RadioMenuItem*, 2> speedlimit_on_item_;
|
||||
std::array<Gtk::RadioMenuItem*, 2> speedlimit_off_item_;
|
||||
Gtk::RadioMenuItem* ratio_on_item_ = nullptr;
|
||||
Gtk::RadioMenuItem* ratio_off_item_ = nullptr;
|
||||
Gtk::ScrolledWindow* scroll_ = nullptr;
|
||||
|
|
|
@ -20,7 +20,7 @@ using namespace std::literals;
|
|||
|
||||
std::string gl_confdir;
|
||||
|
||||
void gtr_pref_init(std::string const& config_dir)
|
||||
void gtr_pref_init(std::string_view config_dir)
|
||||
{
|
||||
gl_confdir = config_dir;
|
||||
}
|
||||
|
@ -199,7 +199,7 @@ std::string gtr_pref_string_get(tr_quark const key)
|
|||
return std::string{ sv };
|
||||
}
|
||||
|
||||
void gtr_pref_string_set(tr_quark const key, std::string const& value)
|
||||
void gtr_pref_string_set(tr_quark const key, std::string_view value)
|
||||
{
|
||||
tr_variantDictAddStr(getPrefs(), key, value);
|
||||
}
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <libtransmission/transmission.h> /* tr_variant, tr_session */
|
||||
#include <libtransmission/quark.h>
|
||||
|
||||
void gtr_pref_init(std::string const& config_dir);
|
||||
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);
|
||||
|
@ -25,7 +26,7 @@ void gtr_pref_flag_set(tr_quark const key, bool value);
|
|||
std::vector<std::string> gtr_pref_strv_get(tr_quark const key);
|
||||
|
||||
std::string gtr_pref_string_get(tr_quark const key);
|
||||
void gtr_pref_string_set(tr_quark const key, std::string const& value);
|
||||
void gtr_pref_string_set(tr_quark const key, std::string_view value);
|
||||
|
||||
void gtr_pref_save(tr_session*);
|
||||
tr_variant* gtr_pref_get_all();
|
||||
|
|
|
@ -1170,8 +1170,6 @@ PrefsDialog::Impl::Impl(PrefsDialog& dialog, Glib::RefPtr<Session> const& core)
|
|||
: dialog_(dialog)
|
||||
, core_(core)
|
||||
{
|
||||
static tr_quark const prefs_quarks[] = { TR_KEY_peer_port, TR_KEY_download_dir };
|
||||
|
||||
core_prefs_tag_ = core_->signal_prefs_changed().connect(sigc::mem_fun(*this, &Impl::on_core_prefs_changed));
|
||||
|
||||
dialog_.add_button(_("_Help"), Gtk::RESPONSE_HELP);
|
||||
|
@ -1191,7 +1189,8 @@ PrefsDialog::Impl::Impl(PrefsDialog& dialog, Glib::RefPtr<Session> const& core)
|
|||
n->append_page(*remotePage(), _("Remote"));
|
||||
|
||||
/* init from prefs keys */
|
||||
for (auto const key : prefs_quarks)
|
||||
static auto constexpr PrefsQuarks = std::array<tr_quark, 2>{ TR_KEY_peer_port, TR_KEY_download_dir };
|
||||
for (auto const key : PrefsQuarks)
|
||||
{
|
||||
on_core_prefs_changed(key);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ private:
|
|||
|
||||
tr_torrent* create_new_torrent(tr_ctor* ctor);
|
||||
|
||||
void set_sort_mode(std::string const& mode, bool is_reversed);
|
||||
void set_sort_mode(std::string_view mode, bool is_reversed);
|
||||
|
||||
void maybe_inhibit_hibernation();
|
||||
void set_hibernation_allowed(bool allowed);
|
||||
|
@ -537,7 +537,7 @@ int compare_by_state(Gtk::TreeModel::iterator const& a, Gtk::TreeModel::iterator
|
|||
|
||||
} // namespace
|
||||
|
||||
void Session::Impl::set_sort_mode(std::string const& mode, bool is_reversed)
|
||||
void Session::Impl::set_sort_mode(std::string_view mode, bool is_reversed)
|
||||
{
|
||||
auto const& col = torrent_cols.torrent;
|
||||
Gtk::TreeSortable::SlotCompare sort_func;
|
||||
|
|
|
@ -180,13 +180,10 @@ bool on_tree_view_button_pressed(
|
|||
Gtk::TreeModel::Path path;
|
||||
auto const selection = view->get_selection();
|
||||
|
||||
if (view->get_path_at_pos((int)event->x, (int)event->y, path))
|
||||
if (view->get_path_at_pos((int)event->x, (int)event->y, path) && !selection->is_selected(path))
|
||||
{
|
||||
if (!selection->is_selected(path))
|
||||
{
|
||||
selection->unselect_all();
|
||||
selection->select(path);
|
||||
}
|
||||
selection->unselect_all();
|
||||
selection->select(path);
|
||||
}
|
||||
|
||||
if (callback)
|
||||
|
|
|
@ -1519,15 +1519,12 @@ static constexpr tr_quark priorityKey(int priority)
|
|||
{
|
||||
case TR_PRI_LOW:
|
||||
return TR_KEY_priority_low;
|
||||
break;
|
||||
|
||||
case TR_PRI_HIGH:
|
||||
return TR_KEY_priority_high;
|
||||
break;
|
||||
|
||||
default:
|
||||
return TR_KEY_priority_normal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -193,23 +193,18 @@ QVariant FileTreeModel::headerData(int column, Qt::Orientation orientation, int
|
|||
{
|
||||
case COL_NAME:
|
||||
return tr("File");
|
||||
break;
|
||||
|
||||
case COL_SIZE:
|
||||
return tr("Size");
|
||||
break;
|
||||
|
||||
case COL_PROGRESS:
|
||||
return tr("Progress");
|
||||
break;
|
||||
|
||||
case COL_WANTED:
|
||||
return tr("Download");
|
||||
break;
|
||||
|
||||
case COL_PRIORITY:
|
||||
return tr("Priority");
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -98,15 +98,12 @@ QVariant TorrentModel::data(QModelIndex const& index, int role) const
|
|||
{
|
||||
case Qt::DisplayRole:
|
||||
return t->name();
|
||||
break;
|
||||
|
||||
case Qt::DecorationRole:
|
||||
return t->getMimeTypeIcon();
|
||||
break;
|
||||
|
||||
case TorrentRole:
|
||||
return QVariant::fromValue(t);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -141,9 +141,12 @@ TEST(Crypto, ssha1)
|
|||
EXPECT_TRUE(tr_ssha1_matches(ssha1, plain_text));
|
||||
EXPECT_TRUE(tr_ssha1_matches_(ssha1, plain_text));
|
||||
|
||||
using ssha1_func = std::string (*)(std::string_view plain_text);
|
||||
static auto constexpr Ssha1Funcs = std::array<ssha1_func, 2>{ tr_ssha1, tr_ssha1_ };
|
||||
|
||||
for (size_t j = 0; j < HashCount; ++j)
|
||||
{
|
||||
auto const hash = (j % 2 == 0) ? tr_ssha1(plain_text) : tr_ssha1_(plain_text);
|
||||
auto const hash = Ssha1Funcs[j % 2](plain_text);
|
||||
|
||||
// phrase matches each of generated hashes
|
||||
EXPECT_TRUE(tr_ssha1_matches(hash, plain_text));
|
||||
|
|
|
@ -116,22 +116,22 @@ protected:
|
|||
return path;
|
||||
}
|
||||
|
||||
static auto get_folder_files(std::string const& path)
|
||||
{
|
||||
std::vector<std::string> ret;
|
||||
using file_func_t = std::function<void(char const* filename)>;
|
||||
|
||||
tr_sys_path_info info;
|
||||
if (tr_sys_path_get_info(path.data(), 0, &info) && (info.type == TR_SYS_PATH_IS_DIRECTORY))
|
||||
static void depthFirstWalk(char const* path, file_func_t func)
|
||||
{
|
||||
auto info = tr_sys_path_info{};
|
||||
if (tr_sys_path_get_info(path, 0, &info) && (info.type == TR_SYS_PATH_IS_DIRECTORY))
|
||||
{
|
||||
auto const odir = tr_sys_dir_open(path.data());
|
||||
if (odir != TR_BAD_SYS_DIR)
|
||||
if (auto const odir = tr_sys_dir_open(path); odir != TR_BAD_SYS_DIR)
|
||||
{
|
||||
char const* name;
|
||||
while ((name = tr_sys_dir_read_name(odir)) != nullptr)
|
||||
{
|
||||
if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0)
|
||||
{
|
||||
ret.push_back(tr_strvPath(path, name));
|
||||
auto const filename = tr_strvPath(path, name);
|
||||
depthFirstWalk(tr_strvPath(path, name).c_str(), func);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,22 +139,22 @@ protected:
|
|||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
func(path);
|
||||
}
|
||||
|
||||
static void rimraf(std::string const& path, bool verbose = false)
|
||||
{
|
||||
for (auto const& child : get_folder_files(path))
|
||||
auto remove = [verbose](char const* filename)
|
||||
{
|
||||
rimraf(child, verbose);
|
||||
}
|
||||
if (verbose)
|
||||
{
|
||||
std::cerr << "cleanup: removing '" << filename << "'" << std::endl;
|
||||
}
|
||||
|
||||
if (verbose)
|
||||
{
|
||||
std::cerr << "cleanup: removing '" << path << "'" << std::endl;
|
||||
}
|
||||
tr_sys_path_remove(filename);
|
||||
};
|
||||
|
||||
tr_sys_path_remove(path.data());
|
||||
depthFirstWalk(path.c_str(), remove);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in New Issue