// (c) 2006 Seb Ruiz <me@sebruiz.net>
// See COPYING file for licensing information

#ifndef AMAROK_PODCASTBUNDLE_H
#define AMAROK_PODCASTBUNDLE_H

#include "podcastsettings.h"
#include <kurl.h>
#include <krfcdate.h>
#include <tqdatetime.h>

class PodcastChannelBundle
{
    public:
        PodcastChannelBundle()
            : m_parentId( -1 )
            , m_autoscan( false )
            , m_fetchType( -1 )
            , m_autotransfer( false )
            , m_purge( false )
            , m_purgeCount( -1 ) { }

        PodcastChannelBundle( const KURL &url, const TQString &title, const TQString &author, const KURL &link,
                              const TQString &desc,  const TQString &copy, PodcastSettings *settings )
        {   m_url = url;
            m_title = title;
            m_author = author;
            m_link = link;
            m_description = desc;
            m_copyright = copy;
            m_parentId = -1;
            setSettings( settings );
        }

        void setSettings( PodcastSettings *settings )
        {
            m_saveLocation = settings->saveLocation();
            m_autoscan     = settings->autoscan();
            m_fetchType    = settings->fetchType();
            m_autotransfer = settings->autoTransfer();
            m_purge        = settings->hasPurge();
            m_purgeCount   = settings->purgeCount();
        }

        PodcastSettings * getSettings()
        {
            return new PodcastSettings( m_title, m_saveLocation, m_autoscan, m_fetchType,
                                        m_autotransfer, m_purge, m_purgeCount );
        }

        /// Return the url of the podcast feed
        const KURL    &url()         const;
        /// The title of the Podcast channel
        const TQString &title()       const;
        /// The author of the Podcast channel
        const TQString &author()      const;
        /// A url to the webpage of the podcast
        const KURL    &link()        const;
        /// A url to the image of the podcast
        const KURL    &imageURL()    const;
        const TQString &description() const;
        const TQString &copyright()   const;
        /// The id which the parent folder has in the database
        int     parentId()    const;

        void    setURL( const KURL &u );
        void    setTitle( const TQString &t );
        void    setAuthor( const TQString &a );
        void    setLink( const KURL &l );
        void    setImageURL( const KURL &i );
        void    setDescription( const TQString &d );
        void    setCopyright( const TQString &c );
        void    setParentId( const int p );

        void    setSaveLocation( const TQString &s );
        void    setAutoScan( const bool b );
        void    setFetchType( const int i );
        void    setAutoTransfer( const bool b );
        void    setPurge( const bool b );
        void    setPurgeCount( const int i );

        //settings
        const TQString& saveLocation() const;
        bool autoscan()     const;
        int  fetchType()    const;
        bool autotransfer() const;
        bool hasPurge()     const;
        int  purgeCount()   const;

    private:
        KURL    m_url;
        TQString m_title;
        TQString m_author;
        KURL    m_link;
        KURL    m_imageUrl;
        TQString m_description;
        TQString m_copyright;
        int     m_parentId;

        TQString m_saveLocation;
        bool    m_autoscan;
        int     m_fetchType;
        bool    m_autotransfer;
        bool    m_purge;
        int     m_purgeCount;
};

inline const KURL    &PodcastChannelBundle::url()         const { return m_url; }
inline const TQString &PodcastChannelBundle::title()       const { return m_title; }
inline const TQString &PodcastChannelBundle::author()      const { return m_author; }
inline const KURL    &PodcastChannelBundle::link()        const { return m_link; }
inline const KURL    &PodcastChannelBundle::imageURL()    const { return m_imageUrl; }
inline const TQString &PodcastChannelBundle::description() const { return m_description; }
inline const TQString &PodcastChannelBundle::copyright()   const { return m_copyright; }
inline int     PodcastChannelBundle::parentId()    const { return m_parentId; }

inline void    PodcastChannelBundle::setURL         ( const KURL &u )    { m_url = u; }
inline void    PodcastChannelBundle::setTitle       ( const TQString &t ) { m_title = t; }
inline void    PodcastChannelBundle::setAuthor      ( const TQString &a ) { m_author = a; }
inline void    PodcastChannelBundle::setLink        ( const KURL &l )    { m_link = l; }
inline void    PodcastChannelBundle::setImageURL    ( const KURL &i )    { m_imageUrl = i; }
inline void    PodcastChannelBundle::setDescription ( const TQString &d ) { m_description = d; }
inline void    PodcastChannelBundle::setCopyright   ( const TQString &c ) { m_copyright = c; }
inline void    PodcastChannelBundle::setParentId    ( const int p )      { m_parentId = p; }

inline void    PodcastChannelBundle::setSaveLocation( const TQString &s ) { m_saveLocation = s; }
inline void    PodcastChannelBundle::setAutoScan( const bool b )         { m_autoscan = b; }
inline void    PodcastChannelBundle::setFetchType( const int i )         { m_fetchType = i; }
inline void    PodcastChannelBundle::setAutoTransfer( const bool b )     { m_autotransfer = b; }
inline void    PodcastChannelBundle::setPurge( const bool b )            { m_purge = b; }
inline void    PodcastChannelBundle::setPurgeCount( const int i )        { m_purgeCount = i; }

inline const TQString &PodcastChannelBundle::saveLocation() const { return m_saveLocation; }
inline bool    PodcastChannelBundle::autoscan()     const { return m_autoscan; }
inline int     PodcastChannelBundle::fetchType()    const { return m_fetchType; }
inline bool    PodcastChannelBundle::autotransfer() const { return m_autotransfer; }
inline bool    PodcastChannelBundle::hasPurge()     const { return m_purge; }
inline int     PodcastChannelBundle::purgeCount()   const { return m_purgeCount; }



class PodcastEpisodeBundle
{
    public:
        PodcastEpisodeBundle()
            : m_id( 0 )
            , m_duration( 0 )
            , m_size( 0 )
            , m_isNew( false )
        {
        }
        PodcastEpisodeBundle( const KURL &url,       const KURL &parent,  const TQString &title,
                              const TQString &author, const TQString &desc, const TQString &date,
                              const TQString &type,   const int duration,  const TQString &guid,
                              const bool isNew  )
            : m_id( 0 )
            , m_size( 0 )
        {
            m_url = url;
            m_parent = parent;
            m_author = author;
            m_title = title;
            m_description = desc;
            m_type = type;
            m_date = date;
            m_duration = duration < 0 ? 0 : duration;
            m_guid = guid;
            m_isNew = isNew;

            if( !date.isEmpty() )
                m_dateTime.setTime_t( KRFCDate::parseDate( date ) );
        }

        /// The row id which this podcast episode has in the database
        int     dBId()        const;
        /// The remote url to the podcast episode
        const KURL    &url()         const;
        /// The local url of the podcast episode (if it has been downloaded, an invalid url otherwise)
        const KURL    &localUrl()    const;
        /// The url of the podcast channel
        const KURL    &parent()      const;
        const TQString &author()      const;
        const TQString &title()       const;
        const TQString &subtitle()    const;
        const TQString &description() const;
        const TQString &date()        const;
        TQDateTime dateTime()  const;
        /// File type of the podcast episode, eg ogg, mp3 etc
        const TQString &type()        const;
        int     duration()    const; // duration in seconds
        uint    size()        const; // file/stream size in bytes
        /// unique identifier that should be available in the feed (RSS 2.0: guid ATOM: id)
        const TQString &guid()        const;
        /// Has this particular podcast episode been listened to?
        bool    isNew()       const;

        void    setDBId( const int i );
        void    setURL( const KURL &u );
        void    setLocalURL( const KURL &u );
        void    setParent( const KURL &u );
        void    setAuthor( const TQString &a );
        void    setTitle( const TQString &t );
        void    setSubtitle( const TQString &s );
        void    setDescription( const TQString &d );
        void    setDate( const TQString &d );
        void    setType( const TQString &t );
        void    setDuration( const int i );
        void    setSize( const uint i );
        void    setGuid( const TQString &g );
        void    setNew( const bool &b );

        void detach(); // for being able to apply TQDeepCopy<>

    private:
        int     m_id;
        KURL    m_url;
        KURL    m_localUrl;
        KURL    m_parent;
        TQString m_author;
        TQString m_title;
        TQString m_subtitle;
        TQString m_description;
        TQString m_date;
        TQDateTime m_dateTime;
        TQString m_type;
        int     m_duration;
        uint    m_size;
        TQString m_guid;
        bool    m_isNew;
};

inline int            PodcastEpisodeBundle::dBId()        const { return m_id; }
inline const KURL    &PodcastEpisodeBundle::url()         const { return m_url; }
inline const KURL    &PodcastEpisodeBundle::localUrl()    const { return m_localUrl; }
inline const KURL    &PodcastEpisodeBundle::parent()      const { return m_parent; }
inline const TQString &PodcastEpisodeBundle::author()      const { return m_author; }
inline const TQString &PodcastEpisodeBundle::title()       const { return m_title; }
inline const TQString &PodcastEpisodeBundle::subtitle()    const { return m_subtitle; }
inline const TQString &PodcastEpisodeBundle::description() const { return m_description; }
inline const TQString &PodcastEpisodeBundle::date()        const { return m_date; }
inline TQDateTime      PodcastEpisodeBundle::dateTime()    const { return m_dateTime; }
inline const TQString &PodcastEpisodeBundle::type()        const { return m_type; }
inline int            PodcastEpisodeBundle::duration()    const { return m_duration; }
inline uint           PodcastEpisodeBundle::size()        const { return m_size; }
inline const TQString &PodcastEpisodeBundle::guid()        const { return m_guid; }
inline bool           PodcastEpisodeBundle::isNew()       const { return m_isNew; }

inline void    PodcastEpisodeBundle::setDBId( const int i )             { m_id = i; }
inline void    PodcastEpisodeBundle::setURL( const KURL &u )            { m_url = u; }
inline void    PodcastEpisodeBundle::setLocalURL( const KURL &u )       { m_localUrl = u; }
inline void    PodcastEpisodeBundle::setParent( const KURL &u )         { m_parent = u; }
inline void    PodcastEpisodeBundle::setAuthor( const TQString &a )      { m_author = a; }
inline void    PodcastEpisodeBundle::setTitle( const TQString &t )       { m_title = t; }
inline void    PodcastEpisodeBundle::setSubtitle( const TQString &t )    { m_subtitle = t; }
inline void    PodcastEpisodeBundle::setDescription( const TQString &d ) { m_description = d; }
inline void    PodcastEpisodeBundle::setDate( const TQString &d )
               { m_date = d; if( !d.isEmpty() ) m_dateTime.setTime_t( KRFCDate::parseDate( d ) );}
inline void    PodcastEpisodeBundle::setType( const TQString &t )        { m_type = t; }
inline void    PodcastEpisodeBundle::setDuration( const int i )         { m_duration = i; }
inline void    PodcastEpisodeBundle::setSize( const uint i )            { m_size = i; }
inline void    PodcastEpisodeBundle::setGuid( const TQString &g )        { m_guid = g; }
inline void    PodcastEpisodeBundle::setNew( const bool &b )            { m_isNew = b; }

#endif /* AMAROK_PODCASTBUNDLE_H */
