/****************************************************************************
**
** 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/>.
****************************************************************************/

#ifndef WEBFEEDSAPP_H
#define WEBFEEDSAPP_H
#include <QObject>
#include <QAbstractItemModel>
#include <QDeclarativeListProperty>
#include <QDeclarativeEngine>
#include "pageitem.h"
#include "abstractfeedaggreagatorservice.h"
#include "pageitemmodel.h"
#include "applicationsettings.h"

namespace WebFeeds
{
class WebFeedsApp : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QDeclarativeListProperty<AbstractFeedAggreagatorService> services READ services NOTIFY servicesChanged)
    Q_PROPERTY(WebFeeds::PageItemModel* pageItemModel READ pageItemModel NOTIFY pageItemModelChanged)
    Q_PROPERTY(ApplicationSettings* settings READ settings NOTIFY settingsChanged)
public:
    explicit WebFeedsApp(QObject *parent = 0);
    QDeclarativeListProperty<AbstractFeedAggreagatorService> services();
    void initialize(QDeclarativeEngine* engine);
    PageItemModel* pageItemModel() const;
    ApplicationSettings* settings();

public slots:
    Q_INVOKABLE PageItem* rootItem() const;
    Q_INVOKABLE QStringList contextMenuItems(PageItem *item);
    Q_INVOKABLE QStringList menuItems(PageItem *item);
    Q_INVOKABLE void shareStory(const QString &title, const QString &url) const;
    Q_INVOKABLE void launchSettingsApplet() const;

private:
    static const char* s_settingsAppletName;
    static const char* s_removeServiceMenuItem;
    static const char* s_aboutMenuItem;
    static const char* s_settingsMenuItem;
    PageItemModel* m_model;
    PageItemPtr m_rootItem;
    QList<AbstractFeedAggreagatorService*> m_services;
    ApplicationSettings m_settings;
    bool isServiceEnabled(AbstractFeedAggreagatorService *service);
    int serviceItemIndex(AbstractFeedAggreagatorService *service);

private slots:
    void onServiceAuthenticationDataChanged(AbstractFeedAggreagatorService *service);

signals:
    void servicesChanged();
    void pageItemModelChanged();
    void settingsChanged();
};
} // namespace WebFeeds
Q_IMPORT_PLUGIN(newsblurservice)
Q_IMPORT_PLUGIN(googlereaderservice)
#endif // WEBFEEDSAPP_H
