From c5804975ec535433effc1dbecefa1b51910b1b67 Mon Sep 17 00:00:00 2001 From: Roman Savochenko Date: Wed, 22 Nov 2023 09:45:36 +0200 Subject: KARM: Non negative busy counter and Item Reset Signed-off-by: Roman Savochenko --- karm/idletimedetector.cpp | 20 +++++++++++++------- karm/karmui.rc | 2 ++ karm/mainwindow.cpp | 9 +++++++++ karm/mainwindow.h | 1 + karm/preferences.cpp | 2 +- karm/taskview.cpp | 5 +++++ karm/taskview.h | 3 +++ 7 files changed, 34 insertions(+), 8 deletions(-) diff --git a/karm/idletimedetector.cpp b/karm/idletimedetector.cpp index 110eacd0..dd2c4d56 100644 --- a/karm/idletimedetector.cpp +++ b/karm/idletimedetector.cpp @@ -1,3 +1,5 @@ +#include + #include "idletimedetector.h" #include @@ -67,30 +69,34 @@ void IdleTimeDetector::informOverrun(int idleSeconds) _timer->stop(); - TQDateTime idleStart = TQDateTime::currentDateTime().addSecs(-idleSeconds); - TQString idleStartTQString = TDEGlobal::locale()->formatTime(idleStart.time()); + struct timespec tm; + + clock_gettime(CLOCK_MONOTONIC, &tm); + int start = tm.tv_sec - idleSeconds; + TQDateTime idleStart = TQDateTime::currentDateTime().addSecs(-idleSeconds); int id = TQMessageBox::warning( 0, i18n("Idle Detection"), i18n("Desktop has been idle since %1." - " What should we do?").arg(idleStartTQString), + " What should we do?").arg(TDEGlobal::locale()->formatTime(idleStart.time())), i18n("Revert && Stop"), i18n("Revert && Continue"), i18n("Continue Timing"),0,2); - TQDateTime end = TQDateTime::currentDateTime(); - int diff = idleStart.secsTo(end)/secsPerMinute; + + clock_gettime(CLOCK_MONOTONIC, &tm); + int diff = tm.tv_sec - start; if (id == 0) { // Revert And Stop kdDebug(5970) << "Now it is " << TQDateTime::currentDateTime() << endl; kdDebug(5970) << "Reverting timer to " << TDEGlobal::locale()->formatTime(idleStart.time()).ascii() << endl; - emit(extractTime(idleSeconds/60+diff)); // we need to subtract the time that has been added during idleness. + emit(extractTime(diff/60)); emit(stopAllTimersAt(idleStart)); } else if (id == 1) { // Revert and Continue - emit(extractTime(idleSeconds/60+diff)); + emit(extractTime(diff/60)); _timer->start(testInterval); } else diff --git a/karm/karmui.rc b/karm/karmui.rc index 77818aeb..34efa9cb 100644 --- a/karm/karmui.rc +++ b/karm/karmui.rc @@ -19,6 +19,7 @@ &Clock + @@ -50,6 +51,7 @@ + diff --git a/karm/mainwindow.cpp b/karm/mainwindow.cpp index 8265db05..13879e62 100644 --- a/karm/mainwindow.cpp +++ b/karm/mainwindow.cpp @@ -123,6 +123,7 @@ void MainWindow::slotSelectionChanged() actionEdit->setEnabled(item); actionStart->setEnabled(item && !item->isRunning() && !item->isComplete()); actionStop->setEnabled(item && item->isRunning()); + actionResetTime->setEnabled(item && !item->isRunning()); actionMarkAsComplete->setEnabled(item && !item->isComplete()); actionMarkAsIncomplete->setEnabled(item && item->isComplete()); } @@ -281,6 +282,11 @@ void MainWindow::makeMenus() TQT_TQOBJECT(_taskView), TQT_SLOT( stopCurrentTimer() ), actionCollection(), "stop"); + actionResetTime = new TDEAction( i18n("Re&set Time"), + 0, + TQT_TQOBJECT(_taskView), + TQT_SLOT( resetTimeCurrentTask() ), actionCollection(), + "reset_times"); actionStopAll = new TDEAction( i18n("Stop &All Timers"), Key_Escape, TQT_TQOBJECT(_taskView), @@ -406,6 +412,9 @@ void MainWindow::makeMenus() actionStopAll->setToolTip( i18n("Stop all of the active timers") ); actionStopAll->setWhatsThis( i18n("Stop all of the active timers") ); + actionResetTime->setToolTip( i18n("Reset times of the selected task") ); + actionResetTime->setWhatsThis( i18n("Reset times of the selected task") ); + actionNew->setToolTip( i18n("Create new top level task") ); actionNew->setWhatsThis( i18n("This will create a new top level task.") ); diff --git a/karm/mainwindow.h b/karm/mainwindow.h index 7d055802..0ca6021b 100644 --- a/karm/mainwindow.h +++ b/karm/mainwindow.h @@ -42,6 +42,7 @@ class MainWindow : public KParts::MainWindow, virtual public KarmDCOPIface KarmTray* _tray; TDEAction* actionStart; TDEAction* actionStop; + TDEAction* actionResetTime; TDEAction* actionStopAll; TDEAction* actionDelete; TDEAction* actionEdit; diff --git a/karm/preferences.cpp b/karm/preferences.cpp index 29b242cf..8a81d260 100644 --- a/karm/preferences.cpp +++ b/karm/preferences.cpp @@ -58,7 +58,7 @@ void Preferences::makeBehaviorPage() ( i18n("Detect desktop as idle after"), behaviorPage, "_doIdleDetectionW"); _idleDetectValueW = new TQSpinBox (1,60*24, 1, behaviorPage, "_idleDetectValueW"); - _idleDetectValueW->setSuffix(i18n(" min")); + _idleDetectValueW->setSuffix(i18n(" sec")); _promptDeleteW = new TQCheckBox ( i18n( "Prompt before deleting tasks" ), behaviorPage, "_promptDeleteW" ); diff --git a/karm/taskview.cpp b/karm/taskview.cpp index d1b80bf8..9d4e1ad7 100644 --- a/karm/taskview.cpp +++ b/karm/taskview.cpp @@ -479,6 +479,11 @@ void TaskView::stopCurrentTimer() stopTimerFor( current_item()); } +void TaskView::resetTimeCurrentTask() +{ + if(current_item()) current_item()->resetTimes(); +} + void TaskView::minuteUpdate() { addTimeToActiveTasks(1, false); diff --git a/karm/taskview.h b/karm/taskview.h index c74f86cf..f5e32907 100644 --- a/karm/taskview.h +++ b/karm/taskview.h @@ -101,6 +101,9 @@ class TaskView : public TDEListView /** Stop all running timers as if it was qdt */ void stopAllTimersAt(TQDateTime qdt); + /** Reset session and total time to zero for the current item in the view. */ + void resetTimeCurrentTask(); + /** Calls newTask dialog with caption "New Task". */ void newTask(); -- cgit v1.2.3