UI: Refactor Password dialog.

This commit is contained in:
Nodir Temirkhodjaev 2018-01-12 13:29:08 +05:00
parent da78f3e49d
commit 768dd703e7
9 changed files with 37 additions and 85 deletions

View File

@ -7,6 +7,7 @@ TARGET = FortFirewall
DESTDIR = ./
MOC_DIR = .moc
OBJECTS_DIR = .obj
RCC_DIR = .rcc
SOURCES += \
main.cpp \
@ -107,7 +108,6 @@ HEADERS += \
QML_FILES += \
qml/*.qml \
qml/boxes/*.qml \
qml/controls/*.qml \
qml/pages/*.qml \
qml/pages/addresses/*.qml \

View File

@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/">
<file>qml/boxes/PasswordBox.qml</file>
<file>qml/controls/ButtonMenu.qml</file>
<file>qml/controls/ButtonPopup.qml</file>
<file>qml/controls/HSeparator.qml</file>

View File

@ -1,6 +1,7 @@
#include "fortmanager.h"
#include <QApplication>
#include <QInputDialog>
#include <QMenu>
#include <QMessageBox>
#include <QQmlApplicationEngine>
@ -197,7 +198,9 @@ void FortManager::showWindow()
setupEngine();
}
if (!m_appWindow) return;
if (!m_appWindow || !(m_appWindow->isVisible()
|| checkPassword()))
return;
if (m_firewallConfToEdit == nullConf()) {
setFirewallConfToEdit(cloneConf(*m_firewallConf));
@ -234,6 +237,20 @@ void FortManager::exit(int retcode)
qApp->exit(retcode);
}
bool FortManager::checkPassword()
{
const QString passwordHash = firewallConf()->passwordHash();
if (passwordHash.isEmpty())
return true;
const QString password = QInputDialog::getText(
&m_window, tr("Password input"), tr("Please enter the password"),
QLineEdit::Password);
return !password.isEmpty()
&& StringUtil::cryptoHash(password) == passwordHash;
}
void FortManager::showErrorBox(const QString &text,
const QString &title)
{

View File

@ -50,6 +50,8 @@ public slots:
void exit(int retcode = 0);
bool checkPassword();
void showErrorBox(const QString &text,
const QString &title = QString());
void showInfoBox(const QString &text,

Binary file not shown.

View File

@ -37,22 +37,32 @@
<context>
<name>FortManager</name>
<message>
<location filename="../fortmanager.cpp" line="455"/>
<location filename="../fortmanager.cpp" line="247"/>
<source>Password input</source>
<translation>Ввод пароля</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="247"/>
<source>Please enter the password</source>
<translation>Наберите пароль пожалуйста</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="474"/>
<source>Options</source>
<translation>Опции</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="461"/>
<location filename="../fortmanager.cpp" line="480"/>
<source>Filter Enabled</source>
<translation>Фильтр включен</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="465"/>
<location filename="../fortmanager.cpp" line="484"/>
<source>Stop Traffic</source>
<translation>Остановить трафик</translation>
</message>
<message>
<location filename="../fortmanager.cpp" line="482"/>
<location filename="../fortmanager.cpp" line="501"/>
<source>Quit</source>
<translation>Выйти</translation>
</message>
@ -332,13 +342,11 @@
<translation>Статистика</translation>
</message>
<message>
<location filename="../qml/boxes/PasswordBox.qml" line="32"/>
<location filename="../qml/pages/OptionsPage.qml" line="88"/>
<source>Password:</source>
<translation>Пароль:</translation>
</message>
<message>
<location filename="../qml/boxes/PasswordBox.qml" line="48"/>
<location filename="../qml/pages/MainPage.qml" line="99"/>
<source>OK</source>
<translation>OK</translation>
@ -349,7 +357,6 @@
<translation>Применить</translation>
</message>
<message>
<location filename="../qml/boxes/PasswordBox.qml" line="62"/>
<location filename="../qml/pages/MainPage.qml" line="132"/>
<source>Cancel</source>
<translation>Отмена</translation>

View File

@ -12,6 +12,8 @@ int main(int argc, char *argv[])
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication::setQuitOnLastWindowClosed(false);
QApplication app(argc, argv);
app.setApplicationName(APP_NAME);
app.setApplicationVersion(APP_VERSION_STR);

View File

@ -1,67 +0,0 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import "../controls"
import com.fortfirewall 1.0
Pane {
id: passwordBox
enabled: false
opacity: enabled ? 1.0 : 0
Behavior on opacity { OpacityAnimator { duration: 200 } }
property alias password: editPassword.text
function reset() {
enabled = firewallConf.hasPassword;
password = "";
}
ColumnLayout {
anchors.centerIn: parent
width: 400
RowLayout {
Layout.fillWidth: true
Label {
anchors.verticalCenter: parent.verticalCenter
text: translationManager.dummyBool
&& qsTranslate("qml", "Password:")
}
TextFieldFrame {
id: editPassword
Layout.fillWidth: true
echoMode: TextInput.Password
passwordMaskDelay: 300
}
}
RowLayout {
anchors.right: parent.right
Button {
icon.source: "qrc:/images/tick.png"
text: translationManager.dummyBool
&& qsTranslate("qml", "OK")
onClicked: {
if (stringUtil.cryptoHash(password)
=== firewallConf.passwordHash) {
passwordBox.enabled = false;
} else {
editPassword.forceActiveFocus();
editPassword.selectAll();
}
}
}
Button {
icon.source: "qrc:/images/cancel.png"
text: translationManager.dummyBool
&& qsTranslate("qml", "Cancel")
onClicked: closeWindow()
}
}
}
}

View File

@ -1,6 +1,5 @@
import QtQuick 2.9
import QtQuick.Controls 2.2
import "boxes"
import "controls"
import "pages"
import com.fortfirewall 1.0
@ -26,8 +25,6 @@ ApplicationWindow {
}
}
onVisibleChanged: passwordBox.reset()
function closeWindow() {
fortManager.closeWindow();
}
@ -70,9 +67,4 @@ ApplicationWindow {
Component.onDestruction: closed()
}
}
PasswordBox {
id: passwordBox
anchors.fill: parent
}
}