filechooser portal: Make sure we can save

Explicitly request files for saving to be writable, otherwise
we are at the mercy of the portal, which currently gets it wrong.
This commit is contained in:
Matthias Clasen 2017-01-17 14:08:38 -05:00
parent 4f80d234bf
commit f4a0f2e5ca

View File

@ -53,6 +53,7 @@ typedef struct {
char *portal_handle; char *portal_handle;
guint portal_response_signal_id; guint portal_response_signal_id;
gboolean modal; gboolean modal;
gboolean writable;
gboolean hidden; gboolean hidden;
@ -304,6 +305,8 @@ show_portal_file_chooser (GtkFileChooserNative *self,
g_variant_new_string (self->cancel_label)); g_variant_new_string (self->cancel_label));
g_variant_builder_add (&opt_builder, "{sv}", "modal", g_variant_builder_add (&opt_builder, "{sv}", "modal",
g_variant_new_boolean (data->modal)); g_variant_new_boolean (data->modal));
g_variant_builder_add (&opt_builder, "{sv}", "writable",
g_variant_new_boolean (data->writable));
g_variant_builder_add (&opt_builder, "{sv}", "filters", get_filters (GTK_FILE_CHOOSER (self))); g_variant_builder_add (&opt_builder, "{sv}", "filters", get_filters (GTK_FILE_CHOOSER (self)));
if (GTK_FILE_CHOOSER_NATIVE (self)->current_name) if (GTK_FILE_CHOOSER_NATIVE (self)->current_name)
g_variant_builder_add (&opt_builder, "{sv}", "current_name", g_variant_builder_add (&opt_builder, "{sv}", "current_name",
@ -376,6 +379,7 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
GDBusConnection *connection; GDBusConnection *connection;
GtkFileChooserAction action; GtkFileChooserAction action;
const char *method_name; const char *method_name;
gboolean writable;
if (!gtk_should_use_portal ()) if (!gtk_should_use_portal ())
return FALSE; return FALSE;
@ -387,9 +391,15 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self)); action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (self));
if (action == GTK_FILE_CHOOSER_ACTION_OPEN) if (action == GTK_FILE_CHOOSER_ACTION_OPEN)
{
method_name = "OpenFile"; method_name = "OpenFile";
writable = FALSE;
}
else if (action == GTK_FILE_CHOOSER_ACTION_SAVE) else if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
{
method_name = "SaveFile"; method_name = "SaveFile";
writable = FALSE;
}
else else
{ {
g_warning ("GTK_FILE_CHOOSER_ACTION_%s is not supported by GtkFileChooserNativePortal", action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ? "SELECT_FOLDER" : "CREATE_FOLDER"); g_warning ("GTK_FILE_CHOOSER_ACTION_%s is not supported by GtkFileChooserNativePortal", action == GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ? "SELECT_FOLDER" : "CREATE_FOLDER");
@ -401,6 +411,7 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
data->connection = connection; data->connection = connection;
data->method_name = method_name; data->method_name = method_name;
data->writable = writable;
if (gtk_native_dialog_get_modal (GTK_NATIVE_DIALOG (self))) if (gtk_native_dialog_get_modal (GTK_NATIVE_DIALOG (self)))
data->modal = TRUE; data->modal = TRUE;