first commit
This commit is contained in:
184
project/fm_viewer/ui/rm_popup_pw.cpp
Normal file
184
project/fm_viewer/ui/rm_popup_pw.cpp
Normal file
@@ -0,0 +1,184 @@
|
||||
#include "rm_popup_pw.h"
|
||||
#if (USE_PASSWORD_POPUP)
|
||||
|
||||
#include "../fm_dimensions.h"
|
||||
|
||||
#include <QVBoxLayout>
|
||||
#include <QSettings>
|
||||
#include "rm_button.h"
|
||||
#include "fm_button.h"
|
||||
#include "rm_popup_content_background.h"
|
||||
#include "title_widget.h"
|
||||
#include "../core/fm_strings.h"
|
||||
#define USER_SETTINGS "HKEY_CURRENT_USER\\SOFTWARE\\XLDR_88_VIEWER"
|
||||
#include <QThread>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QCryptographicHash>
|
||||
#include <QMessageBox>
|
||||
|
||||
RMPopupPW::RMPopupPW(PW_MODE mode, QWidget *parent) : RMPopup(parent,FMS::txt("password_input"),"")
|
||||
{
|
||||
int height = POPUP_INFO_HEIGHT;
|
||||
|
||||
// 신규 모드
|
||||
if(readPW().isEmpty()) {
|
||||
currentMode = PW_NEW;
|
||||
height = 260;
|
||||
//_title->titleLabel->setText(FMS::txt("password_change"));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 변경 모드
|
||||
if(mode == PW_CHANGE)
|
||||
{
|
||||
_title->titleLabel->setText(FMS::txt("password_change"));
|
||||
height = 280;
|
||||
}
|
||||
currentMode = mode;
|
||||
}
|
||||
|
||||
this->setFixedSize(340,height);
|
||||
|
||||
_title->closeButton->setHidden(true);
|
||||
|
||||
QVBoxLayout* layout = new QVBoxLayout(_contentWidget);
|
||||
|
||||
layout->setContentsMargins(10,13,10,12);
|
||||
|
||||
RMPopupContentBackground* bg = new RMPopupContentBackground(_contentWidget);
|
||||
layout->addWidget(bg);
|
||||
|
||||
QVBoxLayout* contentLayout = new QVBoxLayout(bg);
|
||||
contentLayout->setAlignment(Qt::AlignTop);
|
||||
|
||||
if(currentMode == PW_CHECK) {
|
||||
editPWCheck = addLine(contentLayout,bg,"");
|
||||
connect(editPWCheck,SIGNAL(returnPressed()),this,SLOT(onOK()));
|
||||
}
|
||||
else if(currentMode == PW_NEW) {
|
||||
|
||||
RMLayout::addLabel(bg,contentLayout,FMS::txt("pw_message"),"text_normal_label");
|
||||
editPWNew = addLine(contentLayout,bg,FMS::txt("input") + ":"); //
|
||||
editPWConfirm = addLine(contentLayout,bg,FMS::txt("confirm") + ":"); // FMS::txt("password") + ":"
|
||||
}
|
||||
else if (currentMode == PW_CHANGE)
|
||||
{
|
||||
RMLayout::addLabel(bg,contentLayout,FMS::txt("pw_message"),"text_normal_label");
|
||||
editPWOld = addLine(contentLayout,bg,FMS::txt("old") + ":"); //
|
||||
editPWNew = addLine(contentLayout,bg,FMS::txt("input") + ":"); //
|
||||
editPWConfirm = addLine(contentLayout,bg,FMS::txt("confirm") + ":"); // FMS::txt("password") + ":"
|
||||
}
|
||||
|
||||
|
||||
QSize btnSize = QSize(90,27);
|
||||
okButton = RMButton::create(_buttonWidget,_buttonLayout,"button",FMS::txt("ok"),btnSize);
|
||||
okButton->setText(FMS::txt("ok"));
|
||||
connect(okButton,SIGNAL(clicked()),this,SLOT(onOK()));
|
||||
|
||||
RMButton* cancelButton = RMButton::create(_buttonWidget,_buttonLayout,"button",FMS::txt("cancel"),btnSize);
|
||||
cancelButton->setText(FMS::txt("cancel"));
|
||||
connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
|
||||
|
||||
if(currentMode == PW_CHECK) {
|
||||
RMButton* changeButton = RMButton::create(_buttonWidget,_buttonLayout,"button",FMS::txt("change"),btnSize);
|
||||
changeButton->setText(FMS::txt("change"));
|
||||
connect(changeButton,SIGNAL(clicked()),this,SLOT(onChangePW()));
|
||||
}
|
||||
}
|
||||
QLineEdit* RMPopupPW::addLine(QVBoxLayout* layout, QWidget* parent, QString label)
|
||||
{
|
||||
QWidget* lw = new QWidget(parent);
|
||||
layout->addWidget(lw);
|
||||
|
||||
QHBoxLayout* ll = new QHBoxLayout(lw);
|
||||
ll->setAlignment(Qt::AlignCenter);
|
||||
|
||||
if(!label.isEmpty()) {
|
||||
RMLayout::addLabel(lw,
|
||||
ll,
|
||||
label,
|
||||
"text_header_label");
|
||||
}
|
||||
|
||||
QLineEdit* e = new QLineEdit(lw);
|
||||
e->setEchoMode(QLineEdit::Password);
|
||||
e->setStyleSheet("font-family: Fixedsys;color : #111111;background-color: #DDDDDD;border:1px;border-style:solid;border-color:#313131;");
|
||||
ll->addWidget(e);
|
||||
e->setMaxLength(20);
|
||||
|
||||
//e->setFixedWidth(180);
|
||||
|
||||
connect(e, SIGNAL(textChanged(const QString &)), this, SLOT(onTextCahnged(const QString&)));
|
||||
return e;
|
||||
}
|
||||
void RMPopupPW::onOK()
|
||||
{
|
||||
if(currentMode == PW_NEW) {
|
||||
if(editPWNew->text().length() >= 4 && editPWNew->text() == editPWConfirm->text())
|
||||
{
|
||||
savePW(editPWNew->text());
|
||||
accept();
|
||||
return;
|
||||
}
|
||||
showMessage(FMS::txt("password_wrong"));
|
||||
}
|
||||
else if (currentMode == PW_CHECK) {
|
||||
QString pw = editPWCheck->text();
|
||||
QString epw = QString(QCryptographicHash::hash(pw.toUtf8(),QCryptographicHash::Sha1).toHex());
|
||||
if(epw == readPW())
|
||||
{
|
||||
accept();
|
||||
return;
|
||||
}
|
||||
showMessage(FMS::txt("password_wrong"));
|
||||
}
|
||||
else if (currentMode == PW_CHANGE)
|
||||
{
|
||||
if(editPWNew->text().length() >= 4 && editPWNew->text() == editPWConfirm->text())
|
||||
{
|
||||
QString pw = editPWOld->text();
|
||||
QString epw = QString(QCryptographicHash::hash(pw.toUtf8(),QCryptographicHash::Sha1).toHex());
|
||||
if(epw == readPW())
|
||||
{
|
||||
savePW(editPWNew->text());
|
||||
currentMode = PW_CHECK;
|
||||
accept();
|
||||
return;
|
||||
}
|
||||
}
|
||||
showMessage(FMS::txt("password_wrong"));
|
||||
}
|
||||
}
|
||||
void RMPopupPW::showMessage(QString message)
|
||||
{
|
||||
QMessageBox::warning(this,FMS::txt("warning"),message,QMessageBox::Ok,QMessageBox::NoButton);
|
||||
}
|
||||
|
||||
void RMPopupPW::onTextCahnged(const QString& txt)
|
||||
{
|
||||
//qInfo() << txt;
|
||||
}
|
||||
void RMPopupPW::onChangePW()
|
||||
{
|
||||
currentMode = PW_CHANGE;
|
||||
accept();
|
||||
}
|
||||
void RMPopupPW::savePW(QString pw)
|
||||
{
|
||||
QSettings settings(USER_SETTINGS,QSettings::NativeFormat);
|
||||
QString epw = QString(QCryptographicHash::hash(pw.toUtf8(),QCryptographicHash::Sha1).toHex());
|
||||
settings.setValue("pw",epw);
|
||||
settings.sync();
|
||||
}
|
||||
|
||||
QString RMPopupPW::readPW() {
|
||||
|
||||
QSettings settings(USER_SETTINGS,QSettings::NativeFormat);
|
||||
if(settings.contains("pw") == true)
|
||||
{
|
||||
//qInfo() << settings.value("pw").toString();
|
||||
return settings.value("pw").toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
#endif // #if (USE_PASSWORD_POPUP)
|
||||
Reference in New Issue
Block a user