as_slot.cpp

Thu, 06 Aug 2009 13:21:30 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 06 Aug 2009 13:21:30 +0200
changeset 15
0e0eb7c91312
parent 12
ceb4ba3d2d00
permissions
-rw-r--r--

Remove seemingly declarations unnecessary according to Qt 4.5.2 headers.

     1 //
     2 //  OSSP asgui - Accounting system graphical user interface
     3 //  Copyright (c) 2002-2009 The OSSP Project (http://www.ossp.org/)
     4 //  Copyright (c) 2002-2009 Ralf S. Engelschall <rse@engelschall.com>
     5 //  Copyright (c) 2002-2009 Michael Schloh von Bennewitz <michael@schloh.com>
     6 //  Copyright (c) 2002-2009 Cable & Wireless Telecommunications Services GmbH
     7 //
     8 //  This file is part of OSSP asgui, an accounting system graphical user
     9 //  interface which can be found at http://asgui.europalab.com/.
    10 //
    11 //  Permission to use, copy, modify, and distribute this software for
    12 //  any purpose with or without fee is hereby granted, provided that
    13 //  the above copyright notice and this permission notice appear in all
    14 //  copies.
    15 //
    16 //  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    17 //  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    18 //  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
    19 //  IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR
    20 //  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    21 //  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    22 //  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    23 //  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    24 //  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    25 //  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    26 //  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    27 //  SUCH DAMAGE.
    28 //
    29 //  as_slot.cpp: ISO C++ implementation
    30 //
    32 // system headers
    33 #include <memory>
    34 #include <cstring>
    36 // Qt headers
    37 #include <q3filedialog.h>
    38 #include <qcombobox.h>
    39 #include <qclipboard.h>
    40 #include <qmenudata.h>
    41 #include <qdatastream.h>
    42 #include <qstatusbar.h>
    43 #include <qaction.h>
    44 #include <q3popupmenu.h>
    46 // Qt style headers
    47 #include <qcdestyle.h>
    48 #include <qcleanlooksstyle.h>
    49 #include <qcommonstyle.h>
    50 #include <qmotifstyle.h>
    51 #include <qplastiquestyle.h>
    52 #include <qwindowscestyle.h>
    53 #include <qwindowsmobilestyle.h>
    54 #include <qwindowsstyle.h>
    55 #include <qwindowsvistastyle.h>
    56 #include <qwindowsxpstyle.h>
    58 //Added by qt3to4:
    59 #include <QPixmap>
    60 #include <QCloseEvent>
    61 #include <Q3TextStream>
    62 #include <Q3MemArray>
    63 #include <Q3Action>
    65 // User interface
    66 #include "as_const.h"           // Application constants
    67 #include "as_except.h"          // Exception classes
    68 #include "as_tableitem.h"       // For our custom table items
    69 #include "as_generic.h"         // Generic classes
    70 #include "as_uuid.h"            // UUID classes
    71 #include "as_datedit.h"         // Derived from QDateEdit
    72 #include "as_amount.h"          // Derived from QTimeEdit
    73 #include "as_crc.h"             // Useful Qualistring class
    74 #include "as_pref.h"            // For Preferences class
    75 #include "as_panel.h"           // For Prefpanel class
    76 #include "as_reportpanel.h"     // For Reportpanel class
    77 #include "as_helpanel.h"        // For Helpanel class
    78 #include "as_sfile.h"           // For Simplefile class
    79 #include "as_table.h"           // For TiTable class
    81 // RPC headers
    82 #ifdef HAVE_ESOAP
    83 #include <easysoap/SOAP.h>
    84 #endif // HAVE_ESOAP
    85 #ifdef HAVE_MICO
    86 #include <coss/CosNaming.h>
    87 #include "as_stub.h"            // CORBA stubs and skeletons
    88 #endif // HAVE_MICO
    90 // Icon pixel maps
    91 #include "as_gfx/cwlogo.xpm"    // static const char *s_kpcCwlogo_xpm[]
    92 #include "as_gfx/ossplogo.xpm"  // static const char *s_kpcOssplogo_xpm[]
    93 #include "as_gfx/statok.xpm"    // static const char *s_kpcStatokay_xpm[]
    94 #include "as_gfx/staterr.xpm"   // static const char *s_kpcStaterror_xpm[]
    95 #include "as_gfx/statwrn.xpm"   // static const char *s_kpcStatwarn_xpm[]
    96 #include "as_gfx/statvoid.xpm"  // static const char *s_kpcStatvoid_xpm[]
    99 //
   100 // Cut an entry
   101 //
   102 void Titraqform::cutEntry(void)
   103 {
   104     this->copyEntry();  // Reuse slot
   105     this->delEntry();   // Reuse slot
   106 }
   108 //
   109 // Copy an entry
   110 //
   111 void Titraqform::copyEntry(void)
   112 {
   113     QString Selection;  // Will hold the selected text
   114     QClipboard *pClip;  // Will reference the global clipboard
   116     // Initialize data and clipboard handle
   117     Selection = getRowdata();   // Use accessor
   118     pClip = QApplication::clipboard();
   120     Q_ASSERT(!Selection.isNull());
   121     pClip->setText(Selection, QClipboard::Selection); // Doesn't work on Windows
   122     pClip->setText(Selection, QClipboard::Clipboard); // Works on both equally
   123 }
   125 //
   126 // Paste an entry
   127 //
   128 void Titraqform::pasteEntry(void)
   129 {
   130     int nRows = 0;              // Paste so many rows as are stored
   131     QString Selection;          // Will receive the clipboard text
   132     QClipboard *pClip = NULL;   // Will reference the global clipboard
   134     pClip = QApplication::clipboard();                  // Prime the clips
   135     Selection = pClip->text(QClipboard::Clipboard);     // Windows and Unix
   136     nRows = Selection.count(QChar('\n'));               // How many rows
   137     if (Selection.isNull() && nRows > 0) { // Ignore empty clipboards
   138         this->addEntry(nRows);                          // Reuse slot
   139         setRowdata(Selection);                          // Use accessor
   141         // Update line numbers for this new row and all subsequent rows
   142         for (int nIter = m_pMaintable->currentRow(); nIter < m_pMaintable->numRows(); nIter++)
   143             m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter).rightJustify(4, QChar('0')));
   145         // Do basic data validation to warn against missing fields
   146         for (int nIter = 0; nIter < nRows; nIter++)
   147             this->validateRow(m_pMaintable->currentRow() + nIter, 0);
   149         m_pStatbar->message(QString::number(nRows) + trUtf8(" rows pasted"), 4000);
   150         updEdit(m_pMaintable->currentRow()); // Reflect in the update controls
   151     }
   152     else // Well, I guess the user tried to paste an empty clipboard
   153         m_pStatbar->message(trUtf8("The clipboard is empty"), 4000);
   154 }
   156 //
   157 // Append a blank row entry
   158 //
   159 void Titraqform::addEntry(int nRows)
   160 {
   161     Q3TableSelection Select; // Highlighted text
   162     int nTotal = 0;         // Total row select
   163     int nCurrent = 0;       // Current row
   164     std::auto_ptr<AS::Uuid> pGuid(new AS::Uuid); // For GUID production
   166     // Decide how many rows to add
   167     Select = m_pMaintable->selection(0);
   168     if (nRows > 0)
   169         nTotal = nRows;
   170     else
   171         nTotal = Select.bottomRow() - Select.topRow() + 1;
   173     // Optimize viewing by repainting cells only once after processing
   174     m_pMaintable->setUpdatesEnabled(false);
   176     // Add a row after selection and focus to the new row
   177     if (Select.bottomRow() + 1 != m_pMaintable->numRows()) { // Add upwards
   178         m_pMaintable->insertRows(Select.topRow(), nTotal);
   179         m_pMaintable->setDirty();   // Set data to dirty state
   180         m_pMaintable->setCurrentCell(Select.topRow(), m_pMaintable->currentColumn());
   182         // According to Trolltech, insertRows() "clears the selection(s)".
   183         // They are pretty wrong about that, so unfortunately we'll have to
   184         // take care of the dirty work ourselves with a clearSelection().
   185         m_pMaintable->clearSelection(false);
   186         m_pMaintable->selectRow(m_pMaintable->currentRow());
   188         // Update relevant data fields for all new rows
   189         for (int nIter = 0; nIter < nTotal; nIter++) {
   190             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXSTATUS, QString(QChar('W')));
   191             m_pMaintable->setPixmap(Select.topRow() + nIter, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatwarn_xpm));
   192             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXUSER, m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER));
   193             pGuid->genId();
   194             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXGUID, QString::fromStdString(pGuid->getString()));
   195             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXCRC, "0"); // 0 = invalid entry
   196             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXREV, "0"); // Entry not revised
   197             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXDATE, QDate::currentDate().toString(Qt::ISODate));
   198             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXSTART, "00:00");
   199             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXFINISH, "00:00");
   200             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXAMOUNT, "00:00");
   201 //            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXTASK, "/");
   202 //            m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXREMARK, "Remark");
   203             m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXCRC, "1"); // 0 = invalid entry
   204             this->calcCrc(Select.topRow() + nIter, -1);
   205         }
   206     }
   207     else { // Special case on last row add downwards
   208         m_pMaintable->insertRows(Select.bottomRow() + 1, nTotal);
   209         m_pMaintable->setDirty();   // Set data to dirty state
   210         m_pMaintable->setCurrentCell(Select.bottomRow() + 1, m_pMaintable->currentColumn());
   212         // According to Trolltech, insertRows() "clears the selection(s)".
   213         // They are pretty wrong about that, so unfortunately we'll have to
   214         // take care of the dirty work ourselves with a clearSelection().
   215         m_pMaintable->clearSelection(false);
   216         m_pMaintable->selectRow(m_pMaintable->currentRow());
   218         // Update relevant data fields for all new rows
   219         for (int nIter = 1; nIter <= nTotal; nIter++) {
   220             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXSTATUS, QString(QChar('W')));
   221             m_pMaintable->setPixmap(Select.bottomRow() + nIter, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatwarn_xpm));
   222             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXUSER, m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER));
   223             pGuid->genId();
   224             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXGUID, QString::fromStdString(pGuid->getString()));
   225             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXCRC, "0");
   226             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXREV, "0");
   227             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXDATE, QDate::currentDate().toString(Qt::ISODate));
   228             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXSTART, "00:00");
   229             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXFINISH, "00:00");
   230             m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXAMOUNT, "00:00");
   231 //            m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXTASK, "/");
   232 //            m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXREMARK, "Remark");
   233             this->calcCrc(Select.bottomRow() + nIter, -1);
   234         }
   235     }
   237     // Update line numbers for this new row and all subsequent rows
   238     for (int nIter = m_pMaintable->currentRow(); nIter < m_pMaintable->numRows(); nIter++)
   239         m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter).rightJustify(4, QChar('0')));
   241     updEdit(m_pMaintable->currentRow()); // Reflect in the update controls
   242     m_pStatusedit->setPixmap(QPixmap(s_kpcStatwarn_xpm)); // Show pixmap
   244     m_pMaintable->setUpdatesEnabled(true);  // Turn updates back on
   245     m_pMaintable->repaintContents(true);    // Do a general repaint of table
   246     m_pMaintable->ensureCellVisible(m_pMaintable->currentRow() + nTotal - 1, m_pMaintable->currentColumn());
   247     m_pMaintable->ensureCellVisible(m_pMaintable->currentRow(), m_pMaintable->currentColumn());
   249     // In case we added the first and only row entry,
   250     // do post state adjustments like icon undimming
   251     if (m_pMaintable->numRows() == 1) {
   252         m_pDelrowact->setEnabled(true);
   253         m_pRefreshact->setEnabled(true);
   254         m_pCutact->setEnabled(true);
   255         m_pCopyact->setEnabled(true);
   257         // Brighten all the edit controls also
   258         m_pLineedit->setEnabled(true);
   259         m_pUseredit->setEnabled(true);
   260         m_pGuidedit->setEnabled(true);
   261         m_pCrcedit->setEnabled(true);
   262         m_pRevedit->setEnabled(true);
   263         m_pDateedit->setEnabled(true);
   264         m_pStarttime->setEnabled(true);
   265         m_pEndtime->setEnabled(true);
   266         m_pAmount->setEnabled(true);
   267         m_pTasks->setEnabled(true);
   268         m_pRemark->setEnabled(true);
   270         // And optionally the RPC actions, too
   271 #if defined HAVE_MICO || defined HAVE_ESOAP
   272         m_pSyncact->setEnabled(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON)
   273             | m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON));
   274 #endif // HAVE_MICO || defined HAVE_ESOAP
   275     }
   276 }
   278 //
   279 // Delete a row entry
   280 //
   281 void Titraqform::delEntry(int nRows)
   282 {
   283     Q3TableSelection Select = m_pMaintable->selection(0);    // Highlighted text
   284     int nTotal = Select.bottomRow() - Select.topRow() + 1;  // Total row select
   285     Q3MemArray<int> Rowselect(nTotal);                       // Row array
   287     // Calculate rows to delete from selection highlight
   288     for (int nIter = 0; nIter < nTotal; ++nIter)
   289         Rowselect[nIter] = Select.topRow() + nIter;
   291     // Remove the row at selection and focus to the next row
   292     if (m_pMaintable->currentRow() + 1 != m_pMaintable->numRows()) {
   293         m_pMaintable->setCurrentCell(Select.bottomRow() + 1, m_pMaintable->currentColumn());
   294         m_pMaintable->removeRows(Rowselect);
   295         m_pMaintable->setDirty();   // Set data to dirty state
   296     }
   297     else {  // Special case to handle removing of only row or last row
   298         m_pMaintable->removeRows(Rowselect);
   299         m_pMaintable->setDirty();   // Set data to dirty state
   300     }
   302     // Update line numbers for this new row and all subsequent rows
   303     for (int nIter = m_pMaintable->currentRow(); nIter < m_pMaintable->numRows(); nIter++)
   304         m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter));
   306     // In case we removed the last remaining row,
   307     // do post state adjustments like icon dimming
   308     if (m_pMaintable->numRows() <= 0) {
   309         m_pDelrowact->setEnabled(false);
   310         m_pRefreshact->setEnabled(false);
   311         m_pCutact->setEnabled(false);
   312         m_pCopyact->setEnabled(false);
   314         // Dim all the edit controls also
   315         m_pStatusedit->setPixmap(s_kpcStatvoid_xpm);
   316         m_pLineedit->setEnabled(false);
   317         m_pUseredit->setEnabled(false);
   318         m_pGuidedit->setEnabled(false);
   319         m_pCrcedit->setEnabled(false);
   320         m_pRevedit->setEnabled(false);
   321         m_pDateedit->setEnabled(false);
   322         m_pStarttime->setEnabled(false);
   323         m_pEndtime->setEnabled(false);
   324         m_pAmount->setEnabled(false);
   325         m_pTasks->setEnabled(false);
   326         m_pRemark->setEnabled(false);
   328         // And optionally dim the RPC actions
   329 #if defined HAVE_MICO || defined HAVE_ESOAP
   330         m_pSyncact->setEnabled(false);
   331 #endif // HAVE_MICO || defined HAVE_ESOAP
   332     }
   333 }
   335 //
   336 // Refresh the display of all data items
   337 //
   338 void Titraqform::refreshDisplay(void)
   339 {
   340     int nIter = 0;                          // Matrix iterator
   341     int nRows = m_pMaintable->numRows();    // Total number of rows
   343     // Sweep through matrix validating linewise
   344     // data and updating line numbers for all rows
   345     while (nIter < nRows) {
   346         this->validateRow(nIter, 0);
   347         m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter).rightJustify(4, QChar('0')));
   348         nIter++;
   349     }
   351     m_pMaintable->repaintContents(false);   // Do a general repaint of table
   352     m_pStatbar->message(trUtf8("Display was refreshed"), 4000); // Announce result
   353 }
   355 //
   356 // Make and display a new document window
   357 //
   358 void Titraqform::newDoc(void)
   359 {
   360     int nResult = 0; // Holds return value from save first messagebox
   362     // Check modification state of current data
   363     if (m_pMaintable->isDirty()) {
   364         nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE)
   365                 + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST),
   366                   trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2);
   368         switch (nResult) {
   369         case 0: // First button selected, so save first
   370             this->saveFile();   // Save changes first
   371             break;
   372         case 1: // Second button selected, so don't save
   373             break;
   374         case 2: // Third button selected, so return sofort
   375         default:
   376             m_pStatbar->message(trUtf8("New aborted"), 4000);
   377             return;
   378             break;
   379         }
   380     }
   382     if (!m_pMaintable->isDirty() || nResult == 1) { // Check modification state
   383         // Fall through to implicit new doc code
   384         this->setCaption(trUtf8("No file name"));
   385         m_pStatbar->message(trUtf8("New document"), 4000);
   386         this->enableIface(true);            // Enable the interface
   387         m_pMaintable->setNumRows(0);        // Remove all data in table
   388         this->setFilename("");               // Signal a closed doc state
   389         this->addEntry(1);                  // Default new op adds a row
   390         m_pMaintable->setDirty(false);      // Start out clean
   391     }
   392 }
   394 //
   395 // Open and display an existing document
   396 //
   397 void Titraqform::openDoc(void)
   398 {
   399     int nResult = 0; // Holds return value from save first messagebox
   401 //
   402 // This block will guide the user to saving the contents of the timesheet
   403 // before losing them in an open operation. The question and dialog box will
   404 // not be raised if no open timesheet exists or if it was just serialized.
   405 //
   406     if (m_pMaintable->isDirty()) { // Check modification state
   407         nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE)
   408                 + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST),
   409                   trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2);
   411         switch (nResult) {
   412         case 0: // Save first
   413             this->saveFile(); // Save changes first
   414             break;
   415         case 1: // Don't save first but do load
   416             break;
   417         case 2: // Don't do a load timesheet
   418         default:
   419             m_pStatbar->message(trUtf8("Loading aborted"), 4000);
   420             return;
   421             break;
   422         }
   423     }
   425 //
   426 // This block ensures that conditions of first block logic were met if
   427 // applicable. If so, the user gives a file name to open or cancels the
   428 // operation. The corresponding file will be opened, and if this is
   429 // unsuccessful then the post state is exactly the same as the pre state.
   430 //
   431     if (!m_pMaintable->isDirty() || nResult == 1) { // Check modification state
   432         // Make sure we correctly get the name of the default file to open
   433         QString Openas = m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR);
   434         if (Openas.startsWith(TITRAQ_HOMEDIRTOK))
   435             Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1);
   437         // This dialog asks which file the user wants to open
   438         QString Filestring = Q3FileDialog::getOpenFileName(Openas,
   439             trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"),
   440             this, trUtf8("ChooserDialog"), trUtf8("Choose a file to open"), NULL, false);
   442         // We might have a filename to work on, so do something with it
   443         if (!Filestring.isEmpty()) {
   444             QFile Filetemp(Filestring);             // File to load
   445             try {
   446                 if (Filetemp.exists() && validateData(Filetemp)) { // Be extra sure
   447                     setFilename(Filestring);        // Set the new file name
   448                     m_pMaintable->setNumRows(0);    // Clear out old data
   449                     m_pMaintable->setDirty(false);  // Reset dirty flag
   450                     loadData(Filetemp);             // Pass to helper method
   451                     this->setCaption(Filestring);   // Caption in the titlebar
   452                     m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000);
   453                     this->enableIface(true);        // Turn on the lights
   454                     this->setOpen(true);            // Indicate doc is open
   455                 }
   456             }
   457             catch (Genexcept& Genex) { // Crap, we failed
   458                 m_pStatbar->message(trUtf8("Loading failed"), 4000);
   459                 Genex.reportErr();
   460                 return;
   461             }
   462         }
   463         else // An empty filename returning from the file dialog means cancel
   464             m_pStatbar->message(trUtf8("Loading aborted"), 4000);
   465     }
   466 }
   468 //
   469 // Serialize current state to the current file
   470 //
   471 void Titraqform::saveFile(void)
   472 {
   473     QString Fname;
   474     Simplefile Filevents;
   476     try {
   477         Fname = *this->getFilename();
   479         // First time saves are really just saveName in disguise
   480         if (Fname.isEmpty()) {
   481             try {
   482                 this->saveName();       // Try to 'save as'
   483                 return;                 // and short circuit
   484             }
   485             catch (Genexcept& Genex) {
   486 //                Genex.reportErr();      // Report the error
   487                 return;                 // and short circuit
   488             }
   489         }
   491         Filevents.setName(Fname);   // Construct a file to write
   492         if (m_pPrefs->getBool(TITRAQ_PREFBAKON, TITRAQ_DEFBAKON))
   493             Filevents.makeBackup(); // Back up to filename.bak
   494         this->saveData(Filevents);  // Pass to helper method
   495     }
   496     catch (Genexcept& Genex) {
   497         Genex.reportErr();
   498     }
   499     // Reset and give output to main window
   500     this->setCaption(Fname);
   501     m_pStatbar->message(trUtf8("File %1 saved").arg(Fname), 4000);
   502     m_pMaintable->setDirty(false);  // Set the clean state to allow close
   503 }
   505 //
   506 // Serialize current state to a selected file
   507 //
   508 void Titraqform::saveAs(void)
   509 {
   510     int nResult = 0; // For checking user's answer
   512     // Make sure we correctly get the name of the default file to open
   513     QString Openas = m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR);
   514     if (Openas.startsWith(TITRAQ_HOMEDIRTOK))
   515         Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1);
   517     // And then get the name of the selected file to save to
   518     QString Filestring = Q3FileDialog::getSaveFileName(Openas, trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false);
   519     if (!Filestring.isEmpty()) {
   520         if (QFile::exists(Filestring)) {
   521             nResult = QMessageBox::warning(this, QString(TITRAQ_APPTITLE)
   522                     + ' ' + asgui_version.v_short, trUtf8(TITRAQ_OVERWRITE),
   523                       trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1);
   524             switch (nResult) {
   525             case 0: // Overwrite contents
   526                 this->setFilename(Filestring);
   527                 this->saveFile();
   528                 break;
   529             case 1: // Don't overwrite
   530             default:
   531                 break;
   532             }
   533         }
   534         else {
   535             // Conditionally use a unique extension like '.as' if user prefers
   536             if (m_pPrefs->getBool(TITRAQ_PREFEXTENDON, TITRAQ_DEFEXTENDON)) {
   537                 QString Extension = TITRAQ_FEXTENSION;  // Logic to handle
   538                 if (!Filestring.endsWith(Extension))    // AS file extension
   539                     Filestring += Extension;            // insertion
   540             }
   541             this->setFilename(Filestring);  // Set filename of object first
   542             this->saveFile();               // Finish by calling the save action
   543         }
   544     }
   545     else
   546         // User did not select a valid file and push okay button
   547         m_pStatbar->message(trUtf8("Saving aborted"), 4000);
   548 }
   550 //
   551 // Implicitly serialize current state to a selected file
   552 // The main difference with saveAs is that this uses exceptions
   553 //
   554 void Titraqform::saveName(void)
   555 {
   556     int nResult = 0; // For checking user's answer
   558     // Make sure we correctly get the name of the default file to open
   559     QString Openas = m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR);
   560     if (Openas.startsWith(TITRAQ_HOMEDIRTOK))
   561         Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1);
   563     nResult = 1;            // We loop on this dialog only if an indecisive user
   564     while (nResult > 0) {   // is hesitant to overwrite a file over and over again
   565         QString Filestring = Q3FileDialog::getSaveFileName(Openas, trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false);
   566         if (!Filestring.isEmpty()) {
   567             if (QFile::exists(Filestring)) {
   568                 nResult = QMessageBox::warning(this, QString(TITRAQ_APPTITLE)
   569                         + ' ' + asgui_version.v_short, trUtf8(TITRAQ_OVERWRITE),
   570                           trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1);
   571                 switch (nResult) {
   572                 case 0: // Overwrite contents
   573                     this->setFilename(Filestring);
   574                     this->saveFile();
   575                     break;
   576                 case 1: // Don't overwrite
   577                 default:
   578                     break;
   579                 }
   580             }
   581             else {
   583                 // Conditionally use a unique extension like '.as' if user prefers
   584                 if (m_pPrefs->getBool(TITRAQ_PREFEXTENDON, TITRAQ_DEFEXTENDON)) {
   585                     QString Extension = TITRAQ_FEXTENSION;  // Logic to handle
   586                     if (!Filestring.endsWith(Extension))    // AS file extension
   587                         Filestring += Extension;            // insertion
   588                 }
   589                 this->setFilename(Filestring);  // Set filename of object first
   590                 nResult = 0;                    // Reset our loop control
   591                 this->saveFile();               // Finish by calling the save action
   592             }
   593         }
   594         else {
   595             // User did not select a valid file and push okay button
   596             m_pStatbar->message(trUtf8("Saving aborted"), 4000);
   597             throw Genexcept(TITRAQ_SAVECANCELLED);
   598         }
   599     }
   600 }
   602 //
   603 // Close current document, and then quit the application
   604 //
   605 void Titraqform::quitApp(void)
   606 {
   607     int nResult = 0;
   609     if (m_pMaintable->isDirty()) {
   610         nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE)
   611                 + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST),
   612                   trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2);
   614         switch (nResult) {      // Maybe save before closing
   615         case 0: // Save first
   616             this->saveFile();   // Save changes first
   617             break;
   618         case 1: // Don't save first
   619             m_pMaintable->setDirty(false);
   620             break;
   621         case 2: // Do nothing
   622         default:
   623             return; // Go away without closing
   624             break;
   625         }
   626     }
   628     // We should be clean now, but double check just in case
   629     if (!m_pMaintable->isDirty())
   630         qApp->quit();
   631 }
   633 //
   634 // Close current document, displaying in main window
   635 //
   636 void Titraqform::closeEvent(QCloseEvent *pClosit)
   637 {
   638     int nResult = 0;
   640     if (!this->isOpen())    // Short circuit if user
   641         qApp->quit();       // selects close twice
   643     // Check modification state of current data
   644     if (m_pMaintable->isDirty()) {
   645         nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE)
   646                 + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST),
   647                   trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2);
   649         switch (nResult) {      // Maybe save before closing
   650         case 0: // Save first
   651             this->saveFile();   // Save changes first
   652             break;
   653         case 1: // Don't save first
   654             m_pMaintable->setDirty(false);
   655             break;
   656         case 2: // Do nothing
   657         default:
   658             pClosit->ignore();
   659             return; // Go away without closing
   660             break;
   661         }
   662     }
   664     if (!m_pMaintable->isDirty()) { // Check again
   665         // Fall through to implicit close code
   666         this->setCaption(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short);
   667         try { // There might be problems, so wrap these last ops with error handling
   668             QString Lightsout;          // It's late, go to bed
   669             if (this->isOpen())
   670                 Lightsout = trUtf8("Closed document ") + *this->getFilename();
   671             this->setOpen(false);       // Set doc state to closed
   672             this->enableIface(false);   // Turn off the lights
   673             m_pStatbar->message(Lightsout, 4000);
   674         }
   675         catch (Genexcept& Genex) {
   676             Genex.reportErr();
   677         }
   678     }
   679     pClosit->ignore();  // Finish off by not closing
   680 }
   682 //
   683 // Edit menu select all entries
   684 //
   685 void Titraqform::selAll(void)
   686 {
   687     Prototype Unimp;
   688     Unimp.doMbox();
   689 }
   691 //
   692 // Edit a table entry in place, without the usual edit controls
   693 //
   694 void Titraqform::inplaceEdit(int nRow, int nCol, int nButton, const QPoint &Mousepos)
   695 {
   696     // Table read only attribute must be reset here, so that editing can take
   697     // place. Otherwise calls to editCell are ignored (for obvious reasons).
   698     m_pMaintable->setReadOnly(false);
   700     // After editCell() is called, beginEdit() and endEdit() execute. The read
   701     // only attribute is reset in endEdit() to return everything to normal.
   702     m_pMaintable->editCell(nRow, nCol);
   704     m_pMaintable->setEdition(nCol);
   705 }
   707 //
   708 // Update the edit controls widget sizes
   709 //
   710 void Titraqform::updSizes(int nSection, int nOldsize, int nNewsize)
   711 {
   712     switch (nSection) {
   713     case TITRAQ_IDXALLCTRLS:
   714         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) > 0)
   715             m_pStatusedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) - TITRAQ_SPACING);
   716         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) > 0)
   717             m_pLineedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) - TITRAQ_SPACING);
   718         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) > 0)
   719             m_pUseredit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) - TITRAQ_SPACING);
   720         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) > 0)
   721             m_pGuidedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) - TITRAQ_SPACING);
   722         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) > 0)
   723             m_pCrcedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) - TITRAQ_SPACING);
   724         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) > 0)
   725             m_pRevedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) - TITRAQ_SPACING);
   726         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) > 0)
   727             m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING);
   728         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) > 0)
   729             m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING);
   730         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) > 0)
   731             m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING);
   732         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) > 0)
   733             m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING);
   734         if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) > 0)
   735             m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING);
   736 //        if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXRCOL)))
   737 //            m_pRemark->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREMARK) - TITRAQ_SPACING);
   738         break;
   739     case TITRAQ_IDXSTATUS:
   740         m_pStatusedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) - TITRAQ_SPACING);
   741         break;
   742     case TITRAQ_IDXLINE:
   743         m_pLineedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) - TITRAQ_SPACING);
   744         break;
   745     case TITRAQ_IDXUSER:
   746         m_pUseredit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) - TITRAQ_SPACING);
   747         break;
   748     case TITRAQ_IDXGUID:
   749         m_pGuidedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) - TITRAQ_SPACING);
   750         break;
   751     case TITRAQ_IDXCRC:
   752         m_pCrcedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) - TITRAQ_SPACING);
   753         break;
   754     case TITRAQ_IDXREV:
   755         m_pRevedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) - TITRAQ_SPACING);
   756         break;
   757     case TITRAQ_IDXDATE:
   758         m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING);
   759         break;
   760     case TITRAQ_IDXSTART:
   761         m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING);
   762         break;
   763     case TITRAQ_IDXFINISH:
   764         m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING);
   765         break;
   766     case TITRAQ_IDXAMOUNT:
   767         m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING);
   768         break;
   769     case TITRAQ_IDXTASK:
   770         m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING);
   771         break;
   772     case TITRAQ_IDXREMARK:
   773 //        m_pRemark->setFixedWidth(nNewsize);
   774         break;
   775     default:
   776         throw Genexcept("Unrecognized main window column header.");
   777         break;
   778     }
   780     // As a last and redundant step, adjust size of first visible control
   781     switch(this->getFirstcol()) {
   782     case TITRAQ_IDXSTATUS:
   783         m_pStatusedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   784         break;
   785     case TITRAQ_IDXLINE:
   786         m_pLineedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   787         break;
   788     case TITRAQ_IDXUSER:
   789         m_pUseredit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   790         break;
   791     case TITRAQ_IDXGUID:
   792         m_pGuidedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   793         break;
   794     case TITRAQ_IDXCRC:
   795         m_pCrcedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   796         break;
   797     case TITRAQ_IDXREV:
   798         m_pRevedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   799         break;
   800     case TITRAQ_IDXDATE:
   801         m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   802         break;
   803     case TITRAQ_IDXSTART:
   804         m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   805         break;
   806     case TITRAQ_IDXFINISH:
   807         m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   808         break;
   809     case TITRAQ_IDXAMOUNT:
   810         m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   811         break;
   812     case TITRAQ_IDXTASK:
   813         m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING + TITRAQ_SPACING / 2);
   814         break;
   815     default:    // Probably no columns are visible?
   816         break;
   817     }
   818 }
   820 //
   821 // What to do if a data cell is modified
   822 //
   823 void Titraqform::dataChanged(int nRow, int nCol)
   824 {
   825     if (nCol != TITRAQ_IDXSTATUS && nCol != TITRAQ_IDXLINE)
   826         m_pMaintable->setDirty();   // Mark this timesheet dirty, changes pending save
   827 }
   829 //
   830 // Convenience member calculates CRC for current row
   831 //
   832 void Titraqform::calcCrc(void)
   833 {
   834     this->calcCrc(-1, -1);
   835 }
   837 //
   838 // Calculates CRC for the specified row, fires when data is changed
   839 //
   840 void Titraqform::calcCrc(int nRow, int nCol)
   841 {
   842     if (nCol != TITRAQ_IDXSTATUS && nCol != TITRAQ_IDXLINE \
   843                                  && m_pMaintable->numRows() > 0) {
   844         U32 Testcrc, Valcrc;
   845         QString Crcstr;
   846         std::auto_ptr<Qualistring>pWholerow(new Qualistring);
   847         int nRealrow = -1;
   849         // Build the data that will be used in testing CRC calculation
   850         nRealrow = (nRow >= 0) ? nRow : m_pMaintable->currentRow();
   851         *pWholerow = m_pMaintable->text(nRealrow, TITRAQ_IDXUSER);
   852         for (int nIter = TITRAQ_IDXUSER + 1; nIter < TITRAQ_IDXTAIL; nIter++)
   853             if (nIter != TITRAQ_IDXCRC) // Don't checksum the checksum!
   854                 *pWholerow += m_pMaintable->text(nRealrow, nIter);
   856         // Update the checksum and revision only if necessary
   857         Testcrc = pWholerow->getCrc();
   859         // FIXME: This thing is not very unportable, because toUInt != U32
   860         if (Testcrc != m_pMaintable->text(nRealrow, TITRAQ_IDXCRC).toUInt()) {
   862 //            // Bump the revision number of our entry to control conflicts
   863 //            nNewrev = m_pMaintable->text(nRealrow, TITRAQ_IDXREV).toInt() + 1;
   864 //            m_pMaintable->setText(nRealrow, TITRAQ_IDXREV, QString::number(nNewrev));
   866             // Build the data that will be used in setting CRC calculation
   867             *pWholerow = m_pMaintable->text(nRealrow, TITRAQ_IDXUSER);
   868             for (int nIter = TITRAQ_IDXUSER + 1; nIter < TITRAQ_IDXTAIL; nIter++)
   869                 if (nIter != TITRAQ_IDXCRC) // Don't checksum the checksum!
   870                     *pWholerow += m_pMaintable->text(nRealrow, nIter);
   872             Valcrc = pWholerow->getCrc(); // Finally set the checksum to its new value
   873             Crcstr = QString::number(Valcrc, 16).rightJustify(8, '0');
   874             m_pMaintable->setText(nRealrow, TITRAQ_IDXCRC, "0x" + Crcstr);
   875             m_pCrcedit->setText("0x" + Crcstr);
   876         }
   877     }
   878 }
   880 //
   881 // Gets a hit on every table click
   882 //
   883 void Titraqform::onClick(int nRow, int nCol, int nButton, const QPoint &Mousepos)
   884 {
   885     // Give the clueless user some hints when clicking an empty timesheet
   886     if (m_pMaintable->numRows() <= 0)
   887         m_pStatbar->message(trUtf8("Empty timesheet, add entries first please"), 2000);
   888 }
   890 //
   891 // Update the edit controls contents
   892 //
   893 void Titraqform::updEdit(int nRow, int nCol)
   894 {
   895     // Why is the app sending negative row signal? I don't know yet,
   896     // so add in this nasty hack to fend off the debug spew on stderr
   897     if (m_pMaintable->numRows() > 0 && nRow >= 0) {
   898         // Field strings to check for validity and process
   899         QString Textline(m_pMaintable->text(nRow, TITRAQ_IDXLINE));
   900         QString Textuser(m_pMaintable->text(nRow, TITRAQ_IDXUSER));
   901         QString Textguid(m_pMaintable->text(nRow, TITRAQ_IDXGUID));
   902         QString Textcrc(m_pMaintable->text(nRow, TITRAQ_IDXCRC));
   903         QString Textrev(m_pMaintable->text(nRow, TITRAQ_IDXREV));
   904         QString Textdate(m_pMaintable->text(nRow, TITRAQ_IDXDATE));
   905         QString Textstart(m_pMaintable->text(nRow, TITRAQ_IDXSTART));
   906         QString Textfinish(m_pMaintable->text(nRow, TITRAQ_IDXFINISH));
   907         QString Textamount(m_pMaintable->text(nRow, TITRAQ_IDXAMOUNT));
   908         QString Texttask(m_pMaintable->text(nRow, TITRAQ_IDXTASK));
   909         QString Textremark(m_pMaintable->text(nRow, TITRAQ_IDXREMARK));
   911         // Reset the edition state member
   912         m_pMaintable->setEdition();
   914         // Set text of member edit controls
   915         if (m_pMaintable->text(nRow, TITRAQ_IDXSTATUS).isEmpty())   // If row is empty
   916             m_pStatusedit->setPixmap(s_kpcStatvoid_xpm);            // add a placeholder
   917         else
   918             m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRow, TITRAQ_IDXSTATUS));
   919         m_pLineedit->setText(Textline);
   920         m_pUseredit->setText(Textuser);
   921         m_pGuidedit->setText(Textguid);
   922         m_pCrcedit->setText(Textcrc);
   923         m_pRevedit->setText(Textrev);
   925 //        QRegExp Shorten("/(\\w+)$");    // For stripping prefix off the current task
   926 //        Texttask.remove(0, Shorten.search(Texttask) + 1); // Strip leading slash
   928         m_pRemark->setText(Textremark);
   929         m_pTasks->setCurrentText(Texttask);
   931         // Date field not suitable for empty string text
   932         if (Textdate == ".")
   933             m_pDateedit->setDate(QDate::currentDate());
   934         else if (Textdate.isEmpty())
   935             m_pDateedit->setDate(QDate::fromString("0000-00-00", Qt::ISODate));
   936         else
   937             m_pDateedit->setDate(QDate::fromString(Textdate, Qt::ISODate));
   939         // Start time not suitable for empty string text
   940         if (Textstart == ".")
   941             m_pStarttime->setTime(QTime::currentTime());
   942         else if (Textstart.isEmpty())
   943             m_pStarttime->setTime(QTime::QTime(0, 0));
   944         else
   945             m_pStarttime->setTime(QTime::fromString(Textstart, Qt::ISODate));
   947         // Finish time not suitable for empty string text
   948         if (Textfinish == ".")
   949             m_pEndtime->setTime(QTime::currentTime());
   950         else if (Textfinish.isEmpty())
   951             m_pEndtime->setTime(QTime::QTime(0, 0));
   952         else
   953             m_pEndtime->setTime(QTime::fromString(Textfinish, Qt::ISODate));
   955         // Amount time not suitable for empty string text
   956         if (Textamount == ".") {
   957             int nDifference = m_pStarttime->time().secsTo(m_pEndtime->time());
   958             m_pAmount->setTime(QTime(0, 0).addSecs(nDifference));
   959         }
   960         else if (Textamount.isEmpty())
   961             m_pAmount->setTime(QTime::QTime(0, 0));
   962         else
   963             m_pAmount->setTime(QTime::fromString(Textamount, Qt::ISODate));
   964     }
   965 }
   967 //
   968 // Validate current row of the matrix
   969 //
   970 void Titraqform::validateRow(void)
   971 {
   972     this->validateRow(-1, -1);
   973 }
   975 //
   976 // Validate specified row of the matrix
   977 //
   978 void Titraqform::validateRow(int nRow, int nCol)
   979 {
   980     int nRealrow = -1;
   982     if (!this->isOpen()) { // If no data is loaded then short circuit
   983         m_pStatbar->message(trUtf8("Timesheet contains no data"), 4000);
   984         return;
   985     }
   987     nRealrow = (nRow >= 0) ? nRow : m_pMaintable->currentRow();
   988     QString Statis = m_pMaintable->text(nRealrow, TITRAQ_IDXSTATUS); // Get text
   990     // Review whole data validity, and set pixmap accordingly
   991     if (m_pMaintable->text(nRealrow, TITRAQ_IDXUSER).isEmpty() ||
   992         m_pMaintable->text(nRealrow, TITRAQ_IDXGUID).isEmpty() ||
   993         m_pMaintable->text(nRealrow, TITRAQ_IDXCRC).isEmpty() ||
   994         m_pMaintable->text(nRealrow, TITRAQ_IDXREV).isEmpty() ||
   995         m_pMaintable->text(nRealrow, TITRAQ_IDXDATE).isEmpty() ||
   996         m_pMaintable->text(nRealrow, TITRAQ_IDXSTART).isEmpty() ||
   997         m_pMaintable->text(nRealrow, TITRAQ_IDXFINISH).isEmpty() ||
   998         m_pMaintable->text(nRealrow, TITRAQ_IDXAMOUNT).isEmpty() ||
   999         m_pMaintable->text(nRealrow, TITRAQ_IDXTASK).isEmpty())
  1000     { // No K&R style to show where actual code begins
  1001         if (Statis.startsWith(QString("W"))) { // Conditionally set pixmap to avoid overhead
  1002 // FIXME: Next line commented out, and I see that this algorythm needs help
  1003 //            m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS));
  1005         else if (!Statis.startsWith(QString("E"))) { // Conditionally set pixmap to avoid overhead
  1006             m_pMaintable->setText(nRealrow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'E'));
  1007             m_pMaintable->setPixmap(nRealrow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStaterror_xpm));
  1008             m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS));
  1011     else {
  1012         if (!Statis.startsWith(QString("O"))) { // Conditionally set pixmap to avoid overhead
  1013             m_pMaintable->setText(nRealrow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'O'));
  1014             m_pMaintable->setPixmap(nRealrow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatokay_xpm));
  1015             m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS));
  1019     // Test for blank user field, and set to default if so
  1020     if (m_pMaintable->text(nRealrow, TITRAQ_IDXUSER).isEmpty())
  1021         m_pMaintable->setText(nRealrow, TITRAQ_IDXUSER, m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER));
  1023     // Test for blank date field, and set to default if so
  1024     if (m_pMaintable->text(nRealrow, TITRAQ_IDXDATE) == ".")
  1025         m_pMaintable->setText(nRealrow, TITRAQ_IDXDATE, QDate::currentDate().toString(Qt::ISODate));
  1027     // Test for blank start field, and set to default if so
  1028     if (m_pMaintable->text(nRealrow, TITRAQ_IDXSTART) == ".")
  1029         m_pMaintable->setText(nRealrow, TITRAQ_IDXSTART, QTime::currentTime().toString("hh:mm"));
  1031     // Test for blank finish field, and set to default if so
  1032     if (m_pMaintable->text(nRealrow, TITRAQ_IDXFINISH) == ".")
  1033         m_pMaintable->setText(nRealrow, TITRAQ_IDXFINISH, QTime::currentTime().toString("hh:mm"));
  1035     // Test for blank amount field, and set to default if so
  1036     if (m_pMaintable->text(nRealrow, TITRAQ_IDXAMOUNT) == ".") {
  1037         QTime Begin  = QTime::fromString(m_pMaintable->text(nRealrow, TITRAQ_IDXSTART), Qt::ISODate);
  1038         QTime End    = QTime::fromString(m_pMaintable->text(nRealrow, TITRAQ_IDXFINISH), Qt::ISODate);
  1039         QString Diff = QTime(0, 0).addSecs(Begin.secsTo(End)).toString("hh:mm");
  1040         m_pMaintable->setText(nRealrow, TITRAQ_IDXAMOUNT, Diff);
  1044 //
  1045 // Update the current line number column item
  1046 //
  1047 void Titraqform::updateLine(const QString &Instring)
  1049     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXLINE, Instring);
  1052 //
  1053 // Update the current user column item
  1054 //
  1055 void Titraqform::updateUser(const QString &Instring)
  1057     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXUSER, Instring);
  1060 //
  1061 // Update the current GUID column item
  1062 //
  1063 void Titraqform::updateGuid(const QString &Instring)
  1065     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXGUID, Instring);
  1068 //
  1069 // Update the current CRC column item
  1070 //
  1071 void Titraqform::updateCrc(const QString &Instring)
  1073     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXCRC, Instring);
  1076 //
  1077 // Update the current rev column item
  1078 //
  1079 void Titraqform::updateRev(const QString &Instring)
  1081     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXREV, Instring);
  1084 //
  1085 // Update the current date column item
  1086 //
  1087 void Titraqform::updateDate(const QDate &Dateup)
  1089         m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXDATE, Dateup.toString(Qt::ISODate));
  1092 //
  1093 // Update the current start column item
  1094 //
  1095 void Titraqform::updateStart(const QTime &Startup)
  1097     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXSTART, Startup.toString("hh:mm"));
  1100 //
  1101 // Update the current finish column item
  1102 //
  1103 void Titraqform::updateFinish(const QTime &Finishup)
  1105     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXFINISH, Finishup.toString("hh:mm"));
  1108 //
  1109 // Update the current amount column item
  1110 //
  1111 void Titraqform::updateAmount(const QTime &Amountup)
  1113     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXAMOUNT, Amountup.toString("hh:mm"));
  1116 //
  1117 // Update the current task column item
  1118 //
  1119 void Titraqform::updateTask(const QString &Taskup)
  1121 //    // FIXME: Broken
  1122 //    RtTableItem *pTask = NULL;
  1123 //    pTask = static_cast<RtTableItem *>(m_pMaintable->item(m_pMaintable->currentRow(), TITRAQ_IDXTASK));
  1124 //    pTask->setText(Taskup);
  1126     // Don't try to use the Taskup string, because it ignores autocompletion
  1127     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXTASK, m_pTasks->currentText());
  1130 //
  1131 // Update the current remark column item
  1132 //
  1133 void Titraqform::updateRemark(const QString &Remarkup)
  1135     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXREMARK, Remarkup);
  1138 //
  1139 // Confirm any recent editions on a whole row
  1140 //
  1141 void Titraqform::confirmEdit(void)
  1143     RtTableItem *pTask = NULL;  // Task item is a derived class
  1145     // Conversions from edit control data formats to native tabular format
  1146     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXDATE, m_pDateedit->date().toString(Qt::ISODate));
  1147     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXSTART, m_pStarttime->time().toString(Qt::ISODate));
  1148     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXFINISH, m_pEndtime->time().toString(Qt::ISODate));
  1149     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXAMOUNT, m_pAmount->time().toString(Qt::ISODate));
  1151     // Specially handle task fields
  1152     pTask = static_cast<RtTableItem *>(m_pMaintable->item(m_pMaintable->currentRow(), TITRAQ_IDXTASK));
  1153     pTask->setText(m_pTasks->currentText());
  1155     m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXREMARK, m_pRemark->text());
  1158 //
  1159 // Edit menu configure preferences
  1160 //
  1161 void Titraqform::configPrefs(void)
  1163     QString Templine;               // Used for preferences resetting
  1164     Prefpanel *pUserpanel = NULL;   // The user preferences panel itself
  1166     // Create a new preferences panel window
  1167     pUserpanel = new Prefpanel(this, "Userprefpanel");
  1168     connect(pUserpanel, SIGNAL(applied(void)), SLOT(applyPrefs(void)));
  1170     // Set default values to appear in initialized panel widgets
  1171     pUserpanel->setAccounts(m_pPrefs->getString(TITRAQ_PREFACCOUNTS, TITRAQ_DEFACCOUNTS));
  1172     pUserpanel->setEvents(m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR));
  1173     pUserpanel->setUser(m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER));
  1174     pUserpanel->setHome(m_pPrefs->getString(TITRAQ_PREFHOME, TITRAQ_DEFHOME));
  1175     pUserpanel->setCorbahost(m_pPrefs->getString(TITRAQ_PREFCORBHOST, TITRAQ_DEFCORBHOST));
  1176     pUserpanel->setSoaphost(m_pPrefs->getString(TITRAQ_PREFSOAPHOST, TITRAQ_DEFSOAPHOST));
  1177 #ifdef HAVE_MICO
  1178     pUserpanel->setCorbaon(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON));
  1179 #else
  1180     pUserpanel->setCorbaon(false);
  1181     pUserpanel->lockCorba();
  1182 #endif
  1183 #ifdef HAVE_ESOAP
  1184     pUserpanel->setSoapon(m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON));
  1185 #else
  1186     pUserpanel->setSoapon(false);
  1187     pUserpanel->lockSoap();
  1188 #endif
  1189     pUserpanel->setBackon(m_pPrefs->getBool(TITRAQ_PREFBAKON, TITRAQ_DEFBAKON));
  1190     pUserpanel->setExtendon(m_pPrefs->getBool(TITRAQ_PREFEXTENDON, TITRAQ_DEFEXTENDON));
  1191     pUserpanel->setDetailon(m_pPrefs->getBool(TITRAQ_PREFDETAILON, TITRAQ_DEFDETAILON));
  1192     pUserpanel->setSignaton(m_pPrefs->getBool(TITRAQ_PREFSIGNATON, TITRAQ_DEFSIGNATON));
  1194     // Set default style which can be more complicated due to mapping...
  1195     switch (m_pPrefs->getNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE)) {
  1196     case TITRAQ_STYLECDE:
  1197         pUserpanel->setStyle(TITRAQ_STRCDE);
  1198         break;
  1199     case TITRAQ_STYLESGI:
  1200         pUserpanel->setStyle(TITRAQ_STRSGI);
  1201         break;
  1202     case TITRAQ_STYLEMOTIF:
  1203         pUserpanel->setStyle(TITRAQ_STRMOTIF);
  1204         break;
  1205     case TITRAQ_STYLEMPLUS:
  1206         pUserpanel->setStyle(TITRAQ_STRMPLUS);
  1207         break;
  1208     case TITRAQ_STYLEPLAT:
  1209         pUserpanel->setStyle(TITRAQ_STRPLAT);
  1210         break;
  1211     case TITRAQ_STYLEMSOFT:
  1212         pUserpanel->setStyle(TITRAQ_STRMSOFT);
  1213         break;
  1214     default:
  1215         pUserpanel->setStyle(TITRAQ_STRCDE);    // My personal favourite ;-)
  1216         break;
  1219     // Colour preferences
  1220     int nRed, nGreen, nBlue;
  1221     QColorGroup Origcolour, Altcolour;
  1222     const QColor Origlight = QColor(TITRAQ_DEFLIGHTRED, TITRAQ_DEFLIGHTGREEN, TITRAQ_DEFLIGHTBLUE);
  1223     const QColor Origdark  = QColor(TITRAQ_DEFDARKRED, TITRAQ_DEFDARKGREEN, TITRAQ_DEFDARKBLUE);
  1224     const QColor Altlight = QColor(TITRAQ_DEFLTALTRED, TITRAQ_DEFLTALTGREEN, TITRAQ_DEFLTALTBLUE);
  1225     const QColor Altdark  = QColor(TITRAQ_DEFDKALTRED, TITRAQ_DEFDKALTGREEN, TITRAQ_DEFDKALTBLUE);
  1227     // Set colours to revert to if user screws up and wants out
  1228     Origcolour.setColor(QColorGroup::Foreground, Origlight);
  1229     Origcolour.setColor(QColorGroup::Background, Origdark);
  1230     pUserpanel->setOrigcolour(&Origcolour);
  1231     Altcolour.setColor(QColorGroup::Foreground, Altlight);
  1232     Altcolour.setColor(QColorGroup::Background, Altdark);
  1233     pUserpanel->setAltcolour(&Altcolour);
  1235     // Set colour preferences saved from last session
  1236     nRed   = m_pPrefs->getNumber(TITRAQ_PREFLIGHTRED, TITRAQ_DEFLIGHTRED);
  1237     nGreen = m_pPrefs->getNumber(TITRAQ_PREFLIGHTGREEN, TITRAQ_DEFLIGHTGREEN);
  1238     nBlue  = m_pPrefs->getNumber(TITRAQ_PREFLIGHTBLUE, TITRAQ_DEFLIGHTBLUE);
  1239     const QColor Lightshade = QColor(nRed, nGreen, nBlue);
  1240     pUserpanel->setLight(&Lightshade);
  1241     nRed   = m_pPrefs->getNumber(TITRAQ_PREFDARKRED, TITRAQ_DEFDARKRED);
  1242     nGreen = m_pPrefs->getNumber(TITRAQ_PREFDARKGREEN, TITRAQ_DEFDARKGREEN);
  1243     nBlue  = m_pPrefs->getNumber(TITRAQ_PREFDARKBLUE, TITRAQ_DEFDARKBLUE);
  1244     const QColor Darkshade = QColor(nRed, nGreen, nBlue);
  1245     pUserpanel->setDark(&Darkshade);
  1247     // Modal panel handler
  1248     if (pUserpanel->exec() == QDialog::Accepted)
  1249         this->applyPrefs(pUserpanel);
  1251     // Dispose Panel object
  1252     delete pUserpanel;
  1255 //
  1256 // View menu normal
  1257 //
  1258 void Titraqform::normalView(void)
  1260     // All view types except normal are disabled until implemention, so
  1261     // this body can remain empty, causing nothing to happen on selection.
  1264 //
  1265 // View menu editing
  1266 //
  1267 void Titraqform::editingView(void)
  1269     // All view types except normal are disabled until implemention, so
  1270     // this body can remain empty, causing nothing to happen on selection.
  1273 //
  1274 // View menu timing
  1275 //
  1276 void Titraqform::timingView(void)
  1278     // All view types except normal are disabled until implemention, so
  1279     // this body can remain empty, causing nothing to happen on selection.
  1282 //
  1283 // View menu show file toolbar
  1284 //
  1285 void Titraqform::showFilebar(void)
  1287     if (m_pFiletools->isVisible()) {
  1288         m_pFiletools->hide();
  1289         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR), false);
  1291     else {
  1292         m_pFiletools->show();
  1293         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR), true);
  1297 //
  1298 // View menu show edit toolbar
  1299 //
  1300 void Titraqform::showEditbar(void)
  1302     if (m_pEdittools->isVisible()) {
  1303         m_pEdittools->hide();
  1304         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR), false);
  1306     else {
  1307         m_pEdittools->show();
  1308         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR), true);
  1312 //
  1313 // View menu show view toolbar
  1314 //
  1315 void Titraqform::showViewbar(void)
  1317     if (m_pViewtools->isVisible()) {
  1318         m_pViewtools->hide();
  1319         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXVIEWBAR), false);
  1321     else {
  1322         m_pViewtools->show();
  1323         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXVIEWBAR), true);
  1327 //
  1328 // View menu show prefs toolbar
  1329 //
  1330 void Titraqform::showPrefsbar(void)
  1332     if (m_pPrefstools->isVisible()) {
  1333         m_pPrefstools->hide();
  1334         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXPREFBAR), false);
  1336     else {
  1337         m_pPrefstools->show();
  1338         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXPREFBAR), true);
  1342 //
  1343 // View menu show whats this toolbar
  1344 //
  1345 void Titraqform::showWhatsbar(void)
  1347     if (m_pWhatstools->isVisible()) {
  1348         m_pWhatstools->hide();
  1349         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), false);
  1351     else {
  1352         m_pWhatstools->show();
  1353         m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), true);
  1357 //
  1358 // View menu show status column
  1359 //
  1360 void Titraqform::showStatcol(void)
  1362     // Test if column is currently shown, conditionally show or hide it
  1363     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL))) {
  1364         m_pMaintable->hideColumn(TITRAQ_IDXSTATUS);
  1365         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL), false);
  1366         m_pStatusedit->hide();
  1368     else {
  1369         m_pMaintable->showColumn(TITRAQ_IDXSTATUS);
  1370         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL), true);
  1371         m_pStatusedit->show();
  1374     // Make sure switch take place right away and sizes are handled
  1375     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXSTATCOL));
  1376     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1379 //
  1380 // View menu show line numbers column
  1381 //
  1382 void Titraqform::showLinecol(void)
  1384     // Test if column is currently shown, conditionally show or hide it
  1385     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL))) {
  1386         m_pMaintable->hideColumn(TITRAQ_IDXLINE);
  1387         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL), false);
  1388         m_pLineedit->hide();
  1390     else {
  1391         m_pMaintable->showColumn(TITRAQ_IDXLINE);
  1392         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL), true);
  1393         m_pLineedit->show();
  1396     // Make sure switch take place right away and sizes are handled
  1397     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXLCOL));
  1398     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1401 //
  1402 // View menu show users column
  1403 //
  1404 void Titraqform::showUsercol(void)
  1406     // Test if column is currently shown, conditionally show or hide it
  1407     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL))) {
  1408         m_pMaintable->hideColumn(TITRAQ_IDXUSER);
  1409         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL), false);
  1410         m_pUseredit->hide();
  1412     else {
  1413         m_pMaintable->showColumn(TITRAQ_IDXUSER);
  1414         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL), true);
  1415         m_pUseredit->show();
  1418     // Make sure switch take place right away and sizes are handled
  1419     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1420     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXUCOL));
  1423 //
  1424 // View menu show GUIDs column
  1425 //
  1426 void Titraqform::showGuidcol(void)
  1428     // Test if column is currently shown, conditionally show or hide it
  1429     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL))) {
  1430         m_pMaintable->hideColumn(TITRAQ_IDXGUID);
  1431         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL), false);
  1432         m_pGuidedit->hide();
  1434     else {
  1435         m_pMaintable->showColumn(TITRAQ_IDXGUID);
  1436         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL), true);
  1437         m_pGuidedit->show();
  1440     // Make sure switch take place right away and sizes are handled
  1441     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXGCOL));
  1442     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1445 //
  1446 // View menu show CRC column
  1447 //
  1448 void Titraqform::showCrccol(void)
  1450     // Test if column is currently shown, conditionally show or hide it
  1451     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL))) {
  1452         m_pMaintable->hideColumn(TITRAQ_IDXCRC);
  1453         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL), false);
  1454         m_pCrcedit->hide();
  1456     else {
  1457         m_pMaintable->showColumn(TITRAQ_IDXCRC);
  1458         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL), true);
  1459         m_pCrcedit->show();
  1462     // Make sure switch take place right away and sizes are handled
  1463     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXCCOL));
  1464     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1467 //
  1468 // View menu show Rev column
  1469 //
  1470 void Titraqform::showRevcol(void)
  1472     // Test if column is currently shown, conditionally show or hide it
  1473     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL))) {
  1474         m_pMaintable->hideColumn(TITRAQ_IDXREV);
  1475         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL), false);
  1476         m_pRevedit->hide();
  1478     else {
  1479         m_pMaintable->showColumn(TITRAQ_IDXREV);
  1480         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL), true);
  1481         m_pRevedit->show();
  1484     // Make sure switch take place right away and sizes are handled
  1485     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXREVCOL));
  1486     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1489 //
  1490 // View menu show dates column
  1491 //
  1492 void Titraqform::showDatecol(void)
  1494     // Test if column is currently shown, conditionally show or hide it
  1495     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL))) {
  1496         m_pMaintable->hideColumn(TITRAQ_IDXDATE);
  1497         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL), false);
  1498         m_pDateedit->hide();
  1500     else {
  1501         m_pMaintable->showColumn(TITRAQ_IDXDATE);
  1502         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL), true);
  1503         m_pDateedit->show();
  1506     // Make sure switch take place right away and sizes are handled
  1507     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXDCOL));
  1508     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1511 //
  1512 // View menu show start time column
  1513 //
  1514 void Titraqform::showStartcol(void)
  1516     // Test if column is currently shown, conditionally show or hide it
  1517     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL))) {
  1518         m_pMaintable->hideColumn(TITRAQ_IDXSTART);
  1519         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL), false);
  1520         m_pStarttime->hide();
  1522     else {
  1523         m_pMaintable->showColumn(TITRAQ_IDXSTART);
  1524         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL), true);
  1525         m_pStarttime->show();
  1528     // Make sure switch take place right away and sizes are handled
  1529     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL));
  1530     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1533 //
  1534 // View menu show finish time column
  1535 //
  1536 void Titraqform::showFinishcol(void)
  1538     // Test if column is currently shown, conditionally show or hide it
  1539     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL))) {
  1540         m_pMaintable->hideColumn(TITRAQ_IDXFINISH);
  1541         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL), false);
  1542         m_pEndtime->hide();
  1544     else {
  1545         m_pMaintable->showColumn(TITRAQ_IDXFINISH);
  1546         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL), true);
  1547         m_pEndtime->show();
  1550     // Make sure switch take place right away and sizes are handled
  1551     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXFCOL));
  1552     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1555 //
  1556 // View menu show Amounts column
  1557 //
  1558 void Titraqform::showAmountcol(void)
  1560     // Test if column is currently shown, conditionally show or hide it
  1561     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL))) {
  1562         m_pMaintable->hideColumn(TITRAQ_IDXAMOUNT);
  1563         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL), false);
  1564         m_pAmount->hide();
  1566     else {
  1567         m_pMaintable->showColumn(TITRAQ_IDXAMOUNT);
  1568         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL), true);
  1569         m_pAmount->show();
  1572     // Make sure switch take place right away and sizes are handled
  1573     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXACOL));
  1574     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1577 //
  1578 // View menu show tasks column
  1579 //
  1580 void Titraqform::showTaskcol(void)
  1582     // Test if column is currently shown, conditionally show or hide it
  1583     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXTCOL))) {
  1584         m_pMaintable->hideColumn(TITRAQ_IDXTASK);
  1585         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXTCOL), false);
  1586         m_pTasks->hide();
  1588     else {
  1589         m_pMaintable->showColumn(TITRAQ_IDXTASK);
  1590         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXTCOL), true);
  1591         m_pTasks->show();
  1594     // Make sure switch take place right away and sizes are handled
  1595     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXTCOL));
  1596     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1599 //
  1600 // View menu show Remarks column
  1601 //
  1602 void Titraqform::showRemarkcol(void)
  1604     // Test if column is currently shown, conditionally show or hide it
  1605     if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL))) {
  1606         m_pMaintable->hideColumn(TITRAQ_IDXREMARK);
  1607         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL), false);
  1608         m_pRemark->hide();
  1610     else {
  1611         m_pMaintable->showColumn(TITRAQ_IDXREMARK);
  1612         m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL), true);
  1613         m_pRemark->show();
  1616     // Make sure switch take place right away and sizes are handled
  1617     //m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXREMCOL));
  1618     this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next
  1621 //
  1622 // Generate a local formatted report
  1623 //
  1624 void Titraqform::genReport(void)
  1626     try { // Create and execute a new local report window
  1627         std::auto_ptr<AS::Reportpanel> pReport(new AS::Reportpanel
  1628             (m_pMaintable, m_pPrefs, this, "Locreportpanel"));
  1629         pReport->exec();
  1630         delete pReport.release(); // Technically unnecessary, smart pointer
  1632     catch (Genexcept& Genex) {
  1633         Genex.reportErr();
  1634         return;
  1638 //
  1639 // Syncronize data with server using IIOP
  1640 //
  1641 void Titraqform::syncIiop(void)
  1643 #ifdef HAVE_MICO
  1644     // Short circuit if user has disabled CORBA transmission in prefs
  1645     if (!m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON))
  1646         return;
  1648     char **ppcInargv = NULL;    // Parameters to the ORB
  1649     CORBA::ORB_var Orb;         // The ORB iself
  1651     CORBA::Object_var Nameobj;      // Name service reference
  1652     CosNaming::NamingContext_var Namectx; // COSS ns context
  1653     CosNaming::Name Cosname;        // Our requested obj name
  1655     CORBA::Object_var Objcaster;    // Generic CORBA object
  1656     Asdatabase_var Asdbase;         // Casted object to ASDB
  1657     Astuple Singlerow;              // A single row of AS data
  1659     QString *pOrbargv = new QString(TITRAQ_ORBINIT);
  1660     int nCount = pOrbargv->count(' ');
  1661     int nNamesize = 0;
  1663     // Build a false incoming argv with which we initialize the ORB
  1664     ppcInargv = new char *[nCount + 3]; // 3 = arg0 + last section + COSS host
  1665     *ppcInargv = new char[strlen(*qApp->argv() + 2)]; // For cmd name
  1666     strcpy(ppcInargv[0], *qApp->argv());              // Copy cmd name
  1667     for (int nIter = 0; nIter <= nCount; nIter++) {
  1668         QString Section = pOrbargv->section(' ', nIter, nIter);
  1669         ppcInargv[nIter + 1] = new char[strlen(Section.ascii() + 2)];
  1670         strcpy(ppcInargv[nIter + 1], Section.ascii());
  1673     // Build the single string COSS naming host name with associated port number
  1674     *pOrbargv = TITRAQ_COSSPART1
  1675               + m_pPrefs->getString(TITRAQ_PREFCORBHOST, TITRAQ_DEFCORBHOST)
  1676               + TITRAQ_COSSPART2;
  1677     nNamesize = strlen(pOrbargv->ascii());
  1678     ppcInargv[nCount + 2] = new char[nNamesize];
  1679     strcpy(ppcInargv[nCount + 2], pOrbargv->ascii());
  1681     try {
  1682         // Initialization of the ORB and COSS naming service
  1683         nCount = nCount + 3; // Raise the count to include app, last sec, COSS
  1684         Orb = CORBA::ORB_init(nCount, ppcInargv, "mico-local-orb");
  1685         Nameobj = Orb->resolve_initial_references("NameService");
  1686         Namectx = CosNaming::NamingContext::_narrow(Nameobj);
  1687         if (CORBA::is_nil(Namectx)) { // Verify sanity
  1688             m_pStatbar->message(trUtf8("Could not find the COSS naming service"));
  1689             qWarning("Could not find the COSS naming service\n");
  1692         // Clean up our dynamically allocated array
  1693         for (int nIter = 0; nIter < nCount; nIter++)
  1694             delete ppcInargv[nIter];
  1695         delete ppcInargv; // Free the array itself
  1696         delete pOrbargv;  // Free the intermediate string
  1698         // Prepare the COSS name request
  1699         Cosname.length(1);
  1700         Cosname[0].id = CORBA::string_dup("Asdatabase");
  1701         Cosname[0].kind = CORBA::string_dup("");
  1703         try { // Resolve to a CORBA object
  1704             Objcaster = Namectx->resolve(Cosname);
  1706         catch (CosNaming::NamingContext::NotFound &Cossex) {
  1707             m_pStatbar->message(trUtf8("NotFound exception thrown"));
  1708             qWarning("NotFound exception thrown\n");
  1709             return;
  1711         catch (CosNaming::NamingContext::CannotProceed &Cossex) {
  1712             m_pStatbar->message(trUtf8("CannotProceed exception thrown"));
  1713             qWarning("CannotProceed exception thrown\n");
  1714             return;
  1716         catch (CosNaming::NamingContext::InvalidName &Cossex) {
  1717             m_pStatbar->message(trUtf8("InvalidName exception thrown"));
  1718             qWarning("InvalidName exception thrown\n");
  1719             return;
  1722         // Cast the generic CORBA object to a AS database type
  1723         Asdbase = Asdatabase::_narrow(Objcaster);
  1724         if (CORBA::is_nil(Asdbase)) { // Verify sanity
  1725             m_pStatbar->message(trUtf8("Could not find the AS database"));
  1726             qWarning("Could not find the AS database\n");
  1727             return;
  1730         // Open an account object on the remote server
  1731         Account_var Account = Asdbase->Open("/tmp/events.as");
  1732         if (CORBA::is_nil(Account)) { // Verify sanity
  1733             m_pStatbar->message(trUtf8("Could not create an account object on the server"));
  1734             qWarning("Could not create an account object on the server\n");
  1735             return;
  1738         // Fill account log object(s) to marshall and transmit
  1739         int nRow = m_pMaintable->currentRow();
  1740         Q3TableSelection Select = m_pMaintable->selection(0);    // Capture selected rows
  1741         int nTotal = Select.bottomRow() - Select.topRow() + 1;  // Total rows selected
  1743         // Remember, CORBA::stri_dup creates smart pointers
  1744         for (int nIter = 0; nIter < nTotal; nIter++) {
  1745             Singlerow.szUser   = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXUSER));
  1746             Singlerow.szGuid   = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXGUID));
  1747             Singlerow.szCrc    = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXCRC).remove("0x"));
  1748             Singlerow.szRev    = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXREV));
  1749             Singlerow.szDate   = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXDATE));
  1750             Singlerow.szStart  = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXSTART));
  1751             Singlerow.szFinish = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXFINISH));
  1752             Singlerow.szAmount = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXAMOUNT));
  1753 //            Singlerow.nRev     = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXREV).toUInt();
  1754 //            Singlerow.nDate    = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXDATE).toUInt();
  1755 //            Singlerow.nStart   = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXSTART).toUInt();
  1756 //            Singlerow.nFinish  = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXFINISH).toUInt();
  1757 //            Singlerow.nAmount  = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXAMOUNT).toUInt();
  1758             Singlerow.szTask   = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXTASK));
  1759             Singlerow.szRemark = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXREMARK));
  1760             Account->Log(Singlerow); // Finally transmit to server
  1763         m_pStatbar->message(trUtf8("Successful transmission of accounting data"));
  1765     catch (const CORBA::Exception &Corbex) {
  1766         m_pStatbar->message(trUtf8("Caught CORBA exception: %1").arg(Corbex._repoid()));
  1767         qWarning("Caught CORBA exception: %s", Corbex._repoid());
  1769     catch (...) {
  1770         qWarning("Caught unknown exception\n");
  1772 #endif // HAVE_MICO
  1775 //
  1776 // Syncronize data with server using SOAP
  1777 //
  1778 void Titraqform::syncSoap(void)
  1780 #ifdef HAVE_ESOAP
  1781     // Short circuit if user has disabled SOAP transmission in prefs
  1782     if (!m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON))
  1783         return;
  1785     USING_EASYSOAP_NAMESPACE
  1787     try {
  1788         SOAPMethod Logmeth("Log", TITRAQ_SOAPSPACE); // SOAP namespace
  1789         SOAPString Clistr;                  // Outgoing parameter to marshall
  1790         int nCrc;                           // SOAP unmarshalled return value
  1792         // Build the single string SOAP end point which look like this:
  1793         //   "http://www.europalab.com/cgi-bin/asdbserv"
  1794         QString Endpoint;
  1795         Endpoint = TITRAQ_PREFIXHTTP + m_pPrefs->getString(TITRAQ_PREFSOAPHOST, TITRAQ_DEFSOAPHOST);
  1796         SOAPProxy Proxy(Endpoint.ascii());
  1798         // Fill account log object(s) to marshall and transmit
  1799         Q3TableSelection Select = m_pMaintable->selection(0);    // Capture selected rows
  1800         int nTotal = Select.bottomRow() - Select.topRow() + 1;  // Total rows selected
  1802         // Iterate through the selection of row entries to transmit
  1803         for (int nRowiter = 0; nRowiter < nTotal; nRowiter++) {
  1804             QString Syncthis = m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXUSER);
  1805             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXGUID);
  1806             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXCRC).remove("0x");
  1807             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXREV);
  1808             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXDATE);
  1809             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXSTART);
  1810             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXFINISH);
  1811             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXAMOUNT);
  1812             Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXTASK);
  1813             Syncthis += ' ' + ('"' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXREMARK)) + '"';
  1814             Clistr = Syncthis;                          // Build RPC parameter
  1815             Logmeth.AddParameter("Tuple") << Clistr;    // Prepare for marshalling
  1816             const SOAPResponse &Logresp = Proxy.Execute(Logmeth);
  1817             Logresp.GetReturnValue() >> nCrc;
  1819         m_pStatbar->message(trUtf8("Successful transmission, CRC returned %1").arg(nCrc));
  1821     catch (SOAPException& Soapex) { // Announce the exception we received
  1822         m_pStatbar->message(trUtf8("Caught SOAP exception: %1").arg(Soapex.What().Str()));
  1823         qDebug("Caught SOAP exception: %s", Soapex.What().Str());
  1825     catch (...) {
  1826         qDebug("Caught unknown exception\n");
  1828 #endif // HAVE_ESOAP
  1831 //
  1832 // Save user preferences
  1833 //
  1834 void Titraqform::savePrefs(void)
  1836     // Get check status from column menu and pass it to prefs handler
  1837     m_pPrefs->setBool(TITRAQ_PREFSTATCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL)));
  1838     m_pPrefs->setBool(TITRAQ_PREFLCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL)));
  1839     m_pPrefs->setBool(TITRAQ_PREFUCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL)));
  1840     m_pPrefs->setBool(TITRAQ_PREFGCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL)));
  1841     m_pPrefs->setBool(TITRAQ_PREFCCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL)));
  1842     m_pPrefs->setBool(TITRAQ_PREFREVCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL)));
  1843     m_pPrefs->setBool(TITRAQ_PREFDCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL)));
  1844     m_pPrefs->setBool(TITRAQ_PREFSTARTCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL)));
  1845     m_pPrefs->setBool(TITRAQ_PREFFCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL)));
  1846     m_pPrefs->setBool(TITRAQ_PREFACOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL)));
  1847     m_pPrefs->setBool(TITRAQ_PREFFCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL)));
  1848     m_pPrefs->setBool(TITRAQ_PREFREMCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL)));
  1850     // Get check status from toolbar menu and pass it to prefs handler
  1851     m_pPrefs->setBool(TITRAQ_PREFFILEBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR)));
  1852     m_pPrefs->setBool(TITRAQ_PREFEDITBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR)));
  1853     m_pPrefs->setBool(TITRAQ_PREFVIEWBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXVIEWBAR)));
  1854     m_pPrefs->setBool(TITRAQ_PREFPREFBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXPREFBAR)));
  1855     m_pPrefs->setBool(TITRAQ_PREFWHATBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR)));
  1857     // Get column widths from main table and pass it to prefs handler
  1858     if (m_pMaintable->columnWidth(TITRAQ_IDXSTATUS) > 0)
  1859         m_pPrefs->setNumber(TITRAQ_PREFSTATCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXSTATUS));
  1860     if (m_pMaintable->columnWidth(TITRAQ_IDXLINE) > 0)
  1861         m_pPrefs->setNumber(TITRAQ_PREFLCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXLINE));
  1862     if (m_pMaintable->columnWidth(TITRAQ_IDXUSER) > 0)
  1863         m_pPrefs->setNumber(TITRAQ_PREFUCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXUSER));
  1864     if (m_pMaintable->columnWidth(TITRAQ_IDXGUID) > 0)
  1865         m_pPrefs->setNumber(TITRAQ_PREFGCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXGUID));
  1866     if (m_pMaintable->columnWidth(TITRAQ_IDXCRC) > 0)
  1867         m_pPrefs->setNumber(TITRAQ_PREFCCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXCRC));
  1868     if (m_pMaintable->columnWidth(TITRAQ_IDXREV) > 0)
  1869         m_pPrefs->setNumber(TITRAQ_PREFREVCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXREV));
  1870     if (m_pMaintable->columnWidth(TITRAQ_IDXDATE) > 0)
  1871         m_pPrefs->setNumber(TITRAQ_PREFDCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXDATE));
  1872     if (m_pMaintable->columnWidth(TITRAQ_IDXSTART) > 0)
  1873         m_pPrefs->setNumber(TITRAQ_PREFSTARTCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXSTART));
  1874     if (m_pMaintable->columnWidth(TITRAQ_IDXFINISH) > 0)
  1875         m_pPrefs->setNumber(TITRAQ_PREFFCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXFINISH));
  1876     if (m_pMaintable->columnWidth(TITRAQ_IDXAMOUNT) > 0)
  1877         m_pPrefs->setNumber(TITRAQ_PREFACOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXAMOUNT));
  1878     if (m_pMaintable->columnWidth(TITRAQ_IDXTASK) > 0)
  1879         m_pPrefs->setNumber(TITRAQ_PREFTCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXTASK));
  1880     if (m_pMaintable->columnWidth(TITRAQ_IDXREMARK) > 0)
  1881         m_pPrefs->setNumber(TITRAQ_PREFREMCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXREMARK));
  1883     // Get sorting order and direction from table and pass it to prefs handler
  1884     m_pPrefs->setNumber(TITRAQ_PREFSORTCOL, (long)m_pMaintable->getSortcol());
  1885     m_pPrefs->setBool(TITRAQ_PREFSORTDIR, (long)m_pMaintable->getSortdir());
  1887     // Set frame geometry preferences
  1888     m_pPrefs->setNumber(TITRAQ_PREFFRAMEWIDTH, (long)this->width());
  1889     m_pPrefs->setNumber(TITRAQ_PREFFRAMEHEIGHT, (long)this->height());
  1891     // Remember main window layout and doc positions
  1892     QString Laystring;
  1893     Q3TextStream Laystream(&Laystring, QIODevice::WriteOnly);
  1894     //Laystream << *this; // Persist the main window
  1895     m_pPrefs->setString(TITRAQ_PREFFRAMELAY, Laystring);
  1898 //
  1899 // Get help on Titraq functionality
  1900 //
  1901 void Titraqform::helpContents(void)
  1903     try { // Create and execute a new help contents window
  1904         std::auto_ptr<AS::Helpanel> pHelpcont(new AS::Helpanel(TITRAQ_REFHELP, this, "Helpanel"));
  1905         pHelpcont->exec();
  1906         delete pHelpcont.release(); // Technically unnecessary, smart pointer
  1908     catch (Genexcept& Genex) {
  1909         Genex.reportErr();
  1910         return;
  1914 //
  1915 // Learn more about this program itself
  1916 //
  1917 void Titraqform::aboutTitraq(void)
  1919     QString Namever = QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short;
  1920     QMessageBox *pCwmsg = new QMessageBox(Namever,
  1921         QObject::trUtf8("The as-gui is a time and task-based accounting\n"
  1922                "system that acts as both a work-like punch card and\n"
  1923                "time tracker. Development of as-gui is sponsored by\n"
  1924                "Cable & Wireless Telecommunications Services GmbH."),
  1925         QMessageBox::NoIcon, QMessageBox::Ok | QMessageBox::Default,
  1926         QMessageBox::NoButton, QMessageBox::NoButton,
  1927         NULL, "Titraqmessage", true, Qt::WStyle_NormalBorder);
  1929     pCwmsg->setIconPixmap(QPixmap(s_kpcCwlogo_xpm));
  1930     pCwmsg->exec();
  1933 //
  1934 // Learn more about the OSSP
  1935 //
  1936 void Titraqform::aboutOSSP(void)
  1938     QString Namever = QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short;
  1939     QMessageBox *pOsspmsg = new QMessageBox(Namever,
  1940         QObject::trUtf8("The open source software project (OSSP) is\n"
  1941                "a collective effort aimed at implementing\n"
  1942                "high-quality Unix software components,\n"
  1943                "ranging from networking, multi-threading\n"
  1944                "and algorithmic libraries to networking\n"
  1945                "servers and development tools."),
  1946         QMessageBox::NoIcon, QMessageBox::Ok | QMessageBox::Default,
  1947         QMessageBox::NoButton, QMessageBox::NoButton,
  1948         NULL, "Osspmessage", true, Qt::WStyle_NormalBorder);
  1950     pOsspmsg->setIconPixmap(QPixmap(s_kpcOssplogo_xpm));
  1951     pOsspmsg->exec();
  1954 //
  1955 // Learn more about this program and Qt
  1956 //
  1957 void Titraqform::aboutQt(void)
  1959     QMessageBox::aboutQt(this, QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short);
  1962 //
  1963 // Apply preference values from a signal emitting object
  1964 //
  1965 void Titraqform::applyPrefs(void)
  1967     Prefpanel *pPan = (Prefpanel *)QObject::sender();
  1968     this->applyPrefs(pPan);
  1971 //
  1972 // Accept preference values from a inbound Panel object
  1973 //
  1974 void Titraqform::applyPrefs(Prefpanel *pPrefpanel)
  1976     m_pPrefs->setString(TITRAQ_PREFACCOUNTS, pPrefpanel->getAccounts());
  1977     m_pPrefs->setString(TITRAQ_PREFASDIR, pPrefpanel->getEvents());
  1978     m_pPrefs->setString(TITRAQ_PREFUSER, pPrefpanel->getUser());
  1979     m_pPrefs->setString(TITRAQ_PREFHOME, pPrefpanel->getHome());
  1980     m_pPrefs->setString(TITRAQ_PREFCORBHOST, pPrefpanel->getCorbahost());
  1981     m_pPrefs->setString(TITRAQ_PREFSOAPHOST, pPrefpanel->getSoaphost());
  1982     m_pPrefs->setBool(TITRAQ_PREFCORBON, pPrefpanel->getCorbaon());
  1983     m_pPrefs->setBool(TITRAQ_PREFSOAPON, pPrefpanel->getSoapon());
  1984     m_pPrefs->setBool(TITRAQ_PREFBAKON, pPrefpanel->getBackon());
  1985     m_pPrefs->setBool(TITRAQ_PREFEXTENDON, pPrefpanel->getExtendon());
  1986     m_pPrefs->setBool(TITRAQ_PREFDETAILON, pPrefpanel->getDetailon());
  1987     m_pPrefs->setBool(TITRAQ_PREFSIGNATON, pPrefpanel->getSignaton());
  1988     m_pPrefs->setNumber(TITRAQ_PREFLIGHTRED, pPrefpanel->getLight()->red());
  1989     m_pPrefs->setNumber(TITRAQ_PREFLIGHTGREEN, pPrefpanel->getLight()->green());
  1990     m_pPrefs->setNumber(TITRAQ_PREFLIGHTBLUE, pPrefpanel->getLight()->blue());
  1991     m_pPrefs->setNumber(TITRAQ_PREFDARKRED, pPrefpanel->getDark()->red());
  1992     m_pPrefs->setNumber(TITRAQ_PREFDARKGREEN, pPrefpanel->getDark()->green());
  1993     m_pPrefs->setNumber(TITRAQ_PREFDARKBLUE, pPrefpanel->getDark()->blue());
  1995     // Dim the lights if no RPC transports are available
  1996     if (this->isOpen())
  1997         m_pSyncact->setEnabled(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON)
  1998             | m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON));
  1999     else
  2000         m_pSyncact->setEnabled(false);
  2002     // Get the selected style which can be more complicated due to mapping...
  2003     if (pPrefpanel->getStyle() == TITRAQ_STRCDE) {
  2004         m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE);
  2005         qApp->setStyle(new QCDEStyle);
  2007     //else if (pPrefpanel->getStyle() == TITRAQ_STRSGI) {    // Not supported
  2008     //    m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLESGI);
  2009     //    qApp->setStyle(new QSGIStyle);
  2010     //}
  2011     else if (pPrefpanel->getStyle() == TITRAQ_STRMOTIF) {
  2012         m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEMOTIF);
  2013         qApp->setStyle(new QMotifStyle);
  2015     //else if (pPrefpanel->getStyle() == TITRAQ_STRMPLUS) {  // Not supported
  2016     //    m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEMPLUS);
  2017     //    qApp->setStyle(new QMotifPlusStyle);
  2018     //}
  2019     //else if (pPrefpanel->getStyle() == TITRAQ_STRPLAT) {  // Not supported
  2020     //    m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEPLAT);
  2021     //    qApp->setStyle(new QPlatinumStyle);
  2022     //}
  2023     else if (pPrefpanel->getStyle() == TITRAQ_STRMSOFT) {
  2024         m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEMSOFT);
  2025         qApp->setStyle(new QWindowsStyle);
  2027     else // My personal favourite ;-)
  2028         m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE);

mercurial