Index: ossp-pkg/as/as-gui/as_assist.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_assist.cpp,v rcsdiff -q -kk '-r1.118' '-r1.119' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_assist.cpp,v' 2>/dev/null --- as_assist.cpp 2004/05/27 21:48:40 1.118 +++ as_assist.cpp 2004/08/20 17:47:07 1.119 @@ -932,12 +932,12 @@ this->updSizes(TITRAQ_IDXALLCTRLS, -1, -1); // Validate data just as it is being entered - connect(m_pDateedit, SIGNAL(valueChanged(const QDate &)), SLOT(validateData(void))); - connect(m_pStarttime, SIGNAL(valueChanged(const QTime &)), SLOT(validateData(void))); - connect(m_pEndtime, SIGNAL(valueChanged(const QTime &)), SLOT(validateData(void))); - connect(m_pAmount, SIGNAL(valueChanged(const QTime &)), SLOT(validateData(void))); - connect(m_pTasks, SIGNAL(textChanged(const QString &)), SLOT(validateData(void))); - connect(m_pRemark, SIGNAL(textChanged(const QString &)), SLOT(validateData(void))); + connect(m_pDateedit, SIGNAL(valueChanged(const QDate &)), SLOT(validateRow(void))); + connect(m_pStarttime, SIGNAL(valueChanged(const QTime &)), SLOT(validateRow(void))); + connect(m_pEndtime, SIGNAL(valueChanged(const QTime &)), SLOT(validateRow(void))); + connect(m_pAmount, SIGNAL(valueChanged(const QTime &)), SLOT(validateRow(void))); + connect(m_pTasks, SIGNAL(textChanged(const QString &)), SLOT(validateRow(void))); + connect(m_pRemark, SIGNAL(textChanged(const QString &)), SLOT(validateRow(void))); // Signals sent between table cells and corresponding edit control widgets connect(m_pLineedit, SIGNAL(textChanged(const QString &)), SLOT(updateLine(const QString &))); @@ -1083,7 +1083,7 @@ try { this->setFilename(qApp->argv()[nIter]); // Store inital filename Initial.setName(*this->getFilename()); // Initial file to load - if (Initial.exists(*getFilename())) { + if (Initial.exists(*getFilename()) && validateData(Initial)) { this->loadData(Initial); // Pass to helper method enableIface(true); // Turn on the lights m_pStatbar->message(trUtf8("Loaded document ") + *this->getFilename()); Index: ossp-pkg/as/as-gui/as_const.h RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_const.h,v rcsdiff -q -kk '-r1.64' '-r1.65' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_const.h,v' 2>/dev/null --- as_const.h 2004/05/27 21:48:40 1.64 +++ as_const.h 2004/08/20 17:47:07 1.65 @@ -216,6 +216,8 @@ #define TITRAQ_INCOMPATDATA "Error: incompatible data format." #define TITRAQ_INVALIDDATA "Error: invalid data format." #define TITRAQ_SAVECANCELLED "Warning: save operation failed, because the user cancelled." +#define TITRAQ_READPFILFAIL "Could not open personal data file for reading." +#define TITRAQ_READAFILFAIL "Could not open account file at %1 for reading." // Indexes of table columns #define TITRAQ_IDXALLCTRLS -1 Index: ossp-pkg/as/as-gui/as_dataop.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_dataop.cpp,v rcsdiff -q -kk '-r1.54' '-r1.55' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_dataop.cpp,v' 2>/dev/null --- as_dataop.cpp 2004/05/27 21:48:41 1.54 +++ as_dataop.cpp 2004/08/20 17:47:07 1.55 @@ -65,8 +65,11 @@ this->loadAccounts(Account); // Pass off to do the real work } else { - if (!Fileobj.open(IO_ReadOnly)) // Try to open file - throw Genexcept("Could not open account file for reading."); + if (!Fileobj.open(IO_ReadOnly)) { // Try to open file + QString Readerrstr; + Readerrstr = trUtf8(TITRAQ_READAFILFAIL).arg(Fileobj.name()); + throw Genexcept(Readerrstr.ascii()); + } else Fileobj.flush(); // Begin processing file cleanly QTextStream Account(&Fileobj); // Convert data to stream @@ -155,7 +158,7 @@ } else { if (!Fileobj.open(IO_ReadOnly)) // Try to open file - throw Genexcept("Could not open personal data file for reading."); + throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); else Fileobj.flush(); // Begin processing file cleanly QTextStream Asentry(&Fileobj); // Convert data to stream @@ -186,31 +189,6 @@ Line = QString(""); } - // Ensure that the right data version pattern precedes the data - QString Datapattern = QString(TITRAQ_DATAPATTERN); - if (!Line.startsWith(Datapattern)) { // Incompatible data format - QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, - TITRAQ_NOPATTERNFOUND + QString(TITRAQ_DATAPATTERN) + TITRAQ_WASNOTFOUNDIN, - QMessageBox::Critical, QMessageBox::Ok | QMessageBox::Escape, - QMessageBox::NoButton, QMessageBox::NoButton); - Problema.exec(); // Give the user the bad news - throw Genexcept(TITRAQ_INVALIDDATA); - } - else if (Line.section(Datapattern, 1).section('.', 0, 0).toInt() != TITRAQ_DATAVERSIONMAJ) { - QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, - TITRAQ_BADVERSIONMAJ, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, - QMessageBox::NoButton, QMessageBox::NoButton); - Problema.exec(); // Give the user the bad news - throw Genexcept(TITRAQ_INCOMPATDATA); - } - else if (Line.section(Datapattern, 1).section('.', 1, 1).toInt() > TITRAQ_DATAVERSIONMIN) { - QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, - TITRAQ_BADVERSIONMIN, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, - QMessageBox::NoButton, QMessageBox::NoButton); - Problema.exec(); // Give the user the bad news - throw Genexcept(TITRAQ_INCOMPATDATA); - } - // Strip out extra line feeds after reading the data symbol Line = QString(""); // Reset our line while (Line.isEmpty() && !Tstream.atEnd()) { @@ -391,7 +369,7 @@ } else { if (!Fileobj.open(IO_WriteOnly)) // Try to open file - throw Genexcept("Could not open personal data file for writing."); + throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); QTextStream Asentry(&Fileobj); // Convert data to stream this->saveData(Asentry); // Pass off to do the real work Fileobj.close(); // Finish fileop by closing @@ -468,6 +446,74 @@ } // +// Convenience method to validate AS data in a file +// +const bool Titraqform::validateData(QFile &Filin) const +{ + QString Firstline; // Will contain the first line of text + bool bRet = false; // Set the initial return value + + if (Filin.isOpen()) { // Check open state of file + Filin.flush(); // Not sure if this is needed + Filin.reset(); // Set the file index position to 0 + Filin.readLine(Firstline, QString(TITRAQ_DATAPATTERN).length() + 2L); + } + else { + if (!Filin.open(IO_ReadOnly)) // Try to open file + throw Genexcept(trUtf8(TITRAQ_READPFILFAIL)); + else { // File is now open + Filin.readLine(Firstline, QString(TITRAQ_DATAPATTERN).length() + 2L); + Filin.close(); // Remember to close + } + } + + try { // Pass off to worker method + bRet = this->validateData(Firstline); + } + catch (Genexcept &) { + throw; // Rethrow onwards + } + return bRet; +} + +// +// Validate the AS data pattern in a line +// +const bool Titraqform::validateData(QString &Linin) const +{ + bool bRet = false; // Initial return value + + // Ensure that the right data version pattern precedes the data + QString Datapattern = QString(TITRAQ_DATAPATTERN); + if (!Linin.startsWith(Datapattern)) { // Incompatible data format + QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, + TITRAQ_NOPATTERNFOUND + QString(TITRAQ_DATAPATTERN) + TITRAQ_WASNOTFOUNDIN, + QMessageBox::Critical, QMessageBox::Ok | QMessageBox::Escape, + QMessageBox::NoButton, QMessageBox::NoButton); + Problema.exec(); // Give the user the bad news + throw Genexcept(TITRAQ_INVALIDDATA); + } + else if (Linin.section(Datapattern, 1).section('.', 0, 0).toInt() != TITRAQ_DATAVERSIONMAJ) { + QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, + TITRAQ_BADVERSIONMAJ, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, + QMessageBox::NoButton, QMessageBox::NoButton); + Problema.exec(); // Give the user the bad news + throw Genexcept(TITRAQ_INCOMPATDATA); + } + else if (Linin.section(Datapattern, 1).section('.', 1, 1).toInt() > TITRAQ_DATAVERSIONMIN) { + QMessageBox Problema(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short, + TITRAQ_BADVERSIONMIN, QMessageBox::Warning, QMessageBox::Ok | QMessageBox::Escape, + QMessageBox::NoButton, QMessageBox::NoButton); + Problema.exec(); // Give the user the bad news + throw Genexcept(TITRAQ_INCOMPATDATA); + } + else + bRet = true; + + return bRet; // Not reached in case of failure +} + +// // Get a whole row of data // const QString Titraqform::getRowdata(void) const Index: ossp-pkg/as/as-gui/as_gui.h RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_gui.h,v rcsdiff -q -kk '-r1.82' '-r1.83' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_gui.h,v' 2>/dev/null --- as_gui.h 2004/05/27 22:02:29 1.82 +++ as_gui.h 2004/08/20 17:47:07 1.83 @@ -228,8 +228,8 @@ void onClick(int, int, int, const QPoint &); // Table was clicked void inplaceEdit(int, int, int, const QPoint &); // Enter in place edit mode void updEdit(int, int nCol = 0); // Update edit controls - void validateData(void); // Validate current row of matrix data - void validateData(int, int); // Validate specified row of matrix data + void validateRow(void); // Validate current row of matrix + void validateRow(int, int); // Validate specified row of matrix void updSizes(int, int, int); // Update edit sizes void calcCrc(void); // Calculate CRC of current row void calcCrc(int, int); // Calculate CRC of specified row @@ -318,6 +318,8 @@ void loadData(QTextStream &); // Load personal data from stream void saveData(QFile &); // Save accounting data to file void saveData(QTextStream &); // Save accounting data to stream + const bool validateData(QFile &) const; // Validate personal data in file + const bool validateData(QString &) const; // Validate personal data from string }; #endif // AS_GUI_MWIN_H Index: ossp-pkg/as/as-gui/as_slot.cpp RCS File: /v/ossp/cvs/ossp-pkg/as/as-gui/as_slot.cpp,v rcsdiff -q -kk '-r1.143' '-r1.144' -u '/v/ossp/cvs/ossp-pkg/as/as-gui/as_slot.cpp,v' 2>/dev/null --- as_slot.cpp 2004/08/13 12:36:03 1.143 +++ as_slot.cpp 2004/08/20 17:47:07 1.144 @@ -133,7 +133,7 @@ // Do basic data validation to warn against missing fields for (int nIter = 0; nIter < nRows; nIter++) - this->validateData(m_pMaintable->currentRow() + nIter, 0); + this->validateRow(m_pMaintable->currentRow() + nIter, 0); m_pStatbar->message(QString::number(nRows) + trUtf8(" rows pasted"), 4000); updEdit(m_pMaintable->currentRow()); // Reflect in the update controls @@ -332,7 +332,7 @@ // Sweep through matrix validating linewise // data and updating line numbers for all rows while (nIter < nRows) { - this->validateData(nIter, 0); + this->validateRow(nIter, 0); m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter).rightJustify(4, QChar('0'))); nIter++; } @@ -430,19 +430,21 @@ // We might have a filename to work on, so do something with it if (!Filestring.isEmpty()) { - setFilename(Filestring); // Set the new file name - m_pMaintable->setNumRows(0); // Clear out old data - m_pMaintable->setDirty(false); // Reset dirty flag - QFile Filetemp(Filestring); // File to load + QFile Filetemp(Filestring); // File to load try { - loadData(Filetemp); // Pass to helper method - this->setCaption(Filestring); // Caption in the titlebar - m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); - this->enableIface(true); // Turn on the lights + if (Filetemp.exists() && validateData(Filetemp)) { // Be extra sure + setFilename(Filestring); // Set the new file name + m_pMaintable->setNumRows(0); // Clear out old data + m_pMaintable->setDirty(false); // Reset dirty flag + loadData(Filetemp); // Pass to helper method + this->setCaption(Filestring); // Caption in the titlebar + m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); + this->enableIface(true); // Turn on the lights + this->setOpen(true); // Indicate doc is open + } } catch (Genexcept& Genex) { // Crap, we failed m_pStatbar->message(trUtf8("Loading failed"), 4000); - this->setOpen(false); Genex.reportErr(); return; } @@ -947,17 +949,17 @@ } // -// Validate current row of matrix data +// Validate current row of the matrix // -void Titraqform::validateData(void) +void Titraqform::validateRow(void) { - this->validateData(-1, -1); + this->validateRow(-1, -1); } // -// Validate specified row of matrix data +// Validate specified row of the matrix // -void Titraqform::validateData(int nRow, int nCol) +void Titraqform::validateRow(int nRow, int nCol) { int nRealrow = -1;