QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
23#include <QObject>
24#include <QUrl>
25#include <QPixmap>
26#include <QDateTime>
27
34
44class CORE_EXPORT QgsNewsFeedParser : public QObject
45{
46 Q_OBJECT
47 public:
48
49#ifndef SIP_RUN
50 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeed = QgsSettingsTree::sTreeApp->createNamedListNode( QStringLiteral( "news-feed" ) );
55
56 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeedEntries = sTreeNewsFeed->createNamedListNode( QStringLiteral( "entries" ) );
63#endif
64
70 class Entry
71 {
72 public:
73
75 int key = 0;
76
78 QString title;
79
81 QString imageUrl;
82
84 QPixmap image;
85
87 QString content;
88
90 QUrl link;
91
93 bool sticky = false;
94
96 QDateTime expiry;
97 };
98
105 QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcfg = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
106
110 QList< QgsNewsFeedParser::Entry > entries() const;
111
119 void dismissEntry( int key );
120
125 void dismissAll();
126
130 QString authcfg() const;
131
135 static QString keyForFeed( const QString &baseUrl );
136
137 public slots:
138
143 void fetch();
144
145 signals:
146
152 void fetched( const QList< QgsNewsFeedParser::Entry > &entries );
153
161
171
179
184 void imageFetched( int key, const QPixmap &pixmap );
185
186 private slots:
187
188 void onFetch( const QString &content );
189
190 private:
191
192 QString mBaseUrl;
193 QUrl mFeedUrl;
194 QString mAuthCfg;
195 qint64 mFetchStartTime = 0;
196 QString mFeedKey;
197
198 QList< Entry > mEntries;
199 bool mBlockSignals = false;
200
201 void readStoredEntries();
202 Entry readEntryFromSettings( int key );
203 void storeEntryInSettings( const Entry &entry );
204 void fetchImageForEntry( const Entry &entry );
205
206 friend class TestQgsNewsFeedParser;
207
208};
209
210#endif // QGSNEWSFEEDPARSER_H
HTTP network content fetcher.
Represents a single entry from a news feed.
QString content
HTML content of news entry.
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.
QString title
Entry title.
Parser for published QGIS news feeds.
void entryDismissed(const QgsNewsFeedParser::Entry &entry)
Emitted whenever an entry is dismissed (as a result of a call to dismissEntry()).
static const QgsSettingsEntryString * settingsFeedEntryTitle
static const QgsSettingsEntryString * settingsFeedEntryLink
void fetched(const QList< QgsNewsFeedParser::Entry > &entries)
Emitted when entries have been fetched from the feed.
static const QgsSettingsEntryString * settingsFeedEntryImageUrl
static const QgsSettingsEntryDouble * settingsFeedLatitude
static const QgsSettingsEntryInteger64 * settingsFeedLastFetchTime
static const QgsSettingsEntryBool * settingsFeedEntrySticky
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
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...
A boolean settings entry.
A double settings entry.
A 64 bits integer (long long) settings entry.
A string settings entry.
A variant settings entry.
QgsSettingsTreeNamedListNode is a named list tree node for the settings tree to help organizing and i...
QgsSettingsTreeNamedListNode * createNamedListNode(const QString &key, const Qgis::SettingsTreeNodeOptions &options=Qgis::SettingsTreeNodeOptions())
Creates a named list tree node.
static QgsSettingsTreeNode * sTreeApp
#define SIP_TRANSFERTHIS
Definition qgis_sip.h:53