mirror of
https://github.com/qgis/QGIS.git
synced 2025-10-06 00:07:29 -04:00
Auto-prune expired news items on launch
This commit is contained in:
parent
64ecc06fed
commit
f4ea33fef1
@ -92,7 +92,8 @@ void QgsNewsFeedParser::dismissEntry( int key )
|
||||
}
|
||||
}
|
||||
|
||||
emit entryDismissed( dismissed );
|
||||
if ( !mBlockSignals )
|
||||
emit entryDismissed( dismissed );
|
||||
}
|
||||
|
||||
void QgsNewsFeedParser::dismissAll()
|
||||
@ -189,7 +190,16 @@ void QgsNewsFeedParser::readStoredEntries()
|
||||
mEntries.reserve( existing.size() );
|
||||
for ( const QString &entry : existing )
|
||||
{
|
||||
mEntries.append( readEntryFromSettings( entry.toInt() ) );
|
||||
const Entry e = readEntryFromSettings( entry.toInt() );
|
||||
if ( !e.expiry.isValid() || e.expiry > QDateTime::currentDateTime() )
|
||||
mEntries.append( e );
|
||||
else
|
||||
{
|
||||
// expired entry, prune it
|
||||
mBlockSignals = true;
|
||||
dismissEntry( e.key );
|
||||
mBlockSignals = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,6 +162,7 @@ class CORE_EXPORT QgsNewsFeedParser : public QObject
|
||||
QString mSettingsKey;
|
||||
|
||||
QList< Entry > mEntries;
|
||||
bool mBlockSignals = false;
|
||||
|
||||
void readStoredEntries();
|
||||
Entry readEntryFromSettings( int key );
|
||||
|
@ -35,6 +35,7 @@ class TestQgsNewsFeedParser: public QObject
|
||||
void cleanup(); // will be called after every testfunction.
|
||||
|
||||
void testFetch();
|
||||
void testAutoExpiry();
|
||||
void testModel();
|
||||
void testProxyModel();
|
||||
|
||||
@ -193,6 +194,32 @@ void TestQgsNewsFeedParser::testFetch()
|
||||
QCOMPARE( parser5.entries().count(), 0 );
|
||||
}
|
||||
|
||||
void TestQgsNewsFeedParser::testAutoExpiry()
|
||||
{
|
||||
const QUrl url( QStringLiteral( "xxx" ) );
|
||||
const QString feedKey = QgsNewsFeedParser::keyForFeed( url.toString() );
|
||||
QgsSettings().remove( feedKey, QgsSettings::Core );
|
||||
|
||||
// ensure entries "auto expire" when past their use-by date
|
||||
QgsNewsFeedParser::Entry testEntry;
|
||||
testEntry.key = 1;
|
||||
testEntry.title = QStringLiteral( "test entry" );
|
||||
QgsNewsFeedParser::Entry testEntry2;
|
||||
testEntry2.key = 2;
|
||||
testEntry2.title = QStringLiteral( "test entry2" );
|
||||
testEntry2.expiry = QDateTime( QDate( 1997, 1, 1 ), QTime( 0, 0, 0 ), Qt::UTC );
|
||||
|
||||
QgsNewsFeedParser parser( url );
|
||||
parser.storeEntryInSettings( testEntry );
|
||||
parser.storeEntryInSettings( testEntry2 );
|
||||
|
||||
// on relaunch, expired entries should be auto-pruned
|
||||
QgsNewsFeedParser parser2( url );
|
||||
QCOMPARE( parser2.entries().count(), 1 );
|
||||
QCOMPARE( parser2.entries().at( 0 ).title, QStringLiteral( "test entry" ) );
|
||||
QVERIFY( !parser2.entries().at( 0 ).expiry.isValid() );
|
||||
}
|
||||
|
||||
void TestQgsNewsFeedParser::testModel()
|
||||
{
|
||||
// test news feed model
|
||||
|
Loading…
x
Reference in New Issue
Block a user