On Sun, Dec 03, 2006 at 04:15:47PM +0100, Michael Gerz wrote:

> Hi,
> 
> there is a real show stopper on Windows: If you save an existing file 
> under a new name or if you open a new file, LyX crashes. The reason is 
> that LyXFileDialog (in src/frontends/qt4) returns a Windows-like file 
> name (bad) if the file name is non-existing, whereas it returns a 
> POSIX-like file name (good) if the user picks an existing name.
> 
> Unfortunately, I have no idea why this happens. Could anybody please help?
> 
> A thousand thanks in advance!!!

Does the attached patch help?

-- 
Enrico
Index: src/frontends/qt4/FileDialog.C
===================================================================
--- src/frontends/qt4/FileDialog.C      (revision 16161)
+++ src/frontends/qt4/FileDialog.C      (working copy)
@@ -20,6 +20,7 @@
 #include "gettext.h"
 
 #include "support/filefilterlist.h"
+#include "support/os.h"
 
 /** when this is defined, the code will use
  * QFileDialog::getOpenFileName and friends to create filedialogs.
@@ -44,6 +45,7 @@ using lyx::support::makeAbsPath;
 namespace lyx {
 
 using support::FileFilterList;
+using support::os::internal_path;
 using std::endl;
 
 
@@ -82,9 +84,9 @@ FileDialog::Result const FileDialog::sav
 #ifdef USE_NATIVE_FILEDIALOG
        docstring const startsWith
                = lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), 
lyx::to_utf8(path)));
-       result.second = qstring_to_ucs4(QFileDialog::getSaveFileName(
-               qApp->focusWidget(),
-               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) 
));
+       result.second = lyx::from_utf8(internal_path(fromqstr(
+               QFileDialog::getSaveFileName(qApp->focusWidget(),
+               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) 
))));
 #else
        LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
        dlg.setFileMode(QFileDialog::AnyFile);
@@ -97,7 +99,8 @@ FileDialog::Result const FileDialog::sav
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = qstring_to_ucs4(dlg.selectedFiles()[0]);
+               result.second = lyx::from_utf8(internal_path(
+                                       fromqstr(dlg.selectedFiles()[0])));
        dlg.hide();
 #endif
        return result;
@@ -117,9 +120,9 @@ FileDialog::Result const FileDialog::ope
 #ifdef USE_NATIVE_FILEDIALOG
        docstring const startsWith =
                lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), 
lyx::to_utf8(path)));
-       result.second = qstring_to_ucs4(QFileDialog::getOpenFileName(
-               qApp->focusWidget(), 
-               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) 
));
+       result.second = lyx::from_utf8(internal_path(fromqstr(
+               QFileDialog::getOpenFileName(qApp->focusWidget(), 
+               toqstr(title_), toqstr(startsWith), toqstr(filters.as_string()) 
))));
 #else
        LyXFileDialog dlg(title_, path, filters, private_->b1, private_->b2);
 
@@ -130,7 +133,8 @@ FileDialog::Result const FileDialog::ope
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = qstring_to_ucs4(dlg.selectedFiles()[0]);
+               result.second = lyx::from_utf8(internal_path(
+                                       fromqstr(dlg.selectedFiles()[0])));
        dlg.hide();
 #endif
        return result;
@@ -148,9 +152,9 @@ FileDialog::Result const FileDialog::ope
 #ifdef USE_NATIVE_FILEDIALOG
        docstring const startsWith
                = lyx::from_utf8(makeAbsPath(lyx::to_utf8(suggested), 
lyx::to_utf8(path)));
-       result.second = qstring_to_ucs4(QFileDialog::getExistingDirectory(
-               qApp->focusWidget(),
-               toqstr(title_),toqstr(startsWith) ));
+       result.second = lyx::from_utf8(internal_path(fromqstr(
+               QFileDialog::getExistingDirectory(qApp->focusWidget(),
+               toqstr(title_),toqstr(startsWith)))));
 #else
        FileFilterList const filter(_("Directories"));
 
@@ -165,7 +169,8 @@ FileDialog::Result const FileDialog::ope
        int res = dlg.exec();
        lyxerr[Debug::GUI] << "result " << res << endl;
        if (res == QDialog::Accepted)
-               result.second = qstring_to_ucs4(dlg.selectedFiles()[0]);
+               result.second = lyx::from_utf8(internal_path(
+                                       fromqstr(dlg.selectedFiles()[0])));
        dlg.hide();
 #endif
        return result;

Reply via email to