QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 "qgssettingsentryimpl.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
115  static const inline QgsSettingsEntryInteger settingsFeedLastFetchTime = QgsSettingsEntryInteger( QStringLiteral( "%1/lastFetchTime" ), QgsSettings::Prefix::CORE, 0, QObject::tr( "Feed last fetch time" ), Qgis::SettingsOptions(), 0 );
118  static const inline QgsSettingsEntryString settingsFeedLanguage = QgsSettingsEntryString( QStringLiteral( "%1/lang" ), QgsSettings::Prefix::CORE, QString(), QObject::tr( "Feed language" ) );
120  static const inline QgsSettingsEntryDouble settingsFeedLatitude = QgsSettingsEntryDouble( QStringLiteral( "%1/latitude" ), QgsSettings::Prefix::CORE, 0.0, QObject::tr( "Feed latitude" ) );
122  static const inline QgsSettingsEntryDouble settingsFeedLongitude = QgsSettingsEntryDouble( QStringLiteral( "%1/longitude" ), QgsSettings::Prefix::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 
156  void entryDismissed( const QgsNewsFeedParser::Entry &entry );
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
QgsNewsFeedParser
Parser for published QGIS news feeds.
Definition: qgsnewsfeedparser.h:37
QgsSettingsEntryString
A string settings entry.
Definition: qgssettingsentryimpl.h:87
QgsSettingsEntryInteger
An integer settings entry.
Definition: qgssettingsentryimpl.h:299
QgsNewsFeedParser::Entry::expiry
QDateTime expiry
Optional auto-expiry time for entry.
Definition: qgsnewsfeedparser.h:73
QgsNetworkContentFetcher
HTTP network content fetcher. A simple method for fetching remote HTTP content and converting the con...
Definition: qgsnetworkcontentfetcher.h:39
qgis_sip.h
qgssettingsentryimpl.h
QgsNewsFeedParser::Entry::link
QUrl link
Optional URL link for entry.
Definition: qgsnewsfeedparser.h:67
QgsSettingsEntryDouble
A double settings entry.
Definition: qgssettingsentryimpl.h:394
QgsNewsFeedParser::Entry::title
QString title
Entry title.
Definition: qgsnewsfeedparser.h:55
QgsNewsFeedParser::Entry::content
QString content
HTML content of news entry.
Definition: qgsnewsfeedparser.h:64
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:58
QgsNewsFeedParser::Entry::image
QPixmap image
Optional image data.
Definition: qgsnewsfeedparser.h:61
SIP_TRANSFERTHIS
#define SIP_TRANSFERTHIS
Definition: qgis_sip.h:53
QgsSettings::Prefix::CORE
static const char * CORE
Definition: qgssettings.h:91