|
12 | 12 | #include <QFileDialog> |
13 | 13 | #include <QFile> |
14 | 14 | #include <QStringList> |
| 15 | +#include <QMessageBox> |
15 | 16 | #include <memory> |
16 | 17 |
|
17 | 18 | #define HEADER_ADDRESS_WIDTH 80 |
@@ -69,6 +70,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), |
69 | 70 |
|
70 | 71 | connect(ui->actionOpen, SIGNAL(triggered()), this, |
71 | 72 | SLOT(slotFileOpen())); |
| 73 | + connect(ui->actionSave, SIGNAL(triggered()), this, |
| 74 | + SLOT(slotFileSave())); |
72 | 75 | connect(ui->actionConnect, SIGNAL(triggered()), this, |
73 | 76 | SLOT(slotProgConnect())); |
74 | 77 | connect(ui->actionReadId, SIGNAL(triggered()), this, |
@@ -139,6 +142,51 @@ void MainWindow::slotFileOpen() |
139 | 142 | file.close(); |
140 | 143 | } |
141 | 144 |
|
| 145 | +void MainWindow::slotFileSave() |
| 146 | +{ |
| 147 | + qint64 ret; |
| 148 | + uint8_t *buffer; |
| 149 | + uint32_t size; |
| 150 | + QString fileName; |
| 151 | + |
| 152 | + bufferTableModel.getBuffer(buffer, size); |
| 153 | + |
| 154 | + if (!size) |
| 155 | + { |
| 156 | + QMessageBox::information(this, tr("Information"), |
| 157 | + tr("The buffer is empty")); |
| 158 | + return; |
| 159 | + } |
| 160 | + |
| 161 | + fileName = QFileDialog::getSaveFileName(this, tr("Save buffer to file"), |
| 162 | + ".", tr("Binary Files (*)")); |
| 163 | + |
| 164 | + if (fileName.isNull()) |
| 165 | + return; |
| 166 | + |
| 167 | + QFile file(fileName); |
| 168 | + if (!file.open(QIODevice::WriteOnly)) |
| 169 | + { |
| 170 | + qCritical() << "Failed to open file:" << fileName << ", error:" << |
| 171 | + file.errorString(); |
| 172 | + return; |
| 173 | + } |
| 174 | + |
| 175 | + ret = file.write(reinterpret_cast<char *>(buffer), size); |
| 176 | + if (ret < 0) |
| 177 | + { |
| 178 | + qCritical() << "Failed to write file:" << fileName << ", error:" << |
| 179 | + file.errorString(); |
| 180 | + } |
| 181 | + else if (ret != size) |
| 182 | + { |
| 183 | + qCritical() << "Failed to write file: written " << ret << " bytes of " |
| 184 | + << size; |
| 185 | + } |
| 186 | + |
| 187 | + file.close(); |
| 188 | +} |
| 189 | + |
142 | 190 | void MainWindow::setUiStateConnected(bool isConnected) |
143 | 191 | { |
144 | 192 | ui->chipSelectComboBox->setEnabled(isConnected); |
|
0 commit comments