diff --git a/widget/gtk/nsDeviceContextSpecG.cpp b/widget/gtk/nsDeviceContextSpecG.cpp index eac145e2b244..1876e90dca49 100644 --- a/widget/gtk/nsDeviceContextSpecG.cpp +++ b/widget/gtk/nsDeviceContextSpecG.cpp @@ -411,20 +411,26 @@ nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const nsAString& aPrinterNa NS_ENSURE_ARG_POINTER(aPrintSettings); - /* Set filename */ - nsAutoCString filename; - const char *path; - - if (!(path = PR_GetEnv("PWD"))) - path = PR_GetEnv("HOME"); - - if (path) - filename = nsPrintfCString("%s/mozilla.pdf", path); - else - filename.AssignLiteral("mozilla.pdf"); + // Set a default file name. + nsAutoString filename; + nsresult rv = aPrintSettings->GetToFileName(filename); + if (NS_FAILED(rv) || filename.IsEmpty()) { + const char* path = PR_GetEnv("PWD"); + if (!path) { + path = PR_GetEnv("HOME"); + } - DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get())); - aPrintSettings->SetToFileName(NS_ConvertUTF8toUTF16(filename)); + if (path) { + CopyUTF8toUTF16(path, filename); + filename.AppendLiteral("/mozilla.pdf"); + } else { + filename.AssignLiteral("mozilla.pdf"); + } + + DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", + NS_ConvertUTF16toUTF8(filename).get())); + aPrintSettings->SetToFileName(filename); + } aPrintSettings->SetIsInitializedFromPrinter(true);