libcalamares: use namespace Calamares::GeoIP consistently

This commit is contained in:
Adriaan de Groot 2023-09-10 22:26:17 +02:00
parent 47cbcbd348
commit d199288034
17 changed files with 45 additions and 52 deletions

View File

@ -9,7 +9,7 @@
#include "GeoIPFixed.h" #include "GeoIPFixed.h"
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -32,4 +32,4 @@ GeoIPFixed::processReply( const QByteArray& data )
} }
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares

View File

@ -12,7 +12,7 @@
#include "Interface.h" #include "Interface.h"
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -39,5 +39,5 @@ public:
}; };
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares
#endif #endif

View File

@ -17,7 +17,7 @@
#include <QByteArray> #include <QByteArray>
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -89,4 +89,4 @@ GeoIPJSON::processReply( const QByteArray& data )
} }
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares

View File

@ -12,7 +12,7 @@
#include "Interface.h" #include "Interface.h"
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -40,5 +40,5 @@ public:
}; };
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares
#endif #endif

View File

@ -22,7 +22,7 @@
QTEST_GUILESS_MAIN( GeoIPTests ) QTEST_GUILESS_MAIN( GeoIPTests )
using namespace CalamaresUtils::GeoIP; using namespace Calamares::GeoIP;
GeoIPTests::GeoIPTests() {} GeoIPTests::GeoIPTests() {}
@ -86,7 +86,6 @@ GeoIPTests::testJSONbad()
QCOMPARE( tz.first, QString() ); QCOMPARE( tz.first, QString() );
} }
static const char xml_data_ubiquity[] = static const char xml_data_ubiquity[] =
R"(<Response> R"(<Response>
<Ip>85.150.1.1</Ip> <Ip>85.150.1.1</Ip>
@ -131,7 +130,6 @@ GeoIPTests::testXML2()
#endif #endif
} }
void void
GeoIPTests::testXMLalt() GeoIPTests::testXMLalt()
{ {
@ -163,7 +161,7 @@ GeoIPTests::testXMLbad()
void void
GeoIPTests::testSplitTZ() GeoIPTests::testSplitTZ()
{ {
using namespace CalamaresUtils::GeoIP; using namespace Calamares::GeoIP;
auto tz = splitTZString( QStringLiteral( "Moon/Dark_side" ) ); auto tz = splitTZString( QStringLiteral( "Moon/Dark_side" ) );
QCOMPARE( tz.first, QStringLiteral( "Moon" ) ); QCOMPARE( tz.first, QStringLiteral( "Moon" ) );
QCOMPARE( tz.second, QStringLiteral( "Dark_side" ) ); QCOMPARE( tz.second, QStringLiteral( "Dark_side" ) );
@ -186,14 +184,13 @@ GeoIPTests::testSplitTZ()
QCOMPARE( tz.second, QStringLiteral( "North_Dakota/Beulah" ) ); QCOMPARE( tz.second, QStringLiteral( "North_Dakota/Beulah" ) );
} }
#define CHECK_GET( t, selector, url ) \ #define CHECK_GET( t, selector, url ) \
{ \ { \
auto tz = GeoIP##t( selector ) \ auto tz = GeoIP##t( selector ) \
.processReply( CalamaresUtils::Network::Manager::instance().synchronousGet( QUrl( url ) ) ); \ .processReply( CalamaresUtils::Network::Manager::instance().synchronousGet( QUrl( url ) ) ); \
qDebug() << tz; \ qDebug() << tz; \
QCOMPARE( default_tz, tz ); \ QCOMPARE( default_tz, tz ); \
auto tz2 = CalamaresUtils::GeoIP::Handler( "" #t, url, selector ).get(); \ auto tz2 = Calamares::GeoIP::Handler( "" #t, url, selector ).get(); \
qDebug() << tz2; \ qDebug() << tz2; \
QCOMPARE( default_tz, tz2 ); \ QCOMPARE( default_tz, tz2 ); \
} }

View File

@ -13,7 +13,7 @@
#include <QtXml/QDomDocument> #include <QtXml/QDomDocument>
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -59,7 +59,6 @@ getElementTexts( const QByteArray& data, const QString& tag )
return elements; return elements;
} }
QString QString
GeoIPXML::rawReply( const QByteArray& data ) GeoIPXML::rawReply( const QByteArray& data )
{ {
@ -90,4 +89,4 @@ GeoIPXML::processReply( const QByteArray& data )
} }
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares

View File

@ -12,7 +12,7 @@
#include "Interface.h" #include "Interface.h"
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -40,5 +40,5 @@ public:
}; };
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares
#endif #endif

View File

@ -23,10 +23,10 @@
#include <memory> #include <memory>
static const NamedEnumTable< CalamaresUtils::GeoIP::Handler::Type >& static const NamedEnumTable< Calamares::GeoIP::Handler::Type >&
handlerTypes() handlerTypes()
{ {
using Type = CalamaresUtils::GeoIP::Handler::Type; using Type = Calamares::GeoIP::Handler::Type;
// *INDENT-OFF* // *INDENT-OFF*
// clang-format off // clang-format off
@ -42,7 +42,7 @@ handlerTypes()
return names; return names;
} }
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -142,7 +142,6 @@ Handler::get() const
return do_query( m_type, m_url, m_selector ); return do_query( m_type, m_url, m_selector );
} }
QFuture< RegionZonePair > QFuture< RegionZonePair >
Handler::query() const Handler::query() const
{ {
@ -163,7 +162,6 @@ Handler::getRaw() const
return do_raw_query( m_type, m_url, m_selector ); return do_raw_query( m_type, m_url, m_selector );
} }
QFuture< QString > QFuture< QString >
Handler::queryRaw() const Handler::queryRaw() const
{ {
@ -175,4 +173,4 @@ Handler::queryRaw() const
} }
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares

View File

@ -16,7 +16,7 @@
#include <QVariantMap> #include <QVariantMap>
#include <QtConcurrent/QtConcurrentRun> #include <QtConcurrent/QtConcurrentRun>
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -82,5 +82,5 @@ private:
}; };
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares
#endif #endif

View File

@ -12,7 +12,7 @@
#include "utils/Logger.h" #include "utils/Logger.h"
#include "utils/String.h" #include "utils/String.h"
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -43,4 +43,4 @@ splitTZString( const QString& tz )
} }
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares

View File

@ -19,7 +19,7 @@
class QByteArray; class QByteArray;
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -98,5 +98,5 @@ protected:
}; };
} // namespace GeoIP } // namespace GeoIP
} // namespace CalamaresUtils } // namespace Calamares
#endif #endif

View File

@ -11,7 +11,6 @@
* This is a test-application that does one GeoIP parse. * This is a test-application that does one GeoIP parse.
*/ */
#include "GeoIPFixed.h" #include "GeoIPFixed.h"
#include "GeoIPJSON.h" #include "GeoIPJSON.h"
#ifdef QT_XML_LIB #ifdef QT_XML_LIB
@ -23,7 +22,7 @@
#include <iostream> #include <iostream>
using std::cerr; using std::cerr;
using namespace CalamaresUtils::GeoIP; using namespace Calamares::GeoIP;
int int
main( int argc, char** argv ) main( int argc, char** argv )

View File

@ -245,7 +245,7 @@ Config::setCurrentLocation()
void void
Config::setCurrentLocation( const QString& regionzone ) Config::setCurrentLocation( const QString& regionzone )
{ {
auto r = CalamaresUtils::GeoIP::splitTZString( regionzone ); auto r = Calamares::GeoIP::splitTZString( regionzone );
if ( r.isValid() ) if ( r.isValid() )
{ {
setCurrentLocation( r.first, r.second ); setCurrentLocation( r.first, r.second );
@ -459,23 +459,23 @@ getAdjustLiveTimezone( const QVariantMap& configurationMap, bool& adjustLiveTime
} }
static inline void static inline void
getStartingTimezone( const QVariantMap& configurationMap, CalamaresUtils::GeoIP::RegionZonePair& startingTimezone ) getStartingTimezone( const QVariantMap& configurationMap, Calamares::GeoIP::RegionZonePair& startingTimezone )
{ {
QString region = CalamaresUtils::getString( configurationMap, "region" ); QString region = CalamaresUtils::getString( configurationMap, "region" );
QString zone = CalamaresUtils::getString( configurationMap, "zone" ); QString zone = CalamaresUtils::getString( configurationMap, "zone" );
if ( !region.isEmpty() && !zone.isEmpty() ) if ( !region.isEmpty() && !zone.isEmpty() )
{ {
startingTimezone = CalamaresUtils::GeoIP::RegionZonePair( region, zone ); startingTimezone = Calamares::GeoIP::RegionZonePair( region, zone );
} }
else else
{ {
startingTimezone startingTimezone
= CalamaresUtils::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) ); = Calamares::GeoIP::RegionZonePair( QStringLiteral( "America" ), QStringLiteral( "New_York" ) );
} }
if ( CalamaresUtils::getBool( configurationMap, "useSystemTimezone", false ) ) if ( CalamaresUtils::getBool( configurationMap, "useSystemTimezone", false ) )
{ {
auto systemtz = CalamaresUtils::GeoIP::splitTZString( QTimeZone::systemTimeZoneId() ); auto systemtz = Calamares::GeoIP::splitTZString( QTimeZone::systemTimeZoneId() );
if ( systemtz.isValid() ) if ( systemtz.isValid() )
{ {
cDebug() << "Overriding configured timezone" << startingTimezone << "with system timezone" << systemtz; cDebug() << "Overriding configured timezone" << startingTimezone << "with system timezone" << systemtz;
@ -485,7 +485,7 @@ getStartingTimezone( const QVariantMap& configurationMap, CalamaresUtils::GeoIP:
} }
static inline void static inline void
getGeoIP( const QVariantMap& configurationMap, std::unique_ptr< CalamaresUtils::GeoIP::Handler >& geoip ) getGeoIP( const QVariantMap& configurationMap, std::unique_ptr< Calamares::GeoIP::Handler >& geoip )
{ {
bool ok = false; bool ok = false;
QVariantMap map = CalamaresUtils::getSubMap( configurationMap, "geoip", ok ); QVariantMap map = CalamaresUtils::getSubMap( configurationMap, "geoip", ok );
@ -495,7 +495,7 @@ getGeoIP( const QVariantMap& configurationMap, std::unique_ptr< CalamaresUtils::
QString style = CalamaresUtils::getString( map, "style" ); QString style = CalamaresUtils::getString( map, "style" );
QString selector = CalamaresUtils::getString( map, "selector" ); QString selector = CalamaresUtils::getString( map, "selector" );
geoip = std::make_unique< CalamaresUtils::GeoIP::Handler >( style, url, selector ); geoip = std::make_unique< Calamares::GeoIP::Handler >( style, url, selector );
if ( !geoip->isValid() ) if ( !geoip->isValid() )
{ {
cWarning() << "GeoIP Style" << style << "is not recognized."; cWarning() << "GeoIP Style" << style << "is not recognized.";
@ -552,7 +552,7 @@ Config::startGeoIP()
auto& network = CalamaresUtils::Network::Manager::instance(); auto& network = CalamaresUtils::Network::Manager::instance();
if ( network.hasInternet() || network.synchronousPing( m_geoip->url() ) ) if ( network.hasInternet() || network.synchronousPing( m_geoip->url() ) )
{ {
using Watcher = QFutureWatcher< CalamaresUtils::GeoIP::RegionZonePair >; using Watcher = QFutureWatcher< Calamares::GeoIP::RegionZonePair >;
m_geoipWatcher = std::make_unique< Watcher >(); m_geoipWatcher = std::make_unique< Watcher >();
m_geoipWatcher->setFuture( m_geoip->query() ); m_geoipWatcher->setFuture( m_geoip->query() );
connect( m_geoipWatcher.get(), &Watcher::finished, this, &Config::completeGeoIP ); connect( m_geoipWatcher.get(), &Watcher::finished, this, &Config::completeGeoIP );

View File

@ -171,19 +171,19 @@ private:
* This may be overridden by setting *useSystemTimezone* or by * This may be overridden by setting *useSystemTimezone* or by
* GeoIP settings. * GeoIP settings.
*/ */
CalamaresUtils::GeoIP::RegionZonePair m_startingTimezone; Calamares::GeoIP::RegionZonePair m_startingTimezone;
/** @brief Handler for GeoIP lookup (if configured) /** @brief Handler for GeoIP lookup (if configured)
* *
* The GeoIP lookup needs to be started at some suitable time, * The GeoIP lookup needs to be started at some suitable time,
* by explicitly calling *TODO* * by explicitly calling *TODO*
*/ */
std::unique_ptr< CalamaresUtils::GeoIP::Handler > m_geoip; std::unique_ptr< Calamares::GeoIP::Handler > m_geoip;
// Implementation details for doing GeoIP lookup // Implementation details for doing GeoIP lookup
void startGeoIP(); void startGeoIP();
void completeGeoIP(); void completeGeoIP();
std::unique_ptr< QFutureWatcher< CalamaresUtils::GeoIP::RegionZonePair > > m_geoipWatcher; std::unique_ptr< QFutureWatcher< Calamares::GeoIP::RegionZonePair > > m_geoipWatcher;
}; };

View File

@ -329,7 +329,7 @@ setLanguageIcon( Config* c, const QVariantMap& configurationMap )
} }
static inline void static inline void
logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler ) logGeoIPHandler( Calamares::GeoIP::Handler* handler )
{ {
if ( handler ) if ( handler )
{ {
@ -339,7 +339,7 @@ logGeoIPHandler( CalamaresUtils::GeoIP::Handler* handler )
} }
static void static void
setCountry( Config* config, const QString& countryCode, CalamaresUtils::GeoIP::Handler* handler ) setCountry( Config* config, const QString& countryCode, Calamares::GeoIP::Handler* handler )
{ {
if ( countryCode.length() != 2 ) if ( countryCode.length() != 2 )
{ {
@ -378,10 +378,10 @@ setGeoIP( Config* config, const QVariantMap& configurationMap )
{ {
using FWString = QFutureWatcher< QString >; using FWString = QFutureWatcher< QString >;
auto* handler = new CalamaresUtils::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ), auto* handler = new Calamares::GeoIP::Handler( CalamaresUtils::getString( geoip, "style" ),
CalamaresUtils::getString( geoip, "url" ), CalamaresUtils::getString( geoip, "url" ),
CalamaresUtils::getString( geoip, "selector" ) ); CalamaresUtils::getString( geoip, "selector" ) );
if ( handler->type() != CalamaresUtils::GeoIP::Handler::Type::None ) if ( handler->type() != Calamares::GeoIP::Handler::Type::None )
{ {
auto* future = new FWString(); auto* future = new FWString();
QObject::connect( future, QObject::connect( future,

View File

@ -23,7 +23,7 @@ class WelcomePage;
class GeneralRequirements; class GeneralRequirements;
class Config; class Config;
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -59,7 +59,7 @@ public:
* the given 2-letter country code. Uses the handler's information (if * the given 2-letter country code. Uses the handler's information (if
* given) for error reporting. * given) for error reporting.
*/ */
void setCountry( const QString&, CalamaresUtils::GeoIP::Handler* handler ); void setCountry( const QString&, Calamares::GeoIP::Handler* handler );
Calamares::RequirementsList checkRequirements() override; Calamares::RequirementsList checkRequirements() override;

View File

@ -21,7 +21,7 @@
#include <QObject> #include <QObject>
#include <QVariantMap> #include <QVariantMap>
namespace CalamaresUtils namespace Calamares
{ {
namespace GeoIP namespace GeoIP
{ {
@ -56,7 +56,7 @@ public:
* the given 2-letter country code. Uses the handler's information (if * the given 2-letter country code. Uses the handler's information (if
* given) for error reporting. * given) for error reporting.
*/ */
void setCountry( const QString&, CalamaresUtils::GeoIP::Handler* handler ); void setCountry( const QString&, Calamares::GeoIP::Handler* handler );
Calamares::RequirementsList checkRequirements() override; Calamares::RequirementsList checkRequirements() override;
QObject* getConfig() override; QObject* getConfig() override;