OSSP CVS Repository

ossp - Difference in ossp-pkg/as/as-gui/as_dataop.cpp versions 1.54 and 1.55
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/as/as-gui/as_dataop.cpp 1.54 -> 1.55

--- 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

CVSTrac 2.0.1