/****************************************************************************
**
** Copyright (C) 2012 Róbert Márki
**
** This file is part of Web Feeds.
**
** Web Feeds 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 3 of the License, or
** (at your option) any later version.
**
** Web Feeds 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 Web Feeds.  If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/

#include "storyitem.h"

namespace GoogleReader
{
StoryItem::StoryItem(PageItemPtr parent, AbstractFeedAggreagatorService *service) :
    GoogleReaderItem(parent, service),
    m_read(false),
    m_readStateLocked(false),
    m_keptUnread(false),
    m_starred(false),    
    m_inReadingList(false),
    m_starredBusy(false)
{
}

GoogleReaderItem::ItemType StoryItem::itemType() const
{
    return GoogleReaderItem::ItStoryItem;
}

bool StoryItem::isRead() const
{
    return m_read;
}

void StoryItem::setRead(bool read)
{
    m_read = read;
    emit readChanged();
    emit dataChanged(PageItemWeakRef(this));
}

bool StoryItem::isKeptUnread() const
{
    return m_keptUnread;
}

void StoryItem::setKeptUnread(bool keptUnread)
{
    m_keptUnread = keptUnread;
    emit keptUnreadChanged();
    emit dataChanged(PageItemWeakRef(this));
}

bool StoryItem::isStarred() const
{
    return m_starred;
}

void StoryItem::setStarred(bool starred)
{
    m_starred = starred;
    emit starredChanged();
    emit dataChanged(PageItemWeakRef(this));
}

QString StoryItem::contents() const
{
    return m_contents;
}

void StoryItem::setContents(const QString &contents)
{
    m_contents = contents;
    emit contentsChanged();
    emit dataChanged(PageItemWeakRef(this));
}

QString StoryItem::url() const
{
    return m_url;
}

void StoryItem::setUrl(const QString& url)
{
    m_url = url;
    emit urlChanged();
    emit dataChanged(PageItemWeakRef(this));
}

bool StoryItem::isStarredBusy() const
{
    return m_starredBusy;
}

void StoryItem::setStarredBusy(bool busy)
{
    m_starredBusy = busy;
    emit starredBusyChanged();
}

QDateTime StoryItem::date() const
{
    return m_date;
}

void StoryItem::setDate(const QDateTime &date)
{
    m_date = date;
    if(!m_fromattedDate.length() && !m_date.isNull())
    {
        QDateTime localDate = m_date.toLocalTime();
        if(localDate.date() == QDate::currentDate())
            m_fromattedDate = localDate.time().toString(Qt::DefaultLocaleShortDate);
        else
            m_fromattedDate = localDate.date().toString(Qt::DefaultLocaleShortDate);
        m_formattedDateTime = localDate.toString(Qt::DefaultLocaleShortDate);
    }
    else
    {
        m_formattedDateTime.clear();
        m_fromattedDate.clear();
    }
}

QString StoryItem::formattedDate() const
{
    return m_fromattedDate;
}

QString StoryItem::formattedDateTime() const
{
    return m_formattedDateTime;
}

QString StoryItem::feedId() const
{
    return m_feedId;
}

void StoryItem::setFeedId(const QString &feedId)
{
    m_feedId = feedId;
}

QString StoryItem::author() const
{
    return m_author;
}

void StoryItem::setAuthor(const QString &author)
{
    m_author = author;
}

bool StoryItem::isReadStateLocked() const
{
    return m_readStateLocked;
}

void StoryItem::setReadStateLocked(bool locked)
{
    m_readStateLocked = locked;
    emit readStateLockedChanged();
}

QStringList StoryItem::tags() const
{
    return m_tags;
}

void StoryItem::setTags(const QStringList &tags)
{
    m_tags = tags;
    emit tagsChanged();
}

bool StoryItem::isInReadingList() const
{
    return m_inReadingList;
}

void StoryItem::setInReadingList(bool inReadingList)
{
    m_inReadingList = inReadingList;
}
} // namespace GoogleReader
