mirror of
https://github.com/parchlinux/calamares.git
synced 2025-02-24 02:45:44 -05:00
Style: use QStringLiteral
- In many cases, using QLatin1String is a de-optimization, when applied to a C string literal. Kevin Kofler pointed out that those should basically all be QStringLiteral, instead. (Compile tests with -O3 show that in the optimized object file, the code size difference is negligible). - Drop the explicit constructor entirely in cases where we're calling QProcess::execute(), for consistency. - Do a little less messing around in the mapping of keyboard locales to keyboard map names.
This commit is contained in:
parent
290559f8c1
commit
ac769d1de8
6 changed files with 48 additions and 46 deletions
|
@ -49,10 +49,10 @@ CalamaresApplication::CalamaresApplication( int& argc, char* argv[] )
|
|||
// <org>/<app>/, so we end up with ~/.cache/Calamares/calamares/
|
||||
// which is excessively squidly.
|
||||
//
|
||||
// setOrganizationName( QLatin1String( CALAMARES_ORGANIZATION_NAME ) );
|
||||
setOrganizationDomain( QLatin1String( CALAMARES_ORGANIZATION_DOMAIN ) );
|
||||
setApplicationName( QLatin1String( CALAMARES_APPLICATION_NAME ) );
|
||||
setApplicationVersion( QLatin1String( CALAMARES_VERSION ) );
|
||||
// setOrganizationName( QStringLiteral( CALAMARES_ORGANIZATION_NAME ) );
|
||||
setOrganizationDomain( QStringLiteral( CALAMARES_ORGANIZATION_DOMAIN ) );
|
||||
setApplicationName( QStringLiteral( CALAMARES_APPLICATION_NAME ) );
|
||||
setApplicationVersion( QStringLiteral( CALAMARES_VERSION ) );
|
||||
|
||||
cDebug() << "Calamares version:" << CALAMARES_VERSION;
|
||||
|
||||
|
|
|
@ -95,8 +95,7 @@ KeyboardPage::KeyboardPage( QWidget* parent )
|
|||
QString model = m_models.value( text, "pc105" );
|
||||
|
||||
// Set Xorg keyboard model
|
||||
QProcess::execute( QLatin1Literal( "setxkbmap" ),
|
||||
QStringList() << "-model" << model );
|
||||
QProcess::execute( "setxkbmap", QStringList{ "-model", model } );
|
||||
} );
|
||||
|
||||
CALAMARES_RETRANSLATE( ui->retranslateUi( this ); )
|
||||
|
@ -356,11 +355,15 @@ KeyboardPage::onActivate()
|
|||
|
||||
lang.replace( '-', '_' ); // Normalize separators
|
||||
}
|
||||
if ( !lang.isEmpty() && specialCaseMap.contains( lang.toStdString() ) )
|
||||
if ( !lang.isEmpty() )
|
||||
{
|
||||
QLatin1String newLang( specialCaseMap.value( lang.toStdString() ).c_str() );
|
||||
cDebug() << " .. special case language" << lang << '>' << newLang;
|
||||
lang = newLang;
|
||||
std::string lang_s = lang.toStdString();
|
||||
if ( specialCaseMap.contains( lang_s ) )
|
||||
{
|
||||
QString newLang = QString::fromStdString( specialCaseMap.value( lang_s ) );
|
||||
cDebug() << " .. special case language" << lang << "becomes" << newLang;
|
||||
lang = newLang;
|
||||
}
|
||||
}
|
||||
if ( !lang.isEmpty() )
|
||||
{
|
||||
|
@ -478,9 +481,8 @@ KeyboardPage::onListVariantCurrentItemChanged( QListWidgetItem* current, QListWi
|
|||
connect( &m_setxkbmapTimer, &QTimer::timeout,
|
||||
this, [=]
|
||||
{
|
||||
QProcess::execute( QLatin1Literal( "setxkbmap" ),
|
||||
xkbmap_args( QStringList(), layout, variant ) );
|
||||
cDebug() << "xkbmap selection changed to: " << layout << "-" << variant;
|
||||
QProcess::execute( "setxkbmap", xkbmap_args( QStringList(), layout, variant ) );
|
||||
cDebug() << "xkbmap selection changed to: " << layout << '-' << variant;
|
||||
m_setxkbmapTimer.disconnect( this );
|
||||
} );
|
||||
m_setxkbmapTimer.start( QApplication::keyboardInputInterval() );
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
GeoIPJSON::GeoIPJSON(const QString& attribute)
|
||||
: GeoIP( attribute.isEmpty() ? QLatin1String( "time_zone" ) : attribute )
|
||||
: GeoIP( attribute.isEmpty() ? QStringLiteral( "time_zone" ) : attribute )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -53,15 +53,15 @@ GeoIPTests::testJSON()
|
|||
GeoIPJSON handler;
|
||||
auto tz = handler.processReply( json_data_attribute );
|
||||
|
||||
QCOMPARE( tz.first, QLatin1String( "Europe" ) );
|
||||
QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) );
|
||||
QCOMPARE( tz.first, QStringLiteral( "Europe" ) );
|
||||
QCOMPARE( tz.second, QStringLiteral( "Amsterdam" ) );
|
||||
|
||||
// JSON is quite tolerant
|
||||
tz = handler.processReply( "time_zone: \"Europe/Brussels\"" );
|
||||
QCOMPARE( tz.second, QLatin1String( "Brussels" ) );
|
||||
QCOMPARE( tz.second, QStringLiteral( "Brussels" ) );
|
||||
|
||||
tz = handler.processReply( "time_zone: America/New_York\n" );
|
||||
QCOMPARE( tz.first, QLatin1String( "America" ) );
|
||||
QCOMPARE( tz.first, QStringLiteral( "America" ) );
|
||||
}
|
||||
|
||||
void GeoIPTests::testJSONalt()
|
||||
|
@ -72,8 +72,8 @@ void GeoIPTests::testJSONalt()
|
|||
QCOMPARE( tz.first, QString() ); // Not found
|
||||
|
||||
tz = handler.processReply( "tarifa: 12\nzona_de_hora: Europe/Madrid" );
|
||||
QCOMPARE( tz.first, QLatin1String( "Europe" ) );
|
||||
QCOMPARE( tz.second, QLatin1String( "Madrid" ) );
|
||||
QCOMPARE( tz.first, QStringLiteral( "Europe" ) );
|
||||
QCOMPARE( tz.second, QStringLiteral( "Madrid" ) );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -122,8 +122,8 @@ GeoIPTests::testXML()
|
|||
GeoIPXML handler;
|
||||
auto tz = handler.processReply( xml_data_ubiquity );
|
||||
|
||||
QCOMPARE( tz.first, QLatin1String( "Europe" ) );
|
||||
QCOMPARE( tz.second, QLatin1String( "Amsterdam" ) );
|
||||
QCOMPARE( tz.first, QStringLiteral( "Europe" ) );
|
||||
QCOMPARE( tz.second, QStringLiteral( "Amsterdam" ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -137,8 +137,8 @@ GeoIPTests::testXML2()
|
|||
GeoIPXML handler;
|
||||
auto tz = handler.processReply( data );
|
||||
|
||||
QCOMPARE( tz.first, QLatin1String( "America" ) );
|
||||
QCOMPARE( tz.second, QLatin1String( "North_Dakota/Beulah" ) ); // Without space
|
||||
QCOMPARE( tz.first, QStringLiteral( "America" ) );
|
||||
QCOMPARE( tz.second, QStringLiteral( "North_Dakota/Beulah" ) ); // Without space
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -149,8 +149,8 @@ void GeoIPTests::testXMLalt()
|
|||
GeoIPXML handler( "ZT" );
|
||||
|
||||
auto tz = handler.processReply( "<A><B/><C><ZT>Moon/Dark_side</ZT></C></A>" );
|
||||
QCOMPARE( tz.first, QLatin1String( "Moon" ) );
|
||||
QCOMPARE( tz.second, QLatin1String( "Dark_side" ) );
|
||||
QCOMPARE( tz.first, QStringLiteral( "Moon" ) );
|
||||
QCOMPARE( tz.second, QStringLiteral( "Dark_side" ) );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -172,26 +172,26 @@ GeoIPTests::testXMLbad()
|
|||
|
||||
void GeoIPTests::testSplitTZ()
|
||||
{
|
||||
auto tz = GeoIP::splitTZString( QLatin1String("Moon/Dark_side") );
|
||||
QCOMPARE( tz.first, QLatin1String("Moon") );
|
||||
QCOMPARE( tz.second, QLatin1String("Dark_side") );
|
||||
auto tz = GeoIP::splitTZString( QStringLiteral("Moon/Dark_side") );
|
||||
QCOMPARE( tz.first, QStringLiteral("Moon") );
|
||||
QCOMPARE( tz.second, QStringLiteral("Dark_side") );
|
||||
|
||||
// Some providers return weirdly escaped data
|
||||
tz = GeoIP::splitTZString( QLatin1String("America\\/NewYork") );
|
||||
QCOMPARE( tz.first, QLatin1String("America") );
|
||||
QCOMPARE( tz.second, QLatin1String("NewYork") ); // That's not actually the zone name
|
||||
tz = GeoIP::splitTZString( QStringLiteral("America\\/NewYork") );
|
||||
QCOMPARE( tz.first, QStringLiteral("America") );
|
||||
QCOMPARE( tz.second, QStringLiteral("NewYork") ); // That's not actually the zone name
|
||||
|
||||
// Check that bogus data fails
|
||||
tz = GeoIP::splitTZString( QString() );
|
||||
QCOMPARE( tz.first, QString() );
|
||||
|
||||
tz = GeoIP::splitTZString( QLatin1String("America.NewYork") );
|
||||
tz = GeoIP::splitTZString( QStringLiteral("America.NewYork") );
|
||||
QCOMPARE( tz.first, QString() );
|
||||
|
||||
// Check that three-level is split properly and space is replaced
|
||||
tz = GeoIP::splitTZString( QLatin1String("America/North Dakota/Beulah") );
|
||||
QCOMPARE( tz.first, QLatin1String("America") );
|
||||
QCOMPARE( tz.second, QLatin1String("North_Dakota/Beulah") );
|
||||
tz = GeoIP::splitTZString( QStringLiteral("America/North Dakota/Beulah") );
|
||||
QCOMPARE( tz.first, QStringLiteral("America") );
|
||||
QCOMPARE( tz.second, QStringLiteral("North_Dakota/Beulah") );
|
||||
}
|
||||
|
||||
|
||||
|
@ -221,7 +221,7 @@ synchronous_get( const char* urlstring )
|
|||
|
||||
void GeoIPTests::testGet()
|
||||
{
|
||||
if ( !QProcessEnvironment::systemEnvironment().contains( QLatin1String("TEST_HTTP_GET") ) )
|
||||
if ( !QProcessEnvironment::systemEnvironment().contains( QStringLiteral("TEST_HTTP_GET") ) )
|
||||
{
|
||||
qDebug() << "Skipping HTTP GET tests";
|
||||
return;
|
||||
|
@ -232,8 +232,8 @@ void GeoIPTests::testGet()
|
|||
auto default_tz = default_handler.processReply( synchronous_get( "https://geoip.kde.org/v1/calamares" ) );
|
||||
|
||||
// This is bogus, because the test isn't always run by me
|
||||
// QCOMPARE( default_tz.first, QLatin1String("Europe") );
|
||||
// QCOMPARE( default_tz.second, QLatin1String("Amsterdam") );
|
||||
// QCOMPARE( default_tz.first, QStringLiteral("Europe") );
|
||||
// QCOMPARE( default_tz.second, QStringLiteral("Amsterdam") );
|
||||
QVERIFY( !default_tz.first.isEmpty() );
|
||||
QVERIFY( !default_tz.second.isEmpty() );
|
||||
|
||||
|
@ -242,12 +242,12 @@ void GeoIPTests::testGet()
|
|||
// services don't agree on the location of where the test is run.
|
||||
CHECK_GET( JSON, QString(), "https://geoip.kde.org/v1/calamares" ) // Check it's consistent
|
||||
CHECK_GET( JSON, QString(), "http://freegeoip.net/json/" ) // Original FreeGeoIP service
|
||||
CHECK_GET( JSON, QLatin1String("timezone"), "https://ipapi.co/json" ) // Different JSON
|
||||
CHECK_GET( JSON, QLatin1String("timezone"), "http://ip-api.com/json" )
|
||||
CHECK_GET( JSON, QStringLiteral("timezone"), "https://ipapi.co/json" ) // Different JSON
|
||||
CHECK_GET( JSON, QStringLiteral("timezone"), "http://ip-api.com/json" )
|
||||
|
||||
CHECK_GET( JSON, QLatin1String("location.time_zone"), "http://geoip.nekudo.com/api/" ) // 2-level JSON
|
||||
CHECK_GET( JSON, QStringLiteral("location.time_zone"), "http://geoip.nekudo.com/api/" ) // 2-level JSON
|
||||
|
||||
CHECK_GET( JSON, QLatin1String("Location.TimeZone"), "https://geoip.kde.org/debug" ) // 2-level JSON
|
||||
CHECK_GET( JSON, QStringLiteral("Location.TimeZone"), "https://geoip.kde.org/debug" ) // 2-level JSON
|
||||
|
||||
#ifdef HAVE_XML
|
||||
CHECK_GET( XML, QString(), "http://geoip.ubuntu.com/lookup" ) // Ubiquity's XML format
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <QtXml/QDomDocument>
|
||||
|
||||
GeoIPXML::GeoIPXML( const QString& element )
|
||||
: GeoIP( element.isEmpty() ? QLatin1String( "TimeZone" ) : element )
|
||||
: GeoIP( element.isEmpty() ? QStringLiteral( "TimeZone" ) : element )
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -38,10 +38,10 @@ int main(int argc, char** argv)
|
|||
}
|
||||
|
||||
GeoIP* handler = nullptr;
|
||||
if ( QLatin1String( "json" ) == argv[1] )
|
||||
if ( QStringLiteral( "json" ) == argv[1] )
|
||||
handler = new GeoIPJSON;
|
||||
#ifdef HAVE_XML
|
||||
else if ( QLatin1String( "xml" ) == argv[1] )
|
||||
else if ( QStringLiteral( "xml" ) == argv[1] )
|
||||
handler = new GeoIPXML;
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue