QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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#ifndef SIP_RUN
55 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeed = QgsSettingsTree::sTreeApp->createNamedListNode( u"news-feed"_s );
60
61 static inline QgsSettingsTreeNamedListNode *sTreeNewsFeedEntries = sTreeNewsFeed->createNamedListNode( u"entries"_s );
68#endif
69
75 class Entry
76 {
77 public:
79 int key = 0;
80
82 QString title;
83
85 QString imageUrl;
86
88 QPixmap image;
89
91 QString content;
92
94 QUrl link;
95
97 bool sticky = false;
98
100 QDateTime expiry;
101 };
102
109 QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcfg = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
110
116 bool enabled() const SIP_SKIP { return mEnabled; }
117
123 void setEnabled( bool enabled ) SIP_SKIP;
124
130 bool isFetching() const { return mIsFetching; }
131
135 QList< QgsNewsFeedParser::Entry > entries() const;
136
144 Q_INVOKABLE void dismissEntry( int key );
145
150 Q_INVOKABLE void dismissAll();
151
155 QString authcfg() const;
156
160 static QString keyForFeed( const QString &baseUrl );
161
162 public slots:
163
168 void fetch();
169
170 signals:
171
177 void fetched( const QList< QgsNewsFeedParser::Entry > &entries );
178
186
196
204
209 void imageFetched( int key, const QPixmap &pixmap );
210
216
222
223 private slots:
224
225 void onFetch( const QString &content );
226
227 private:
228 QString mBaseUrl;
229 QUrl mFeedUrl;
230 QString mAuthCfg;
231 qint64 mFetchStartTime = 0;
232 QString mFeedKey;
233
234 QList< Entry > mEntries;
235 bool mBlockSignals = false;
236
237 bool mEnabled = true;
238 bool mIsFetching = false;
239
240 void readStoredEntries();
241 Entry readEntryFromSettings( int key );
242 void storeEntryInSettings( const Entry &entry );
243 void fetchImageForEntry( const Entry &entry );
244
246};
247
248#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:52
#define SIP_SKIP
Definition qgis_sip.h:133