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