MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / openFile

Method openFile

app/src/IO/FileTransmission.cpp:262–301  ·  view source on GitHub ↗

* @brief Opens a file selection dialog. */

Source from the content-addressed store, hash-verified

260 * @brief Opens a file selection dialog.
261 */
262void IO::FileTransmission::openFile()
263{
264 auto* dialog =
265 new QFileDialog(qApp->activeWindow(), tr("Select file to transmit"), QDir::homePath());
266 dialog->setFileMode(QFileDialog::ExistingFile);
267 dialog->setAttribute(Qt::WA_DeleteOnClose);
268
269 connect(dialog, &QFileDialog::fileSelected, this, [this](const QString& path) {
270 if (path.isEmpty())
271 return;
272
273 QMetaObject::invokeMethod(
274 this,
275 [this, path]() {
276 if (fileOpen())
277 closeFile();
278
279 m_filePath = path;
280 m_file.setFileName(path);
281 if (m_file.open(QFile::ReadOnly)) {
282 m_bytesTotal = m_file.size();
283 m_bytesSent = 0;
284
285 if (m_transferMode == PlainText)
286 m_stream = new QTextStream(&m_file);
287
288 Q_EMIT fileChanged();
289 Q_EMIT progressChanged();
290 appendLog(
291 tr("File selected: %1 (%2 bytes)").arg(QFileInfo(path).fileName()).arg(m_bytesTotal));
292 } else {
293 qWarning() << "File open error:" << m_file.errorString();
294 appendLog(tr("Error opening file: %1").arg(m_file.errorString()));
295 }
296 },
297 Qt::QueuedConnection);
298 });
299
300 dialog->open();
301}
302
303/**
304 * @brief Closes the currently selected file and resets state.

Callers

nothing calls this directly

Calls 7

isEmptyMethod · 0.80
errorStringMethod · 0.80
activeWindowMethod · 0.45
setFileNameMethod · 0.45
openMethod · 0.45
sizeMethod · 0.45
fileNameMethod · 0.45

Tested by

no test coverage detected