#include "mainwindow.h"
#include "connexion.h"

#include <QApplication>
#include <QFile>
#include <QDebug>

using namespace ConnexionSpace;

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 a(argc,argv);
    QFile f(a.applicationDirPath ()+"/errorLog.txt");
    f.remove();
    Connexion *c = new Connexion;
    if (!c->connectToDrTux())
    {
          qWarning() << __FILE__ << QString::number(__LINE__) << "unable to connect to Dr Tux" ;
        }
    MainWindowRequete * mw = new MainWindowRequete;
    mw->show();    
    return a.exec();
    delete mw;
}
