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

#include <qmessagebox.h>
#include <qfile.h>
#include "usermanager.h"
#include <qapplication.h>


void LoginDialog::init()
{
    connect( buttonQuit, SIGNAL( clicked() ), qApp, SLOT( quit() ) );
}


void LoginDialog::buttonLogin_clicked()
{
    if ( editUser->text() != "root" ) {
	QFile f( editUser->text() );
	if ( !f.open( IO_ReadOnly ) ) {
	    QMessageBox::critical( this, "Could not login", QString( "No such User: " ) + editUser->text() );
	    editUser->clear();
	    editPasswd->clear();
	    editUser->setFocus();
	    return;
	}
	QString passwd;
	f.readLine( passwd, 1024 );
	passwd.remove( passwd.length() - 1, 1 );
	if ( passwd != editUser->text() ) {
	    QMessageBox::critical( this, "Could not login", "Incorrect Password " );
	    editUser->clear();
	    editPasswd->clear();
	    editUser->setFocus();
	    return;
	}
    } else if ( editPasswd->text() != "toor" ) {
	    QMessageBox::critical( this, "Could not login", "Incorrect Password " );
	    editUser->clear();
	    editPasswd->clear();
	    editUser->setFocus();
	    return;
   }

    UserManager mgr( this, 0, TRUE );
    mgr.setLogin( editUser->text(), editPasswd->text() );
    mgr.exec();
    editUser->clear();
    editPasswd->clear();
    editUser->setFocus();
}

