QGIS API Documentation 3.99.0-Master (357b655ed83)
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 <QString>
26#include <QUrl>
27
28using namespace Qt::StringLiterals;
29
36
46class CORE_EXPORT QgsNewsFeedParser : public QObject
47{
48 Q_OBJECT
49
50 Q_PROPERTY( bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged );
51 Q_PROPERTY( bool isFetching READ isFetching NOTIFY isFetchingChanged );
52
53 public:
54
55#ifndef SIP_RUN
56 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeed = QgsSettingsTree::sTreeApp->createNamedListNode( u"news-feed"_s );
61
62 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeedEntries = sTreeNewsFeed->createNamedListNode( u"entries"_s );
69#endif
70
76 class Entry
77 {
78 public:
79
81 int key = 0;
82
84 QString title;
85
87 QString imageUrl;
88
90 QPixmap image;
91
93 QString content;
94
96 QUrl link;
97
99 bool sticky = false;
100
102 QDateTime expiry;
103 };
104
111 QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcfg = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
112
118 bool enabled() const SIP_SKIP { return mEnabled; }
119
125 void setEnabled( bool enabled ) SIP_SKIP;
126
132 bool isFetching() const { return mIsFetching; }
133
137 QList< QgsNewsFeedParser::Entry > entries() const;
138
146 Q_INVOKABLE void dismissEntry( int key );
147
152 Q_INVOKABLE void dismissAll();
153
157 QString authcfg() const;
158
162 static QString keyForFeed( const QString &baseUrl );
163
164 public slots:
165
170 void fetch();
171
172 signals:
173
179 void fetched( const QList< QgsNewsFeedParser::Entry > &entries );
180
188
198
206
211 void imageFetched( int key, const QPixmap &pixmap );
212
218
224
225 private slots:
226
227 void onFetch( const QString &content );
228
229 private:
230
231 QString mBaseUrl;
232 QUrl mFeedUrl;
233 QString mAuthCfg;
234 qint64 mFetchStartTime = 0;
235 QString mFeedKey;
236
237 QList< Entry > mEntries;
238 bool mBlockSignals = false;
239
240 bool mEnabled = true;
241 bool mIsFetching = false;
242
243 void readStoredEntries();
244 Entry readEntryFromSettings( int key );
245 void storeEntryInSettings( const Entry &entry );
246 void fetchImageForEntry( const Entry &entry );
247
249
250};
251
252#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
void enabledChanged()
Emitted when the enabled/disabled state of the feed URL associated to the news parser changes.
static QgsSettingsTreeNamedListNode * sTreeNewsFeed
static const QgsSettingsEntryString * settingsFeedEntryTitle
static const QgsSettingsEntryString * settingsFeedEntryLink
void fetched(const QList< QgsNewsFeedParser::Entry > &entries)
Emitted when entries have been fetched from the feed.
void isFetchingChanged()
Emitted when the news parser's fetching state changes.
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
static const QgsSettingsEntryDouble * settingsFeedLongitude
static const QgsSettingsEntryString * settingsFeedLanguage
bool enabled() const
Returns true if the feed URL associated with the news parser is enabled.
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()).
bool isFetching() const
Returns true if the news parser is fetching items.
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.
void setEnabled(bool enabled)
Sets whether the feed URL associated with the news parser is enabled.
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
#define SIP_SKIP
Definition qgis_sip.h:134