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, TQT_SLOT(fileOpen()), actionCollection());
44 KStdAction::saveAs(
this, TQT_SLOT(fileSaveAs()), actionCollection());
45 KStdAction::save(
this, TQT_SLOT(save()), actionCollection());
49 _watcher->updateMenus();
53 connect( _taskView, TQT_SIGNAL( totalTimesChanged(
long,
long ) ),
54 this, TQT_SLOT( updateTime(
long,
long ) ) );
55 connect( _taskView, TQT_SIGNAL( selectionChanged ( TQListViewItem * )),
56 this, TQT_SLOT(slotSelectionChanged()));
57 connect( _taskView, TQT_SIGNAL( updateButtons() ),
58 this, TQT_SLOT(slotSelectionChanged()));
62 TQT_SIGNAL( contextMenuRequested( TQListViewItem*,
const TQPoint&,
int )),
64 TQT_SLOT( contextMenuRequest( TQListViewItem*,
const TQPoint&,
int )));
66 _tray =
new KarmTray(
this );
68 connect( _tray, TQT_SIGNAL( quitSelected() ), TQT_SLOT( quit() ) );
70 connect( _taskView, TQT_SIGNAL( timersActive() ), _tray, TQT_SLOT( startClock() ) );
71 connect( _taskView, TQT_SIGNAL( timersActive() ),
this, TQT_SLOT( enableStopAll() ));
72 connect( _taskView, TQT_SIGNAL( timersInactive() ), _tray, TQT_SLOT( stopClock() ) );
73 connect( _taskView, TQT_SIGNAL( timersInactive() ),
this, TQT_SLOT( disableStopAll()));
74 connect( _taskView, TQT_SIGNAL( tasksChanged( TQPtrList<Task> ) ),
75 _tray, TQT_SLOT( updateToolTip( TQPtrList<Task> ) ));
81 _preferences->emitSignals();
82 slotSelectionChanged();
85 setXMLFile(
"karmui.rc");
98 void karmPart::slotSelectionChanged()
100 Task* item= _taskView->current_item();
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, TQT_SLOT( quit() ), actionCollection());
117 (void) KStdAction::print(
this, TQT_SLOT( print() ), actionCollection());
118 actionKeyBindings = KStdAction::keyBindings(
this, TQT_SLOT( keyBindings() ),
119 actionCollection() );
120 actionPreferences = KStdAction::preferences(TQT_TQOBJECT(_preferences),
121 TQT_SLOT(showDialog()),
122 actionCollection() );
123 (void) KStdAction::save(
this, TQT_SLOT( save() ), actionCollection() );
124 TDEAction* actionStartNewSession =
new TDEAction( i18n(
"Start &New Session"),
127 TQT_SLOT( startNewSession() ),
129 "start_new_session");
130 TDEAction* actionResetAll =
new TDEAction( i18n(
"&Reset All Times"),
133 TQT_SLOT( resetAllTimes() ),
136 actionStart =
new TDEAction( i18n(
"&Start"),
137 TQString::fromLatin1(
"1rightarrow"), Key_S,
138 TQT_TQOBJECT(_taskView),
139 TQT_SLOT( startCurrentTimer() ), actionCollection(),
141 actionStop =
new TDEAction( i18n(
"S&top"),
142 TQString::fromLatin1(
"process-stop"), 0,
143 TQT_TQOBJECT(_taskView),
144 TQT_SLOT( stopCurrentTimer() ), actionCollection(),
146 actionStopAll =
new TDEAction( i18n(
"Stop &All Timers"),
148 TQT_TQOBJECT(_taskView),
151 actionStopAll->setEnabled(
false);
153 actionNew =
new TDEAction( i18n(
"&New..."),
154 TQString::fromLatin1(
"document-new"), CTRL+Key_N,
155 TQT_TQOBJECT(_taskView),
156 TQT_SLOT( newTask() ), actionCollection(),
158 actionNewSub =
new TDEAction( i18n(
"New &Subtask..."),
159 TQString::fromLatin1(
"application-vnd.tde.tdemultiple"), CTRL+ALT+Key_N,
160 TQT_TQOBJECT(_taskView),
161 TQT_SLOT( newSubTask() ), actionCollection(),
163 actionDelete =
new TDEAction( i18n(
"&Delete"),
164 TQString::fromLatin1(
"edit-delete"), Key_Delete,
165 TQT_TQOBJECT(_taskView),
166 TQT_SLOT( deleteTask() ), actionCollection(),
168 actionEdit =
new TDEAction( i18n(
"&Edit..."),
169 TQString::fromLatin1(
"edit"), CTRL + Key_E,
170 TQT_TQOBJECT(_taskView),
171 TQT_SLOT( editTask() ), actionCollection(),
180 actionMarkAsComplete =
new TDEAction( i18n(
"&Mark as Complete"),
181 TQString::fromLatin1(
"text-x-generic"),
183 TQT_TQOBJECT(_taskView),
184 TQT_SLOT( markTaskAsComplete() ),
187 actionMarkAsIncomplete =
new TDEAction( i18n(
"&Mark as Incomplete"),
188 TQString::fromLatin1(
"text-x-generic"),
190 TQT_TQOBJECT(_taskView),
191 TQT_SLOT( markTaskAsIncomplete() ),
193 "mark_as_incomplete");
194 actionClipTotals =
new TDEAction( i18n(
"&Copy Totals to Clipboard"),
195 TQString::fromLatin1(
"klipper"),
197 TQT_TQOBJECT(_taskView),
198 TQT_SLOT( clipTotals() ),
201 actionClipHistory =
new TDEAction( i18n(
"Copy &History to Clipboard"),
202 TQString::fromLatin1(
"klipper"),
204 TQT_TQOBJECT(_taskView),
205 TQT_SLOT( clipHistory() ),
209 new TDEAction( i18n(
"Import &Legacy Flat File..."), 0,
210 TQT_TQOBJECT(_taskView), TQT_SLOT(loadFromFlatFile()), actionCollection(),
212 new TDEAction( i18n(
"&Export to CSV File..."), 0,
213 TQT_TQOBJECT(_taskView), TQT_SLOT(exportcsvFile()), actionCollection(),
215 new TDEAction( i18n(
"Export &History to CSV File..."), 0,
216 TQT_TQOBJECT(
this), TQT_SLOT(exportcsvHistory()), actionCollection(),
217 "export_csvhistory");
218 new TDEAction( i18n(
"Import Tasks From &Planner..."), 0,
219 TQT_TQOBJECT(_taskView), TQT_SLOT(importPlanner()), actionCollection(),
221 new TDEAction( i18n(
"Configure KArm..."), 0,
222 TQT_TQOBJECT(_preferences), TQT_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, TQT_SIGNAL(textChanged()),
291 this, TQT_SLOT(setModified()));
294 disconnect(_taskView, TQT_SIGNAL(textChanged()),
295 this, TQT_SLOT(setModified()));
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 KDE_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 ) );
445 _taskView->deleteTask();
451 return _preferences->promptDelete();
456 _preferences->setPromptDelete( prompt );
464 Task* task = _taskView->first_child();
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++)
509 if ((_taskView->item_at_index(i)->name()==taskName))
512 if (err==TQString()) err=
"task name is abigious";
513 if (err==
"no such task") err=TQString();
518 _taskView->item_at_index(index)->setPercentComplete( perCent, _taskView->storage() );
524 (
const TQString& taskId,
const TQString& datetime,
long minutes )
529 TQDateTime startDateTime;
532 if ( minutes <= 0 ) rval = KARM_ERR_INVALID_DURATION;
535 task = _taskView->first_child();
539 t = _hasUid( task, taskId );
540 task = task->nextSibling();
542 if ( t == NULL ) rval = KARM_ERR_UID_NOT_FOUND;
547 startDate = TQDate::fromString( datetime, Qt::ISODate );
548 if ( datetime.length() > 10 )
550 startTime = TQTime::fromString( datetime, Qt::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;
590 task = _taskView->first_child();
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++)
654 if ((_taskView->item_at_index(i)->name()==taskname))
656 _taskView->startTimerFor( _taskView->item_at_index(i) );
665 TQString err=
"no such task";
666 for (
int i=0; i<_taskView->count(); i++)
668 if ((_taskView->item_at_index(i)->name()==taskname))
670 _taskView->stopTimerFor( _taskView->item_at_index(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 );
693 return _taskView->importPlanner(fileName);
696 void karmPart::startNewSession()
698 _taskView->startNewSession();
702 #include <tqpopupmenu.h> 703 #include "karm_part.moc" virtual void setReadWrite(bool rw)
This is a virtual function inherited from KParts::ReadWritePart.
TQDate from
For history reports, the lower bound of the date range to report on.
TQString name() const
returns the name of this task.
TQString delimiter
The delimiter to use when outputting comma-seperated value reports.
virtual bool openFile()
This must be implemented by each part.
void changeTotalTimes(long minutesSession, long minutes)
adds minutes to total and session time
TQString taskIdFromName(const TQString &taskName) const
Return id of task found, empty string if no match.
virtual void setModified(bool modified)
Reimplemented to disable and enable Save action.
int bookTime(const TQString &taskId, const TQString &iso8601StartDateTime, long durationInMinutes)
TQString setpromptdelete(bool prompt)
set if prompted on deleting a task
bool isComplete()
Return true if task is complete (percent complete equals 100).
void quit()
Graceful shutdown.
Task * firstChild() const
return parent Task or null in case of TaskView.
REPORTTYPE reportType
The type of report we are running.
TQString starttimerfor(const TQString &taskname)
Start timer for all tasks with the summary taskname.
Stores entries from export dialog.
bool isRunning() const
return the state of a task - if it's running or not
int addTask(const TQString &taskName)
TQString deletetodo()
delete the current item
void stopAllTimers()
Tells the listener to stop timing.
int totalMinutesForTaskId(const TQString &taskId)
Total time currently associated with a task.
virtual bool save()
save your tasks
TQDate to
For history reports, the upper bound of the date range to report on.
bool getpromptdelete()
get if prompted on deleting a task
bool decimalMinutes
True if the durations should be output in decimal hours.
TQString version() const
Return karm version.
bool allTasks
True if the report should contain all tasks in Karm.
REPORTTYPE
The different report types.
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 quote
The quote to use for text fields when outputting comma-seperated reports.
TQString uid() const
Return unique iCalendar Todo ID for this task.
TQString getError(int karmErrorNumber) const
virtual bool saveFile()
This must be implemented by each read-write part.
TQString setPerCentComplete(const TQString &taskName, int PerCent)
TQString stoptimerfor(const TQString &taskname)
Stop timer for all tasks with the summary taskname.
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.
TQString importplannerfile(TQString filename)
import planner project file