issue #1027 use unicode filepaths

This commit is contained in:
Sebastian Hoogen
2014-09-21 23:45:32 +02:00
committed by wmayer
parent 7db2cdc008
commit 01cf0f5872
28 changed files with 396 additions and 243 deletions

View File

@@ -479,7 +479,7 @@ void Application::open(const char* FileName, const char* Module)
wc.setIgnoreEvents(WaitCursor::NoEvents);
Base::FileInfo File(FileName);
string te = File.extension();
string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str());
// if the active document is empty and not modified, close it
// in case of an automatically created empty document at startup
App::Document* act = App::GetApplication().getActiveDocument();
@@ -494,7 +494,7 @@ void Application::open(const char* FileName, const char* Module)
Command::doCommand(Command::App, "import %s", Module);
try {
// load the file with the module
Command::doCommand(Command::App, "%s.open(\"%s\")", Module, File.filePath().c_str());
Command::doCommand(Command::App, "%s.open(u\"%s\")", Module, unicodepath.c_str());
// ViewFit
if (!File.hasExtension("FCStd") && sendHasMsgToActiveView("ViewFit")) {
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
@@ -525,6 +525,7 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch
wc.setIgnoreEvents(WaitCursor::NoEvents);
Base::FileInfo File(FileName);
std::string te = File.extension();
string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str());
if (Module != 0) {
// issue module loading
@@ -533,14 +534,14 @@ void Application::importFrom(const char* FileName, const char* DocName, const ch
try {
// load the file with the module
if (File.hasExtension("FCStd")) {
Command::doCommand(Command::App, "%s.open(\"%s\")"
, Module, File.filePath().c_str());
Command::doCommand(Command::App, "%s.open(u\"%s\")"
, Module, unicodepath.c_str());
if (activeDocument())
activeDocument()->setModified(false);
}
else {
Command::doCommand(Command::App, "%s.insert(\"%s\",\"%s\")"
, Module, File.filePath().c_str(), DocName);
Command::doCommand(Command::App, "%s.insert(u\"%s\",\"%s\")"
, Module, unicodepath.c_str(), DocName);
ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath
("User parameter:BaseApp/Preferences/View");
if (hGrp->GetBool("AutoFitToView", true))
@@ -570,6 +571,7 @@ void Application::exportTo(const char* FileName, const char* DocName, const char
WaitCursor wc;
Base::FileInfo File(FileName);
std::string te = File.extension();
string unicodepath = Base::Tools::escapedUnicodeFromUtf8(File.filePath().c_str());
if (Module != 0) {
try {
@@ -588,7 +590,7 @@ void Application::exportTo(const char* FileName, const char* DocName, const char
}
str << "import " << Module << std::endl;
str << Module << ".export(__objs__,\"" << File.filePath() << "\")" << std::endl;
str << Module << ".export(__objs__,u\"" << unicodepath << "\")" << std::endl;
str << "del __objs__" << std::endl;
std::string code = str.str();

View File

@@ -233,11 +233,13 @@ PyObject* Application::sShowObject(PyObject * /*self*/, PyObject *args,PyObject
PyObject* Application::sOpen(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
// only used to open Python files
const char* Name;
if (!PyArg_ParseTuple(args, "s",&Name))
char* Name;
if (!PyArg_ParseTuple(args, "et","utf-8",&Name))
return NULL;
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
PY_TRY {
QString fileName = QString::fromUtf8(Name);
QString fileName = QString::fromUtf8(Utf8Name.c_str());
QFileInfo fi;
fi.setFile(fileName);
QString ext = fi.completeSuffix().toLower();
@@ -291,13 +293,15 @@ PyObject* Application::sOpen(PyObject * /*self*/, PyObject *args,PyObject * /*kw
PyObject* Application::sInsert(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
const char* Name;
const char* DocName=0;
if (!PyArg_ParseTuple(args, "s|s",&Name,&DocName))
char* Name;
char* DocName=0;
if (!PyArg_ParseTuple(args, "et|s","utf-8",&Name,&DocName))
return NULL;
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
PY_TRY {
QString fileName = QString::fromUtf8(Name);
QString fileName = QString::fromUtf8(Utf8Name.c_str());
QFileInfo fi;
fi.setFile(fileName);
QString ext = fi.completeSuffix().toLower();
@@ -352,9 +356,11 @@ PyObject* Application::sInsert(PyObject * /*self*/, PyObject *args,PyObject * /*
PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
PyObject* object;
const char* filename;
if (!PyArg_ParseTuple(args, "Os",&object,&filename))
char* Name;
if (!PyArg_ParseTuple(args, "Oet",&object,"utf-8",&Name))
return NULL;
std::string Utf8Name = std::string(Name);
PyMem_Free(Name);
PY_TRY {
App::Document* doc = 0;
@@ -370,7 +376,7 @@ PyObject* Application::sExport(PyObject * /*self*/, PyObject *args,PyObject * /*
// get the view that belongs to the found document
if (doc) {
QString fileName = QString::fromUtf8(filename);
QString fileName = QString::fromUtf8(Utf8Name.c_str());
QFileInfo fi;
fi.setFile(fileName);
QString ext = fi.completeSuffix().toLower();
@@ -687,9 +693,10 @@ PyObject* Application::sActiveWorkbenchHandler(PyObject * /*self*/, PyObject *ar
PyObject* Application::sAddResPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
char* filePath;
if (!PyArg_ParseTuple(args, "s", &filePath)) // convert args: Python->C
if (!PyArg_ParseTuple(args, "et", "utf-8", &filePath)) // convert args: Python->C
return NULL; // NULL triggers exception
QString path = QString::fromUtf8(filePath);
PyMem_Free(filePath);
if (QDir::isRelativePath(path)) {
// Home path ends with '/'
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
@@ -705,9 +712,10 @@ PyObject* Application::sAddResPath(PyObject * /*self*/, PyObject *args,PyObject
PyObject* Application::sAddLangPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
char* filePath;
if (!PyArg_ParseTuple(args, "s", &filePath)) // convert args: Python->C
if (!PyArg_ParseTuple(args, "et", "utf-8", &filePath)) // convert args: Python->C
return NULL; // NULL triggers exception
QString path = QString::fromUtf8(filePath);
PyMem_Free(filePath);
if (QDir::isRelativePath(path)) {
// Home path ends with '/'
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());
@@ -722,9 +730,10 @@ PyObject* Application::sAddLangPath(PyObject * /*self*/, PyObject *args,PyObject
PyObject* Application::sAddIconPath(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
char* filePath;
if (!PyArg_ParseTuple(args, "s", &filePath)) // convert args: Python->C
return NULL; // NULL triggers exception
if (!PyArg_ParseTuple(args, "et", "utf-8", &filePath)) // convert args: Python->C
return NULL; // NULL triggers exception
QString path = QString::fromUtf8(filePath);
PyMem_Free(filePath);
if (QDir::isRelativePath(path)) {
// Home path ends with '/'
QString home = QString::fromUtf8(App::GetApplication().GetHomePath());