QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsnewsfeedparser.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsnewsfeedparser.h
3 -------------------
4 begin : July 2019
5 copyright : (C) 2019 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15#ifndef QGSNEWSFEEDPARSER_H
16#define QGSNEWSFEEDPARSER_H
17
18#include "qgis_core.h"
19#include "qgis_sip.h"
20#include "qgssettingstree.h"
21
22#include <QDateTime>
23#include <QObject>
24#include <QPixmap>
25#include <QUrl>
26
33
43class CORE_EXPORT QgsNewsFeedParser : public QObject
44{
45 Q_OBJECT
46 public:
47
48#ifndef SIP_RUN
49 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeed = QgsSettingsTree::sTreeApp->createNamedListNode( QStringLiteral( "news-feed" ) );
54
55 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeedEntries = sTreeNewsFeed->createNamedListNode( QStringLiteral( "entries" ) );
62#endif
63
69 class Entry
70 {
71 public:
72
74 int key = 0;
75
77 QString title;
78
80 QString imageUrl;
81
83 QPixmap image;
84
86 QString content;
87
89 QUrl link;
90
92 bool sticky = false;
93
95 QDateTime expiry;
96 };
97
104 QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcfg = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
105
109 QList< QgsNewsFeedParser::Entry > entries() const;
110
118 void dismissEntry( int key );
119
124 void dismissAll();
125
129 QString authcfg() const;
130
134 static QString keyForFeed( const QString &baseUrl );
135
136 public slots:
137
142 void fetch();
143
144 signals:
145
151 void fetched( const QList< QgsNewsFeedParser::Entry > &entries );
152
160
170
178
183 void imageFetched( int key, const QPixmap &pixmap );
184
185 private slots:
186
187 void onFetch( const QString &content );
188
189 private:
190
191 QString mBaseUrl;
192 QUrl mFeedUrl;
193 QString mAuthCfg;
194 qint64 mFetchStartTime = 0;
195 QString mFeedKey;
196
197 QList< Entry > mEntries;
198 bool mBlockSignals = false;
199
200 void readStoredEntries();
201 Entry readEntryFromSettings( int key );
202 void storeEntryInSettings( const Entry &entry );
203 void fetchImageForEntry( const Entry &entry );
204
206
207};
208
209#endif // QGSNEWSFEEDPARSER_H
HTTP network content fetcher.
Represents a single entry from a news feed.
QString content
HTML content of news entry.
bool sticky
true if entry is "sticky" and should always be shown at the top
QUrl link
Optional URL link for entry.
QString imageUrl
Optional URL for image associated with entry.
QPixmap image
Optional image data.
QDateTime expiry
Optional auto-expiry time for entry.
int key
Unique entry identifier.
QString title
Entry title.
void entryDismissed(const QgsNewsFeedParser::Entry &entry)
Emitted whenever an entry is dismissed (as a result of a call to dismissEntry()).
static QgsSettingsTreeNamedListNode * sTreeNewsFeedEntries
static QgsSettingsTreeNamedListNode * sTreeNewsFeed
static const QgsSettingsEntryString * settingsFeedEntryTitle
void dismissEntry(int key)
Dismisses an entry with matching key.
static const QgsSettingsEntryString * settingsFeedEntryLink
void fetch()
Fetches new entries from the feed's URL.
void fetched(const QList< QgsNewsFeedParser::Entry > &entries)
Emitted when entries have been fetched from the feed.
friend class TestQgsNewsFeedParser
static const QgsSettingsEntryString * settingsFeedEntryImageUrl
static const QgsSettingsEntryDouble * settingsFeedLatitude
QString authcfg() const
Returns the authentication configuration for the parser.
static const QgsSettingsEntryInteger64 * settingsFeedLastFetchTime
QgsNewsFeedParser(const QUrl &feedUrl, const QString &authcfg=QString(), QObject *parent=nullptr)
Constructor for QgsNewsFeedParser, parsing the specified feedUrl.
static const QgsSettingsEntryBool * settingsFeedEntrySticky
void dismissAll()
Dismisses all current news items.
static const QgsSettingsEntryDouble * settingsFeedLongitude
static const QgsSettingsEntryString * settingsFeedLanguage
static const QgsSettingsEntryString * settingsFeedEntryContent
void entryUpdated(const QgsNewsFeedParser::Entry &entry)
Emitted whenever an existing entry is available from the feed (as a result of a call to fetch()).
static const QgsSettingsEntryVariant * settingsFeedEntryExpiry
static QString keyForFeed(const QString &baseUrl)
Returns the settings key used for a feed with the given baseUrl.
void entryAdded(const QgsNewsFeedParser::Entry &entry)
Emitted whenever a new entry is available from the feed (as a result of a call to fetch()).
void imageFetched(int key, const QPixmap &pixmap)
Emitted when the image attached to the entry with the specified key has been fetched and is now avail...
QList< QgsNewsFeedParser::Entry > entries() const
Returns a list of existing entries in the feed.
A boolean settings entry.
A double settings entry.
A 64 bits integer (long long) settings entry.
A string settings entry.
A variant settings entry.
A named list tree node for the settings tree to help organizing and introspecting the tree.
static QgsSettingsTreeNode * sTreeApp
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53