Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Share Portal #38

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions po/POTFILES
Original file line number Diff line number Diff line change
Expand Up @@ -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
45 changes: 45 additions & 0 deletions src/Share/Dialog.vala
Original file line number Diff line number Diff line change
@@ -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 ();
}
}
63 changes: 63 additions & 0 deletions src/Share/Portal.vala
Original file line number Diff line number Diff line change
@@ -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<ObjectPath, Dialog> handles;
private DBusConnection connection;

public Portal (DBusConnection connection) {
handles = new HashTable<ObjectPath, Dialog> (str_hash, str_equal);
this.connection = connection;
}

public async void share (
ObjectPath handle,
string app_id,
string parent_window,
HashTable<string, Variant> 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<Dialog> (handle, dialog);
} catch (Error e) {
critical (e.message);
}


var _results = new HashTable<string, Variant> (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 ();
}
}
3 changes: 3 additions & 0 deletions src/XdgDesktopPortalPantheon.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions src/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down