-
-
Notifications
You must be signed in to change notification settings - Fork 204
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
Add GetRealPath to document portal #1269
Conversation
Also, should there be some sanity checks, like only accept the path with the |
You just pass the ID, not the path. If you path is e.g.
This should be generated automatically from the XML file. |
I see, didn't realize that and it makes sense.
I meant in case we were going to pass path with |
I have now added a test |
Can you please squash your commits into one? |
So, we are not going for extended file attributes then? Would be nice to have some rationale for why this path has been chosen. I'm worrying a bit about the performance here because every single file lookup will incur multiple dbus messages between 4 different processes. |
Maybe a stupid question as this is something I know nothing about. Wouldn't extended file attributes as proposed in the original bug be GIO specific? Why multiple DBus messages between 4 different processes?
|
No, extended file attributes are a standard linux feature. They are exposed in GIO via GFileAttribute currently, so this is only about how Glib/GIO would provide a nice API for it.
App, xdg-dbus-proxy, dbus broker, portal. |
It would still require all the other counterparts (e.g. Qt) to implement support for it, right? I also think this would be less discoverable, even though it's probably a better solution. Maybe this solution can be a temporary one? Most importantly because it would take way more time to get this available for clients. You would need this to land in GLib first in order to support it in xdg-desktop-portal and it would also require the most recent versions of Glib for clients to use it.
That's 4 processes involved, but I think it's still one message for |
One could write code to read the extended attribute just like they could write code to call the portal. There is no need to wait for GIO or anything else really. It would just be more convenient. That being said, I'm not against this portal in principle. |
The problem with file attributes is, that it is not very well supported. Qt for example don't seem to have native support for reading it. On most programming languages you'll need to find and add a additional library just for getting the correct file path. This would make xdg-desktop-portal an even more nightmare to use than it already is. We could however support both: This Function and a file attribute,. But adding a file attribute is outside the scope of this PR. |
Right, but it's more low-level and not something clients will adopt as easily as simple DBus call.
I agree, making this one as first option, while having file attributes as something to use in the future along this one. |
As written (one doc ID), does this mean the app should send multiple requests for multiple files? If that's the case, wouldn't it be better to be able to request multiple document IDs at once so there is only one request instead of multiple ones? (also have only one response instead of multiple ones) Also, is it possible to handle this with a file chooser option? (returning files and their paths at the same time, or is it the extended file attributes?) |
I think one will be the most common use-case, but I guess this PR can be changed to support more at once to be future-proof.
This would not work in case when you are not opening the file first using file chooser portal. The path from the document portal can be already saved in an app as part of settings. In such case you just need to get the host path without going through file chooser portal first. |
Most Apps don't call the file chooser portal directly. They just use the function the Toolkit provides and the Toolkit uses the Portal. So most Apps can't take advantage of such a Option.
I could add a second function which takes an array. Many D_Bus libraries are not in a good state, so I think we should also provide a solution which just takes a string. |
Yes, but it is expected that the toolkits will implement the function (as you said, they already integrate portals). |
It wouldn't make sense to have two same calls, where one does the same thing just for more document IDs. It should not be a problem to make this accept an array of strings and return something like That said, I believe most of the cases will be using this to translate just one path and that's even my use case so I don't really insist on this. +1 from me on this MR, with just a suggestion to change the naming of that method |
As I said, there are many D-Bus Bindings out there who are not in a good state. Having a Method that only takes a string and not an Array would also be easier to use on the command line. |
We already have much more complicated method signatures and things work fine. This is really not a good argument at all. |
Depends on what binding you use. I mainly program, in PyQt and QtDBus is completely broken. I need to use jeepney for most Portals. Adding a new dependency just to show the real path is something I want to avoid. |
If the bindings are the problem the bindings should be fixed instead. Otherwise you are just pushing for more technical debt. |
@JakobDev are you going to update this change to take more document IDs? I can look into it myself if you don't have time to do so. I really want this change landed as soon as possible. |
Sorry, I forgot this PR. I try to look into it next Week, but I can't promise I'll have time. |
I have now updated the Code with help from @ebassi to use a Array. The test is not updated yet. |
I think safer would be to return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wrote some suggestions how I think this should be changed to correctly document the method and to make the method return map<string, bytearray>. I tested it and it works. I haven't tried to update the test.
@@ -273,5 +273,21 @@ | |||
<arg type='s' name='app_id' direction='in'/> | |||
<arg type='a{say}' name='docs' direction='out'/> | |||
</method> | |||
|
|||
<!-- | |||
GetRealPath: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetRealPath: | |
GetRealPaths: |
|
||
<!-- | ||
GetRealPath: | ||
@doc_id: the ID of the file in the document store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@doc_id: the ID of the file in the document store | |
@doc_id: the IDs of the files in the document store |
<!-- | ||
GetRealPath: | ||
@doc_id: the ID of the file in the document store | ||
@path: the path for the file in the host filesystem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@path: the path for the file in the host filesystem | |
@path: a dictionary mapping application IDs to the paths in the host filesystem |
@doc_id: the ID of the file in the document store | ||
@path: the path for the file in the host filesystem | ||
|
||
Gets the filesystem path for a document store entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gets the filesystem path for a document store entry. | |
Gets the filesystem paths for document store entries. |
|
||
This method was added in version 5 of this interface. | ||
--> | ||
<method name="GetRealPath"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<method name="GetRealPath"> | |
<method name="GetRealPaths"> |
} | ||
|
||
static gboolean | ||
portal_get_real_path (GDBusMethodInvocation *invocation, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
portal_get_real_path (GDBusMethodInvocation *invocation, | |
portal_get_real_paths (GDBusMethodInvocation *invocation, |
@@ -1445,6 +1529,7 @@ on_bus_acquired (GDBusConnection *connection, | |||
g_signal_connect_swapped (dbus_api, "handle-lookup", G_CALLBACK (handle_method), portal_lookup); | |||
g_signal_connect_swapped (dbus_api, "handle-info", G_CALLBACK (handle_method), portal_info); | |||
g_signal_connect_swapped (dbus_api, "handle-list", G_CALLBACK (handle_method), portal_list); | |||
g_signal_connect_swapped (dbus_api, "handle-get-real-path", G_CALLBACK (handle_method), portal_get_real_path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g_signal_connect_swapped (dbus_api, "handle-get-real-path", G_CALLBACK (handle_method), portal_get_real_path); | |
g_signal_connect_swapped (dbus_api, "handle-get-real-paths", G_CALLBACK (handle_method), portal_get_real_paths); |
g_variant_builder_add (&builder, "^ay", path); | ||
} | ||
|
||
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(aay)", &builder)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(aay)", &builder)); | |
g_dbus_method_invocation_return_value (invocation, g_variant_new ("(@a{say})", g_variant_builder_end(&builder))); |
return FALSE; | ||
} | ||
|
||
g_variant_builder_add (&builder, "^ay", path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
g_variant_builder_add (&builder, "^ay", path); | |
g_variant_builder_add (&builder, "{s@ay}", id_list[i], g_variant_new_bytestring(path)); |
|
||
g_variant_get (parameters, "(^a&s)", &id_list); | ||
|
||
GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aay")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("aay")); | |
GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("a{say}")); |
You can implemnt that if you want. I ave little to no motivation in messing with glib further. The last one already took a few hours. |
I can take over if you don't mind. I wrote suggestions for the changes, but it still requires to finish the tests. |
I have submitted #1364 to continue with the changes I suggested here. |
This new function allows Apps to get the Real Path from a Document ID. IF you are using the FileChooser Portal, you get the a
/run/user/1000/doc
path. That's a Problem for Apps who display the Path in the UI e.g. a recent files menu.This new function allows Apps to get the real Path, so it be displayed probably in the UI.Sandboxed Apps can only get the real path for those document IDs they have access to.
This PR is currently missing tests, as I don't know if this new function gets accepted. Please also note that I don't have much experience in C.
Fixes #475