/****************************************************************************
**
** 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 <QtGui/QApplication>
#include <QtDeclarative>
#include <QPalette>
#include <QDebug>
#include "qmlapplicationviewer.h"
#include "pageitemmodel.h"
#include "pageitem.h"
#include "abstractfeedaggreagatorservice.h"
#include "webfeedsapp.h"
#include "applicationsettings.h"

Q_DECL_EXPORT int main(int argc, char *argv[])
{
    QScopedPointer<QApplication> app(createApplication(argc, argv));

    app->setOrganizationName("gsmiko");
    app->setApplicationName("Web Feeds");

    /*change the applications color palette
    this is the only way to change the color of links
    inside a QML Text element*/
    QPalette palette = app->palette();
    palette.setColor(QPalette::Link, qRgb(255, 140, 0));
    app->setPalette(palette);

    //register the types of the WebFeeds namespace
    qmlRegisterType<WebFeeds::PageItemModel>("WebFeeds", 1, 0, "PageItemModel");
    qmlRegisterType<PageItem>("WebFeeds", 1, 0, "PageItem");
    qmlRegisterType<ApplicationSettings>("WebFeeds", 1, 0, "ApplicationSettings");
    qmlRegisterType<WebFeeds::WebFeedsApp>("WebFeeds", 1, 0, "WebFeedsApp");
    qmlRegisterType<AbstractFeedAggreagatorService>();

    QmlApplicationViewer viewer;
    WebFeeds::WebFeedsApp webFeedsApp;
    //expose the WebFeedsApp instance as a context property
    viewer.rootContext()->setContextProperty("webFeedsApp", &webFeedsApp);
    webFeedsApp.initialize(viewer.engine());

    viewer.setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
    viewer.setMainQmlFile(QLatin1String("qrc:/app/qml/main.qml"));
    viewer.showExpanded();

    return app->exec();
}
