8 #include "tdeaccelmenuwatch.h"
9 #include <dcopclient.h>
11 #include <tdeaction.h>
12 #include <tdeapplication.h>
13 #include <tdeconfig.h>
15 #include <tdeglobal.h>
16 #include <kkeydialog.h>
17 #include <tdelocale.h>
18 #include <tdemessagebox.h>
19 #include <kstatusbar.h>
20 #include <kstdaction.h>
21 #include <tqkeycode.h>
22 #include <tqpopupmenu.h>
23 #include <tqptrlist.h>
26 #include "karmerrors.h"
27 #include "karmutility.h"
28 #include "mainwindow.h"
29 #include "preferences.h"
37 MainWindow::MainWindow(
const TQString &icsfile )
38 : DCOPObject (
"KarmDCOPIface" ),
39 KParts::MainWindow(0,TQt::WStyle_ContextHelp),
40 _accel ( new TDEAccel( this ) ),
46 _taskView =
new TaskView(
this, 0, icsfile );
48 setCentralWidget( _taskView );
53 _preferences = Preferences::instance();
57 _watcher->updateMenus();
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 )));
73 TQT_SIGNAL( contextMenuRequested( TQListViewItem*,
const TQPoint&,
int )),
75 TQT_SLOT( contextMenuRequest( TQListViewItem*,
const TQPoint&,
int )));
77 _tray =
new KarmTray(
this );
79 connect( _tray, TQT_SIGNAL( quitSelected() ), TQT_SLOT( quit() ) );
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> ) ));
92 _preferences->emitSignals();
93 slotSelectionChanged();
96 if ( !kapp->dcopClient()->isRegistered() )
98 kapp->dcopClient()->registerAs(
"karm" );
99 kapp->dcopClient()->setDefaultObject( objId() );
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." );
119 void MainWindow::slotSelectionChanged()
121 Task* item= _taskView->current_item();
122 actionDelete->setEnabled(item);
123 actionEdit->setEnabled(item);
125 actionStop->setEnabled(item && item->
isRunning());
126 actionResetTime->setEnabled(item && !item->
isRunning());
127 actionMarkAsComplete->setEnabled(item && !item->
isComplete());
128 actionMarkAsIncomplete->setEnabled(item && item->
isComplete());
138 void MainWindow::setStatusBar(TQString qs)
140 statusBar()->message(qs.isEmpty() ?
"" : i18n(qs.ascii()));
143 bool MainWindow::save()
145 kdDebug(5970) <<
"Saving time data to disk." << endl;
146 TQString err=_taskView->save();
147 if (err.isEmpty()) statusBar()->message(i18n(
"Successfully saved tasks and history"),1807);
148 else statusBar()->message(i18n(err.ascii()),7707);
153 void MainWindow::exportcsvHistory()
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());
163 void MainWindow::quit()
169 MainWindow::~MainWindow()
171 kdDebug(5970) <<
"MainWindow::~MainWindows: Quitting karm." << endl;
172 _taskView->stopAllTimers();
174 _taskView->closeStorage();
177 void MainWindow::enableStopAll()
179 actionStopAll->setEnabled(
true);
182 void MainWindow::disableStopAll()
184 actionStopAll->setEnabled(
false);
195 _sessionSum += sessionDiff;
196 _totalSum += totalDiff;
201 void MainWindow::updateStatusBar( )
205 time = formatTime( _sessionSum );
206 statusBar()->changeItem( i18n(
"Session: %1").arg(time), 0 );
208 time = formatTime( _totalSum );
209 statusBar()->changeItem( i18n(
"Total: %1" ).arg(time), 1);
212 void MainWindow::startStatusBar()
214 statusBar()->insertItem( i18n(
"Session"), 0, 0,
true );
215 statusBar()->insertItem( i18n(
"Total" ), 1, 0,
true );
218 void MainWindow::saveProperties( TDEConfig* cfg )
220 _taskView->stopAllTimers();
222 cfg->writeEntry(
"WindowShown", isVisible());
225 void MainWindow::readProperties( TDEConfig* cfg )
227 if( cfg->readBoolEntry(
"WindowShown",
true ))
231 void MainWindow::keyBindings()
233 KKeyDialog::configure( actionCollection(),
this );
236 void MainWindow::startNewSession()
238 _taskView->startNewSession();
241 void MainWindow::resetAllTimes()
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();
248 void MainWindow::makeMenus()
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"),
266 TQT_SLOT( startNewSession() ),
268 "start_new_session");
269 TDEAction* actionResetAll =
new TDEAction( i18n(
"&Reset All Times"),
272 TQT_SLOT( resetAllTimes() ),
275 actionStart =
new TDEAction( i18n(
"&Start"),
276 TQString::fromLatin1(
"1rightarrow"), Key_S,
277 TQT_TQOBJECT(_taskView),
278 TQT_SLOT( startCurrentTimer() ), actionCollection(),
280 actionStop =
new TDEAction( i18n(
"S&top"),
281 TQString::fromLatin1(
"process-stop"), Key_S,
282 TQT_TQOBJECT(_taskView),
283 TQT_SLOT( stopCurrentTimer() ), actionCollection(),
285 actionResetTime =
new TDEAction( i18n(
"Re&set Time"),
287 TQT_TQOBJECT(_taskView),
288 TQT_SLOT( resetTimeCurrentTask() ), actionCollection(),
290 actionStopAll =
new TDEAction( i18n(
"Stop &All Timers"),
292 TQT_TQOBJECT(_taskView),
293 TQT_SLOT( stopAllTimers() ), actionCollection(),
295 actionStopAll->setEnabled(
false);
297 actionNew =
new TDEAction( i18n(
"&New..."),
298 TQString::fromLatin1(
"document-new"), CTRL+Key_N,
299 TQT_TQOBJECT(_taskView),
300 TQT_SLOT( newTask() ), actionCollection(),
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(),
307 actionDelete =
new TDEAction( i18n(
"&Delete"),
308 TQString::fromLatin1(
"edit-delete"), Key_Delete,
309 TQT_TQOBJECT(_taskView),
310 TQT_SLOT( deleteTask() ), actionCollection(),
312 actionEdit =
new TDEAction( i18n(
"&Edit..."),
313 TQString::fromLatin1(
"edit"), CTRL + Key_E,
314 TQT_TQOBJECT(_taskView),
315 TQT_SLOT( editTask() ), actionCollection(),
324 actionMarkAsComplete =
new TDEAction( i18n(
"&Mark as Complete"),
325 TQString::fromLatin1(
"text-x-generic"),
327 TQT_TQOBJECT(_taskView),
328 TQT_SLOT( markTaskAsComplete() ),
331 actionMarkAsIncomplete =
new TDEAction( i18n(
"&Mark as Incomplete"),
332 TQString::fromLatin1(
"text-x-generic"),
334 TQT_TQOBJECT(_taskView),
335 TQT_SLOT( markTaskAsIncomplete() ),
337 "mark_as_incomplete");
338 actionClipTotals =
new TDEAction( i18n(
"&Copy Totals to Clipboard"),
339 TQString::fromLatin1(
"klipper"),
341 TQT_TQOBJECT(_taskView),
342 TQT_SLOT( clipTotals() ),
346 actionClipTotals =
new TDEAction( i18n(
"&Copy Session Time to Clipboard"),
347 TQString::fromLatin1(
"klipper"),
349 TQT_TQOBJECT(_taskView),
350 TQT_SLOT( clipSession() ),
353 actionClipHistory =
new TDEAction( i18n(
"Copy &History to Clipboard"),
354 TQString::fromLatin1(
"klipper"),
356 TQT_TQOBJECT(_taskView),
357 TQT_SLOT( clipHistory() ),
361 new TDEAction( i18n(
"Import &Legacy Flat File..."), 0,
362 TQT_TQOBJECT(_taskView), TQT_SLOT(loadFromFlatFile()), actionCollection(),
364 new TDEAction( i18n(
"&Export to CSV File..."), 0,
365 TQT_TQOBJECT(_taskView), TQT_SLOT(exportcsvFile()), actionCollection(),
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(),
381 setXMLFile( TQString::fromLatin1(
"karmui.rc") );
385 actionKeyBindings->setToolTip( i18n(
"Configure key bindings") );
386 actionKeyBindings->setWhatsThis( i18n(
"This will let you configure key"
387 "bindings which is specific to karm") );
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 "
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 "
399 actionStart->setToolTip( i18n(
"Start timing for selected task") );
400 actionStart->setWhatsThis( i18n(
"This will start timing for the selected "
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."));
409 actionStop->setToolTip( i18n(
"Stop timing of the selected task") );
410 actionStop->setWhatsThis( i18n(
"Stop timing of the selected task") );
412 actionStopAll->setToolTip( i18n(
"Stop all of the active timers") );
413 actionStopAll->setWhatsThis( i18n(
"Stop all of the active timers") );
415 actionResetTime->setToolTip( i18n(
"Reset times of the selected task") );
416 actionResetTime->setWhatsThis( i18n(
"Reset times of the selected task") );
418 actionNew->setToolTip( i18n(
"Create new top level task") );
419 actionNew->setWhatsThis( i18n(
"This will create a new top level task.") );
421 actionDelete->setToolTip( i18n(
"Delete selected task") );
422 actionDelete->setWhatsThis( i18n(
"This will delete the selected task and "
423 "all its subtasks.") );
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 "
435 actionClipTotals->setToolTip(i18n(
"Copy task totals to clipboard"));
436 actionClipHistory->setToolTip(i18n(
"Copy time card history to clipboard."));
438 slotSelectionChanged();
441 void MainWindow::print()
447 void MainWindow::loadGeometry()
449 if (initialGeometrySet()) setAutoSaveSettings();
452 TDEConfig &config = *kapp->config();
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() );
464 void MainWindow::saveGeometry()
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());
473 bool MainWindow::queryClose()
475 if ( !kapp->sessionSaving() ) {
479 return TDEMainWindow::queryClose();
482 void MainWindow::contextMenuRequest( TQListViewItem*,
const TQPoint& point,
int )
484 TQPopupMenu* pop =
dynamic_cast<TQPopupMenu*
>(
485 factory()->container( i18n(
"task_popup" ),
this ) );
503 _taskView->deleteTask();
509 return _preferences->promptDelete();
514 _preferences->setPromptDelete( prompt );
522 Task* task = _taskView->first_child();
523 while ( rval.isEmpty() && task )
525 rval = _hasTask( task, taskname );
526 task = task->nextSibling();
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;
542 return KARM_ERR_GENERIC_SAVE_FAILED;
549 TQString err=
"no such task";
550 for (
int i=0; i<_taskView->count(); i++)
552 if ((_taskView->item_at_index(i)->name()==taskName))
555 if (err==TQString()) err=
"task name is abigious";
556 if (err==
"no such task") err=TQString();
561 _taskView->item_at_index(index)->setPercentComplete( perCent, _taskView->storage() );
567 (
const TQString& taskId,
const TQString& datetime,
long minutes )
572 TQDateTime startDateTime;
575 if ( minutes <= 0 ) rval = KARM_ERR_INVALID_DURATION;
578 task = _taskView->first_child();
582 t = _hasUid( task, taskId );
583 task = task->nextSibling();
585 if ( t == NULL ) rval = KARM_ERR_UID_NOT_FOUND;
590 startDate = TQDate::fromString( datetime, Qt::ISODate );
591 if ( datetime.length() > 10 )
593 startTime = TQTime::fromString( datetime, Qt::ISODate );
595 else startTime = TQTime( 12, 0 );
596 if ( startDate.isValid() && startTime.isValid() )
598 startDateTime = TQDateTime( startDate, startTime );
600 else rval = KARM_ERR_INVALID_DATE;
607 t->
changeTotalTimes( t->sessionTime() + minutes, t->totalTime() + minutes );
608 if ( ! _taskView->storage()->bookTime( t, startDateTime, minutes * 60 ) )
610 rval = KARM_ERR_GENERIC_SAVE_FAILED;
621 if ( mkb <= KARM_MAX_ERROR_NO )
return m_error[ mkb ];
622 else return i18n(
"Invalid error number: %1" ).arg( mkb );
630 kdDebug(5970) <<
"MainWindow::totalTimeForTask( " << taskId <<
" )" << endl;
633 task = _taskView->first_child();
637 t = _hasUid( task, taskId );
638 task = task->nextSibling();
642 rval = t->totalTime();
643 kdDebug(5970) <<
"MainWindow::totalTimeForTask - task found: rval = " << rval << endl;
647 kdDebug(5970) <<
"MainWindow::totalTimeForTask - task not found" << endl;
648 rval = KARM_ERR_UID_NOT_FOUND;
654 TQString MainWindow::_hasTask(
Task* task,
const TQString &taskname )
const
657 if ( task->
name() == taskname )
664 while ( rval.isEmpty() && nexttask )
666 rval = _hasTask( nexttask, taskname );
667 nexttask = nexttask->nextSibling();
673 Task* MainWindow::_hasUid(
Task* task,
const TQString &uid )
const
679 if ( task->
uid() == uid ) rval = task;
683 while ( !rval && nexttask )
685 rval = _hasUid( nexttask, uid );
686 nexttask = nexttask->nextSibling();
694 TQString err=
"no such task";
695 for (
int i=0; i<_taskView->count(); i++)
697 if ((_taskView->item_at_index(i)->name()==taskname))
700 if (err==TQString()) err=
"task name is abigious";
701 if (err==
"no such task") err=TQString();
704 if (err==TQString()) _taskView->startTimerFor( _taskView->item_at_index(index) );
711 TQString err=
"no such task";
712 for (
int i=0; i<_taskView->count(); i++)
714 if ((_taskView->item_at_index(i)->name()==taskname))
717 if (err==TQString()) err=
"task name is abigious";
718 if (err==
"no such task") err=TQString();
721 if (err==TQString()) _taskView->stopTimerFor( _taskView->item_at_index(index) );
725 TQString
MainWindow::exportcsvfile( TQString filename, TQString from, TQString to,
int type,
bool decimalMinutes,
bool allTasks, TQString delimiter, TQString quote )
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;
740 return _taskView->report( rc );
745 return _taskView->importPlanner(fileName);
749 #include "mainwindow.moc"
TQDate from
For history reports, the lower bound of the date range to report on.
int totalMinutesForTaskId(const TQString &taskId)
Total time currently associated with a task.
TQString name() const
returns the name of this task.
int addTask(const TQString &storage)
TQString taskIdFromName(const TQString &taskName) const
Return id of task found, empty string if no match.
TQString delimiter
The delimiter to use when outputting comma-seperated value reports.
TQString exportcsvfile(TQString filename, TQString from, TQString to, int type, bool decimalMinutes, bool allTasks, TQString delimiter, TQString quote)
export csv history or totals file
bool getpromptdelete()
shall there be a "really delete" question
TQString setpromptdelete(bool prompt)
set if there will be a "really delete" question
TQString getError(int karmErrorNumber) const
void changeTotalTimes(long minutesSession, long minutes)
adds minutes to total and session time
bool isComplete()
Return true if task is complete (percent complete equals 100).
Task * firstChild() const
return parent Task or null in case of TaskView.
Provide printing capabilities.
REPORTTYPE reportType
The type of report we are running.
TQString starttimerfor(const TQString &taskname)
start the timer for taskname
TQString version() const
Return karm version.
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...
Stores entries from export dialog.
TQString stoptimerfor(const TQString &taskname)
stop the timer for taskname
bool isRunning() const
return the state of a task - if it's running or not
TQString setPerCentComplete(const TQString &taskName, int PerCent)
TQDate to
For history reports, the upper bound of the date range to report on.
TQString importplannerfile(TQString filename)
import planner project file
bool decimalMinutes
True if the durations should be output in decimal hours.
bool allTasks
True if the report should contain all tasks in Karm.
REPORTTYPE
The different report types.
TQString deletetodo()
delete the current item
int bookTime(const TQString &taskId, const TQString &iso8601StartDateTime, long durationInMinutes)
TQString quote
The quote to use for text fields when outputting comma-seperated reports.
TQString uid() const
Return unique iCalendar Todo ID for this task.
Container and interface for the tasks.
A class representing a task.
KURL url
For reports that write to a file, the filename to write to.