OSSP CVS Repository

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

ossp-pkg/as/as-gui/as_slot.cpp 1.100 -> 1.101

--- as_slot.cpp  2003/01/31 14:03:03     1.100
+++ as_slot.cpp  2003/01/31 18:03:36     1.101
@@ -338,7 +338,7 @@
     m_pMaintable->setNumRows(0);        // Remove all data in table
     this->setCaption(trUtf8("No file name"));
     m_pStatbar->message(trUtf8("New document"), 4000);
-    this->setFilename(QString(""));
+    this->setOpen();                    // Signal an open doc state
     this->addEntry(1);                  // Default new op adds a row
     m_pMaintable->setDirty(false);      // Start out clean
 }
@@ -350,69 +350,69 @@
 {
     int nResult = 0;    // Holds return value from save first messagebox
 
-    // Make sure we correctly get the name of the default file to open
-    QString Openas = m_pPrefs->getString(TITRAQ_PREFASFILE, TITRAQ_DEFASFILE);
-    if (Openas.startsWith(TITRAQ_HOMEDIRTOK))
-        Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1);
-
-    QString Filestring = QFileDialog::getOpenFileName(Openas, trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to open"), NULL, false);
-
-    if (!Filestring.isEmpty()) {
-        QFile Filetemp(Filestring); // File to load
-        // Check modification state of current data
-        if (m_pMaintable->isDirty()) {
-            nResult = QMessageBox::information(this, trUtf8(TITRAQ_APPTITLE),
-                      trUtf8(TITRAQ_SAVEFIRST), trUtf8("&Save"),
-                      trUtf8("&Discard"), trUtf8("Cancel"), 0, 2);
-
-            switch (nResult) {
-            case 0: // Save first
-                this->saveFile();               // Save changes first
-                setFilename(Filestring);        // Set the new file name
-                m_pMaintable->setNumRows(0);    // Clear out old data
-                try {
-                    loadData(Filetemp);         // Pass to helper method
-                }
-                catch (Genexcept& Genex) {
-                    Genex.reportErr();
-                    return;
-                }
-                break;
-            case 1: // Don't save first but do load
-                setFilename(Filestring);        // Set the new file name
-                m_pMaintable->setNumRows(0);    // Clear out old data
-                try {
-                    loadData(Filetemp);         // Pass to helper method
-                }
-                catch (Genexcept& Genex) {
-                    Genex.reportErr();
-                    return;
-                }
-                break;
-            case 2: // Don't do a load timesheet
-            default:
-                break;
-            }
+//
+// This block will guide the user to saving the contents of the timesheet
+// before losing them in an open operation. The question and dialog box will
+// not be raised if no open timesheet exists or if it was just serialized.
+//
+    if (m_pMaintable->isDirty()) { // Check modification state
+        nResult = QMessageBox::information(this, trUtf8(TITRAQ_APPTITLE),
+                  trUtf8(TITRAQ_SAVEFIRST), trUtf8("&Save"),
+                  trUtf8("&Discard"), trUtf8("Cancel"), 0, 2);
+
+        switch (nResult) {
+        case 0: // Save first
+            this->saveFile(); // Save changes first
+            break;
+        case 1: // Don't save first but do load
+            break;
+        case 2: // Don't do a load timesheet
+        default:
+            m_pStatbar->message(trUtf8("Loading aborted"), 4000);
+            return;
+            break;
         }
-        else {
+    }
+
+//
+// This block ensures that conditions of first block logic were met if
+// applicable. If so, the user gives a file name to open or cancels the
+// operation. The corresponding file will be opened, and if this is
+// unsuccessful then the post state is exactly the same as the pre state.
+//
+    if (!m_pMaintable->isDirty() || nResult == 1) { // Check modification state
+        // Make sure we correctly get the name of the default file to open
+        QString Openas = m_pPrefs->getString(TITRAQ_PREFASFILE, TITRAQ_DEFASFILE);
+        if (Openas.startsWith(TITRAQ_HOMEDIRTOK))
+            Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1);
+
+        // This dialog asks which file the user wants to open
+        QString Filestring = QFileDialog::getOpenFileName(Openas,
+            trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"),
+            this, trUtf8("ChooserDialog"), trUtf8("Choose a file to open"), NULL, false);
+
+        // 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
             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
             }
-            catch (Genexcept& Genex) {
+            catch (Genexcept& Genex) { // Crap, we failed
+                m_pStatbar->message(trUtf8("Loading failed"), 4000);
+                this->setOpen(false);
                 Genex.reportErr();
                 return;
             }
         }
-
-        // Fall through to implicit open code
-        this->setCaption(Filestring);
-        m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
-        this->enableIface(true);    // Turn on the lights
+        else // An empty filename returning from the file dialog means cancel
+            m_pStatbar->message(trUtf8("Loading aborted"), 4000);
     }
-    else
-        m_pStatbar->message(trUtf8("Loading aborted"), 4000);
 }
 
 //

CVSTrac 2.0.1