void GnomeFileManager::Activate(uint64_t timestamp)
{
glib::Cancellable cancellable;
glib::Object<GFile> file(g_file_new_for_uri(TRASH_URI.c_str()));
glib::Object<GAppInfo> app_info(g_file_query_default_handler(file, cancellable, nullptr));
if (app_info)
{
GdkDisplay* display = gdk_display_get_default();
glib::Object<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
if (timestamp > 0)
gdk_app_launch_context_set_timestamp(context, timestamp);
auto const& gcontext = glib::object_cast<GAppLaunchContext>(context);
auto proxy = std::make_shared<glib::DBusProxy>(NAUTILUS_NAME, NAUTILUS_PATH,
"org.freedesktop.Application");
glib::String context_string(g_app_launch_context_get_startup_notify_id(gcontext, app_info, nullptr));
if (context_string && g_utf8_validate(context_string, -1, nullptr))
{
GVariantBuilder builder;
g_variant_builder_init(&builder, G_VARIANT_TYPE("a{sv}"));
g_variant_builder_add(&builder, "{sv}", "desktop-startup-id", g_variant_new("s", context_string.Value()));
GVariant *param = g_variant_new("(@a{sv})", g_variant_builder_end(&builder));
// Passing the proxy to the lambda we ensure that it will be destroyed when needed
proxy->CallBegin("Activate", param, [proxy] (GVariant*, glib::Error const&) {});
}
}
}