1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-30 19:46:56 +00:00

Remove unnecessary "id" member of TrNotification in gtk/notify.c (#851)

The "id" member's only purpose is to serve as the key for the
active_notifications hash table. However, the same thing can be very easily
achieved by switching the GHashTable's hash/equal functions to "direct", which
just use the void pointers (which all keys are in a GHashTable) directly as if
they were values, and use GUINT_TO_POINTER() when referring to this hash table's
key.

Co-authored-by: Mike Gelfand <mikedld@users.noreply.github.com>
This commit is contained in:
Daniel Kamil Kozar 2021-08-07 23:24:11 +02:00 committed by GitHub
parent a7370fe8fb
commit 79e8bc5c46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -24,7 +24,6 @@ static gboolean server_supports_actions = FALSE;
typedef struct TrNotification
{
guint id;
TrCore* core;
int torrent_id;
}
@ -89,7 +88,7 @@ static void g_signal_callback(GDBusProxy const* dbus_proxy, char const* sender_n
g_return_if_fail(g_variant_is_of_type(params, G_VARIANT_TYPE("(u*)")));
g_variant_get(params, "(u*)", &id, NULL);
n = g_hash_table_lookup(active_notifications, GINT_TO_POINTER((int*)&id));
n = g_hash_table_lookup(active_notifications, GUINT_TO_POINTER(id));
if (n == NULL)
{
@ -98,7 +97,7 @@ static void g_signal_callback(GDBusProxy const* dbus_proxy, char const* sender_n
if (g_strcmp0(signal_name, "NotificationClosed") == 0)
{
g_hash_table_remove(active_notifications, GINT_TO_POINTER((int*)&n->id));
g_hash_table_remove(active_notifications, GUINT_TO_POINTER(id));
}
else if (g_strcmp0(signal_name, "ActionInvoked") == 0 && g_variant_is_of_type(params, G_VARIANT_TYPE("(us)")))
{
@ -146,7 +145,7 @@ static void dbus_proxy_ready_callback(GObject* source, GAsyncResult* res, gpoint
void gtr_notify_init(void)
{
active_notifications = g_hash_table_new_full(g_int_hash, g_int_equal, NULL, tr_notification_free);
active_notifications = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, tr_notification_free);
g_dbus_proxy_new_for_bus(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, NULL, NOTIFICATIONS_DBUS_NAME,
NOTIFICATIONS_DBUS_CORE_OBJECT, NOTIFICATIONS_DBUS_CORE_INTERFACE, NULL, dbus_proxy_ready_callback, NULL);
}
@ -169,8 +168,9 @@ static void notify_callback(GObject* source, GAsyncResult* res, gpointer user_da
return;
}
g_variant_get(result, "(u)", &n->id);
g_hash_table_insert(active_notifications, GINT_TO_POINTER((int*)&n->id), n);
guint id;
g_variant_get(result, "(u)", &id);
g_hash_table_insert(active_notifications, GUINT_TO_POINTER(id), n);
g_variant_unref(result);
}
@ -227,7 +227,7 @@ void gtr_notify_torrent_completed(TrCore* core, int torrent_id)
g_variant_builder_init(&hints_builder, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add(&hints_builder, "{sv}", "category", g_variant_new_string("transfer.complete"));
g_dbus_proxy_call(proxy, "Notify", g_variant_new("(susssasa{sv}i)", "Transmission", n->id, "transmission",
g_dbus_proxy_call(proxy, "Notify", g_variant_new("(susssasa{sv}i)", "Transmission", 0, "transmission",
_("Torrent Complete"), tr_torrentName(tor), &actions_builder, &hints_builder, -1), G_DBUS_CALL_FLAGS_NONE, -1, NULL,
notify_callback, n);
}