Refuse to overwrite imported file with multiple subpages

This commit is contained in:
Gavin MacGregor
2025-03-05 18:41:39 +00:00
parent 564243822e
commit 10059e5d0b
4 changed files with 18 additions and 3 deletions

View File

@@ -206,6 +206,7 @@ bool LoadT42Format::load(QFile *inFile, TeletextDocument *document)
m_warnings.clear(); m_warnings.clear();
m_error.clear(); m_error.clear();
m_reExportWarning = false;
for (;;) { for (;;) {
if (!readPacket()) if (!readPacket())
@@ -247,6 +248,7 @@ bool LoadT42Format::load(QFile *inFile, TeletextDocument *document)
if (readPageNumber != foundPageNumber) { if (readPageNumber != foundPageNumber) {
// More than one page in .t42 file - end of current page reached // More than one page in .t42 file - end of current page reached
m_warnings.append("More than one page in .t42 file, only first full page loaded."); m_warnings.append("More than one page in .t42 file, only first full page loaded.");
m_reExportWarning = true;
break; break;
} }
// Could get here if X/0 with same page number was found with no body packets inbetween // Could get here if X/0 with same page number was found with no body packets inbetween
@@ -421,6 +423,7 @@ bool LoadEP1Format::load(QFile *inFile, TeletextDocument *document)
{ {
m_warnings.clear(); m_warnings.clear();
m_error.clear(); m_error.clear();
m_reExportWarning = false;
unsigned char inLine[42]; unsigned char inLine[42];
unsigned char numOfSubPages = 1; unsigned char numOfSubPages = 1;
@@ -440,6 +443,7 @@ bool LoadEP1Format::load(QFile *inFile, TeletextDocument *document)
return false; return false;
m_warnings.append("More than one page in EP1/EPX file, only first full page loaded."); m_warnings.append("More than one page in EP1/EPX file, only first full page loaded.");
m_reExportWarning = true;
} }
// Check for header of a (sub)page // Check for header of a (sub)page

View File

@@ -43,11 +43,13 @@ public:
QString fileDialogFilter() const { return QString(description() + " (*." + extensions().join(" *.") + ')'); }; QString fileDialogFilter() const { return QString(description() + " (*." + extensions().join(" *.") + ')'); };
QStringList warningStrings() const { return m_warnings; }; QStringList warningStrings() const { return m_warnings; };
QString errorString() const { return m_error; }; QString errorString() const { return m_error; };
bool reExportWarning() const { return m_reExportWarning; };
protected: protected:
TeletextDocument const *m_document; TeletextDocument const *m_document;
QStringList m_warnings; QStringList m_warnings;
QString m_error; QString m_error;
bool m_reExportWarning = false;
}; };
class LoadTTIFormat : public LoadFormat class LoadTTIFormat : public LoadFormat

View File

@@ -332,6 +332,7 @@ void MainWindow::init()
setAttribute(Qt::WA_DeleteOnClose); setAttribute(Qt::WA_DeleteOnClose);
m_isUntitled = true; m_isUntitled = true;
m_reExportWarning = false;
m_textWidget = new TeletextWidget; m_textWidget = new TeletextWidget;
@@ -1087,6 +1088,8 @@ void MainWindow::loadFile(const QString &fileName)
if (!loadingFormat->warningStrings().isEmpty()) if (!loadingFormat->warningStrings().isEmpty())
QMessageBox::warning(this, QApplication::applicationDisplayName(), tr("The following issues were encountered when loading<br>%1:<ul><li>%2</li></ul>").arg(QDir::toNativeSeparators(fileName), loadingFormat->warningStrings().join("</li><li>"))); QMessageBox::warning(this, QApplication::applicationDisplayName(), tr("The following issues were encountered when loading<br>%1:<ul><li>%2</li></ul>").arg(QDir::toNativeSeparators(fileName), loadingFormat->warningStrings().join("</li><li>")));
m_reExportWarning = loadingFormat->reExportWarning();
setCurrentFile(fileName); setCurrentFile(fileName);
statusBar()->showMessage(tr("File loaded"), 2000); statusBar()->showMessage(tr("File loaded"), 2000);
} }
@@ -1228,9 +1231,14 @@ void MainWindow::exportFile(bool fromAuto)
QString exportFileName; QString exportFileName;
SaveFormat *exportFormat = nullptr; SaveFormat *exportFormat = nullptr;
if (fromAuto) if (fromAuto) {
if (m_reExportWarning) {
QMessageBox::StandardButton ret = QMessageBox::warning(this, QApplication::applicationDisplayName(), tr("Will not overwrite imported file %1:\nAll other subpages in that file would be erased.\nPlease save or export to a different file.").arg(strippedName(m_exportAutoFileName)));
return;
}
exportFileName = m_exportAutoFileName; exportFileName = m_exportAutoFileName;
else { } else {
if (m_exportAutoFileName.isEmpty()) if (m_exportAutoFileName.isEmpty())
exportFileName = m_curFile; exportFileName = m_curFile;
else else
@@ -1284,6 +1292,7 @@ void MainWindow::exportFile(bool fromAuto)
MainWindow::prependToRecentFiles(exportFileName); MainWindow::prependToRecentFiles(exportFileName);
m_exportAutoFileName = exportFileName; m_exportAutoFileName = exportFileName;
m_reExportWarning = false;
statusBar()->showMessage(tr("File exported"), 2000); statusBar()->showMessage(tr("File exported"), 2000);
} }

View File

@@ -139,7 +139,7 @@ private:
QRadioButton *m_levelRadioButton[4]; QRadioButton *m_levelRadioButton[4];
QString m_curFile, m_exportAutoFileName, m_exportImageFileName; QString m_curFile, m_exportAutoFileName, m_exportImageFileName;
bool m_isUntitled; bool m_isUntitled, m_reExportWarning;
LoadFormats m_loadFormats; LoadFormats m_loadFormats;
SaveFormats m_saveFormats; SaveFormats m_saveFormats;