/****************************************************************************
**
** 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 "applicationsettings.h"
#include <QDebug>

const char* ApplicationSettings::s_eventFeedEnabledKey          = "/apps/ControlPanel/WebFeeds/EnableFeed";
const char* ApplicationSettings::s_maximumCachedItemCountKey    = "/apps/ControlPanel/WebFeeds/NumberOfItemsInCache";
const char* ApplicationSettings::s_feedImageScalingKey          = "/apps/ControlPanel/WebFeeds/FeedImageScaling";

/*!
  \class ApplicationSettings
  \brief The ApplicationSettings class provides the application's user
  editable settings stored with GConf.
*/
/*!
  \var ApplicationSettings::s_eventFeedEnabledKey
  The GConf path associated with the value, that determines wether publishing
  to the event feed on the home screen is enabled.
*/
/*!
  \var ApplicationSettings::s_maximumCachedItemCountKey
  The GConf path associated with the value, that stores the maximum number
  of items that are allowed to be stored in the cache.
*/
/*!
  Constructs an ApplicationSettings object with the given \a parent.
*/
ApplicationSettings::ApplicationSettings(QObject *parent) :
    QObject(parent)
#ifdef MEEGO_EDITION_HARMATTAN
    ,m_eventFeedEnabledItem(new GConfItem(ApplicationSettings::s_eventFeedEnabledKey, this))
    ,m_maximumCachedItemCountItem(new GConfItem(ApplicationSettings::s_maximumCachedItemCountKey, this))
    ,m_feedImageScalingItem(new GConfItem(ApplicationSettings::s_feedImageScalingKey, this))
#endif
{
#ifdef MEEGO_EDITION_HARMATTAN
    connect(m_feedImageScalingItem, SIGNAL(valueChanged()),
            this, SIGNAL(feedImageScalingChanged()));
#endif
}

/*!
  Returns true if publishing to the event feed on the home screen is enabled,
  otherwise returns false.
*/
bool ApplicationSettings::eventFeedEnabled() const
{
#ifdef MEEGO_EDITION_HARMATTAN
    return m_eventFeedEnabledItem->value(false).toBool();
#else
    return false;
#endif
}

/*!
  Returns the maximum number of items that are allowed to be stored
  in the cache.
*/
int ApplicationSettings::maximumCachedItemCount() const
{
#ifdef MEEGO_EDITION_HARMATTAN
    return m_maximumCachedItemCountItem->value(-1).toInt();
#else
    return -1;
#endif
}

int ApplicationSettings::feedImageScaling() const
{
    int ret = ApplicationSettings::FiOriginalSize;
#ifdef MEEGO_EDITION_HARMATTAN
    ret = m_feedImageScalingItem->value(ApplicationSettings::FiOriginalSize).toInt();
#endif
    return ret;
}
