QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QObject>
21 #include <QUrl>
22 #include <QPixmap>
23 #include <QDateTime>
24 
26 
36 class CORE_EXPORT QgsNewsFeedParser : public QObject
37 {
38  Q_OBJECT
39  public:
40 
46  class Entry
47  {
48  public:
49 
51  int key = 0;
52 
54  QString title;
55 
57  QString imageUrl;
58 
60  QPixmap image;
61 
63  QString content;
64 
66  QUrl link;
67 
69  bool sticky = false;
70 
72  QDateTime expiry;
73  };
74 
81  QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcfg = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
82 
86  QList< QgsNewsFeedParser::Entry > entries() const;
87 
95  void dismissEntry( int key );
96 
101  void dismissAll();
102 
106  QString authcfg() const;
107 
111  static QString keyForFeed( const QString &baseUrl );
112 
113  public slots:
114 
119  void fetch();
120 
121  signals:
122 
128  void fetched( const QList< QgsNewsFeedParser::Entry > &entries );
129 
136  void entryAdded( const QgsNewsFeedParser::Entry &entry );
137 
145 
150  void imageFetched( int key, const QPixmap &pixmap );
151 
152  private slots:
153 
154  void onFetch( const QString &content );
155 
156  private:
157 
158  QString mBaseUrl;
159  QUrl mFeedUrl;
160  QString mAuthCfg;
161  qint64 mFetchStartTime = 0;
162  QString mSettingsKey;
163 
164  QList< Entry > mEntries;
165  bool mBlockSignals = false;
166 
167  void readStoredEntries();
168  Entry readEntryFromSettings( int key );
169  void storeEntryInSettings( const Entry &entry );
170  void fetchImageForEntry( const Entry &entry );
171 
172  friend class TestQgsNewsFeedParser;
173 
174 };
175 
176 #endif // QGSNEWSFEEDPARSER_H
QgsNewsFeedParser
Parser for published QGIS news feeds.
Definition: qgsnewsfeedparser.h:37
QgsNewsFeedParser::entryDismissed
void entryDismissed(const QgsNewsFeedParser::Entry &entry)
Emitted whenever an entry is dismissed (as a result of a call to dismissEntry()).
QgsNewsFeedParser::entryAdded
void entryAdded(const QgsNewsFeedParser::Entry &entry)
Emitted whenever a new entry is available from the feed (as a result of a call to fetch()).
QgsNewsFeedParser::Entry::expiry
QDateTime expiry
Optional auto-expiry time for entry.
Definition: qgsnewsfeedparser.h:72
QgsNetworkContentFetcher
HTTP network content fetcher.
Definition: qgsnetworkcontentfetcher.h:38
QgsNewsFeedParser::fetched
void fetched(const QList< QgsNewsFeedParser::Entry > &entries)
Emitted when entries have fetched from the feed.
qgis_sip.h
QgsNewsFeedParser::Entry::link
QUrl link
Optional URL link for entry.
Definition: qgsnewsfeedparser.h:66
QgsNewsFeedParser::Entry::title
QString title
Entry title.
Definition: qgsnewsfeedparser.h:54
QgsNewsFeedParser::imageFetched
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...
QgsNewsFeedParser::Entry::content
QString content
HTML content of news entry.
Definition: qgsnewsfeedparser.h:63
QgsNewsFeedParser::Entry
Represents a single entry from a news feed.
Definition: qgsnewsfeedparser.h:47
QgsNewsFeedParser::Entry::imageUrl
QString imageUrl
Optional URL for image associated with entry.
Definition: qgsnewsfeedparser.h:57
QgsNewsFeedParser::Entry::image
QPixmap image
Optional image data.
Definition: qgsnewsfeedparser.h:60
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53