@ -40,6 +40,56 @@
# include <Plasma/Plasma>
# include <Plasma/Plasma>
# ifdef HAVE_ICU
# include <unicode/translit.h>
# endif
namespace
{
QString groupName ( const QString & name )
{
if ( name . isEmpty ( ) ) {
return QString ( ) ;
}
// Here we will apply a locale based strategy for the first character.
// If first character is hangul, run decomposition and return the choseong (consonants).
if ( name [ 0 ] . script ( ) = = QChar : : Script_Hangul ) {
auto decomposed = name [ 0 ] . decomposition ( ) ;
if ( decomposed . isEmpty ( ) ) {
return name . left ( 1 ) ;
}
return decomposed . left ( 1 ) ;
}
if ( QLocale : : system ( ) . language ( ) = = QLocale : : Japanese ) {
// We do this here for Japanese locale because:
// 1. it does not make much sense to have every different Kanji to have a different group.
// 2. ICU transliterator can't yet convert Kanji to Hiragana.
// https://unicode-org.atlassian.net/browse/ICU-5874
if ( name [ 0 ] . script ( ) = = QChar : : Script_Han ) {
// Unicode Han
return QString : : fromUtf8 ( " \xe6 \xbc \xa2 " ) ;
}
}
# ifdef HAVE_ICU
static auto ue = UErrorCode : : U_ZERO_ERROR ;
static auto transliterator =
std : : unique_ptr < icu : : Transliterator > ( icu : : Transliterator : : createInstance ( " Han-Latin; "
" Katakana-Hiragana; "
" Latin-ASCII " ,
UTRANS_FORWARD ,
ue ) ) ;
if ( ue = = UErrorCode : : U_ZERO_ERROR ) {
icu : : UnicodeString icuText ( reinterpret_cast < const char16_t * > ( name . data ( ) ) , name . size ( ) ) ;
transliterator - > transliterate ( icuText ) ;
return QString : : fromUtf16 ( icuText . getBuffer ( ) , static_cast < int > ( icuText . length ( ) ) ) . left ( 1 ) ;
}
# endif
return name . left ( 1 ) ;
}
}
AppEntry : : AppEntry ( AbstractModel * owner , KService : : Ptr service , NameFormat nameFormat )
AppEntry : : AppEntry ( AbstractModel * owner , KService : : Ptr service , NameFormat nameFormat )
: AbstractEntry ( owner )
: AbstractEntry ( owner )
, m_service ( service )
, m_service ( service )
@ -78,6 +128,7 @@ AppEntry::AppEntry(AbstractModel *owner, const QString &id)
void AppEntry : : init ( NameFormat nameFormat )
void AppEntry : : init ( NameFormat nameFormat )
{
{
m_name = nameFromService ( m_service , nameFormat ) ;
m_name = nameFromService ( m_service , nameFormat ) ;
m_group = groupName ( m_name ) ;
if ( nameFormat = = GenericNameOnly ) {
if ( nameFormat = = GenericNameOnly ) {
m_description = nameFromService ( m_service , NameOnly ) ;
m_description = nameFromService ( m_service , NameOnly ) ;
@ -118,6 +169,11 @@ KService::Ptr AppEntry::service() const
return m_service ;
return m_service ;
}
}
QString AppEntry : : group ( ) const
{
return m_group ;
}
QString AppEntry : : id ( ) const
QString AppEntry : : id ( ) const
{
{
if ( ! m_id . isEmpty ( ) ) {
if ( ! m_id . isEmpty ( ) ) {