Merge branch 'fix.nonunix.builds' into 'master'

Fix non-portal (UNIX) builds

See merge request GNOME/gtk!1252
This commit is contained in:
Matthias Clasen 2019-12-16 17:38:56 +00:00
commit 0546fd7c8a
5 changed files with 74 additions and 7 deletions

View File

@ -24,6 +24,9 @@
#include <fcntl.h> #include <fcntl.h>
#include <gio/gio.h> #include <gio/gio.h>
#ifdef G_OS_UNIX
#include <gio/gunixfdlist.h> #include <gio/gunixfdlist.h>
#ifndef O_PATH #ifndef O_PATH
@ -353,3 +356,5 @@ file_transfer_portal_retrieve_files_finish (GAsyncResult *result,
return FALSE; return FALSE;
} }
#endif /* G_OS_UNIX */

View File

@ -691,6 +691,7 @@ string_deserializer (GdkContentDeserializer *deserializer)
g_object_unref (filter); g_object_unref (filter);
} }
#ifdef G_OS_UNIX
static void static void
portal_finish (GObject *object, portal_finish (GObject *object,
GAsyncResult *result, GAsyncResult *result,
@ -777,6 +778,7 @@ portal_file_deserializer (GdkContentDeserializer *deserializer)
deserializer); deserializer);
g_object_unref (output); g_object_unref (output);
} }
#endif /* G_OS_UNIX */
static void static void
file_uri_deserializer_finish (GObject *source, file_uri_deserializer_finish (GObject *source,
@ -852,7 +854,6 @@ init (void)
static gboolean initialized = FALSE; static gboolean initialized = FALSE;
GSList *formats, *f; GSList *formats, *f;
const char *charset; const char *charset;
gboolean has_portal;
if (initialized) if (initialized)
return; return;
@ -905,24 +906,31 @@ init (void)
g_slist_free (formats); g_slist_free (formats);
has_portal = file_transfer_portal_available (); #ifdef G_OS_UNIX
gboolean has_portal = file_transfer_portal_available ();
if (has_portal) if (has_portal)
gdk_content_register_deserializer ("application/vnd.portal.files", gdk_content_register_deserializer ("application/vnd.portal.files",
GDK_TYPE_FILE_LIST, GDK_TYPE_FILE_LIST,
portal_file_deserializer, portal_file_deserializer,
NULL, NULL,
NULL); NULL);
#endif
gdk_content_register_deserializer ("text/uri-list", gdk_content_register_deserializer ("text/uri-list",
GDK_TYPE_FILE_LIST, GDK_TYPE_FILE_LIST,
file_uri_deserializer, file_uri_deserializer,
NULL, NULL,
NULL); NULL);
#ifdef G_OS_UNIX
if (has_portal) if (has_portal)
gdk_content_register_deserializer ("application/vnd.portal.files", gdk_content_register_deserializer ("application/vnd.portal.files",
G_TYPE_FILE, G_TYPE_FILE,
portal_file_deserializer, portal_file_deserializer,
NULL, NULL,
NULL); NULL);
#endif
gdk_content_register_deserializer ("text/uri-list", gdk_content_register_deserializer ("text/uri-list",
G_TYPE_FILE, G_TYPE_FILE,
file_uri_deserializer, file_uri_deserializer,

View File

@ -702,6 +702,7 @@ file_serializer_finish (GObject *source,
gdk_content_serializer_return_success (serializer); gdk_content_serializer_return_success (serializer);
} }
#ifdef G_OS_UNIX
static void static void
portal_ready (GObject *object, portal_ready (GObject *object,
GAsyncResult *result, GAsyncResult *result,
@ -758,6 +759,7 @@ portal_file_serializer (GdkContentSerializer *serializer)
file_transfer_portal_register_files ((const char **)files->pdata, TRUE, portal_ready, serializer); file_transfer_portal_register_files ((const char **)files->pdata, TRUE, portal_ready, serializer);
gdk_content_serializer_set_task_data (serializer, files, (GDestroyNotify)g_ptr_array_unref); gdk_content_serializer_set_task_data (serializer, files, (GDestroyNotify)g_ptr_array_unref);
} }
#endif /* G_OS_UNIX */
static void static void
file_uri_serializer (GdkContentSerializer *serializer) file_uri_serializer (GdkContentSerializer *serializer)
@ -866,7 +868,6 @@ init (void)
static gboolean initialized = FALSE; static gboolean initialized = FALSE;
GSList *formats, *f; GSList *formats, *f;
const char *charset; const char *charset;
gboolean has_portal;
if (initialized) if (initialized)
return; return;
@ -922,7 +923,8 @@ init (void)
g_slist_free (formats); g_slist_free (formats);
has_portal = file_transfer_portal_available (); #ifdef G_OS_UNIX
gboolean has_portal = file_transfer_portal_available ();
if (has_portal) if (has_portal)
gdk_content_register_serializer (G_TYPE_FILE, gdk_content_register_serializer (G_TYPE_FILE,
@ -930,6 +932,8 @@ init (void)
portal_file_serializer, portal_file_serializer,
NULL, NULL,
NULL); NULL);
#endif
gdk_content_register_serializer (G_TYPE_FILE, gdk_content_register_serializer (G_TYPE_FILE,
"text/uri-list", "text/uri-list",
file_uri_serializer, file_uri_serializer,
@ -940,12 +944,16 @@ init (void)
file_text_serializer, file_text_serializer,
NULL, NULL,
NULL); NULL);
#ifdef G_OS_UNIX
if (has_portal) if (has_portal)
gdk_content_register_serializer (GDK_TYPE_FILE_LIST, gdk_content_register_serializer (GDK_TYPE_FILE_LIST,
"application/vnd.portal.files", "application/vnd.portal.files",
portal_file_serializer, portal_file_serializer,
NULL, NULL,
NULL); NULL);
#endif
gdk_content_register_serializer (GDK_TYPE_FILE_LIST, gdk_content_register_serializer (GDK_TYPE_FILE_LIST,
"text/uri-list", "text/uri-list",
file_uri_serializer, file_uri_serializer,

View File

@ -19,6 +19,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#ifdef G_OS_UNIX
void void
copy (void) copy (void)
{ {
@ -68,10 +69,21 @@ clipboard_changed (GdkClipboard *clipboard)
g_print ("clipboard contents now: %s, local: %d\n", s, gdk_clipboard_is_local (clipboard)); g_print ("clipboard contents now: %s, local: %d\n", s, gdk_clipboard_is_local (clipboard));
} }
#else /* G_OS_UNIX */
void
hello (void)
{
g_print ("hello world\n");
}
#endif /* !G_OS_UNIX */
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
GtkWidget *window, *button, *box; GtkWidget *window, *box;
GtkWidget *button = NULL;
GdkClipboard *clipboard; GdkClipboard *clipboard;
gtk_init (); gtk_init ();
@ -88,9 +100,10 @@ main (int argc, char *argv[])
gtk_window_set_resizable (GTK_WINDOW (window), FALSE); gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
button = gtk_button_new (); button = gtk_button_new ();
#ifdef G_OS_UNIX /* portal usage is supported on *nix only */
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_button_set_label (GTK_BUTTON (button), "copy"); gtk_button_set_label (GTK_BUTTON (button), "copy");
g_signal_connect (button, "clicked", G_CALLBACK (copy), NULL); g_signal_connect (button, "clicked", G_CALLBACK (copy), NULL);
gtk_container_add (GTK_CONTAINER (box), button); gtk_container_add (GTK_CONTAINER (box), button);
@ -105,6 +118,14 @@ main (int argc, char *argv[])
clipboard = gdk_display_get_clipboard (gdk_display_get_default ()); clipboard = gdk_display_get_clipboard (gdk_display_get_default ());
g_signal_connect (clipboard, "changed", G_CALLBACK (clipboard_changed), NULL); g_signal_connect (clipboard, "changed", G_CALLBACK (clipboard_changed), NULL);
#else /* G_OS_UNIX -- original non-portal-enabled code */
gtk_button_set_label (GTK_BUTTON (button), "hello world");
g_signal_connect (button, "clicked", G_CALLBACK (hello), NULL);
gtk_container_add (GTK_CONTAINER (window), button);
#endif /* !G_OS_UNIX */
gtk_widget_show (window); gtk_widget_show (window);
gtk_main (); gtk_main ();

View File

@ -103,6 +103,8 @@ visible_child_changed_cb (GtkWidget *stack,
} }
} }
#ifdef G_OS_UNIX /* portal usage supported on *nix only */
static GSList * static GSList *
get_file_list (const char *dir) get_file_list (const char *dir)
{ {
@ -129,6 +131,29 @@ get_file_list (const char *dir)
return g_slist_reverse (list); return g_slist_reverse (list);
} }
#else /* G_OS_UNIX -- original non-portal-enabled code */
static GList *
get_file_list (const char *dir)
{
GFileEnumerator *enumerator;
GFile *file;
GList *list = NULL;
file = g_file_new_for_path (dir);
enumerator = g_file_enumerate_children (file, "standard::name", 0, NULL, NULL);
g_object_unref (file);
if (enumerator == NULL)
return NULL;
while (g_file_enumerator_iterate (enumerator, NULL, &file, NULL, NULL) && file != NULL)
list = g_list_prepend (list, g_object_ref (file));
return g_list_reverse (list);
}
#endif /* !G_OS_UNIX */
static void static void
format_list_add_row (GtkWidget *list, format_list_add_row (GtkWidget *list,
const char *format_name, const char *format_name,