Skip to content

Commit

Permalink
Merge pull request #321 from asashnov/318-odd-export-behavior
Browse files Browse the repository at this point in the history
318 odd export behavior
  • Loading branch information
limpkin authored Jul 31, 2018
2 parents 454f11b + 617ab63 commit 4c337d1
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/DbBackupsTracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ QString DbBackupsTracker::getTrackedBackupFileFormat()
return "none";

if (isAnEncryptedBackup(d))
return "SympleCrypt";
return "SimpleCrypt";

return "none";
}
Expand Down
2 changes: 1 addition & 1 deletion src/DbBackupsTracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class DbBackupsTracker : public QObject

/**
* Guess the current tracked backup file format,
* currently suported: "none" and "SympleCrypt"
* currently suported: "none" and "SimpleCrypt"
* throws: DbBackupsTrackerNoBackupFileSet
*/
QString getTrackedBackupFileFormat();
Expand Down
35 changes: 18 additions & 17 deletions src/DbBackupsTrackerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,13 @@ void DbBackupsTrackerController::askForExportBackup()

void DbBackupsTrackerController::exportDbBackup()
{
QString format;
try
{
format = dbBackupsTracker.getTrackedBackupFileFormat();
}
catch (DbBackupsTrackerNoBackupFileSet)
{
format = "SympleCrypt";
}

QString format = "SimpleCrypt";

window->wantExportDatabase();

// one-time connection, must be disconected immediately in the slot
connect(wsClient, &WSClient::dbExported, this, &DbBackupsTrackerController::handleExportDbResult);

wsClient->exportDbFile(format);
}

Expand Down Expand Up @@ -202,17 +197,23 @@ void DbBackupsTrackerController::clearTrackerCardInfo()

void DbBackupsTrackerController::handleExportDbResult(const QByteArray &d, bool success)
{
if (success)
{
QString file = getBackupFilePath();
writeDbBackup(file, d);
// one-time connection
disconnect(wsClient, &WSClient::dbExported, this, &DbBackupsTrackerController::handleExportDbResult);

window->handleBackupExported();
}
else
if (! success)
{
QMessageBox::warning(window, tr("Error"), tr(d));
return;
}

QString file = getBackupFilePath();
if (file.isEmpty())
return;

writeDbBackup(file, d);

if (window)
window->handleBackupExported();
}

void DbBackupsTrackerController::handleNewTrack(const QString &cardId, const QString &path)
Expand Down
40 changes: 29 additions & 11 deletions src/DbExportsRegistryController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void DbExportsRegistryController::setWSClient(WSClient *wsClient)
{
DbExportsRegistryController::wsClient = wsClient;
dbExportsRegistry->setCurrentCardDbMetadata(wsClient->get_cardId(), wsClient->get_credentialsDbChangeNumber(), wsClient->get_dataDbChangeNumber());
connect(wsClient, &WSClient::dbExported, this, &DbExportsRegistryController::registerDbExported, Qt::UniqueConnection);
}

void DbExportsRegistryController::hidePrompt()
Expand All @@ -62,6 +63,17 @@ void DbExportsRegistryController::handleCardIdChanged(QString cardId, int creden
dbExportsRegistry->setCurrentCardDbMetadata(QString(), -1, -1);
}

/**! Register the last export time by any reason.
* This method will be called every time WSClient::dbExported signal is fired.
*
* The reason export was done may be:
* - user clicked 'Export to File' button;
* - monitored backup file was updated
* - periodic backup was done
*
* FIXME: the fact daemon sent a backup doesn't mean it was actually
* written to file.
*/
void DbExportsRegistryController::registerDbExported(const QByteArray &, bool success)
{
if (success)
Expand Down Expand Up @@ -107,22 +119,24 @@ void DbExportsRegistryController::handleDbExportRecommended()

void DbExportsRegistryController::handleExportDbResult(const QByteArray &d, bool success)
{
if (! handleExportResultEnabled)
return;
handleExportResultEnabled = false;
// one-time connection
disconnect(wsClient, &WSClient::dbExported, this, &DbExportsRegistryController::handleExportDbResult);

if (window)
window->handleBackupExported();

if (success)
if (! success)
{
QString fname = QFileDialog::getSaveFileName(window, tr("Save database export..."), QString(),
"Memory exports (*.bin);;All files (*.*)");
if (!fname.isEmpty())
writeDbToFile(d, fname);
}
else
QMessageBox::warning(window, tr("Error"), tr(d));
return;
}

QString fname = QFileDialog::getSaveFileName(window, tr("Save database export..."), QString(),
"Memory exports (*.bin);;All files (*.*)");
if (fname.isEmpty())
return;

writeDbToFile(d, fname);
}

void DbExportsRegistryController::handleDeviceStatusChanged(const Common::MPStatus &status)
Expand Down Expand Up @@ -150,9 +164,13 @@ void DbExportsRegistryController::exportDbBackup()
{
handleExportResultEnabled = true;

QString format = "SympleCrypt";
QString format = "SimpleCrypt";

if (window)
window->wantExportDatabase();

// one-time connection, must be disconected immediately in the slot
connect(wsClient, &WSClient::dbExported, this, &DbExportsRegistryController::handleExportDbResult);

wsClient->exportDbFile(format);
}
13 changes: 0 additions & 13 deletions src/DbMasterController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ void DbMasterController::setWSClient(WSClient *client)
connect(wsClient, &WSClient::cardDbMetadataChanged, this, &DbMasterController::handleCardIdChanged);
connect(wsClient, &WSClient::statusChanged, this, &DbMasterController::handleDeviceStatusChanged);
connect(wsClient, &WSClient::connectedChanged, this, &DbMasterController::handleDeviceConnectedChanged);
connect(wsClient, &WSClient::dbExported, this, &DbMasterController::registerDbExported);

dbExportsRegistryController->setWSClient(wsClient);
}
Expand Down Expand Up @@ -85,15 +84,3 @@ void DbMasterController::handleDeviceConnectedChanged(const bool &connected)

dbExportsRegistryController->handleDeviceConnectedChanged(connected);
}

void DbMasterController::registerDbExported(const QByteArray &data, bool success)
{
if (dbBackupsTrackerController) {
dbBackupsTrackerController->handleExportDbResult(data, success);
if (! dbBackupsTrackerController->getBackupFilePath().isEmpty())
return;
}

dbExportsRegistryController->registerDbExported(data, success);
dbExportsRegistryController->handleExportDbResult(data, success);
}
1 change: 0 additions & 1 deletion src/DbMasterController.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ private slots:
void handleCardIdChanged(QString cardId, int credentialsDbChangeNumber, int dataDbChangeNumber);
void handleDeviceStatusChanged(const Common::MPStatus &status);
void handleDeviceConnectedChanged(const bool &connected);
void registerDbExported(const QByteArray &data, bool success);

private:
MainWindow *window = nullptr;
Expand Down
7 changes: 5 additions & 2 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1168,8 +1168,9 @@ void MainWindow::on_pushButtonExportFile_clicked()
else
wsClient->exportDbFile("SimpleCrypt");


// one-time connection, must be disconected immediately in the slot
connect(wsClient, &WSClient::dbExported, this, &MainWindow::dbExported);

wantExportDatabase();
}

Expand All @@ -1194,8 +1195,10 @@ void MainWindow::on_pushButtonImportFile_clicked()

void MainWindow::dbExported(const QByteArray &d, bool success)
{
ui->widgetHeader->setEnabled(true);
// one-time connection
disconnect(wsClient, &WSClient::dbExported, this, &MainWindow::dbExported);

ui->widgetHeader->setEnabled(true);
if (!success)
QMessageBox::warning(this, tr("Error"), tr(d));
else
Expand Down
4 changes: 2 additions & 2 deletions tests/DbBackupsTrackerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,13 +323,13 @@ void DbBackupsTrackerTests::getFileFormatLegacy()
t->deleteLater();
}

void DbBackupsTrackerTests::getFileFormatSympleCrypt()
void DbBackupsTrackerTests::getFileFormatSimpleCrypt()
{
DbBackupsTracker* t = new DbBackupsTracker("/tmp/test_db_backups_tracker.info");
t->setCardId("00000");
QString file = getTestsDataDirPath() + "tests_backup";
t->track(file);

QCOMPARE(QString("SympleCrypt"), t->getTrackedBackupFileFormat());
QCOMPARE(QString("SimpleCrypt"), t->getTrackedBackupFileFormat());
t->deleteLater();
}
2 changes: 1 addition & 1 deletion tests/DbBackupsTrackerTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private slots:
void credentialChangenumberWrapOver();

void getFileFormatLegacy();
void getFileFormatSympleCrypt();
void getFileFormatSimpleCrypt();

private:
DbBackupsTracker tracker;
Expand Down

0 comments on commit 4c337d1

Please sign in to comment.