/***************************************************************************
 *   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.             *
 ***************************************************************************/
#ifndef CONNEXION_H
#define CONNEXION_H

#include <QtCore>
#include <QtSql>
#include <QSqlDatabase>
#include <QSettings>


extern QString g_pathabsolu;
//lance la connection a DrTuxTest
bool CreateConnection() 
{
    QString host;
    QString utilisateur;
    QString motdepasse;
    QString port = "3306" ;
    QString file = qApp->applicationDirPath()+"/../resources/apitux.ini";
    QFile fichier(file);
    if(!fichier.open(QIODevice::ReadOnly | QIODevice::Text)){
        QMessageBox::warning(0,"erreur",QObject::trUtf8("le fichier apitux.ini n'est pas accessible"),QMessageBox::Ok);}
    QSettings set(file,QSettings::IniFormat);
    host = set.value("connexion/host").toString();
    utilisateur = set.value("connexion/utilisateur").toString();
    motdepasse = set.value("connexion/motdepassemysql").toString();
    port = set.value("connexion/port").toString();
    if(port.isEmpty()) port = "3306";

    QSqlDatabase db = QSqlDatabase :: addDatabase("QMYSQL");
    db.setHostName(host);
    db.setDatabaseName("DrTuxTest");
    db.setUserName(utilisateur);
    db.setPassword(motdepasse);
    db.setPort(port.toInt());

    if (!db.open()) {
	    QMessageBox::critical(0,"Erreur ouverture de base", db.lastError().text());
	    return false;
        }
return true;
}

#endif
