OSSP CVS Repository

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

ossp-pkg/as/as-gui/as_slot.cpp 1.84 -> 1.85

--- as_slot.cpp  2003/01/23 18:04:45     1.84
+++ as_slot.cpp  2003/01/24 16:32:18     1.85
@@ -146,14 +146,16 @@
             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXUSER, m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER));
             pGuid->genId();
             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXGUID, pGuid->getString());
-            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXCRC, "0");
-            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXREV, "0");
+            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXCRC, "0"); // 0 = invalid entry
+            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXREV, "0"); // Entry not revised
             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXDATE, QDate::currentDate().toString("yyyy.MM.dd"));
             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXSTART, "00:00");
             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXFINISH, "00:00");
             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXAMOUNT, "00:00");
 //            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXTASK, "/");
 //            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXREMARK, "Remark");
+            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXCRC, "1"); // 0 = invalid entry
+            this->calcCrc(Select.topRow() + nIter, -1);
         }
     }
     else { // Special case on last row add downwards
@@ -177,6 +179,7 @@
             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXAMOUNT, "00:00");
 //            m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXTASK, "/");
 //            m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXREMARK, "Remark");
+            this->calcCrc(Select.bottomRow() + nIter, -1);
         }
     }
 
@@ -575,6 +578,54 @@
 }
 
 //
+// Convenience member calculates CRC for current row
+//
+void Titraqform::calcCrc(void)
+{
+    this->calcCrc(-1, -1);
+}
+
+//
+// Calculates CRC for the specified row, fires when data is changed
+//
+void Titraqform::calcCrc(int nRow, int nCol)
+{
+    if (nCol != TITRAQ_IDXSTATUS && nCol != TITRAQ_IDXLINE \
+                                 && m_pMaintable->numRows() > 0) {
+        Q_UINT16 Valcrc, Testcrc;
+        QString Wholerow;
+        int nRealrow = -1;
+//        int nNewrev = -1;
+
+        // Build the data that will be used in testing CRC calculation
+        nRealrow = (nRow >= 0) ? nRow : m_pMaintable->currentRow();
+        Wholerow = m_pMaintable->text(nRealrow, TITRAQ_IDXUSER);
+        for (int nIter = TITRAQ_IDXUSER + 1; nIter < TITRAQ_IDXTAIL; nIter++)
+            if (nIter != TITRAQ_IDXCRC) // Don't checksum the checksum!
+                Wholerow += ' ' + m_pMaintable->text(nRealrow, nIter);
+
+        // Update the checksum and revision only if necessary
+        Testcrc = qChecksum(Wholerow.ascii(), Wholerow.length());
+        if (Testcrc != m_pMaintable->text(nRealrow, TITRAQ_IDXCRC).toUInt()) {
+
+//            // Bump the revision number of our entry to control conflicts
+//            nNewrev = m_pMaintable->text(nRealrow, TITRAQ_IDXREV).toInt() + 1;
+//            m_pMaintable->setText(nRealrow, TITRAQ_IDXREV, QString::number(nNewrev));
+
+            // Build the data that will be used in setting CRC calculation
+            Wholerow = m_pMaintable->text(nRealrow, TITRAQ_IDXUSER);
+            for (int nIter = TITRAQ_IDXUSER + 1; nIter < TITRAQ_IDXTAIL; nIter++)
+                if (nIter != TITRAQ_IDXCRC) // Don't checksum the checksum!
+                    Wholerow += ' ' + m_pMaintable->text(nRealrow, nIter);
+
+            // Finally set the checksum to its new value
+            Valcrc = qChecksum(Wholerow.ascii(), Wholerow.length());
+            m_pMaintable->setText(nRealrow, TITRAQ_IDXCRC, QString::number(Valcrc));
+        }
+    }
+}
+
+//
 // Update the edit controls contents
 //
 void Titraqform::updEdit(int nRow, int nCol)
@@ -629,43 +680,54 @@
 }
 
 //
-// Validate one row of matrix data
+// Validate current row of matrix data
+//
+void Titraqform::validateData(void)
+{
+    this->validateData(-1, -1);
+}
+
+//
+// Validate specified row of matrix data
 //
 void Titraqform::validateData(int nRow, int nCol)
 {
+    int nRealrow = -1;
+
     if (!m_pMaintable->numRows() > 0) { // If no rows exist then short circuit
         m_pStatbar->message(trUtf8("Timesheet contains no data"), 4000);
         return;
     }
 
-    QString Statis = m_pMaintable->text(nRow, TITRAQ_IDXSTATUS); // Get text
+    nRealrow = (nRow >= 0) ? nRow : m_pMaintable->currentRow();
+    QString Statis = m_pMaintable->text(nRealrow, TITRAQ_IDXSTATUS); // Get text
 
     // Quick review of data validity, and set pixmaps accordingly
-    if (m_pMaintable->text(nRow, TITRAQ_IDXUSER).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXGUID).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXCRC).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXREV).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXDATE).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXSTART).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXFINISH).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXAMOUNT).isEmpty() ||
-        m_pMaintable->text(nRow, TITRAQ_IDXTASK).isEmpty())
+    if (m_pMaintable->text(nRealrow, TITRAQ_IDXUSER).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXGUID).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXCRC).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXREV).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXDATE).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXSTART).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXFINISH).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXAMOUNT).isEmpty() ||
+        m_pMaintable->text(nRealrow, TITRAQ_IDXTASK).isEmpty())
     { // No K&R style to show where actual code begins
         if (Statis.startsWith(QString("W"))) { // Conditionally set pixmap to avoid overhead
 // FIXME: Next line commented out, and I see that this algorythm needs help
-//            m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRow, TITRAQ_IDXSTATUS));
+//            m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS));
         }
         else if (!Statis.startsWith(QString("E"))) { // Conditionally set pixmap to avoid overhead
-            m_pMaintable->setText(nRow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'E'));
-            m_pMaintable->setPixmap(nRow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStaterror_xpm));
-            m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRow, TITRAQ_IDXSTATUS));
+            m_pMaintable->setText(nRealrow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'E'));
+            m_pMaintable->setPixmap(nRealrow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStaterror_xpm));
+            m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS));
         }
     }
     else {
         if (!Statis.startsWith(QString("O"))) { // Conditionally set pixmap to avoid overhead
-            m_pMaintable->setText(nRow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'O'));
-            m_pMaintable->setPixmap(nRow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatokay_xpm));
-            m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRow, TITRAQ_IDXSTATUS));
+            m_pMaintable->setText(nRealrow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'O'));
+            m_pMaintable->setPixmap(nRealrow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatokay_xpm));
+            m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS));
         }
     }
 }
@@ -1264,8 +1326,8 @@
         // A quasi diff summary to transmit to the server
         QString Syncthis;
         int nRow = m_pMaintable->currentRow();
-        Syncthis += m_pMaintable->text(nRow, 0);
-        for (int nIter = 1; nIter < TITRAQ_IDXTAIL; nIter++)
+        Syncthis += m_pMaintable->text(nRow, TITRAQ_IDXUSER);
+        for (int nIter = TITRAQ_IDXUSER + 1; nIter < TITRAQ_IDXTAIL; nIter++)
             Syncthis += ' ' + m_pMaintable->text(nRow, nIter);
 
         Clistr = Syncthis;                          // Build RPC parameter

CVSTrac 2.0.1