diff --git a/po/POTFILES b/po/POTFILES index 89492413..fb407a6f 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -5,3 +5,5 @@ src/Access/Dialog.vala src/AppChooser/Portal.vala src/AppChooser/Dialog.vala src/AppChooser/AppButton.vala +src/Share/Dialog.vala +src/Share/Portal.vala diff --git a/src/Share/Dialog.vala b/src/Share/Dialog.vala new file mode 100644 index 00000000..91f36eed --- /dev/null +++ b/src/Share/Dialog.vala @@ -0,0 +1,45 @@ +/* + * SPDX-FileCopyrigthText: 2021 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +[DBus (name = "org.freedesktop.impl.portal.Request")] +public class Share.Dialog : Hdy.Window { + // The ID used to register this dialog on the DBusConnection + public uint register_id { get; set; default = 0; } + + // The ID of the app sending the request + public string app_id { get; construct; } + + public string parent_window { get; construct; } + + // The content type to choose an application for + public string content_type { get; construct ; } + + // The filename to choose an app for. That this is just a basename, without a path + public string filename { get; construct; } + + + public Dialog ( + string app_id, + string parent_window, + string content_type, + string filename + ) { + Object ( + app_id: app_id, + parent_window: parent_window, + content_type: content_type, + filename: filename + ); + } + + construct { + + } + + [DBus (name = "Close")] + public void on_close () throws DBusError, IOError { + destroy (); + } +} diff --git a/src/Share/Portal.vala b/src/Share/Portal.vala new file mode 100644 index 00000000..6dc6be58 --- /dev/null +++ b/src/Share/Portal.vala @@ -0,0 +1,63 @@ +/* + * SPDX-FileCopyrigthText: 2021 elementary, Inc. (https://elementary.io) + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +[DBus (name = "org.freedesktop.impl.portal.Share")] +public class Share.Portal : Object { + private HashTable handles; + private DBusConnection connection; + + public Portal (DBusConnection connection) { + handles = new HashTable (str_hash, str_equal); + this.connection = connection; + } + + public async void share ( + ObjectPath handle, + string app_id, + string parent_window, + HashTable options + ) throws DBusError, IOError { + string content_type = ""; + string filename = ""; + + if ("content_type" in options && options["content_type"].is_of_type (VariantType.STRING)) { + content_type = options["content_type"].get_string (); + } + + if ("filename" in options && options["filename"].is_of_type (VariantType.STRING)) { + filename = options["filename"].get_string (); + } + + var dialog = new AppChooser.Dialog ( + app_id, + parent_window, + content_type, + filename + ); + + if ("modal" in options && options["modal"].is_of_type (VariantType.BOOLEAN)) { + dialog.modal = options["modal"].get_boolean (); + } + + try { + dialog.register_id = connection.register_object (handle, dialog); + } catch (Error e) { + critical (e.message); + } + + + var _results = new HashTable (str_hash, str_equal); + uint _response = 2; + + dialog.destroy.connect (() => { + if (dialog.register_id != 0) { + connection.unregister_object (dialog.register_id); + } + }); + + handles[handle] = dialog; + dialog.show_all (); + } +} diff --git a/src/XdgDesktopPortalPantheon.vala b/src/XdgDesktopPortalPantheon.vala index d4f33455..a6f75dd3 100644 --- a/src/XdgDesktopPortalPantheon.vala +++ b/src/XdgDesktopPortalPantheon.vala @@ -37,6 +37,9 @@ private void on_bus_acquired (DBusConnection connection, string name) { connection.register_object ("/org/freedesktop/portal/desktop", new AppChooser.Portal (connection)); debug ("AppChooser Portal registred!"); + + connection.register_object ("/org/freedesktop/portal/desktop", new Share.Portal (connection)); + debug ("Share Portal registred!"); } catch (Error e) { critical ("Unable to register the object: %s", e.message); } diff --git a/src/meson.build b/src/meson.build index 5ae695d8..c2362b60 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,6 +14,8 @@ executable( 'AppChooser/Portal.vala', 'AppChooser/Dialog.vala', 'AppChooser/AppButton.vala', + 'Share/Dialog.vala', + 'Share/Portal.vala', dependencies: [ glib_dep, gobject_dep,