QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
144  void entryDismissed( const QgsNewsFeedParser::Entry &entry );
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  uint 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
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
Represents a single entry from a news feed.
QDateTime expiry
Optional auto-expiry time for entry.
HTTP network content fetcher.
Parser for published QGIS news feeds.
QString content
HTML content of news entry.
QString title
Entry title.
QString imageUrl
Optional URL for image associated with entry.
QUrl link
Optional URL link for entry.
QPixmap image
Optional image data.