Commit 55505843 authored by Karel Slaný's avatar Karel Slaný

Using only one configuration entry to store the PIN value.

parent 3088f0c9
......@@ -99,7 +99,7 @@ Component {
setPinCodeString2.focus = true
} else {
errorLabel.visible = false
settings.updatePinSettings(true, setPinCodeString.text.toString())
settings.updatePinSettings(setPinCodeString.text.toString())
pageView.pop(StackView.Immediate)
}
/* change current pin code */
......@@ -120,7 +120,7 @@ Component {
setPinCodeString2.focus = true
} else {
errorLabel.visible = false
settings.updatePinSettings(true, setPinCodeString.text.toString())
settings.updatePinSettings(setPinCodeString.text.toString())
pageView.pop(StackView.Immediate)
}
} else {
......@@ -133,7 +133,7 @@ Component {
} else if (actionName == "disable") {
if (getPinCodeString.text == currentPIN) {
errorLabel.visible = false
settings.updatePinSettings(false, "")
settings.updatePinSettings("")
pageView.pop(StackView.Immediate)
} else {
errorLabel.text = qsTr("Error: Current PIN code is wrong!")
......@@ -258,7 +258,7 @@ Component {
Connections {
target: settings
onSendPinData: {
currentPIN = currentPinCode
currentPIN = currentPinVal
if (currentPIN == "") {
pinLabel.text = qsTr("Currently there is no PIN code set.")
setPinCodeButton.visible = true
......
......@@ -200,7 +200,7 @@ int main(int argc, char *argv[])
/* OpenSSL support test */
if (QSslSocket::supportsSsl()) {
/* set last update text to status bar */
if (!globSet.lastUpdate.isEmpty() && !globSet.usePinCode) {
if (!globSet.lastUpdate.isEmpty() && globSet._pinVal.isEmpty()) {
emit isds.statusBarTextChanged(
QObject::tr("Last synchronisation: %1").
arg(globSet.lastUpdate), false);
......@@ -227,7 +227,7 @@ int main(int argc, char *argv[])
Accounts::loadModelCounters();
/* show PIN screen if needed */
emit settings.showPinScreen(globSet.usePinCode);
emit settings.showPinScreen(!globSet._pinVal.isEmpty());
/* Run app main event loop */
int ret = app.exec();
......
......@@ -39,8 +39,7 @@ Settings::Settings(void)
downloadCompleteMsgs(false),
msgLifeTimeInDays(DEFAULT_MSG_LIFETIME),
fileLifeTimeInDays(DEFAULT_FILE_LIFETIME),
usePinCode(false),
pinCodeString(""),
_pinVal(),
lastUpdate("")
{
}
......@@ -68,13 +67,10 @@ void Settings::saveGlobalSettingsToFile(QSettings &settings) const
settings.setValue(SETTINGS_MSG_LIFETIME_IN_DAYS, globSet.msgLifeTimeInDays);
settings.setValue(SETTINGS_FILE_LIFETIME_IN_DAYS,
globSet.fileLifeTimeInDays);
settings.setValue(SETTINGS_USE_PIN_CODE, globSet.usePinCode);
if (globSet.usePinCode) {
QByteArray ba;
ba.append(pinCodeString);
settings.setValue(SETTINGS_PIN_CODE_STRING, ba.toBase64());
} else {
settings.setValue(SETTINGS_PIN_CODE_STRING, "");
if (!globSet._pinVal.isEmpty()) {
settings.setValue(SETTINGS_PIN_VAL,
QString::fromUtf8(globSet._pinVal.toUtf8().toBase64()));
}
settings.setValue(SETTINGS_LAST_UPDATE, globSet.lastUpdate);
settings.endGroup();
......@@ -105,10 +101,11 @@ void Settings::loadGlobalSettingsFromFile(const QSettings &settings)
globSet.fileLifeTimeInDays = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_FILE_LIFETIME_IN_DAYS,
DEFAULT_FILE_LIFETIME).toInt();
globSet.usePinCode = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_USE_PIN_CODE, false).toBool();
globSet.pinCodeString = QByteArray::fromBase64(settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_CODE_STRING).toByteArray());
globSet._pinVal = QString::fromUtf8(QByteArray::fromBase64(
settings.value(SETTINGS_GLOBAL_GROUP "/" SETTINGS_PIN_VAL,
QString()).toString().toUtf8()));
globSet.lastUpdate = settings.value(
SETTINGS_GLOBAL_GROUP "/" SETTINGS_LAST_UPDATE).toString();
}
......
......@@ -43,8 +43,7 @@
#define SETTINGS_COMPLETE_MSG "complete_msgs"
#define SETTINGS_MSG_LIFETIME_IN_DAYS "msg_lifetime"
#define SETTINGS_FILE_LIFETIME_IN_DAYS "file_lifetime"
#define SETTINGS_USE_PIN_CODE "use_pin_code"
#define SETTINGS_PIN_CODE_STRING "pin_code_string"
#define SETTINGS_PIN_VAL "pin_val"
#define SETTINGS_LAST_UPDATE "last_update"
#define SETTINGS_LANGUAGE "language"
#define SETTINGS_FONTSIZE "font_size"
......@@ -93,8 +92,7 @@ public:
bool downloadCompleteMsgs;
int msgLifeTimeInDays;
int fileLifeTimeInDays;
bool usePinCode;
QString pinCodeString;
QString _pinVal; /*! PIN value is not read from the configuration file, nor it is stored to the configuration file. */
QString lastUpdate;
};
......
......@@ -83,7 +83,7 @@ void GlobalSettingsQmlWrapper::loadPinSettings(void)
/* ========================================================================= */
{
/* Send PIN data to QML */
emit sendPinData(globSet.usePinCode, globSet.pinCodeString);
emit sendPinData(globSet._pinVal);
}
......@@ -114,15 +114,13 @@ void GlobalSettingsQmlWrapper::updateSettings(const QString &language,
/*
* Slot: Set and save PIN settings from QML to global structure.
*/
void GlobalSettingsQmlWrapper::updatePinSettings(bool usePinCode,
const QString &pinCodeString)
void GlobalSettingsQmlWrapper::updatePinSettings(const QString &pinValue)
/* ========================================================================= */
{
globSet.usePinCode = usePinCode;
if (usePinCode) {
globSet.pinCodeString = pinCodeString;
if (!pinValue.isEmpty()) {
globSet._pinVal = pinValue;
} else {
globSet.pinCodeString = "";
globSet._pinVal.clear();
}
QSettings settings(Settings::settingsPath(), QSettings::IniFormat);
......@@ -135,15 +133,16 @@ void GlobalSettingsQmlWrapper::updatePinSettings(bool usePinCode,
/*
* Slot: Verify PIN entered by user and emit result.
*/
void GlobalSettingsQmlWrapper::verifyPin(const QString &pinCodeString)
void GlobalSettingsQmlWrapper::verifyPin(const QString &pinValue)
/* ========================================================================= */
{
emit sendPinReply(pinCodeString == globSet.pinCodeString);
bool verResult = pinValue == globSet._pinVal;
if ((pinCodeString == globSet.pinCodeString) && !globSet.lastUpdate.isEmpty()) {
emit statusBarTextChanged(
QObject::tr("Last synchronisation: %1").
arg(globSet.lastUpdate), false);
emit sendPinReply(verResult);
if (verResult && !globSet.lastUpdate.isEmpty()) {
emit statusBarTextChanged(tr("Last synchronisation: %1")
.arg(globSet.lastUpdate), false);
}
}
......
......@@ -73,13 +73,12 @@ public:
/*!
* @brief Save PIN settings from QML.
*/
Q_INVOKABLE void updatePinSettings(bool usePinCode,
const QString &pinCodeString);
Q_INVOKABLE void updatePinSettings(const QString &pinValue);
/*!
* @brief Verify PIN entered by user and emit signal with result.
*/
Q_INVOKABLE void verifyPin(const QString &pinCodeString);
Q_INVOKABLE void verifyPin(const QString &pinValue);
/*!
* @brief Returns true if explicit clipboard operations should be used.
......@@ -111,7 +110,7 @@ signals:
/*!
* @brief Send current PIN settings to QML.
*/
void sendPinData(bool usePinCode, QString currentPinCode);
void sendPinData(QString currentPinVal);
/*!
* @brief Send PIN verification result to QML.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment