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