00001 #ifndef MYTHRSSMANAGER_H
00002 #define MYTHRSSMANAGER_H
00003
00004 #include <vector>
00005 using namespace std;
00006
00007 #include <QObject>
00008 #include <QMetaType>
00009 #include <QMutex>
00010 #include <QTimer>
00011 #include <QDateTime>
00012 #include <QByteArray>
00013 #include <QVariant>
00014 #include <QNetworkReply>
00015
00016 #include "rssparse.h"
00017
00018 #include "mythhttppool.h"
00019
00020 class RSSSite;
00021 class MPUBLIC RSSSite : public QObject
00022 {
00023 Q_OBJECT
00024
00025 public:
00026
00027 class List : public vector<RSSSite*>
00028 {
00029 public:
00030 void clear(void)
00031 {
00032 while (size())
00033 {
00034 RSSSite *tmp = back();
00035 pop_back();
00036 tmp->deleteLater();
00037 }
00038 }
00039 };
00040
00041 RSSSite(const QString& title,
00042 const QString& image,
00043 const ArticleType& type,
00044 const QString& description,
00045 const QString& url,
00046 const QString& author,
00047 const bool& download,
00048 const QDateTime& updated);
00049
00050 ~RSSSite();
00051
00052 typedef QList<RSSSite *> rssList;
00053
00054 const QString& GetTitle() const { return m_title; }
00055 const QString& GetImage() const { return m_image; }
00056 const ArticleType& GetType() const { return m_type; }
00057 const QString& GetDescription() const { return m_description; }
00058 const QString& GetURL() const { return m_url; }
00059 const QString& GetAuthor() const { return m_author; }
00060 const bool& GetDownload() const { return m_download; }
00061 const QDateTime& GetUpdated() const { return m_updated; }
00062
00063 unsigned int timeSinceLastUpdate(void) const;
00064
00065 void insertRSSArticle(ResultItem *item);
00066 void clearRSSArticles(void);
00067
00068 ResultItem::resultList GetVideoList(void) const;
00069
00070 void retrieve(void);
00071 void stop(void);
00072 void process(void);
00073
00074 private:
00075
00076 QUrl redirectUrl(const QUrl& possibleRedirectUrl,
00077 const QUrl& oldRedirectUrl) const;
00078
00079 QString m_title;
00080 QString m_image;
00081 ArticleType m_type;
00082 QString m_description;
00083 QString m_url;
00084 QUrl m_urlReq;
00085 QString m_author;
00086 bool m_download;
00087 QDateTime m_updated;
00088
00089 mutable QMutex m_lock;
00090 QByteArray m_data;
00091 QString m_imageURL;
00092 bool m_podcast;
00093
00094 ResultItem::resultList m_articleList;
00095
00096 QNetworkReply *m_reply;
00097 QNetworkAccessManager *m_manager;
00098
00099 private slots:
00100 void slotCheckRedirect(QNetworkReply* reply);
00101
00102 signals:
00103
00104 void finished(RSSSite *item);
00105
00106 };
00107
00108 class MPUBLIC RSSManager : public QObject
00109 {
00110 Q_OBJECT
00111
00112 public:
00113 RSSManager();
00114 ~RSSManager();
00115 void startTimer();
00116 void stopTimer();
00117
00118 signals:
00119 void finished();
00120
00121 public slots:
00122 void doUpdate();
00123
00124 private slots:
00125 void slotRefreshRSS(void);
00126 void slotRSSRetrieved(RSSSite*);
00127
00128 private:
00129 void processAndInsertRSS(RSSSite *site);
00130
00131 QTimer *m_timer;
00132 RSSSite::rssList m_sites;
00133 uint m_updateFreq;
00134 RSSSite::rssList m_inprogress;
00135 };
00136
00137 Q_DECLARE_METATYPE(RSSSite*)
00138
00139 #endif