/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you wish to add, delete or rename functions or slots use
** Qt Designer which will update this file, preserving your code. Create an
** init() function in place of a constructor, and a destroy() function in
** place of a destructor.
*****************************************************************************/

//----------------------- initDialog --------------------------------------------
int Dlg_Login::initDialog(CMoteurCCAM_Base* pCMoteurCCAM_Base, const QString &last_user, const QString &password)
{   lineEdit_Utilisateur->setText(last_user); 
    lineEdit_MotDePasse->setText(password); 
    if (last_user.length()) lineEdit_MotDePasse->setFocus();
    else                    lineEdit_Utilisateur->setFocus();
    if (password.length() && last_user.length())  bouton_OK->setFocus();
    m_pCMoteurCCAM_Base = pCMoteurCCAM_Base;    
    return 1;
}

//----------------------- bouton_OK_clicked -------------------------------------
void Dlg_Login::bouton_OK_clicked()
{
    QString utilisateur = lineEdit_Utilisateur->text();
    QString password = lineEdit_MotDePasse->text();
    
    if ( (lineEdit_Utilisateur->text() != "") ) 
       {
	bool droit_ouvert = m_pCMoteurCCAM_Base->VerificationLogin(utilisateur, password);
	if (droit_ouvert) 
	   {accept();
	   }
    }
}

//----------------------- bouton_Quitter_clicked --------------------------------
void Dlg_Login::bouton_Quitter_clicked()
{
    reject();
}

//----------------------- lineEdit_MotDePasse_textChanged -----------------------
void Dlg_Login::lineEdit_MotDePasse_textChanged( const QString & )
{
    // .................. astuce pour créer les utilisateurs ..................................
    if ( (lineEdit_MotDePasse->text() == "SENSEI") && (lineEdit_Utilisateur->text() == "") ){
	//.................... Appel de la fenêtre saisie/modification fiche praticien ....................
	Dlg_Praticiens* dlg_prat = new Dlg_Praticiens;
	if (dlg_prat==0)      return; // Erreur initialisation
	dlg_prat->initDialog(m_pCMoteurCCAM_Base);
	if (dlg_prat->exec()== QDialog::Rejected){
	    delete dlg_prat;
	    return; // On quitte sans créer de praticien
	}
	delete dlg_prat;
    }
}
 
