/***************************************************************************
 *   Copyright (C) 2007 by Arnold Kraschinski                              *
 *   arnold.kra67@gmx.de                                                   *
 *                                                                         *
 *   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.          *
 ***************************************************************************/


#include <stdlib.h>
#include <ctime>

#include <QStringList>

#include <kaboutdata.h>
#include <kapplication.h>
#include <kcmdlineargs.h>
#include <klocale.h>
#include <kprocess.h>
#include <kstandarddirs.h>
#include <kdebug.h>

#include "kverbos.h"
#include "kverbossettings.h"
#include "kverbosuser.h"
#include "verbdata.h"

int main(int argc, char *argv[])
{
    KAboutData about("kverbos", 0, ki18n("KVerbos"), "2.00.00", ki18n("Study Spanish grammar with KVerbos"), KAboutData::License_GPL, ki18n("© 2007 Arnold Kraschinski"));
    about.addAuthor(ki18n("Arnold Kraschinski"), ki18n("Coding"), "arnold.kra67@gmx.de");
    KCmdLineArgs::init(argc, argv, &about);
    KApplication app;
    app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

    //kDebug() << "This is the number of verbs loaded: " << Verbdata::count() << endl;
    //Verbdata::conjugate("hablar");
    //Verbdata::conjugate("estar");
    //Verbdata::conjugate("desembarazar");


    srand(time(0));

    if (KVerbosSettings::translationLanguage().isEmpty()) {
        QStringList userLanguagesCode = KGlobal::locale()->languageList();
        QStringList::const_iterator itEnd = userLanguagesCode.constEnd();
        QStringList::const_iterator it = userLanguagesCode.constBegin();
        for ( ; it != itEnd; ++it)
        {
            QStringList mdirs = KGlobal::dirs()->findDirs("appdata", "data/" + *it);	
            if (!mdirs.isEmpty()) break;
        }
        if (it == itEnd) KVerbosSettings::setTranslationLanguage("en");
        else KVerbosSettings::setTranslationLanguage(*it);
    }

    app.setTopWidget(new Kverbos());
    return app.exec();
}

