mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Use QFile::{encode,decode}Name for file names
And make them use UTF-8 on Windows instead of the local 8 bit encoding. This will also get us the proper NFD encoding on OS X. Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
dbdf50d03c
commit
8eb6dfdb02
4 changed files with 21 additions and 5 deletions
16
qt-gui.cpp
16
qt-gui.cpp
|
@ -66,6 +66,18 @@ const char *getSetting(QSettings &s, QString name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef Q_OS_WIN
|
||||||
|
static QByteArray encodeUtf8(const QString &fname)
|
||||||
|
{
|
||||||
|
return fname.toUtf8();
|
||||||
|
}
|
||||||
|
|
||||||
|
static QString decodeUtf8(const QByteArray &fname)
|
||||||
|
{
|
||||||
|
return QString::fromUtf8(fname);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
void init_ui(int *argcp, char ***argvp)
|
void init_ui(int *argcp, char ***argvp)
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
|
@ -82,6 +94,10 @@ void init_ui(int *argcp, char ***argvp)
|
||||||
// 106 is "UTF-8", this is faster than lookup by name
|
// 106 is "UTF-8", this is faster than lookup by name
|
||||||
// [http://www.iana.org/assignments/character-sets/character-sets.xml]
|
// [http://www.iana.org/assignments/character-sets/character-sets.xml]
|
||||||
QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106));
|
QTextCodec::setCodecForCStrings(QTextCodec::codecForMib(106));
|
||||||
|
# ifdef Q_OS_WIN
|
||||||
|
QFile::setDecodingFunction(decodeUtf8);
|
||||||
|
QFile::setEncodingFunction(encodeUtf8);
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
QCoreApplication::setOrganizationName("Subsurface");
|
QCoreApplication::setOrganizationName("Subsurface");
|
||||||
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
QCoreApplication::setOrganizationDomain("subsurface.hohndel.org");
|
||||||
|
|
|
@ -765,7 +765,7 @@ void DiveListView::saveSelectedDivesAs()
|
||||||
settings.setValue("LastDir",fileInfo.dir().path());
|
settings.setValue("LastDir",fileInfo.dir().path());
|
||||||
settings.endGroup();
|
settings.endGroup();
|
||||||
|
|
||||||
QByteArray bt = fileName.toLocal8Bit();
|
QByteArray bt = QFile::encodeName(fileName);
|
||||||
save_dives_logic(bt.data(), TRUE);
|
save_dives_logic(bt.data(), TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -825,7 +825,7 @@ void MainWindow::importFiles(const QStringList fileNames)
|
||||||
QByteArray fileNamePtr;
|
QByteArray fileNamePtr;
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
for (int i = 0; i < fileNames.size(); ++i) {
|
for (int i = 0; i < fileNames.size(); ++i) {
|
||||||
fileNamePtr = fileNames.at(i).toUtf8();
|
fileNamePtr = QFile::encodeName(fileNames.at(i));
|
||||||
parse_file(fileNamePtr.data(), &error);
|
parse_file(fileNamePtr.data(), &error);
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
showError(error);
|
showError(error);
|
||||||
|
@ -846,7 +846,7 @@ void MainWindow::loadFiles(const QStringList fileNames)
|
||||||
QByteArray fileNamePtr;
|
QByteArray fileNamePtr;
|
||||||
|
|
||||||
for (int i = 0; i < fileNames.size(); ++i) {
|
for (int i = 0; i < fileNames.size(); ++i) {
|
||||||
fileNamePtr = fileNames.at(i).toUtf8();
|
fileNamePtr = QFile::encodeName(fileNames.at(i));
|
||||||
parse_file(fileNamePtr.data(), &error);
|
parse_file(fileNamePtr.data(), &error);
|
||||||
set_filename(fileNamePtr.data(), TRUE);
|
set_filename(fileNamePtr.data(), TRUE);
|
||||||
setTitle(MWTF_FILENAME);
|
setTitle(MWTF_FILENAME);
|
||||||
|
|
|
@ -759,7 +759,7 @@ void DivelogsDeWebServices::downloadFinished()
|
||||||
if (!zip)
|
if (!zip)
|
||||||
::close(duppedfd);
|
::close(duppedfd);
|
||||||
#else
|
#else
|
||||||
struct zip *zip = zip_open(zipFile.fileName().toUtf8().data(), 0, &errorcode);
|
struct zip *zip = zip_open(QFile::encodeName(zipFile.fileName()), 0, &errorcode);
|
||||||
#endif
|
#endif
|
||||||
if (!zip) {
|
if (!zip) {
|
||||||
char buf[512];
|
char buf[512];
|
||||||
|
@ -855,7 +855,7 @@ void DivelogsDeWebServices::buttonClicked(QAbstractButton* button)
|
||||||
}
|
}
|
||||||
/* parse file and import dives */
|
/* parse file and import dives */
|
||||||
char *error = NULL;
|
char *error = NULL;
|
||||||
parse_file(zipFile.fileName().toUtf8().data(), &error);
|
parse_file(QFile::encodeName(zipFile.fileName()), &error);
|
||||||
if (error != NULL) {
|
if (error != NULL) {
|
||||||
mainWindow()->showError(error);
|
mainWindow()->showError(error);
|
||||||
free(error);
|
free(error);
|
||||||
|
|
Loading…
Add table
Reference in a new issue