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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
82 changed files with 459 additions and 287 deletions

View File

@ -29,12 +29,12 @@ namespace
Session* myCore = nullptr;
void action_cb(Gio::SimpleAction& action, void* user_data)
void action_cb(Gio::SimpleAction& action, gpointer user_data)
{
gtr_actions_handler(action.get_name(), user_data);
}
void sort_changed_cb(Gio::SimpleAction& action, Glib::VariantBase const& value, void* /*user_data*/)
void sort_changed_cb(Gio::SimpleAction& action, Glib::VariantBase const& value, gpointer /*user_data*/)
{
action.set_state(value);
myCore->set_pref(TR_KEY_sort_mode, Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring>>(value).get());
@ -45,7 +45,7 @@ std::array<std::string_view, 2> const show_toggle_entries = {
"toggle-message-log"sv,
};
void toggle_pref_cb(Gio::SimpleAction& action, void* /*user_data*/)
void toggle_pref_cb(Gio::SimpleAction& action, gpointer /*user_data*/)
{
auto const key = action.get_name();
bool val = false;
@ -97,11 +97,6 @@ std::array<std::string_view, 29> const entries = {
"present-main-window"sv,
};
void register_my_icons()
{
Gtk::IconTheme::get_default()->add_resource_path(TR_RESOURCE_PATH "icons");
}
Gtk::Builder* myBuilder = nullptr;
std::unordered_map<Glib::ustring, Glib::RefPtr<Gio::SimpleAction>> key_to_action;
@ -113,12 +108,10 @@ void gtr_actions_set_core(Glib::RefPtr<Session> const& core)
myCore = gtr_get_ptr(core);
}
Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder> const& builder, void* callback_user_data)
Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder> const& builder, gpointer callback_user_data)
{
myBuilder = gtr_get_ptr(builder);
register_my_icons();
auto const action_group = Gio::SimpleActionGroup::create();
auto const match = gtr_pref_string_get(TR_KEY_sort_mode);

View File

@ -14,13 +14,9 @@
class Session;
#define WINDOW_ICON "transmission-main-window-icon"
#define TRAY_ICON "transmission-tray-icon"
#define NOTIFICATION_ICON "transmission-notification-icon"
Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder> const& builder, void* callback_user_data);
Glib::RefPtr<Gio::SimpleActionGroup> gtr_actions_init(Glib::RefPtr<Gtk::Builder> const& builder, gpointer callback_user_data);
void gtr_actions_set_core(Glib::RefPtr<Session> const& core);
void gtr_actions_handler(Glib::ustring const& action_name, void* user_data);
void gtr_actions_handler(Glib::ustring const& action_name, gpointer user_data);
void gtr_action_activate(Glib::ustring const& action_name);
void gtr_action_set_sensitive(Glib::ustring const& action_name, bool is_sensitive);

View File

@ -59,8 +59,6 @@
#include "SystemTrayIcon.h"
#include "Utils.h"
#define MY_CONFIG_NAME "transmission"
using namespace std::literals;
#define SHOW_LICENSE
@ -68,7 +66,9 @@ using namespace std::literals;
namespace
{
char const* LICENSE =
auto const AppIconName = Glib::ustring("transmission"s);
char const* const LICENSE =
"Copyright 2005-2020. All code is copyrighted by the respective authors.\n"
"\n"
"Transmission can be redistributed and/or modified under the terms of the "
@ -83,13 +83,15 @@ char const* LICENSE =
"Some of Transmission's source files have more permissive licenses. "
"Those files may, of course, be used on their own under their own terms.\n";
}
} // namespace
class Application::Impl
{
public:
Impl(Application& app, std::string const& config_dir, bool start_paused, bool is_iconified);
TR_DISABLE_COPY_MOVE(Impl)
void open_files(std::vector<Glib::RefPtr<Gio::File>> const& files);
void on_startup();
@ -161,7 +163,11 @@ private:
bool call_rpc_for_selected_torrents(std::string const& method);
void remove_selected(bool delete_files);
static tr_rpc_callback_status on_rpc_changed(tr_session* session, tr_rpc_callback_type type, tr_torrent* tor, void* gdata);
static tr_rpc_callback_status on_rpc_changed(
tr_session* session,
tr_rpc_callback_type type,
tr_torrent* tor,
gpointer gdata);
private:
Application& app_;
@ -475,6 +481,9 @@ bool Application::Impl::on_rpc_changed_idle(tr_rpc_callback_type type, int torre
case TR_RPC_SESSION_QUEUE_POSITIONS_CHANGED:
/* nothing interesting to do here */
break;
default:
g_assert_not_reached();
}
return false;
@ -484,7 +493,7 @@ tr_rpc_callback_status Application::Impl::on_rpc_changed(
tr_session* /*session*/,
tr_rpc_callback_type type,
tr_torrent* tor,
void* gdata)
gpointer gdata)
{
auto* impl = static_cast<Impl*>(gdata);
auto const torrent_id = tr_torrentId(tor);
@ -502,7 +511,7 @@ namespace
{
sig_atomic_t global_sigcount = 0;
void* sighandler_cbdata = nullptr;
gpointer sighandler_cbdata = nullptr;
void signal_handler(int sig)
{
@ -534,6 +543,9 @@ void Application::on_startup()
void Application::Impl::on_startup()
{
Gtk::IconTheme::get_default()->add_resource_path(gtr_get_full_resource_path("icons"s));
Gtk::Window::set_default_icon_name(AppIconName);
tr_session* session;
::signal(SIGINT, signal_handler);
@ -560,7 +572,7 @@ void Application::Impl::on_startup()
core_ = Session::create(session);
/* init the ui manager */
ui_builder_ = Gtk::Builder::create_from_resource(TR_RESOURCE_PATH "transmission-ui.xml");
ui_builder_ = Gtk::Builder::create_from_resource(gtr_get_full_resource_path("transmission-ui.xml"s));
auto const actions = gtr_actions_init(ui_builder_, this);
app_.set_menubar(gtr_action_get_object<Gio::Menu>("main-window-menu"));
@ -1283,7 +1295,7 @@ void Application::Impl::show_about_dialog()
d.set_authors(authors);
d.set_comments(_("A fast and easy BitTorrent client"));
d.set_copyright(_("Copyright (c) The Transmission Project"));
d.set_logo_icon_name(MY_CONFIG_NAME);
d.set_logo_icon_name(AppIconName);
d.set_name(Glib::get_application_name());
/* Translators: translate "translator-credits" as your name
to have it appear in the credits in the "About"
@ -1402,7 +1414,7 @@ void Application::Impl::copy_magnet_link_to_clipboard(tr_torrent* tor) const
tr_free(magnet);
}
void gtr_actions_handler(Glib::ustring const& action_name, void* user_data)
void gtr_actions_handler(Glib::ustring const& action_name, gpointer user_data)
{
static_cast<Application::Impl*>(user_data)->actions_handler(action_name);
}

View File

@ -28,13 +28,17 @@
#include <glibmm.h>
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Application : public Gtk::Application
{
public:
Application(std::string const& config_dir, bool start_paused, bool is_iconified);
~Application() override;
friend void gtr_actions_handler(Glib::ustring const& action_name, void* user_data);
TR_DISABLE_COPY_MOVE(Application)
friend void gtr_actions_handler(Glib::ustring const& action_name, gpointer user_data);
protected:
void on_startup() override;

View File

@ -40,6 +40,8 @@ public:
Impl(DetailsDialog& dialog, Glib::RefPtr<Session> const& core);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
void set_torrents(std::vector<int> const& torrent_ids);
private:
@ -62,8 +64,8 @@ private:
void onScrapeToggled();
void onBackupToggled();
void on_add_tracker_response(int response, Gtk::Dialog* dialog);
void on_edit_trackers_response(int response, Gtk::Dialog* dialog);
void on_add_tracker_response(int response, std::shared_ptr<Gtk::Dialog>& dialog);
void on_edit_trackers_response(int response, std::shared_ptr<Gtk::Dialog>& dialog);
void torrent_set_bool(tr_quark key, bool value);
void torrent_set_int(tr_quark key, int value);
@ -569,6 +571,9 @@ Glib::ustring activityString(int activity, bool finished)
case TR_STATUS_STOPPED:
return finished ? _("Finished") : _("Paused");
default:
g_assert_not_reached();
}
return {};
@ -1551,6 +1556,9 @@ bool DetailsDialog::Impl::onPeerViewQueryTooltip(int x, int y, bool keyboard_tip
case 'T':
s = _("Peer is connected over µTP");
break;
default:
g_assert_not_reached();
}
if (s != nullptr)
@ -1910,6 +1918,9 @@ void appendAnnounceInfo(tr_tracker_view const& tracker, time_t const now, Gtk::T
_("Asking for more peers now… <small>%s</small>"),
tr_strltime_rounded(now - tracker.lastAnnounceStartTime));
break;
default:
g_assert_not_reached();
}
}
@ -1966,6 +1977,9 @@ void appendScrapeInfo(tr_tracker_view const& tracker, time_t const now, Gtk::Tex
_("Asking for peer counts now… <small>%s</small>"),
tr_strltime_rounded(now - tracker.lastScrapeStartTime));
break;
default:
g_assert_not_reached();
}
}
@ -2189,7 +2203,7 @@ void DetailsDialog::Impl::onBackupToggled()
refresh();
}
void DetailsDialog::Impl::on_edit_trackers_response(int response, Gtk::Dialog* dialog)
void DetailsDialog::Impl::on_edit_trackers_response(int response, std::shared_ptr<Gtk::Dialog>& dialog)
{
bool do_destroy = true;
@ -2242,7 +2256,7 @@ void DetailsDialog::Impl::on_edit_trackers_response(int response, Gtk::Dialog* d
if (do_destroy)
{
delete dialog;
dialog.reset();
}
}
@ -2287,13 +2301,13 @@ void DetailsDialog::Impl::on_edit_trackers()
guint row;
int const torrent_id = tr_torrentId(tor);
auto* d = new Gtk::Dialog(
auto d = std::make_shared<Gtk::Dialog>(
gtr_sprintf(_("%s - Edit Trackers"), tr_torrentName(tor)),
dialog_,
Gtk::DIALOG_MODAL | Gtk::DIALOG_DESTROY_WITH_PARENT);
d->add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
d->add_button(_("_Save"), Gtk::RESPONSE_ACCEPT);
d->signal_response().connect([this, d](int response) { on_edit_trackers_response(response, d); });
d->signal_response().connect([this, d](int response) mutable { on_edit_trackers_response(response, d); });
row = 0;
auto* t = Gtk::make_managed<HigWorkarea>();
@ -2338,7 +2352,7 @@ void DetailsDialog::Impl::on_tracker_list_selection_changed()
edit_trackers_button_->set_sensitive(tor != nullptr);
}
void DetailsDialog::Impl::on_add_tracker_response(int response, Gtk::Dialog* dialog)
void DetailsDialog::Impl::on_add_tracker_response(int response, std::shared_ptr<Gtk::Dialog>& dialog)
{
bool destroy = true;
@ -2378,7 +2392,7 @@ void DetailsDialog::Impl::on_add_tracker_response(int response, Gtk::Dialog* dia
if (destroy)
{
delete dialog;
dialog.reset();
}
}
@ -2390,13 +2404,13 @@ void DetailsDialog::Impl::on_tracker_list_add_button_clicked()
{
guint row;
auto* w = new Gtk::Dialog(
auto w = std::make_shared<Gtk::Dialog>(
gtr_sprintf(_("%s - Add Tracker"), tr_torrentName(tor)),
dialog_,
Gtk::DIALOG_DESTROY_WITH_PARENT);
w->add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
w->add_button(_("_Add"), Gtk::RESPONSE_ACCEPT);
w->signal_response().connect([this, w](int response) { on_add_tracker_response(response, w); });
w->signal_response().connect([this, w](int response) mutable { on_add_tracker_response(response, w); });
row = 0;
auto* t = Gtk::make_managed<HigWorkarea>();

View File

@ -14,6 +14,8 @@
#include <glibmm.h>
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class DetailsDialog : public Gtk::Dialog
@ -21,6 +23,8 @@ class DetailsDialog : public Gtk::Dialog
public:
~DetailsDialog() override;
TR_DISABLE_COPY_MOVE(DetailsDialog)
static std::unique_ptr<DetailsDialog> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
void set_torrents(std::vector<int> const& torrent_ids);

View File

@ -19,7 +19,7 @@
namespace
{
std::array<char const*, 4> image_types = { "ico", "png", "gif", "jpg" };
std::array<char const*, 4> const image_types = { "ico", "png", "gif", "jpg" };
struct favicon_data
{
@ -73,37 +73,30 @@ Glib::RefPtr<Gdk::Pixbuf> favicon_load_from_cache(std::string const& host)
}
}
void favicon_web_done_cb(tr_session*, bool, bool, long, std::string_view, void*);
void favicon_web_done_cb(tr_session*, bool, bool, long, std::string_view, gpointer);
bool favicon_web_done_idle_cb(favicon_data* fav)
bool favicon_web_done_idle_cb(std::unique_ptr<favicon_data> fav)
{
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
bool finished = false;
if (!fav->contents.empty()) /* we got something... try to make a pixbuf from it */
{
favicon_save_to_cache(fav->host, fav->contents);
pixbuf = favicon_load_from_cache(fav->host);
finished = pixbuf != nullptr;
}
if (!finished) /* no pixbuf yet... */
if (pixbuf == nullptr && ++fav->type < image_types.size()) /* keep trying */
{
if (++fav->type == image_types.size()) /* failure */
{
finished = true;
}
else /* keep trying */
{
fav->contents.clear();
tr_webRun(fav->session, get_url(fav->host, fav->type).c_str(), favicon_web_done_cb, fav);
}
fav->contents.clear();
auto* const session = fav->session;
auto const next_url = get_url(fav->host, fav->type);
tr_webRun(session, next_url.c_str(), favicon_web_done_cb, fav.release());
}
if (finished)
// Not released into the next web request, means we're done trying (even if `pixbuf` is still invalid)
if (fav != nullptr)
{
fav->func(pixbuf);
delete fav;
}
return false;
@ -115,12 +108,12 @@ void favicon_web_done_cb(
bool /*did_timeout*/,
long /*code*/,
std::string_view data,
void* vfav)
gpointer vfav)
{
auto* fav = static_cast<favicon_data*>(vfav);
fav->contents.assign(std::data(data), std::size(data));
Glib::signal_idle().connect([fav]() { return favicon_web_done_idle_cb(fav); });
Glib::signal_idle().connect([fav]() { return favicon_web_done_idle_cb(std::unique_ptr<favicon_data>(fav)); });
}
} // namespace
@ -138,12 +131,12 @@ void gtr_get_favicon(
}
else
{
auto* data = new favicon_data();
auto data = std::make_unique<favicon_data>();
data->session = session;
data->func = pixbuf_ready_func;
data->host = host;
tr_webRun(session, get_url(host, 0).c_str(), favicon_web_done_cb, data);
tr_webRun(session, get_url(host, 0).c_str(), favicon_web_done_cb, data.release());
}
}

View File

@ -24,11 +24,11 @@
#include "Session.h"
#include "Utils.h"
#define TR_COLUMN_ID_KEY "tr-model-column-id-key"
namespace
{
auto const ColumnIdKey = Glib::Quark("tr-model-column-id-key");
enum
{
/* these two fields could be any number at all so long as they're not
@ -76,6 +76,8 @@ public:
Impl(FileList& widget, Glib::RefPtr<Session> const& core, int torrent_id);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
void set_torrent(int torrent_id);
private:
@ -423,7 +425,7 @@ void buildTree(FileRowNode& node, build_data& build)
auto& child_data = node.data();
bool const isLeaf = node.child_count() == 0;
auto const mime_type = isLeaf ? gtr_get_mime_type_from_filename(child_data.name) : DIRECTORY_MIME_TYPE;
auto const mime_type = isLeaf ? gtr_get_mime_type_from_filename(child_data.name) : DirectoryMimeType;
auto const icon = gtr_get_mime_type_icon(mime_type, Gtk::ICON_SIZE_MENU, *build.w);
auto const file = isLeaf ? tr_torrentFile(build.tor, child_data.index) : tr_file_view{};
int const priority = isLeaf ? file.priority : 0;
@ -637,7 +639,7 @@ bool FileList::Impl::onViewPathToggled(Gtk::TreeViewColumn* col, Gtk::TreeModel:
bool handled = false;
auto const cid = GPOINTER_TO_INT(col->get_data(TR_COLUMN_ID_KEY));
auto const cid = GPOINTER_TO_INT(col->get_data(ColumnIdKey));
auto* tor = core_->find_torrent(torrent_id_);
if (tor != nullptr && (cid == file_cols.priority.index() || cid == file_cols.enabled.index()))
@ -725,7 +727,7 @@ struct rename_data
{
Glib::ustring newname;
Glib::ustring path_string;
void* impl;
gpointer impl;
};
bool FileList::Impl::on_rename_done_idle(Glib::ustring const& path_string, Glib::ustring const& newname, int error)
@ -735,7 +737,7 @@ bool FileList::Impl::on_rename_done_idle(Glib::ustring const& path_string, Glib:
if (auto const iter = store_->get_iter(path_string); iter)
{
bool const isLeaf = iter->children().empty();
auto const mime_type = isLeaf ? gtr_get_mime_type_from_filename(newname) : DIRECTORY_MIME_TYPE;
auto const mime_type = isLeaf ? gtr_get_mime_type_from_filename(newname) : DirectoryMimeType;
auto const icon = gtr_get_mime_type_icon(mime_type, Gtk::ICON_SIZE_MENU, *view_);
(*iter)[file_cols.label] = newname;
@ -795,7 +797,7 @@ void FileList::Impl::cell_edited_callback(Glib::ustring const& path_string, Glib
}
/* do the renaming */
auto* rename_data = new struct rename_data();
auto rename_data = std::make_unique<struct rename_data>();
rename_data->newname = newname;
rename_data->impl = this;
rename_data->path_string = path_string;
@ -804,14 +806,14 @@ void FileList::Impl::cell_edited_callback(Glib::ustring const& path_string, Glib
oldpath.c_str(),
newname.c_str(),
static_cast<tr_torrent_rename_done_func>(
[](tr_torrent* /*tor*/, char const* /*oldpath*/, char const* /*newname*/, int error, void* data)
[](tr_torrent* /*tor*/, char const* /*oldpath*/, char const* /*newname*/, int error, gpointer data)
{
Glib::signal_idle().connect(
[rdata = std::shared_ptr<struct rename_data>(static_cast<struct rename_data*>(data)), error]() {
return static_cast<Impl*>(rdata->impl)->on_rename_done_idle(rdata->path_string, rdata->newname, error);
});
}),
rename_data);
rename_data.release());
}
FileList::FileList(Glib::RefPtr<Session> const& core, int torrent_id)
@ -902,7 +904,7 @@ FileList::Impl::Impl(FileList& widget, Glib::RefPtr<Session> const& core, int to
width += 30; /* room for the sort indicator */
auto* rend = Gtk::make_managed<Gtk::CellRendererToggle>();
auto* col = Gtk::make_managed<Gtk::TreeViewColumn>(title, *rend);
col->set_data(TR_COLUMN_ID_KEY, GINT_TO_POINTER(file_cols.enabled.index()));
col->set_data(ColumnIdKey, GINT_TO_POINTER(file_cols.enabled.index()));
col->set_fixed_width(width);
col->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
col->set_cell_data_func(*rend, sigc::ptr_fun(&renderDownload));
@ -921,7 +923,7 @@ FileList::Impl::Impl(FileList& widget, Glib::RefPtr<Session> const& core, int to
rend->property_xalign() = 0.5F;
rend->property_yalign() = 0.5F;
auto* col = Gtk::make_managed<Gtk::TreeViewColumn>(title, *rend);
col->set_data(TR_COLUMN_ID_KEY, GINT_TO_POINTER(file_cols.priority.index()));
col->set_data(ColumnIdKey, GINT_TO_POINTER(file_cols.priority.index()));
col->set_fixed_width(width);
col->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
col->set_sort_column(file_cols.priority);

View File

@ -12,6 +12,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class FileList : public Gtk::ScrolledWindow
@ -20,6 +22,8 @@ public:
FileList(Glib::RefPtr<Session> const& core, int torrent_id);
~FileList() override;
TR_DISABLE_COPY_MOVE(FileList)
void clear();
void set_torrent(int torrent_id);

View File

@ -28,7 +28,6 @@ namespace
auto const DIRTY_KEY = Glib::Quark("tr-filter-dirty-key");
auto const SESSION_KEY = Glib::Quark("tr-session-key");
auto const TEXT_KEY = Glib::Quark("tr-filter-text-key");
auto const TORRENT_MODEL_KEY = Glib::Quark("tr-filter-torrent-model-key");
} // namespace
@ -39,6 +38,8 @@ public:
Impl(FilterBar& widget, tr_session* session, Glib::RefPtr<Gtk::TreeModel> const& torrent_model);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
Glib::RefPtr<Gtk::TreeModel> get_filter_model() const;
private:
@ -72,6 +73,8 @@ private:
sigc::connection torrent_model_row_changed_tag_;
sigc::connection torrent_model_row_inserted_tag_;
sigc::connection torrent_model_row_deleted_cb_tag_;
Glib::ustring filter_text_;
};
/***
@ -611,23 +614,23 @@ Gtk::ComboBox* FilterBar::Impl::activity_combo_box_new(Glib::RefPtr<Gtk::TreeMod
namespace
{
bool testText(tr_torrent const* tor, Glib::ustring const* key)
bool testText(tr_torrent const* tor, Glib::ustring const& key)
{
bool ret = false;
if (key == nullptr || key->empty())
if (key.empty())
{
ret = true;
}
else
{
/* test the torrent name... */
ret = Glib::ustring(tr_torrentName(tor)).casefold().find(*key) != Glib::ustring::npos;
ret = Glib::ustring(tr_torrentName(tor)).casefold().find(key) != Glib::ustring::npos;
/* test the files... */
for (tr_file_index_t i = 0, n = tr_torrentFileCount(tor); i < n && !ret; ++i)
{
ret = Glib::ustring(tr_torrentFile(tor, i).name).casefold().find(*key) != Glib::ustring::npos;
ret = Glib::ustring(tr_torrentFile(tor, i).name).casefold().find(key) != Glib::ustring::npos;
}
}
@ -638,10 +641,7 @@ bool testText(tr_torrent const* tor, Glib::ustring const* key)
void FilterBar::Impl::filter_entry_changed()
{
filter_model_->set_data(
TEXT_KEY,
new Glib::ustring(gtr_str_strip(entry_->get_text().casefold())),
[](void* p) { delete static_cast<Glib::ustring*>(p); });
filter_text_ = gtr_str_strip(entry_->get_text().casefold());
filter_model_->refilter();
}
@ -654,10 +654,9 @@ void FilterBar::Impl::filter_entry_changed()
bool FilterBar::Impl::is_row_visible(Gtk::TreeModel::const_iterator const& iter)
{
auto* tor = static_cast<tr_torrent*>(iter->get_value(torrent_cols.torrent));
auto const* text = static_cast<Glib::ustring const*>(filter_model_->get_data(TEXT_KEY));
return tor != nullptr && test_tracker(tor, active_tracker_type_, active_tracker_host_) &&
test_torrent_activity(tor, active_activity_type_) && testText(tor, text);
test_torrent_activity(tor, active_activity_type_) && testText(tor, filter_text_);
}
void FilterBar::Impl::selection_changed_cb()

View File

@ -12,6 +12,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
typedef struct tr_session tr_session;
class FilterBar : public Gtk::Box
@ -20,6 +22,8 @@ public:
FilterBar(tr_session* session, Glib::RefPtr<Gtk::TreeModel> const& torrent_model);
~FilterBar() override;
TR_DISABLE_COPY_MOVE(FilterBar)
Glib::RefPtr<Gtk::TreeModel> get_filter_model() const;
private:

View File

@ -20,6 +20,8 @@ public:
Impl(FreeSpaceLabel& label, Glib::RefPtr<Session> const& core, std::string const& dir);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
void set_dir(std::string const& dir);
private:

View File

@ -12,6 +12,8 @@
#include <glibmm.h>
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class FreeSpaceLabel : public Gtk::Label
@ -20,6 +22,8 @@ public:
FreeSpaceLabel(Glib::RefPtr<Session> const& core, std::string const& dir = {});
~FreeSpaceLabel() override;
TR_DISABLE_COPY_MOVE(FreeSpaceLabel)
void set_dir(std::string const& dir);
private:

View File

@ -10,6 +10,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
/**
*** utility code for making dialog layout that follows the Gnome HIG.
*** see section 8.2.2, Visual Design > Window Layout > Dialogs.
@ -20,6 +22,8 @@ class HigWorkarea : public Gtk::Grid
public:
HigWorkarea();
TR_DISABLE_COPY_MOVE(HigWorkarea)
void add_section_divider(guint& row);
void add_section_title_widget(guint& row, Gtk::Widget& w);
void add_section_title(guint& row, Glib::ustring const& section_title);

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())

View File

@ -11,8 +11,8 @@
#include <gtkmm.h>
#define DIRECTORY_MIME_TYPE "folder"
#define UNKNOWN_MIME_TYPE "unknown"
extern Glib::ustring const DirectoryMimeType;
extern Glib::ustring const UnknownMimeType;
Glib::ustring gtr_get_mime_type_from_filename(std::string const& file);

View File

@ -43,6 +43,8 @@ public:
Impl(MainWindow& window, Glib::RefPtr<Gio::ActionGroup> const& actions, Glib::RefPtr<Session> const& core);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
Glib::RefPtr<Gtk::TreeSelection> get_selection() const;
void refresh();
@ -142,7 +144,7 @@ Gtk::TreeView* MainWindow::Impl::makeview(Glib::RefPtr<Gtk::TreeModel> const& mo
selection_ = view->get_selection();
column_ = new Gtk::TreeViewColumn();
column_ = Gtk::make_managed<Gtk::TreeViewColumn>();
column_->set_title(_("Torrent"));
column_->set_resizable(true);
column_->set_sizing(Gtk::TREE_VIEW_COLUMN_FIXED);
@ -594,7 +596,7 @@ MainWindow::Impl::Impl(MainWindow& window, Glib::RefPtr<Gio::ActionGroup> const&
tr_sessionSetAltSpeedFunc(
core_->get_session(),
[](tr_session* /*s*/, bool /*isEnabled*/, bool /*byUser*/, void* p)
[](tr_session* /*s*/, bool /*isEnabled*/, bool /*byUser*/, gpointer p)
{ Glib::signal_idle().connect_once([p]() { static_cast<Impl*>(p)->onAltSpeedToggledIdle(); }); },
this);

View File

@ -27,6 +27,8 @@
#include <glibmm.h>
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class MainWindow : public Gtk::ApplicationWindow
@ -34,6 +36,8 @@ class MainWindow : public Gtk::ApplicationWindow
public:
~MainWindow() override;
TR_DISABLE_COPY_MOVE(MainWindow)
static std::unique_ptr<MainWindow> create(
Gtk::Application& app,
Glib::RefPtr<Gio::ActionGroup> const& actions,

View File

@ -19,11 +19,11 @@
#include "Session.h"
#include "Utils.h"
#define FILE_CHOSEN_KEY "file-is-chosen"
namespace
{
auto const FileChosenKey = Glib::Quark("file-is-chosen");
class MakeProgressDialog : public Gtk::Dialog
{
public:
@ -34,6 +34,8 @@ public:
Glib::RefPtr<Session> const& core);
~MakeProgressDialog() override;
TR_DISABLE_COPY_MOVE(MakeProgressDialog)
private:
bool onProgressDialogRefresh();
void onProgressDialogResponse(int response);
@ -57,6 +59,8 @@ class MakeDialog::Impl
public:
Impl(MakeDialog& dialog, Glib::RefPtr<Session> const& core);
TR_DISABLE_COPY_MOVE(Impl)
private:
void onSourceToggled2(Gtk::ToggleButton* tb, Gtk::FileChooserButton* chooser);
void onChooserChosen(Gtk::FileChooserButton* chooser);
@ -361,7 +365,7 @@ void MakeDialog::Impl::setFilename(std::string const& filename)
void MakeDialog::Impl::onChooserChosen(Gtk::FileChooserButton* chooser)
{
chooser->set_data(FILE_CHOSEN_KEY, GINT_TO_POINTER(true));
chooser->set_data(FileChosenKey, GINT_TO_POINTER(true));
setFilename(chooser->get_filename());
}
@ -369,7 +373,7 @@ void MakeDialog::Impl::onSourceToggled2(Gtk::ToggleButton* tb, Gtk::FileChooserB
{
if (tb->get_active())
{
if (chooser->get_data(FILE_CHOSEN_KEY) != nullptr)
if (chooser->get_data(FileChosenKey) != nullptr)
{
onChooserChosen(chooser);
}

View File

@ -12,6 +12,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class MakeDialog : public Gtk::Dialog
@ -19,6 +21,8 @@ class MakeDialog : public Gtk::Dialog
public:
~MakeDialog() override;
TR_DISABLE_COPY_MOVE(MakeDialog)
static std::unique_ptr<MakeDialog> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
protected:

View File

@ -49,12 +49,14 @@ public:
Impl(MessageLogWindow& window, Glib::RefPtr<Session> const& core);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
private:
bool onRefresh();
void onSaveRequest();
void onSaveDialogResponse(Gtk::FileChooserDialog* d, int response);
void doSave(Gtk::Window* parent, Glib::ustring const& filename);
void onSaveDialogResponse(std::shared_ptr<Gtk::FileChooserDialog>& d, int response);
void doSave(Gtk::Window& parent, Glib::ustring const& filename);
void onClearRequest();
void onPauseToggled(Gtk::ToggleToolButton* w);
@ -162,20 +164,20 @@ Glib::ustring gtr_asctime(time_t t)
} // namespace
void MessageLogWindow::Impl::doSave(Gtk::Window* parent, Glib::ustring const& filename)
void MessageLogWindow::Impl::doSave(Gtk::Window& parent, Glib::ustring const& filename)
{
auto* fp = fopen(filename.c_str(), "w+");
if (fp == nullptr)
{
auto* w = new Gtk::MessageDialog(
*parent,
auto w = std::make_shared<Gtk::MessageDialog>(
parent,
gtr_sprintf(_("Couldn't save \"%s\""), filename),
false,
Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_CLOSE);
w->set_secondary_text(Glib::strerror(errno));
w->signal_response().connect([w](int /*response*/) { delete w; });
w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
w->show();
}
else
@ -215,23 +217,23 @@ void MessageLogWindow::Impl::doSave(Gtk::Window* parent, Glib::ustring const& fi
}
}
void MessageLogWindow::Impl::onSaveDialogResponse(Gtk::FileChooserDialog* d, int response)
void MessageLogWindow::Impl::onSaveDialogResponse(std::shared_ptr<Gtk::FileChooserDialog>& d, int response)
{
if (response == Gtk::RESPONSE_ACCEPT)
{
doSave(d, d->get_filename());
doSave(*d, d->get_filename());
}
delete d;
d.reset();
}
void MessageLogWindow::Impl::onSaveRequest()
{
auto* d = new Gtk::FileChooserDialog(window_, _("Save Log"), Gtk::FILE_CHOOSER_ACTION_SAVE);
auto d = std::make_shared<Gtk::FileChooserDialog>(window_, _("Save Log"), Gtk::FILE_CHOOSER_ACTION_SAVE);
d->add_button(_("_Cancel"), Gtk::RESPONSE_CANCEL);
d->add_button(_("_Save"), Gtk::RESPONSE_ACCEPT);
d->signal_response().connect([this, d](int response) { onSaveDialogResponse(d, response); });
d->signal_response().connect([this, d](int response) mutable { onSaveDialogResponse(d, response); });
d->show();
}

View File

@ -12,6 +12,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class MessageLogWindow : public Gtk::Window
@ -19,6 +21,8 @@ class MessageLogWindow : public Gtk::Window
public:
~MessageLogWindow() override;
TR_DISABLE_COPY_MOVE(MessageLogWindow)
static std::unique_ptr<MessageLogWindow> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
protected:

View File

@ -17,9 +17,7 @@
#include "Session.h"
#include "Utils.h"
#define NOTIFICATIONS_DBUS_NAME "org.freedesktop.Notifications"
#define NOTIFICATIONS_DBUS_CORE_OBJECT "/org/freedesktop/Notifications"
#define NOTIFICATIONS_DBUS_CORE_INTERFACE "org.freedesktop.Notifications"
using namespace std::literals;
using StringVariantType = Glib::Variant<Glib::ustring>;
using StringListVariantType = Glib::Variant<std::vector<Glib::ustring>>;
@ -28,6 +26,10 @@ using UInt32VariantType = Glib::Variant<guint32>;
namespace
{
auto const NotificationsDbusName = Glib::ustring("org.freedesktop.Notifications"s);
auto const NotificationsDbusCoreObject = Glib::ustring("/org/freedesktop/Notifications"s);
auto const NotificationsDbusCoreInterface = Glib::ustring("org.freedesktop.Notifications"s);
struct TrNotification
{
Glib::RefPtr<Session> core;
@ -122,7 +124,7 @@ void dbus_proxy_ready_callback(Glib::RefPtr<Gio::AsyncResult>& res)
if (proxy == nullptr)
{
g_warning("Failed to create proxy for %s", NOTIFICATIONS_DBUS_NAME);
g_warning("Failed to create proxy for %s", NotificationsDbusName.c_str());
return;
}
@ -136,9 +138,9 @@ void gtr_notify_init()
{
Gio::DBus::Proxy::create_for_bus(
Gio::DBus::BUS_TYPE_SESSION,
NOTIFICATIONS_DBUS_NAME,
NOTIFICATIONS_DBUS_CORE_OBJECT,
NOTIFICATIONS_DBUS_CORE_INTERFACE,
NotificationsDbusName,
NotificationsDbusCoreObject,
NotificationsDbusCoreInterface,
&dbus_proxy_ready_callback,
{},
Gio::DBus::PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES);

View File

@ -31,13 +31,13 @@
namespace
{
#define N_RECENT 4
auto const MaxRecentDestinations = size_t{ 4 };
std::list<std::string> get_recent_destinations()
{
std::list<std::string> list;
for (int i = 0; i < N_RECENT; ++i)
for (size_t i = 0; i < MaxRecentDestinations; ++i)
{
auto const key = gtr_sprintf("recent-download-dir-%d", i + 1);
@ -65,8 +65,8 @@ void save_recent_destination(Glib::RefPtr<Session> const& core, std::string cons
/* add it to the front of the list */
list.push_front(dir);
/* save the first N_RECENT directories */
list.resize(N_RECENT);
/* save the first MaxRecentDestinations directories */
list.resize(MaxRecentDestinations);
int i = 0;
for (auto const& d : list)
{
@ -88,6 +88,8 @@ class OptionsDialog::Impl
public:
Impl(OptionsDialog& dialog, Glib::RefPtr<Session> const& core, std::unique_ptr<tr_ctor, void (*)(tr_ctor*)> ctor);
TR_DISABLE_COPY_MOVE(Impl)
private:
void sourceChanged(Gtk::FileChooserButton* b);
void downloadDirChanged(Gtk::FileChooserButton* b);

View File

@ -12,12 +12,16 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
typedef struct tr_ctor tr_ctor;
class TorrentUrlChooserDialog : public Gtk::Dialog
{
public:
TR_DISABLE_COPY_MOVE(TorrentUrlChooserDialog)
static std::unique_ptr<TorrentUrlChooserDialog> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
protected:
@ -30,6 +34,8 @@ private:
class TorrentFileChooserDialog : public Gtk::FileChooserDialog
{
public:
TR_DISABLE_COPY_MOVE(TorrentFileChooserDialog)
static std::unique_ptr<TorrentFileChooserDialog> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
protected:
@ -44,6 +50,8 @@ class OptionsDialog : public Gtk::Dialog
public:
~OptionsDialog() override;
TR_DISABLE_COPY_MOVE(OptionsDialog)
static std::unique_ptr<OptionsDialog> create(
Gtk::Window& parent,
Glib::RefPtr<Session> const& core,

View File

@ -38,8 +38,6 @@
#include "PrefsDialog.h"
#include "Utils.h"
#define MY_CONFIG_NAME "transmission"
using namespace std::literals;
std::string gl_confdir;
@ -133,7 +131,7 @@ static tr_variant* getPrefs()
{
tr_variantInitDict(&settings, 0);
tr_prefs_init_defaults(&settings);
tr_sessionLoadSettings(&settings, gl_confdir.c_str(), MY_CONFIG_NAME);
tr_sessionLoadSettings(&settings, gl_confdir.c_str(), nullptr);
ensure_sound_cmd_is_a_list(&settings);
loaded = true;
}

View File

@ -36,6 +36,8 @@ public:
Impl(PrefsDialog& dialog, Glib::RefPtr<Session> const& core);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
private:
Gtk::Widget* speedPage();
Gtk::Widget* downloadingPage();
@ -92,12 +94,12 @@ Gtk::CheckButton* new_check_button(Glib::ustring const& mnemonic, tr_quark const
return w;
}
#define IDLE_DATA "idle-data"
auto const IdleDataKey = Glib::Quark("idle-data");
bool spun_cb_idle(Gtk::SpinButton* spin, tr_quark const key, Glib::RefPtr<Session> const& core, bool isDouble)
{
bool keep_waiting = true;
auto* last_change = static_cast<Glib::Timer*>(spin->get_data(IDLE_DATA));
auto* last_change = static_cast<Glib::Timer*>(spin->get_data(IdleDataKey));
/* has the user stopped making changes? */
if (last_change->elapsed() > 0.33)
@ -115,7 +117,7 @@ bool spun_cb_idle(Gtk::SpinButton* spin, tr_quark const key, Glib::RefPtr<Sessio
}
/* cleanup */
spin->set_data(IDLE_DATA, nullptr);
spin->set_data(IdleDataKey, nullptr);
keep_waiting = false;
spin->unreference();
}
@ -127,12 +129,12 @@ void spun_cb(Gtk::SpinButton* w, tr_quark const key, Glib::RefPtr<Session> const
{
/* user may be spinning through many values, so let's hold off
for a moment to keep from flooding the core with changes */
auto* last_change = static_cast<Glib::Timer*>(w->get_data(IDLE_DATA));
auto* last_change = static_cast<Glib::Timer*>(w->get_data(IdleDataKey));
if (last_change == nullptr)
{
last_change = new Glib::Timer();
w->set_data(IDLE_DATA, last_change, [](void* p) { delete static_cast<Glib::Timer*>(p); });
w->set_data(IdleDataKey, last_change, [](gpointer p) { delete static_cast<Glib::Timer*>(p); });
w->reference();
Glib::signal_timeout().connect_seconds([w, key, core, isDouble]() { return spun_cb_idle(w, key, core, isDouble); }, 1);
}
@ -363,8 +365,11 @@ namespace
struct blocklist_data
{
blocklist_data() = default;
~blocklist_data();
TR_DISABLE_COPY_MOVE(blocklist_data)
sigc::connection updateBlocklistTag;
Gtk::Button* updateBlocklistButton = nullptr;
std::unique_ptr<Gtk::MessageDialog> updateBlocklistDialog;
@ -918,8 +923,11 @@ namespace
struct network_page_data
{
network_page_data() = default;
~network_page_data();
TR_DISABLE_COPY_MOVE(network_page_data)
Glib::RefPtr<Session> core;
Gtk::Label* portLabel = nullptr;
Gtk::Button* portButton = nullptr;

View File

@ -12,6 +12,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class PrefsDialog : public Gtk::Dialog
@ -19,6 +21,8 @@ class PrefsDialog : public Gtk::Dialog
public:
~PrefsDialog() override;
TR_DISABLE_COPY_MOVE(PrefsDialog)
static std::unique_ptr<PrefsDialog> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
protected:

View File

@ -32,6 +32,8 @@ public:
Impl(RelocateDialog& dialog, Glib::RefPtr<Session> const& core, std::vector<int> const& torrent_ids);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
private:
void onResponse(int response);
bool onTimer();

View File

@ -13,6 +13,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class RelocateDialog : public Gtk::Dialog
@ -20,6 +22,8 @@ class RelocateDialog : public Gtk::Dialog
public:
~RelocateDialog() override;
TR_DISABLE_COPY_MOVE(RelocateDialog)
static std::unique_ptr<RelocateDialog> create(
Gtk::Window& parent,
Glib::RefPtr<Session> const& core,

View File

@ -44,13 +44,31 @@
#include "Session.h"
#include "Utils.h"
using namespace std::literals;
namespace
{
using TrVariantPtr = std::shared_ptr<tr_variant>;
TrVariantPtr create_variant(tr_variant&& other)
{
auto result = TrVariantPtr(
tr_new0(tr_variant, 1),
[](tr_variant* ptr)
{
tr_variantFree(ptr);
tr_free(ptr);
});
*result = std::move(other);
tr_variantInitBool(&other, false);
return result;
}
class ScopedModelSortBlocker
{
public:
ScopedModelSortBlocker(Gtk::TreeSortable& model)
explicit ScopedModelSortBlocker(Gtk::TreeSortable& model)
: model_(model)
{
model_.get_sort_column_id(sort_column_id_, sort_type_);
@ -62,6 +80,8 @@ public:
model_.set_sort_column(sort_column_id_, sort_type_);
}
TR_DISABLE_COPY_MOVE(ScopedModelSortBlocker)
private:
Gtk::TreeSortable& model_;
int sort_column_id_ = -1;
@ -978,11 +998,11 @@ void Session::Impl::add_torrent(tr_torrent* tor, bool do_notify)
tr_torrentSetMetadataCallback(
tor,
[](auto* tor2, void* impl) { static_cast<Impl*>(impl)->on_torrent_metadata_changed(tor2); },
[](auto* tor2, gpointer impl) { static_cast<Impl*>(impl)->on_torrent_metadata_changed(tor2); },
this);
tr_torrentSetCompletenessCallback(
tor,
[](auto* tor2, auto completeness, bool was_running, void* impl)
[](auto* tor2, auto completeness, bool was_running, gpointer impl)
{ static_cast<Impl*>(impl)->on_torrent_completeness_changed(tor2, completeness, was_running); },
this);
}
@ -1438,13 +1458,13 @@ void Session::Impl::update()
*** Hibernate
**/
#define SESSION_MANAGER_SERVICE_NAME "org.gnome.SessionManager"
#define SESSION_MANAGER_INTERFACE "org.gnome.SessionManager"
#define SESSION_MANAGER_OBJECT_PATH "/org/gnome/SessionManager"
namespace
{
auto const SessionManagerServiceName = Glib::ustring("org.gnome.SessionManager"s);
auto const SessionManagerInterface = Glib::ustring("org.gnome.SessionManager"s);
auto const SessionManagerObjectPath = Glib::ustring("/org/gnome/SessionManager"s);
bool gtr_inhibit_hibernation(guint32& cookie)
{
bool success = false;
@ -1458,8 +1478,8 @@ bool gtr_inhibit_hibernation(guint32& cookie)
auto const connection = Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION);
auto response = connection->call_sync(
SESSION_MANAGER_OBJECT_PATH,
SESSION_MANAGER_INTERFACE,
SessionManagerObjectPath,
SessionManagerInterface,
"Inhibit",
Glib::VariantContainerBase::create_tuple({
Glib::Variant<Glib::ustring>::create(application),
@ -1467,7 +1487,7 @@ bool gtr_inhibit_hibernation(guint32& cookie)
Glib::Variant<Glib::ustring>::create(reason),
Glib::Variant<guint32>::create(flags),
}),
SESSION_MANAGER_SERVICE_NAME,
SessionManagerServiceName,
1000);
cookie = Glib::VariantBase::cast_dynamic<Glib::Variant<guint32>>(response.get_child(0)).get();
@ -1492,11 +1512,11 @@ void gtr_uninhibit_hibernation(guint inhibit_cookie)
auto const connection = Gio::DBus::Connection::get_sync(Gio::DBus::BUS_TYPE_SESSION);
connection->call_sync(
SESSION_MANAGER_OBJECT_PATH,
SESSION_MANAGER_INTERFACE,
SessionManagerObjectPath,
SessionManagerInterface,
"Uninhibit",
Glib::VariantContainerBase::create_tuple({ Glib::Variant<guint32>::create(inhibit_cookie) }),
SESSION_MANAGER_SERVICE_NAME,
SessionManagerServiceName,
1000);
/* logging */
@ -1601,19 +1621,17 @@ namespace
int64_t nextTag = 1;
typedef void (*server_response_func)(Session* core, tr_variant* response, gpointer user_data);
std::map<int64_t, std::function<void(tr_variant*)>> pendingRequests;
bool core_read_rpc_response_idle(tr_variant* response)
bool core_read_rpc_response_idle(TrVariantPtr const& response)
{
if (int64_t tag = 0; tr_variantDictFindInt(response, TR_KEY_tag, &tag))
if (int64_t tag = 0; tr_variantDictFindInt(response.get(), TR_KEY_tag, &tag))
{
if (auto const data_it = pendingRequests.find(tag); data_it != pendingRequests.end())
{
if (auto const& response_func = data_it->second; response_func)
{
response_func(response);
response_func(response.get());
}
pendingRequests.erase(data_it);
@ -1624,18 +1642,13 @@ bool core_read_rpc_response_idle(tr_variant* response)
}
}
tr_variantFree(response);
delete response;
return false;
}
void core_read_rpc_response(tr_session* /*session*/, tr_variant* response, void* /*user_data*/)
void core_read_rpc_response(tr_session* /*session*/, tr_variant* response, gpointer /*user_data*/)
{
auto* response_copy = new tr_variant(std::move(*response));
tr_variantInitBool(response, false);
Glib::signal_idle().connect([response_copy]() { return core_read_rpc_response_idle(response_copy); });
Glib::signal_idle().connect([response_copy = create_variant(std::move(*response))]() mutable
{ return core_read_rpc_response_idle(response_copy); });
}
} // namespace

View File

@ -30,10 +30,9 @@
#include <gtkmm.h>
#include <libtransmission/transmission.h>
#include <libtransmission/tr-macros.h>
#include <libtransmission/variant.h>
#define TR_RESOURCE_PATH "/com/transmissionbt/transmission/"
class Session : public Glib::Object
{
public:
@ -47,6 +46,8 @@ public:
public:
~Session() override;
TR_DISABLE_COPY_MOVE(Session)
static Glib::RefPtr<Session> create(tr_session* session);
tr_session* close();
@ -145,7 +146,7 @@ public:
sigc::signal<void(bool)>& signal_port_tested();
protected:
Session(tr_session* session);
explicit Session(tr_session* session);
private:
class Impl;
@ -162,7 +163,7 @@ public:
TorrentModelColumns();
Gtk::TreeModelColumn<Glib::ustring> name_collated;
Gtk::TreeModelColumn<void*> torrent;
Gtk::TreeModelColumn<gpointer> torrent;
Gtk::TreeModelColumn<int> torrent_id;
Gtk::TreeModelColumn<double> speed_up;
Gtk::TreeModelColumn<double> speed_down;

View File

@ -26,6 +26,8 @@ public:
Impl(StatsDialog& dialog, Glib::RefPtr<Session> const& core);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
private:
bool updateStats();
void dialogResponse(int response);

View File

@ -12,6 +12,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class StatsDialog : public Gtk::Dialog
@ -19,6 +21,8 @@ class StatsDialog : public Gtk::Dialog
public:
~StatsDialog() override;
TR_DISABLE_COPY_MOVE(StatsDialog)
static std::unique_ptr<StatsDialog> create(Gtk::Window& parent, Glib::RefPtr<Session> const& core);
protected:

View File

@ -26,7 +26,16 @@
#include "SystemTrayIcon.h"
#include "Utils.h"
#define ICON_NAME "transmission"
using namespace std::literals;
namespace
{
auto const TrayIconName = Glib::ustring("transmission-tray-icon"s);
auto const AppIconName = Glib::ustring("transmission"s);
auto const AppName = Glib::ustring("transmission-gtk"s);
} // namespace
class SystemTrayIcon::Impl
{
@ -34,6 +43,8 @@ public:
Impl(Gtk::Window& main_window, Glib::RefPtr<Session> const& core);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
void refresh();
private:
@ -142,24 +153,24 @@ void SystemTrayIcon::Impl::refresh()
namespace
{
std::string getIconName()
Glib::ustring getIconName()
{
std::string icon_name;
Glib::ustring icon_name;
auto theme = Gtk::IconTheme::get_default();
// if the tray's icon is a 48x48 file, use it.
// otherwise, use the fallback builtin icon.
if (!theme->has_icon(TRAY_ICON))
if (!theme->has_icon(TrayIconName))
{
icon_name = ICON_NAME;
icon_name = AppIconName;
}
else
{
auto const icon_info = theme->lookup_icon(TRAY_ICON, 48, Gtk::ICON_LOOKUP_USE_BUILTIN);
auto const icon_info = theme->lookup_icon(TrayIconName, 48, Gtk::ICON_LOOKUP_USE_BUILTIN);
bool const icon_is_builtin = icon_info.get_filename().empty();
icon_name = icon_is_builtin ? ICON_NAME : TRAY_ICON;
icon_name = icon_is_builtin ? AppIconName : TrayIconName;
}
return icon_name;
@ -188,7 +199,7 @@ SystemTrayIcon::Impl::Impl(Gtk::Window& main_window, Glib::RefPtr<Session> const
#ifdef HAVE_LIBAPPINDICATOR
indicator_ = app_indicator_new(ICON_NAME, icon_name.c_str(), APP_INDICATOR_CATEGORY_SYSTEM_SERVICES);
indicator_ = app_indicator_new(AppName.c_str(), icon_name.c_str(), APP_INDICATOR_CATEGORY_SYSTEM_SERVICES);
app_indicator_set_status(indicator_, APP_INDICATOR_STATUS_ACTIVE);
app_indicator_set_menu(indicator_, Glib::unwrap(menu_));
app_indicator_set_title(indicator_, Glib::get_application_name().c_str());

View File

@ -12,6 +12,8 @@
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
class Session;
class SystemTrayIcon
@ -20,6 +22,8 @@ public:
SystemTrayIcon(Gtk::Window& main_window, Glib::RefPtr<Session> const& core);
~SystemTrayIcon();
TR_DISABLE_COPY_MOVE(SystemTrayIcon)
void refresh();
private:

View File

@ -21,11 +21,6 @@
/* #define TEST_RTL */
#define DEFAULT_BAR_HEIGHT 12
#define SMALL_SCALE 0.9
#define COMPACT_ICON_SIZE Gtk::ICON_SIZE_MENU
#define FULL_ICON_SIZE Gtk::ICON_SIZE_DND
/***
****
***/
@ -33,6 +28,12 @@
namespace
{
auto const DefaultBarHeight = 12;
auto const CompactBarWidth = 50;
auto const SmallScale = 0.9;
auto const CompactIconSize = Gtk::ICON_SIZE_MENU;
auto const FullIconSize = Gtk::ICON_SIZE_DND;
Glib::ustring getProgressString(tr_torrent const* tor, uint64_t total_size, tr_stat const* st)
{
Glib::ustring gstr;
@ -307,6 +308,9 @@ Glib::ustring getStatusString(
st->peersGettingFromUs,
st->peersConnected);
break;
default:
g_assert_not_reached();
}
}
@ -333,9 +337,11 @@ Glib::ustring getStatusString(
class TorrentCellRenderer::Impl
{
public:
Impl(TorrentCellRenderer& renderer);
explicit Impl(TorrentCellRenderer& renderer);
~Impl();
TR_DISABLE_COPY_MOVE(Impl)
void get_size_compact(Gtk::Widget& widget, int& width, int& height) const;
void get_size_full(Gtk::Widget& widget, int& width, int& height) const;
@ -351,7 +357,7 @@ public:
Gtk::CellRendererState flags);
public:
Glib::Property<void*> torrent;
Glib::Property<gpointer> torrent;
Glib::Property<int> bar_height;
/* Use this instead of tr_stat.pieceUploadSpeed so that the model can
@ -386,17 +392,17 @@ Glib::RefPtr<Gdk::Pixbuf> get_icon(tr_torrent const* tor, Gtk::IconSize icon_siz
if (auto const n_files = tr_torrentFileCount(tor); n_files == 0)
{
mime_type = UNKNOWN_MIME_TYPE;
mime_type = UnknownMimeType;
}
else if (n_files > 1)
{
mime_type = DIRECTORY_MIME_TYPE;
mime_type = DirectoryMimeType;
}
else
{
auto const* const name = tr_torrentFile(tor, 0).name;
mime_type = strchr(name, '/') != nullptr ? DIRECTORY_MIME_TYPE : gtr_get_mime_type_from_filename(name);
mime_type = strchr(name, '/') != nullptr ? DirectoryMimeType : gtr_get_mime_type_from_filename(name);
}
return gtr_get_mime_type_icon(mime_type, icon_size, for_widget);
@ -420,7 +426,7 @@ void TorrentCellRenderer::Impl::get_size_compact(Gtk::Widget& widget, int& width
auto* const tor = static_cast<tr_torrent*>(torrent.get_value());
auto const* const st = tr_torrentStatCached(tor);
auto const icon = get_icon(tor, COMPACT_ICON_SIZE, widget);
auto const icon = get_icon(tor, CompactIconSize, widget);
auto const name = Glib::ustring(tr_torrentName(tor));
auto const gstr_stat = getShortStatusString(tor, st, upload_speed_KBps.get_value(), download_speed_KBps.get_value());
renderer_.get_padding(xpad, ypad);
@ -433,16 +439,14 @@ void TorrentCellRenderer::Impl::get_size_compact(Gtk::Widget& widget, int& width
text_renderer_->property_scale() = 1.0;
text_renderer_->get_preferred_size(widget, min_size, name_size);
text_renderer_->property_text() = gstr_stat;
text_renderer_->property_scale() = SMALL_SCALE;
text_renderer_->property_scale() = SmallScale;
text_renderer_->get_preferred_size(widget, min_size, stat_size);
/**
*** LAYOUT
**/
#define BAR_WIDTH 50
width = xpad * 2 + icon_size.width + GUI_PAD + BAR_WIDTH + GUI_PAD + stat_size.width;
width = xpad * 2 + icon_size.width + GUI_PAD + CompactBarWidth + GUI_PAD + stat_size.width;
height = ypad * 2 + std::max(name_size.height, bar_height.get_value());
}
@ -460,7 +464,7 @@ void TorrentCellRenderer::Impl::get_size_full(Gtk::Widget& widget, int& width, i
auto const* const st = tr_torrentStatCached(tor);
auto const total_size = tr_torrentInfo(tor)->totalSize;
auto const icon = get_icon(tor, FULL_ICON_SIZE, widget);
auto const icon = get_icon(tor, FullIconSize, widget);
auto const name = Glib::ustring(tr_torrentName(tor));
auto const gstr_stat = getStatusString(tor, st, upload_speed_KBps.get_value(), download_speed_KBps.get_value());
auto const gstr_prog = getProgressString(tor, total_size, st);
@ -476,7 +480,7 @@ void TorrentCellRenderer::Impl::get_size_full(Gtk::Widget& widget, int& width, i
text_renderer_->get_preferred_size(widget, min_size, name_size);
text_renderer_->property_text() = gstr_prog;
text_renderer_->property_weight() = Pango::WEIGHT_NORMAL;
text_renderer_->property_scale() = SMALL_SCALE;
text_renderer_->property_scale() = SmallScale;
text_renderer_->get_preferred_size(widget, min_size, prog_size);
text_renderer_->property_text() = gstr_stat;
text_renderer_->get_preferred_size(widget, min_size, stat_size);
@ -592,7 +596,7 @@ void TorrentCellRenderer::Impl::render_compact(
auto const percentDone = get_percent_done(tor, st, &seed);
bool const sensitive = active || st->error;
auto const icon = get_icon(tor, COMPACT_ICON_SIZE, widget);
auto const icon = get_icon(tor, CompactIconSize, widget);
auto const name = Glib::ustring(tr_torrentName(tor));
auto const gstr_stat = getShortStatusString(tor, st, upload_speed_KBps.get_value(), download_speed_KBps.get_value());
renderer_.get_padding(xpad, ypad);
@ -610,12 +614,12 @@ void TorrentCellRenderer::Impl::render_compact(
icon_area.set_width(width);
auto prog_area = fill_area;
prog_area.set_width(BAR_WIDTH);
prog_area.set_width(CompactBarWidth);
auto stat_area = fill_area;
text_renderer_->property_text() = gstr_stat;
text_renderer_->property_ellipsize() = Pango::ELLIPSIZE_NONE;
text_renderer_->property_scale() = SMALL_SCALE;
text_renderer_->property_scale() = SmallScale;
text_renderer_->get_preferred_width(widget, min_width, width);
stat_area.set_width(width);
@ -652,7 +656,7 @@ void TorrentCellRenderer::Impl::render_compact(
progress_renderer_->render(cr, widget, prog_area, prog_area, flags);
text_renderer_->property_text() = gstr_stat;
text_renderer_->property_scale() = SMALL_SCALE;
text_renderer_->property_scale() = SmallScale;
text_renderer_->property_ellipsize() = Pango::ELLIPSIZE_END;
text_renderer_->property_foreground_rgba() = text_color;
text_renderer_->render(cr, widget, stat_area, stat_area, flags);
@ -683,7 +687,7 @@ void TorrentCellRenderer::Impl::render_full(
auto const percentDone = get_percent_done(tor, st, &seed);
bool const sensitive = active || st->error;
auto const icon = get_icon(tor, FULL_ICON_SIZE, widget);
auto const icon = get_icon(tor, FullIconSize, widget);
auto const name = Glib::ustring(tr_torrentName(tor));
auto const gstr_prog = getProgressString(tor, total_size, st);
auto const gstr_stat = getStatusString(tor, st, upload_speed_KBps.get_value(), download_speed_KBps.get_value());
@ -708,7 +712,7 @@ void TorrentCellRenderer::Impl::render_full(
Gdk::Rectangle prog_area;
text_renderer_->property_text() = gstr_prog;
text_renderer_->property_weight() = Pango::WEIGHT_NORMAL;
text_renderer_->property_scale() = SMALL_SCALE;
text_renderer_->property_scale() = SmallScale;
text_renderer_->get_preferred_size(widget, min_size, size);
prog_area.set_height(size.height);
@ -779,7 +783,7 @@ void TorrentCellRenderer::Impl::render_full(
text_renderer_->render(cr, widget, name_area, name_area, flags);
text_renderer_->property_text() = gstr_prog;
text_renderer_->property_scale() = SMALL_SCALE;
text_renderer_->property_scale() = SmallScale;
text_renderer_->property_weight() = Pango::WEIGHT_NORMAL;
text_renderer_->render(cr, widget, prog_area, prog_area, flags);
@ -840,7 +844,7 @@ TorrentCellRenderer::~TorrentCellRenderer() = default;
TorrentCellRenderer::Impl::Impl(TorrentCellRenderer& renderer)
: torrent(renderer, "torrent", nullptr)
, bar_height(renderer, "bar-height", DEFAULT_BAR_HEIGHT)
, bar_height(renderer, "bar-height", DefaultBarHeight)
, upload_speed_KBps(renderer, "piece-upload-speed", 0)
, download_speed_KBps(renderer, "piece-download-speed", 0)
, compact(renderer, "compact", false)
@ -854,7 +858,7 @@ TorrentCellRenderer::Impl::Impl(TorrentCellRenderer& renderer)
icon_renderer_ = Gtk::make_managed<Gtk::CellRendererPixbuf>();
}
Glib::PropertyProxy<void*> TorrentCellRenderer::property_torrent()
Glib::PropertyProxy<gpointer> TorrentCellRenderer::property_torrent()
{
return impl_->torrent.get_proxy();
}

View File

@ -13,6 +13,8 @@
#include <glibmm.h>
#include <gtkmm.h>
#include <libtransmission/tr-macros.h>
struct tr_torrent;
class TorrentCellRenderer : public Gtk::CellRenderer
@ -21,7 +23,9 @@ public:
TorrentCellRenderer();
~TorrentCellRenderer() override;
Glib::PropertyProxy<void*> property_torrent();
TR_DISABLE_COPY_MOVE(TorrentCellRenderer)
Glib::PropertyProxy<gpointer> property_torrent();
Glib::PropertyProxy<double> property_piece_upload_speed();
Glib::PropertyProxy<double> property_piece_download_speed();
Glib::PropertyProxy<int> property_bar_height();

View File

@ -28,27 +28,29 @@
#include "Session.h"
#include "Utils.h"
using namespace std::literals;
/***
**** UNITS
***/
int const mem_K = 1024;
char const* mem_K_str = N_("KiB");
char const* mem_M_str = N_("MiB");
char const* mem_G_str = N_("GiB");
char const* mem_T_str = N_("TiB");
char const* const mem_K_str = N_("KiB");
char const* const mem_M_str = N_("MiB");
char const* const mem_G_str = N_("GiB");
char const* const mem_T_str = N_("TiB");
int const disk_K = 1000;
char const* disk_K_str = N_("kB");
char const* disk_M_str = N_("MB");
char const* disk_G_str = N_("GB");
char const* disk_T_str = N_("TB");
char const* const disk_K_str = N_("kB");
char const* const disk_M_str = N_("MB");
char const* const disk_G_str = N_("GB");
char const* const disk_T_str = N_("TB");
int const speed_K = 1000;
char const* speed_K_str = N_("kB/s");
char const* speed_M_str = N_("MB/s");
char const* speed_G_str = N_("GB/s");
char const* speed_T_str = N_("TB/s");
char const* const speed_K_str = N_("kB/s");
char const* const speed_M_str = N_("MB/s");
char const* const speed_G_str = N_("GB/s");
char const* const speed_T_str = N_("TB/s");
/***
****
@ -239,9 +241,14 @@ void gtr_add_torrent_error_dialog(Gtk::Widget& child, int err, tr_torrent* dupli
secondary = gtr_sprintf(_("The torrent file \"%s\" encountered an unknown error."), filename);
}
auto* w = new Gtk::MessageDialog(*win, _("Error opening torrent"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
auto w = std::make_shared<Gtk::MessageDialog>(
*win,
_("Error opening torrent"),
false,
Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_CLOSE);
w->set_secondary_text(secondary);
w->signal_response().connect([w](int /*response*/) { delete w; });
w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
w->show_all();
}
@ -470,7 +477,7 @@ Gtk::ComboBox* gtr_priority_combo_new()
****
***/
#define GTR_CHILD_HIDDEN "gtr-child-hidden"
auto const ChildHiddenKey = Glib::Quark("gtr-child-hidden");
void gtr_widget_set_visible(Gtk::Widget& w, bool b)
{
@ -489,14 +496,14 @@ void gtr_widget_set_visible(Gtk::Widget& w, bool b)
continue;
}
if (b && l->get_data(GTR_CHILD_HIDDEN) != nullptr)
if (b && l->get_data(ChildHiddenKey) != nullptr)
{
l->steal_data(GTR_CHILD_HIDDEN);
l->steal_data(ChildHiddenKey);
gtr_widget_set_visible(*l, true);
}
else if (!b)
{
l->set_data(GTR_CHILD_HIDDEN, GINT_TO_POINTER(1));
l->set_data(ChildHiddenKey, GINT_TO_POINTER(1));
gtr_widget_set_visible(*l, false);
}
}
@ -524,7 +531,12 @@ void gtr_unrecognized_url_dialog(Gtk::Widget& parent, Glib::ustring const& url)
Glib::ustring gstr;
auto* w = new Gtk::MessageDialog(*window, _("Unrecognized URL"), false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_CLOSE);
auto w = std::make_shared<Gtk::MessageDialog>(
*window,
_("Unrecognized URL"),
false,
Gtk::MESSAGE_ERROR,
Gtk::BUTTONS_CLOSE);
gstr += gtr_sprintf(_("Transmission doesn't know how to use \"%s\""), url);
@ -538,7 +550,7 @@ void gtr_unrecognized_url_dialog(Gtk::Widget& parent, Glib::ustring const& url)
}
w->set_secondary_text(gstr);
w->signal_response().connect([w](int /*response*/) { delete w; });
w->signal_response().connect([w](int /*response*/) mutable { w.reset(); });
w->show();
}
@ -574,3 +586,9 @@ void gtr_label_set_text(Gtk::Label& lb, Glib::ustring const& newstr)
lb.set_text(newstr);
}
}
std::string gtr_get_full_resource_path(std::string const& rel_path)
{
static auto const BasePath = "/com/transmissionbt/transmission/"s;
return BasePath + rel_path;
}

View File

@ -9,6 +9,8 @@
#pragma once
#include <functional>
#include <string>
#include <sys/types.h>
#include <glibmm.h>
@ -18,22 +20,22 @@
#include <libtransmission/tr-macros.h>
extern int const mem_K;
extern char const* mem_K_str;
extern char const* mem_M_str;
extern char const* mem_G_str;
extern char const* mem_T_str;
extern char const* const mem_K_str;
extern char const* const mem_M_str;
extern char const* const mem_G_str;
extern char const* const mem_T_str;
extern int const disk_K;
extern char const* disk_K_str;
extern char const* disk_M_str;
extern char const* disk_G_str;
extern char const* disk_T_str;
extern char const* const disk_K_str;
extern char const* const disk_M_str;
extern char const* const disk_G_str;
extern char const* const disk_T_str;
extern int const speed_K;
extern char const* speed_K_str;
extern char const* speed_M_str;
extern char const* speed_G_str;
extern char const* speed_T_str;
extern char const* const speed_K_str;
extern char const* const speed_M_str;
extern char const* const speed_G_str;
extern char const* const speed_T_str;
enum
{
@ -139,6 +141,8 @@ inline T gtr_str_strip(T const& text)
return new_begin == T::npos ? T() : text.substr(new_begin, new_end == T::npos ? new_end : new_end - new_begin + 1);
}
std::string gtr_get_full_resource_path(std::string const& rel_path);
namespace gtr_detail
{

View File

@ -35,12 +35,13 @@
#include "Prefs.h"
#include "Utils.h"
#define MY_CONFIG_NAME "transmission"
#define MY_READABLE_NAME "transmission-gtk"
namespace
{
auto const* const AppConfigDirName = "transmission";
auto const* const AppTranslationDomainName = "transmission-gtk";
auto const* const AppName = "transmission-gtk";
Glib::OptionEntry create_option_entry(Glib::ustring const& long_name, gchar short_name, Glib::ustring const& description)
{
Glib::OptionEntry entry;
@ -56,16 +57,16 @@ int main(int argc, char** argv)
{
/* init i18n */
setlocale(LC_ALL, "");
bindtextdomain(MY_READABLE_NAME, TRANSMISSIONLOCALEDIR);
bind_textdomain_codeset(MY_READABLE_NAME, "UTF-8");
textdomain(MY_READABLE_NAME);
bindtextdomain(AppTranslationDomainName, TRANSMISSIONLOCALEDIR);
bind_textdomain_codeset(AppTranslationDomainName, "UTF-8");
textdomain(AppTranslationDomainName);
/* init glib/gtk */
Glib::init();
Glib::set_application_name(_("Transmission"));
/* default settings */
std::string config_dir = tr_getDefaultConfigDir(MY_CONFIG_NAME);
std::string config_dir;
bool show_version = false;
bool start_paused = false;
bool is_iconified = false;
@ -100,18 +101,21 @@ int main(int argc, char** argv)
/* handle the trivial "version" option */
if (show_version)
{
fprintf(stderr, "%s %s\n", MY_READABLE_NAME, LONG_VERSION_STRING);
fprintf(stderr, "%s %s\n", AppName, LONG_VERSION_STRING);
return 0;
}
Gtk::Window::set_default_icon_name(MY_CONFIG_NAME);
/* init the unit formatters */
tr_formatter_mem_init(mem_K, _(mem_K_str), _(mem_M_str), _(mem_G_str), _(mem_T_str));
tr_formatter_size_init(disk_K, _(disk_K_str), _(disk_M_str), _(disk_G_str), _(disk_T_str));
tr_formatter_speed_init(speed_K, _(speed_K_str), _(speed_M_str), _(speed_G_str), _(speed_T_str));
/* set up the config dir */
if (config_dir.empty())
{
config_dir = tr_getDefaultConfigDir(AppConfigDirName);
}
gtr_pref_init(config_dir);
g_mkdir_with_parents(config_dir.c_str(), 0755);

View File

@ -64,6 +64,18 @@
#define TR_UNLIKELY(x) (x)
#endif
#define TR_DISABLE_COPY(Class) \
Class(Class const&) = delete; \
Class& operator=(Class const&) = delete;
#define TR_DISABLE_MOVE(Class) \
Class(Class&&) = delete; \
Class& operator=(Class&&) = delete;
#define TR_DISABLE_COPY_MOVE(Class) \
TR_DISABLE_COPY(Class) \
TR_DISABLE_MOVE(Class)
/***
****
***/

View File

@ -10,8 +10,9 @@
#include <QPointer>
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Macros.h"
#include "ui_AboutDialog.h"
class LicenseDialog;

View File

@ -16,8 +16,9 @@
#include <QTimer>
#include <QTranslator>
#include <libtransmission/tr-macros.h>
#include "FaviconCache.h"
#include "Macros.h"
#include "Typedefs.h"
#include "Utils.h" // std::hash<QString>

View File

@ -12,7 +12,7 @@
#include <QSet>
#include <QTimer>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class QGridLayout;

View File

@ -15,8 +15,9 @@
#include <QSet>
#include <QTimer>
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Macros.h"
#include "Session.h"
#include "Typedefs.h"

View File

@ -15,7 +15,8 @@
#include <QPixmap>
#include <QString>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
#include "Utils.h" // std::hash<QString>
class QNetworkAccessManager;

View File

@ -10,7 +10,7 @@
#include <QItemDelegate>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class FileTreeDelegate : public QItemDelegate
{

View File

@ -17,7 +17,7 @@
#include <QString>
#include <QVariant>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class FileTreeItem
{

View File

@ -15,7 +15,7 @@
#include <QMap>
#include <QSet>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class FileTreeItem;

View File

@ -11,7 +11,8 @@
#include <QSet>
#include <QTreeView>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
#include "Torrent.h" // FileList
class QAction;

View File

@ -14,8 +14,9 @@
#include <QTimer>
#include <QWidget>
#include <libtransmission/tr-macros.h>
#include "FaviconCache.h"
#include "Macros.h"
#include "Torrent.h"
#include "Typedefs.h"

View File

@ -10,7 +10,7 @@
#include <QComboBox>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class FilterBarComboBox : public QComboBox
{

View File

@ -10,7 +10,7 @@
#include <QItemDelegate>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class QAbstractItemModel;
class QComboBox;

View File

@ -12,7 +12,7 @@
#include <QString>
#include <QTimer>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class Session;

View File

@ -10,7 +10,7 @@
#include <QToolButton>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class IconToolButton : public QToolButton
{

View File

@ -10,7 +10,7 @@
#include <QObject>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class InteropObject : public QObject
{

View File

@ -8,8 +8,9 @@
#pragma once
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Macros.h"
#include "ui_LicenseDialog.h"
class LicenseDialog : public BaseDialog

View File

@ -1,15 +0,0 @@
#pragma once
#include <QtGlobal>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 13, 0))
#define TR_DISABLE_MOVE(Class) Q_DISABLE_MOVE(Class)
#define TR_DISABLE_COPY_MOVE(Class) Q_DISABLE_COPY_MOVE(Class)
#else
#define TR_DISABLE_MOVE(Class) \
Class(Class&&) = delete; \
Class& operator=(Class&&) = delete;
#define TR_DISABLE_COPY_MOVE(Class) \
Q_DISABLE_COPY(Class) \
TR_DISABLE_MOVE(Class)
#endif

View File

@ -19,8 +19,9 @@
#include <QTimer>
#include <QWidgetList>
#include <libtransmission/tr-macros.h>
#include "Filters.h"
#include "Macros.h"
#include "Speed.h"
#include "TorrentFilter.h"
#include "Typedefs.h"

View File

@ -10,8 +10,9 @@
#include <memory>
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Macros.h"
#include "ui_MakeDialog.h"
class QAbstractButton;

View File

@ -16,9 +16,10 @@
#include <QString>
#include <QTimer>
#include <libtransmission/tr-macros.h>
#include "AddData.h" // AddData
#include "BaseDialog.h"
#include "Macros.h"
#include "Torrent.h" // FileList
#include "ui_OptionsDialog.h"

View File

@ -10,7 +10,7 @@
#include <QToolButton>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class PathButton : public QToolButton
{

View File

@ -16,9 +16,9 @@
#include <QVariant>
#include <libtransmission/quark.h>
#include <libtransmission/tr-macros.h>
#include "Filters.h"
#include "Macros.h"
class QDateTime;

View File

@ -10,8 +10,9 @@
#include <QMap>
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Macros.h"
#include "Prefs.h"
#include "ui_PrefsDialog.h"

View File

@ -8,8 +8,9 @@
#pragma once
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Macros.h"
#include "Typedefs.h"
#include "ui_RelocateDialog.h"

View File

@ -23,10 +23,9 @@
#include <libtransmission/transmission.h>
#include <libtransmission/quark.h>
#include <libtransmission/tr-macros.h>
#include <libtransmission/variant.h>
#include "Macros.h"
class QByteArray;
class QNetworkAccessManager;

View File

@ -18,7 +18,8 @@
#include <QPair>
#include <QQueue>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
#include "RpcClient.h"
class RpcQueue : public QObject

View File

@ -19,8 +19,8 @@
#include <libtransmission/transmission.h>
#include <libtransmission/quark.h>
#include <libtransmission/tr-macros.h>
#include "Macros.h"
#include "RpcClient.h"
#include "RpcQueue.h"
#include "Torrent.h"

View File

@ -10,8 +10,9 @@
#include <QWidgetList>
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "Macros.h"
#include "ui_SessionDialog.h"
class Prefs;

View File

@ -43,7 +43,7 @@
#include <QLabel>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class SqueezeLabel : public QLabel
{

View File

@ -8,12 +8,13 @@
#pragma once
#include "BaseDialog.h"
#include "Macros.h"
#include "ui_StatsDialog.h"
#include <QTimer>
#include <libtransmission/tr-macros.h>
#include "BaseDialog.h"
#include "ui_StatsDialog.h"
class Session;
class StatsDialog : public BaseDialog

View File

@ -21,10 +21,10 @@
#include <libtransmission/transmission.h>
#include <libtransmission/crypto-utils.h>
#include <libtransmission/quark.h>
#include <libtransmission/tr-macros.h>
#include "FaviconCache.h"
#include "IconCache.h"
#include "Macros.h"
#include "Speed.h"
#ifdef ERROR

View File

@ -12,7 +12,7 @@
#include <QStyledItemDelegate>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class QStyle;
class QStyleOptionProgressBar;

View File

@ -8,7 +8,8 @@
#pragma once
#include "Macros.h"
#include <libtransmission/tr-macros.h>
#include "TorrentDelegate.h"
class TorrentDelegateMin : public TorrentDelegate

View File

@ -13,8 +13,9 @@
#include <QSortFilterProxyModel>
#include <QTimer>
#include <libtransmission/tr-macros.h>
#include "Filters.h"
#include "Macros.h"
class QString;

View File

@ -13,7 +13,8 @@
#include <QAbstractListModel>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
#include "Torrent.h"
#include "Typedefs.h"

View File

@ -10,7 +10,7 @@
#include <QListView>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class TorrentView : public QListView
{

View File

@ -10,7 +10,7 @@
#include <QItemDelegate>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class QStyle;

View File

@ -12,7 +12,8 @@
#include <QAbstractListModel>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
#include "Torrent.h"
#include "Typedefs.h"

View File

@ -10,7 +10,7 @@
#include <QSortFilterProxyModel>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class TrackerModelFilter : public QSortFilterProxyModel
{

View File

@ -15,7 +15,7 @@
#include <QSet>
#include <QString>
#include "Macros.h"
#include <libtransmission/tr-macros.h>
class TorrentModel;