Fix desync between file saving and file opening portal callbakcs.
This commit is contained in:
parent
b012069269
commit
a6025d69f0
1 changed files with 13 additions and 7 deletions
|
@ -112,22 +112,28 @@ void FileBrowser::FileBrowserOpenCallback(GObject *src, GAsyncResult *res, gpoin
|
|||
void FileBrowser::FileBrowserSaveCallback(GObject *src, GAsyncResult *res, gpointer data) {
|
||||
(void)src;
|
||||
FileBrowser *self = (FileBrowser*)data;
|
||||
self->open = false;
|
||||
GVariant *variant = xdp_portal_save_file_finish(self->portal, res, NULL);
|
||||
if (variant == NULL) {
|
||||
printf("Variant was null.\n");
|
||||
printf("Cancelled.\n");
|
||||
return;
|
||||
}
|
||||
GVariant *first_index = g_variant_get_child_value(variant, 0);
|
||||
if (first_index == NULL) {
|
||||
printf("Variant had no first index.\n");
|
||||
return;
|
||||
GVariant *uris = g_variant_lookup_value(variant, "uris", G_VARIANT_TYPE_STRING_ARRAY);
|
||||
GVariant *first_uri = g_variant_get_child_value(uris, 0);
|
||||
gsize length;
|
||||
const gchar* c_str_without_terminater = g_variant_get_string(first_uri, &length);
|
||||
vector<char> c_str_vec;
|
||||
c_str_vec.reserve(length + 1);
|
||||
for (gsize i = 0; i < length; i++) {
|
||||
c_str_vec.push_back(c_str_without_terminater[i]);
|
||||
}
|
||||
const char *c_str = (const char*)g_variant_get_bytestring(first_index);
|
||||
c_str_vec.push_back('\0');
|
||||
const char *c_str = c_str_vec.data();
|
||||
printf("Selected file %s\n", c_str);
|
||||
string str = c_str;
|
||||
if (str.starts_with("file://")) {
|
||||
str = str.substr(string("file://").length());
|
||||
}
|
||||
self->open = false;
|
||||
self->selected = path(str);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue