From e6776bcfe5d181fcbe420049b45e4487118ef722 Mon Sep 17 00:00:00 2001 From: Dalton Messmer Date: Wed, 23 Oct 2024 13:17:14 -0400 Subject: [PATCH] Remove usage of `QTextCodec` in Hydrogen Import plugin (#7562) * Remove QTextCodec QTextCodec was removed from Qt6 and is only available through the Qt5Compat module. QTextCodec was only used by the HydrogenImport plugin when importing old Hydrogen files that were saved using TinyXML before it supported UTF-8. HydrogenImport would use QTextCodec to try to get the current encoding from the locale, and then use that as a best guess for interpreting the XML data in the unspecified encoding it was saved in. None of this was ever reliable, since the encoding of the computer that saved the Hydrogen file might not be the same as the computer running LMMS and importing that file. There is no good solution here, so I decided to simply assume the old Hydrogen files are UTF-8 encoded. The worst that can happen is someone's ancient Hydrogen files containing non-ASCII text of some random encoding becomes mojibake'd after importing into LMMS, which is something that already could have happened. * Clean up a little --- plugins/HydrogenImport/CMakeLists.txt | 2 +- plugins/HydrogenImport/HydrogenImport.cpp | 3 ++- .../{local_file_mgr.cpp => LocalFileMng.cpp} | 10 +++------- plugins/HydrogenImport/LocalFileMng.h | 7 ------- 4 files changed, 6 insertions(+), 16 deletions(-) rename plugins/HydrogenImport/{local_file_mgr.cpp => LocalFileMng.cpp} (97%) diff --git a/plugins/HydrogenImport/CMakeLists.txt b/plugins/HydrogenImport/CMakeLists.txt index 27e8d6a4d..34f4d43ae 100644 --- a/plugins/HydrogenImport/CMakeLists.txt +++ b/plugins/HydrogenImport/CMakeLists.txt @@ -1,4 +1,4 @@ INCLUDE(BuildPlugin) -BUILD_PLUGIN(hydrogenimport HydrogenImport.cpp HydrogenImport.h local_file_mgr.cpp LocalFileMng.h) +BUILD_PLUGIN(hydrogenimport HydrogenImport.cpp HydrogenImport.h LocalFileMng.cpp LocalFileMng.h) diff --git a/plugins/HydrogenImport/HydrogenImport.cpp b/plugins/HydrogenImport/HydrogenImport.cpp index 144a2f5e7..6a81b507d 100644 --- a/plugins/HydrogenImport/HydrogenImport.cpp +++ b/plugins/HydrogenImport/HydrogenImport.cpp @@ -1,7 +1,8 @@ +#include "HydrogenImport.h" + #include #include "LocalFileMng.h" -#include "HydrogenImport.h" #include "Song.h" #include "Engine.h" #include "Instrument.h" diff --git a/plugins/HydrogenImport/local_file_mgr.cpp b/plugins/HydrogenImport/LocalFileMng.cpp similarity index 97% rename from plugins/HydrogenImport/local_file_mgr.cpp rename to plugins/HydrogenImport/LocalFileMng.cpp index 227440501..c4d11c7e2 100644 --- a/plugins/HydrogenImport/local_file_mgr.cpp +++ b/plugins/HydrogenImport/LocalFileMng.cpp @@ -1,12 +1,11 @@ -#include +#include "LocalFileMng.h" + #include #include #include #include -#include -#include "LocalFileMng.h" namespace lmms { @@ -197,10 +196,7 @@ QDomDocument LocalFileMng::openXmlDocument( const QString& filename ) return QDomDocument(); if( TinyXMLCompat ) { - QString enc = QTextCodec::codecForLocale()->name(); - if( enc == QString("System") ) { - enc = "UTF-8"; - } + const QString enc = "UTF-8"; // unknown encoding, so assume utf-8 and call it a day QByteArray line; QByteArray buf = QString("\n") .arg( enc ) diff --git a/plugins/HydrogenImport/LocalFileMng.h b/plugins/HydrogenImport/LocalFileMng.h index 0aaf7d1c8..1260dbfdd 100644 --- a/plugins/HydrogenImport/LocalFileMng.h +++ b/plugins/HydrogenImport/LocalFileMng.h @@ -14,12 +14,6 @@ namespace lmms class LocalFileMng { public: - LocalFileMng(); - ~LocalFileMng(); - std::vector getallPatternList(){ - return m_allPatternList; - } - static QString readXmlString( QDomNode , const QString& nodeName, const QString& defaultValue, bool bCanBeEmpty = false, bool bShouldExists = true , bool tinyXmlCompatMode = false); static float readXmlFloat( QDomNode , const QString& nodeName, float defaultValue, bool bCanBeEmpty = false, bool bShouldExists = true , bool tinyXmlCompatMode = false); static int readXmlInt( QDomNode , const QString& nodeName, int defaultValue, bool bCanBeEmpty = false, bool bShouldExists = true , bool tinyXmlCompatMode = false); @@ -27,7 +21,6 @@ public: static void convertFromTinyXMLString( QByteArray* str ); static bool checkTinyXMLCompatMode( const QString& filename ); static QDomDocument openXmlDocument( const QString& filename ); - std::vector m_allPatternList; };