SaveFile: support clients that set both current_name / current_file options
It has been reported that when saving files from Telegram Desktop (and the GNOME xdg-desktop portal is in use), the filename entry ends up empty. dbus-monitor
shows that Telegram Desktop (or maybe Qt6) sets both the current_file
and the current_folder
+ current_name
options:
...
dict entry(
string "current_name"
variant string "AnimatedSticker.tgs"
)
dict entry(
string "current_folder"
variant array of bytes "/home/luca/Scaricati" + \0
)
dict entry(
string "current_file"
variant array of bytes "/home/luca/Scaricati/AnimatedSticker.tgs" + \0
)
]
Here we're saving a sticker from a chat, and /home/luca/Scaricati/AnimatedSticker.tgs
does not yet exist when launching the save dialog. The spec says:
current_file The current file (when saving an existing file). The byte array is expected to be null-terminated
However in this case the client tentatively set current_file
in conjunction to current_folder
+ current_name
because the file might already exist.
Here's the relevant code in xdg-desktop-portal-gnome. As you can see, if current_file is set, then nothing else is taken in consideration.
if (g_variant_lookup (arg_options, "current_file", "^&ay", &path))
{
g_autoptr(GFile) file = g_file_new_for_path (path);
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (dialog), file, NULL);
}
else
{
if (g_variant_lookup (arg_options, "current_name", "&s", ¤t_name))
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), current_name);
if (g_variant_lookup (arg_options, "current_folder", "^&ay", &path))
{
g_autoptr(GFile) file = g_file_new_for_path (path);
gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), file, NULL);
}
}
https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/blob/42.1/src/filechooser.c#L574