static void impl_deactivate(PeasActivatable *activatable) { XmrMprisPlugin *plugin; plugin = XMR_MPRIS_PLUGIN(activatable); g_signal_handlers_disconnect_by_func(plugin->window, track_changed, plugin); g_signal_handlers_disconnect_by_func(plugin->player, player_tick, plugin); g_signal_handlers_disconnect_by_func(plugin->player, player_state_changed, plugin); if (plugin->root_id != 0) { g_dbus_connection_unregister_object(plugin->connection, plugin->root_id); plugin->root_id = 0; } if (plugin->player_id != 0) { g_dbus_connection_unregister_object(plugin->connection, plugin->player_id); plugin->player_id = 0; } if (plugin->name_own_id > 0) { g_bus_unown_name(plugin->name_own_id); plugin->name_own_id = 0; } if (plugin->connection != NULL) { g_object_unref(plugin->connection); plugin->connection = NULL; } if (plugin->current_song) { song_info_free(plugin->current_song); plugin->current_song = NULL; } g_object_unref(plugin->window); g_object_unref(plugin->player); }
static void impl_activate(PeasActivatable *activatable) { XmrMprisPlugin *plugin; GError *error = NULL; GDBusInterfaceInfo *ifaceinfo; plugin = XMR_MPRIS_PLUGIN(activatable); g_object_get(plugin, "object", &plugin->window, NULL); g_object_get(plugin->window, "player", &plugin->player, NULL); g_signal_connect(plugin->window, "track-changed", G_CALLBACK(track_changed), plugin); g_signal_connect(plugin->player, "tick", G_CALLBACK(player_tick), plugin); plugin->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { xmr_debug("Unable to connect to D-Bus session bus: %s", error->message); return ; } /* parse introspection data */ plugin->node_info = g_dbus_node_info_new_for_xml(mpris_introspection_xml, &error); if (error != NULL) { xmr_debug("Unable to read MPRIS interface specificiation: %s", error->message); return; } /* register root interface */ ifaceinfo = g_dbus_node_info_lookup_interface (plugin->node_info, MPRIS_ROOT_INTERFACE); plugin->root_id = g_dbus_connection_register_object(plugin->connection, MPRIS_OBJECT_NAME, ifaceinfo, &root_vtable, plugin, NULL, &error); if (error != NULL) { xmr_debug("unable to register MPRIS root interface: %s", error->message); g_error_free (error); } /* register player interface */ ifaceinfo = g_dbus_node_info_lookup_interface(plugin->node_info, MPRIS_PLAYER_INTERFACE); plugin->player_id = g_dbus_connection_register_object(plugin->connection, MPRIS_OBJECT_NAME, ifaceinfo, &player_vtable, plugin, NULL, &error); if (error != NULL) { xmr_debug("Unable to register MPRIS player interface: %s", error->message); g_error_free (error); } plugin->name_own_id = g_bus_own_name(G_BUS_TYPE_SESSION, MPRIS_BUS_NAME_PREFIX ".xmradio", G_BUS_NAME_OWNER_FLAGS_NONE, NULL, (GBusNameAcquiredCallback) name_acquired_cb, (GBusNameLostCallback) name_lost_cb, g_object_ref(plugin), g_object_unref); }