Fix most of critical issues reported by Sonar (GTK client) (#2309)

* (C++) Macros should not be used to define constants

* (C++) Memory should not be managed manually

* (C++) "void*" should not be used in typedefs, member variables, function parameters or return type

* (C++) When the "Rule-of-Zero" is not applicable, the "Rule-of-Five" should be followed

* (C++) "switch" statements should have "default" clauses

* (C++) "explicit" should be used on single-parameter constructors and conversiosn operators

* (C++) Non-const global variables should not be used
This commit is contained in:
Mike Gelfand
2021-12-14 11:43:27 +03:00
committed by GitHub
parent 7015f48798
commit 3e072f9bd4
82 changed files with 459 additions and 287 deletions

View File

@@ -14,11 +14,16 @@
#include "IconCache.h"
#include "Utils.h"
#define VOID_PIXBUF_KEY "void-pixbuf"
using namespace std::literals;
Glib::ustring const DirectoryMimeType = "folder"s;
Glib::ustring const UnknownMimeType = "unknown"s;
namespace
{
auto const VoidPixbufKey = "void-pixbuf"s;
struct IconCache
{
Glib::RefPtr<Gtk::IconTheme> icon_theme;
@@ -48,7 +53,7 @@ std::unique_ptr<IconCache> icon_cache_new(Gtk::Widget& for_widget, Gtk::IconSize
auto icons = std::make_unique<IconCache>();
icons->icon_theme = Gtk::IconTheme::get_for_screen(for_widget.get_screen());
icons->icon_size = get_size_in_pixels(icon_size);
icons->cache.emplace(VOID_PIXBUF_KEY, create_void_pixbuf(icons->icon_size, icons->icon_size));
icons->cache.emplace(VoidPixbufKey, create_void_pixbuf(icons->icon_size, icons->icon_size));
return icons;
}
@@ -134,7 +139,7 @@ Glib::RefPtr<Gdk::Pixbuf> icon_cache_get_mime_type_icon(IconCache& icons, Glib::
auto key = _icon_cache_get_icon_key(icon);
if (key.empty())
{
key = VOID_PIXBUF_KEY;
key = VoidPixbufKey;
}
if (auto pixbuf_it = icons.cache.find(key); pixbuf_it != icons.cache.end())