#include "dialogin.hpp"

#include <QCryptographicHash>

#include <qdebug.h>

#include <qmessagebox.h>

extern bool g_op_mode;	//是否操作员模式

extern QString g_op_pswd;	//操作员密码

Dialogin::Dialogin(QWidget * parent) : QDialog(parent) {
	ui.setupUi(this);
	m_pswd = "";
	this->setWindowFlags(Qt::FramelessWindowHint);
}

Dialogin::~Dialogin() {
	
}

void Dialogin::on_pushButton_close_released()
{
	this->close();
}
void Dialogin::on_pushButton_clr_released()
{
	m_pswd = "";
	ui.lineEdit->setText("");
}
void Dialogin::on_pushButton_ok_released()
{
	QString md5Str = QCryptographicHash::hash(m_pswd.toLatin1(), QCryptographicHash::Md5).toHex();
	qDebug() << "m_pswd_op:" << m_pswd;
	qDebug() << "m_pswd_op md5:" << md5Str;
	qDebug() << "g_admin_pswd_op md5:" << g_op_pswd;
	if (md5Str.compare(g_op_pswd, Qt::CaseInsensitive) == 0)
	{
		g_op_mode = true;
		//QMessageBox::information(NULL, QStringLiteral("提示消息"), QStringLiteral("验证通过，进入管理员模式"), QMessageBox::Ok);
		emit enter_op();
		this->close();
	}
	else {
		QMessageBox::information(NULL, QStringLiteral("提示消息"), QStringLiteral("密码错误，请重新输入"), QMessageBox::Ok);
		on_pushButton_clr_released();
	}
}
void Dialogin::on_pushButton_0_released()
{
	m_pswd += "0";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_1_released()
{
	m_pswd += "1";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_2_released()
{
	m_pswd += "2";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_3_released()
{
	m_pswd += "3";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_4_released()
{
	m_pswd += "4";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_5_released()
{
	m_pswd += "5";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_6_released()
{
	m_pswd += "6";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_7_released()
{
	m_pswd += "7";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_8_released()
{
	m_pswd += "8";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
void Dialogin::on_pushButton_9_released()
{
	m_pswd += "9";
	ui.lineEdit->setText(ui.lineEdit->text() + "*");
}
