Skip to content

Commit

Permalink
file chooser portal: Port to new Request API
Browse files Browse the repository at this point in the history
The portal API has changed, we need to adapt.

https://bugzilla.gnome.org/show_bug.cgi?id=768499
  • Loading branch information
Matthias Clasen committed Jul 8, 2016
1 parent 6cf71ed commit 445d12e
Showing 1 changed file with 22 additions and 29 deletions.
51 changes: 22 additions & 29 deletions gtk/gtkfilechoosernativeportal.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ typedef struct {
GDBusConnection *connection;
char *portal_handle;
guint portal_response_signal_id;
GDBusSignalCallback signal_callback;
gboolean modal;

gboolean hidden;
Expand Down Expand Up @@ -239,6 +240,19 @@ open_file_msg_cb (GObject *source_object,
filechooser_portal_data_free (data);
self->mode_data = NULL;
}
else
{
data->portal_response_signal_id =
g_dbus_connection_signal_subscribe (data->connection,
"org.freedesktop.portal.Desktop",
"org.freedesktop.portal.Request",
"Response",
data->portal_handle,
NULL,
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
data->signal_callback,
self, NULL);
}

g_object_unref (reply);
}
Expand Down Expand Up @@ -266,16 +280,13 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
{
FilechooserPortalData *data;
GtkWindow *transient_for;
guint update_preview_signal;
GDBusConnection *connection;
char *parent_window_str;
GDBusMessage *message;
GVariantBuilder opt_builder;
GtkFileChooserAction action;
gboolean multiple;
const char *method_name;
const char *signal_name;
GDBusSignalCallback signal_callback;

if (!gtk_should_use_portal ())
return FALSE;
Expand All @@ -288,23 +299,11 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
multiple = gtk_file_chooser_get_select_multiple (GTK_FILE_CHOOSER (self));

if (action == GTK_FILE_CHOOSER_ACTION_OPEN && !multiple)
{
method_name = "OpenFile";
signal_name = "OpenFileResponse";
signal_callback = one_file_response;
}
method_name = "OpenFile";
else if (action == GTK_FILE_CHOOSER_ACTION_OPEN && multiple)
{
method_name = "OpenFiles";
signal_name = "OpenFilesResponse";
signal_callback = multi_file_response;
}
method_name = "OpenFiles";
else if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
{
method_name = "SaveFile";
signal_name = "SaveFileResponse";
signal_callback = one_file_response;
}
method_name = "SaveFile";
else
{
g_warning ("GTK_FILE_CHOOSER_ACTION_%s is not supported by GtkFileChooserNativePortal", action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ? "SELECT_FOLDER" : "CREATE_FOLDER");
Expand All @@ -315,6 +314,11 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
data->self = g_object_ref (self);
data->connection = connection;

if (strcmp (method_name, "OpenFiles") == 0)
data->signal_callback = multi_file_response;
else
data->signal_callback = one_file_response;

message = g_dbus_message_new_method_call ("org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.FileChooser",
Expand Down Expand Up @@ -379,17 +383,6 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
g_variant_builder_end (&opt_builder)));
g_free (parent_window_str);

data->portal_response_signal_id =
g_dbus_connection_signal_subscribe (data->connection,
"org.freedesktop.portal.Desktop",
"org.freedesktop.portal.FileChooser",
signal_name,
"/org/freedesktop/portal/desktop",
NULL,
G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
signal_callback,
self, NULL);

g_dbus_connection_send_message_with_reply (data->connection,
message,
G_DBUS_SEND_MESSAGE_FLAGS_NONE,
Expand Down

0 comments on commit 445d12e

Please sign in to comment.