Skip to content
Snippets Groups Projects
Commit ab5d3b9c authored by Ming Rui Zhang's avatar Ming Rui Zhang
Browse files

newwizardwidget: add potential password dialog when exporting account

Change-Id: I6e534712366514c5c81e03880252887ba0899c71
parent 89e7438b
Branches
No related tags found
No related merge requests found
...@@ -360,16 +360,11 @@ NewWizardWidget::on_skipBtn_clicked() ...@@ -360,16 +360,11 @@ NewWizardWidget::on_skipBtn_clicked()
void void
NewWizardWidget::on_exportBtn_clicked() NewWizardWidget::on_exportBtn_clicked()
{ {
QFileDialog dialog(this); if (Utils::exportAccount(this)) {
QString dir = QFileDialog::getExistingDirectory(this, tr("Export Account Here"),
QDir::homePath() + "/Desktop", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
if (!dir.isEmpty()) {
LRCInstance::accountModel().exportToFile(LRCInstance::getCurrAccId(), dir + "/export.gz");
}
emit NavigationRequested(ScreenEnum::CallScreen); emit NavigationRequested(ScreenEnum::CallScreen);
emit LRCInstance::instance().accountListChanged(); emit LRCInstance::instance().accountListChanged();
} }
}
void void
NewWizardWidget::on_usernameEdit_textChanged(const QString &arg1) NewWizardWidget::on_usernameEdit_textChanged(const QString &arg1)
......
...@@ -749,33 +749,7 @@ SettingsWidget::unban(int index) ...@@ -749,33 +749,7 @@ SettingsWidget::unban(int index)
void void
SettingsWidget::exportAccountSlot() SettingsWidget::exportAccountSlot()
{ {
QFileDialog dialog(this); Utils::exportAccount(this);
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
QString filePrefix { "file:///" };
auto filePath = QString::fromLocal8Bit(fileUri.toEncoded());
filePath = filePath.remove(filePrefix);
if (LRCInstance::getCurrAccConfig().archiveHasPassword) {
PasswordDialog dialog (this, PasswordEnteringPurpose::ExportAccount);
dialog.setExportPath(filePath);
int doneCode = dialog.exec();
if (doneCode == PasswordDialog::SuccessCode)
QMessageBox::information(0, tr("Success"), tr("Export Successful"));
} else {
bool success = LRCInstance::accountModel().exportToFile(LRCInstance::getCurrAccId(), filePath);
if (success) {
QMessageBox::information(0, tr("Success"), tr("Export Successful"));
} else {
QMessageBox::critical(0, tr("Error"), tr("Export Failed"));
}
}
}
} }
void void
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "updateconfirmdialog.h" #include "updateconfirmdialog.h"
#include "version.h" #include "version.h"
#include "mainwindow.h" #include "mainwindow.h"
#include "passworddialog.h"
#include <globalinstances.h> #include <globalinstances.h>
#include <qrencode.h> #include <qrencode.h>
...@@ -44,6 +45,7 @@ ...@@ -44,6 +45,7 @@
#include <QBitmap> #include <QBitmap>
#include <QObject> #include <QObject>
#include <QErrorMessage> #include <QErrorMessage>
#include <QFileDialog>
#include <QPainter> #include <QPainter>
#include <QStackedWidget> #include <QStackedWidget>
#include <QPropertyAnimation> #include <QPropertyAnimation>
...@@ -777,6 +779,43 @@ Utils::setCurrentScalingRatio(float ratio) ...@@ -777,6 +779,43 @@ Utils::setCurrentScalingRatio(float ratio)
CURRENT_SCALING_RATIO = ratio; CURRENT_SCALING_RATIO = ratio;
} }
bool
Utils::exportAccount(QWidget* parent)
{
QFileDialog dialog(parent);
auto openPath = QDir::homePath() + "/Desktop" + "/export.gz";
auto fileUri = QFileDialog::getSaveFileUrl(parent, QObject::tr("Export Account"), QUrl::fromLocalFile(openPath),
QObject::tr("Gzip File") + " (*.gz)", nullptr, QFileDialog::DontResolveSymlinks);
if (!fileUri.isEmpty()) {
// remove prefix from QUri encoded data
QString filePrefix{ "file:///" };
auto filePath = QString::fromLocal8Bit(fileUri.toEncoded());
filePath = filePath.remove(filePrefix);
if (LRCInstance::getCurrAccConfig().archiveHasPassword) {
PasswordDialog dialog(parent, PasswordEnteringPurpose::ExportAccount);
dialog.setExportPath(filePath);
int doneCode = dialog.exec();
if (doneCode == PasswordDialog::SuccessCode) {
QMessageBox::information(0, QObject::tr("Success"), QObject::tr("Export Successful"));
return true;
}
}
else {
bool success = LRCInstance::accountModel().exportToFile(LRCInstance::getCurrAccId(), filePath);
if (success) {
QMessageBox::information(0, QObject::tr("Success"), QObject::tr("Export Successful"));
} else {
QMessageBox::critical(0, QObject::tr("Error"), QObject::tr("Export Failed"));
}
return success;
}
}
return false;
}
QString QString
Utils::formattedTime(int duration) Utils::formattedTime(int duration)
{ {
......
...@@ -78,6 +78,7 @@ void forceDeleteAsync(const QString& path); ...@@ -78,6 +78,7 @@ void forceDeleteAsync(const QString& path);
QString getChangeLog(); QString getChangeLog();
float getCurrentScalingRatio(); float getCurrentScalingRatio();
void setCurrentScalingRatio(float ratio); void setCurrentScalingRatio(float ratio);
bool exportAccount(QWidget* parent);
// updates // updates
void cleanUpdateFiles(); void cleanUpdateFiles();
......
...@@ -602,6 +602,11 @@ QLabel#dragDropLabel { ...@@ -602,6 +602,11 @@ QLabel#dragDropLabel {
background: rgba(216, 234, 252, 0.95); background: rgba(216, 234, 252, 0.95);
} }
QLabel#wrongPasswordLabel {
color: red;
margin-left: 8px;
}
/* setAvatarDialog { */ /* setAvatarDialog { */
QPushButton#pictureButton:default, QPushButton#fileButton:default { QPushButton#pictureButton:default, QPushButton#fileButton:default {
background-color: rgb(0, 192, 213,); background-color: rgb(0, 192, 213,);
...@@ -639,10 +644,6 @@ QSpinBox::down-button { ...@@ -639,10 +644,6 @@ QSpinBox::down-button {
} }
/* SettingsWidget { */ /* SettingsWidget { */
SettingsWidget QLabel#wrongPasswordLabel {
color: red;
margin-left: 8px;
}
SettingsWidget QLabel#exportedPIN { SettingsWidget QLabel#exportedPIN {
color: darkblue; color: darkblue;
margin-bottom: 4px; margin-bottom: 4px;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment