From ef21744feb660a1fdbce1d02ef402ca17fb51502 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 20 Jun 2019 11:44:53 -0700 Subject: [PATCH] Add filename extension properly --- ui/src/mainwindow.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ui/src/mainwindow.cpp b/ui/src/mainwindow.cpp index 5045e9d..a4e797a 100644 --- a/ui/src/mainwindow.cpp +++ b/ui/src/mainwindow.cpp @@ -102,6 +102,9 @@ void MainWindow::SaveAsPDFButton() { // Get a save file name auto filename = QFileDialog::getSaveFileName(this, tr("Save as PDF"), "", tr("PDF Files (*.pdf)")); if (!filename.isEmpty()) { + if (!filename.endsWith(".pdf")) + filename = filename + ".pdf"; + bool success = rust_save_as_pdf(this->currentWallets.toStdString().c_str(), filename.toStdString().c_str()); if (success) { QMessageBox::information(this, tr("Saved!"), tr("The wallets were saved to ") + filename); @@ -119,11 +122,20 @@ void MainWindow::SaveAsJSONButton() { auto filename = QFileDialog::getSaveFileName(this, tr("Save as text"), "", tr("Text Files (*.txt)")); if (!filename.isEmpty()) { + if (!filename.endsWith(".txt")) + filename = filename + ".txt"; + + QFile file(filename); if (file.open(QIODevice::WriteOnly)) { QTextStream stream(&file); stream << this->currentWallets << endl; + + QMessageBox::information(this, tr("Saved!"), tr("The wallets were saved to ") + filename); + } else { + QMessageBox::warning(this, tr("Failed to save file"), + tr("Couldn't save the file for some unknown reason")); } } }