diff --git a/gtk/gtkfilelauncher.c b/gtk/gtkfilelauncher.c index 1536883030..5f0c62f251 100644 --- a/gtk/gtkfilelauncher.c +++ b/gtk/gtkfilelauncher.c @@ -53,11 +53,13 @@ struct _GtkFileLauncher GFile *file; unsigned int always_ask : 1; + unsigned int writable : 1; }; enum { PROP_FILE = 1, - PROP_ALWAYS_ASK = 2, + PROP_ALWAYS_ASK, + PROP_WRITABLE, NUM_PROPERTIES }; @@ -99,6 +101,10 @@ gtk_file_launcher_get_property (GObject *object, g_value_set_boolean (value, self->always_ask); break; + case PROP_WRITABLE: + g_value_set_boolean (value, self->writable); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -123,6 +129,10 @@ gtk_file_launcher_set_property (GObject *object, gtk_file_launcher_set_always_ask (self, g_value_get_boolean (value)); break; + case PROP_WRITABLE: + gtk_file_launcher_set_writable (self, g_value_get_boolean (value)); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); break; @@ -163,6 +173,18 @@ gtk_file_launcher_class_init (GtkFileLauncherClass *class) FALSE, G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY); + /** + * GtkFileLauncher:writable: (attributes org.gtk.Property.get=gtk_file_launcher_get_writable org.gtk.Property.set=gtk_file_launcher_set_writable) + * + * Whether to make the file writable for the handler. + * + * Since: 4.14 + */ + properties[PROP_WRITABLE] = + g_param_spec_boolean ("writable", NULL, NULL, + FALSE, + G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS|G_PARAM_EXPLICIT_NOTIFY); + g_object_class_install_properties (object_class, NUM_PROPERTIES, properties); } @@ -272,6 +294,47 @@ gtk_file_launcher_set_always_ask (GtkFileLauncher *self, g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_ALWAYS_ASK]); } +/** + * gtk_file_launcher_get_writable: + * @self: a `GtkFileLauncher` + * + * Returns whether to make the file writable for the handler. + * + * Returns: `TRUE` if the file will be made writable + * + * Since: 4.14 + */ +gboolean +gtk_file_launcher_get_writable (GtkFileLauncher *self) +{ + g_return_val_if_fail (GTK_IS_FILE_LAUNCHER (self), FALSE); + + return self->writable; +} + +/** + * gtk_file_launcher_set_writable: + * @self: a `GtkFileLauncher` + * @writable: a `gboolean` + * + * Sets whether to make the file writable for the handler. + * + * Since: 4.14 + */ +void +gtk_file_launcher_set_writable (GtkFileLauncher *self, + gboolean writable) +{ + g_return_if_fail (GTK_IS_FILE_LAUNCHER (self)); + + if (self->writable == writable) + return; + + self->writable = writable; + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_WRITABLE]); +} + /* }}} */ /* {{{ Async implementation */ @@ -433,7 +496,15 @@ gtk_file_launcher_launch (GtkFileLauncher *self, #ifndef G_OS_WIN32 if (gtk_openuri_portal_is_available ()) { - gtk_openuri_portal_open_async (self->file, FALSE, self->always_ask, parent, cancellable, open_done, task); + GtkOpenuriFlags flags = 0; + + if (self->always_ask) + flags |= GTK_OPENURI_FLAGS_ASK; + + if (self->writable) + flags |= GTK_OPENURI_FLAGS_WRITABLE; + + gtk_openuri_portal_open_async (self->file, FALSE, flags, parent, cancellable, open_done, task); } else #endif @@ -527,7 +598,9 @@ gtk_file_launcher_open_containing_folder (GtkFileLauncher *self, #ifndef G_OS_WIN32 if (gtk_openuri_portal_is_available ()) { - gtk_openuri_portal_open_async (self->file, TRUE, FALSE, parent, cancellable, open_done, task); + GtkOpenuriFlags flags = 0; + + gtk_openuri_portal_open_async (self->file, TRUE, flags, parent, cancellable, open_done, task); } else #endif diff --git a/gtk/gtkfilelauncher.h b/gtk/gtkfilelauncher.h index 129ca35515..e402eac394 100644 --- a/gtk/gtkfilelauncher.h +++ b/gtk/gtkfilelauncher.h @@ -46,6 +46,11 @@ GDK_AVAILABLE_IN_4_12 void gtk_file_launcher_set_always_ask (GtkFileLauncher *self, gboolean always_ask); +GDK_AVAILABLE_IN_4_14 +gboolean gtk_file_launcher_get_writable (GtkFileLauncher *self); +GDK_AVAILABLE_IN_4_14 +void gtk_file_launcher_set_writable (GtkFileLauncher *self, + gboolean writable); GDK_AVAILABLE_IN_4_10 void gtk_file_launcher_launch (GtkFileLauncher *self, GtkWindow *parent, diff --git a/gtk/gtkopenuriportal.c b/gtk/gtkopenuriportal.c index e41305acd5..3d5bc76c33 100644 --- a/gtk/gtkopenuriportal.c +++ b/gtk/gtkopenuriportal.c @@ -112,7 +112,7 @@ typedef struct { GFile *file; char *uri; gboolean open_folder; - gboolean always_ask; + GtkOpenuriFlags flags; GDBusConnection *connection; GCancellable *cancellable; GTask *task; @@ -276,7 +276,6 @@ open_uri (OpenUriData *data, { GFile *file = data->file; gboolean open_folder = data->open_folder; - gboolean always_ask = data->always_ask; GTask *task; GVariant *opts = NULL; int i; @@ -321,8 +320,13 @@ open_uri (OpenUriData *data, if (activation_token) g_variant_builder_add (&opt_builder, "{sv}", "activation_token", g_variant_new_string (activation_token)); - if (always_ask && !open_folder) - g_variant_builder_add (&opt_builder, "{sv}", "ask", g_variant_new_boolean (always_ask)); + if (!open_folder) + { + if (data->flags & GTK_OPENURI_FLAGS_ASK) + g_variant_builder_add (&opt_builder, "{sv}", "ask", g_variant_new_boolean (TRUE)); + if (data->flags & GTK_OPENURI_FLAGS_WRITABLE) + g_variant_builder_add (&opt_builder, "{sv}", "writable", g_variant_new_boolean (TRUE)); + } opts = g_variant_builder_end (&opt_builder); @@ -458,7 +462,7 @@ window_handle_exported (GtkWindow *window, void gtk_openuri_portal_open_async (GFile *file, gboolean open_folder, - gboolean always_ask, + GtkOpenuriFlags flags, GtkWindow *parent, GCancellable *cancellable, GAsyncReadyCallback callback, @@ -478,7 +482,7 @@ gtk_openuri_portal_open_async (GFile *file, data->parent = parent ? g_object_ref (parent) : NULL; data->file = g_object_ref (file); data->open_folder = open_folder; - data->always_ask = always_ask; + data->flags = flags; data->cancellable = cancellable ? g_object_ref (cancellable) : NULL; data->task = g_task_new (parent, cancellable, callback, user_data); g_task_set_check_cancellable (data->task, FALSE); diff --git a/gtk/gtkopenuriportal.h b/gtk/gtkopenuriportal.h index 9eb153fb8e..3236f46e68 100644 --- a/gtk/gtkopenuriportal.h +++ b/gtk/gtkopenuriportal.h @@ -28,9 +28,15 @@ G_BEGIN_DECLS gboolean gtk_openuri_portal_is_available (void); +typedef enum +{ + GTK_OPENURI_FLAGS_ASK = 1 << 0, + GTK_OPENURI_FLAGS_WRITABLE = 1 << 1, +} GtkOpenuriFlags; + void gtk_openuri_portal_open_async (GFile *file, gboolean open_folder, - gboolean always_ask, + GtkOpenuriFlags flags, GtkWindow *window, GCancellable *cancellable, GAsyncReadyCallback callback,