2 #include "kaccelmenuwatch.h"
4 #include "karmerrors.h"
6 #include "preferences.h"
11 #include <kinstance.h>
13 #include <kstdaction.h>
14 #include <kfiledialog.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 KAccel( 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()
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 KAction* actionStartNewSession =
new KAction( i18n(
"Start &New Session"),
127 TQT_SLOT( startNewSession() ),
129 "start_new_session");
130 KAction* actionResetAll =
new KAction( i18n(
"&Reset All Times"),
133 TQT_SLOT( resetAllTimes() ),
136 actionStart =
new KAction( i18n(
"&Start"),
137 TQString::fromLatin1(
"1rightarrow"), Key_S,
138 TQT_TQOBJECT(_taskView),
139 TQT_SLOT( startCurrentTimer() ), actionCollection(),
141 actionStop =
new KAction( i18n(
"S&top"),
142 TQString::fromLatin1(
"stop"), 0,
143 TQT_TQOBJECT(_taskView),
144 TQT_SLOT( stopCurrentTimer() ), actionCollection(),
146 actionStopAll =
new KAction( i18n(
"Stop &All Timers"),
148 TQT_TQOBJECT(_taskView),
149 TQT_SLOT( stopAllTimers() ), actionCollection(),
151 actionStopAll->setEnabled(
false);
153 actionNew =
new KAction( i18n(
"&New..."),
154 TQString::fromLatin1(
"filenew"), CTRL+Key_N,
155 TQT_TQOBJECT(_taskView),
156 TQT_SLOT( newTask() ), actionCollection(),
158 actionNewSub =
new KAction( i18n(
"New &Subtask..."),
159 TQString::fromLatin1(
"kmultiple"), CTRL+ALT+Key_N,
160 TQT_TQOBJECT(_taskView),
161 TQT_SLOT( newSubTask() ), actionCollection(),
163 actionDelete =
new KAction( i18n(
"&Delete"),
164 TQString::fromLatin1(
"editdelete"), Key_Delete,
165 TQT_TQOBJECT(_taskView),
166 TQT_SLOT( deleteTask() ), actionCollection(),
168 actionEdit =
new KAction( i18n(
"&Edit..."),
169 TQString::fromLatin1(
"edit"), CTRL + Key_E,
170 TQT_TQOBJECT(_taskView),
171 TQT_SLOT( editTask() ), actionCollection(),
180 actionMarkAsComplete =
new KAction( i18n(
"&Mark as Complete"),
181 TQString::fromLatin1(
"document"),
183 TQT_TQOBJECT(_taskView),
184 TQT_SLOT( markTaskAsComplete() ),
187 actionMarkAsIncomplete =
new KAction( i18n(
"&Mark as Incomplete"),
188 TQString::fromLatin1(
"document"),
190 TQT_TQOBJECT(_taskView),
191 TQT_SLOT( markTaskAsIncomplete() ),
193 "mark_as_incomplete");
194 actionClipTotals =
new KAction( i18n(
"&Copy Totals to Clipboard"),
195 TQString::fromLatin1(
"klipper"),
197 TQT_TQOBJECT(_taskView),
198 TQT_SLOT( clipTotals() ),
201 actionClipHistory =
new KAction( i18n(
"Copy &History to Clipboard"),
202 TQString::fromLatin1(
"klipper"),
204 TQT_TQOBJECT(_taskView),
205 TQT_SLOT( clipHistory() ),
209 new KAction( i18n(
"Import &Legacy Flat File..."), 0,
210 TQT_TQOBJECT(_taskView), TQT_SLOT(loadFromFlatFile()), actionCollection(),
212 new KAction( i18n(
"&Export to CSV File..."), 0,
213 TQT_TQOBJECT(_taskView), TQT_SLOT(exportcsvFile()), actionCollection(),
215 new KAction( i18n(
"Export &History to CSV File..."), 0,
216 TQT_TQOBJECT(
this), TQT_SLOT(exportcsvHistory()), actionCollection(),
217 "export_csvhistory");
218 new KAction( i18n(
"Import Tasks From &Planner..."), 0,
219 TQT_TQOBJECT(_taskView), TQT_SLOT(importPlanner()), actionCollection(),
221 new KAction( 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()),
294 disconnect(_taskView, TQT_SIGNAL(textChanged()),
304 KAction *
save = actionCollection()->action(KStdAction::stdName(KStdAction::Save));
311 save->setEnabled(
true);
313 save->setEnabled(
false);
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 <kaboutdata.h>
374 KInstance* karmPartFactory::s_instance = 0L;
375 KAboutData* 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 KInstance* karmPartFactory::instance()
408 s_about =
new KAboutData(
"karmpart", I18N_NOOP(
"karmPart"),
"0.1");
409 s_about->addAuthor(
"Thorsten Staerk", 0,
"thorsten@staerk.de");
410 s_instance =
new KInstance(s_about);
417 KDE_EXPORT
void* init_libkarmpart()
419 KGlobal::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;
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;
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"