Merge branch 'fix-file-transfer-portal' into 'main'

Stop recursion in registering serializers

See merge request GNOME/gtk!5013
This commit is contained in:
Matthias Clasen 2022-09-07 15:04:43 +00:00
commit a08277adcd
4 changed files with 94 additions and 38 deletions

View File

@ -97,7 +97,7 @@ add_files (GDBusProxy *proxy,
AddFileData *afd)
{
GUnixFDList *fd_list;
GVariantBuilder fds;
GVariantBuilder fds, options;
int i;
char *key;
@ -146,9 +146,10 @@ add_files (GDBusProxy *proxy,
key = (char *)g_object_get_data (G_OBJECT (afd->task), "key");
g_variant_builder_init (&options, G_VARIANT_TYPE_VARDICT);
g_dbus_proxy_call_with_unix_fd_list (proxy,
"AddFiles",
g_variant_new ("(sah)", key, &fds),
g_variant_new ("(saha{sv})", key, &fds, &options),
0, -1,
fd_list,
NULL,
@ -480,20 +481,8 @@ connection_closed (GDBusConnection *connection,
}
static void
got_proxy (GObject *source,
GAsyncResult *result,
gpointer data)
finish_registration (void)
{
GError *error = NULL;
file_transfer_proxy = g_dbus_proxy_new_for_bus_finish (result, &error);
if (!file_transfer_proxy)
{
g_message ("Failed to get file transfer portal: %s", error->message);
g_clear_error (&error);
return;
}
gdk_content_register_serializer (G_TYPE_FILE,
"application/vnd.portal.files",
portal_file_serializer,
@ -523,6 +512,21 @@ got_proxy (GObject *source,
"closed", G_CALLBACK (connection_closed), NULL);
}
static gboolean
proxy_has_owner (GDBusProxy *proxy)
{
char *owner;
owner = g_dbus_proxy_get_name_owner (proxy);
if (owner)
{
g_free (owner);
return TRUE;
}
return FALSE;
}
void
file_transfer_portal_register (void)
{
@ -531,7 +535,8 @@ file_transfer_portal_register (void)
if (!called)
{
called = TRUE;
g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION,
file_transfer_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES
| G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS
| G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
@ -540,8 +545,13 @@ file_transfer_portal_register (void)
"/org/freedesktop/portal/documents",
"org.freedesktop.portal.FileTransfer",
NULL,
got_proxy,
NULL);
if (file_transfer_proxy && !proxy_has_owner (file_transfer_proxy))
g_clear_object (&file_transfer_proxy);
if (file_transfer_proxy)
finish_registration ();
}
}

View File

@ -407,8 +407,6 @@ gdk_content_register_deserializer (const char *mime_type,
g_return_if_fail (mime_type != NULL);
g_return_if_fail (deserialize != NULL);
init ();
deserializer = g_slice_new0 (Deserializer);
deserializer->mime_type = g_intern_string (mime_type);

View File

@ -413,8 +413,6 @@ gdk_content_register_serializer (GType type,
g_return_if_fail (mime_type != NULL);
g_return_if_fail (serialize != NULL);
init ();
serializer = g_slice_new0 (Serializer);
serializer->mime_type = g_intern_string (mime_type);

View File

@ -82,6 +82,10 @@ read_upto_done (GObject *source,
str = g_data_input_stream_read_upto_finish (out, result, NULL, &error);
g_assert_no_error (error);
if (g_test_verbose ())
g_test_message ("src formats: %s", str);
g_free (str);
*done = TRUE;
@ -89,8 +93,8 @@ read_upto_done (GObject *source,
}
static void
assert_texture_equal (GdkTexture *t1,
GdkTexture *t2)
compare_textures (GdkTexture *t1,
GdkTexture *t2)
{
int width;
int height;
@ -117,6 +121,28 @@ assert_texture_equal (GdkTexture *t1,
g_free (d2);
}
static void
compare_files (const char *file1,
const char *file2)
{
char *m1, *m2;
gsize l1, l2;
GError *error = NULL;
g_file_get_contents (file1, &m1, &l1, &error);
g_assert_no_error (error);
g_file_get_contents (file2, &m2, &l2, &error);
g_assert_no_error (error);
if (l1 != l2)
g_test_fail_printf ("file length mismatch: %s %s\n", file1, file2);
else if (memcmp (m1, m2, l1) != 0)
g_test_fail_printf ("file mismatch: %s %s\n", file1, file2);
g_free (m1);
g_free (m2);
}
static void
test_clipboard_roundtrip (const char *type,
const char *value,
@ -182,9 +208,9 @@ test_clipboard_roundtrip (const char *type,
g_assert_cmpstr (stdout_buf, ==, result);
else if (g_str_has_prefix (stdout_buf, "ERROR"))
{
g_test_fail ();
g_test_fail_printf ("dest error: %s", stdout_buf);
}
else if (g_str_has_suffix (value, ".png"))
else if (g_str_equal (type, "image"))
{
GFile *f1, *f2;
GdkTexture *t1, *t2;
@ -197,27 +223,30 @@ test_clipboard_roundtrip (const char *type,
t2 = gdk_texture_new_from_file (f2, &error);
g_assert_no_error (error);
assert_texture_equal (t1, t2);
compare_textures (t1, t2);
g_object_unref (t1);
g_object_unref (t2);
g_object_unref (f1);
g_object_unref (f2);
}
else
else if (g_str_equal (type, "file"))
{
char *m1, *m2;
gsize l1, l2;
compare_files (value, stdout_buf);
}
else if (g_str_equal (type, "files"))
{
char **in_files, **out_files;
g_file_get_contents (value, &m1, &l1, &error);
g_assert_no_error (error);
g_file_get_contents (stdout_buf, &m2, &l2, &error);
g_assert_no_error (error);
in_files = g_strsplit (value, ":", -1);
out_files = g_strsplit (stdout_buf, ":", -1);
g_assert_cmpmem (m1, l1, m2, l2);
g_assert_cmpint (g_strv_length (in_files), ==, g_strv_length (out_files));
for (int i = 0; in_files[i]; i++)
compare_files (in_files[i], out_files[i]);
g_free (m1);
g_free (m2);
g_strfreev (in_files);
g_strfreev (out_files);
}
g_assert_null (stderr_buf);
@ -239,6 +268,8 @@ test_clipboard_text (void)
filename = g_test_build_filename (G_TEST_DIST, "clipboard-data", "test.txt", NULL);
test_clipboard_roundtrip ("text", filename, NULL);
g_free (filename);
}
static void
@ -260,13 +291,32 @@ test_clipboard_color (void)
static void
test_clipboard_file (void)
{
test_clipboard_roundtrip ("file", "/etc/passwd", "/etc/passwd");
char *filename;
filename = g_test_build_filename (G_TEST_DIST, "clipboard-data", "test.txt", NULL);
test_clipboard_roundtrip ("file", filename, NULL);
g_free (filename);
}
static void
test_clipboard_files (void)
{
test_clipboard_roundtrip ("files", "/etc/passwd:/boot/ostree", "/etc/passwd:/boot/ostree");
char **filenames;
char *string;
filenames = g_new (char *, 3);
filenames[0] = g_test_build_filename (G_TEST_DIST, "clipboard-data", "image.png", NULL);
filenames[1] = g_test_build_filename (G_TEST_DIST, "clipboard-data", "test.txt", NULL);
filenames[2] = NULL;
string = g_strjoinv (":", filenames);
test_clipboard_roundtrip ("files", string, NULL);
g_free (string);
g_strfreev (filenames);
}
int