From 30594f2480053d1ec76b9f21b78a1459ec71024e Mon Sep 17 00:00:00 2001 From: nowrep Date: Thu, 23 May 2013 18:16:20 +0200 Subject: [PATCH] [PasswordManager] Give user feedback when importing/exporting passwords. --- src/lib/preferences/autofillmanager.cpp | 32 ++++++++++++++++++------- src/lib/preferences/autofillmanager.h | 4 ++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/lib/preferences/autofillmanager.cpp b/src/lib/preferences/autofillmanager.cpp index b3eb6e3c8..c773d4dee 100644 --- a/src/lib/preferences/autofillmanager.cpp +++ b/src/lib/preferences/autofillmanager.cpp @@ -276,12 +276,30 @@ void AutoFillManager::showExceptions() void AutoFillManager::importPasswords() { - const QString &fileName = QFileDialog::getOpenFileName(this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); - if (fileName.isEmpty()) { + m_fileName = QFileDialog::getOpenFileName(this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); + + if (m_fileName.isEmpty()) { return; } - QFile file(fileName); + QTimer::singleShot(0, this, SLOT(slotImportPasswords())); +} + +void AutoFillManager::exportPasswords() +{ + m_fileName = QFileDialog::getSaveFileName(this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); + + if (m_fileName.isEmpty()) { + return; + } + + QTimer::singleShot(0, this, SLOT(slotExportPasswords())); +} + +void AutoFillManager::slotImportPasswords() +{ + QFile file(m_fileName); + if (!file.open(QFile::ReadOnly)) { ui->importExportLabel->setText(tr("Cannot read file!")); return; @@ -298,14 +316,10 @@ void AutoFillManager::importPasswords() QApplication::restoreOverrideCursor(); } -void AutoFillManager::exportPasswords() +void AutoFillManager::slotExportPasswords() { - const QString &fileName = QFileDialog::getSaveFileName(this, tr("Choose file..."), QDir::homePath() + "/passwords.xml", "*.xml"); - if (fileName.isEmpty()) { - return; - } + QFile file(m_fileName); - QFile file(fileName); if (!file.open(QFile::WriteOnly)) { ui->importExportLabel->setText(tr("Cannot write to file!")); return; diff --git a/src/lib/preferences/autofillmanager.h b/src/lib/preferences/autofillmanager.h index 8bb5b7d5b..60329f1ef 100644 --- a/src/lib/preferences/autofillmanager.h +++ b/src/lib/preferences/autofillmanager.h @@ -55,10 +55,14 @@ private slots: void importPasswords(); void exportPasswords(); + void slotImportPasswords(); + void slotExportPasswords(); + private: Ui::AutoFillManager* ui; PasswordManager* m_passwordManager; + QString m_fileName; bool m_passwordsShown; };