@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
cmake_minimum_required(VERSION 3.7)
|
||||
|
||||
if(HAVE_TRANSLATIONS)
|
||||
include(../cmake/Translations.cmake)
|
||||
@@ -1145,6 +1145,11 @@ if(FREEBSD)
|
||||
target_link_libraries(strawberry_lib PRIVATE iconv)
|
||||
endif()
|
||||
|
||||
if(HAVE_ICU)
|
||||
target_include_directories(strawberry_lib SYSTEM PRIVATE ${ICU_INCLUDE_DIRS})
|
||||
target_link_libraries(strawberry_lib PRIVATE ${ICU_LIBRARIES})
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(strawberry_lib PRIVATE
|
||||
"-framework AppKit"
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#cmakedefine HAVE_MUSICBRAINZ
|
||||
#cmakedefine HAVE_GLOBALSHORTCUTS
|
||||
#cmakedefine HAVE_X11_GLOBALSHORTCUTS
|
||||
#cmakedefine HAVE_ICU
|
||||
|
||||
#cmakedefine USE_INSTALL_PREFIX
|
||||
|
||||
#cmakedefine HAVE_GSTREAMER
|
||||
|
||||
@@ -23,7 +23,12 @@
|
||||
|
||||
#include <memory>
|
||||
#include <cstdlib>
|
||||
#include <iconv.h>
|
||||
|
||||
#ifdef HAVE_ICU
|
||||
# include <unicode/translit.h>
|
||||
#else
|
||||
# include <iconv.h>
|
||||
#endif
|
||||
|
||||
#include <QtGlobal>
|
||||
#include <QApplication>
|
||||
@@ -786,16 +791,39 @@ QString DesktopEnvironment() {
|
||||
|
||||
}
|
||||
|
||||
QString UnicodeToAscii(const QString &unicode) {
|
||||
#ifdef HAVE_ICU
|
||||
|
||||
QString Transliterate(const QString &accented_str) {
|
||||
|
||||
UErrorCode errorcode = U_ZERO_ERROR;
|
||||
std::unique_ptr<icu::Transliterator> transliterator;
|
||||
transliterator.reset(icu::Transliterator::createInstance("Any-Latin; Latin-ASCII;", UTRANS_FORWARD, errorcode));
|
||||
|
||||
if (!transliterator) return accented_str;
|
||||
|
||||
QByteArray accented_data = accented_str.toUtf8();
|
||||
icu::UnicodeString ustring = icu::UnicodeString(accented_data.constData());
|
||||
transliterator->transliterate(ustring);
|
||||
|
||||
std::string unaccented_str;
|
||||
ustring.toUTF8String(unaccented_str);
|
||||
|
||||
return QString::fromStdString(unaccented_str);
|
||||
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
QString Transliterate(const QString &accented_str) {
|
||||
|
||||
#ifdef LC_ALL
|
||||
setlocale(LC_ALL, "");
|
||||
#endif
|
||||
|
||||
iconv_t conv = iconv_open("ASCII//TRANSLIT", "UTF-8");
|
||||
if (conv == reinterpret_cast<iconv_t>(-1)) return unicode;
|
||||
if (conv == reinterpret_cast<iconv_t>(-1)) return accented_str;
|
||||
|
||||
QByteArray utf8 = unicode.toUtf8();
|
||||
QByteArray utf8 = accented_str.toUtf8();
|
||||
|
||||
size_t input_len = utf8.length() + 1;
|
||||
char *input_ptr = new char[input_len];
|
||||
@@ -817,8 +845,11 @@ QString UnicodeToAscii(const QString &unicode) {
|
||||
delete[] output_ptr;
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
QString MacAddress() {
|
||||
|
||||
QString ret;
|
||||
|
||||
@@ -132,7 +132,7 @@ QString GetRandomString(const int len, const QString &UseCharacters);
|
||||
|
||||
QString DesktopEnvironment();
|
||||
|
||||
QString UnicodeToAscii(const QString &unicode);
|
||||
QString Transliterate(const QString &accented_str);
|
||||
|
||||
QString MacAddress();
|
||||
|
||||
|
||||
@@ -110,7 +110,7 @@ QString AlbumCoverLoader::AlbumCoverFilename(QString artist, QString album, cons
|
||||
album.remove('/').remove('\\');
|
||||
|
||||
QString filename = artist + "-" + album;
|
||||
filename = Utilities::UnicodeToAscii(filename.toLower());
|
||||
filename = Utilities::Transliterate(filename.toLower());
|
||||
filename = filename.replace(' ', '-')
|
||||
.replace("--", "-")
|
||||
.remove(OrganizeFormat::kInvalidFatCharacters)
|
||||
|
||||
@@ -128,7 +128,7 @@ QString OrganizeFormat::GetFilenameForSong(const Song &song, QString extension)
|
||||
}
|
||||
|
||||
if (remove_problematic_) filename = filename.remove(kProblematicCharacters);
|
||||
if (remove_non_fat_ || (remove_non_ascii_ && !allow_ascii_ext_)) filename = Utilities::UnicodeToAscii(filename);
|
||||
if (remove_non_fat_ || (remove_non_ascii_ && !allow_ascii_ext_)) filename = Utilities::Transliterate(filename);
|
||||
if (remove_non_fat_) filename = filename.remove(kInvalidFatCharacters);
|
||||
|
||||
if (remove_non_ascii_) {
|
||||
|
||||
Reference in New Issue
Block a user