aboutsummaryrefslogtreecommitdiff
path: root/src-qt5/core/lumina-desktop/desktop-plugins/rssreader/RSSObjects.h
blob: 3069bf8dba44277dcf3eb6d8c723315d9a2c4f48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//===========================================
//  Lumina-DE source code
//  Copyright (c) 2016, Ken Moore
//  Available under the 3-clause BSD license
//  See the LICENSE file for full details
//===========================================
#ifndef _LUMINA_DESKTOP_RSS_READER_PLUGIN_OBJECT_H
#define _LUMINA_DESKTOP_RSS_READER_PLUGIN_OBJECT_H

#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QString>
#include <QDateTime>
#include <QList>
#include <QIcon>
#include <QTimer>
#include <QXmlStreamReader> //Contained in the Qt "core" module - don't need the full "xml" module for this
#include <QSslError>

struct RSSitem{
  //Required Fields
  QString title, link, description;

  //Optional Fields
  QString comments_url, author_email, author, guid;
  QDateTime pubdate; //when the item was published
  //IGNORED INFO from RSS2 spec: "category", "source", "enclosure"
};

struct RSSchannel{
  //Required fields
  QString title, link, description;

  //Optional Fields
  QDateTime lastBuildDate, lastPubDate; //last build/publish dates
  // - channel refresh information
  int timetolive; //in minutes - time until next sync should be performed
  //QList<int> skiphours;
  //QStringList skipdays;
  // - icon info
  QIcon icon;
  QString icon_url, icon_title, icon_link, icon_description;
  QSize icon_size;
  //All items within this channel
  QList<RSSitem> items;

  //Optional RSS2 elements ignored:
  // "cloud", "textInput", "rating", "language", "copyright", "managingEditor", "webMaster",
  // "category", "generator", "docs"

  //Internal data for bookkeeping
  QDateTime lastsync, nextsync;
  QString originalURL; //in case it was redirected to some "fixed" url later
};

class RSSReader : public QObject{
	Q_OBJECT
public:
	RSSReader(QObject *parent, QString settingsPrefix);
	~RSSReader();

	//Information retrieval
	QStringList channels(); //returns all ID's
	RSSchannel dataForID(QString ID);

	//Initial setup
	void addUrls(QStringList urls);
	void removeUrl(QString ID);
	
public slots:
	void syncNow(); //not generally needed

private:
	//Internal data objects
	QHash<QString, RSSchannel> hash; // ID/data
        QString setprefix;
	QTimer *syncTimer;	
	QNetworkAccessManager *NMAN;
        QStringList outstandingURLS;


	//Simple hash data search functions
        QString keyForUrl(QString url);

	//Network request function
	void requestRSS(QString url);
	
	//RSS parsing functions
	RSSchannel readRSS(QByteArray bytes);
	RSSchannel readRSSChannel(QXmlStreamReader *rss);
	RSSitem readRSSItem(QXmlStreamReader *rss);
        void readRSSImage(RSSchannel *item, QXmlStreamReader *rss);
	QDateTime RSSDateTime(QString datetime);

private slots:
	void replyFinished(QNetworkReply *reply);
	void sslErrors(QNetworkReply *reply, const QList<QSslError> &errors);
	void checkTimes();

signals:
	void rssChanged(QString); //ID
	void newChannelsAvailable();
};

#endif
bgstack15