Georg Baum wrote:
Abdelrazak Younes wrote:
Is this the correct fix?
No. replaceEnvironmentPath() is supposed to work on internal paths already.
The rule is very simple: Paths with backslashes are not allowed in any part
of the code except when they are output to an external file or for display
purposes.
You have to call internalPath() as early as possible, in this case when
reading the name from the preferences file, but I don't know whether we
support paths with backslashes in the preferences file at all. If we do not
support that, then you need to make sure that internal_path() is called for
the result of all file dialogs (but I thought that Enrico did that
already).
The problem was not in reading the rc but when reading the Qt edit
boxes. This patch fixes that plus a few more. It also convert
internal_path() to unicode:
docstring internal_path(docstring const & p)
{
// FIXME UNICODE
return from_utf8(subst(get_long_path(to_utf8(p)), "\\", "/"));
}
Am I right here that this should solve problems with special characters
in filenames used within the GUI?
By the way, most of lyxrc is still using std::string for paths...
Abdel.
I
Abdel.
Index: frontends/qt4/QExternal.C
===================================================================
--- frontends/qt4/QExternal.C (revision 16743)
+++ frontends/qt4/QExternal.C (working copy)
@@ -455,7 +455,8 @@
{
InsetExternalParams params = controller().params();
- params.filename.set(internal_path(fromqstr(dialog_->fileED->text())),
+ /// FIXME: UNICODE
+ params.filename.set(to_utf8(internal_path(dialog_->fileED->text())),
kernel().bufferFilepath());
params.settemplate(controller().getTemplate(
Index: frontends/qt4/QGraphics.C
===================================================================
--- frontends/qt4/QGraphics.C (revision 16743)
+++ frontends/qt4/QGraphics.C (working copy)
@@ -270,7 +270,8 @@
{
InsetGraphicsParams & igp = controller().params();
- igp.filename.set(internal_path(fromqstr(dialog_->filename->text())),
+ /// FIXME: UNICODE
+ igp.filename.set(to_utf8(internal_path(dialog_->filename->text())),
kernel().bufferFilepath());
// the bb section
Index: frontends/qt4/QInclude.C
===================================================================
--- frontends/qt4/QInclude.C (revision 16743)
+++ frontends/qt4/QInclude.C (working copy)
@@ -103,7 +103,7 @@
{
InsetCommandParams params = controller().params();
- params["filename"] =
from_utf8(internal_path(fromqstr(dialog_->filenameED->text())));
+ params["filename"] = internal_path(dialog_->filenameED->text());
params.preview(dialog_->previewCB->isChecked());
int const item = dialog_->typeCO->currentIndex();
Index: frontends/qt4/QPrefsDialog.C
===================================================================
--- frontends/qt4/QPrefsDialog.C (revision 16743)
+++ frontends/qt4/QPrefsDialog.C (working copy)
@@ -176,12 +176,6 @@
}
-string const internal_path(QString const & input)
-{
- return lyx::support::os::internal_path(fromqstr(input));
-}
-
-
string const internal_path_list(QString const & input)
{
return lyx::support::os::internal_path_list(fromqstr(input));
@@ -254,8 +248,10 @@
{
// FIXME: can derive CB from the two EDs
rc.use_kbmap = keymapCB->isChecked();
- rc.primary_kbmap = internal_path(firstKeymapED->text());
- rc.secondary_kbmap = internal_path(secondKeymapED->text());
+
+ // FIXME: UNICODE
+ rc.primary_kbmap = to_utf8(internal_path(firstKeymapED->text()));
+ rc.secondary_kbmap = to_utf8(internal_path(secondKeymapED->text()));
}
@@ -683,13 +679,13 @@
void PrefPaths::apply(LyXRC & rc) const
{
- rc.document_path = internal_path(workingDirED->text());
- rc.template_path = internal_path(templateDirED->text());
- rc.backupdir_path = internal_path(backupDirED->text());
- rc.tempdir_path = internal_path(tempDirED->text());
+ rc.document_path = to_utf8(internal_path(workingDirED->text()));
+ rc.template_path = to_utf8(internal_path(templateDirED->text()));
+ rc.backupdir_path = to_utf8(internal_path(backupDirED->text()));
+ rc.tempdir_path = to_utf8(internal_path(tempDirED->text()));
rc.path_prefix = internal_path_list(pathPrefixED->text());
// FIXME: should be a checkbox only
- rc.lyxpipes = internal_path(lyxserverDirED->text());
+ rc.lyxpipes = to_utf8(internal_path(lyxserverDirED->text()));
}
@@ -707,7 +703,7 @@
void PrefPaths::select_templatedir()
{
docstring file(form_->controller().browsedir(
- qstring_to_ucs4(templateDirED->text()),
+ internal_path(templateDirED->text()),
_("Select a document templates directory")));
if (!file.empty())
templateDirED->setText(toqstr(file));
@@ -717,7 +713,7 @@
void PrefPaths::select_tempdir()
{
docstring file(form_->controller().browsedir(
- qstring_to_ucs4(tempDirED->text()),
+ internal_path(tempDirED->text()),
_("Select a temporary directory")));
if (!file.empty())
tempDirED->setText(toqstr(file));
@@ -727,7 +723,7 @@
void PrefPaths::select_backupdir()
{
docstring file(form_->controller().browsedir(
- qstring_to_ucs4(backupDirED->text()),
+ internal_path(backupDirED->text()),
_("Select a backups directory")));
if (!file.empty())
backupDirED->setText(toqstr(file));
@@ -737,7 +733,7 @@
void PrefPaths::select_workingdir()
{
docstring file(form_->controller().browsedir(
- qstring_to_ucs4(workingDirED->text()),
+ internal_path(workingDirED->text()),
_("Select a document directory")));
if (!file.empty())
workingDirED->setText(toqstr(file));
@@ -747,7 +743,7 @@
void PrefPaths::select_lyxpipe()
{
docstring file(form_->controller().browse(
- qstring_to_ucs4(lyxserverDirED->text()),
+ internal_path(lyxserverDirED->text()),
_("Give a filename for the LyX server pipe")));
if (!file.empty())
lyxserverDirED->setText(toqstr(file));
@@ -811,7 +807,7 @@
rc.isp_esc_chars = fromqstr(escapeCharactersED->text());
rc.isp_use_esc_chars = !rc.isp_esc_chars.empty();
// FIXME: remove isp_use_pers_dict
- rc.isp_pers_dict = internal_path(persDictionaryED->text());
+ rc.isp_pers_dict = to_utf8(internal_path(persDictionaryED->text()));
rc.isp_use_pers_dict = !rc.isp_pers_dict.empty();
rc.isp_accept_compound = compoundWordCB->isChecked();
rc.isp_use_input_encoding = inputEncodingCB->isChecked();
@@ -849,7 +845,8 @@
void PrefSpellchecker::select_dict()
{
- docstring
file(form_->controller().browsedict(qstring_to_ucs4(persDictionaryED->text())));
+ docstring file(form_->controller().browsedict(
+ internal_path(persDictionaryED->text())));
if (!file.empty())
persDictionaryED->setText(toqstr(file));
}
@@ -1606,7 +1603,7 @@
rc.print_oddpage_flag = fromqstr(printerOddED->text());
rc.print_collcopies_flag = fromqstr(printerCollatedED->text());
rc.print_landscape_flag = fromqstr(printerLandscapeED->text());
- rc.print_to_file = internal_path(printerToFileED->text());
+ rc.print_to_file = to_utf8(internal_path(printerToFileED->text()));
rc.print_extra_options = fromqstr(printerExtraED->text());
rc.print_spool_printerprefix = fromqstr(printerSpoolPrefixED->text());
rc.print_paper_dimension_flag = fromqstr(printerPaperSizeED->text());
@@ -1677,8 +1674,8 @@
void PrefUserInterface::apply(LyXRC & rc) const
{
- rc.ui_file = internal_path(uiFileED->text());
- rc.bind_file = internal_path(bindFileED->text());
+ rc.ui_file = to_utf8(internal_path(uiFileED->text()));
+ rc.bind_file = to_utf8(internal_path(bindFileED->text()));
rc.use_lastfilepos = restoreCursorCB->isChecked();
rc.load_session = loadSessionCB->isChecked();
if (loadWindowSizeCB->isChecked()) {
@@ -1723,7 +1720,9 @@
void PrefUserInterface::select_ui()
{
- docstring
file(form_->controller().browseUI(qstring_to_ucs4(uiFileED->text())));
+ docstring const name =
+ internal_path(uiFileED->text());
+ docstring file(form_->controller().browseUI(name));
if (!file.empty())
uiFileED->setText(toqstr(file));
}
@@ -1731,7 +1730,9 @@
void PrefUserInterface::select_bind()
{
- docstring
file(form_->controller().browsebind(qstring_to_ucs4(bindFileED->text())));
+ docstring const name =
+ internal_path(bindFileED->text());
+ docstring file(form_->controller().browsebind(name));
if (!file.empty())
bindFileED->setText(toqstr(file));
}
Index: frontends/qt4/qt_helpers.C
===================================================================
--- frontends/qt4/qt_helpers.C (revision 16743)
+++ frontends/qt4/qt_helpers.C (working copy)
@@ -17,6 +17,7 @@
#include "lengthcommon.h"
#include "gettext.h"
+#include "support/os.h"
#include "support/lstrings.h"
#include "support/convert.h"
@@ -179,4 +180,10 @@
}
+docstring const internal_path(QString const & input)
+{
+ return lyx::support::os::internal_path(qstring_to_ucs4(input));
+}
+
+
} // namespace lyx
Index: frontends/qt4/qt_helpers.h
===================================================================
--- frontends/qt4/qt_helpers.h (revision 16743)
+++ frontends/qt4/qt_helpers.h (working copy)
@@ -59,6 +59,9 @@
*/
QString const qt_(std::string const & str);
+///
+docstring const internal_path(QString const & input);
+
} // namespace lyx
#endif // QTHELPERS_H
Index: support/os.h
===================================================================
--- support/os.h (revision 16743)
+++ support/os.h (working copy)
@@ -14,6 +14,8 @@
#ifndef OS_H
#define OS_H
+#include "support/docstring.h"
+
#include <string>
@@ -50,6 +52,9 @@
/// Converts a host OS style path to unix style.
std::string internal_path(std::string const & p);
+/// Converts a host OS style path to unix style.
+docstring internal_path(docstring const & p);
+
/// Converts a unix style path list to host OS style.
std::string external_path_list(std::string const & p);
Index: support/os_cygwin.C
===================================================================
--- support/os_cygwin.C (revision 16743)
+++ support/os_cygwin.C (working copy)
@@ -211,6 +211,13 @@
}
+docstring internal_path(docstring const & p)
+{
+ // FIXME UNICODE
+ return from_utf8(convert_path(to_utf8(p), PathStyle(posix)));
+}
+
+
string external_path_list(string const & p)
{
return convert_path_list(p, PathStyle(posix));
Index: support/os_unix.C
===================================================================
--- support/os_unix.C (revision 16743)
+++ support/os_unix.C (working copy)
@@ -70,6 +70,12 @@
}
+docstring internal_path(docstring const & p)
+{
+ return p;
+}
+
+
string external_path_list(string const & p)
{
return p;
Index: support/os_win32.C
===================================================================
--- support/os_win32.C (revision 16743)
+++ support/os_win32.C (working copy)
@@ -16,6 +16,7 @@
#include "support/os.h"
#include "support/os_win32.h"
+#include "support/docstring.h"
#include "support/lstrings.h"
#include "support/filetools.h"
#include "support/package.h"
@@ -240,6 +241,13 @@
}
+docstring internal_path(docstring const & p)
+{
+ // FIXME UNICODE
+ return from_utf8(subst(get_long_path(to_utf8(p)), "\\", "/"));
+}
+
+
string external_path_list(string const & p)
{
return subst(p, '/', '\\');