[libcalamares] Apply coding style to geoip/

main
Adriaan de Groot 6 years ago
parent a2ab91474f
commit ec073ee188

@ -45,16 +45,22 @@ static QString
selectMap( const QVariantMap& m, const QStringList& l, int index )
{
if ( index >= l.count() )
{
return QString();
}
QString attributeName = l[ index ];
if ( index == l.count() - 1 )
{
return CalamaresUtils::getString( m, attributeName );
}
else
{
bool success = false; // bogus
if ( m.contains( attributeName ) )
{
return selectMap( CalamaresUtils::getSubMap( m, attributeName, success ), l, index + 1 );
}
return QString();
}
}
@ -67,15 +73,15 @@ GeoIPJSON::rawReply( const QByteArray& data )
YAML::Node doc = YAML::Load( data );
QVariant var = CalamaresUtils::yamlToVariant( doc );
if ( !var.isNull() &&
var.isValid() &&
var.type() == QVariant::Map )
if ( !var.isNull() && var.isValid() && var.type() == QVariant::Map )
{
return selectMap( var.toMap(), m_element.split( '.' ), 0 );
}
else
{
cWarning() << "Invalid YAML data for GeoIPJSON";
}
}
catch ( YAML::Exception& e )
{
CalamaresUtils::explainYamlException( e, data, "GeoIP data" );
@ -90,5 +96,5 @@ GeoIPJSON::processReply( const QByteArray& data )
return splitTZString( rawReply( data ) );
}
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils

@ -48,6 +48,6 @@ public:
virtual QString rawReply( const QByteArray& ) override;
};
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils
#endif

@ -51,16 +51,20 @@ getElementTexts( const QByteArray& data, const QString& tag )
auto e = tzElements.at( it ).toElement();
auto e_text = e.text();
if ( !e_text.isEmpty() )
{
elements.append( e_text );
}
}
}
else
{
cWarning() << "GeoIP XML data error:" << domError << "(line" << errorLine << errorColumn << ')';
}
if ( elements.count() < 1 )
{
cWarning() << "GeopIP XML had no non-empty elements" << tag;
}
return elements;
}
@ -71,7 +75,9 @@ GeoIPXML::rawReply( const QByteArray& data )
{
for ( const auto& e : getElementTexts( data, m_element ) )
if ( !e.isEmpty() )
{
return e;
}
return QString();
}
@ -83,11 +89,13 @@ GeoIPXML::processReply( const QByteArray& data )
{
auto tz = splitTZString( e );
if ( !tz.first.isEmpty() )
{
return tz;
}
}
return RegionZonePair();
}
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils

@ -48,6 +48,6 @@ public:
virtual QString rawReply( const QByteArray& ) override;
};
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils
#endif

@ -28,8 +28,8 @@
#include "utils/Variant.h"
#include <QEventLoop>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <memory>
@ -85,9 +85,7 @@ Handler::Handler( const QString& implementation, const QString& url, const QStri
#endif
}
Handler::~Handler()
{
}
Handler::~Handler() {}
static QByteArray
synchronous_get( const QString& urlstring )
@ -129,7 +127,9 @@ do_query( Handler::Type type, const QString& url, const QString& selector )
{
const auto interface = create_interface( type, selector );
if ( !interface )
{
return RegionZonePair();
}
return interface->processReply( synchronous_get( url ) );
}
@ -139,7 +139,9 @@ do_raw_query( Handler::Type type, const QString& url, const QString& selector )
{
const auto interface = create_interface( type, selector );
if ( !interface )
{
return QString();
}
return interface->rawReply( synchronous_get( url ) );
}
@ -148,7 +150,9 @@ RegionZonePair
Handler::get() const
{
if ( !isValid() )
{
return RegionZonePair();
}
return do_query( m_type, m_url, m_selector );
}
@ -160,17 +164,16 @@ Handler::query() const
QString url = m_url;
QString selector = m_selector;
return QtConcurrent::run( [=]
{
return do_query( type, url, selector );
} );
return QtConcurrent::run( [=] { return do_query( type, url, selector ); } );
}
QString
Handler::getRaw() const
{
if ( !isValid() )
{
return QString();
}
return do_raw_query( m_type, m_url, m_selector );
}
@ -182,11 +185,8 @@ Handler::queryRaw() const
QString url = m_url;
QString selector = m_selector;
return QtConcurrent::run( [=]
{
return do_raw_query( type, url, selector );
} );
return QtConcurrent::run( [=] { return do_raw_query( type, url, selector ); } );
}
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils

@ -21,9 +21,9 @@
#include "Interface.h"
#include <QtConcurrent/QtConcurrentRun>
#include <QString>
#include <QVariantMap>
#include <QtConcurrent/QtConcurrentRun>
namespace CalamaresUtils
{
@ -89,7 +89,6 @@ private:
const QString m_selector;
};
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils
#endif

@ -30,9 +30,7 @@ Interface::Interface(const QString& e)
{
}
Interface::~Interface()
{
}
Interface::~Interface() {}
RegionZonePair
splitTZString( const QString& tz )
@ -53,5 +51,5 @@ splitTZString( const QString& tz )
return RegionZonePair( QString(), QString() );
}
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils

@ -42,11 +42,20 @@ class DLLEXPORT RegionZonePair : public QPair<QString, QString>
{
public:
/** @brief Construct from an existing pair. */
explicit RegionZonePair( const QPair& p ) : QPair(p) { }
explicit RegionZonePair( const QPair& p )
: QPair( p )
{
}
/** @brief Construct from two strings, like qMakePair(). */
RegionZonePair( const QString& region, const QString& zone ) : QPair( region, zone ) { }
RegionZonePair( const QString& region, const QString& zone )
: QPair( region, zone )
{
}
/** @brief An invalid zone pair (empty strings). */
RegionZonePair() : QPair( QString(), QString() ) { }
RegionZonePair()
: QPair( QString(), QString() )
{
}
bool isValid() const { return !first.isEmpty(); }
};
@ -60,8 +69,7 @@ public:
* pair of empty QStrings if it can't. (e.g. America/North Dakota/Beulah
* will return "America", "North_Dakota/Beulah").
*/
DLLEXPORT RegionZonePair
splitTZString( const QString& s );
DLLEXPORT RegionZonePair splitTZString( const QString& s );
/**
* @brief Interface for GeoIP retrievers.
@ -95,6 +103,6 @@ protected:
QString m_element; // string for selecting from data
};
}
} // namespace
} // namespace GeoIP
} // namespace CalamaresUtils
#endif

@ -30,7 +30,8 @@
using std::cerr;
using namespace CalamaresUtils::GeoIP;
int main(int argc, char** argv)
int
main( int argc, char** argv )
{
if ( argc != 2 )
{
@ -40,10 +41,14 @@ int main(int argc, char** argv)
Interface* handler = nullptr;
if ( QStringLiteral( "json" ) == argv[ 1 ] )
{
handler = new GeoIPJSON;
}
#ifdef QT_XML_LIB
else if ( QStringLiteral( "xml" ) == argv[ 1 ] )
{
handler = new GeoIPXML;
}
#endif
if ( !handler )
@ -53,7 +58,8 @@ int main(int argc, char** argv)
}
QByteArray ba;
while( !std::cin.eof() ) {
while ( !std::cin.eof() )
{
char arr[ 1024 ];
std::cin.read( arr, sizeof( arr ) );
int s = static_cast< int >( std::cin.gcount() );
@ -67,7 +73,8 @@ int main(int argc, char** argv)
}
else
{
std::cout << "TimeZone Region=" << tz.first.toLatin1().constData() << "\nTimeZone Zone=" << tz.second.toLatin1().constData() << '\n';
std::cout << "TimeZone Region=" << tz.first.toLatin1().constData()
<< "\nTimeZone Zone=" << tz.second.toLatin1().constData() << '\n';
}
return 0;

Loading…
Cancel
Save