Merge pull request #2181 from AsahiLinux/hello-im-a-mac

[users] Handle Device Tree platforms (e.g. Apple Silicon) for guessing the product name
This commit is contained in:
dalto8 2023-08-20 17:02:17 +00:00 committed by GitHub
commit 0eb431dd2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -321,7 +321,7 @@ Config::hostnameStatus() const
static QString
cleanupForHostname( const QString& s )
{
QRegExp dmirx( "[^a-zA-Z0-9]", Qt::CaseInsensitive );
QRegExp dmirx( "(^Apple|\\(.*\\)|[^a-zA-Z0-9])", Qt::CaseInsensitive );
return s.toLower().replace( dmirx, " " ).remove( ' ' );
}
@ -339,15 +339,30 @@ guessProductName()
if ( !tried )
{
QFile dmiFile( QStringLiteral( "/sys/devices/virtual/dmi/id/product_name" ) );
QFile modelFile( QStringLiteral( "/proc/device-tree/model" ) );
if ( dmiFile.exists() && dmiFile.open( QIODevice::ReadOnly ) )
{
dmiProduct = cleanupForHostname( QString::fromLocal8Bit( dmiFile.readAll().simplified().data() ) );
if ( !dmiProduct.isEmpty() )
{
tried = true;
return dmiProduct;
}
}
if ( dmiProduct.isEmpty() )
if ( modelFile.exists() && modelFile.open( QIODevice::ReadOnly ) )
{
dmiProduct = QStringLiteral( "pc" );
dmiProduct
= cleanupForHostname( QString::fromLocal8Bit( modelFile.readAll().chopped( 1 ).simplified().data() ) );
if ( !dmiProduct.isEmpty() )
{
tried = true;
return dmiProduct;
}
}
dmiProduct = QStringLiteral( "pc" );
tried = true;
}
return dmiProduct;