/*
 * This file is part of people
 *
 * Copyright (C) 2009-2010 Collabora Ltd. <info@collabora.co.uk>
 *   @author George Goldberg <george.goldberg@collabora.co.uk>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

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

#include "abstract-interface.h"
#include "person.h"
#include "telepathy-person-interface.h"

#include <KAboutData>
#include <KCmdLineArgs>
#include <KDebug>
#include <KApplication>

#include <QStandardItemModel>

namespace
{
    static void signal_handler(int signal)
    {
        if ((signal == SIGTERM) || (signal == SIGINT)) {
            QCoreApplication * const app(QCoreApplication::instance());
            if (app != 0) {
                app->quit();
            }
        }
    }
}

int main(int argc, char *argv[])
{
    KAboutData aboutData("test_people_lib",
                         0,
                         ki18n("Test People Lib"),
                         "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.";
    }

    kDebug() << "Let's go...";

    kDebug() << "Create a Person.";
    Person *person = new Person(QUrl::fromEncoded("nepomuk:/myself"), 0);

    kDebug() << "Get the TelepathyInterface from the Person.";
    QSharedPointer<TelepathyPersonInterface> interface = person->interface<TelepathyPersonInterface>();

    kDebug() << "Get the same interface again to see if it is in the cache.";
    QSharedPointer<TelepathyPersonInterface> interface2 = person->interface<TelepathyPersonInterface>();

  //  kDebug() << "Try an invalid type";
  //  QStandardItemModel *widget = person->interface<QStandardItemModel>();

    kDebug() << "The End.";

    // Start event loop.
    return app.exec();
}

