| | 86 | bool Text::EditorDock::exportTextAs() { |
| | 87 | // show a funny `export text as` dialog |
| | 88 | QString new_filename = QFileDialog::getSaveFileName(main, |
| | 89 | tr("Export Card Text (%1)").arg(getCodec()->getName()), |
| | 90 | filename.isEmpty() ? QDir::homePath() : QFileInfo(filename).absolutePath(), |
| | 91 | tr("Plain Text File (*.txt);;Any File (*)")); |
| | 92 | if(new_filename.isEmpty()) |
| | 93 | return false; |
| | 94 | |
| | 95 | // save filename and go on exporting normally |
| | 96 | this->filename = new_filename; |
| | 97 | this->exportText(); |
| | 98 | } |
| | 99 | |
| | 100 | bool Text::EditorDock::exportText() { |
| | 101 | if(this->filename.isEmpty()) { |
| | 102 | return exportTextAs(); |
| | 103 | } |
| | 104 | |
| | 105 | QFile file(this->filename); |
| | 106 | // everything in one line ;-) |
| | 107 | if(!file.open( QIODevice::WriteOnly | QIODevice::Text ) || |
| | 108 | (file.write( this->getText().toAscii() ) == -1) ) { |
| | 109 | QMessageBox::critical(main, tr("Could not export to file"), |
| | 110 | tr("Plain text export to file %1 failed: %2").arg(filename).arg(file.errorString())); |
| | 111 | return false; |
| | 112 | } else { |
| | 113 | main->statusBar()->showMessage(tr("Successfully exported card text as %1 to %2 ").arg(getCodec()->getName()).arg(filename), 5000); |
| | 114 | return true; |
| | 115 | } |
| | 116 | } |
| | 117 | |