/***************************************************************************
 *   Copyright (C) 2008 by Ian Reinhart Geiser                             *
 *   geiseri@yahoo.com                                                     *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#ifndef RSSPROVIDER_H
#define RSSPROVIDER_H

#include <QObject>
#include <QString>
#include <QPixmap>
#include <QList>

class QTimer;
class QPainter;
class QTextDocument;
class QRectF;
class QWebPage;

struct RSSObject
{
    RSSObject( const QPixmap &i, const QString &t, const QString d) : image(i), title(t), description(d) {;}
    QPixmap image;
    QString title;
    QString description;
};

/**
Download an RSS feed and display titles in a channel.

	@author Ian Reinhart Geiser <igeiser@devonit.com>
*/
class RSSProvider : public QObject
{
Q_OBJECT
public:
    RSSProvider(QObject *parent = 0);
    ~RSSProvider();
	
signals:
     void newImage( const QPixmap &newPix );
	
private slots:
     void timeout();
     void downloadNewFeed();
     void renderWebPage();
private:
     QList<RSSObject> parseRSS( const QByteArray &xml ) const;
     void printTextBox( const QRectF & box, QTextDocument * text, QPainter * painter );
     void generateWebImage( const QString &html, const QString &url );
     QTimer *m_timer;
     int m_offset;
     QList<RSSObject> m_rss;
     QWebPage *m_desc;
};

#endif

