[users] Full name transliteration support for user creation
This commit is contained in:
parent
0bad5469fc
commit
48eae463cc
@ -21,6 +21,18 @@ if( LibPWQuality_FOUND )
|
|||||||
add_definitions( -DCHECK_PWQUALITY -DHAVE_LIBPWQUALITY )
|
add_definitions( -DCHECK_PWQUALITY -DHAVE_LIBPWQUALITY )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_package( ICU COMPONENTS uc i18n )
|
||||||
|
set_package_properties(
|
||||||
|
ICU PROPERTIES
|
||||||
|
PURPOSE "Transliteration support for full name to username conversion"
|
||||||
|
)
|
||||||
|
|
||||||
|
if( ICU_FOUND )
|
||||||
|
list( APPEND USER_EXTRA_LIB ICU::uc ICU::i18n )
|
||||||
|
include_directories( ${ICU_INCLUDE_DIRS} )
|
||||||
|
add_definitions( -DHAVE_ICU )
|
||||||
|
endif()
|
||||||
|
|
||||||
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
|
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
|
||||||
|
|
||||||
set( JOB_SRC
|
set( JOB_SRC
|
||||||
|
@ -23,6 +23,11 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QRegExp>
|
#include <QRegExp>
|
||||||
|
|
||||||
|
#ifdef HAVE_ICU
|
||||||
|
#include <unicode/translit.h>
|
||||||
|
#include <unicode/unistr.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
static const QRegExp USERNAME_RX( "^[a-z_][a-z0-9_-]*[$]?$" );
|
static const QRegExp USERNAME_RX( "^[a-z_][a-z0-9_-]*[$]?$" );
|
||||||
static constexpr const int USERNAME_MAX_LENGTH = 31;
|
static constexpr const int USERNAME_MAX_LENGTH = 31;
|
||||||
|
|
||||||
@ -279,6 +284,30 @@ guessProductName()
|
|||||||
}
|
}
|
||||||
return dmiProduct;
|
return dmiProduct;
|
||||||
}
|
}
|
||||||
|
#ifdef HAVE_ICU
|
||||||
|
static QString
|
||||||
|
transliterate( const QString& input )
|
||||||
|
{
|
||||||
|
static UErrorCode ue = UErrorCode::U_ZERO_ERROR;
|
||||||
|
static auto transliterator = std::unique_ptr< icu::Transliterator >(
|
||||||
|
icu::Transliterator::createInstance( "Any-Latin; Latin-ASCII", UTRANS_FORWARD, ue )
|
||||||
|
);
|
||||||
|
|
||||||
|
if(ue!=0){
|
||||||
|
cWarning() << "Can't create transliterator";
|
||||||
|
|
||||||
|
//it'll be checked later for non-ASCII characters
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto transliterable = icu::UnicodeString( input.toUtf8().data() );
|
||||||
|
|
||||||
|
transliterator->transliterate( transliterable );
|
||||||
|
|
||||||
|
return QString::fromUtf16( transliterable.getTerminatedBuffer() );
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static QString
|
static QString
|
||||||
makeLoginNameSuggestion( const QStringList& parts )
|
makeLoginNameSuggestion( const QStringList& parts )
|
||||||
@ -337,8 +366,16 @@ Config::setFullName( const QString& name )
|
|||||||
emit fullNameChanged( name );
|
emit fullNameChanged( name );
|
||||||
|
|
||||||
// Build login and hostname, if needed
|
// Build login and hostname, if needed
|
||||||
|
QString cleanName = CalamaresUtils::removeDiacritics( name ).toLower().simplified();
|
||||||
|
|
||||||
|
#ifdef HAVE_ICU
|
||||||
|
cleanName = transliterate(cleanName);
|
||||||
|
#else
|
||||||
QRegExp rx( "[^a-zA-Z0-9 ]", Qt::CaseInsensitive );
|
QRegExp rx( "[^a-zA-Z0-9 ]", Qt::CaseInsensitive );
|
||||||
QString cleanName = CalamaresUtils::removeDiacritics( name ).toLower().replace( rx, " " ).simplified();
|
cleanName.replace( rx, " " );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
QStringList cleanParts = cleanName.split( ' ' );
|
QStringList cleanParts = cleanName.split( ' ' );
|
||||||
|
|
||||||
if ( !m_customLoginName )
|
if ( !m_customLoginName )
|
||||||
|
@ -29,6 +29,18 @@ if( LibPWQuality_FOUND )
|
|||||||
add_definitions( -DCHECK_PWQUALITY -DHAVE_LIBPWQUALITY )
|
add_definitions( -DCHECK_PWQUALITY -DHAVE_LIBPWQUALITY )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_package( ICU COMPONENTS uc i18n )
|
||||||
|
set_package_properties(
|
||||||
|
ICU PROPERTIES
|
||||||
|
PURPOSE "Transliteration support for full name to username conversion"
|
||||||
|
)
|
||||||
|
|
||||||
|
if( ICU_FOUND )
|
||||||
|
list( APPEND USER_EXTRA_LIB ICU::uc ICU::i18n )
|
||||||
|
include_directories( ${ICU_INCLUDE_DIRS} )
|
||||||
|
add_definitions( -DHAVE_ICU )
|
||||||
|
endif()
|
||||||
|
|
||||||
calamares_add_plugin( usersq
|
calamares_add_plugin( usersq
|
||||||
TYPE viewmodule
|
TYPE viewmodule
|
||||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||||
|
Loading…
Reference in New Issue
Block a user