2 #include "tdeaccelmenuwatch.h"
4 #include "karmerrors.h"
6 #include "preferences.h"
11 #include <kinstance.h>
12 #include <tdeaction.h>
13 #include <kstdaction.h>
14 #include <tdefiledialog.h>
15 #include <tdeglobal.h>
16 #include <tdelocale.h>
19 #include <tqtextstream.h>
20 #include <tqmultilineedit.h>
21 #include <tqpopupmenu.h>
22 #include "mainwindow.h"
24 karmPart::karmPart( TQWidget *parentWidget,
const char *widgetName,
25 TQObject *parent,
const char *name )
26 : DCOPObject (
"KarmDCOPIface" ), KParts::ReadWritePart(parent, name),
27 _accel ( new TDEAccel( parentWidget ) ),
31 setInstance( karmPartFactory::instance() );
34 _taskView =
new TaskView( parentWidget, widgetName );
37 _preferences = Preferences::instance();
43 KStdAction::open(
this, TQ_SLOT(fileOpen()), actionCollection());
44 KStdAction::saveAs(
this, TQ_SLOT(fileSaveAs()), actionCollection());
45 KStdAction::save(
this, TQ_SLOT(save()), actionCollection());
49 _watcher->updateMenus();
53 connect( _taskView, TQ_SIGNAL( totalTimesChanged(
long,
long ) ),
54 this, TQ_SLOT( updateTime(
long,
long ) ) );
55 connect( _taskView, TQ_SIGNAL( selectionChanged ( TQListViewItem * )),
56 this, TQ_SLOT(slotSelectionChanged()));
57 connect( _taskView, TQ_SIGNAL( updateButtons() ),
58 this, TQ_SLOT(slotSelectionChanged()));
62 TQ_SIGNAL( contextMenuRequested( TQListViewItem*,
const TQPoint&,
int )),
64 TQ_SLOT( contextMenuRequest( TQListViewItem*,
const TQPoint&,
int )));
66 _tray =
new KarmTray(
this );
68 connect( _tray, TQ_SIGNAL( quitSelected() ), TQ_SLOT( quit() ) );
70 connect( _taskView, TQ_SIGNAL( timersActive() ), _tray, TQ_SLOT( startClock() ) );
71 connect( _taskView, TQ_SIGNAL( timersActive() ),
this, TQ_SLOT( enableStopAll() ));
72 connect( _taskView, TQ_SIGNAL( timersInactive() ), _tray, TQ_SLOT( stopClock() ) );
73 connect( _taskView, TQ_SIGNAL( timersInactive() ),
this, TQ_SLOT( disableStopAll()));
74 connect( _taskView, TQ_SIGNAL( tasksChanged( TQPtrList<Task> ) ),
75 _tray, TQ_SLOT( updateToolTip( TQPtrList<Task> ) ));
81 _preferences->emitSignals();
82 slotSelectionChanged();
85 setXMLFile(
"karmui.rc");
98 void karmPart::slotSelectionChanged()
101 actionDelete->setEnabled(item);
102 actionEdit->setEnabled(item);
104 actionStop->setEnabled(item && item->
isRunning());
105 actionMarkAsComplete->setEnabled(item && !item->
isComplete());
106 actionMarkAsIncomplete->setEnabled(item && item->
isComplete());
109 void karmPart::makeMenus()
116 (void) KStdAction::quit(
this, TQ_SLOT(
quit() ), actionCollection());
117 (void) KStdAction::print(
this, TQ_SLOT( print() ), actionCollection());
118 actionKeyBindings = KStdAction::keyBindings(
this, TQ_SLOT( keyBindings() ),
119 actionCollection() );
120 actionPreferences = KStdAction::preferences(_preferences,
121 TQ_SLOT(showDialog()),
122 actionCollection() );
123 (void) KStdAction::save(
this, TQ_SLOT(
save() ), actionCollection() );
124 TDEAction* actionStartNewSession =
new TDEAction( i18n(
"Start &New Session"),
127 TQ_SLOT( startNewSession() ),
129 "start_new_session");
130 TDEAction* actionResetAll =
new TDEAction( i18n(
"&Reset All Times"),
133 TQ_SLOT( resetAllTimes() ),
136 actionStart =
new TDEAction( i18n(
"&Start"),
137 TQString::fromLatin1(
"1rightarrow"), Key_S,
139 TQ_SLOT( startCurrentTimer() ), actionCollection(),
141 actionStop =
new TDEAction( i18n(
"S&top"),
142 TQString::fromLatin1(
"process-stop"), 0,
144 TQ_SLOT( stopCurrentTimer() ), actionCollection(),
146 actionStopAll =
new TDEAction( i18n(
"Stop &All Timers"),
149 TQ_SLOT( stopAllTimers() ), actionCollection(),
151 actionStopAll->setEnabled(
false);
153 actionNew =
new TDEAction( i18n(
"&New..."),
154 TQString::fromLatin1(
"document-new"), CTRL+Key_N,
156 TQ_SLOT( newTask() ), actionCollection(),
158 actionNewSub =
new TDEAction( i18n(
"New &Subtask..."),
159 TQString::fromLatin1(
"application-vnd.tde.tdemultiple"), CTRL+ALT+Key_N,
161 TQ_SLOT( newSubTask() ), actionCollection(),
163 actionDelete =
new TDEAction( i18n(
"&Delete"),
164 TQString::fromLatin1(
"edit-delete"), Key_Delete,
166 TQ_SLOT( deleteTask() ), actionCollection(),
168 actionEdit =
new TDEAction( i18n(
"&Edit..."),
169 TQString::fromLatin1(
"edit"), CTRL + Key_E,
171 TQ_SLOT( editTask() ), actionCollection(),
180 actionMarkAsComplete =
new TDEAction( i18n(
"&Mark as Complete"),
181 TQString::fromLatin1(
"text-x-generic"),
184 TQ_SLOT( markTaskAsComplete() ),
187 actionMarkAsIncomplete =
new TDEAction( i18n(
"&Mark as Incomplete"),
188 TQString::fromLatin1(
"text-x-generic"),
191 TQ_SLOT( markTaskAsIncomplete() ),
193 "mark_as_incomplete");
194 actionClipTotals =
new TDEAction( i18n(
"&Copy Totals to Clipboard"),
195 TQString::fromLatin1(
"klipper"),
198 TQ_SLOT( clipTotals() ),
201 actionClipHistory =
new TDEAction( i18n(
"Copy &History to Clipboard"),
202 TQString::fromLatin1(
"klipper"),
205 TQ_SLOT( clipHistory() ),
209 new TDEAction( i18n(
"Import &Legacy Flat File..."), 0,
210 _taskView, TQ_SLOT(loadFromFlatFile()), actionCollection(),
212 new TDEAction( i18n(
"&Export to CSV File..."), 0,
213 _taskView, TQ_SLOT(exportcsvFile()), actionCollection(),
215 new TDEAction( i18n(
"Export &History to CSV File..."), 0,
216 this, TQ_SLOT(exportcsvHistory()), actionCollection(),
217 "export_csvhistory");
218 new TDEAction( i18n(
"Import Tasks From &Planner..."), 0,
219 _taskView, TQ_SLOT(importPlanner()), actionCollection(),
221 new TDEAction( i18n(
"Configure KArm..."), 0,
222 _preferences, TQ_SLOT(showDialog()), actionCollection(),
233 actionKeyBindings->setToolTip( i18n(
"Configure key bindings") );
234 actionKeyBindings->setWhatsThis( i18n(
"This will let you configure key"
235 "bindings which is specific to karm") );
237 actionStartNewSession->setToolTip( i18n(
"Start a new session") );
238 actionStartNewSession->setWhatsThis( i18n(
"This will reset the session time "
239 "to 0 for all tasks, to start a "
240 "new session, without affecting "
242 actionResetAll->setToolTip( i18n(
"Reset all times") );
243 actionResetAll->setWhatsThis( i18n(
"This will reset the session and total "
244 "time to 0 for all tasks, to restart from "
247 actionStart->setToolTip( i18n(
"Start timing for selected task") );
248 actionStart->setWhatsThis( i18n(
"This will start timing for the selected "
250 "It is even possible to time several tasks "
251 "simultaneously.\n\n"
252 "You may also start timing of a tasks by "
253 "double clicking the left mouse "
254 "button on a given task. This will, however, "
255 "stop timing of other tasks."));
257 actionStop->setToolTip( i18n(
"Stop timing of the selected task") );
258 actionStop->setWhatsThis( i18n(
"Stop timing of the selected task") );
260 actionStopAll->setToolTip( i18n(
"Stop all of the active timers") );
261 actionStopAll->setWhatsThis( i18n(
"Stop all of the active timers") );
263 actionNew->setToolTip( i18n(
"Create new top level task") );
264 actionNew->setWhatsThis( i18n(
"This will create a new top level task.") );
266 actionDelete->setToolTip( i18n(
"Delete selected task") );
267 actionDelete->setWhatsThis( i18n(
"This will delete the selected task and "
268 "all its subtasks.") );
270 actionEdit->setToolTip( i18n(
"Edit name or times for selected task") );
271 actionEdit->setWhatsThis( i18n(
"This will bring up a dialog box where you "
272 "may edit the parameters for the selected "
280 actionClipTotals->setToolTip(i18n(
"Copy task totals to clipboard"));
281 actionClipHistory->setToolTip(i18n(
"Copy time card history to clipboard."));
283 slotSelectionChanged();
290 connect(_taskView, TQ_SIGNAL(textChanged()),
294 disconnect(_taskView, TQ_SIGNAL(textChanged()),
298 ReadWritePart::setReadWrite(rw);
304 TDEAction *
save = actionCollection()->action(KStdAction::stdName(KStdAction::Save));
311 save->setEnabled(
true);
313 save->setEnabled(
false);
316 ReadWritePart::setModified(modified);
322 _taskView->
load(m_file);
325 emit setStatusBarText( m_url.prettyURL() );
333 if (isReadWrite() ==
false)
338 if (file.open(IO_WriteOnly) ==
false)
342 TQTextStream stream(&file);
349 void karmPart::fileOpen()
354 TQString file_name = KFileDialog::getOpenFileName();
356 if (file_name.isEmpty() ==
false)
360 void karmPart::fileSaveAs()
363 TQString file_name = KFileDialog::getSaveFileName();
364 if (file_name.isEmpty() ==
false)
371 #include <tdeaboutdata.h>
372 #include <tdelocale.h>
374 TDEInstance* karmPartFactory::s_instance = 0L;
375 TDEAboutData* karmPartFactory::s_about = 0L;
377 karmPartFactory::karmPartFactory()
382 karmPartFactory::~karmPartFactory()
390 KParts::Part* karmPartFactory::createPartObject( TQWidget *parentWidget,
const char *widgetName,
391 TQObject *parent,
const char *name,
392 const char *classname,
const TQStringList &args )
398 if (TQCString(classname) ==
"KParts::ReadOnlyPart")
404 TDEInstance* karmPartFactory::instance()
408 s_about =
new TDEAboutData(
"karmpart", I18N_NOOP(
"karmPart"),
"0.1");
409 s_about->addAuthor(
"Thorsten Staerk", 0,
"thorsten@staerk.de");
410 s_instance =
new TDEInstance(s_about);
417 TDE_EXPORT
void* init_libkarmpart()
419 TDEGlobal::locale()->insertCatalogue(
"karm");
420 return new karmPartFactory;
424 void karmPart::contextMenuRequest( TQListViewItem*,
const TQPoint& point,
int )
426 TQPopupMenu* pop =
dynamic_cast<TQPopupMenu*
>(
427 factory()->container( i18n(
"task_popup" ),
this ) );
451 return _preferences->promptDelete();
456 _preferences->setPromptDelete( prompt );
465 while ( rval.isEmpty() && task )
467 rval = _hasTask( task, taskname );
468 task = task->nextSibling();
481 kdDebug(5970) <<
"Saving time data to disk." << endl;
482 TQString err=_taskView->
save();
491 DesktopList desktopList;
492 TQString uid = _taskView->
addTask( taskname, 0, 0, desktopList );
493 kdDebug(5970) <<
"MainWindow::addTask( " << taskname <<
" ) returns " << uid << endl;
494 if ( uid.length() > 0 )
return 0;
499 return KARM_ERR_GENERIC_SAVE_FAILED;
506 TQString err=
"no such task";
507 for (
int i=0; i<_taskView->
count(); i++)
512 if (err==TQString()) err=
"task name is abigious";
513 if (err==
"no such task") err=TQString();
524 (
const TQString& taskId,
const TQString& datetime,
long minutes )
529 TQDateTime startDateTime;
532 if ( minutes <= 0 ) rval = KARM_ERR_INVALID_DURATION;
539 t = _hasUid( task, taskId );
540 task = task->nextSibling();
542 if ( t == NULL ) rval = KARM_ERR_UID_NOT_FOUND;
547 startDate = TQDate::fromString( datetime, TQt::ISODate );
548 if ( datetime.length() > 10 )
550 startTime = TQTime::fromString( datetime, TQt::ISODate );
552 else startTime = TQTime( 12, 0 );
553 if ( startDate.isValid() && startTime.isValid() )
555 startDateTime = TQDateTime( startDate, startTime );
557 else rval = KARM_ERR_INVALID_DATE;
564 t->
changeTotalTimes( t->sessionTime() + minutes, t->totalTime() + minutes );
565 if ( ! _taskView->
storage()->
bookTime( t, startDateTime, minutes * 60 ) )
567 rval = KARM_ERR_GENERIC_SAVE_FAILED;
578 if ( mkb <= KARM_MAX_ERROR_NO )
return m_error[ mkb ];
579 else return i18n(
"Invalid error number: %1" ).arg( mkb );
587 kdDebug(5970) <<
"MainWindow::totalTimeForTask( " << taskId <<
" )" << endl;
594 t = _hasUid( task, taskId );
595 task = task->nextSibling();
599 rval = t->totalTime();
600 kdDebug(5970) <<
"MainWindow::totalTimeForTask - task found: rval = " << rval << endl;
604 kdDebug(5970) <<
"MainWindow::totalTimeForTask - task not found" << endl;
605 rval = KARM_ERR_UID_NOT_FOUND;
611 TQString karmPart::_hasTask(
Task* task,
const TQString &taskname )
const
614 if ( task->
name() == taskname )
621 while ( rval.isEmpty() && nexttask )
623 rval = _hasTask( nexttask, taskname );
624 nexttask = nexttask->nextSibling();
630 Task* karmPart::_hasUid(
Task* task,
const TQString &uid )
const
636 if ( task->
uid() == uid ) rval = task;
640 while ( !rval && nexttask )
642 rval = _hasUid( nexttask, uid );
643 nexttask = nexttask->nextSibling();
651 TQString err=
"no such task";
652 for (
int i=0; i<_taskView->
count(); i++)
665 TQString err=
"no such task";
666 for (
int i=0; i<_taskView->
count(); i++)
677 TQString
karmPart::exportcsvfile( TQString filename, TQString from, TQString to,
int type,
bool decimalMinutes,
bool allTasks, TQString delimiter, TQString quote )
683 rc.
from=TQDate::fromString( from );
686 rc.
to=TQDate::fromString( to );
688 return _taskView->
report( rc );
696 void karmPart::startNewSession()
702 #include <tqpopupmenu.h>
703 #include "karm_part.moc"
bool bookTime(const Task *task, const TQDateTime &startDateTime, long durationInSeconds)
Book time to a task.
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.
Container and interface for the tasks.
KarmStorage * storage()
Returns a pointer to storage object.
Task * first_child() const
Return the first item in the view, cast to a Task pointer.
long count()
Return the total number if items in the view.
TQString importPlanner(TQString fileName="")
used to import tasks from imendio planner
TQString addTask(const TQString &taskame, long total, long session, const DesktopList &desktops, Task *parent=0)
Add a task to view and storage.
TQString report(const ReportCriteria &rc)
call export function for csv totals or history
Task * current_item() const
Return the current item in the view, cast to a Task pointer.
TQString save()
Save to persistent storage.
Task * item_at_index(int i)
Return the i'th item (zero-based), cast to a Task pointer.
void load(TQString filename="")
Load the view from storage.
void deleteTask(bool markingascomplete=false)
Delete task (and children) from view.
void startTimerFor(Task *task, TQDateTime startTime=TQDateTime::currentDateTime())
starts timer for task.
void startNewSession()
Reset session time to zero for all tasks.
A class representing a task.
bool isComplete()
Return true if task is complete (percent complete equals 100).
TQString name() const
returns the name of this task.
Task * firstChild() const
return parent Task or null in case of TaskView.
void changeTotalTimes(long minutesSession, long minutes)
adds minutes to total and session time
TQString uid() const
Return unique iCalendar Todo ID for this task.
void setPercentComplete(const int percent, KarmStorage *storage)
Update percent complete for this task.
bool isRunning() const
return the state of a task - if it's running or not
virtual void setReadWrite(bool rw)
This is a virtual function inherited from KParts::ReadWritePart.
virtual void setModified(bool modified)
Reimplemented to disable and enable Save action.
bool getpromptdelete()
get if prompted on deleting a task
int addTask(const TQString &taskName)
TQString getError(int karmErrorNumber) const
TQString exportcsvfile(TQString filename, TQString from, TQString to, int type=0, bool decimalMinutes=true, bool allTasks=true, TQString delimiter="r", TQString quote="q")
export csv history or totals file
TQString setPerCentComplete(const TQString &taskName, int PerCent)
virtual bool saveFile()
This must be implemented by each read-write part.
TQString starttimerfor(const TQString &taskname)
Start timer for all tasks with the summary taskname.
int bookTime(const TQString &taskId, const TQString &iso8601StartDateTime, long durationInMinutes)
int totalMinutesForTaskId(const TQString &taskId)
Total time currently associated with a task.
TQString stoptimerfor(const TQString &taskname)
Stop timer for all tasks with the summary taskname.
TQString taskIdFromName(const TQString &taskName) const
Return id of task found, empty string if no match.
TQString version() const
Return karm version.
TQString setpromptdelete(bool prompt)
set if prompted on deleting a task
virtual bool save()
save your tasks
void quit()
Graceful shutdown.
TQString importplannerfile(TQString filename)
import planner project file
virtual bool openFile()
This must be implemented by each part.
TQString deletetodo()
delete the current item