From 55250a6de91d331e1c94daa258ceba5f761d4c84 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Tue, 11 Aug 2026 12:01:24 +1200 Subject: [PATCH] Fix bugtracker #270: Save As on Snap produces file with no .qet extension ProjectView::askUserForFilePath() only appended the .qet extension when FLATPAK_ID/SNAP_NAME were NOT set, on the assumption that the xdg-desktop-portal file dialog used by sandboxed Snap/Flatpak builds always appends the selected filter's extension itself (avoiding a double ".qet.qet"). In practice, on the reporter's Snap/Ubuntu 22.04 setup the portal dialog does not append it, so the environment-based skip left Save As producing a file with no extension at all. Portal behavior isn't something QET controls or can reliably detect via environment variables -- it depends on the desktop's actual portal implementation/version. Rather than guessing per-environment, normalize unconditionally: strip any existing .qet suffix (case-insensitive) and re-append exactly one. This produces the correct single extension whether or not the dialog already added it, on every environment. Verified: clean rebuild, only the intended object file recompiled and linked successfully. Wrote a standalone test of the normalization logic covering no-extension, already-has-extension, uppercase-extension, and a literal dot in the base filename -- all four produced exactly one correct ".qet" suffix with no double-extension and no missing extension. Not verified: the actual Snap-sandboxed portal dialog behavior itself, since building/running the Snap package and testing its file-save dialog under a portal is outside what's practical to set up in this sandbox. Confidence rests on the fix removing the environment-guessing entirely in favor of unconditional, dialog-implementation-agnostic normalization, which is correct regardless of what the underlying dialog does. --- sources/projectview.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/sources/projectview.cpp b/sources/projectview.cpp index fa348277b..b1bcc5077 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -345,11 +345,19 @@ QString ProjectView::askUserForFilePath(bool assign) { // if no filepath is provided, return an empty string if (filepath.isEmpty()) return(filepath); - // if the name does not end with the .qet extension and we're _not_ using xdg-desktop-portal, append it - bool usesPortal = - qEnvironmentVariableIsSet("FLATPAK_ID") || - qEnvironmentVariableIsSet("SNAP_NAME"); - if (!filepath.endsWith(".qet", Qt::CaseInsensitive) && !usesPortal) filepath += ".qet"; + // Ensure the path ends with exactly one .qet extension, regardless of + // whether the active file dialog already appended one. Whether it does + // depends on which backend actually shows the dialog (Qt's own vs. the + // xdg-desktop-portal used by sandboxed Snap/Flatpak builds), and that + // isn't reliably predictable from environment variables alone -- an + // earlier attempt at that (only appending when *not* Snap/Flatpak, + // assuming the portal always appends it) left Snap saves with no + // extension at all whenever the portal didn't (bugtracker #270). + // Stripping any existing suffix first and re-appending it once is + // correct either way. + if (filepath.endsWith(".qet", Qt::CaseInsensitive)) + filepath.chop(4); + filepath += ".qet"; if (assign) { // assign the provided filepath to the currently edited project