diff --git a/mscore/importgtp.cpp b/mscore/importgtp.cpp index 3df4d6d188..224d13ae6c 100644 --- a/mscore/importgtp.cpp +++ b/mscore/importgtp.cpp @@ -41,6 +41,7 @@ #include "libmscore/tremolobar.h" #include "libmscore/segment.h" #include "libmscore/rehearsalmark.h" +#include "preferences.h" namespace Ms { @@ -76,6 +77,7 @@ GuitarPro::GuitarPro(Score* s, int v) { score = s; version = v; + _codec = QTextCodec::codecForName(preferences.importCharsetGP.toLatin1()); } GuitarPro::~GuitarPro() @@ -142,7 +144,10 @@ QString GuitarPro::readPascalString(int n) read(s, l); s[l] = 0; skip(n - l); - return QString(s); + if(_codec) + return _codec->toUnicode(s); + else + return QString(s); } //--------------------------------------------------------- @@ -155,7 +160,10 @@ QString GuitarPro::readWordPascalString() char c[l+1]; read(c, l); c[l] = 0; - return QString::fromLocal8Bit(c); + if(_codec) + return _codec->toUnicode(c); + else + return QString::fromLocal8Bit(c); } //--------------------------------------------------------- @@ -168,7 +176,10 @@ QString GuitarPro::readBytePascalString() char c[l+1]; read(c, l); c[l] = 0; - return QString::fromLocal8Bit(c); + if(_codec) + return _codec->toUnicode(c); + else + return QString::fromLocal8Bit(c); } //--------------------------------------------------------- @@ -186,7 +197,10 @@ QString GuitarPro::readDelphiString() char c[l + 1]; read(c, l); c[l] = 0; - return QString::fromLatin1(c); + if(_codec) + return _codec->toUnicode(c); + else + return QString::fromLatin1(c); } //--------------------------------------------------------- diff --git a/mscore/importgtp.h b/mscore/importgtp.h index a7b40bf788..3d99cfc25a 100644 --- a/mscore/importgtp.h +++ b/mscore/importgtp.h @@ -74,6 +74,8 @@ class GuitarPro { QFile* f; int curPos; + QTextCodec* _codec; + void skip(qint64 len); void read(void* p, qint64 len); int readUChar(); diff --git a/mscore/importove.cpp b/mscore/importove.cpp index 0f91a9dc78..ea06b42465 100644 --- a/mscore/importove.cpp +++ b/mscore/importove.cpp @@ -2391,7 +2391,7 @@ Score::FileError importOve(Score* score, const QString& name) { oveFile.close(); - oveSong.setTextCodecName(preferences.importCharset); + oveSong.setTextCodecName(preferences.importCharsetOve); oveLoader->setOve(&oveSong); oveLoader->setFileStream((unsigned char*) buffer.data(), buffer.size()); bool result = oveLoader->load(); diff --git a/mscore/preferences.cpp b/mscore/preferences.cpp index f1032b0a3c..9464b95cd1 100644 --- a/mscore/preferences.cpp +++ b/mscore/preferences.cpp @@ -172,7 +172,8 @@ void Preferences::init() checkUpdateStartup = 0; followSong = true; - importCharset = "GBK"; + importCharsetOve = "GBK"; + importCharsetGP = "UTF-8"; importStyleFile = ""; shortestNote = MScore::division/4; @@ -313,7 +314,8 @@ void Preferences::write() s.setValue("defaultPlayDuration", MScore::defaultPlayDuration); s.setValue("importStyleFile", importStyleFile); s.setValue("shortestNote", shortestNote); - s.setValue("importCharset", importCharset); + s.setValue("importCharsetOve", importCharsetOve); + s.setValue("importCharsetGP", importCharsetGP); s.setValue("warnPitchRange", MScore::warnPitchRange); s.setValue("followSong", followSong); @@ -453,7 +455,8 @@ void Preferences::read() MScore::defaultPlayDuration = s.value("defaultPlayDuration", MScore::defaultPlayDuration).toInt(); importStyleFile = s.value("importStyleFile", importStyleFile).toString(); shortestNote = s.value("shortestNote", shortestNote).toInt(); - importCharset = s.value("importCharset", importCharset).toString(); + importCharsetOve = s.value("importCharsetOve", importCharsetOve).toString(); + importCharsetGP = s.value("importCharsetGP", importCharsetGP).toString(); MScore::warnPitchRange = s.value("warnPitchRange", MScore::warnPitchRange).toBool(); followSong = s.value("followSong", followSong).toBool(); @@ -947,14 +950,18 @@ void PreferenceDialog::updateValues() useImportBuildinStyle->setChecked(prefs.importStyleFile.isEmpty()); useImportStyleFile->setChecked(!prefs.importStyleFile.isEmpty()); - importCharsetList->clear(); QList charsets = QTextCodec::availableCodecs(); qSort(charsets.begin(), charsets.end()); int idx = 0; + importCharsetListOve->clear(); + importCharsetListGP->clear(); foreach (QByteArray charset, charsets) { - importCharsetList->addItem(charset); - if (charset == prefs.importCharset) - importCharsetList->setCurrentIndex(idx); + importCharsetListOve->addItem(charset); + importCharsetListGP->addItem(charset); + if (charset == prefs.importCharsetOve) + importCharsetListOve->setCurrentIndex(idx); + if (charset == prefs.importCharsetGP) + importCharsetListGP->setCurrentIndex(idx); idx++; } @@ -1397,7 +1404,8 @@ void PreferenceDialog::apply() } prefs.shortestNote = ticks; - prefs.importCharset = importCharsetList->currentText(); + prefs.importCharsetOve = importCharsetListOve->currentText(); + prefs.importCharsetGP = importCharsetListGP->currentText(); MScore::warnPitchRange = warnPitchRange->isChecked(); prefs.useOsc = oscServer->isChecked(); diff --git a/mscore/preferences.h b/mscore/preferences.h index 672739e66f..986404baaa 100644 --- a/mscore/preferences.h +++ b/mscore/preferences.h @@ -144,7 +144,8 @@ struct Preferences { int checkUpdateStartup; bool followSong; - QString importCharset; + QString importCharsetOve; + QString importCharsetGP; QString importStyleFile; int shortestNote; // for midi input MidiImportOperations midiImportOperations; diff --git a/mscore/prefsdialog.ui b/mscore/prefsdialog.ui index 049108aa43..a2935ac77c 100644 --- a/mscore/prefsdialog.ui +++ b/mscore/prefsdialog.ui @@ -2361,34 +2361,35 @@ - Character Set used when import non-unicode strings. (For binary file import) + Character set used when importing binary files false - + - - - - 0 - 0 - - - - Character Set: - - - - - - - - 0 - 0 - - - + + + + + Overture import character set: + + + + + + + + + + Guitar Pro import character set: + + + + + + +