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 FileBrowser::FileBrowserSaveCallback(GObject *src, GAsyncResult *res, gpointer data) {
|
||||||
(void)src;
|
(void)src;
|
||||||
FileBrowser *self = (FileBrowser*)data;
|
FileBrowser *self = (FileBrowser*)data;
|
||||||
self->open = false;
|
|
||||||
GVariant *variant = xdp_portal_save_file_finish(self->portal, res, NULL);
|
GVariant *variant = xdp_portal_save_file_finish(self->portal, res, NULL);
|
||||||
if (variant == NULL) {
|
if (variant == NULL) {
|
||||||
printf("Variant was null.\n");
|
printf("Cancelled.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GVariant *first_index = g_variant_get_child_value(variant, 0);
|
GVariant *uris = g_variant_lookup_value(variant, "uris", G_VARIANT_TYPE_STRING_ARRAY);
|
||||||
if (first_index == NULL) {
|
GVariant *first_uri = g_variant_get_child_value(uris, 0);
|
||||||
printf("Variant had no first index.\n");
|
gsize length;
|
||||||
return;
|
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;
|
string str = c_str;
|
||||||
if (str.starts_with("file://")) {
|
if (str.starts_with("file://")) {
|
||||||
str = str.substr(string("file://").length());
|
str = str.substr(string("file://").length());
|
||||||
}
|
}
|
||||||
|
self->open = false;
|
||||||
self->selected = path(str);
|
self->selected = path(str);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue