OSSP CVS Repository

ossp - Check-in [2842]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2842
Date: 2002-Nov-18 23:13:56 (local)
2002-Nov-18 22:13:56 (UTC)
User:ms
Branch:
Comment: Break the monolithic pig-constructor into smaller pigs.
Tickets:
Inspections:
Files:
ossp-pkg/as/as-gui/as_gui.cpp      1.11 -> 1.12     361 inserted, 222 deleted
ossp-pkg/as/as-gui/as_gui.h      1.8 -> 1.9     25 inserted, 5 deleted
ossp-pkg/titraq/titraq.cpp      1.11 -> 1.12     361 inserted, 222 deleted
ossp-pkg/titraq/titraq.h      1.8 -> 1.9     25 inserted, 5 deleted

ossp-pkg/as/as-gui/as_gui.cpp 1.11 -> 1.12

--- as_gui.cpp   2002/11/14 22:26:30     1.11
+++ as_gui.cpp   2002/11/18 22:13:56     1.12
@@ -1,4 +1,4 @@
-// System interface
+// Qt headers
 #include <qtooltip.h>
 #include <qwhatsthis.h>
 #include <qdatetimeedit.h>
@@ -9,13 +9,19 @@
 #include <qfile.h>
 #include <qfiledialog.h>
 
+// System headers
+#include <iostream>
+
 // User interface
-#include "titraq.h"         // Main classes
-#include "generic.h"        // Generic classes
-#include "gfx/ossplogo.xpm" // OSSP logo: static const char *s_kpcOssplogo_xpm[]
-#include "gfx/filenew.xpm"  // static const char *s_kpcFilenew_xpm[]
-#include "gfx/fileopen.xpm" // static const char *s_kpcFileopen_xpm[]
-#include "gfx/filesave.xpm" // static const char *s_kpcFilesave_xpm[]
+#include "titraq.h"             // Main classes
+#include "titrex.h"             // Exception classes
+#include "generic.h"            // Generic classes
+#include "gfx/ossplogo.xpm"     // static const char *s_kpcOssplogo_xpm[]
+#include "gfx/qtlogo.xpm"       // static const char *s_kpcQtlogo_xpm[]
+#include "gfx/filenew.xpm"      // static const char *s_kpcFilenew_xpm[]
+#include "gfx/fileopen.xpm"     // static const char *s_kpcFileopen_xpm[]
+#include "gfx/filesave.xpm"     // static const char *s_kpcFilesave_xpm[]
+#include "gfx/whatsthis.xpm"    // static const char *s_kpcWhatsthis_xpm[]
 
 // Overload init for custom initialization of the app
 void Titraqform::init(void)
@@ -36,33 +42,290 @@
 Titraqform::Titraqform(QWidget *pParent,  const char *kszName, WFlags Flags) :
     QMainWindow(pParent, kszName, Flags)
 {
-//    // Abstract main widget building
-//    setupMenubar();
-//    setupFiletools();
-//    setupStatusbar();
-//    setupCentralwidget();
+    // Early member initialization
+    m_bDirt = false;
+    m_szFilename = new QString();
+
+    // Initialize icon images
+    m_pOsspicon = new QImage(s_kpcOssplogo_xpm);
+    m_pQticon = new QImage(s_kpcQtlogo_xpm);
+    m_pNewicon = new QImage(s_kpcFilenew_xpm);
+    m_pOpenicon = new QImage(s_kpcFileopen_xpm);
+    m_pSaveicon = new QImage(s_kpcFilesave_xpm);
+    m_pWhatsicon = new QImage(s_kpcWhatsthis_xpm);
 
     // Initial widget manipulations
     if (!kszName)
         setName(trUtf8("Titraqform"));
     resize(600, 480);
-    m_pMenubar = menuBar();     // Setup the menu bar
-    m_pStatbar = statusBar();   // Setup the status bar
     setCaption("OSSP Titraq");
 
 //    // Lock down window size
 //    setSizePolicy(QSizePolicy((QSizePolicy::SizeType)0,
 //        (QSizePolicy::SizeType)0, 0, 0, sizePolicy().hasHeightForWidth()));
 
-    // Early member initialization
-    m_bDirt = false;
-    m_szFilename = new QString();
+    // Abstractly build main widgets
+    try {
+        setupActions();
+        setupMenubar();
+        setupFiletools();
+        setupStatusbar();
+        setupCentralwidget();
+        setupTable();
+        setupOutput();
+        setupButtons();
+    }
+    catch (Genexcept& Genex) {
+        Genex.reportErr();
+        exit(1);
+    }
+
+    init(); // Initialize signal and slot connections
+    m_pStatbar->message(trUtf8("Ready"));   // Signal a ready condition
+}
+
+//
+// Add a blank row entry to the current data window
+//
+void Titraqform::addEntry(void)
+{
+    Prototype Unimp;
+    Unimp.doMbox();
+//    if (!pTable->text().isEmpty()) {
+//        QTableRow *pRow = new QTableRow;
+//        pRow->setText(0, NULL);
+//        pRow->setText(1, NULL);
+//        pRow->setText(2, NULL);
+//        pRow->setText(3, NULL);
+//    }
+}
+
+//
+// Choose a file using a handy file dialog
+//
+void Titraqform::delEntry(void)
+{
+    Prototype Unimp;
+    Unimp.doMbox();
+}
+
+//
+// Write current data to a meta device
+//
+void Titraqform::writeEntry(void)
+{
+    Prototype Unimp;
+    Unimp.doMbox();
+}
+
+//
+// Make and display a new document window
+//
+void Titraqform::newDoc(void)
+{
+    Prototype Unimp;
+    Unimp.doMbox();
+//    Titraqform *pNewform = new Titraqform;
+//    pNewform->show();
+}
+
+//
+// Choose a file using a handy file dialog
+//
+void Titraqform::choose(void)
+{
+    QString Filestring = QFileDialog::getOpenFileName(QString::null, QString::null, this);
+    if (!Filestring.isEmpty())
+        load(Filestring);
+    else
+        m_pStatbar->message(trUtf8("Loading aborted"), 4000);
+}
+
+//
+// Load accounting data into main window
+//
+void Titraqform::load(const QString &Filestring)
+{
+    QFile Filetemp(Filestring);         // File to load
+
+    if (!Filetemp.open(IO_ReadOnly))    // Need a wrapped exception here
+        return;
+
+    QTextStream Textstream(&Filetemp);  // Convert the file contents to a stream
+    m_pStatus->setText(Textstream.read());
+    m_pStatus->setEdited(false);
+    setCaption(Filestring);
+    m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
+}
+
+//
+// Serialize current state to the current file
+//
+void Titraqform::save(void)
+{
+    // First time saves are really just saveAs in disguise
+    if (m_szFilename->isEmpty()) {
+        saveAs();
+        return;
+    }
+
+    // Try to read the status text, and write it to a file
+    QString Statustext = m_pStatus->text();
+    QFile Filetemp(*m_szFilename);
+    if (!Filetemp.open(IO_WriteOnly)) {
+        m_pStatbar->message(QString(trUtf8("Could not write to %1")).arg(*m_szFilename), 4000);
+        return;
+    }
+
+    // Serialize file contents and write to text line
+    QTextStream Filestream(&Filetemp);
+    Filestream << Statustext;
+    Filetemp.close();
+
+    // Reset the text line, and give output to main window
+    m_pStatus->setEdited(FALSE);
+    setCaption(*m_szFilename);
+    m_pStatbar->message(QString(trUtf8("File %1 saved")).arg(*m_szFilename), 4000);
+    m_bDirt = false;    // Set the clean state to allow a close operation
+}
+
+//
+// Serialize current state to a selected file
+//
+void Titraqform::saveAs(void)
+{
+    // First get the selected file name to save to
+    QString Filestring = QFileDialog::getSaveFileName(QString::null, QString::null, this);
+    if (!Filestring.isEmpty()) {
+        *m_szFilename = Filestring;
+        m_pStatus->setText(*m_szFilename);
+        save(); // Finish off by calling the save action
+    }
+    else {
+        // User did not select a valid file and push okay button
+        m_pStatbar->message(trUtf8("Saving aborted"), 4000);
+    }
+}
+
+//
+// Close current document, displaying in main window
+//
+void Titraqform::closeEvent(QCloseEvent *pClosit)
+{
+    // Check modification state of current data
+    if (!this->isDirty()) {
+        pClosit->accept();
+        return;
+    }
+
+    // Ask user to acknowlege a possibly data-damaging close event
+    switch(QMessageBox::information(this, "OSSP titraq",
+        trUtf8("The document has been\nchanged since the last save.")),
+        trUtf8("Save Now"), trUtf8("Cancel"), trUtf8("Leave Anyway"), 0, 1) {
+    case 0:
+        save();
+        pClosit->accept();
+        break;
+    case 1:
+        default:    // Just for sanity
+        pClosit->ignore();
+        break;
+    case 2:
+        pClosit->accept();
+        break;
+    }
+}
+
+//
+// Check to see if state has changed since last save
+//
+bool Titraqform::isDirty(void)
+{
+    return m_bDirt;
+}
+
+//
+// Learn more about this program itself
+//
+void Titraqform::about(void)
+{
+    QMessageBox::about(this, "OSSP titraq",
+        trUtf8("OSSP titraq is a time and task-based\n"
+               "accounting system that acts as both a\n"
+               "nwork-like punch card and time tracker."));
+}
+
+//
+// Learn more about the OSSP
+//
+void Titraqform::aboutOSSP(void)
+{
+    QMessageBox::about(this, "OSSP",
+        trUtf8("The open source software project (OSSP) is\n"
+               "a collective effort aimed at implementing\n"
+               "high-quality Unix software components,\n"
+               "ranging from networking, multi-threading\n"
+               "and algorithmic libraries to networking\n"
+               "servers and development tools."));
+}
+
+//
+// Learn more about this program and Qt
+//
+void Titraqform::aboutQt(void)
+{
+    QMessageBox::aboutQt(this, "OSSP titraq");
+}
+
+//
+// Construct the menu bar
+//
+void Titraqform::setupMenubar(void)
+{
+    m_pMenubar = menuBar(); // Grab menu bar owned by QMainWindow
+    if (m_pMenubar == NULL) // Sanity check
+        throw Genexcept("Main window menu bar nonexistant.");
 
     // Make an easter egg ;-)
     QToolTip::add(m_pMenubar, QRect(0, 0, 2, 2), "Easter egg");
 
+    // Construct and populate the file menu with actions
+    QPopupMenu *pFilepopup = new QPopupMenu(this);
+    if (pFilepopup == NULL) // Sanity check
+        throw Genexcept("Main window file popup creation failed.");
+    m_pMenubar->insertItem(trUtf8("&File"), pFilepopup);
+    m_pFilenewact->addTo(pFilepopup);
+    m_pFileopenact->addTo(pFilepopup);
+    pFilepopup->insertSeparator();
+    m_pFilecloseact->addTo(pFilepopup);
+    pFilepopup->insertSeparator();
+    m_pFilesaveact->addTo(pFilepopup);
+    m_pFilesaveasact->addTo(pFilepopup);
+    pFilepopup->insertSeparator();
+    m_pFilequitact->addTo(pFilepopup);
+
+    // Construct and populate the help menu with subitems
+    QPopupMenu *pHelppopup = new QPopupMenu(this);
+    if (pHelppopup == NULL) // Sanity check
+        throw Genexcept("Main window help popup creation failed.");
+    m_pMenubar->insertItem(trUtf8("&Help"), pHelppopup);
+    pHelppopup->insertItem(trUtf8("&About"), this, SLOT(about()), Key_F1);
+    pHelppopup->insertSeparator();
+    pHelppopup->insertItem(QPixmap(*m_pOsspicon), trUtf8("About &OSSP"), this, SLOT(aboutOSSP()));
+    pHelppopup->insertItem(QPixmap(*m_pQticon), trUtf8("About &Qt"), this, SLOT(aboutQt()));
+    pHelppopup->insertSeparator();
+    pHelppopup->insertItem(QPixmap(*m_pWhatsicon), trUtf8("What's &This"), this, SLOT(whatsThis()), SHIFT+Key_F1);
+}
+
+//
+// Construct various actions
+//
+void Titraqform::setupActions(void)
+{
     // File new action
     m_pFilenewact = new QAction(trUtf8("New File"), QPixmap(s_kpcFilenew_xpm), trUtf8("&New"), CTRL+Key_N, this, "New");
+    if (m_pFilenewact == NULL) // Sanity check
+        throw Genexcept("Main window file new action creation failed.");
     connect(m_pFilenewact, SIGNAL(activated()), this, SLOT(newDoc()));
     QMimeSourceFactory::defaultFactory()->setPixmap("filenew", m_pFilenewact->iconSet().pixmap());
     const char *kszFilenewtext = trUtf8("<p><img source=\"filenew\"> "
@@ -73,6 +336,8 @@
 
     // File open action
     m_pFileopenact = new QAction(trUtf8("Open File"), QPixmap(s_kpcFileopen_xpm), trUtf8("&Open"), CTRL+Key_O, this, "Open");
+    if (m_pFileopenact == NULL) // Sanity check
+        throw Genexcept("Main window file open action creation failed.");
     connect(m_pFileopenact, SIGNAL(activated()), this, SLOT(choose()));
     QMimeSourceFactory::defaultFactory()->setPixmap("fileopen", m_pFileopenact->iconSet().pixmap());
     const char *kszFileopentext = trUtf8("<p><img source=\"fileopen\"> "
@@ -83,6 +348,8 @@
 
     // File save current action
     m_pFilesaveact = new QAction(trUtf8("Save File"), QPixmap(s_kpcFilesave_xpm), trUtf8("&Save"), CTRL+Key_S, this, "Save");
+    if (m_pFilesaveact == NULL) // Sanity check
+        throw Genexcept("Main window file save action creation failed.");
     connect(m_pFilesaveact, SIGNAL(activated()), this, SLOT(save()));
     QMimeSourceFactory::defaultFactory()->setPixmap("filesave", m_pFilesaveact->iconSet().pixmap());
     const char *kszFilesavetext = trUtf8("<p><img source=\"filesave\"> "
@@ -94,19 +361,27 @@
 
     // File save selected action
     m_pFilesaveasact = new QAction(trUtf8("Save File As"), trUtf8("Save &as"), 0, this, "SaveAs");
+    if (m_pFilesaveasact == NULL) // Sanity check
+        throw Genexcept("Main window file save as action creation failed.");
     connect(m_pFilesaveasact, SIGNAL(activated()), this, SLOT(saveAs()));
     m_pFilesaveasact->setWhatsThis(kszFilesavetext);
 
     // File close current action
     m_pFilecloseact = new QAction(trUtf8("Close"), trUtf8("&Close"), CTRL+Key_W, this, "Close");
+    if (m_pFilecloseact == NULL) // Sanity check
+        throw Genexcept("Main window file close action creation failed.");
     connect(m_pFilecloseact, SIGNAL(activated()), this, SLOT(close()));
 
     // File quit action
-    m_pFilequitact = new QAction(trUtf8("Quit"), trUtf8("&Quit"), CTRL+Key_Q, this, "Quit");
+    m_pFilequitact = new QAction(trUtf8("Exit"), trUtf8("&Exit"), CTRL+Key_Q, this, "Exit");
+    if (m_pFilequitact == NULL) // Sanity check
+        throw Genexcept("Main window file quit action creation failed.");
     connect(m_pFilequitact, SIGNAL(activated()), qApp, SLOT(quit()));
 
     // Add data row action
     m_pAddrowact = new QAction(trUtf8("Add Row"), QPixmap(s_kpcOssplogo_xpm), trUtf8("Add &row"), 0, this, "Addrow");
+    if (m_pAddrowact == NULL) // Sanity check
+        throw Genexcept("Main window add row action creation failed.");
     connect(m_pAddrowact, SIGNAL(activated()), this, SLOT(addEntry()));
     QMimeSourceFactory::defaultFactory()->setPixmap("ossplogo", m_pAddrowact->iconSet().pixmap());
     const char *kszAddrowtext = trUtf8("<p><img source=\"ossplogo\"> "
@@ -117,6 +392,8 @@
 
     // Delete data row action
     m_pDeleterowact = new QAction(trUtf8("Add Row"), QPixmap(s_kpcOssplogo_xpm), trUtf8("Add &row"), 0, this, "Deleterow");
+    if (m_pDeleterowact == NULL) // Sanity check
+        throw Genexcept("Main window delete row action creation failed.");
     connect(m_pDeleterowact, SIGNAL(activated()), this, SLOT(delEntry()));
     QMimeSourceFactory::defaultFactory()->setPixmap("ossplogo", m_pDeleterowact->iconSet().pixmap());
     const char *kszDeleterowtext = trUtf8("<p><img source=\"ossplogo\"> "
@@ -127,6 +404,8 @@
 
     // Write data action
     m_pWritedataact = new QAction(trUtf8("Add Row"), QPixmap(s_kpcOssplogo_xpm), trUtf8("Add &row"), 0, this, "Writedata");
+    if (m_pWritedataact == NULL) // Sanity check
+        throw Genexcept("Main window write data action creation failed.");
     connect(m_pWritedataact, SIGNAL(activated()), this, SLOT(writeEntry()));
     QMimeSourceFactory::defaultFactory()->setPixmap("ossplogo", m_pWritedataact->iconSet().pixmap());
     const char *kszWritedatatext = trUtf8("<p><img source=\"ossplogo\"> "
@@ -134,51 +413,69 @@
                                    "You can also select the <b>Write data</b> command "
                                    "from the <b>Accounting</b> menu.</p>");
     m_pWritedataact->setWhatsThis(kszWritedatatext);
+}
 
-    // Construct and populate the file menu with actions
-    QPopupMenu *pFilepopup = new QPopupMenu(this);
-    m_pMenubar->insertItem(trUtf8("&File"), pFilepopup);
-    m_pFilenewact->addTo(pFilepopup);
-    m_pFileopenact->addTo(pFilepopup);
-    m_pFilesaveact->addTo(pFilepopup);
-    m_pFilesaveasact->addTo(pFilepopup);
-    pFilepopup->insertSeparator();
-    m_pFilecloseact->addTo(pFilepopup);
-    m_pFilequitact->addTo(pFilepopup);
-
-    // Construct and populate the help menu with subitems
-    QPopupMenu *pHelppopup = new QPopupMenu(this);
-    m_pMenubar->insertItem(trUtf8("&Help"), pHelppopup);
-    pHelppopup->insertItem(trUtf8("&About"), this, SLOT(about()), Key_F1);
-    pHelppopup->insertItem(trUtf8("About &Qt"), this, SLOT(aboutQt()));
-    pHelppopup->insertSeparator();
-    pHelppopup->insertItem(trUtf8("What's &This"), this, SLOT(whatsThis()), SHIFT+Key_F1);
-
+//
+// Construct the file tool bar
+//
+void Titraqform::setupFiletools(void)
+{
     // Construct and populate the main tool bar
     m_pToolbar = new QToolBar("Toolfile", this, DockTop);
+    if (m_pToolbar == NULL) // Sanity check
+        throw Genexcept("Main window tool bar creation failed.");
     m_pToolbar->setLabel(trUtf8("File Ops"));
     m_pFilenewact->addTo(m_pToolbar);
     m_pFileopenact->addTo(m_pToolbar);
     m_pFilesaveact->addTo(m_pToolbar);
     QWhatsThis::whatsThisButton(m_pToolbar); // Preconfigured whats this button
+}
 
+//
+// Construct the status bar
+//
+void Titraqform::setupStatusbar(void)
+{
+    m_pStatbar = statusBar();   // Grab status bar owned by QMainWindow
+    if (m_pStatbar == NULL)     // Sanity check
+        throw Genexcept("Main window status bar nonexistant.");
+}
+
+//
+// Construct the central widget
+//
+void Titraqform::setupCentralwidget(void)
+{
     // Create a central frame and associated layout for QMainWindow
     m_pCenframe = new QFrame(this, "Centralframe");
+    if (m_pCenframe == NULL)    // Sanity check
+        throw Genexcept("Main window central frame creation failed.");
     m_pCenframe->setFrameShape(QFrame::StyledPanel);
     m_pCenframe->setFrameShadow(QFrame::Sunken);
     setCentralWidget(m_pCenframe);
 
-    // Layout controls for toolbar, table, buttons, and status line
+    // Layout controls for table, buttons, and status line
     m_pMainlayout = new QVBoxLayout(m_pCenframe, 10, 6, "Mainlayout");  // For layouts
     m_pPackagelayout = new QVBoxLayout(0, 0, 6, "Packagelayout");       // For table
     m_pControllayout = new QHBoxLayout(0, 0, 6, "Controllayout");       // For buttons
 
+    if (!(m_pMainlayout && m_pMainlayout && m_pMainlayout))             // Sanity check
+        throw Genexcept("Main window layout creation failed.");
+
     // Specify ordering of the layouts
     m_pMainlayout->addLayout(m_pPackagelayout);
     m_pMainlayout->addLayout(m_pControllayout);
+}
 
+//
+// Construct the table
+//
+void Titraqform::setupTable(void)
+{
     // The table itself
     m_pMaintable = new QTable(m_pCenframe, "Maintable");
+    if (m_pMaintable == NULL)   // Sanity check
+        throw Genexcept("Main window table creation failed.");
     m_pMaintable->setNumRows(g_knRows);
     m_pMaintable->setNumCols(g_knCols);
     m_pMaintable->setReadOnly(false);                   // Not read only
@@ -200,10 +497,9 @@
     m_pTablehead->setMovingEnabled(true);
 
     // Icon image items
-    m_pIconimage = new QImage(s_kpcOssplogo_xpm);
-    m_pIconpixmap = new QPixmap(m_pIconimage->scaleHeight(m_pMaintable->rowHeight(6)));
+    QPixmap Osspminipix(QPixmap(m_pOsspicon->scaleHeight(m_pMaintable->rowHeight(6))));
     m_pMaintable->setItem(0, 0, new QTableItem(m_pMaintable, QTableItem::Never, "OSSP trac"));
-    m_pMaintable->setPixmap(0, 0, *m_pIconpixmap);
+    m_pMaintable->setPixmap(0, 0, Osspminipix);
 
 //    // Make a generic table item for all rows
 //    for (int i = 1; i < knRows; ++i)
@@ -236,6 +532,8 @@
 
     // Populate the task stringlist
     m_pTaskentries = new QStringList;
+    if (m_pTaskentries == NULL) // Sanity check
+        throw Genexcept("Main window task entries creation failed.");
     *m_pTaskentries << trUtf8("titraq") << trUtf8("opgui") << trUtf8("email") << trUtf8("admin") << trUtf8("pmod") << trUtf8("psod") << trUtf8("meeting") << trUtf8("training");
 
     // Make the combobox items for all rows
@@ -274,9 +572,17 @@
 //    }
 
     m_pPackagelayout->addWidget(m_pMaintable);  // Finally add the damn table
+}
 
+//
+// Construct the bottom output line
+//
+void Titraqform::setupOutput(void)
+{
     // Bottom output line
     m_pStatus = new QLineEdit(m_pCenframe, "Status");
+    if (m_pStatus == NULL)   // Sanity check
+        throw Genexcept("Main window status output creation failed.");
     m_pStatus->setText(trUtf8("Happy birthday to Ralf"));
     m_pStatus->setFrameShape(QLineEdit::LineEditPanel);
     m_pStatus->setFrameShadow(QLineEdit::Sunken);
@@ -291,9 +597,17 @@
                                 " You can also change the data in place, or above "
                                 "from the <b>Accounting table</b>.");
     QWhatsThis::add(m_pStatus, kszStatouttext);
+}
 
+//
+// Construct the buttons
+//
+void Titraqform::setupButtons(void)
+{
     // Tuple push button add
     m_pAddbutton = new QPushButton(m_pCenframe, "AddButton");
+    if (m_pAddbutton == NULL)   // Sanity check
+        throw Genexcept("Main window add button creation failed.");
     m_pAddbutton->setCursor(QCursor(13));
     m_pAddbutton->setText(trUtf8("&Add"));
     QToolTip::add(m_pAddbutton, trUtf8("Add Entry"));
@@ -302,6 +616,8 @@
 
     // Tuple push button delete
     m_pDeletebutton = new QPushButton(m_pCenframe, "Deletebutton");
+    if (m_pDeletebutton == NULL)    // Sanity check
+        throw Genexcept("Main window delete button creation failed.");
     m_pDeletebutton->setCursor(QCursor(13));
     m_pDeletebutton->setText(trUtf8("&Delete"));
     m_pDeletebutton->setFlat(false);
@@ -311,6 +627,8 @@
 
     // Tuple push button write
     m_pWritebutton = new QPushButton(m_pCenframe, "Writebutton");
+    if (m_pWritebutton == NULL) // Sanity check
+        throw Genexcept("Main window write button creation failed.");
     m_pWritebutton->setCursor(QCursor(13));
     m_pWritebutton->setText(trUtf8("&Write"));
     QToolTip::add(m_pWritebutton, trUtf8("Write Entry"));
@@ -319,6 +637,8 @@
 
     // Tuple push button quit
     m_pQuitbutton = new QPushButton(m_pCenframe, "Quitbutton");
+    if (m_pQuitbutton == NULL)  // Sanity check
+        throw Genexcept("Main window quit button creation failed.");
     m_pQuitbutton->setCursor(QCursor(13));
     m_pQuitbutton->setText(trUtf8("&Quit"));
     m_pQuitbutton->setFlat(false);
@@ -326,187 +646,6 @@
     connect(m_pQuitbutton, SIGNAL(clicked()), qApp, SLOT(quit()));
     m_pControllayout->addWidget(m_pQuitbutton);
 
-    init(); // Initialize signal and slot connections
-    m_pStatbar->message(trUtf8("Ready"));   // Signal a ready condition
-}
-
-//
-// Add a blank row entry to the current data window
-//
-void Titraqform::addEntry(void)
-{
-    Prototype Unimp;
-    Unimp.doMbox();
-//    if (!pTable->text().isEmpty()) {
-//        QTableRow *pRow = new QTableRow;
-//        pRow->setText(0, NULL);
-//        pRow->setText(1, NULL);
-//        pRow->setText(2, NULL);
-//        pRow->setText(3, NULL);
-//    }
-}
-
-//
-// Choose a file using a handy file dialog
-//
-void Titraqform::delEntry(void)
-{
-    Prototype Unimp;
-    Unimp.doMbox();
-}
-
-//
-// Write current data to a meta device
-//
-void Titraqform::writeEntry(void)
-{
-    Prototype Unimp;
-    Unimp.doMbox();
-}
-
-//
-// Make and display a new document window
-//
-void Titraqform::newDoc(void)
-{
-    Prototype Unimp;
-    Unimp.doMbox();
-//    Titraqform *pNewform = new Titraqform;
-//    pNewform->show();
-}
-
-//
-// Choose a file using a handy file dialog
-//
-void Titraqform::choose(void)
-{
-    QString Filestring = QFileDialog::getOpenFileName(QString::null, QString::null, this);
-    if (!Filestring.isEmpty())
-        load(Filestring);
-    else
-        m_pStatbar->message(trUtf8("Loading aborted"), 4000);
-}
-
-//
-// Load accounting data into main window
-//
-void Titraqform::load(const QString &Filestring)
-{
-    QFile Filetemp(Filestring);         // File to load
-
-    if (!Filetemp.open(IO_ReadOnly))    // Need a wrapped exception here
-        return;
-
-    QTextStream Textstream(&Filetemp);  // Convert the file contents to a stream
-    m_pStatus->setText(Textstream.read());
-    m_pStatus->setEdited(false);
-    setCaption(Filestring);
-    m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
-}
-
-//
-// Serialize current state to the current file
-//
-void Titraqform::save(void)
-{
-    // First time saves are really just saveAs in disguise
-    if (m_szFilename->isEmpty()) {
-        saveAs();
-        return;
-    }
-
-    // Try to read the status text, and write it to a file
-    QString Statustext = m_pStatus->text();
-    QFile Filetemp(*m_szFilename);
-    if (!Filetemp.open(IO_WriteOnly)) {
-        m_pStatbar->message(QString(trUtf8("Could not write to %1")).arg(*m_szFilename), 4000);
-        return;
-    }
-
-    // Serialize file contents and write to text line
-    QTextStream Filestream(&Filetemp);
-    Filestream << Statustext;
-    Filetemp.close();
-
-    // Reset the text line, and give output to main window
-    m_pStatus->setEdited(FALSE);
-    setCaption(*m_szFilename);
-    m_pStatbar->message(QString(trUtf8("File %1 saved")).arg(*m_szFilename), 4000);
-    m_bDirt = false;    // Set the clean state to allow a close operation
-}
-
-//
-// Serialize current state to a selected file
-//
-void Titraqform::saveAs(void)
-{
-    // First get the selected file name to save to
-    QString Filestring = QFileDialog::getSaveFileName(QString::null, QString::null, this);
-    if (!Filestring.isEmpty()) {
-        *m_szFilename = Filestring;
-        m_pStatus->setText(*m_szFilename);
-        save(); // Finish off by calling the save action
-    }
-    else {
-        // User did not select a valid file and push okay button
-        m_pStatbar->message(trUtf8("Saving aborted"), 4000);
-    }
-}
-
-//
-// Close current document, displaying in main window
-//
-void Titraqform::closeEvent(QCloseEvent *pClosit)
-{
-    // Check modification state of current data
-    if (!this->isDirty()) {
-        pClosit->accept();
-        return;
-    }
-
-    // Ask user to acknowlege a possibly data-damaging close event
-    switch(QMessageBox::information(this, "OSSP titraq",
-        trUtf8("The document has been\nchanged since the last save.")),
-        trUtf8("Save Now"), trUtf8("Cancel"), trUtf8("Leave Anyway"), 0, 1) {
-    case 0:
-        save();
-        pClosit->accept();
-        break;
-    case 1:
-        default:    // Just for sanity
-        pClosit->ignore();
-        break;
-    case 2:
-        pClosit->accept();
-        break;
-    }
-}
-
-//
-// Check to see if state has changed since last save
-//
-bool Titraqform::isDirty(void)
-{
-    return m_bDirt;
-}
-
-//
-// Learn more about this program itself
-//
-void Titraqform::about(void)
-{
-    QMessageBox::about(this, "OSSP titraq",
-        trUtf8("OSSP titraq is a time and task-based\n"
-               "accounting system that acts as both a\n"
-               "nwork-like punch card and time tracker."));
-}
-
-//
-// Learn more about this program and Qt
-//
-void Titraqform::aboutQt(void)
-{
-    QMessageBox::aboutQt(this, "OSSP titraq");
 }
 
 //


ossp-pkg/as/as-gui/as_gui.h 1.8 -> 1.9

--- as_gui.h     2002/11/14 22:26:30     1.8
+++ as_gui.h     2002/11/18 22:13:56     1.9
@@ -13,6 +13,9 @@
 #include <qlineedit.h>
 #include <qlayout.h>
 
+// Intentional no operation
+#define TITRAQ_NOP ((void)0)
+
 
 // Main table size
 const int g_knRows = 16;
@@ -25,7 +28,7 @@
 
 public:
     Titraqform(QWidget *pParent = 0, const char *kszName = 0, WFlags Flags = 0);
-    ~Titraqform();
+    ~Titraqform(void);
 
     // Main application actions
     QAction     *m_pFilenewact,   *m_pFileopenact;
@@ -37,10 +40,16 @@
     // Table, cells, and entries in package layout
     QTable      *m_pMaintable;
     QHeader     *m_pTablehead;
-    QImage      *m_pIconimage;
-    QPixmap     *m_pIconpixmap;
     QStringList *m_pTaskentries;
 
+    // Reusable graphics
+    QImage      *m_pOsspicon;
+    QImage      *m_pQticon;
+    QImage      *m_pNewicon;
+    QImage      *m_pOpenicon;
+    QImage      *m_pSaveicon;
+    QImage      *m_pWhatsicon;
+
     // Push buttons in control layout
     QPushButton *m_pAddbutton;
     QPushButton *m_pDeletebutton;
@@ -61,7 +70,8 @@
     void save(void);                    // Serialize to the current file
     void saveAs(void);                  // Serialize to a selected file
     void about(void);                   // Learn more about this program itself
-    void aboutQt(void);                 // Learn more about this program and Qt
+    void aboutOSSP(void);               // Learn more about the OSSP
+    void aboutQt(void);                 // Learn more about Qt
 
 protected:
     // Application main events
@@ -74,7 +84,7 @@
     QHBoxLayout *m_pControllayout;      // Lower control buttons
 
 private:
-    // Don't destroy these, they are owned by QMainWindow
+    // Owned by QMainWindow
     QMenuBar    *m_pMenubar;
     QStatusBar  *m_pStatbar;
 
@@ -87,6 +97,16 @@
 
     // Standard methods
     bool isDirty(void);                 // Check for changed state danger
+
+    // Constructor helpers
+    void setupActions(void);            // Actions
+    void setupMenubar(void);            // Menu bar
+    void setupFiletools(void);          // Tool bar
+    void setupStatusbar(void);          // Status bar
+    void setupCentralwidget(void);      // Frame widget
+    void setupTable(void);              // Table widget
+    void setupOutput(void);             // Output widget
+    void setupButtons(void);            // Push button widgets
 };
 
 #endif // TITRAQMWIN_H



CVSTrac 2.0.1