OSSP CVS Repository

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

ossp-pkg/as/as-gui/as_slot.cpp 1.95 -> 1.96

--- as_slot.cpp  2003/01/30 20:26:03     1.95
+++ as_slot.cpp  2003/01/30 22:02:41     1.96
@@ -303,7 +303,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("");
+    this->setFilename(QString(""));
     this->addEntry(1);                  // Default new op adds a row
     m_pMaintable->setDirty(false);      // Start out clean
 }
@@ -390,12 +390,18 @@
     QTextStream Streamevents, Streambak;
 
     try {
-        Fname = QString(*this->getFilename());
+        Fname = *this->getFilename();
 
-        // First time saves are really just saveAs in disguise
+        // First time saves are really just saveName in disguise
         if (Fname.isEmpty()) {
-            this->saveAs();
-            return;
+            try {
+                this->saveName();       // Try to 'save as'
+                return;                 // and short circuit
+            }
+            catch (Genexcept& Genex) {
+                Genex.reportErr();      // Report the error
+                return;                 // and short circuit
+            }
         }
 
         Filevents.setName(Fname); // Construct a file to back up and write
@@ -459,9 +465,55 @@
             this->saveFile();               // Finish by calling the save action
         }
     }
-    else {
+    else
         // User did not select a valid file and push okay button
         m_pStatbar->message(trUtf8("Saving aborted"), 4000);
+}
+
+//
+// Implicitly serialize current state to a selected file
+// The main difference with saveAs is that this uses exceptions
+//
+void Titraqform::saveName(void)
+{
+    int nResult = 0; // For checking user's answer
+
+    // 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);
+
+    nResult = 1;            // We loop on this dialog only if an indecisive user
+    while (nResult > 0) {   // is hesitant to overwrite a file over and over again
+        QString Filestring = QFileDialog::getSaveFileName(Openas, trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false);
+        if (!Filestring.isEmpty()) {
+            if (QFile::exists(Filestring)) {
+                nResult = QMessageBox::warning(this, trUtf8(TITRAQ_APPTITLE),
+                          trUtf8(TITRAQ_OVERWRITE), trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1);
+                switch (nResult) {
+                case 0: // Overwrite contents
+                    this->setFilename(Filestring);
+                    this->saveFile();
+                    break;
+                case 1: // Don't overwrite
+                default:
+                    break;
+                }
+            }
+            else {
+                QString Extension = TITRAQ_FEXTENSION;  // Logic to handle
+                if (!Filestring.endsWith(Extension))    // AS file extension
+                    Filestring += Extension;            // insertion
+                this->setFilename(Filestring);  // Set filename of object first
+                nResult = 0;                    // Reset our loop control
+                this->saveFile();               // Finish by calling the save action
+            }
+        }
+        else {
+            // User did not select a valid file and push okay button
+            m_pStatbar->message(trUtf8("Saving aborted"), 4000);
+            throw Genexcept(TITRAQ_SAVECANCELLED);
+        }
     }
 }
 
@@ -496,9 +548,17 @@
     }
 
     // Fall through to implicit close code
-    this->enableIface(false);   // Turn off the lights
-    this->setOpen(false);       // Set doc state to closed
-    pClosit->ignore();          // Finish off by not closing
+    this->setCaption(TITRAQ_APPTITLE);
+    try { // There might be problems, so wrap these last ops with error handling
+        if (this->isOpen())
+            m_pStatbar->message(trUtf8("Closed document ") + *this->getFilename(), 4000);
+        this->setOpen(false);       // Set doc state to closed
+        this->enableIface(false);   // Turn off the lights
+    }
+    catch (Genexcept& Genex) {
+        Genex.reportErr();
+    }
+    pClosit->ignore();              // Finish off by not closing
 }
 
 //

CVSTrac 2.0.1