QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 "qgssettingsentry.h"
21 #include <QObject>
22 #include <QUrl>
23 #include <QPixmap>
24 #include <QDateTime>
25 
27 
37 class CORE_EXPORT QgsNewsFeedParser : public QObject
38 {
39  Q_OBJECT
40  public:
41 
47  class Entry
48  {
49  public:
50 
52  int key = 0;
53 
55  QString title;
56 
58  QString imageUrl;
59 
61  QPixmap image;
62 
64  QString content;
65 
67  QUrl link;
68 
70  bool sticky = false;
71 
73  QDateTime expiry;
74  };
75 
82  QgsNewsFeedParser( const QUrl &feedUrl, const QString &authcfg = QString(), QObject *parent SIP_TRANSFERTHIS = nullptr );
83 
87  QList< QgsNewsFeedParser::Entry > entries() const;
88 
96  void dismissEntry( int key );
97 
102  void dismissAll();
103 
107  QString authcfg() const;
108 
112  static QString keyForFeed( const QString &baseUrl );
113 
114 #ifndef SIP_RUN
116  static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%1/lastFetchTime" ), QgsSettings::Core, 0, QObject::tr( "Feed last fetch time" ), 0 );
118  static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%1/lang" ), QgsSettings::Core, QString(), QObject::tr( "Feed language" ) );
120  static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%1/latitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed latitude" ) );
122  static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%1/longitude" ), QgsSettings::Core, 0.0, QObject::tr( "Feed longitude" ) );
123 #endif
124 
125  public slots:
126 
131  void fetch();
132 
133  signals:
134 
140  void fetched( const QList< QgsNewsFeedParser::Entry > &entries );
141 
148  void entryAdded( const QgsNewsFeedParser::Entry &entry );
149 
157 
162  void imageFetched( int key, const QPixmap &pixmap );
163 
164  private slots:
165 
166  void onFetch( const QString &content );
167 
168  private:
169 
170  QString mBaseUrl;
171  QUrl mFeedUrl;
172  QString mAuthCfg;
173  qint64 mFetchStartTime = 0;
174  QString mSettingsKey;
175 
176  QList< Entry > mEntries;
177  bool mBlockSignals = false;
178 
179  void readStoredEntries();
180  Entry readEntryFromSettings( int key );
181  void storeEntryInSettings( const Entry &entry );
182  void fetchImageForEntry( const Entry &entry );
183 
184  friend class TestQgsNewsFeedParser;
185 
186 };
187 
188 #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()).
void fetched(const QList< QgsNewsFeedParser::Entry > &entries)
Emitted when entries have fetched from the feed.
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 double settings entry.
An integer settings entry.
A string settings entry.
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53