/***************************************************************************
 *   Copyright (C) 2009 by Docteur Pierre-Marie Desombre.   *
 *   pm.desombre@medsyn.fr  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License as       *
 *   published by the Free Software Foundation; either version 3 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 Library General Public     *
 *   License along with this program; if not, write to the                 *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include <QtGui>
#include <QtCore>
#include <QApplication>
#include <QtDebug>
#include "apidialog.h"
#include "textdialog.h"
#include "connexion.h"
QString g_pathabsolu;

 void myMessageOutput(QtMsgType type, const char *msg)
 {
     QFile file(qApp->applicationDirPath ()+"/errorLog.txt");
     file.open(QIODevice::ReadWrite|QIODevice::Append);
     QTextStream s(&file);
     switch (type) {
     case QtDebugMsg:
         s << "Debug: " << QString(msg) << "\n";
         break;
     case QtWarningMsg:
         s << "Warning: " << QString(msg) << "\n";
         break;
     case QtCriticalMsg:
         s << "Critical: " << QString(msg) << "\n";
         break;
     case QtFatalMsg:
         s << "Fatal: " << QString(msg) << "\n";
         abort();
     }

     file.close();
 }

int main(int argc,char* argv[]){
    //qInstallMsgHandler(myMessageOutput);
    QApplication app(argc,argv);
    QFile f(app.applicationDirPath ()+"/errorLog.txt");
    f.remove();
    app.addLibraryPath(app.applicationDirPath());
    QStringList arguments = app.arguments();
    QFileInfo pathinfo(arguments[0]);
    g_pathabsolu = pathinfo.absolutePath();
     /*QTranslator translator;
     translator.load("apitux_en.qm");
     app.installTranslator(&translator);*/
     qDebug() << "avant create";
      QStringList library ;
    QString strLib;
    QString str;
    library = app.libraryPaths();
    foreach(str,library){
        strLib += str+"\n";
        }
    qDebug() << "libraries = "+strLib;
    if(CreateConnection()==false){
        QMessageBox msgdb;
	    msgdb.setWindowTitle(QObject::trUtf8("Erreur ouverture de base"));
	    msgdb.setText(QObject::trUtf8("Impossible de se connecter à la base "));
	    msgdb.setIcon(QMessageBox::Critical);
	    msgdb.exec();
	    if(QMessageBox::Ok){
	        return false;
	    }
    }
    qDebug() << "main";
    apidialog *wideget = new apidialog;
    wideget->show();
    return app.exec();
}
