/*
* Copyright (C) 2010 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
*
* 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 <KAboutData>
#include <KCmdLineArgs>
#include <KDebug>
#include <KApplication>

#include <KTelepathy/ModelMenu>
#include <KTelepathy/ContactsModelMenu>
#include <KTelepathy/ContactsListModel>
#include <KTelepathy/GroupedContactsProxyModel>
#include <KTelepathy/AccountsModel>
#include <QMainWindow>
#include <QMenuBar>
#include <QMainWindow>
#include <QLabel>

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_test_modelmenu", 0, ki18n("Test ModelMenu"), "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.";
    }

    QMainWindow* window = new QMainWindow(0);
    QLabel* label = new QLabel(i18n("Hello"));
    window->setCentralWidget(label);
    window->setMinimumSize(600,100);

//------

    KTelepathy::ContactsListModel* model = new KTelepathy::ContactsListModel;

    KTelepathy::ContactsModelMenu* contactsmenu = new KTelepathy::ContactsModelMenu;
    contactsmenu->setTitle("Contacts");
    contactsmenu->connect(contactsmenu, SIGNAL(activated(Nepomuk::PersonContact&)), SLOT(pippo(Nepomuk::PersonContact&)));

    window->menuBar()->addMenu(contactsmenu);

//------

    KTelepathy::ModelMenu* accountsmenu = new KTelepathy::ModelMenu;
    accountsmenu->setTitle(i18n("Accounts"));

    KTelepathy::AccountsModel* accountModel = new KTelepathy::AccountsModel;
    accountsmenu->setModel(accountModel);

    window->menuBar()->addMenu(accountsmenu);

//------

    window->show();

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