00001 /* ============================================================ 00002 * File : newsengine.h 00003 * Author: Renchi Raju <renchi@pooh.tam.uiuc.edu> 00004 * Date : 2003-09-03 00005 * Description : 00006 * 00007 * Copyright 2003 by Renchi Raju 00008 00009 * This program is free software; you can redistribute it 00010 * and/or modify it under the terms of the GNU General 00011 * Public License as published bythe Free Software Foundation; 00012 * either version 2, or (at your option) 00013 * any later version. 00014 * 00015 * This program is distributed in the hope that it will be useful, 00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 * GNU General Public License for more details. 00019 * 00020 * ============================================================ */ 00021 00022 #ifndef NEWSENGINE_H 00023 #define NEWSENGINE_H 00024 00025 #include <qstring.h> 00026 #include <qptrlist.h> 00027 #include <qobject.h> 00028 #include <qdatetime.h> 00029 #include <qcstring.h> 00030 00031 class QUrlOperator; 00032 class QNetworkOperation; 00033 class NewsSite; 00034 00035 // ------------------------------------------------------- 00036 00037 class NewsArticle 00038 { 00039 public: 00040 00041 typedef QPtrList<NewsArticle> List; 00042 00043 NewsArticle(NewsSite *parent, const QString& title, 00044 const QString& desc, const QString& artURL); 00045 ~NewsArticle(); 00046 00047 const QString& title() const; 00048 const QString& description() const; 00049 const QString& articleURL() const { return m_articleURL; } 00050 00051 private: 00052 00053 QString m_title; 00054 QString m_desc; 00055 NewsSite *m_parent; 00056 QString m_articleURL; 00057 }; 00058 00059 // ------------------------------------------------------- 00060 00061 class NewsSite : public QObject 00062 { 00063 Q_OBJECT 00064 00065 public: 00066 00067 enum State { 00068 Retrieving = 0, 00069 RetrieveFailed, 00070 WriteFailed, 00071 Success 00072 }; 00073 00074 typedef QPtrList<NewsSite> List; 00075 00076 NewsSite(const QString& name, const QString& url, 00077 const QDateTime& updated); 00078 ~NewsSite(); 00079 00080 const QString& url() const; 00081 const QString& name() const; 00082 QString description() const; 00083 const QDateTime& lastUpdated() const; 00084 unsigned int timeSinceLastUpdate() const; // in minutes 00085 00086 void insertNewsArticle(NewsArticle* item); 00087 void clearNewsArticles(); 00088 NewsArticle::List& articleList(); 00089 00090 void retrieve(); 00091 void stop(); 00092 void process(); 00093 00094 bool successful() const; 00095 QString errorMsg() const; 00096 00097 private: 00098 00099 QString m_name; 00100 QString m_url; 00101 QString m_desc; 00102 QDateTime m_updated; 00103 QString m_destDir; 00104 QByteArray m_data; 00105 State m_state; 00106 QString m_errorString; 00107 00108 NewsArticle::List m_articleList; 00109 QUrlOperator* m_urlOp; 00110 00111 void ReplaceHtmlChar( QString &s); 00112 00113 signals: 00114 00115 void finished(NewsSite* item); 00116 00117 private slots: 00118 00119 void slotFinished(QNetworkOperation*); 00120 void slotGotData(const QByteArray& data, 00121 QNetworkOperation* op); 00122 }; 00123 00124 #endif /* NEWSENGINE_H */
1.5.5