Commit 0ebdeb72 authored by Ming Rui Zhang's avatar Ming Rui Zhang Committed by Andreas Traczyk

settingswidget: change export account mechanism

- add option of entering password
- change file save dialog style

Change-Id: I973a2f4871cff82bdcc71a49d9f67f37f259ec73
parent 1e1973cd
......@@ -21,11 +21,14 @@
#include <QTimer>
#include <QtConcurrent/QtConcurrent>
#include <QMessageBox>
#include "lrcinstance.h"
#include "utils.h"
PasswordDialog::PasswordDialog(QWidget* parent)
PasswordDialog::PasswordDialog(QWidget* parent, PasswordEnteringPurpose purpose)
:ui(new Ui::PasswordDialog),
purpose_(purpose),
QDialog(parent)
{
ui->setupUi(this);
......@@ -39,15 +42,52 @@ PasswordDialog::PasswordDialog(QWidget* parent)
ui->currentPasswordEdit->setEnabled(LRCInstance::getCurrAccConfig().archiveHasPassword);
connect(ui->currentPasswordEdit, &QLineEdit::textChanged, this, &PasswordDialog::validatePassword);
connect(ui->passwordEdit, &QLineEdit::textChanged, this, &PasswordDialog::validatePassword);
connect(ui->confirmPasswordEdit, &QLineEdit::textChanged, this, &PasswordDialog::validatePassword);
connect(ui->btnChangePasswordConfirm, &QPushButton::clicked, [this] { savePassword(); });
if (purpose_ == PasswordEnteringPurpose::ChangePassword) {
ui->verticalSpacerCurrentTNew->changeSize(20, 8, QSizePolicy::Fixed, QSizePolicy::Fixed);
ui->verticalSpacerNewTConfirm->changeSize(20, 8, QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(ui->currentPasswordEdit, &QLineEdit::textChanged, this, &PasswordDialog::validatePassword);
connect(ui->passwordEdit, &QLineEdit::textChanged, this, &PasswordDialog::validatePassword);
connect(ui->confirmPasswordEdit, &QLineEdit::textChanged, this, &PasswordDialog::validatePassword);
connect(ui->btnChangePasswordConfirm, &QPushButton::clicked,
[this] {
spinnerMovie_->start();
ui->spinnerLabel->show();
QtConcurrent::run([this] { savePassword(); });
});
} else if (purpose_ == PasswordEnteringPurpose::ExportAccount) {
setWindowTitle(tr("Enter the password of this account"));
ui->passwordEdit->hide();
ui->confirmPasswordEdit->hide();
ui->verticalSpacerCurrentTNew->changeSize(20, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
ui->verticalSpacerNewTConfirm->changeSize(20, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(ui->btnChangePasswordConfirm, &QAbstractButton::clicked,
[this] {
spinnerMovie_->start();
ui->spinnerLabel->show();
QtConcurrent::run([this] { exportAccount(); });
});
}
connect(ui->currentPasswordEdit, &QLineEdit::textChanged,
[this] {
if (ui->currentPasswordEdit->text().isEmpty()) {
ui->btnChangePasswordConfirm->setEnabled(false);
} else {
ui->wrongPasswordLabel->hide();
ui->btnChangePasswordConfirm->setEnabled(true);
}
});
connect(ui->btnChangePasswordCancel, &QPushButton::clicked, [this] { reject(); });
ui->btnChangePasswordConfirm->setEnabled(false);
ui->wrongPasswordLabel->hide();
spinnerMovie_ = new QMovie(":/images/ajax-loader.gif");
spinnerMovie_->setScaledSize(QSize(20, 20));
ui->spinnerLabel->setMovie(spinnerMovie_);
ui->spinnerLabel->hide();
}
PasswordDialog::~PasswordDialog()
......@@ -55,6 +95,23 @@ PasswordDialog::~PasswordDialog()
delete ui;
}
void
PasswordDialog::exportAccount()
{
bool success = LRCInstance::accountModel().exportToFile(LRCInstance::getCurrAccId(),
path_,
ui->currentPasswordEdit->text().toStdString());
ui->spinnerLabel->hide();
spinnerMovie_->stop();
if(success) {
done(SuccessCode);
} else {
Utils::whileBlocking<QLineEdit>(ui->currentPasswordEdit)->clear();
ui->btnChangePasswordConfirm->setEnabled(false);
ui->wrongPasswordLabel->show();
}
}
void
PasswordDialog::validatePassword()
{
......@@ -74,16 +131,21 @@ PasswordDialog::validatePassword()
void
PasswordDialog::savePassword()
{
if (LRCInstance::accountModel().changeAccountPassword(LRCInstance::getCurrAccId(),
ui->currentPasswordEdit->text().toStdString(), ui->passwordEdit->text().toStdString())) {
bool success = LRCInstance::accountModel().changeAccountPassword(LRCInstance::getCurrAccId(),
ui->currentPasswordEdit->text().toStdString(), ui->passwordEdit->text().toStdString());
ui->spinnerLabel->hide();
spinnerMovie_->stop();
if (success) {
auto confProps = LRCInstance::accountModel().getAccountConfig(LRCInstance::getCurrAccId());
confProps.archiveHasPassword = !ui->passwordEdit->text().isEmpty();
LRCInstance::accountModel().setAccountConfig(LRCInstance::getCurrAccId(), confProps);
accept();
done(SuccessCode);
} else {
Utils::whileBlocking<QLineEdit>(ui->currentPasswordEdit)->clear();
ui->btnChangePasswordConfirm->setEnabled(false);
ui->wrongPasswordLabel->show();
ui->currentPasswordEdit->setText("");
}
}
......@@ -18,23 +18,38 @@
#pragma once
#include <QDialog>
#include <QMovie>
namespace Ui {
class PasswordDialog;
}
enum class PasswordEnteringPurpose{
ChangePassword,
ExportAccount
};
class PasswordDialog : public QDialog
{
Q_OBJECT
public:
PasswordDialog(QWidget* parent = nullptr);
PasswordDialog(QWidget* parent = nullptr, PasswordEnteringPurpose purpose = PasswordEnteringPurpose::ChangePassword);
~PasswordDialog();
static const int SuccessCode = 200;
void setExportPath(const std::string& path) { path_ = path; }
private slots:
void validatePassword();
void exportAccount();
private:
Ui::PasswordDialog* ui;
PasswordEnteringPurpose purpose_ { PasswordEnteringPurpose::ChangePassword };
std::string path_;
QMovie* spinnerMovie_;
void savePassword();
};
\ No newline at end of file
};
This diff is collapsed.
......@@ -492,7 +492,10 @@ void SettingsWidget::setAvatar(PhotoboothWidget* avatarWidget, bool stopPhotoboo
void SettingsWidget::passwordClicked()
{
PasswordDialog passwdDialog(this);
passwdDialog.exec();
int doneCode = passwdDialog.exec();
if(doneCode == PasswordDialog::SuccessCode)
QMessageBox::information(0, tr("Success"), tr("Password Changed Successfully"));
}
void SettingsWidget::toggleAdvancedSIPSettings()
......@@ -753,11 +756,31 @@ void SettingsWidget::unban(int index)
void SettingsWidget::exportAccountSlot()
{
QFileDialog dialog(this);
QString dir = QFileDialog::getExistingDirectory(this, tr("Export Account Here"),
QDir::homePath() + "/Desktop", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
auto openPath = QDir::homePath() + "/Desktop" + "/export.gz";
auto fileUri = QFileDialog::getSaveFileUrl(this, tr("Export Account"), QUrl::fromLocalFile(openPath),
tr("Gzip File") + " (*.gz)", nullptr, QFileDialog::DontResolveSymlinks);
if (!fileUri.isEmpty()) {
// remove prefix from QUri encoded data
std::string filePrefix { "file:///" };
auto filePathStd = fileUri.toEncoded().toStdString();
filePathStd = filePathStd.substr(filePathStd.find(filePrefix) + static_cast<int>(filePrefix.size()));
if (LRCInstance::getCurrAccConfig().archiveHasPassword) {
PasswordDialog dialog (this, PasswordEnteringPurpose::ExportAccount);
dialog.setExportPath(filePathStd);
int doneCode = dialog.exec();
if (doneCode == PasswordDialog::SuccessCode)
QMessageBox::information(0, tr("Success"), tr("Export Successful"));
} else {
bool success = LRCInstance::accountModel().exportToFile(LRCInstance::getCurrAccId(), filePathStd);
if (success) {
QMessageBox::information(0, tr("Success"), tr("Export Successful"));
} else {
QMessageBox::critical(0, tr("Error"), tr("Export Failed"));
}
if (!dir.isEmpty()) {
LRCInstance::accountModel().exportToFile(LRCInstance::getCurrAccId(), (dir + "/export.gz").toStdString());
}
}
}
......
......@@ -392,6 +392,21 @@ QPushButton#deleteBanBtn:pressed, QPushButton#cancelChangeBtn:pressed{
background-color: rgb(219, 55, 54);
}
QPushButton#btnChangePasswordCancel {
background-color: rgb(252, 91, 90);
color: white;
}
QPushButton#btnChangePasswordCancel:hover {
background-color: red;
color: white;
}
QPushButton#btnChangePasswordCancel:pressed {
background-color: darkred;
color: white;
}
QComboBox{
background: transparent;
border-radius: 0px;
......
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