diff --git a/file_browser.cpp b/file_browser.cpp index e54116e..d1bb89d 100644 --- a/file_browser.cpp +++ b/file_browser.cpp @@ -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 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