/*
 * This file is part of telepathy-contactlist-qml
 *
 * Copyright (C) 2009-2010 Collabora Ltd. <info@collabora.co.uk>
 *   @Author George Goldberg <george.goldberg@collabora.co.uk>
 * Copyright (C) 2010 A M Desenvolvimento de Software LTDA
 * Copyright (C) 2010 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
 *
 * This program 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 2
 * of the License, or (at your option) any later version.
 *
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301, USA.
 */

extern "C"
{
#include <signal.h>
}

#include <KAboutData>
#include <KCmdLineArgs>
#include <QtDeclarative/QtDeclarative>

#include <KTelepathy/PersonSetModel>

namespace
{
    static void signal_handler(int signal)
    {
        if ((signal == SIGTERM) || (signal == SIGINT)) {
            QCoreApplication * const app(QCoreApplication::instance());
            if (app != 0) {
                kDebug() << "Signal Handler Called. Exiting...";
                app->quit();
            }
        }
    }
}



int main(int argc, char* argv[])
{
    KAboutData aboutData("telepathy-contactslist-qml", 0, ki18n("Telepathy Nepomuk Enabled QML Contact List"), "0.1");

    KCmdLineArgs::init(argc, argv, &aboutData);
    KApplication app;

    // Set up signal handlers.
    if (signal(SIGINT, signal_handler) == SIG_ERR) {
        kWarning() << "Setting up SIGINT signal handler failed.";
    }

    if (signal(SIGTERM, signal_handler) == SIG_ERR) {
        kWarning() << "Setting up SIGTERM signal handler failed.";
    }

    KTelepathy::PersonSetModel model = new KTelepathy::PersonSetModel(KTelepathy::PeopleManager::instance()->everyone());

    QDeclarativeView view;
    view.rootContext()->setContextProperty(QLatin1String("personSetModel"), model);
//    view.setSource(QUrl(QLatin1String("../data/themes/default/main.qml")));
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    view.resize(800, 480);
    view.setMinimumWidth(480);
    view.setWindowTitle(QLatin1String("TweeUp"));
    view.show();
    return app.exec();
}

