mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-27 00:33:48 -05:00
Include lat/long in newsfeed url if available
This commit is contained in:
parent
f4ea33fef1
commit
e783323fd7
@ -41,9 +41,32 @@ QgsNewsFeedParser::QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcf
|
|||||||
if ( after > 0 )
|
if ( after > 0 )
|
||||||
query.addQueryItem( QStringLiteral( "after" ), qgsDoubleToString( after, 0 ) );
|
query.addQueryItem( QStringLiteral( "after" ), qgsDoubleToString( after, 0 ) );
|
||||||
|
|
||||||
const QString lang = QgsSettings().value( QStringLiteral( "locale/userLocale" ), QStringLiteral( "en_US" ) ).toString().left( 2 );
|
QString feedLanguage = QgsSettings().value( QStringLiteral( "%1/lang" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toString();
|
||||||
if ( !lang.isEmpty() )
|
if ( feedLanguage.isEmpty() )
|
||||||
query.addQueryItem( QStringLiteral( "lang" ), lang );
|
{
|
||||||
|
feedLanguage = QgsSettings().value( QStringLiteral( "locale/userLocale" ), QStringLiteral( "en_US" ) ).toString().left( 2 );
|
||||||
|
}
|
||||||
|
if ( !feedLanguage.isEmpty() )
|
||||||
|
query.addQueryItem( QStringLiteral( "lang" ), feedLanguage );
|
||||||
|
|
||||||
|
bool latOk = false;
|
||||||
|
bool longOk = false;
|
||||||
|
const double feedLat = QgsSettings().value( QStringLiteral( "%1/latitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &latOk );
|
||||||
|
const double feedLong = QgsSettings().value( QStringLiteral( "%1/longitude" ).arg( mSettingsKey ), QString(), QgsSettings::Core ).toDouble( &longOk );
|
||||||
|
if ( latOk && longOk )
|
||||||
|
{
|
||||||
|
// hack to allow testing using local files
|
||||||
|
if ( feedUrl.isLocalFile() )
|
||||||
|
{
|
||||||
|
query.addQueryItem( QStringLiteral( "lat" ), QString::number( static_cast< int >( feedLat ) ) );
|
||||||
|
query.addQueryItem( QStringLiteral( "lon" ), QString::number( static_cast< int >( feedLong ) ) );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
query.addQueryItem( QStringLiteral( "lat" ), qgsDoubleToString( feedLat ) );
|
||||||
|
query.addQueryItem( QStringLiteral( "lon" ), qgsDoubleToString( feedLong ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// bit of a hack to allow testing using local files
|
// bit of a hack to allow testing using local files
|
||||||
if ( feedUrl.isLocalFile() )
|
if ( feedUrl.isLocalFile() )
|
||||||
|
@ -36,6 +36,7 @@ class TestQgsNewsFeedParser: public QObject
|
|||||||
|
|
||||||
void testFetch();
|
void testFetch();
|
||||||
void testAutoExpiry();
|
void testAutoExpiry();
|
||||||
|
void testGeoFencing();
|
||||||
void testModel();
|
void testModel();
|
||||||
void testProxyModel();
|
void testProxyModel();
|
||||||
|
|
||||||
@ -220,6 +221,34 @@ void TestQgsNewsFeedParser::testAutoExpiry()
|
|||||||
QVERIFY( !parser2.entries().at( 0 ).expiry.isValid() );
|
QVERIFY( !parser2.entries().at( 0 ).expiry.isValid() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestQgsNewsFeedParser::testGeoFencing()
|
||||||
|
{
|
||||||
|
QList< QgsNewsFeedParser::Entry > entries;
|
||||||
|
|
||||||
|
const QUrl url( QUrl::fromLocalFile( QStringLiteral( TEST_DATA_DIR ) + "/newsfeed/feed" ) );
|
||||||
|
const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() );
|
||||||
|
QgsSettings().remove( feedKey, QgsSettings::Core );
|
||||||
|
QgsSettings().setValue( QStringLiteral( "%1/latitude" ).arg( feedKey ), 37.2343, QgsSettings::Core );
|
||||||
|
QgsSettings().setValue( QStringLiteral( "%1/longitude" ).arg( feedKey ), -115.8067, QgsSettings::Core );
|
||||||
|
|
||||||
|
QgsNewsFeedParser parser( url );
|
||||||
|
QSignalSpy spy( &parser, &QgsNewsFeedParser::entryAdded );
|
||||||
|
QVERIFY( parser.entries().isEmpty() );
|
||||||
|
QEventLoop loop;
|
||||||
|
connect( &parser, &QgsNewsFeedParser::fetched, this, [ =, &loop, &entries ]( const QList< QgsNewsFeedParser::Entry > &e )
|
||||||
|
{
|
||||||
|
entries = e;
|
||||||
|
loop.quit();
|
||||||
|
} );
|
||||||
|
|
||||||
|
parser.fetch();
|
||||||
|
loop.exec();
|
||||||
|
|
||||||
|
// check only geofenced entries are present (i.e. that request has included lat/lon params)
|
||||||
|
QCOMPARE( entries.count(), 1 );
|
||||||
|
QCOMPARE( entries.at( 0 ).title, QStringLiteral( "Secret docs leaked" ) );
|
||||||
|
}
|
||||||
|
|
||||||
void TestQgsNewsFeedParser::testModel()
|
void TestQgsNewsFeedParser::testModel()
|
||||||
{
|
{
|
||||||
// test news feed model
|
// test news feed model
|
||||||
|
12
tests/testdata/newsfeed/feed_lang=en&lat=37&lon=-115
vendored
Normal file
12
tests/testdata/newsfeed/feed_lang=en&lat=37&lon=-115
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"pk": 7,
|
||||||
|
"publish_from": 1557073748.136,
|
||||||
|
"publish_to": null,
|
||||||
|
"title": "Secret docs leaked",
|
||||||
|
"image": "",
|
||||||
|
"content": "<p>Super secret docs are leaked!</p>",
|
||||||
|
"url": "https://nsa.gov",
|
||||||
|
"sticky": false
|
||||||
|
}
|
||||||
|
]
|
Loading…
x
Reference in New Issue
Block a user