Store publish_to field locally

This commit is contained in:
Nyall Dawson 2019-07-15 10:26:22 +10:00
parent 0a336d4c89
commit 64ecc06fed
5 changed files with 24 additions and 2 deletions

View File

@ -50,6 +50,8 @@ Represents a single entry from a news feed.
QUrl link;
bool sticky;
QDateTime expiry;
};
QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcfg = QString(), QObject *parent /TransferThis/ = 0 );

View File

@ -159,6 +159,10 @@ void QgsNewsFeedParser::onFetch( const QString &content )
newEntry.content = entryMap.value( QStringLiteral( "content" ) ).toString();
newEntry.link = entryMap.value( QStringLiteral( "url" ) ).toString();
newEntry.sticky = entryMap.value( QStringLiteral( "sticky" ) ).toBool();
bool ok = false;
const uint expiry = entryMap.value( QStringLiteral( "publish_to" ) ).toUInt( &ok );
if ( ok )
newEntry.expiry.setTime_t( expiry );
newEntries.append( newEntry );
if ( !newEntry.imageUrl.isEmpty() )
@ -201,6 +205,7 @@ QgsNewsFeedParser::Entry QgsNewsFeedParser::readEntryFromSettings( const int key
entry.content = settings.value( QStringLiteral( "content" ) ).toString();
entry.link = settings.value( QStringLiteral( "link" ) ).toString();
entry.sticky = settings.value( QStringLiteral( "sticky" ) ).toBool();
entry.expiry = settings.value( QStringLiteral( "expiry" ) ).toDateTime();
if ( !entry.imageUrl.isEmpty() )
{
const QString previewDir = QStringLiteral( "%1/previewImages" ).arg( QgsApplication::qgisSettingsDirPath() );
@ -227,6 +232,8 @@ void QgsNewsFeedParser::storeEntryInSettings( const QgsNewsFeedParser::Entry &en
settings.setValue( QStringLiteral( "%1/content" ).arg( baseSettingsKey ), entry.content, QgsSettings::Core );
settings.setValue( QStringLiteral( "%1/link" ).arg( baseSettingsKey ), entry.link, QgsSettings::Core );
settings.setValue( QStringLiteral( "%1/sticky" ).arg( baseSettingsKey ), entry.sticky, QgsSettings::Core );
if ( entry.expiry.isValid() )
settings.setValue( QStringLiteral( "%1/expiry" ).arg( baseSettingsKey ), entry.expiry, QgsSettings::Core );
}
void QgsNewsFeedParser::fetchImageForEntry( const QgsNewsFeedParser::Entry &entry )

View File

@ -20,6 +20,7 @@
#include <QObject>
#include <QUrl>
#include <QPixmap>
#include <QDateTime>
class QgsNetworkContentFetcher;
@ -66,6 +67,9 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject
//! TRUE if entry is "sticky" and should always be shown at the top
bool sticky = false;
//! Optional auto-expiry time for entry
QDateTime expiry;
};
/**

View File

@ -97,7 +97,10 @@ void TestQgsNewsFeedParser::testFetch()
QCOMPARE( parser.entries().count(), 5 );
QCOMPARE( parser.entries().at( 0 ).title, QStringLiteral( "Next Microsoft Windows code name revealed" ) );
QVERIFY( parser.entries().at( 0 ).expiry.isValid() );
QCOMPARE( parser.entries().at( 0 ).expiry.toUTC(), QDateTime( QDate( 2027, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( parser.entries().at( 1 ).title, QStringLiteral( "QGIS core will be rewritten in Rust" ) );
QVERIFY( !parser.entries().at( 1 ).expiry.isValid() );
QCOMPARE( parser.entries().at( 2 ).title, QStringLiteral( "QGIS Italian Meeting" ) );
QCOMPARE( parser.entries().at( 3 ).title, QStringLiteral( "QGIS acquired by ESRI" ) );
QCOMPARE( parser.entries().at( 4 ).title, QStringLiteral( "Null Island QGIS Meeting" ) );
@ -128,7 +131,10 @@ void TestQgsNewsFeedParser::testFetch()
// check only new entries are present
QCOMPARE( entries.count(), 4 );
QCOMPARE( entries.at( 0 ).title, QStringLiteral( "QGIS acquired by ESRI" ) );
QVERIFY( parser.entries().at( 0 ).expiry.isValid() );
QCOMPARE( parser.entries().at( 0 ).expiry.toUTC(), QDateTime( QDate( 2027, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( entries.at( 1 ).title, QStringLiteral( "Next Microsoft Windows code name revealed" ) );
QVERIFY( !parser.entries().at( 1 ).expiry.isValid() );
QCOMPARE( entries.at( 2 ).title, QStringLiteral( "Null Island QGIS Meeting" ) );
QCOMPARE( entries.at( 3 ).title, QStringLiteral( "QGIS Italian Meeting" ) );
@ -145,7 +151,10 @@ void TestQgsNewsFeedParser::testFetch()
// previous entries should be automatically read
QCOMPARE( parser3.entries().count(), 4 );
QCOMPARE( parser3.entries().at( 0 ).title, QStringLiteral( "QGIS acquired by ESRI" ) );
QVERIFY( parser.entries().at( 0 ).expiry.isValid() );
QCOMPARE( parser.entries().at( 0 ).expiry.toUTC(), QDateTime( QDate( 2027, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC ) );
QCOMPARE( parser3.entries().at( 1 ).title, QStringLiteral( "Next Microsoft Windows code name revealed" ) );
QVERIFY( !parser.entries().at( 1 ).expiry.isValid() );
QCOMPARE( parser3.entries().at( 2 ).title, QStringLiteral( "Null Island QGIS Meeting" ) );
QCOMPARE( parser3.entries().at( 3 ).title, QStringLiteral( "QGIS Italian Meeting" ) );

View File

@ -2,7 +2,7 @@
{
"pk": 4,
"publish_from": 1557073748.13,
"publish_to": null,
"publish_to": 1798761600.0,
"title": "Next Microsoft Windows code name revealed",
"image": "",
"content": "<p>Rumors from a whistleblower revealed the next Windows release code name: <strong>Winux</strong></p>\r\n<p>The next version of the popular operating system will ship a modified version of Wine that will run inside a docker container virtualized on Vagrant on VirtualBox running on Alpine Linux on the bare metal.</p>",
@ -12,7 +12,7 @@
{
"pk": 6,
"publish_from": 915196568.0,
"publish_to": 32472144000.0,
"publish_to": null,
"title": "QGIS core will be rewritten in Rust",
"image": "http://0.0.0.0:8000/media/feedimages/rust.png",
"content": "<p>Tired with C++ intricacies, the core developers have decided to rewrite QGIS in <strong>Rust</strong>, since Qt is not available for Rust, the new GUI will be based on Tcl/Tk.</p>",