michael@1: // michael@1: // OSSP asgui - Accounting system graphical user interface michael@1: // Copyright (c) 2002-2004 The OSSP Project (http://www.ossp.org/) michael@1: // Copyright (c) 2002-2004 Ralf S. Engelschall michael@1: // Copyright (c) 2002-2004 Michael Schloh von Bennewitz michael@1: // Copyright (c) 2002-2004 Cable & Wireless Telecommunications Services GmbH michael@1: // michael@1: // This file is part of OSSP asgui, an accounting system graphical user michael@1: // interface which can be found at http://www.ossp.org/pkg/tool/asgui/. michael@1: // michael@1: // Permission to use, copy, modify, and distribute this software for michael@1: // any purpose with or without fee is hereby granted, provided that michael@1: // the above copyright notice and this permission notice appear in all michael@1: // copies. michael@1: // michael@1: // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED michael@1: // WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF michael@1: // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. michael@1: // IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR michael@1: // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@1: // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@1: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF michael@1: // USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND michael@1: // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, michael@1: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT michael@1: // OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF michael@1: // SUCH DAMAGE. michael@1: // michael@1: // as_slot.cpp: ISO C++ implementation michael@1: // michael@1: michael@1: // system headers michael@1: #include michael@1: #include michael@1: michael@1: // Qt headers michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: michael@1: // Qt style headers michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: #include michael@1: michael@1: // User interface michael@1: #include "as_const.h" // Application constants michael@1: #include "as_except.h" // Exception classes michael@1: #include "as_tableitem.h" // For our custom table items michael@1: #include "as_generic.h" // Generic classes michael@1: #include "as_uuid.h" // UUID classes michael@1: #include "as_datedit.h" // Derived from QDateEdit michael@1: #include "as_amount.h" // Derived from QTimeEdit michael@1: #include "as_crc.h" // Useful Qualistring class michael@1: #include "as_pref.h" // For Preferences class michael@1: #include "as_panel.h" // For Prefpanel class michael@1: #include "as_reportpanel.h" // For Reportpanel class michael@1: #include "as_helpanel.h" // For Helpanel class michael@1: #include "as_sfile.h" // For Simplefile class michael@1: #include "as_table.h" // For TiTable class michael@1: michael@1: // RPC headers michael@1: #ifdef HAVE_ESOAP michael@1: #include michael@1: #endif // HAVE_ESOAP michael@1: #ifdef HAVE_MICO michael@1: #include michael@1: #include "as_stub.h" // CORBA stubs and skeletons michael@1: #endif // HAVE_MICO michael@1: michael@1: // Icon pixel maps michael@1: #include "as_gfx/cwlogo.xpm" // static const char *s_kpcCwlogo_xpm[] michael@1: #include "as_gfx/ossplogo.xpm" // static const char *s_kpcOssplogo_xpm[] michael@1: #include "as_gfx/statok.xpm" // static const char *s_kpcStatokay_xpm[] michael@1: #include "as_gfx/staterr.xpm" // static const char *s_kpcStaterror_xpm[] michael@1: #include "as_gfx/statwrn.xpm" // static const char *s_kpcStatwarn_xpm[] michael@1: #include "as_gfx/statvoid.xpm" // static const char *s_kpcStatvoid_xpm[] michael@1: michael@1: michael@1: // michael@1: // Cut an entry michael@1: // michael@1: void Titraqform::cutEntry(void) michael@1: { michael@1: this->copyEntry(); // Reuse slot michael@1: this->delEntry(); // Reuse slot michael@1: } michael@1: michael@1: // michael@1: // Copy an entry michael@1: // michael@1: void Titraqform::copyEntry(void) michael@1: { michael@1: QString Selection; // Will hold the selected text michael@1: QClipboard *pClip; // Will reference the global clipboard michael@1: michael@1: // Initialize data and clipboard handle michael@1: Selection = getRowdata(); // Use accessor michael@1: pClip = QApplication::clipboard(); michael@1: michael@1: Q_ASSERT(!Selection.isNull()); michael@1: pClip->setText(Selection, QClipboard::Selection); // Doesn't work on Windows michael@1: pClip->setText(Selection, QClipboard::Clipboard); // Works on both equally michael@1: } michael@1: michael@1: // michael@1: // Paste an entry michael@1: // michael@1: void Titraqform::pasteEntry(void) michael@1: { michael@1: int nRows = 0; // Paste so many rows as are stored michael@1: QString Selection; // Will receive the clipboard text michael@1: QClipboard *pClip = NULL; // Will reference the global clipboard michael@1: michael@1: pClip = QApplication::clipboard(); // Prime the clips michael@1: Selection = pClip->text(QClipboard::Clipboard); // Windows and Unix michael@1: nRows = Selection.contains(QChar('\n')); // How many rows michael@1: if (Selection != NULL && nRows > 0) { // Ignore empty clipboards michael@1: this->addEntry(nRows); // Reuse slot michael@1: setRowdata(Selection); // Use accessor michael@1: michael@1: // Update line numbers for this new row and all subsequent rows michael@1: for (int nIter = m_pMaintable->currentRow(); nIter < m_pMaintable->numRows(); nIter++) michael@1: m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter).rightJustify(4, QChar('0'))); michael@1: michael@1: // Do basic data validation to warn against missing fields michael@1: for (int nIter = 0; nIter < nRows; nIter++) michael@1: this->validateRow(m_pMaintable->currentRow() + nIter, 0); michael@1: michael@1: m_pStatbar->message(QString::number(nRows) + trUtf8(" rows pasted"), 4000); michael@1: updEdit(m_pMaintable->currentRow()); // Reflect in the update controls michael@1: } michael@1: else // Well, I guess the user tried to paste an empty clipboard michael@1: m_pStatbar->message(trUtf8("The clipboard is empty"), 4000); michael@1: } michael@1: michael@1: // michael@1: // Append a blank row entry michael@1: // michael@1: void Titraqform::addEntry(int nRows) michael@1: { michael@1: QTableSelection Select; // Highlighted text michael@1: int nTotal = 0; // Total row select michael@1: int nCurrent = 0; // Current row michael@1: std::auto_ptr pGuid(new AS::Uuid); // For GUID production michael@1: michael@1: // Decide how many rows to add michael@1: Select = m_pMaintable->selection(0); michael@1: if (nRows > 0) michael@1: nTotal = nRows; michael@1: else michael@1: nTotal = Select.bottomRow() - Select.topRow() + 1; michael@1: michael@1: // Optimize viewing by repainting cells only once after processing michael@1: m_pMaintable->setUpdatesEnabled(false); michael@1: michael@1: // Add a row after selection and focus to the new row michael@1: if (Select.bottomRow() + 1 != m_pMaintable->numRows()) { // Add upwards michael@1: m_pMaintable->insertRows(Select.topRow(), nTotal); michael@1: m_pMaintable->setDirty(); // Set data to dirty state michael@1: m_pMaintable->setCurrentCell(Select.topRow(), m_pMaintable->currentColumn()); michael@1: michael@1: // According to Trolltech, insertRows() "clears the selection(s)". michael@1: // They are pretty wrong about that, so unfortunately we'll have to michael@1: // take care of the dirty work ourselves with a clearSelection(). michael@1: m_pMaintable->clearSelection(false); michael@1: m_pMaintable->selectRow(m_pMaintable->currentRow()); michael@1: michael@1: // Update relevant data fields for all new rows michael@1: for (int nIter = 0; nIter < nTotal; nIter++) { michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXSTATUS, QString(QChar('W'))); michael@1: m_pMaintable->setPixmap(Select.topRow() + nIter, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatwarn_xpm)); michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXUSER, m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER)); michael@1: pGuid->genId(); michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXGUID, pGuid->getString()); michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXCRC, "0"); // 0 = invalid entry michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXREV, "0"); // Entry not revised michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXDATE, QDate::currentDate().toString(Qt::ISODate)); michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXSTART, "00:00"); michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXFINISH, "00:00"); michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXAMOUNT, "00:00"); michael@1: // m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXTASK, "/"); michael@1: // m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXREMARK, "Remark"); michael@1: m_pMaintable->setText(Select.topRow() + nIter, TITRAQ_IDXCRC, "1"); // 0 = invalid entry michael@1: this->calcCrc(Select.topRow() + nIter, -1); michael@1: } michael@1: } michael@1: else { // Special case on last row add downwards michael@1: m_pMaintable->insertRows(Select.bottomRow() + 1, nTotal); michael@1: m_pMaintable->setDirty(); // Set data to dirty state michael@1: m_pMaintable->setCurrentCell(Select.bottomRow() + 1, m_pMaintable->currentColumn()); michael@1: michael@1: // According to Trolltech, insertRows() "clears the selection(s)". michael@1: // They are pretty wrong about that, so unfortunately we'll have to michael@1: // take care of the dirty work ourselves with a clearSelection(). michael@1: m_pMaintable->clearSelection(false); michael@1: m_pMaintable->selectRow(m_pMaintable->currentRow()); michael@1: michael@1: // Update relevant data fields for all new rows michael@1: for (int nIter = 1; nIter <= nTotal; nIter++) { michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXSTATUS, QString(QChar('W'))); michael@1: m_pMaintable->setPixmap(Select.bottomRow() + nIter, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatwarn_xpm)); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXUSER, m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER)); michael@1: pGuid->genId(); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXGUID, pGuid->getString()); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXCRC, "0"); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXREV, "0"); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXDATE, QDate::currentDate().toString(Qt::ISODate)); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXSTART, "00:00"); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXFINISH, "00:00"); michael@1: m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXAMOUNT, "00:00"); michael@1: // m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXTASK, "/"); michael@1: // m_pMaintable->setText(Select.bottomRow() + nIter, TITRAQ_IDXREMARK, "Remark"); michael@1: this->calcCrc(Select.bottomRow() + nIter, -1); michael@1: } michael@1: } michael@1: michael@1: // Update line numbers for this new row and all subsequent rows michael@1: for (int nIter = m_pMaintable->currentRow(); nIter < m_pMaintable->numRows(); nIter++) michael@1: m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter).rightJustify(4, QChar('0'))); michael@1: michael@1: updEdit(m_pMaintable->currentRow()); // Reflect in the update controls michael@1: m_pStatusedit->setPixmap(QPixmap(s_kpcStatwarn_xpm)); // Show pixmap michael@1: michael@1: m_pMaintable->setUpdatesEnabled(true); // Turn updates back on michael@1: m_pMaintable->repaintContents(true); // Do a general repaint of table michael@1: m_pMaintable->ensureCellVisible(m_pMaintable->currentRow() + nTotal - 1, m_pMaintable->currentColumn()); michael@1: m_pMaintable->ensureCellVisible(m_pMaintable->currentRow(), m_pMaintable->currentColumn()); michael@1: michael@1: // In case we added the first and only row entry, michael@1: // do post state adjustments like icon undimming michael@1: if (m_pMaintable->numRows() == 1) { michael@1: m_pDelrowact->setEnabled(true); michael@1: m_pRefreshact->setEnabled(true); michael@1: m_pCutact->setEnabled(true); michael@1: m_pCopyact->setEnabled(true); michael@1: michael@1: // Brighten all the edit controls also michael@1: m_pLineedit->setEnabled(true); michael@1: m_pUseredit->setEnabled(true); michael@1: m_pGuidedit->setEnabled(true); michael@1: m_pCrcedit->setEnabled(true); michael@1: m_pRevedit->setEnabled(true); michael@1: m_pDateedit->setEnabled(true); michael@1: m_pStarttime->setEnabled(true); michael@1: m_pEndtime->setEnabled(true); michael@1: m_pAmount->setEnabled(true); michael@1: m_pTasks->setEnabled(true); michael@1: m_pRemark->setEnabled(true); michael@1: michael@1: // And optionally the RPC actions, too michael@1: #if defined HAVE_MICO || defined HAVE_ESOAP michael@1: m_pSyncact->setEnabled(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON) michael@1: | m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON)); michael@1: #endif // HAVE_MICO || defined HAVE_ESOAP michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Delete a row entry michael@1: // michael@1: void Titraqform::delEntry(int nRows) michael@1: { michael@1: QTableSelection Select = m_pMaintable->selection(0); // Highlighted text michael@1: int nTotal = Select.bottomRow() - Select.topRow() + 1; // Total row select michael@1: QMemArray Rowselect(nTotal); // Row array michael@1: michael@1: // Calculate rows to delete from selection highlight michael@1: for (int nIter = 0; nIter < nTotal; ++nIter) michael@1: Rowselect[nIter] = Select.topRow() + nIter; michael@1: michael@1: // Remove the row at selection and focus to the next row michael@1: if (m_pMaintable->currentRow() + 1 != m_pMaintable->numRows()) { michael@1: m_pMaintable->setCurrentCell(Select.bottomRow() + 1, m_pMaintable->currentColumn()); michael@1: m_pMaintable->removeRows(Rowselect); michael@1: m_pMaintable->setDirty(); // Set data to dirty state michael@1: } michael@1: else { // Special case to handle removing of only row or last row michael@1: m_pMaintable->removeRows(Rowselect); michael@1: m_pMaintable->setDirty(); // Set data to dirty state michael@1: } michael@1: michael@1: // Update line numbers for this new row and all subsequent rows michael@1: for (int nIter = m_pMaintable->currentRow(); nIter < m_pMaintable->numRows(); nIter++) michael@1: m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter)); michael@1: michael@1: // In case we removed the last remaining row, michael@1: // do post state adjustments like icon dimming michael@1: if (m_pMaintable->numRows() <= 0) { michael@1: m_pDelrowact->setEnabled(false); michael@1: m_pRefreshact->setEnabled(false); michael@1: m_pCutact->setEnabled(false); michael@1: m_pCopyact->setEnabled(false); michael@1: michael@1: // Dim all the edit controls also michael@1: m_pStatusedit->setPixmap(s_kpcStatvoid_xpm); michael@1: m_pLineedit->setEnabled(false); michael@1: m_pUseredit->setEnabled(false); michael@1: m_pGuidedit->setEnabled(false); michael@1: m_pCrcedit->setEnabled(false); michael@1: m_pRevedit->setEnabled(false); michael@1: m_pDateedit->setEnabled(false); michael@1: m_pStarttime->setEnabled(false); michael@1: m_pEndtime->setEnabled(false); michael@1: m_pAmount->setEnabled(false); michael@1: m_pTasks->setEnabled(false); michael@1: m_pRemark->setEnabled(false); michael@1: michael@1: // And optionally dim the RPC actions michael@1: #if defined HAVE_MICO || defined HAVE_ESOAP michael@1: m_pSyncact->setEnabled(false); michael@1: #endif // HAVE_MICO || defined HAVE_ESOAP michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Refresh the display of all data items michael@1: // michael@1: void Titraqform::refreshDisplay(void) michael@1: { michael@1: int nIter = 0; // Matrix iterator michael@1: int nRows = m_pMaintable->numRows(); // Total number of rows michael@1: michael@1: // Sweep through matrix validating linewise michael@1: // data and updating line numbers for all rows michael@1: while (nIter < nRows) { michael@1: this->validateRow(nIter, 0); michael@1: m_pMaintable->setText(nIter, TITRAQ_IDXLINE, QString::number(nIter).rightJustify(4, QChar('0'))); michael@1: nIter++; michael@1: } michael@1: michael@1: m_pMaintable->repaintContents(false); // Do a general repaint of table michael@1: m_pStatbar->message(trUtf8("Display was refreshed"), 4000); // Announce result michael@1: } michael@1: michael@1: // michael@1: // Make and display a new document window michael@1: // michael@1: void Titraqform::newDoc(void) michael@1: { michael@1: int nResult = 0; // Holds return value from save first messagebox michael@1: michael@1: // Check modification state of current data michael@1: if (m_pMaintable->isDirty()) { michael@1: nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE) michael@1: + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST), michael@1: trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2); michael@1: michael@1: switch (nResult) { michael@1: case 0: // First button selected, so save first michael@1: this->saveFile(); // Save changes first michael@1: break; michael@1: case 1: // Second button selected, so don't save michael@1: break; michael@1: case 2: // Third button selected, so return sofort michael@1: default: michael@1: m_pStatbar->message(trUtf8("New aborted"), 4000); michael@1: return; michael@1: break; michael@1: } michael@1: } michael@1: michael@1: if (!m_pMaintable->isDirty() || nResult == 1) { // Check modification state michael@1: // Fall through to implicit new doc code michael@1: this->setCaption(trUtf8("No file name")); michael@1: m_pStatbar->message(trUtf8("New document"), 4000); michael@1: this->enableIface(true); // Enable the interface michael@1: m_pMaintable->setNumRows(0); // Remove all data in table michael@1: this->setFilename(""); // Signal a closed doc state michael@1: this->addEntry(1); // Default new op adds a row michael@1: m_pMaintable->setDirty(false); // Start out clean michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Open and display an existing document michael@1: // michael@1: void Titraqform::openDoc(void) michael@1: { michael@1: int nResult = 0; // Holds return value from save first messagebox michael@1: michael@1: // michael@1: // This block will guide the user to saving the contents of the timesheet michael@1: // before losing them in an open operation. The question and dialog box will michael@1: // not be raised if no open timesheet exists or if it was just serialized. michael@1: // michael@1: if (m_pMaintable->isDirty()) { // Check modification state michael@1: nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE) michael@1: + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST), michael@1: trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2); michael@1: michael@1: switch (nResult) { michael@1: case 0: // Save first michael@1: this->saveFile(); // Save changes first michael@1: break; michael@1: case 1: // Don't save first but do load michael@1: break; michael@1: case 2: // Don't do a load timesheet michael@1: default: michael@1: m_pStatbar->message(trUtf8("Loading aborted"), 4000); michael@1: return; michael@1: break; michael@1: } michael@1: } michael@1: michael@1: // michael@1: // This block ensures that conditions of first block logic were met if michael@1: // applicable. If so, the user gives a file name to open or cancels the michael@1: // operation. The corresponding file will be opened, and if this is michael@1: // unsuccessful then the post state is exactly the same as the pre state. michael@1: // michael@1: if (!m_pMaintable->isDirty() || nResult == 1) { // Check modification state michael@1: // Make sure we correctly get the name of the default file to open michael@1: QString Openas = m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR); michael@1: if (Openas.startsWith(TITRAQ_HOMEDIRTOK)) michael@1: Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1); michael@1: michael@1: // This dialog asks which file the user wants to open michael@1: QString Filestring = QFileDialog::getOpenFileName(Openas, michael@1: trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), michael@1: this, trUtf8("ChooserDialog"), trUtf8("Choose a file to open"), NULL, false); michael@1: michael@1: // We might have a filename to work on, so do something with it michael@1: if (!Filestring.isEmpty()) { michael@1: QFile Filetemp(Filestring); // File to load michael@1: try { michael@1: if (Filetemp.exists() && validateData(Filetemp)) { // Be extra sure michael@1: setFilename(Filestring); // Set the new file name michael@1: m_pMaintable->setNumRows(0); // Clear out old data michael@1: m_pMaintable->setDirty(false); // Reset dirty flag michael@1: loadData(Filetemp); // Pass to helper method michael@1: this->setCaption(Filestring); // Caption in the titlebar michael@1: m_pStatbar->message(trUtf8("Loaded document ") + Filestring, 4000); michael@1: this->enableIface(true); // Turn on the lights michael@1: this->setOpen(true); // Indicate doc is open michael@1: } michael@1: } michael@1: catch (Genexcept& Genex) { // Crap, we failed michael@1: m_pStatbar->message(trUtf8("Loading failed"), 4000); michael@1: Genex.reportErr(); michael@1: return; michael@1: } michael@1: } michael@1: else // An empty filename returning from the file dialog means cancel michael@1: m_pStatbar->message(trUtf8("Loading aborted"), 4000); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Serialize current state to the current file michael@1: // michael@1: void Titraqform::saveFile(void) michael@1: { michael@1: QString Fname; michael@1: Simplefile Filevents; michael@1: michael@1: try { michael@1: Fname = *this->getFilename(); michael@1: michael@1: // First time saves are really just saveName in disguise michael@1: if (Fname.isEmpty()) { michael@1: try { michael@1: this->saveName(); // Try to 'save as' michael@1: return; // and short circuit michael@1: } michael@1: catch (Genexcept& Genex) { michael@1: // Genex.reportErr(); // Report the error michael@1: return; // and short circuit michael@1: } michael@1: } michael@1: michael@1: Filevents.setName(Fname); // Construct a file to write michael@1: if (m_pPrefs->getBool(TITRAQ_PREFBAKON, TITRAQ_DEFBAKON)) michael@1: Filevents.makeBackup(); // Back up to filename.bak michael@1: this->saveData(Filevents); // Pass to helper method michael@1: } michael@1: catch (Genexcept& Genex) { michael@1: Genex.reportErr(); michael@1: } michael@1: // Reset and give output to main window michael@1: this->setCaption(Fname); michael@1: m_pStatbar->message(trUtf8("File %1 saved").arg(Fname), 4000); michael@1: m_pMaintable->setDirty(false); // Set the clean state to allow close michael@1: } michael@1: michael@1: // michael@1: // Serialize current state to a selected file michael@1: // michael@1: void Titraqform::saveAs(void) michael@1: { michael@1: int nResult = 0; // For checking user's answer michael@1: michael@1: // Make sure we correctly get the name of the default file to open michael@1: QString Openas = m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR); michael@1: if (Openas.startsWith(TITRAQ_HOMEDIRTOK)) michael@1: Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1); michael@1: michael@1: // And then get the name of the selected file to save to michael@1: QString Filestring = QFileDialog::getSaveFileName(Openas, trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false); michael@1: if (!Filestring.isEmpty()) { michael@1: if (QFile::exists(Filestring)) { michael@1: nResult = QMessageBox::warning(this, QString(TITRAQ_APPTITLE) michael@1: + ' ' + asgui_version.v_short, trUtf8(TITRAQ_OVERWRITE), michael@1: trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1); michael@1: switch (nResult) { michael@1: case 0: // Overwrite contents michael@1: this->setFilename(Filestring); michael@1: this->saveFile(); michael@1: break; michael@1: case 1: // Don't overwrite michael@1: default: michael@1: break; michael@1: } michael@1: } michael@1: else { michael@1: // Conditionally use a unique extension like '.as' if user prefers michael@1: if (m_pPrefs->getBool(TITRAQ_PREFEXTENDON, TITRAQ_DEFEXTENDON)) { michael@1: QString Extension = TITRAQ_FEXTENSION; // Logic to handle michael@1: if (!Filestring.endsWith(Extension)) // AS file extension michael@1: Filestring += Extension; // insertion michael@1: } michael@1: this->setFilename(Filestring); // Set filename of object first michael@1: this->saveFile(); // Finish by calling the save action michael@1: } michael@1: } michael@1: else michael@1: // User did not select a valid file and push okay button michael@1: m_pStatbar->message(trUtf8("Saving aborted"), 4000); michael@1: } michael@1: michael@1: // michael@1: // Implicitly serialize current state to a selected file michael@1: // The main difference with saveAs is that this uses exceptions michael@1: // michael@1: void Titraqform::saveName(void) michael@1: { michael@1: int nResult = 0; // For checking user's answer michael@1: michael@1: // Make sure we correctly get the name of the default file to open michael@1: QString Openas = m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR); michael@1: if (Openas.startsWith(TITRAQ_HOMEDIRTOK)) michael@1: Openas = QDir::homeDirPath() + Openas.remove(0, QString(TITRAQ_HOMEDIRTOK).length() - 1); michael@1: michael@1: nResult = 1; // We loop on this dialog only if an indecisive user michael@1: while (nResult > 0) { // is hesitant to overwrite a file over and over again michael@1: QString Filestring = QFileDialog::getSaveFileName(Openas, trUtf8("Accounting Data (*.as);;Text files (*.txt);;All Files (*)"), this, trUtf8("ChooserDialog"), trUtf8("Choose a file to save"), NULL, false); michael@1: if (!Filestring.isEmpty()) { michael@1: if (QFile::exists(Filestring)) { michael@1: nResult = QMessageBox::warning(this, QString(TITRAQ_APPTITLE) michael@1: + ' ' + asgui_version.v_short, trUtf8(TITRAQ_OVERWRITE), michael@1: trUtf8("&Yes"), trUtf8("&No"), NULL, 1, 1); michael@1: switch (nResult) { michael@1: case 0: // Overwrite contents michael@1: this->setFilename(Filestring); michael@1: this->saveFile(); michael@1: break; michael@1: case 1: // Don't overwrite michael@1: default: michael@1: break; michael@1: } michael@1: } michael@1: else { michael@1: michael@1: // Conditionally use a unique extension like '.as' if user prefers michael@1: if (m_pPrefs->getBool(TITRAQ_PREFEXTENDON, TITRAQ_DEFEXTENDON)) { michael@1: QString Extension = TITRAQ_FEXTENSION; // Logic to handle michael@1: if (!Filestring.endsWith(Extension)) // AS file extension michael@1: Filestring += Extension; // insertion michael@1: } michael@1: this->setFilename(Filestring); // Set filename of object first michael@1: nResult = 0; // Reset our loop control michael@1: this->saveFile(); // Finish by calling the save action michael@1: } michael@1: } michael@1: else { michael@1: // User did not select a valid file and push okay button michael@1: m_pStatbar->message(trUtf8("Saving aborted"), 4000); michael@1: throw Genexcept(TITRAQ_SAVECANCELLED); michael@1: } michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Close current document, and then quit the application michael@1: // michael@1: void Titraqform::quitApp(void) michael@1: { michael@1: int nResult = 0; michael@1: michael@1: if (m_pMaintable->isDirty()) { michael@1: nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE) michael@1: + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST), michael@1: trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2); michael@1: michael@1: switch (nResult) { // Maybe save before closing michael@1: case 0: // Save first michael@1: this->saveFile(); // Save changes first michael@1: break; michael@1: case 1: // Don't save first michael@1: m_pMaintable->setDirty(false); michael@1: break; michael@1: case 2: // Do nothing michael@1: default: michael@1: return; // Go away without closing michael@1: break; michael@1: } michael@1: } michael@1: michael@1: // We should be clean now, but double check just in case michael@1: if (!m_pMaintable->isDirty()) michael@1: qApp->quit(); michael@1: } michael@1: michael@1: // michael@1: // Close current document, displaying in main window michael@1: // michael@1: void Titraqform::closeEvent(QCloseEvent *pClosit) michael@1: { michael@1: int nResult = 0; michael@1: michael@1: if (!this->isOpen()) // Short circuit if user michael@1: qApp->quit(); // selects close twice michael@1: michael@1: // Check modification state of current data michael@1: if (m_pMaintable->isDirty()) { michael@1: nResult = QMessageBox::information(this, QString(TITRAQ_APPTITLE) michael@1: + ' ' + asgui_version.v_short, trUtf8(TITRAQ_SAVEFIRST), michael@1: trUtf8("&Save"), trUtf8("&Discard"), trUtf8("Cancel"), 0, 2); michael@1: michael@1: switch (nResult) { // Maybe save before closing michael@1: case 0: // Save first michael@1: this->saveFile(); // Save changes first michael@1: break; michael@1: case 1: // Don't save first michael@1: m_pMaintable->setDirty(false); michael@1: break; michael@1: case 2: // Do nothing michael@1: default: michael@1: pClosit->ignore(); michael@1: return; // Go away without closing michael@1: break; michael@1: } michael@1: } michael@1: michael@1: if (!m_pMaintable->isDirty()) { // Check again michael@1: // Fall through to implicit close code michael@1: this->setCaption(QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short); michael@1: try { // There might be problems, so wrap these last ops with error handling michael@1: QString Lightsout; // It's late, go to bed michael@1: if (this->isOpen()) michael@1: Lightsout = trUtf8("Closed document ") + *this->getFilename(); michael@1: this->setOpen(false); // Set doc state to closed michael@1: this->enableIface(false); // Turn off the lights michael@1: m_pStatbar->message(Lightsout, 4000); michael@1: } michael@1: catch (Genexcept& Genex) { michael@1: Genex.reportErr(); michael@1: } michael@1: } michael@1: pClosit->ignore(); // Finish off by not closing michael@1: } michael@1: michael@1: // michael@1: // Edit menu select all entries michael@1: // michael@1: void Titraqform::selAll(void) michael@1: { michael@1: Prototype Unimp; michael@1: Unimp.doMbox(); michael@1: } michael@1: michael@1: // michael@1: // Edit a table entry in place, without the usual edit controls michael@1: // michael@1: void Titraqform::inplaceEdit(int nRow, int nCol, int nButton, const QPoint &Mousepos) michael@1: { michael@1: // Table read only attribute must be reset here, so that editing can take michael@1: // place. Otherwise calls to editCell are ignored (for obvious reasons). michael@1: m_pMaintable->setReadOnly(false); michael@1: michael@1: // After editCell() is called, beginEdit() and endEdit() execute. The read michael@1: // only attribute is reset in endEdit() to return everything to normal. michael@1: m_pMaintable->editCell(nRow, nCol); michael@1: michael@1: m_pMaintable->setEdition(nCol); michael@1: } michael@1: michael@1: // michael@1: // Update the edit controls widget sizes michael@1: // michael@1: void Titraqform::updSizes(int nSection, int nOldsize, int nNewsize) michael@1: { michael@1: switch (nSection) { michael@1: case TITRAQ_IDXALLCTRLS: michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) > 0) michael@1: m_pStatusedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) > 0) michael@1: m_pLineedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) > 0) michael@1: m_pUseredit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) > 0) michael@1: m_pGuidedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) > 0) michael@1: m_pCrcedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) > 0) michael@1: m_pRevedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) > 0) michael@1: m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) > 0) michael@1: m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) > 0) michael@1: m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) > 0) michael@1: m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING); michael@1: if (m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) > 0) michael@1: m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING); michael@1: // if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXRCOL))) michael@1: // m_pRemark->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREMARK) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXSTATUS: michael@1: m_pStatusedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXLINE: michael@1: m_pLineedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXUSER: michael@1: m_pUseredit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXGUID: michael@1: m_pGuidedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXCRC: michael@1: m_pCrcedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXREV: michael@1: m_pRevedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXDATE: michael@1: m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXSTART: michael@1: m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXFINISH: michael@1: m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXAMOUNT: michael@1: m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXTASK: michael@1: m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING); michael@1: break; michael@1: case TITRAQ_IDXREMARK: michael@1: // m_pRemark->setFixedWidth(nNewsize); michael@1: break; michael@1: default: michael@1: throw Genexcept("Unrecognized main window column header."); michael@1: break; michael@1: } michael@1: michael@1: // As a last and redundant step, adjust size of first visible control michael@1: switch(this->getFirstcol()) { michael@1: case TITRAQ_IDXSTATUS: michael@1: m_pStatusedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTATUS) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXLINE: michael@1: m_pLineedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXLINE) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXUSER: michael@1: m_pUseredit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXUSER) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXGUID: michael@1: m_pGuidedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXGUID) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXCRC: michael@1: m_pCrcedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXCRC) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXREV: michael@1: m_pRevedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXREV) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXDATE: michael@1: m_pDateedit->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXDATE) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXSTART: michael@1: m_pStarttime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXSTART) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXFINISH: michael@1: m_pEndtime->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXFINISH) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXAMOUNT: michael@1: m_pAmount->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXAMOUNT) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: case TITRAQ_IDXTASK: michael@1: m_pTasks->setFixedWidth(m_pMaintable->horizontalHeader()->sectionSize(TITRAQ_IDXTASK) - TITRAQ_SPACING + TITRAQ_SPACING / 2); michael@1: break; michael@1: default: // Probably no columns are visible? michael@1: break; michael@1: } michael@1: } michael@1: michael@1: // michael@1: // What to do if a data cell is modified michael@1: // michael@1: void Titraqform::dataChanged(int nRow, int nCol) michael@1: { michael@1: if (nCol != TITRAQ_IDXSTATUS && nCol != TITRAQ_IDXLINE) michael@1: m_pMaintable->setDirty(); // Mark this timesheet dirty, changes pending save michael@1: } michael@1: michael@1: // michael@1: // Convenience member calculates CRC for current row michael@1: // michael@1: void Titraqform::calcCrc(void) michael@1: { michael@1: this->calcCrc(-1, -1); michael@1: } michael@1: michael@1: // michael@1: // Calculates CRC for the specified row, fires when data is changed michael@1: // michael@1: void Titraqform::calcCrc(int nRow, int nCol) michael@1: { michael@1: if (nCol != TITRAQ_IDXSTATUS && nCol != TITRAQ_IDXLINE \ michael@1: && m_pMaintable->numRows() > 0) { michael@1: U32 Testcrc, Valcrc; michael@1: QString Crcstr; michael@1: std::auto_ptrpWholerow(new Qualistring); michael@1: int nRealrow = -1; michael@1: michael@1: // Build the data that will be used in testing CRC calculation michael@1: nRealrow = (nRow >= 0) ? nRow : m_pMaintable->currentRow(); michael@1: *pWholerow = m_pMaintable->text(nRealrow, TITRAQ_IDXUSER); michael@1: for (int nIter = TITRAQ_IDXUSER + 1; nIter < TITRAQ_IDXTAIL; nIter++) michael@1: if (nIter != TITRAQ_IDXCRC) // Don't checksum the checksum! michael@1: *pWholerow += m_pMaintable->text(nRealrow, nIter); michael@1: michael@1: // Update the checksum and revision only if necessary michael@1: Testcrc = pWholerow->getCrc(); michael@1: michael@1: // FIXME: This thing is not very unportable, because toUInt != U32 michael@1: if (Testcrc != m_pMaintable->text(nRealrow, TITRAQ_IDXCRC).toUInt()) { michael@1: michael@1: // // Bump the revision number of our entry to control conflicts michael@1: // nNewrev = m_pMaintable->text(nRealrow, TITRAQ_IDXREV).toInt() + 1; michael@1: // m_pMaintable->setText(nRealrow, TITRAQ_IDXREV, QString::number(nNewrev)); michael@1: michael@1: // Build the data that will be used in setting CRC calculation michael@1: *pWholerow = m_pMaintable->text(nRealrow, TITRAQ_IDXUSER); michael@1: for (int nIter = TITRAQ_IDXUSER + 1; nIter < TITRAQ_IDXTAIL; nIter++) michael@1: if (nIter != TITRAQ_IDXCRC) // Don't checksum the checksum! michael@1: *pWholerow += m_pMaintable->text(nRealrow, nIter); michael@1: michael@1: Valcrc = pWholerow->getCrc(); // Finally set the checksum to its new value michael@1: Crcstr = QString::number(Valcrc, 16).rightJustify(8, '0'); michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXCRC, "0x" + Crcstr); michael@1: m_pCrcedit->setText("0x" + Crcstr); michael@1: } michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Gets a hit on every table click michael@1: // michael@1: void Titraqform::onClick(int nRow, int nCol, int nButton, const QPoint &Mousepos) michael@1: { michael@1: // Give the clueless user some hints when clicking an empty timesheet michael@1: if (m_pMaintable->numRows() <= 0) michael@1: m_pStatbar->message(trUtf8("Empty timesheet, add entries first please"), 2000); michael@1: } michael@1: michael@1: // michael@1: // Update the edit controls contents michael@1: // michael@1: void Titraqform::updEdit(int nRow, int nCol) michael@1: { michael@1: // Why is the app sending negative row signal? I don't know yet, michael@1: // so add in this nasty hack to fend off the debug spew on stderr michael@1: if (m_pMaintable->numRows() > 0 && nRow >= 0) { michael@1: // Field strings to check for validity and process michael@1: QString Textline(m_pMaintable->text(nRow, TITRAQ_IDXLINE)); michael@1: QString Textuser(m_pMaintable->text(nRow, TITRAQ_IDXUSER)); michael@1: QString Textguid(m_pMaintable->text(nRow, TITRAQ_IDXGUID)); michael@1: QString Textcrc(m_pMaintable->text(nRow, TITRAQ_IDXCRC)); michael@1: QString Textrev(m_pMaintable->text(nRow, TITRAQ_IDXREV)); michael@1: QString Textdate(m_pMaintable->text(nRow, TITRAQ_IDXDATE)); michael@1: QString Textstart(m_pMaintable->text(nRow, TITRAQ_IDXSTART)); michael@1: QString Textfinish(m_pMaintable->text(nRow, TITRAQ_IDXFINISH)); michael@1: QString Textamount(m_pMaintable->text(nRow, TITRAQ_IDXAMOUNT)); michael@1: QString Texttask(m_pMaintable->text(nRow, TITRAQ_IDXTASK)); michael@1: QString Textremark(m_pMaintable->text(nRow, TITRAQ_IDXREMARK)); michael@1: michael@1: // Reset the edition state member michael@1: m_pMaintable->setEdition(); michael@1: michael@1: // Set text of member edit controls michael@1: if (m_pMaintable->text(nRow, TITRAQ_IDXSTATUS).isEmpty()) // If row is empty michael@1: m_pStatusedit->setPixmap(s_kpcStatvoid_xpm); // add a placeholder michael@1: else michael@1: m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRow, TITRAQ_IDXSTATUS)); michael@1: m_pLineedit->setText(Textline); michael@1: m_pUseredit->setText(Textuser); michael@1: m_pGuidedit->setText(Textguid); michael@1: m_pCrcedit->setText(Textcrc); michael@1: m_pRevedit->setText(Textrev); michael@1: michael@1: // QRegExp Shorten("/(\\w+)$"); // For stripping prefix off the current task michael@1: // Texttask.remove(0, Shorten.search(Texttask) + 1); // Strip leading slash michael@1: michael@1: m_pRemark->setText(Textremark); michael@1: m_pTasks->setCurrentText(Texttask); michael@1: michael@1: // Date field not suitable for empty string text michael@1: if (Textdate == ".") michael@1: m_pDateedit->setDate(QDate::currentDate()); michael@1: else if (Textdate.isEmpty()) michael@1: m_pDateedit->setDate(QDate::fromString("0000-00-00", Qt::ISODate)); michael@1: else michael@1: m_pDateedit->setDate(QDate::fromString(Textdate, Qt::ISODate)); michael@1: michael@1: // Start time not suitable for empty string text michael@1: if (Textstart == ".") michael@1: m_pStarttime->setTime(QTime::currentTime()); michael@1: else if (Textstart.isEmpty()) michael@1: m_pStarttime->setTime(QTime::QTime(0, 0)); michael@1: else michael@1: m_pStarttime->setTime(QTime::fromString(Textstart, Qt::ISODate)); michael@1: michael@1: // Finish time not suitable for empty string text michael@1: if (Textfinish == ".") michael@1: m_pEndtime->setTime(QTime::currentTime()); michael@1: else if (Textfinish.isEmpty()) michael@1: m_pEndtime->setTime(QTime::QTime(0, 0)); michael@1: else michael@1: m_pEndtime->setTime(QTime::fromString(Textfinish, Qt::ISODate)); michael@1: michael@1: // Amount time not suitable for empty string text michael@1: if (Textamount == ".") { michael@1: int nDifference = m_pStarttime->time().secsTo(m_pEndtime->time()); michael@1: m_pAmount->setTime(QTime(0, 0).addSecs(nDifference)); michael@1: } michael@1: else if (Textamount.isEmpty()) michael@1: m_pAmount->setTime(QTime::QTime(0, 0)); michael@1: else michael@1: m_pAmount->setTime(QTime::fromString(Textamount, Qt::ISODate)); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Validate current row of the matrix michael@1: // michael@1: void Titraqform::validateRow(void) michael@1: { michael@1: this->validateRow(-1, -1); michael@1: } michael@1: michael@1: // michael@1: // Validate specified row of the matrix michael@1: // michael@1: void Titraqform::validateRow(int nRow, int nCol) michael@1: { michael@1: int nRealrow = -1; michael@1: michael@1: if (!this->isOpen()) { // If no data is loaded then short circuit michael@1: m_pStatbar->message(trUtf8("Timesheet contains no data"), 4000); michael@1: return; michael@1: } michael@1: michael@1: nRealrow = (nRow >= 0) ? nRow : m_pMaintable->currentRow(); michael@1: QString Statis = m_pMaintable->text(nRealrow, TITRAQ_IDXSTATUS); // Get text michael@1: michael@1: // Review whole data validity, and set pixmap accordingly michael@1: if (m_pMaintable->text(nRealrow, TITRAQ_IDXUSER).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXGUID).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXCRC).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXREV).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXDATE).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXSTART).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXFINISH).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXAMOUNT).isEmpty() || michael@1: m_pMaintable->text(nRealrow, TITRAQ_IDXTASK).isEmpty()) michael@1: { // No K&R style to show where actual code begins michael@1: if (Statis.startsWith(QString("W"))) { // Conditionally set pixmap to avoid overhead michael@1: // FIXME: Next line commented out, and I see that this algorythm needs help michael@1: // m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS)); michael@1: } michael@1: else if (!Statis.startsWith(QString("E"))) { // Conditionally set pixmap to avoid overhead michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'E')); michael@1: m_pMaintable->setPixmap(nRealrow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStaterror_xpm)); michael@1: m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS)); michael@1: } michael@1: } michael@1: else { michael@1: if (!Statis.startsWith(QString("O"))) { // Conditionally set pixmap to avoid overhead michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXSTATUS, Statis.replace(TITRAQ_IDXSTATERROR, sizeof(char), 'O')); michael@1: m_pMaintable->setPixmap(nRealrow, TITRAQ_IDXSTATUS, QPixmap(s_kpcStatokay_xpm)); michael@1: m_pStatusedit->setPixmap(m_pMaintable->pixmap(nRealrow, TITRAQ_IDXSTATUS)); michael@1: } michael@1: } michael@1: michael@1: // Test for blank user field, and set to default if so michael@1: if (m_pMaintable->text(nRealrow, TITRAQ_IDXUSER).isEmpty()) michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXUSER, m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER)); michael@1: michael@1: // Test for blank date field, and set to default if so michael@1: if (m_pMaintable->text(nRealrow, TITRAQ_IDXDATE) == ".") michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXDATE, QDate::currentDate().toString(Qt::ISODate)); michael@1: michael@1: // Test for blank start field, and set to default if so michael@1: if (m_pMaintable->text(nRealrow, TITRAQ_IDXSTART) == ".") michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXSTART, QTime::currentTime().toString("hh:mm")); michael@1: michael@1: // Test for blank finish field, and set to default if so michael@1: if (m_pMaintable->text(nRealrow, TITRAQ_IDXFINISH) == ".") michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXFINISH, QTime::currentTime().toString("hh:mm")); michael@1: michael@1: // Test for blank amount field, and set to default if so michael@1: if (m_pMaintable->text(nRealrow, TITRAQ_IDXAMOUNT) == ".") { michael@1: QTime Begin = QTime::fromString(m_pMaintable->text(nRealrow, TITRAQ_IDXSTART), Qt::ISODate); michael@1: QTime End = QTime::fromString(m_pMaintable->text(nRealrow, TITRAQ_IDXFINISH), Qt::ISODate); michael@1: QString Diff = QTime(0, 0).addSecs(Begin.secsTo(End)).toString("hh:mm"); michael@1: m_pMaintable->setText(nRealrow, TITRAQ_IDXAMOUNT, Diff); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Update the current line number column item michael@1: // michael@1: void Titraqform::updateLine(const QString &Instring) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXLINE, Instring); michael@1: } michael@1: michael@1: // michael@1: // Update the current user column item michael@1: // michael@1: void Titraqform::updateUser(const QString &Instring) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXUSER, Instring); michael@1: } michael@1: michael@1: // michael@1: // Update the current GUID column item michael@1: // michael@1: void Titraqform::updateGuid(const QString &Instring) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXGUID, Instring); michael@1: } michael@1: michael@1: // michael@1: // Update the current CRC column item michael@1: // michael@1: void Titraqform::updateCrc(const QString &Instring) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXCRC, Instring); michael@1: } michael@1: michael@1: // michael@1: // Update the current rev column item michael@1: // michael@1: void Titraqform::updateRev(const QString &Instring) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXREV, Instring); michael@1: } michael@1: michael@1: // michael@1: // Update the current date column item michael@1: // michael@1: void Titraqform::updateDate(const QDate &Dateup) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXDATE, Dateup.toString(Qt::ISODate)); michael@1: } michael@1: michael@1: // michael@1: // Update the current start column item michael@1: // michael@1: void Titraqform::updateStart(const QTime &Startup) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXSTART, Startup.toString("hh:mm")); michael@1: } michael@1: michael@1: // michael@1: // Update the current finish column item michael@1: // michael@1: void Titraqform::updateFinish(const QTime &Finishup) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXFINISH, Finishup.toString("hh:mm")); michael@1: } michael@1: michael@1: // michael@1: // Update the current amount column item michael@1: // michael@1: void Titraqform::updateAmount(const QTime &Amountup) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXAMOUNT, Amountup.toString("hh:mm")); michael@1: } michael@1: michael@1: // michael@1: // Update the current task column item michael@1: // michael@1: void Titraqform::updateTask(const QString &Taskup) michael@1: { michael@1: // // FIXME: Broken michael@1: // RtTableItem *pTask = NULL; michael@1: // pTask = static_cast(m_pMaintable->item(m_pMaintable->currentRow(), TITRAQ_IDXTASK)); michael@1: // pTask->setText(Taskup); michael@1: michael@1: // Don't try to use the Taskup string, because it ignores autocompletion michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXTASK, m_pTasks->currentText()); michael@1: } michael@1: michael@1: // michael@1: // Update the current remark column item michael@1: // michael@1: void Titraqform::updateRemark(const QString &Remarkup) michael@1: { michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXREMARK, Remarkup); michael@1: } michael@1: michael@1: // michael@1: // Confirm any recent editions on a whole row michael@1: // michael@1: void Titraqform::confirmEdit(void) michael@1: { michael@1: RtTableItem *pTask = NULL; // Task item is a derived class michael@1: michael@1: // Conversions from edit control data formats to native tabular format michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXDATE, m_pDateedit->date().toString(Qt::ISODate)); michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXSTART, m_pStarttime->time().toString(Qt::ISODate)); michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXFINISH, m_pEndtime->time().toString(Qt::ISODate)); michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXAMOUNT, m_pAmount->time().toString(Qt::ISODate)); michael@1: michael@1: // Specially handle task fields michael@1: pTask = static_cast(m_pMaintable->item(m_pMaintable->currentRow(), TITRAQ_IDXTASK)); michael@1: pTask->setText(m_pTasks->currentText()); michael@1: michael@1: m_pMaintable->setText(m_pMaintable->currentRow(), TITRAQ_IDXREMARK, m_pRemark->text()); michael@1: } michael@1: michael@1: // michael@1: // Edit menu configure preferences michael@1: // michael@1: void Titraqform::configPrefs(void) michael@1: { michael@1: QString Templine; // Used for preferences resetting michael@1: Prefpanel *pUserpanel = NULL; // The user preferences panel itself michael@1: michael@1: // Create a new preferences panel window michael@1: pUserpanel = new Prefpanel(this, "Userprefpanel"); michael@1: connect(pUserpanel, SIGNAL(applied(void)), SLOT(applyPrefs(void))); michael@1: michael@1: // Set default values to appear in initialized panel widgets michael@1: pUserpanel->setAccounts(m_pPrefs->getString(TITRAQ_PREFACCOUNTS, TITRAQ_DEFACCOUNTS)); michael@1: pUserpanel->setEvents(m_pPrefs->getString(TITRAQ_PREFASDIR, TITRAQ_DEFASDIR)); michael@1: pUserpanel->setUser(m_pPrefs->getString(TITRAQ_PREFUSER, TITRAQ_DEFUSER)); michael@1: pUserpanel->setHome(m_pPrefs->getString(TITRAQ_PREFHOME, TITRAQ_DEFHOME)); michael@1: pUserpanel->setCorbahost(m_pPrefs->getString(TITRAQ_PREFCORBHOST, TITRAQ_DEFCORBHOST)); michael@1: pUserpanel->setSoaphost(m_pPrefs->getString(TITRAQ_PREFSOAPHOST, TITRAQ_DEFSOAPHOST)); michael@1: #ifdef HAVE_MICO michael@1: pUserpanel->setCorbaon(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON)); michael@1: #else michael@1: pUserpanel->setCorbaon(false); michael@1: pUserpanel->lockCorba(); michael@1: #endif michael@1: #ifdef HAVE_ESOAP michael@1: pUserpanel->setSoapon(m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON)); michael@1: #else michael@1: pUserpanel->setSoapon(false); michael@1: pUserpanel->lockSoap(); michael@1: #endif michael@1: pUserpanel->setBackon(m_pPrefs->getBool(TITRAQ_PREFBAKON, TITRAQ_DEFBAKON)); michael@1: pUserpanel->setExtendon(m_pPrefs->getBool(TITRAQ_PREFEXTENDON, TITRAQ_DEFEXTENDON)); michael@1: pUserpanel->setDetailon(m_pPrefs->getBool(TITRAQ_PREFDETAILON, TITRAQ_DEFDETAILON)); michael@1: pUserpanel->setSignaton(m_pPrefs->getBool(TITRAQ_PREFSIGNATON, TITRAQ_DEFSIGNATON)); michael@1: michael@1: // Set default style which can be more complicated due to mapping... michael@1: switch (m_pPrefs->getNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE)) { michael@1: case TITRAQ_STYLECDE: michael@1: pUserpanel->setStyle(TITRAQ_STRCDE); michael@1: break; michael@1: case TITRAQ_STYLESGI: michael@1: pUserpanel->setStyle(TITRAQ_STRSGI); michael@1: break; michael@1: case TITRAQ_STYLEMOTIF: michael@1: pUserpanel->setStyle(TITRAQ_STRMOTIF); michael@1: break; michael@1: case TITRAQ_STYLEMPLUS: michael@1: pUserpanel->setStyle(TITRAQ_STRMPLUS); michael@1: break; michael@1: case TITRAQ_STYLEPLAT: michael@1: pUserpanel->setStyle(TITRAQ_STRPLAT); michael@1: break; michael@1: case TITRAQ_STYLEMSOFT: michael@1: pUserpanel->setStyle(TITRAQ_STRMSOFT); michael@1: break; michael@1: default: michael@1: pUserpanel->setStyle(TITRAQ_STRCDE); // My personal favourite ;-) michael@1: break; michael@1: } michael@1: michael@1: // Colour preferences michael@1: int nRed, nGreen, nBlue; michael@1: QColorGroup Origcolour, Altcolour; michael@1: const QColor Origlight = QColor(TITRAQ_DEFLIGHTRED, TITRAQ_DEFLIGHTGREEN, TITRAQ_DEFLIGHTBLUE); michael@1: const QColor Origdark = QColor(TITRAQ_DEFDARKRED, TITRAQ_DEFDARKGREEN, TITRAQ_DEFDARKBLUE); michael@1: const QColor Altlight = QColor(TITRAQ_DEFLTALTRED, TITRAQ_DEFLTALTGREEN, TITRAQ_DEFLTALTBLUE); michael@1: const QColor Altdark = QColor(TITRAQ_DEFDKALTRED, TITRAQ_DEFDKALTGREEN, TITRAQ_DEFDKALTBLUE); michael@1: michael@1: // Set colours to revert to if user screws up and wants out michael@1: Origcolour.setColor(QColorGroup::Foreground, Origlight); michael@1: Origcolour.setColor(QColorGroup::Background, Origdark); michael@1: pUserpanel->setOrigcolour(&Origcolour); michael@1: Altcolour.setColor(QColorGroup::Foreground, Altlight); michael@1: Altcolour.setColor(QColorGroup::Background, Altdark); michael@1: pUserpanel->setAltcolour(&Altcolour); michael@1: michael@1: // Set colour preferences saved from last session michael@1: nRed = m_pPrefs->getNumber(TITRAQ_PREFLIGHTRED, TITRAQ_DEFLIGHTRED); michael@1: nGreen = m_pPrefs->getNumber(TITRAQ_PREFLIGHTGREEN, TITRAQ_DEFLIGHTGREEN); michael@1: nBlue = m_pPrefs->getNumber(TITRAQ_PREFLIGHTBLUE, TITRAQ_DEFLIGHTBLUE); michael@1: const QColor Lightshade = QColor(nRed, nGreen, nBlue); michael@1: pUserpanel->setLight(&Lightshade); michael@1: nRed = m_pPrefs->getNumber(TITRAQ_PREFDARKRED, TITRAQ_DEFDARKRED); michael@1: nGreen = m_pPrefs->getNumber(TITRAQ_PREFDARKGREEN, TITRAQ_DEFDARKGREEN); michael@1: nBlue = m_pPrefs->getNumber(TITRAQ_PREFDARKBLUE, TITRAQ_DEFDARKBLUE); michael@1: const QColor Darkshade = QColor(nRed, nGreen, nBlue); michael@1: pUserpanel->setDark(&Darkshade); michael@1: michael@1: // Modal panel handler michael@1: if (pUserpanel->exec() == QDialog::Accepted) michael@1: this->applyPrefs(pUserpanel); michael@1: michael@1: // Dispose Panel object michael@1: delete pUserpanel; michael@1: } michael@1: michael@1: // michael@1: // View menu normal michael@1: // michael@1: void Titraqform::normalView(void) michael@1: { michael@1: // All view types except normal are disabled until implemention, so michael@1: // this body can remain empty, causing nothing to happen on selection. michael@1: } michael@1: michael@1: // michael@1: // View menu editing michael@1: // michael@1: void Titraqform::editingView(void) michael@1: { michael@1: // All view types except normal are disabled until implemention, so michael@1: // this body can remain empty, causing nothing to happen on selection. michael@1: } michael@1: michael@1: // michael@1: // View menu timing michael@1: // michael@1: void Titraqform::timingView(void) michael@1: { michael@1: // All view types except normal are disabled until implemention, so michael@1: // this body can remain empty, causing nothing to happen on selection. michael@1: } michael@1: michael@1: // michael@1: // View menu show file toolbar michael@1: // michael@1: void Titraqform::showFilebar(void) michael@1: { michael@1: if (m_pFiletools->isVisible()) { michael@1: m_pFiletools->hide(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR), false); michael@1: } michael@1: else { michael@1: m_pFiletools->show(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR), true); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // View menu show edit toolbar michael@1: // michael@1: void Titraqform::showEditbar(void) michael@1: { michael@1: if (m_pEdittools->isVisible()) { michael@1: m_pEdittools->hide(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR), false); michael@1: } michael@1: else { michael@1: m_pEdittools->show(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR), true); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // View menu show view toolbar michael@1: // michael@1: void Titraqform::showViewbar(void) michael@1: { michael@1: if (m_pViewtools->isVisible()) { michael@1: m_pViewtools->hide(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXVIEWBAR), false); michael@1: } michael@1: else { michael@1: m_pViewtools->show(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXVIEWBAR), true); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // View menu show prefs toolbar michael@1: // michael@1: void Titraqform::showPrefsbar(void) michael@1: { michael@1: if (m_pPrefstools->isVisible()) { michael@1: m_pPrefstools->hide(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXPREFBAR), false); michael@1: } michael@1: else { michael@1: m_pPrefstools->show(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXPREFBAR), true); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // View menu show whats this toolbar michael@1: // michael@1: void Titraqform::showWhatsbar(void) michael@1: { michael@1: if (m_pWhatstools->isVisible()) { michael@1: m_pWhatstools->hide(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), false); michael@1: } michael@1: else { michael@1: m_pWhatstools->show(); michael@1: m_pTbarspopup->setItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR), true); michael@1: } michael@1: } michael@1: michael@1: // michael@1: // View menu show status column michael@1: // michael@1: void Titraqform::showStatcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXSTATUS); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL), false); michael@1: m_pStatusedit->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXSTATUS); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL), true); michael@1: m_pStatusedit->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXSTATCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show line numbers column michael@1: // michael@1: void Titraqform::showLinecol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXLINE); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL), false); michael@1: m_pLineedit->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXLINE); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL), true); michael@1: m_pLineedit->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXLCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show users column michael@1: // michael@1: void Titraqform::showUsercol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXUSER); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL), false); michael@1: m_pUseredit->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXUSER); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL), true); michael@1: m_pUseredit->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXUCOL)); michael@1: } michael@1: michael@1: // michael@1: // View menu show GUIDs column michael@1: // michael@1: void Titraqform::showGuidcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXGUID); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL), false); michael@1: m_pGuidedit->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXGUID); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL), true); michael@1: m_pGuidedit->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXGCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show CRC column michael@1: // michael@1: void Titraqform::showCrccol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXCRC); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL), false); michael@1: m_pCrcedit->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXCRC); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL), true); michael@1: m_pCrcedit->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXCCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show Rev column michael@1: // michael@1: void Titraqform::showRevcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXREV); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL), false); michael@1: m_pRevedit->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXREV); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL), true); michael@1: m_pRevedit->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXREVCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show dates column michael@1: // michael@1: void Titraqform::showDatecol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXDATE); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL), false); michael@1: m_pDateedit->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXDATE); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL), true); michael@1: m_pDateedit->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXDCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show start time column michael@1: // michael@1: void Titraqform::showStartcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXSTART); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL), false); michael@1: m_pStarttime->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXSTART); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL), true); michael@1: m_pStarttime->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show finish time column michael@1: // michael@1: void Titraqform::showFinishcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXFINISH); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL), false); michael@1: m_pEndtime->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXFINISH); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL), true); michael@1: m_pEndtime->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXFCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show Amounts column michael@1: // michael@1: void Titraqform::showAmountcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXAMOUNT); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL), false); michael@1: m_pAmount->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXAMOUNT); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL), true); michael@1: m_pAmount->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXACOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show tasks column michael@1: // michael@1: void Titraqform::showTaskcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXTCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXTASK); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXTCOL), false); michael@1: m_pTasks->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXTASK); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXTCOL), true); michael@1: m_pTasks->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXTCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // View menu show Remarks column michael@1: // michael@1: void Titraqform::showRemarkcol(void) michael@1: { michael@1: // Test if column is currently shown, conditionally show or hide it michael@1: if (m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL))) { michael@1: m_pMaintable->hideColumn(TITRAQ_IDXREMARK); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL), false); michael@1: m_pRemark->hide(); michael@1: } michael@1: else { michael@1: m_pMaintable->showColumn(TITRAQ_IDXREMARK); michael@1: m_pColspopup->setItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL), true); michael@1: m_pRemark->show(); michael@1: } michael@1: michael@1: // Make sure switch take place right away and sizes are handled michael@1: m_pColspopup->updateItem(m_pColspopup->idAt(TITRAQ_IDXREMCOL)); michael@1: this->updSizes(TITRAQ_IDXALLCTRLS, 0, 0); // Update size of this and next michael@1: } michael@1: michael@1: // michael@1: // Generate a local formatted report michael@1: // michael@1: void Titraqform::genReport(void) michael@1: { michael@1: try { // Create and execute a new local report window michael@1: std::auto_ptr pReport(new AS::Reportpanel michael@1: (m_pMaintable, m_pPrefs, this, "Locreportpanel")); michael@1: pReport->exec(); michael@1: delete pReport.release(); // Technically unnecessary, smart pointer michael@1: } michael@1: catch (Genexcept& Genex) { michael@1: Genex.reportErr(); michael@1: return; michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Syncronize data with server using IIOP michael@1: // michael@1: void Titraqform::syncIiop(void) michael@1: { michael@1: #ifdef HAVE_MICO michael@1: // Short circuit if user has disabled CORBA transmission in prefs michael@1: if (!m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON)) michael@1: return; michael@1: michael@1: char **ppcInargv = NULL; // Parameters to the ORB michael@1: CORBA::ORB_var Orb; // The ORB iself michael@1: michael@1: CORBA::Object_var Nameobj; // Name service reference michael@1: CosNaming::NamingContext_var Namectx; // COSS ns context michael@1: CosNaming::Name Cosname; // Our requested obj name michael@1: michael@1: CORBA::Object_var Objcaster; // Generic CORBA object michael@1: Asdatabase_var Asdbase; // Casted object to ASDB michael@1: Astuple Singlerow; // A single row of AS data michael@1: michael@1: QString *pOrbargv = new QString(TITRAQ_ORBINIT); michael@1: int nCount = pOrbargv->contains(' '); michael@1: int nNamesize = 0; michael@1: michael@1: // Build a false incoming argv with which we initialize the ORB michael@1: ppcInargv = new char *[nCount + 3]; // 3 = arg0 + last section + COSS host michael@1: *ppcInargv = new char[strlen(*qApp->argv() + 2)]; // For cmd name michael@1: strcpy(ppcInargv[0], *qApp->argv()); // Copy cmd name michael@1: for (int nIter = 0; nIter <= nCount; nIter++) { michael@1: QString Section = pOrbargv->section(' ', nIter, nIter); michael@1: ppcInargv[nIter + 1] = new char[strlen(Section.ascii() + 2)]; michael@1: strcpy(ppcInargv[nIter + 1], Section.ascii()); michael@1: } michael@1: michael@1: // Build the single string COSS naming host name with associated port number michael@1: *pOrbargv = TITRAQ_COSSPART1 michael@1: + m_pPrefs->getString(TITRAQ_PREFCORBHOST, TITRAQ_DEFCORBHOST) michael@1: + TITRAQ_COSSPART2; michael@1: nNamesize = strlen(pOrbargv->ascii()); michael@1: ppcInargv[nCount + 2] = new char[nNamesize]; michael@1: strcpy(ppcInargv[nCount + 2], pOrbargv->ascii()); michael@1: michael@1: try { michael@1: // Initialization of the ORB and COSS naming service michael@1: nCount = nCount + 3; // Raise the count to include app, last sec, COSS michael@1: Orb = CORBA::ORB_init(nCount, ppcInargv, "mico-local-orb"); michael@1: Nameobj = Orb->resolve_initial_references("NameService"); michael@1: Namectx = CosNaming::NamingContext::_narrow(Nameobj); michael@1: if (CORBA::is_nil(Namectx)) { // Verify sanity michael@1: m_pStatbar->message(trUtf8("Could not find the COSS naming service")); michael@1: qWarning("Could not find the COSS naming service\n"); michael@1: } michael@1: michael@1: // Clean up our dynamically allocated array michael@1: for (int nIter = 0; nIter < nCount; nIter++) michael@1: delete ppcInargv[nIter]; michael@1: delete ppcInargv; // Free the array itself michael@1: delete pOrbargv; // Free the intermediate string michael@1: michael@1: // Prepare the COSS name request michael@1: Cosname.length(1); michael@1: Cosname[0].id = CORBA::string_dup("Asdatabase"); michael@1: Cosname[0].kind = CORBA::string_dup(""); michael@1: michael@1: try { // Resolve to a CORBA object michael@1: Objcaster = Namectx->resolve(Cosname); michael@1: } michael@1: catch (CosNaming::NamingContext::NotFound &Cossex) { michael@1: m_pStatbar->message(trUtf8("NotFound exception thrown")); michael@1: qWarning("NotFound exception thrown\n"); michael@1: return; michael@1: } michael@1: catch (CosNaming::NamingContext::CannotProceed &Cossex) { michael@1: m_pStatbar->message(trUtf8("CannotProceed exception thrown")); michael@1: qWarning("CannotProceed exception thrown\n"); michael@1: return; michael@1: } michael@1: catch (CosNaming::NamingContext::InvalidName &Cossex) { michael@1: m_pStatbar->message(trUtf8("InvalidName exception thrown")); michael@1: qWarning("InvalidName exception thrown\n"); michael@1: return; michael@1: } michael@1: michael@1: // Cast the generic CORBA object to a AS database type michael@1: Asdbase = Asdatabase::_narrow(Objcaster); michael@1: if (CORBA::is_nil(Asdbase)) { // Verify sanity michael@1: m_pStatbar->message(trUtf8("Could not find the AS database")); michael@1: qWarning("Could not find the AS database\n"); michael@1: return; michael@1: } michael@1: michael@1: // Open an account object on the remote server michael@1: Account_var Account = Asdbase->Open("/tmp/events.as"); michael@1: if (CORBA::is_nil(Account)) { // Verify sanity michael@1: m_pStatbar->message(trUtf8("Could not create an account object on the server")); michael@1: qWarning("Could not create an account object on the server\n"); michael@1: return; michael@1: } michael@1: michael@1: // Fill account log object(s) to marshall and transmit michael@1: int nRow = m_pMaintable->currentRow(); michael@1: QTableSelection Select = m_pMaintable->selection(0); // Capture selected rows michael@1: int nTotal = Select.bottomRow() - Select.topRow() + 1; // Total rows selected michael@1: michael@1: // Remember, CORBA::stri_dup creates smart pointers michael@1: for (int nIter = 0; nIter < nTotal; nIter++) { michael@1: Singlerow.szUser = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXUSER)); michael@1: Singlerow.szGuid = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXGUID)); michael@1: Singlerow.szCrc = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXCRC).remove("0x")); michael@1: Singlerow.szRev = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXREV)); michael@1: Singlerow.szDate = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXDATE)); michael@1: Singlerow.szStart = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXSTART)); michael@1: Singlerow.szFinish = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXFINISH)); michael@1: Singlerow.szAmount = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXAMOUNT)); michael@1: // Singlerow.nRev = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXREV).toUInt(); michael@1: // Singlerow.nDate = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXDATE).toUInt(); michael@1: // Singlerow.nStart = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXSTART).toUInt(); michael@1: // Singlerow.nFinish = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXFINISH).toUInt(); michael@1: // Singlerow.nAmount = m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXAMOUNT).toUInt(); michael@1: Singlerow.szTask = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXTASK)); michael@1: Singlerow.szRemark = CORBA::string_dup(m_pMaintable->text(Select.topRow() + nIter, TITRAQ_IDXREMARK)); michael@1: Account->Log(Singlerow); // Finally transmit to server michael@1: } michael@1: michael@1: m_pStatbar->message(trUtf8("Successful transmission of accounting data")); michael@1: } michael@1: catch (const CORBA::Exception &Corbex) { michael@1: m_pStatbar->message(trUtf8("Caught CORBA exception: %1").arg(Corbex._repoid())); michael@1: qWarning("Caught CORBA exception: %s", Corbex._repoid()); michael@1: } michael@1: catch (...) { michael@1: qWarning("Caught unknown exception\n"); michael@1: } michael@1: #endif // HAVE_MICO michael@1: } michael@1: michael@1: // michael@1: // Syncronize data with server using SOAP michael@1: // michael@1: void Titraqform::syncSoap(void) michael@1: { michael@1: #ifdef HAVE_ESOAP michael@1: // Short circuit if user has disabled SOAP transmission in prefs michael@1: if (!m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON)) michael@1: return; michael@1: michael@1: USING_EASYSOAP_NAMESPACE michael@1: michael@1: try { michael@1: SOAPMethod Logmeth("Log", TITRAQ_SOAPSPACE); // SOAP namespace michael@1: SOAPString Clistr; // Outgoing parameter to marshall michael@1: int nCrc; // SOAP unmarshalled return value michael@1: michael@1: // Build the single string SOAP end point which look like this: michael@1: // "http://www.europalab.com/cgi-bin/asdbserv" michael@1: QString Endpoint; michael@1: Endpoint = TITRAQ_PREFIXHTTP + m_pPrefs->getString(TITRAQ_PREFSOAPHOST, TITRAQ_DEFSOAPHOST); michael@1: SOAPProxy Proxy(Endpoint.ascii()); michael@1: michael@1: // Fill account log object(s) to marshall and transmit michael@1: QTableSelection Select = m_pMaintable->selection(0); // Capture selected rows michael@1: int nTotal = Select.bottomRow() - Select.topRow() + 1; // Total rows selected michael@1: michael@1: // Iterate through the selection of row entries to transmit michael@1: for (int nRowiter = 0; nRowiter < nTotal; nRowiter++) { michael@1: QString Syncthis = m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXUSER); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXGUID); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXCRC).remove("0x"); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXREV); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXDATE); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXSTART); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXFINISH); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXAMOUNT); michael@1: Syncthis += ' ' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXTASK); michael@1: Syncthis += ' ' + ('"' + m_pMaintable->text(Select.topRow() + nRowiter, TITRAQ_IDXREMARK)) + '"'; michael@1: Clistr = Syncthis; // Build RPC parameter michael@1: Logmeth.AddParameter("Tuple") << Clistr; // Prepare for marshalling michael@1: const SOAPResponse &Logresp = Proxy.Execute(Logmeth); michael@1: Logresp.GetReturnValue() >> nCrc; michael@1: } michael@1: m_pStatbar->message(trUtf8("Successful transmission, CRC returned %1").arg(nCrc)); michael@1: } michael@1: catch (SOAPException& Soapex) { // Announce the exception we received michael@1: m_pStatbar->message(trUtf8("Caught SOAP exception: %1").arg(Soapex.What().Str())); michael@1: qDebug("Caught SOAP exception: %s", Soapex.What().Str()); michael@1: } michael@1: catch (...) { michael@1: qDebug("Caught unknown exception\n"); michael@1: } michael@1: #endif // HAVE_ESOAP michael@1: } michael@1: michael@1: // michael@1: // Save user preferences michael@1: // michael@1: void Titraqform::savePrefs(void) michael@1: { michael@1: // Get check status from column menu and pass it to prefs handler michael@1: m_pPrefs->setBool(TITRAQ_PREFSTATCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTATCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFLCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXLCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFUCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXUCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFGCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXGCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFCCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXCCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFREVCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREVCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFDCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXDCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFSTARTCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXSTARTCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFFCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFACOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXACOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFFCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXFCOL))); michael@1: m_pPrefs->setBool(TITRAQ_PREFREMCOLON, m_pColspopup->isItemChecked(m_pColspopup->idAt(TITRAQ_IDXREMCOL))); michael@1: michael@1: // Get check status from toolbar menu and pass it to prefs handler michael@1: m_pPrefs->setBool(TITRAQ_PREFFILEBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXFILEBAR))); michael@1: m_pPrefs->setBool(TITRAQ_PREFEDITBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXEDITBAR))); michael@1: m_pPrefs->setBool(TITRAQ_PREFVIEWBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXVIEWBAR))); michael@1: m_pPrefs->setBool(TITRAQ_PREFPREFBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXPREFBAR))); michael@1: m_pPrefs->setBool(TITRAQ_PREFWHATBAR, m_pTbarspopup->isItemChecked(m_pTbarspopup->idAt(TITRAQ_IDXWHATBAR))); michael@1: michael@1: // Get column widths from main table and pass it to prefs handler michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXSTATUS) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTATCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXSTATUS)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXLINE) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFLCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXLINE)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXUSER) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFUCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXUSER)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXGUID) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFGCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXGUID)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXCRC) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFCCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXCRC)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXREV) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFREVCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXREV)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXDATE) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFDCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXDATE)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXSTART) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTARTCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXSTART)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXFINISH) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFFCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXFINISH)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXAMOUNT) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFACOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXAMOUNT)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXTASK) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFTCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXTASK)); michael@1: if (m_pMaintable->columnWidth(TITRAQ_IDXREMARK) > 0) michael@1: m_pPrefs->setNumber(TITRAQ_PREFREMCOLWIDTH, (long)m_pMaintable->columnWidth(TITRAQ_IDXREMARK)); michael@1: michael@1: // Get sorting order and direction from table and pass it to prefs handler michael@1: m_pPrefs->setNumber(TITRAQ_PREFSORTCOL, (long)m_pMaintable->getSortcol()); michael@1: m_pPrefs->setBool(TITRAQ_PREFSORTDIR, (long)m_pMaintable->getSortdir()); michael@1: michael@1: // Set frame geometry preferences michael@1: m_pPrefs->setNumber(TITRAQ_PREFFRAMEWIDTH, (long)this->width()); michael@1: m_pPrefs->setNumber(TITRAQ_PREFFRAMEHEIGHT, (long)this->height()); michael@1: michael@1: // Remember main window layout and doc positions michael@1: QString Laystring; michael@1: QTextStream Laystream(&Laystring, IO_WriteOnly); michael@1: Laystream << *this; // Persist the main window michael@1: m_pPrefs->setString(TITRAQ_PREFFRAMELAY, Laystring); michael@1: } michael@1: michael@1: // michael@1: // Get help on Titraq functionality michael@1: // michael@1: void Titraqform::helpContents(void) michael@1: { michael@1: try { // Create and execute a new help contents window michael@1: std::auto_ptr pHelpcont(new AS::Helpanel(TITRAQ_REFHELP, this, "Helpanel")); michael@1: pHelpcont->exec(); michael@1: delete pHelpcont.release(); // Technically unnecessary, smart pointer michael@1: } michael@1: catch (Genexcept& Genex) { michael@1: Genex.reportErr(); michael@1: return; michael@1: } michael@1: } michael@1: michael@1: // michael@1: // Learn more about this program itself michael@1: // michael@1: void Titraqform::aboutTitraq(void) michael@1: { michael@1: QString Namever = QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short; michael@1: QMessageBox *pCwmsg = new QMessageBox(Namever, michael@1: QObject::trUtf8("The as-gui is a time and task-based accounting\n" michael@1: "system that acts as both a work-like punch card and\n" michael@1: "time tracker. Development of as-gui is sponsored by\n" michael@1: "Cable & Wireless Telecommunications Services GmbH."), michael@1: QMessageBox::NoIcon, QMessageBox::Ok | QMessageBox::Default, michael@1: QMessageBox::NoButton, QMessageBox::NoButton, michael@1: NULL, "Titraqmessage", true, Qt::WStyle_NormalBorder); michael@1: michael@1: pCwmsg->setIconPixmap(QPixmap(s_kpcCwlogo_xpm)); michael@1: pCwmsg->exec(); michael@1: } michael@1: michael@1: // michael@1: // Learn more about the OSSP michael@1: // michael@1: void Titraqform::aboutOSSP(void) michael@1: { michael@1: QString Namever = QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short; michael@1: QMessageBox *pOsspmsg = new QMessageBox(Namever, michael@1: QObject::trUtf8("The open source software project (OSSP) is\n" michael@1: "a collective effort aimed at implementing\n" michael@1: "high-quality Unix software components,\n" michael@1: "ranging from networking, multi-threading\n" michael@1: "and algorithmic libraries to networking\n" michael@1: "servers and development tools."), michael@1: QMessageBox::NoIcon, QMessageBox::Ok | QMessageBox::Default, michael@1: QMessageBox::NoButton, QMessageBox::NoButton, michael@1: NULL, "Osspmessage", true, Qt::WStyle_NormalBorder); michael@1: michael@1: pOsspmsg->setIconPixmap(QPixmap(s_kpcOssplogo_xpm)); michael@1: pOsspmsg->exec(); michael@1: } michael@1: michael@1: // michael@1: // Learn more about this program and Qt michael@1: // michael@1: void Titraqform::aboutQt(void) michael@1: { michael@1: QMessageBox::aboutQt(this, QString(TITRAQ_APPTITLE) + ' ' + asgui_version.v_short); michael@1: } michael@1: michael@1: // michael@1: // Apply preference values from a signal emitting object michael@1: // michael@1: void Titraqform::applyPrefs(void) michael@1: { michael@1: Prefpanel *pPan = (Prefpanel *)QObject::sender(); michael@1: this->applyPrefs(pPan); michael@1: } michael@1: michael@1: // michael@1: // Accept preference values from a inbound Panel object michael@1: // michael@1: void Titraqform::applyPrefs(Prefpanel *pPrefpanel) michael@1: { michael@1: m_pPrefs->setString(TITRAQ_PREFACCOUNTS, pPrefpanel->getAccounts()); michael@1: m_pPrefs->setString(TITRAQ_PREFASDIR, pPrefpanel->getEvents()); michael@1: m_pPrefs->setString(TITRAQ_PREFUSER, pPrefpanel->getUser()); michael@1: m_pPrefs->setString(TITRAQ_PREFHOME, pPrefpanel->getHome()); michael@1: m_pPrefs->setString(TITRAQ_PREFCORBHOST, pPrefpanel->getCorbahost()); michael@1: m_pPrefs->setString(TITRAQ_PREFSOAPHOST, pPrefpanel->getSoaphost()); michael@1: m_pPrefs->setBool(TITRAQ_PREFCORBON, pPrefpanel->getCorbaon()); michael@1: m_pPrefs->setBool(TITRAQ_PREFSOAPON, pPrefpanel->getSoapon()); michael@1: m_pPrefs->setBool(TITRAQ_PREFBAKON, pPrefpanel->getBackon()); michael@1: m_pPrefs->setBool(TITRAQ_PREFEXTENDON, pPrefpanel->getExtendon()); michael@1: m_pPrefs->setBool(TITRAQ_PREFDETAILON, pPrefpanel->getDetailon()); michael@1: m_pPrefs->setBool(TITRAQ_PREFSIGNATON, pPrefpanel->getSignaton()); michael@1: m_pPrefs->setNumber(TITRAQ_PREFLIGHTRED, pPrefpanel->getLight()->red()); michael@1: m_pPrefs->setNumber(TITRAQ_PREFLIGHTGREEN, pPrefpanel->getLight()->green()); michael@1: m_pPrefs->setNumber(TITRAQ_PREFLIGHTBLUE, pPrefpanel->getLight()->blue()); michael@1: m_pPrefs->setNumber(TITRAQ_PREFDARKRED, pPrefpanel->getDark()->red()); michael@1: m_pPrefs->setNumber(TITRAQ_PREFDARKGREEN, pPrefpanel->getDark()->green()); michael@1: m_pPrefs->setNumber(TITRAQ_PREFDARKBLUE, pPrefpanel->getDark()->blue()); michael@1: michael@1: // Dim the lights if no RPC transports are available michael@1: if (this->isOpen()) michael@1: m_pSyncact->setEnabled(m_pPrefs->getBool(TITRAQ_PREFCORBON, TITRAQ_DEFCORBON) michael@1: | m_pPrefs->getBool(TITRAQ_PREFSOAPON, TITRAQ_DEFSOAPON)); michael@1: else michael@1: m_pSyncact->setEnabled(false); michael@1: michael@1: // Get the selected style which can be more complicated due to mapping... michael@1: if (pPrefpanel->getStyle() == TITRAQ_STRCDE) { michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE); michael@1: qApp->setStyle(new QCDEStyle); michael@1: } michael@1: else if (pPrefpanel->getStyle() == TITRAQ_STRSGI) { michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLESGI); michael@1: qApp->setStyle(new QSGIStyle); michael@1: } michael@1: else if (pPrefpanel->getStyle() == TITRAQ_STRMOTIF) { michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEMOTIF); michael@1: qApp->setStyle(new QMotifStyle); michael@1: } michael@1: else if (pPrefpanel->getStyle() == TITRAQ_STRMPLUS) { michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEMPLUS); michael@1: qApp->setStyle(new QMotifPlusStyle); michael@1: } michael@1: else if (pPrefpanel->getStyle() == TITRAQ_STRPLAT) { michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEPLAT); michael@1: qApp->setStyle(new QPlatinumStyle); michael@1: } michael@1: else if (pPrefpanel->getStyle() == TITRAQ_STRMSOFT) { michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLEMSOFT); michael@1: qApp->setStyle(new QWindowsStyle); michael@1: } michael@1: else // My personal favourite ;-) michael@1: m_pPrefs->setNumber(TITRAQ_PREFSTYLE, TITRAQ_STYLECDE); michael@1: }