[libcalamares] Make RegionZonePair type stronger
- Derive from QPair instead of being QPair - Add isValid() for checking - Convenience constructors
This commit is contained in:
parent
73a5e7dd62
commit
26b61a4ddb
@ -45,10 +45,10 @@ GeoIP::splitTZString( const QString& tz )
|
||||
cDebug() << "GeoIP reporting" << timezoneString;
|
||||
QString region = tzParts.takeFirst();
|
||||
QString zone = tzParts.join( '/' );
|
||||
return qMakePair( region, zone );
|
||||
return RegionZonePair( region, zone );
|
||||
}
|
||||
|
||||
return qMakePair( QString(), QString() );
|
||||
return RegionZonePair( QString(), QString() );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -37,7 +37,25 @@ namespace CalamaresUtils
|
||||
class GeoIP
|
||||
{
|
||||
public:
|
||||
using RegionZonePair = QPair<QString, QString>;
|
||||
/** @brief A Region, Zone pair of strings
|
||||
*
|
||||
* A GeoIP lookup returns a timezone, which is represented as a Region,
|
||||
* Zone pair of strings (e.g. "Europe" and "Amsterdam"). Generally,
|
||||
* pasting the strings back together with a "/" is the right thing to
|
||||
* do. The Zone **may** contain a "/" (e.g. "Kentucky/Monticello").
|
||||
*/
|
||||
class RegionZonePair : public QPair<QString, QString>
|
||||
{
|
||||
public:
|
||||
/** @brief Construct from an existing pair. */
|
||||
explicit RegionZonePair( const QPair& p ) : QPair(p) { }
|
||||
/** @brief Construct from two strings, like qMakePair(). */
|
||||
RegionZonePair( const QString& region, const QString& zone ) : QPair( region, zone ) { }
|
||||
/** @brief An invalid zone pair (empty strings). */
|
||||
RegionZonePair() : QPair( QString(), QString() ) { }
|
||||
|
||||
bool isValid() const { return !first.isEmpty(); }
|
||||
} ;
|
||||
|
||||
virtual ~GeoIP();
|
||||
|
||||
|
@ -73,7 +73,7 @@ GeoIPJSON::processReply( const QByteArray& data )
|
||||
CalamaresUtils::explainYamlException( e, data, "GeoIP data");
|
||||
}
|
||||
|
||||
return qMakePair( QString(), QString() );
|
||||
return RegionZonePair( QString(), QString() );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
@ -52,14 +52,14 @@ GeoIPXML::processReply( const QByteArray& data )
|
||||
|
||||
// None of them valid
|
||||
cWarning() << "GeopIP XML had no recognizable timezone";
|
||||
return qMakePair( QString(), QString() );
|
||||
return RegionZonePair( QString(), QString() );
|
||||
}
|
||||
else
|
||||
{
|
||||
cWarning() << "GeoIP XML data error:" << domError << "(line" << errorLine << errorColumn << ')';
|
||||
}
|
||||
|
||||
return qMakePair( QString(), QString() );
|
||||
return RegionZonePair( QString(), QString() );
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user