Skip to content

Commit

Permalink
Add filename extension properly
Browse files Browse the repository at this point in the history
  • Loading branch information
adityapk00 committed Jun 20, 2019
1 parent 3a5aa5d commit ef21744
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions ui/src/mainwindow.cpp
Expand Up @@ -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);
Expand All @@ -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"));
}
}
}
Expand Down

0 comments on commit ef21744

Please sign in to comment.