[locale] Convenience function for TZ splitting
This commit is contained in:
parent
3636226425
commit
aaae1507cd
@ -18,6 +18,23 @@
|
|||||||
|
|
||||||
#include "GeoIP.h"
|
#include "GeoIP.h"
|
||||||
|
|
||||||
|
#include "utils/Logger.h"
|
||||||
|
|
||||||
GeoIP::~GeoIP()
|
GeoIP::~GeoIP()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GeoIP::RegionZonePair
|
||||||
|
GeoIP::splitTZString( const QString& timezoneString )
|
||||||
|
{
|
||||||
|
QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts );
|
||||||
|
if ( tzParts.size() >= 2 )
|
||||||
|
{
|
||||||
|
cDebug() << "GeoIP reporting" << timezoneString;
|
||||||
|
QString region = tzParts.takeFirst();
|
||||||
|
QString zone = tzParts.join( '/' );
|
||||||
|
return qMakePair( region, zone );
|
||||||
|
}
|
||||||
|
|
||||||
|
return qMakePair( QString(), QString() );
|
||||||
|
}
|
||||||
|
@ -36,6 +36,8 @@ struct GeoIP
|
|||||||
{
|
{
|
||||||
using RegionZonePair = QPair<QString, QString>;
|
using RegionZonePair = QPair<QString, QString>;
|
||||||
|
|
||||||
|
virtual ~GeoIP();
|
||||||
|
|
||||||
/** @brief Handle a (successful) request by interpreting the data.
|
/** @brief Handle a (successful) request by interpreting the data.
|
||||||
*
|
*
|
||||||
* Should return a ( <zone>, <region> ) pair, e.g.
|
* Should return a ( <zone>, <region> ) pair, e.g.
|
||||||
@ -47,7 +49,8 @@ struct GeoIP
|
|||||||
*/
|
*/
|
||||||
virtual RegionZonePair processReply( QNetworkReply* ) = 0;
|
virtual RegionZonePair processReply( QNetworkReply* ) = 0;
|
||||||
|
|
||||||
virtual ~GeoIP();
|
/** @brief Splits a region/zone string into a pair. */
|
||||||
|
static RegionZonePair splitTZString( const QString& s );
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -44,15 +44,7 @@ FreeGeoIP::processReply( QNetworkReply* reply )
|
|||||||
if ( map.contains( "time_zone" ) &&
|
if ( map.contains( "time_zone" ) &&
|
||||||
!map.value( "time_zone" ).toString().isEmpty() )
|
!map.value( "time_zone" ).toString().isEmpty() )
|
||||||
{
|
{
|
||||||
QString timezoneString = map.value( "time_zone" ).toString();
|
return splitTZString( map.value( "time_zone" ).toString() );
|
||||||
QStringList tzParts = timezoneString.split( '/', QString::SkipEmptyParts );
|
|
||||||
if ( tzParts.size() >= 2 )
|
|
||||||
{
|
|
||||||
cDebug() << "GeoIP reporting" << timezoneString;
|
|
||||||
QString region = tzParts.takeFirst();
|
|
||||||
QString zone = tzParts.join( '/' );
|
|
||||||
return qMakePair( region, zone );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user