karm

mainwindow.cpp
1/*
2* Top Level window for KArm.
3* Distributed under the GPL.
4*/
5
6#include <numeric>
7
8#include "tdeaccelmenuwatch.h"
9#include <dcopclient.h>
10#include <tdeaccel.h>
11#include <tdeaction.h>
12#include <tdeapplication.h> // kapp
13#include <tdeconfig.h>
14#include <kdebug.h>
15#include <tdeglobal.h>
16#include <kkeydialog.h>
17#include <tdelocale.h> // i18n
18#include <tdemessagebox.h>
19#include <kstatusbar.h> // statusBar()
20#include <kstdaction.h>
21#include <tqkeycode.h>
22#include <tqpopupmenu.h>
23#include <tqptrlist.h>
24#include <tqstring.h>
25
26#include "karmerrors.h"
27#include "karmutility.h"
28#include "mainwindow.h"
29#include "preferences.h"
30#include "print.h"
31#include "task.h"
32#include "taskview.h"
33#include "timekard.h"
34#include "tray.h"
35#include "version.h"
36
37MainWindow::MainWindow( const TQString &icsfile )
38 : DCOPObject ( "KarmDCOPIface" ),
39 KParts::MainWindow(0,TQt::WStyle_ContextHelp),
40 _accel ( new TDEAccel( this ) ),
41 _watcher ( new TDEAccelMenuWatch( _accel, TQT_TQOBJECT(this) ) ),
42 _totalSum ( 0 ),
43 _sessionSum( 0 )
44{
45
46 _taskView = new TaskView( this, 0, icsfile );
47
48 setCentralWidget( _taskView );
49 // status bar
50 startStatusBar();
51
52 // setup PreferenceDialog.
53 _preferences = Preferences::instance();
54
55 // popup menus
56 makeMenus();
57 _watcher->updateMenus();
58
59 // connections
60 connect( _taskView, TQT_SIGNAL( totalTimesChanged( long, long ) ),
61 this, TQT_SLOT( updateTime( long, long ) ) );
62 connect( _taskView, TQT_SIGNAL( selectionChanged ( TQListViewItem * )),
63 this, TQT_SLOT(slotSelectionChanged()));
64 connect( _taskView, TQT_SIGNAL( updateButtons() ),
65 this, TQT_SLOT(slotSelectionChanged()));
66 connect( _taskView, TQT_SIGNAL( setStatusBar( TQString ) ),
67 this, TQT_SLOT(setStatusBar( TQString )));
68
69 loadGeometry();
70
71 // Setup context menu request handling
72 connect( _taskView,
73 TQT_SIGNAL( contextMenuRequested( TQListViewItem*, const TQPoint&, int )),
74 this,
75 TQT_SLOT( contextMenuRequest( TQListViewItem*, const TQPoint&, int )));
76
77 _tray = new KarmTray( this );
78
79 connect( _tray, TQT_SIGNAL( quitSelected() ), TQT_SLOT( quit() ) );
80
81 connect( _taskView, TQT_SIGNAL( timersActive() ), _tray, TQT_SLOT( startClock() ) );
82 connect( _taskView, TQT_SIGNAL( timersActive() ), this, TQT_SLOT( enableStopAll() ));
83 connect( _taskView, TQT_SIGNAL( timersInactive() ), _tray, TQT_SLOT( stopClock() ) );
84 connect( _taskView, TQT_SIGNAL( timersInactive() ), this, TQT_SLOT( disableStopAll()));
85 connect( _taskView, TQT_SIGNAL( tasksChanged( TQPtrList<Task> ) ),
86 _tray, TQT_SLOT( updateToolTip( TQPtrList<Task> ) ));
87
88 _taskView->load();
89
90 // Everything that uses Preferences has been created now, we can let it
91 // emit its signals
92 _preferences->emitSignals();
93 slotSelectionChanged();
94
95 // Register with DCOP
96 if ( !kapp->dcopClient()->isRegistered() )
97 {
98 kapp->dcopClient()->registerAs( "karm" );
99 kapp->dcopClient()->setDefaultObject( objId() );
100 }
101
102 // Set up DCOP error messages
103 m_error[ KARM_ERR_GENERIC_SAVE_FAILED ] =
104 i18n( "Save failed, most likely because the file could not be locked." );
105 m_error[ KARM_ERR_COULD_NOT_MODIFY_RESOURCE ] =
106 i18n( "Could not modify calendar resource." );
107 m_error[ KARM_ERR_MEMORY_EXHAUSTED ] =
108 i18n( "Out of memory--could not create object." );
109 m_error[ KARM_ERR_UID_NOT_FOUND ] =
110 i18n( "UID not found." );
111 m_error[ KARM_ERR_INVALID_DATE ] =
112 i18n( "Invalidate date--format is YYYY-MM-DD." );
113 m_error[ KARM_ERR_INVALID_TIME ] =
114 i18n( "Invalid time--format is YYYY-MM-DDTHH:MM:SS." );
115 m_error[ KARM_ERR_INVALID_DURATION ] =
116 i18n( "Invalid task duration--must be greater than zero." );
117}
118
119void MainWindow::slotSelectionChanged()
120{
121 Task* item= _taskView->current_item();
122 actionDelete->setEnabled(item);
123 actionEdit->setEnabled(item);
124 actionStart->setEnabled(item && !item->isRunning() && !item->isComplete());
125 actionStop->setEnabled(item && item->isRunning());
126 actionResetTime->setEnabled(item && !item->isRunning());
127 actionMarkAsComplete->setEnabled(item && !item->isComplete());
128 actionMarkAsIncomplete->setEnabled(item && item->isComplete());
129}
130
131// This is _old_ code, but shows how to enable/disable add comment menu item.
132// We'll need this kind of logic when comments are implemented.
133//void MainWindow::timeLoggingChanged(bool on)
134//{
135// actionAddComment->setEnabled( on );
136//}
137
138void MainWindow::setStatusBar(TQString qs)
139{
140 statusBar()->message(qs.isEmpty() ? "" : i18n(qs.ascii()));
141}
142
143bool MainWindow::save()
144{
145 kdDebug(5970) << "Saving time data to disk." << endl;
146 TQString err=_taskView->save(); // untranslated error msg.
147 if (err.isEmpty()) statusBar()->message(i18n("Successfully saved tasks and history"),1807);
148 else statusBar()->message(i18n(err.ascii()),7707); // no msgbox since save is called when exiting
149 saveGeometry();
150 return true;
151}
152
153void MainWindow::exportcsvHistory()
154{
155 kdDebug(5970) << "Exporting History to disk." << endl;
156 TQString err=_taskView->exportcsvHistory();
157 if (err.isEmpty()) statusBar()->message(i18n("Successfully exported History to CSV-file"),1807);
158 else KMessageBox::error(this, err.ascii());
159 saveGeometry();
160
161}
162
163void MainWindow::quit()
164{
165 kapp->quit();
166}
167
168
169MainWindow::~MainWindow()
170{
171 kdDebug(5970) << "MainWindow::~MainWindows: Quitting karm." << endl;
172 _taskView->stopAllTimers();
173 save();
174 _taskView->closeStorage();
175}
176
177void MainWindow::enableStopAll()
178{
179 actionStopAll->setEnabled(true);
180}
181
182void MainWindow::disableStopAll()
183{
184 actionStopAll->setEnabled(false);
185}
186
187
193void MainWindow::updateTime( long sessionDiff, long totalDiff )
194{
195 _sessionSum += sessionDiff;
196 _totalSum += totalDiff;
197
198 updateStatusBar();
199}
200
201void MainWindow::updateStatusBar( )
202{
203 TQString time;
204
205 time = formatTime( _sessionSum );
206 statusBar()->changeItem( i18n("Session: %1").arg(time), 0 );
207
208 time = formatTime( _totalSum );
209 statusBar()->changeItem( i18n("Total: %1" ).arg(time), 1);
210}
211
212void MainWindow::startStatusBar()
213{
214 statusBar()->insertItem( i18n("Session"), 0, 0, true );
215 statusBar()->insertItem( i18n("Total" ), 1, 0, true );
216}
217
218void MainWindow::saveProperties( TDEConfig* cfg )
219{
220 _taskView->stopAllTimers();
221 _taskView->save();
222 cfg->writeEntry( "WindowShown", isVisible());
223}
224
225void MainWindow::readProperties( TDEConfig* cfg )
226{
227 if( cfg->readBoolEntry( "WindowShown", true ))
228 show();
229}
230
231void MainWindow::keyBindings()
232{
233 KKeyDialog::configure( actionCollection(), this );
234}
235
236void MainWindow::startNewSession()
237{
238 _taskView->startNewSession();
239}
240
241void MainWindow::resetAllTimes()
242{
243 if ( KMessageBox::warningContinueCancel( this, i18n( "Do you really want to reset the time to zero for all tasks?" ),
244 i18n( "Confirmation Required" ), KGuiItem( i18n( "Reset All Times" ) ) ) == KMessageBox::Continue )
245 _taskView->resetTimeForAllTasks();
246}
247
248void MainWindow::makeMenus()
249{
250 TDEAction
251 *actionKeyBindings,
252 *actionNew,
253 *actionNewSub;
254
255 (void) KStdAction::quit( TQT_TQOBJECT(this), TQT_SLOT( quit() ), actionCollection());
256 (void) KStdAction::print( TQT_TQOBJECT(this), TQT_SLOT( print() ), actionCollection());
257 actionKeyBindings = KStdAction::keyBindings( TQT_TQOBJECT(this), TQT_SLOT( keyBindings() ),
258 actionCollection() );
259 actionPreferences = KStdAction::preferences(TQT_TQOBJECT(_preferences),
260 TQT_SLOT(showDialog()),
261 actionCollection() );
262 (void) KStdAction::save( TQT_TQOBJECT(this), TQT_SLOT( save() ), actionCollection() );
263 TDEAction* actionStartNewSession = new TDEAction( i18n("Start &New Session"),
264 0,
265 TQT_TQOBJECT(this),
266 TQT_SLOT( startNewSession() ),
267 actionCollection(),
268 "start_new_session");
269 TDEAction* actionResetAll = new TDEAction( i18n("&Reset All Times"),
270 0,
271 TQT_TQOBJECT(this),
272 TQT_SLOT( resetAllTimes() ),
273 actionCollection(),
274 "reset_all_times");
275 actionStart = new TDEAction( i18n("&Start"),
276 TQString::fromLatin1("1rightarrow"), Key_S,
277 TQT_TQOBJECT(_taskView),
278 TQT_SLOT( startCurrentTimer() ), actionCollection(),
279 "start");
280 actionStop = new TDEAction( i18n("S&top"),
281 TQString::fromLatin1("process-stop"), Key_S,
282 TQT_TQOBJECT(_taskView),
283 TQT_SLOT( stopCurrentTimer() ), actionCollection(),
284 "stop");
285 actionResetTime = new TDEAction( i18n("Re&set Time"),
286 0,
287 TQT_TQOBJECT(_taskView),
288 TQT_SLOT( resetTimeCurrentTask() ), actionCollection(),
289 "reset_times");
290 actionStopAll = new TDEAction( i18n("Stop &All Timers"),
291 Key_Escape,
292 TQT_TQOBJECT(_taskView),
293 TQT_SLOT( stopAllTimers() ), actionCollection(),
294 "stopAll");
295 actionStopAll->setEnabled(false);
296
297 actionNew = new TDEAction( i18n("&New..."),
298 TQString::fromLatin1("document-new"), CTRL+Key_N,
299 TQT_TQOBJECT(_taskView),
300 TQT_SLOT( newTask() ), actionCollection(),
301 "new_task");
302 actionNewSub = new TDEAction( i18n("New &Subtask..."),
303 TQString::fromLatin1("application-vnd.tde.tdemultiple"), CTRL+ALT+Key_N,
304 TQT_TQOBJECT(_taskView),
305 TQT_SLOT( newSubTask() ), actionCollection(),
306 "new_sub_task");
307 actionDelete = new TDEAction( i18n("&Delete"),
308 TQString::fromLatin1("edit-delete"), Key_Delete,
309 TQT_TQOBJECT(_taskView),
310 TQT_SLOT( deleteTask() ), actionCollection(),
311 "delete_task");
312 actionEdit = new TDEAction( i18n("&Edit..."),
313 TQString::fromLatin1("edit"), CTRL + Key_E,
314 TQT_TQOBJECT(_taskView),
315 TQT_SLOT( editTask() ), actionCollection(),
316 "edit_task");
317// actionAddComment = new TDEAction( i18n("&Add Comment..."),
318// TQString::fromLatin1("text-x-generic"),
319// CTRL+ALT+Key_E,
320// TQT_TQOBJECT(_taskView),
321// TQT_SLOT( addCommentToTask() ),
322// actionCollection(),
323// "add_comment_to_task");
324 actionMarkAsComplete = new TDEAction( i18n("&Mark as Complete"),
325 TQString::fromLatin1("text-x-generic"),
326 CTRL+Key_M,
327 TQT_TQOBJECT(_taskView),
328 TQT_SLOT( markTaskAsComplete() ),
329 actionCollection(),
330 "mark_as_complete");
331 actionMarkAsIncomplete = new TDEAction( i18n("&Mark as Incomplete"),
332 TQString::fromLatin1("text-x-generic"),
333 CTRL+Key_M,
334 TQT_TQOBJECT(_taskView),
335 TQT_SLOT( markTaskAsIncomplete() ),
336 actionCollection(),
337 "mark_as_incomplete");
338 actionClipTotals = new TDEAction( i18n("&Copy Totals to Clipboard"),
339 TQString::fromLatin1("klipper"),
340 CTRL+Key_C,
341 TQT_TQOBJECT(_taskView),
342 TQT_SLOT( clipTotals() ),
343 actionCollection(),
344 "clip_totals");
345 // actionClipTotals will never be used again, overwrite it
346 actionClipTotals = new TDEAction( i18n("&Copy Session Time to Clipboard"),
347 TQString::fromLatin1("klipper"),
348 0,
349 TQT_TQOBJECT(_taskView),
350 TQT_SLOT( clipSession() ),
351 actionCollection(),
352 "clip_session");
353 actionClipHistory = new TDEAction( i18n("Copy &History to Clipboard"),
354 TQString::fromLatin1("klipper"),
355 CTRL+ALT+Key_C,
356 TQT_TQOBJECT(_taskView),
357 TQT_SLOT( clipHistory() ),
358 actionCollection(),
359 "clip_history");
360
361 new TDEAction( i18n("Import &Legacy Flat File..."), 0,
362 TQT_TQOBJECT(_taskView), TQT_SLOT(loadFromFlatFile()), actionCollection(),
363 "import_flatfile");
364 new TDEAction( i18n("&Export to CSV File..."), 0,
365 TQT_TQOBJECT(_taskView), TQT_SLOT(exportcsvFile()), actionCollection(),
366 "export_csvfile");
367 new TDEAction( i18n("Export &History to CSV File..."), 0,
368 TQT_TQOBJECT(this), TQT_SLOT(exportcsvHistory()), actionCollection(),
369 "export_csvhistory");
370 new TDEAction( i18n("Import Tasks From &Planner..."), 0,
371 TQT_TQOBJECT(_taskView), TQT_SLOT(importPlanner()), actionCollection(),
372 "import_planner");
373
374/*
375 new TDEAction( i18n("Import E&vents"), 0,
376 _taskView,
377 TQT_SLOT( loadFromKOrgEvents() ), actionCollection(),
378 "import_korg_events");
379 */
380
381 setXMLFile( TQString::fromLatin1("karmui.rc") );
382 createGUI( 0 );
383
384 // Tool tips must be set after the createGUI.
385 actionKeyBindings->setToolTip( i18n("Configure key bindings") );
386 actionKeyBindings->setWhatsThis( i18n("This will let you configure key"
387 "bindings which is specific to karm") );
388
389 actionStartNewSession->setToolTip( i18n("Start a new session") );
390 actionStartNewSession->setWhatsThis( i18n("This will reset the session time "
391 "to 0 for all tasks, to start a "
392 "new session, without affecting "
393 "the totals.") );
394 actionResetAll->setToolTip( i18n("Reset all times") );
395 actionResetAll->setWhatsThis( i18n("This will reset the session and total "
396 "time to 0 for all tasks, to restart from "
397 "scratch.") );
398
399 actionStart->setToolTip( i18n("Start timing for selected task") );
400 actionStart->setWhatsThis( i18n("This will start timing for the selected "
401 "task.\n"
402 "It is even possible to time several tasks "
403 "simultaneously.\n\n"
404 "You may also start timing of a tasks by "
405 "double clicking the left mouse "
406 "button on a given task. This will, however, "
407 "stop timing of other tasks."));
408
409 actionStop->setToolTip( i18n("Stop timing of the selected task") );
410 actionStop->setWhatsThis( i18n("Stop timing of the selected task") );
411
412 actionStopAll->setToolTip( i18n("Stop all of the active timers") );
413 actionStopAll->setWhatsThis( i18n("Stop all of the active timers") );
414
415 actionResetTime->setToolTip( i18n("Reset times of the selected task") );
416 actionResetTime->setWhatsThis( i18n("Reset times of the selected task") );
417
418 actionNew->setToolTip( i18n("Create new top level task") );
419 actionNew->setWhatsThis( i18n("This will create a new top level task.") );
420
421 actionDelete->setToolTip( i18n("Delete selected task") );
422 actionDelete->setWhatsThis( i18n("This will delete the selected task and "
423 "all its subtasks.") );
424
425 actionEdit->setToolTip( i18n("Edit name or times for selected task") );
426 actionEdit->setWhatsThis( i18n("This will bring up a dialog box where you "
427 "may edit the parameters for the selected "
428 "task."));
429 //actionAddComment->setToolTip( i18n("Add a comment to a task") );
430 //actionAddComment->setWhatsThis( i18n("This will bring up a dialog box where "
431 // "you can add a comment to a task. The "
432 // "comment can for instance add information on what you "
433 // "are currently doing. The comment will "
434 // "be logged in the log file."));
435 actionClipTotals->setToolTip(i18n("Copy task totals to clipboard"));
436 actionClipHistory->setToolTip(i18n("Copy time card history to clipboard."));
437
438 slotSelectionChanged();
439}
440
441void MainWindow::print()
442{
443 MyPrinter printer(_taskView);
444 printer.print();
445}
446
447void MainWindow::loadGeometry()
448{
449 if (initialGeometrySet()) setAutoSaveSettings();
450 else
451 {
452 TDEConfig &config = *kapp->config();
453
454 config.setGroup( TQString::fromLatin1("Main Window Geometry") );
455 int w = config.readNumEntry( TQString::fromLatin1("Width"), 100 );
456 int h = config.readNumEntry( TQString::fromLatin1("Height"), 100 );
457 w = TQMAX( w, sizeHint().width() );
458 h = TQMAX( h, sizeHint().height() );
459 resize(w, h);
460 }
461}
462
463
464void MainWindow::saveGeometry()
465{
466 TDEConfig &config = *TDEGlobal::config();
467 config.setGroup( TQString::fromLatin1("Main Window Geometry"));
468 config.writeEntry( TQString::fromLatin1("Width"), width());
469 config.writeEntry( TQString::fromLatin1("Height"), height());
470 config.sync();
471}
472
473bool MainWindow::queryClose()
474{
475 if ( !kapp->sessionSaving() ) {
476 hide();
477 return false;
478 }
479 return TDEMainWindow::queryClose();
480}
481
482void MainWindow::contextMenuRequest( TQListViewItem*, const TQPoint& point, int )
483{
484 TQPopupMenu* pop = dynamic_cast<TQPopupMenu*>(
485 factory()->container( i18n( "task_popup" ), this ) );
486 if ( pop )
487 pop->popup( point );
488}
489
490//----------------------------------------------------------------------------
491//
492// D C O P I N T E R F A C E
493//
494//----------------------------------------------------------------------------
495
496TQString MainWindow::version() const
497{
498 return KARM_VERSION;
499}
500
502{
503 _taskView->deleteTask();
504 return "";
505}
506
508{
509 return _preferences->promptDelete();
510}
511
512TQString MainWindow::setpromptdelete( bool prompt )
513{
514 _preferences->setPromptDelete( prompt );
515 return "";
516}
517
518TQString MainWindow::taskIdFromName( const TQString &taskname ) const
519{
520 TQString rval = "";
521
522 Task* task = _taskView->first_child();
523 while ( rval.isEmpty() && task )
524 {
525 rval = _hasTask( task, taskname );
526 task = task->nextSibling();
527 }
528
529 return rval;
530}
531
532int MainWindow::addTask( const TQString& taskname )
533{
534 DesktopList desktopList;
535 TQString uid = _taskView->addTask( taskname, 0, 0, desktopList );
536 kdDebug(5970) << "MainWindow::addTask( " << taskname << " ) returns " << uid << endl;
537 if ( uid.length() > 0 ) return 0;
538 else
539 {
540 // We can't really tell what happened, b/c the resource framework only
541 // returns a boolean.
542 return KARM_ERR_GENERIC_SAVE_FAILED;
543 }
544}
545
546TQString MainWindow::setPerCentComplete( const TQString& taskName, int perCent )
547{
548 int index;
549 TQString err="no such task";
550 for (int i=0; i<_taskView->count(); i++)
551 {
552 if ((_taskView->item_at_index(i)->name()==taskName))
553 {
554 index=i;
555 if (err==TQString()) err="task name is abigious";
556 if (err=="no such task") err=TQString();
557 }
558 }
559 if (err==TQString())
560 {
561 _taskView->item_at_index(index)->setPercentComplete( perCent, _taskView->storage() );
562 }
563 return err;
564}
565
567( const TQString& taskId, const TQString& datetime, long minutes )
568{
569 int rval = 0;
570 TQDate startDate;
571 TQTime startTime;
572 TQDateTime startDateTime;
573 Task *task, *t;
574
575 if ( minutes <= 0 ) rval = KARM_ERR_INVALID_DURATION;
576
577 // Find task
578 task = _taskView->first_child();
579 t = NULL;
580 while ( !t && task )
581 {
582 t = _hasUid( task, taskId );
583 task = task->nextSibling();
584 }
585 if ( t == NULL ) rval = KARM_ERR_UID_NOT_FOUND;
586
587 // Parse datetime
588 if ( !rval )
589 {
590 startDate = TQDate::fromString( datetime, Qt::ISODate );
591 if ( datetime.length() > 10 ) // "YYYY-MM-DD".length() = 10
592 {
593 startTime = TQTime::fromString( datetime, Qt::ISODate );
594 }
595 else startTime = TQTime( 12, 0 );
596 if ( startDate.isValid() && startTime.isValid() )
597 {
598 startDateTime = TQDateTime( startDate, startTime );
599 }
600 else rval = KARM_ERR_INVALID_DATE;
601
602 }
603
604 // Update task totals (session and total) and save to disk
605 if ( !rval )
606 {
607 t->changeTotalTimes( t->sessionTime() + minutes, t->totalTime() + minutes );
608 if ( ! _taskView->storage()->bookTime( t, startDateTime, minutes * 60 ) )
609 {
610 rval = KARM_ERR_GENERIC_SAVE_FAILED;
611 }
612 }
613
614 return rval;
615}
616
617// There was something really bad going on with DCOP when I used a particular
618// argument name; if I recall correctly, the argument name was errno.
619TQString MainWindow::getError( int mkb ) const
620{
621 if ( mkb <= KARM_MAX_ERROR_NO ) return m_error[ mkb ];
622 else return i18n( "Invalid error number: %1" ).arg( mkb );
623}
624
625int MainWindow::totalMinutesForTaskId( const TQString& taskId )
626{
627 int rval = 0;
628 Task *task, *t;
629
630 kdDebug(5970) << "MainWindow::totalTimeForTask( " << taskId << " )" << endl;
631
632 // Find task
633 task = _taskView->first_child();
634 t = NULL;
635 while ( !t && task )
636 {
637 t = _hasUid( task, taskId );
638 task = task->nextSibling();
639 }
640 if ( t != NULL )
641 {
642 rval = t->totalTime();
643 kdDebug(5970) << "MainWindow::totalTimeForTask - task found: rval = " << rval << endl;
644 }
645 else
646 {
647 kdDebug(5970) << "MainWindow::totalTimeForTask - task not found" << endl;
648 rval = KARM_ERR_UID_NOT_FOUND;
649 }
650
651 return rval;
652}
653
654TQString MainWindow::_hasTask( Task* task, const TQString &taskname ) const
655{
656 TQString rval = "";
657 if ( task->name() == taskname )
658 {
659 rval = task->uid();
660 }
661 else
662 {
663 Task* nexttask = task->firstChild();
664 while ( rval.isEmpty() && nexttask )
665 {
666 rval = _hasTask( nexttask, taskname );
667 nexttask = nexttask->nextSibling();
668 }
669 }
670 return rval;
671}
672
673Task* MainWindow::_hasUid( Task* task, const TQString &uid ) const
674{
675 Task *rval = NULL;
676
677 //kdDebug(5970) << "MainWindow::_hasUid( " << task << ", " << uid << " )" << endl;
678
679 if ( task->uid() == uid ) rval = task;
680 else
681 {
682 Task* nexttask = task->firstChild();
683 while ( !rval && nexttask )
684 {
685 rval = _hasUid( nexttask, uid );
686 nexttask = nexttask->nextSibling();
687 }
688 }
689 return rval;
690}
691TQString MainWindow::starttimerfor( const TQString& taskname )
692{
693 int index;
694 TQString err="no such task";
695 for (int i=0; i<_taskView->count(); i++)
696 {
697 if ((_taskView->item_at_index(i)->name()==taskname))
698 {
699 index=i;
700 if (err==TQString()) err="task name is abigious";
701 if (err=="no such task") err=TQString();
702 }
703 }
704 if (err==TQString()) _taskView->startTimerFor( _taskView->item_at_index(index) );
705 return err;
706}
707
708TQString MainWindow::stoptimerfor( const TQString& taskname )
709{
710 int index;
711 TQString err="no such task";
712 for (int i=0; i<_taskView->count(); i++)
713 {
714 if ((_taskView->item_at_index(i)->name()==taskname))
715 {
716 index=i;
717 if (err==TQString()) err="task name is abigious";
718 if (err=="no such task") err=TQString();
719 }
720 }
721 if (err==TQString()) _taskView->stopTimerFor( _taskView->item_at_index(index) );
722 return err;
723}
724
725TQString MainWindow::exportcsvfile( TQString filename, TQString from, TQString to, int type, bool decimalMinutes, bool allTasks, TQString delimiter, TQString quote )
726{
728 rc.url=filename;
729 rc.from=TQDate::fromString( from );
730 if ( rc.from.isNull() ) rc.from=TQDate::fromString( from, Qt::ISODate );
731 kdDebug(5970) << "rc.from " << rc.from << endl;
732 rc.to=TQDate::fromString( to );
733 if ( rc.to.isNull() ) rc.to=TQDate::fromString( to, Qt::ISODate );
734 kdDebug(5970) << "rc.to " << rc.to << endl;
735 rc.reportType=(ReportCriteria::REPORTTYPE) type; // history report or totals report
736 rc.decimalMinutes=decimalMinutes;
737 rc.allTasks=allTasks;
738 rc.delimiter=delimiter;
739 rc.quote=quote;
740 return _taskView->report( rc );
741}
742
743TQString MainWindow::importplannerfile( TQString fileName )
744{
745 return _taskView->importPlanner(fileName);
746}
747
748
749#include "mainwindow.moc"
bool bookTime(const Task *task, const TQDateTime &startDateTime, long durationInSeconds)
Book time to a task.
Main window to tie the application together.
Definition: mainwindow.h:27
int addTask(const TQString &storage)
Definition: mainwindow.cpp:532
TQString setPerCentComplete(const TQString &taskName, int PerCent)
Definition: mainwindow.cpp:546
TQString setpromptdelete(bool prompt)
set if there will be a "really delete" question
Definition: mainwindow.cpp:512
TQString exportcsvfile(TQString filename, TQString from, TQString to, int type, bool decimalMinutes, bool allTasks, TQString delimiter, TQString quote)
export csv history or totals file
Definition: mainwindow.cpp:725
int totalMinutesForTaskId(const TQString &taskId)
Total time currently associated with a task.
Definition: mainwindow.cpp:625
int bookTime(const TQString &taskId, const TQString &iso8601StartDateTime, long durationInMinutes)
Definition: mainwindow.cpp:567
TQString stoptimerfor(const TQString &taskname)
stop the timer for taskname
Definition: mainwindow.cpp:708
TQString getError(int karmErrorNumber) const
Definition: mainwindow.cpp:619
TQString version() const
Return karm version.
Definition: mainwindow.cpp:496
TQString starttimerfor(const TQString &taskname)
start the timer for taskname
Definition: mainwindow.cpp:691
TQString taskIdFromName(const TQString &taskName) const
Return id of task found, empty string if no match.
Definition: mainwindow.cpp:518
bool getpromptdelete()
shall there be a "really delete" question
Definition: mainwindow.cpp:507
TQString importplannerfile(TQString filename)
import planner project file
Definition: mainwindow.cpp:743
void updateTime(long, long)
Calculate the sum of the session time and the total time for all toplevel tasks and put it in the sta...
Definition: mainwindow.cpp:193
TQString deletetodo()
delete the current item
Definition: mainwindow.cpp:501
Provide printing capabilities.
Definition: print.h:19
Stores entries from export dialog.
bool decimalMinutes
True if the durations should be output in decimal hours.
REPORTTYPE
The different report types.
TQString quote
The quote to use for text fields when outputting comma-seperated reports.
TQDate to
For history reports, the upper bound of the date range to report on.
bool allTasks
True if the report should contain all tasks in Karm.
KURL url
For reports that write to a file, the filename to write to.
TQString delimiter
The delimiter to use when outputting comma-seperated value reports.
REPORTTYPE reportType
The type of report we are running.
TQDate from
For history reports, the lower bound of the date range to report on.
Easy updating of menu accels when changing a TDEAccel object.
Container and interface for the tasks.
Definition: taskview.h:43
KarmStorage * storage()
Returns a pointer to storage object.
Definition: taskview.cpp:114
Task * first_child() const
Return the first item in the view, cast to a Task pointer.
Definition: taskview.cpp:172
long count()
Return the total number if items in the view.
Definition: taskview.cpp:379
TQString exportcsvHistory()
Export comma-separated values format for task history.
Definition: taskview.cpp:341
void resetTimeForAllTasks()
Reset session and total time to zero for all tasks.
Definition: taskview.cpp:453
TQString importPlanner(TQString fileName="")
used to import tasks from imendio planner
Definition: taskview.cpp:308
void closeStorage()
Close the storage and release lock.
Definition: taskview.cpp:237
TQString addTask(const TQString &taskame, long total, long session, const DesktopList &desktops, Task *parent=0)
Add a task to view and storage.
Definition: taskview.cpp:534
TQString report(const ReportCriteria &rc)
call export function for csv totals or history
Definition: taskview.cpp:322
Task * current_item() const
Return the current item in the view, cast to a Task pointer.
Definition: taskview.cpp:177
TQString save()
Save to persistent storage.
Definition: taskview.cpp:365
Task * item_at_index(int i)
Return the i'th item (zero-based), cast to a Task pointer.
Definition: taskview.cpp:182
void deleteTask(bool markingascomplete=false)
Delete task (and children) from view.
Definition: taskview.cpp:645
void startTimerFor(Task *task, TQDateTime startTime=TQDateTime::currentDateTime())
starts timer for task.
Definition: taskview.cpp:386
void stopAllTimers()
Stop all running timers.
Definition: taskview.cpp:413
void startNewSession()
Reset session time to zero for all tasks.
Definition: taskview.cpp:444
A class representing a task.
Definition: task.h:42
bool isComplete()
Return true if task is complete (percent complete equals 100).
Definition: task.cpp:194
TQString name() const
returns the name of this task.
Definition: task.h:162
void changeTotalTimes(long minutesSession, long minutes)
adds minutes to total and session time
Definition: task.cpp:224
TQString uid() const
Return unique iCalendar Todo ID for this task.
Definition: task.h:70
void setPercentComplete(const int percent, KarmStorage *storage)
Update percent complete for this task.
Definition: task.cpp:149
bool isRunning() const
return the state of a task - if it's running or not
Definition: task.cpp:132
Task * firstChild() const
return parent Task or null in case of TaskView.
Definition: task.h:60