From a9957c31933b3f51bccf8f0876e0e4c9a34ae6fd Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Tue, 6 Jan 2015 19:00:46 +0000 Subject: [PATCH] Added device error message to file open error messages Thanks to Mike W9MDB for contributing this as a patch. Also added a few more in elsewhere. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@4883 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- HRDTransceiver.cpp | 2 +- WFPalette.cpp | 4 +- astro.cpp | 2 +- logqso.cpp | 2 +- mainwindow.cpp | 91 +++++++++++++++++++++++++++++----------------- 5 files changed, 62 insertions(+), 39 deletions(-) diff --git a/HRDTransceiver.cpp b/HRDTransceiver.cpp index 93fb85943..84e41f916 100644 --- a/HRDTransceiver.cpp +++ b/HRDTransceiver.cpp @@ -161,7 +161,7 @@ void HRDTransceiver::do_start () QFile HRD_info_file {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath ("HRD Interface Information.txt")}; if (!HRD_info_file.open (QFile::WriteOnly | QFile::Text | QFile::Truncate)) { - throw error {tr ("Failed to open file \"%1\".").arg (HRD_info_file.fileName ())}; + throw error {tr ("Failed to open file \"%1\": %2.").arg (HRD_info_file.fileName ()).arg (HRD_info_file.errorString ())}; } QTextStream HRD_info {&HRD_info_file}; diff --git a/WFPalette.cpp b/WFPalette.cpp index 9d638b5d3..22dda7f99 100644 --- a/WFPalette.cpp +++ b/WFPalette.cpp @@ -109,7 +109,7 @@ namespace } else { - throw_qstring (QObject::tr ("Error opening waterfall palette file \"%1\".").arg (file.fileName ())); + throw_qstring (QObject::tr ("Error opening waterfall palette file \"%1\": %2.").arg (file.fileName ()).arg (file.errorString ())); } return colours; @@ -255,7 +255,7 @@ namespace } else { - throw_qstring (QObject::tr ("Error writing waterfall palette file \"%1\".").arg (file.fileName ())); + throw_qstring (QObject::tr ("Error writing waterfall palette file \"%1\": %2.").arg (file.fileName ()).arg (file.errorString ())); } } } diff --git a/astro.cpp b/astro.cpp index b817212a8..65f47ba43 100644 --- a/astro.cpp +++ b/astro.cpp @@ -145,7 +145,7 @@ void Astro::astroUpdate(QDateTime t, QString mygrid, QString hisgrid, if (!f.open (QIODevice::WriteOnly | QIODevice::Text)) { QMessageBox mb; - mb.setText ("Cannot open \"" + f.fileName () + "\"."); + mb.setText ("Cannot open \"" + f.fileName () + "\" for writing:" + f.errorString ()); mb.exec(); return; } diff --git a/logqso.cpp b/logqso.cpp index b5cdd8a52..54eed8c48 100644 --- a/logqso.cpp +++ b/logqso.cpp @@ -121,7 +121,7 @@ void LogQSO::accept() static QFile f {QDir {QStandardPaths::writableLocation (QStandardPaths::DataLocation)}.absoluteFilePath ("wsjtx.log")}; if(!f.open(QIODevice::Text | QIODevice::Append)) { QMessageBox m; - m.setText("Cannot open file \"" + f.fileName () + "\"."); + m.setText("Cannot open file \"" + f.fileName () + "\" for append:" + f.errorString ()); m.exec(); } else { QString logEntry=m_dateTime.date().toString("yyyy-MMM-dd,") + diff --git a/mainwindow.cpp b/mainwindow.cpp index ab81687eb..3a0f0890a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -902,11 +902,17 @@ void MainWindow::qsy (Frequency f) m_secBandChanged=QDateTime::currentMSecsSinceEpoch()/1000; QFile f2 {m_dataDir.absoluteFilePath ("ALL.TXT")}; - f2.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); - QTextStream out(&f2); - out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm") - << " " << (m_dialFreq / 1.e6) << " MHz " << m_mode << endl; - f2.close(); + if (f2.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) + { + QTextStream out(&f2); + out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm") + << " " << (m_dialFreq / 1.e6) << " MHz " << m_mode << endl; + f2.close(); + } + else + { + msgBox("Cannot open \"" + f2.fileName () + "\" for append:" + f2.errorString ()); + } if (m_config.spot_to_psk_reporter ()) { pskSetLocal (); @@ -957,8 +963,7 @@ void MainWindow::statusChanged() << ui->rptSpinBox->value() << ";" << m_modeTx << endl; f.close(); } else { - msgBox("Cannot open file \"" + f.fileName () + "\"."); - return; + msgBox("Cannot open \"" + f.fileName () + "\" for writing:" + f.errorString ()); } } @@ -1194,7 +1199,7 @@ void MainWindow::on_actionKeyboard_shortcuts_triggered() { QFile f(":/shortcuts.txt"); if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) { - msgBox("Cannot open \"" + f.fileName () + "\"."); + msgBox("Cannot open \"" + f.fileName () + "\" for reading:"+f.errorString ()); return; } m_shortcuts.reset (new QTextEdit); @@ -1222,7 +1227,7 @@ void MainWindow::on_actionSpecial_mouse_commands_triggered() { QFile f(":/mouse_commands.txt"); if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) { - msgBox("Cannot open \"" + f.fileName () + "\"."); + msgBox("Cannot open \"" + f.fileName () + "\" for reading:" + f.errorString ()); return; } m_mouseCmnds.reset (new QTextEdit); @@ -1348,16 +1353,22 @@ void MainWindow::readFromStdout() //readFromStdout return; } else { QFile f {m_dataDir.absoluteFilePath ("ALL.TXT")}; - f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); - QTextStream out(&f); - if(m_RxLog==1) { - out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm") - << " " << (m_dialFreq / 1.e6) << " MHz " << m_mode << endl; - m_RxLog=0; - } - int n=t.length(); - out << t.mid(0,n-2) << endl; - f.close(); + if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) + { + QTextStream out(&f); + if(m_RxLog==1) { + out << QDateTime::currentDateTimeUtc().toString("yyyy-MMM-dd hh:mm") + << " " << (m_dialFreq / 1.e6) << " MHz " << m_mode << endl; + m_RxLog=0; + } + int n=t.length(); + out << t.mid(0,n-2) << endl; + f.close(); + } + else + { + msgBox("Cannot open \"" + f.fileName () + "\" for append:" + f.errorString ()); + } if(m_config.insert_blank () && m_blankLine) { @@ -1549,12 +1560,18 @@ void MainWindow::guiUpdate() last_tx_label->setText("Last Tx: " + t); if(m_restart) { QFile f {m_dataDir.absoluteFilePath ("ALL.TXT")}; - f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); - QTextStream out(&f); - out << QDateTime::currentDateTimeUtc().toString("hhmm") - << " Transmitting " << (m_dialFreq / 1.e6) << " MHz " << m_modeTx - << ": " << t << endl; - f.close(); + if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) + { + QTextStream out(&f); + out << QDateTime::currentDateTimeUtc().toString("hhmm") + << " Transmitting " << (m_dialFreq / 1.e6) << " MHz " << m_modeTx + << ": " << t << endl; + f.close(); + } + else + { + msgBox("Cannot open \"" + f.fileName () + "\" for append:" + f.errorString ()); + } if (m_config.TX_messages ()) { ui->decodedTextBrowser2->displayTransmittedText(t,m_modeTx,ui->TxFreqSpinBox->value ()); @@ -1617,12 +1634,18 @@ void MainWindow::guiUpdate() if(!m_tune) { QFile f {m_dataDir.absoluteFilePath ("ALL.TXT")}; - f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); - QTextStream out(&f); - out << QDateTime::currentDateTimeUtc().toString("hhmm") - << " Transmitting " << (m_dialFreq / 1.e6) << " MHz " << m_modeTx - << ": " << t << endl; - f.close(); + if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append)) + { + QTextStream out(&f); + out << QDateTime::currentDateTimeUtc().toString("hhmm") + << " Transmitting " << (m_dialFreq / 1.e6) << " MHz " << m_modeTx + << ": " << t << endl; + f.close(); + } + else + { + msgBox("Cannot open \"" + f.fileName () + "\" for append:" + f.errorString ()); + } } if (m_config.TX_messages () && !m_tune) @@ -2146,7 +2169,7 @@ void MainWindow::on_addButton_clicked() //Add button QFile f1 {m_dataDir.absoluteFilePath ("CALL3.TXT")}; if(!f1.open(QIODevice::ReadWrite | QIODevice::Text)) { - msgBox("Cannot open \"" + f1.fileName () + "\"."); + msgBox("Cannot open \"" + f1.fileName () + "\" for read/write:" + f1.errorString ()); return; } if(f1.size()==0) { @@ -2157,7 +2180,7 @@ void MainWindow::on_addButton_clicked() //Add button } QFile f2 {m_dataDir.absoluteFilePath ("CALL3.TMP")}; if(!f2.open(QIODevice::WriteOnly | QIODevice::Text)) { - msgBox("Cannot open \"" + f2.fileName () + "\"."); + msgBox("Cannot open \"" + f2.fileName () + "\" for writing:" + f2.errorString ()); return; } QTextStream in(&f1); //Read from CALL3.TXT @@ -2940,7 +2963,7 @@ void MainWindow::on_actionShort_list_of_add_on_prefixes_and_suffixes_triggered() { QFile f(":/prefixes.txt"); if(!f.open(QIODevice::ReadOnly | QIODevice::Text)) { - msgBox("Cannot open \"" + f.fileName () + "\"."); + msgBox("Cannot open \"" + f.fileName () + "\" for reading:" + f.errorString ()); return; } m_prefixes.reset (new QTextEdit);