Skip to content

Commit

Permalink
Remove usage of QTextCodec in Hydrogen Import plugin (#7562)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
messmerd authored Oct 23, 2024
1 parent b8b1dae commit e6776bc
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
2 changes: 1 addition & 1 deletion plugins/HydrogenImport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

3 changes: 2 additions & 1 deletion plugins/HydrogenImport/HydrogenImport.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "HydrogenImport.h"

#include <QDomDocument>

#include "LocalFileMng.h"
#include "HydrogenImport.h"
#include "Song.h"
#include "Engine.h"
#include "Instrument.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#include <sys/stat.h>
#include "LocalFileMng.h"

#include <cctype>

#include <QDomDocument>
#include <QFile>
#include <QLocale>
#include <QTextCodec>

#include "LocalFileMng.h"

namespace lmms
{
Expand Down Expand Up @@ -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("<?xml version='1.0' encoding='%1' ?>\n")
.arg( enc )
Expand Down
7 changes: 0 additions & 7 deletions plugins/HydrogenImport/LocalFileMng.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,13 @@ namespace lmms
class LocalFileMng
{
public:
LocalFileMng();
~LocalFileMng();
std::vector<QString> 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);
static bool readXmlBool( QDomNode , const QString& nodeName, bool defaultValue, bool bShouldExists = true , bool tinyXmlCompatMode = false );
static void convertFromTinyXMLString( QByteArray* str );
static bool checkTinyXMLCompatMode( const QString& filename );
static QDomDocument openXmlDocument( const QString& filename );
std::vector<QString> m_allPatternList;
};


Expand Down

0 comments on commit e6776bc

Please sign in to comment.