diff -Nru timeit-1.2.1/debian/changelog timeit-1.2.5/debian/changelog --- timeit-1.2.1/debian/changelog 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/debian/changelog 2013-09-25 14:19:47.000000000 +0000 @@ -1,3 +1,30 @@ +timeit (1.2.5) precise; urgency=low + + * Bugfix: Idle detection got into an infinite loop. + + -- Kent Asplund Wed, 25 Sep 2013 16:19:13 +0200 + +timeit (1.2.4) precise; urgency=low + + * Feature: Improved information in idle dialog + * Bugfix: Idle detection during hibernation and suspension. + + -- Kent Asplund Fri, 13 Sep 2013 15:29:40 +0200 + +timeit (1.2.3) precise; urgency=low + + * Feature: Quiet mode. + * Bugfix: Idle detection failed when computer was suspended to ram or hibernated + * Bugfix: Unable to compile (on some platforms) as an include was missing. + + -- Kent Asplund Wed, 21 Aug 2013 21:36:30 +0200 + +timeit (1.2.2) precise; urgency=low + + * Bugfix: Week summaries did not start and end on correct day. + + -- Kent Asplund Tue, 23 Jul 2013 07:06:02 +0200 + timeit (1.2.1) precise; urgency=low * Bugfix: Several build problems fixed. Binary files /tmp/WV8idM55XR/timeit-1.2.1/doc/html/C/TimeIT-IdleDialog.png and /tmp/9R9lV7YLn0/timeit-1.2.5/doc/html/C/TimeIT-IdleDialog.png differ diff -Nru timeit-1.2.1/doc/html/C/index.html timeit-1.2.5/doc/html/C/index.html --- timeit-1.2.1/doc/html/C/index.html 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/doc/html/C/index.html 2013-09-25 14:19:47.000000000 +0000 @@ -11,9 +11,9 @@

Introduction

-TimeIT is a tool intended to help you to keep track on how much time you -spend on tasks.

It is intended to be discreet and unobtrusive. It is using -workspace-tracking and idle detection to minimize the interaction needed, in the +TimeIT is a tool intended to help you to keep track on how much time you +spend on tasks.

It is intended to be discreet and unobtrusive. It is using +workspace-tracking and idle detection to minimize the interaction needed, in the intended use case you are not even interacting at all with the program

Download

@@ -39,7 +39,7 @@
  • Shows the state: green if timer(s) are running.
  • Toggles main window when clicked
  • -
  • Has a small menu on right click
  • +
  • Has a small menu on right click
@@ -49,14 +49,14 @@

Tasks

-Tasks can be organized in a tree where one task is parent to others thus grouping tasks bonded +Tasks can be organized in a tree where one task is parent to others thus grouping tasks bonded together like different parts of a project. Parents are then shown with the aggregated time. @@ -73,6 +73,23 @@

Start a task manually

Idle detection

+

Create/edit task

-Creating, or editing, a task is done through menu, toolbar or context menu. +Creating, or editing, a task is done through menu, toolbar or context menu. The dialog then opened contains possibility ty change following aspects of the task: -
+
Name
The name of the task
Parent
@@ -64,7 +64,7 @@
Workspace
-This is setting on which workspaces TimeIt should run the tasks timer. +This is setting on which workspaces TimeIt should run the tasks timer.
+ + + + +
+If TimeIT is detecting idle while a task, or tasks, are running it is presenting a dialog with three choices: +
+
Revert and stop
+
Idle time was not active. Reseting to last known active time and stop counting time
+
Revert and continue
+
Idle time was not active. Reseting to last known active time and Continuing counting time from current time
+
Continue
+
Time span was activity of the computer. Continuing counting time
+
+
+

Preferences

@@ -88,6 +105,8 @@
This is the maximum time of no activity before TimeIt decides that a break have occured. When this
Zero time
Shorter than this time will not be counted.
+
Quiet mode
+
Idle detection is not presenting a dialog questioning why the computer has been idle. No idle periods are registered as work.
@@ -107,7 +126,7 @@

Show/Edit time records

-

By double clicking or using context menu on an item in the summary you +

By double clicking or using context menu on an item in the summary you bring up a window showing the individual time recordings that together bring the sum shown in summary.

@@ -119,6 +138,6 @@

Reporting bugs

-Any found bugs are preferably reported on launchpad +Any found bugs are preferably reported on github - \ No newline at end of file + diff -Nru timeit-1.2.1/git_version_gen.sh timeit-1.2.5/git_version_gen.sh --- timeit-1.2.1/git_version_gen.sh 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/git_version_gen.sh 2013-09-25 14:19:47.000000000 +0000 @@ -28,7 +28,7 @@ else #Git failed to find version number. Falling back to Debian changelog. DEBIAN_VERSION=`head debian/changelog -n 1 | cut -d'(' -f2 |cut -d')' -f1` - VN="${DEBIAN_VERSION}-unofficial" + VN="${DEBIAN_VERSION}" fi if test -r $GVF diff -Nru timeit-1.2.1/src/DB/DefaultValues.h timeit-1.2.5/src/DB/DefaultValues.h --- timeit-1.2.1/src/DB/DefaultValues.h 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/DB/DefaultValues.h 2013-09-25 14:19:47.000000000 +0000 @@ -12,5 +12,5 @@ #define DEFAULT_GT 7 #define DEFAULT_COMPACTLAYOUT true #define DEFAULT_START_MINIMIZED false - +#define DEFAULT_QUIET_MODE false #endif /* DEFAULTVALUES_H_ */ diff -Nru timeit-1.2.1/src/GUI/IIdleDialog.h timeit-1.2.5/src/GUI/IIdleDialog.h --- timeit-1.2.1/src/GUI/IIdleDialog.h 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/GUI/IIdleDialog.h 2013-09-25 14:19:47.000000000 +0000 @@ -10,12 +10,16 @@ #include #include +#include +#include +#include class IIdleDialog { public: virtual ~IIdleDialog() {}; - virtual void setIdleStartTime(time_t idleStartTime) = 0; + virtual void setIdleStartTime(time_t idleStartTime) = 0; + virtual void setActiveTaskList(std::shared_ptr> activeTasks) = 0; virtual void show() = 0; virtual void attach(IActionObserver*) = 0; virtual void detach(IActionObserver*) = 0; diff -Nru timeit-1.2.1/src/GUI/internal/IdleDialog.cpp timeit-1.2.5/src/GUI/internal/IdleDialog.cpp --- timeit-1.2.1/src/GUI/internal/IdleDialog.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/GUI/internal/IdleDialog.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -65,11 +65,34 @@ m_idleStartTime = idleStartTime; } +void IdleDialog::setActiveTaskList(std::shared_ptr> activeTasks) +{ + std::stringstream text; + int i=0; + for ( Task task: *activeTasks) + { + if(i++>0) + { + text<<", "; + } + text<0) + { + str<<_("\n\nTasks affected: "); + str<& timer); - void setIdleStartTime(time_t idleStartTime); + virtual void setIdleStartTime(time_t idleStartTime); + virtual void setActiveTaskList(std::shared_ptr> activeTasks); virtual ~IdleDialog(); virtual void attach(IActionObserver*); virtual void detach(IActionObserver*); // IWidget interface - virtual void show() { Gtk::Dialog::show(); } + virtual void show(); virtual void hide() { Gtk::Dialog::hide(); } virtual void move(int x, int y) { Gtk::Dialog::move(x,y); }; virtual bool is_visible() { return Gtk::Dialog::is_visible(); } ; @@ -51,6 +52,7 @@ Gtk::Button continueButton; std::shared_ptr m_timer; time_t m_idleStartTime; + std::string taskString; std::list observers; void responseHandler(int result); diff -Nru timeit-1.2.1/src/GUI/internal/PreferenceDialog.cpp timeit-1.2.5/src/GUI/internal/PreferenceDialog.cpp --- timeit-1.2.1/src/GUI/internal/PreferenceDialog.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/GUI/internal/PreferenceDialog.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -14,14 +14,12 @@ { PreferenceDialog::PreferenceDialog(std::shared_ptr& database) : - CancelButton(Gtk::StockID("gtk-cancel")), OKButton( - Gtk::StockID("gtk-apply")) + CancelButton(Gtk::StockID("gtk-cancel")), OKButton(Gtk::StockID("gtk-apply")) { - settingsAccessor=database->getSettingsAccessor(); + settingsAccessor = database->getSettingsAccessor(); CompactLayoutButton.set_label(_("Compact layout")); StartMinimizedButton.set_label(_("Start minimized")); - get_vbox()->pack_start(CompactLayoutButton, Gtk::PACK_EXPAND_WIDGET, 3); get_vbox()->pack_start(StartMinimizedButton, Gtk::PACK_EXPAND_WIDGET, 3); @@ -29,6 +27,7 @@ CompactLayoutButton.signal_toggled().connect(sigc::mem_fun(this, &PreferenceDialog::on_data_changed)); StartMinimizedButton.signal_toggled().connect(sigc::mem_fun(this, &PreferenceDialog::on_data_changed)); GzEntry.signal_changed().connect(sigc::mem_fun(this, &PreferenceDialog::on_data_changed)); + QuietButton.signal_toggled().connect(sigc::mem_fun(this, &PreferenceDialog::on_data_changed)); GtEntry.signal_changed().connect(sigc::mem_fun(this, &PreferenceDialog::on_data_changed)); GzEntry.signal_focus_out_event().connect(sigc::mem_fun(this, &PreferenceDialog::on_focus_changed)); GtEntry.signal_focus_out_event().connect(sigc::mem_fun(this, &PreferenceDialog::on_focus_changed)); @@ -36,20 +35,25 @@ signal_button_release_event().connect(sigc::mem_fun(this, &PreferenceDialog::on_button_released)); this->set_events(Gdk::BUTTON_RELEASE_MASK); /******/ - TimeConstantTable.resize(2, 2); + TimeConstantTable.resize(3, 2); { GzLabel.set_text(_("Zero time (m)")); GzEntry.set_range(1, 60); - GzEntry.set_increments(1,10); + GzEntry.set_increments(1, 10); GtLabel.set_text(_("Idle time (m)")); GtEntry.set_range(1, 60); - GtEntry.set_increments(1,10); + GtEntry.set_increments(1, 10); + + QuietLabel.set_text(_("Quiet mode")); TimeConstantTable.attach(GtLabel, 0, 1, 0, 1); TimeConstantTable.attach(GzLabel, 0, 1, 1, 2); - TimeConstantTable.attach(GtEntry,1,2,0,1); - TimeConstantTable.attach(GzEntry,1,2,1,2); + TimeConstantTable.attach(QuietLabel, 0, 1, 2, 3); + + TimeConstantTable.attach(GtEntry, 1, 2, 0, 1); + TimeConstantTable.attach(GzEntry, 1, 2, 1, 2); + TimeConstantTable.attach(QuietButton, 1, 2, 2, 3); } get_vbox()->pack_start(TimeConstantTable); @@ -76,35 +80,32 @@ void PreferenceDialog::set_values() { - oldCompactLayout = settingsAccessor->GetBoolByName("CompactLayout",DEFAULT_COMPACTLAYOUT); - oldStartMinimized = settingsAccessor->GetBoolByName("StartMinimized",DEFAULT_START_MINIMIZED); + oldCompactLayout = settingsAccessor->GetBoolByName("CompactLayout", DEFAULT_COMPACTLAYOUT); + oldStartMinimized = settingsAccessor->GetBoolByName("StartMinimized", DEFAULT_START_MINIMIZED); oldGt = settingsAccessor->GetIntByName("Gt", DEFAULT_GT); oldGz = settingsAccessor->GetIntByName("Gz", DEFAULT_GZ); + oldQuietMode = settingsAccessor->GetBoolByName("Quiet", DEFAULT_QUIET_MODE); GzEntry.set_value(oldGz); GtEntry.set_value(oldGt); CompactLayoutButton.set_active(oldCompactLayout); StartMinimizedButton.set_active(oldStartMinimized); + QuietButton.set_active(oldQuietMode); } void PreferenceDialog::get_values() { - compactLayout=CompactLayoutButton.get_active(); - startMinimized=StartMinimizedButton.get_active(); - gz=GzEntry.get_value_as_int(); - gt=GtEntry.get_value_as_int(); + compactLayout = CompactLayoutButton.get_active(); + startMinimized = StartMinimizedButton.get_active(); + gz = GzEntry.get_value_as_int(); + gt = GtEntry.get_value_as_int(); + quietMode = QuietButton.get_active(); } void PreferenceDialog::on_data_changed() { get_values(); - if(gzSetBoolByName("CompactLayout",compactLayout); + compactLayout = settingsAccessor->SetBoolByName("CompactLayout", compactLayout); oldCompactLayout = compactLayout; } - if(gz!=oldGz) + if (gz != oldGz) { - settingsAccessor->SetIntByName("Gz",gz); - oldGz=gz; + settingsAccessor->SetIntByName("Gz", gz); + oldGz = gz; } - if(gt!=oldGt) + if (gt != oldGt) { - settingsAccessor->SetIntByName("Gt",gt); - oldGt=gt; + settingsAccessor->SetIntByName("Gt", gt); + oldGt = gt; } - if(startMinimized!=oldStartMinimized) + if (startMinimized != oldStartMinimized) { - settingsAccessor->SetBoolByName("StartMinimized",startMinimized); + settingsAccessor->SetBoolByName("StartMinimized", startMinimized); + oldStartMinimized = startMinimized; + } + if(quietMode != oldQuietMode) + { + settingsAccessor->SetBoolByName("Quiet", quietMode); + quietMode = oldQuietMode; } hide(); } - } diff -Nru timeit-1.2.1/src/GUI/internal/PreferenceDialog.h timeit-1.2.5/src/GUI/internal/PreferenceDialog.h --- timeit-1.2.1/src/GUI/internal/PreferenceDialog.h 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/GUI/internal/PreferenceDialog.h 2013-09-25 14:19:47.000000000 +0000 @@ -47,6 +47,9 @@ Gtk::SpinButton GzEntry; Gtk::SpinButton GtEntry; + Gtk::Label QuietLabel; + Gtk::CheckButton QuietButton; + Gtk::Button CancelButton; Gtk::Button OKButton; @@ -56,10 +59,13 @@ int gt; bool compactLayout; bool startMinimized; + bool quietMode; int oldGz; int oldGt; bool oldCompactLayout; bool oldStartMinimized; + bool oldQuietMode; + void on_data_changed(); bool on_focus_changed(GdkEventFocus*); diff -Nru timeit-1.2.1/src/Logic/Controller.cpp timeit-1.2.5/src/Logic/Controller.cpp --- timeit-1.2.1/src/Logic/Controller.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Logic/Controller.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -17,12 +17,14 @@ using namespace GUI; -Controller::Controller(std::shared_ptr& guiFactory, std::shared_ptr& timeKeeper, std::shared_ptr& database) +Controller::Controller(std::shared_ptr& guiFactory, std::shared_ptr& timeKeeper, + std::shared_ptr& database) { - mainWindow_x=0; - mainWindow_y=0; + mainWindow_x = 0; + mainWindow_y = 0; settingsAccessor = database->getSettingsAccessor(); + taskAccessor = database->getTaskAccessor(); selectedTaskID = -1; this->timeKeeper = timeKeeper; this->guiFactory = guiFactory; @@ -39,7 +41,7 @@ { guiFactory->getStatusIcon().show(); guiFactory->getStatusIcon().attach(this); - if(!settingsAccessor->GetBoolByName("StartMinimized",DEFAULT_START_MINIMIZED)) + if (!settingsAccessor->GetBoolByName("StartMinimized", DEFAULT_START_MINIMIZED)) { WidgetPtr mainWindow = guiFactory->getWidget(MAIN_WINDOW); mainWindow->attach(this); @@ -86,21 +88,21 @@ { std::stringstream translatedHelp; std::stringstream helpToUse; - translatedHelp<enable(false); time_t now = time(0); time_t idleStartTime = now - timeKeeper->timeIdle(); - //TODO Automatic off without dialog - idleDialog = std::dynamic_pointer_cast(guiFactory->getWidget(GUI::IDLE_DIALOG)); - idleDialog->attach(this); - idleDialog->setIdleStartTime(idleStartTime); - idleDialog->show(); + + bool quiet = settingsAccessor->GetBoolByName("Quiet", DEFAULT_QUIET_MODE); + if (quiet) + { + on_action_revertAndContinue(); + } + else + { + idleDialog = std::dynamic_pointer_cast(guiFactory->getWidget(GUI::IDLE_DIALOG)); + idleDialog->attach(this); + idleDialog->setIdleStartTime(idleStartTime); + std::shared_ptr > activeTasks = taskAccessor->getRunningTasks(); + idleDialog->setActiveTaskList(activeTasks); + idleDialog->show(); + } } void Controller::on_action_revertAndContinue() @@ -204,14 +216,13 @@ preferenceDialog->show(); } - - -void Controller::on_showDetailsClicked(ISummary* summary,int64_t taskId, time_t startTime, time_t stopTime) +void Controller::on_showDetailsClicked(ISummary* summary, int64_t taskId, time_t startTime, time_t stopTime) { - std::shared_ptr detailsDialog = std::dynamic_pointer_cast(guiFactory->getWidget(GUI::DETAILS_DIALOG)); - if(detailsDialog) + std::shared_ptr detailsDialog = std::dynamic_pointer_cast( + guiFactory->getWidget(GUI::DETAILS_DIALOG)); + if (detailsDialog) { - detailsDialog->set(taskId,startTime,stopTime); + detailsDialog->set(taskId, startTime, stopTime); detailsDialog->show(); } } diff -Nru timeit-1.2.1/src/Logic/IdleDetector.cpp timeit-1.2.5/src/Logic/IdleDetector.cpp --- timeit-1.2.1/src/Logic/IdleDetector.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Logic/IdleDetector.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -20,57 +20,108 @@ XScreenSaverInfo* XInfo = 0; } - -IdleDetector::IdleDetector(const std::shared_ptr& timer) +IdleDetector::IdleDetector() { - m_timer = timer; - int event_base, error_base; - if (display == 0) - { - display = XOpenDisplay(0); - } - if (XInfo == 0) - { - XInfo = XScreenSaverAllocInfo(); - } - IdleDetectionPossible = false; - if (XScreenSaverQueryExtension(display, &event_base, &error_base)) - { - IdleDetectionPossible = true; - } - idleSeconds = 0; - m_timer->attach(this); + int event_base, error_base; + if (display == 0) + { + display = XOpenDisplay(0); + } + if (XInfo == 0) + { + XInfo = XScreenSaverAllocInfo(); + } + IdleDetectionPossible = false; + if (XScreenSaverQueryExtension(display, &event_base, &error_base)) + { + IdleDetectionPossible = true; + } + idleSeconds = 0; + lastPoll = time(NULL); + idleTimeout = 2000; + lastActivity = lastPoll; + isIdle = false; + enabled = false; } IdleDetector::~IdleDetector() { - m_timer->detach(this); - if (XInfo) - { - //TODO safer allocation/dealocation! - XFree(XInfo); - } + if (XInfo) + { + //TODO safer allocation/dealocation! + XFree(XInfo); + XInfo = nullptr; + } +} + +void IdleDetector::setIdleTimeout(int minutes) +{ + idleTimeout = minutes * 60; } -void IdleDetector::on_signal_10_seconds() + +void IdleDetector::reset() { - pollStatus(); + isIdle = false; + lastPoll = time(NULL); } void IdleDetector::pollStatus() { - if (IdleDetectionPossible) - { - XScreenSaverQueryInfo(display, XRootWindow(display, 0), XInfo); - idleSeconds = (XInfo->idle / 1000); - } + if (IdleDetectionPossible) + { + time_t now = time(NULL); + if (isIdle) + { + idleSeconds = now - lastActivity; + } + else + { + if (now - lastPoll > 30) + { + idleSeconds = now - lastActivity; + } + else + { + XScreenSaverQueryInfo(display, XRootWindow(display, 0), XInfo); + idleSeconds = (XInfo->idle / 1000); + lastPoll = now; + if (idleSeconds < 20) + { + lastActivity = now; + } + time_t executionTime = time(NULL) -now; + if( executionTime > 10) + { + //We have been suspended for more than 10 seconds inside this function + idleSeconds = executionTime; + } + } + lastPoll = now; + } + if (enabled && idleSeconds > idleTimeout) + { + isIdle = true; + } + } +} + +bool IdleDetector::idle() +{ + return isIdle; } int IdleDetector::minutesIdle() { - return idleSeconds / secsPerMinute; + return timeIdle() / secsPerMinute; } time_t IdleDetector::timeIdle() { - return idleSeconds; + pollStatus(); + return idleSeconds; +} + +void IdleDetector::setEnabled(bool state) +{ + enabled = state; } diff -Nru timeit-1.2.1/src/Logic/IdleDetector.h timeit-1.2.5/src/Logic/IdleDetector.h --- timeit-1.2.1/src/Logic/IdleDetector.h 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Logic/IdleDetector.h 2013-09-25 14:19:47.000000000 +0000 @@ -14,20 +14,24 @@ class IdleDetector : public TimerObserver { public: - IdleDetector(const std::shared_ptr& timer); + IdleDetector(); virtual ~IdleDetector(); int minutesIdle(); time_t timeIdle(); - //TimerObserver interface - virtual void on_signal_1_second() {}; - virtual void on_signal_10_seconds(); - // + void setIdleTimeout(int minutes); + void reset(); + bool idle(); + void setEnabled(bool state); private: void pollStatus(); bool IdleDetectionPossible; long getTimestamp(); time_t idleSeconds; - std::shared_ptr m_timer; + time_t lastPoll; + long idleTimeout; + bool isIdle; + time_t lastActivity; + bool enabled; }; #endif /* IDLEDETECTOR_H_ */ diff -Nru timeit-1.2.1/src/Logic/Timekeeper.cpp timeit-1.2.5/src/Logic/Timekeeper.cpp --- timeit-1.2.1/src/Logic/Timekeeper.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Logic/Timekeeper.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -9,7 +9,7 @@ //TODO Autostart on movement (if autotracker and supressed dialog) -Timekeeper::Timekeeper(const std::shared_ptr& database, const std::shared_ptr& timer): m_idleDetector(timer) +Timekeeper::Timekeeper(const std::shared_ptr& database, const std::shared_ptr& timer) { m_timer = timer; m_timeAccessor = database->getTimeAccessor(); @@ -39,7 +39,8 @@ { if(name.length() < 1 || name == "Gt") { - m_idleGt = m_settingsAccessor->GetIntByName("Gt", DEFAULT_GT); + long idleGt = m_settingsAccessor->GetIntByName("Gt", DEFAULT_GT); + m_idleDetector.setIdleTimeout(idleGt); } if (name.length()<1 || name == "Gz") { @@ -52,20 +53,20 @@ if (m_enabled) { map::iterator it; - if (m_idleDetector.minutesIdle() < m_idleGz) + if (m_idleDetector.idle()) { - //Only saving time when being certain that somebody is working - for (it = activeTasks.begin(); it != activeTasks.end(); it++) + if (hasRunningTasks()) { - TaskTime tt = it->second; - UpdateTask(tt.taskID); + notifyIdleDetected(); } } - else if (hasRunningTasks()) + else if (m_idleDetector.minutesIdle() < m_idleGz) { - if (m_idleDetector.minutesIdle() >= m_idleGt) + //Only saving time when being certain that somebody is working + for (it = activeTasks.begin(); it != activeTasks.end(); it++) { - notifyIdleDetected(); + TaskTime tt = it->second; + UpdateTask(tt.taskID); } } } @@ -121,6 +122,7 @@ notifyRunningChanged(); } } + m_idleDetector.setEnabled(activeTasks.size()>0); } void Timekeeper::on_taskRemoved(int64_t id) @@ -137,7 +139,7 @@ } } -void Timekeeper::UpdateTask(int64_t id) +void Timekeeper::UpdateTask(int64_t id, time_t now) { map::iterator it; it = activeTasks.find(id); @@ -149,6 +151,12 @@ m_timeAccessor->changeEndTime(task.dbHandle, task.stopTime); } } + +void Timekeeper::UpdateTask(int64_t id) +{ + time_t now = time(NULL); + UpdateTask(id, now); +} bool Timekeeper::hasRunningTasks() { return (activeTasks.size() > 0); @@ -190,6 +198,7 @@ void Timekeeper::notifyRunningChanged() { + m_idleDetector.setEnabled(activeTasks.size()>0); std::list::iterator iter; for (iter = observers.begin(); iter != observers.end(); iter++) { @@ -211,6 +220,10 @@ void Timekeeper::enable(bool enable) { m_enabled = enable; + if(m_enabled) + { + m_idleDetector.reset(); + } } void Timekeeper::attach(TimekeeperObserver* observer) diff -Nru timeit-1.2.1/src/Logic/Timekeeper.h timeit-1.2.5/src/Logic/Timekeeper.h --- timeit-1.2.1/src/Logic/Timekeeper.h 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Logic/Timekeeper.h 2013-09-25 14:19:47.000000000 +0000 @@ -39,6 +39,7 @@ virtual time_t timeIdle() ; virtual int minutesIdle(); private: + void UpdateTask(int64_t id, time_t now); //TimerProxyObserver interface void on_signal_1_second() {}; @@ -66,7 +67,6 @@ std::map activeTasks; int m_idleGz; - int m_idleGt; void notifyRunningChanged(); void notifyIdleDetected(); diff -Nru timeit-1.2.1/src/Misc/Utils.cpp timeit-1.2.5/src/Misc/Utils.cpp --- timeit-1.2.1/src/Misc/Utils.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Misc/Utils.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -21,6 +21,9 @@ namespace Utils { + +#define SECOND_PER_DAY 24*60*60 + std::string getImagePath() { return PROGRAMNAME_DATADIR; @@ -58,12 +61,13 @@ return mktime(timeInfo); } -int getDayOfWeek(struct tm * timeInfo) +int getDayOfWeek(const time_t rawtime) { + struct tm * timeInfo = localtime(&rawtime); int dow=timeInfo->tm_wday; int retVal=dow; - int weekStartsOnDay = *(nl_langinfo(_NL_TIME_FIRST_WEEKDAY)) - 1; + int weekStartsOnDay = *(nl_langinfo(_NL_TIME_FIRST_WEEKDAY))-1; retVal = retVal - weekStartsOnDay; if(retVal<0) { @@ -75,24 +79,25 @@ time_t getBeginingOfWeek(const time_t& rawtime) { struct tm * timeInfo; - timeInfo = localtime(&rawtime); + int dayOfWeek = getDayOfWeek(rawtime); + time_t bow = rawtime - (dayOfWeek) * SECOND_PER_DAY; + timeInfo = localtime(&bow); timeInfo->tm_sec = 0; timeInfo->tm_min = 0; timeInfo->tm_hour = 0; - int dayOfWeek = getDayOfWeek(timeInfo); - timeInfo->tm_mday -= dayOfWeek; + timeInfo->tm_wday = 1; return mktime(timeInfo); } time_t getEndOfWeek(const time_t& rawtime) { struct tm * timeInfo; - timeInfo = localtime(&rawtime); + int dayOfWeek = getDayOfWeek(rawtime); + time_t eow = rawtime + (6 - dayOfWeek) * SECOND_PER_DAY; + timeInfo = localtime(&eow); timeInfo->tm_sec = 59; timeInfo->tm_min = 59; timeInfo->tm_hour = 23; - int dayOfWeek = getDayOfWeek(timeInfo); - timeInfo->tm_mday += (6 - dayOfWeek); return mktime(timeInfo); } time_t getBeginingOfMonth(const time_t& rawtime) @@ -173,15 +178,15 @@ { time_t rawtime; time(&rawtime); - struct tm timeInfo; - timeInfo = *localtime(&rawtime); - timeInfo.tm_year = year - 1900; - timeInfo.tm_mon = month; - timeInfo.tm_mday = day; - timeInfo.tm_hour = hour; - timeInfo.tm_min = min; - timeInfo.tm_sec = sec; - return mktime(&timeInfo); + struct tm* timeInfo; + timeInfo = localtime(&rawtime); + timeInfo->tm_year = year - 1900; + timeInfo->tm_mon = month; + timeInfo->tm_mday = day; + timeInfo->tm_hour = hour; + timeInfo->tm_min = min; + timeInfo->tm_sec = sec; + return mktime(timeInfo); } std::string seconds2ddhhmm(int s) @@ -216,7 +221,7 @@ struct tm toTime = *localtime(&to); retVal << (fromTime.tm_year + 1900) << "-" << setfill('0') << setw(2) << fromTime.tm_mon+1 << "-" << setfill('0') << setw(2) << fromTime.tm_mday << " " << setfill('0') << setw(2) << fromTime.tm_hour << ":" << setfill('0') << setw(2) << fromTime.tm_min; - retVal << " -> "; + retVal << " -> "; if (fromTime.tm_year != toTime.tm_year || fromTime.tm_mon != toTime.tm_mon || fromTime.tm_mday != toTime.tm_mday) { retVal << (toTime.tm_year + 1900) << "-" << setfill('0') << setw(2) << toTime.tm_mon+1 << "-" << setfill('0') << setw(2) diff -Nru timeit-1.2.1/src/Misc/Utils.h timeit-1.2.5/src/Misc/Utils.h --- timeit-1.2.1/src/Misc/Utils.h 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Misc/Utils.h 2013-09-25 14:19:47.000000000 +0000 @@ -24,7 +24,6 @@ time_t getEndOfMonth(const time_t&); time_t getBeginingOfYear(const time_t&); time_t getEndOfYear(const time_t&); - int getDayOfWeek(struct tm * timeInfo); int getDaysInMonth(const time_t& rawtime); std::string seconds2ddhhmm(int s); std::string seconds2hhmm(int s); diff -Nru timeit-1.2.1/src/Tests/DB/TempDB.cpp timeit-1.2.5/src/Tests/DB/TempDB.cpp --- timeit-1.2.1/src/Tests/DB/TempDB.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Tests/DB/TempDB.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -6,6 +6,7 @@ */ #include "TempDB.h" +#include "OSAbstraction.h" namespace Test { @@ -17,7 +18,7 @@ TempDB::~TempDB() { - unlink("/tmp/test.db"); + OSAbstraction::unlink("/tmp/test.db"); } } /* namespace Test */ diff -Nru timeit-1.2.1/src/Tests/Logic/AutoTrackerTest.cpp timeit-1.2.5/src/Tests/Logic/AutoTrackerTest.cpp --- timeit-1.2.1/src/Tests/Logic/AutoTrackerTest.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Tests/Logic/AutoTrackerTest.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -53,7 +53,7 @@ cute::suite make_suite_AutoTrackerTest() { cute::suite s; - s.push_back(CUTE(WorkspaceSwitchTest)); + //s.push_back(CUTE(WorkspaceSwitchTest)); return s; } diff -Nru timeit-1.2.1/src/Tests/Misc/test_utils.cpp timeit-1.2.5/src/Tests/Misc/test_utils.cpp --- timeit-1.2.1/src/Tests/Misc/test_utils.cpp 1970-01-01 00:00:00.000000000 +0000 +++ timeit-1.2.5/src/Tests/Misc/test_utils.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -0,0 +1,191 @@ +#include "test_utils.h" + +#include "cute.h" +#include +#include "Utils.h" + +namespace Test +{ + +void Utils_testGetDaysInMonth() +{ + time_t rawtime = Utils::getTime(2013, 0, 2, 2, 2, 2); + ASSERT_EQUALM("Days in January", 31, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 1, 2, 2, 2, 2); + ASSERT_EQUALM("Days in February 2013", 28, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2016, 1, 2, 2, 2, 2); + ASSERT_EQUALM("Days in February 2016", 29, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 2, 2, 2, 2, 2); + ASSERT_EQUALM("Days in March 2013", 31, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 3, 2, 2, 2, 2); + ASSERT_EQUALM("Days in April 2013", 30, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 4, 2, 2, 2, 2); + ASSERT_EQUALM("Days in May 2013", 31, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 5, 2, 2, 2, 2); + ASSERT_EQUALM("Days in June 2013", 30, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 6, 2, 2, 2, 2); + ASSERT_EQUALM("Days in July 2013", 31, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 7, 2, 2, 2, 2); + ASSERT_EQUALM("Days in August 2013", 31, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 8, 2, 2, 2, 2); + ASSERT_EQUALM("Days in September 2013", 30, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 9, 2, 2, 2, 2); + ASSERT_EQUALM("Days in October 2013", 31, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 10, 2, 2, 2, 2); + ASSERT_EQUALM("Days in November 2013", 30, Utils::getDaysInMonth(rawtime)); + rawtime = Utils::getTime(2013, 4, 2, 2, 2, 2); + ASSERT_EQUALM("Days in December 2013", 31, Utils::getDaysInMonth(rawtime)); +} + +void Utils_convertSecondsToStrings() +{ + int timespan1 = 4 * 60 + 2 * 60 * 60 + 2 * 60 * 60 * 24; + ASSERT_EQUALM("Converting 2 days 2 hours and 4 minutes into a text string", std::string("02:02:04"), + Utils::seconds2ddhhmm(timespan1)); + int timespan2 = 2 * 60 * 60 + 4 * 60; + ASSERT_EQUALM("Converting 2 hours and 4 minutes into a text string", std::string("02:04"), + Utils::seconds2hhmm(timespan2)); +} + +void Utils_convertTimespanToString() +{ + time_t start = Utils::getTime(2013, 0, 4, 11, 0, 0); + time_t stop = Utils::getTime(2013, 0, 4, 12, 0, 0); + std::string result = Utils::createDurationString(start, stop); + std::string expected = "2013-01-04 10:00 -> 11:00"; + ASSERT_EQUALM("Converting a time span of one hour into a text string", expected, result); + + start = Utils::getTime(2012, 0, 4, 11, 0, 0); + stop = Utils::getTime(2013, 0, 4, 12, 0, 0); + result = Utils::createDurationString(start, stop); + expected = "2012-01-04 10:00 -> 2013-01-04 11:00"; + ASSERT_EQUALM("Converting a time span of one year into a text string", expected, result); +} + +void Utils_dayEnd() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getEndOfDay(testPoint); + struct tm *end_of_day = localtime(&eod); + ASSERT_EQUALM("Check year", 113, end_of_day->tm_year); + ASSERT_EQUALM("Check month", 0, end_of_day->tm_mon); + ASSERT_EQUALM("Check day", 4, end_of_day->tm_mday); + ASSERT_EQUALM("Check hour", 23, end_of_day->tm_hour); + ASSERT_EQUALM("Check minute", 59, end_of_day->tm_min); + ASSERT_EQUALM("Check seconds", 59, end_of_day->tm_sec); +} + +void Utils_beginingOfDay() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getBeginingOfDay(testPoint); + struct tm *end_of_day = localtime(&eod); + ASSERT_EQUALM("Check year", 113, end_of_day->tm_year); + ASSERT_EQUALM("Check month", 0, end_of_day->tm_mon); + ASSERT_EQUALM("Check day", 4, end_of_day->tm_mday); + ASSERT_EQUALM("Check hour", 0, end_of_day->tm_hour); + ASSERT_EQUALM("Check minute", 0, end_of_day->tm_min); + ASSERT_EQUALM("Check seconds", 0, end_of_day->tm_sec); +} + +void Utils_beginingOfWeek() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getBeginingOfWeek(testPoint); + struct tm *beginningOfWeek = localtime(&eod); + ASSERT_EQUALM("Check seconds", 0, beginningOfWeek->tm_sec); + ASSERT_EQUALM("Check minute", 0, beginningOfWeek->tm_min); + ASSERT_EQUALM("Check hour", 0, beginningOfWeek->tm_hour); + ASSERT_EQUALM("Check day of week", 1, beginningOfWeek->tm_wday); + ASSERT_EQUALM("Check day of month", 31, beginningOfWeek->tm_mday); + ASSERT_EQUALM("Check month", 11, beginningOfWeek->tm_mon); + ASSERT_EQUALM("Check year", 112, beginningOfWeek->tm_year); +} + +void Utils_endOfWeek() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getEndOfWeek(testPoint); + struct tm *end_of_day = localtime(&eod); + ASSERT_EQUALM("Check seconds", 59, end_of_day->tm_sec); + ASSERT_EQUALM("Check minute", 59, end_of_day->tm_min); + ASSERT_EQUALM("Check hour", 23, end_of_day->tm_hour); + ASSERT_EQUALM("Check day of month", 6, end_of_day->tm_mday); + ASSERT_EQUALM("Check seconds", 59, end_of_day->tm_sec); + ASSERT_EQUALM("Check month", 0, end_of_day->tm_mon); + ASSERT_EQUALM("Check year", 113, end_of_day->tm_year); +} + +void Utils_beginningOfMonth() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getBeginingOfMonth(testPoint); + struct tm *end_of_day = localtime(&eod); + ASSERT_EQUALM("Check year", 113, end_of_day->tm_year); + ASSERT_EQUALM("Check month", 0, end_of_day->tm_mon); + ASSERT_EQUALM("Check day", 1, end_of_day->tm_mday); + ASSERT_EQUALM("Check hour", 0, end_of_day->tm_hour); + ASSERT_EQUALM("Check minute", 0, end_of_day->tm_min); + ASSERT_EQUALM("Check seconds", 0, end_of_day->tm_sec); +} + +void Utils_endOfMonth() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getEndOfMonth(testPoint); + struct tm *end_of_day = localtime(&eod); + ASSERT_EQUALM("Check year", 113, end_of_day->tm_year); + ASSERT_EQUALM("Check month", 0, end_of_day->tm_mon); + ASSERT_EQUALM("Check day", 31, end_of_day->tm_mday); + ASSERT_EQUALM("Check hour", 23, end_of_day->tm_hour); + ASSERT_EQUALM("Check minute", 59, end_of_day->tm_min); + ASSERT_EQUALM("Check seconds", 59, end_of_day->tm_sec); +} + + +void Utils_beginningOfYear() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getBeginingOfYear(testPoint); + struct tm *end_of_day = localtime(&eod); + ASSERT_EQUALM("Check year", 113, end_of_day->tm_year); + ASSERT_EQUALM("Check month", 0, end_of_day->tm_mon); + ASSERT_EQUALM("Check day", 1, end_of_day->tm_mday); + ASSERT_EQUALM("Check hour", 0, end_of_day->tm_hour); + ASSERT_EQUALM("Check minute", 0, end_of_day->tm_min); + ASSERT_EQUALM("Check seconds", 0, end_of_day->tm_sec); +} + +void Utils_endOfYear() +{ + time_t testPoint = Utils::getTime(2013, 0, 4, 12, 0, 0); + time_t eod = Utils::getEndOfYear(testPoint); + struct tm *end_of_day = localtime(&eod); + ASSERT_EQUALM("Check year", 113, end_of_day->tm_year); + ASSERT_EQUALM("Check month", 11, end_of_day->tm_mon); + ASSERT_EQUALM("Check day", 31, end_of_day->tm_mday); + ASSERT_EQUALM("Check hour", 23, end_of_day->tm_hour); + ASSERT_EQUALM("Check minute", 59, end_of_day->tm_min); + ASSERT_EQUALM("Check seconds", 59, end_of_day->tm_sec); +} + + + +cute::suite make_suite_UtilsTest() +{ + cute::suite s; + s.push_back(CUTE(Utils_testGetDaysInMonth)); + s.push_back(CUTE(Utils_convertSecondsToStrings)); + s.push_back(CUTE(Utils_convertTimespanToString)); + s.push_back(CUTE(Utils_dayEnd)); + s.push_back(CUTE(Utils_beginingOfDay)); + s.push_back(CUTE(Utils_beginingOfWeek)); + s.push_back(CUTE(Utils_endOfWeek)); + s.push_back(CUTE(Utils_beginningOfMonth)); + s.push_back(CUTE(Utils_beginningOfYear)); + s.push_back(CUTE(Utils_endOfMonth)); + s.push_back(CUTE(Utils_endOfYear)); + return s; +} + +} /* namespace Test */ diff -Nru timeit-1.2.1/src/Tests/Misc/test_utils.h timeit-1.2.5/src/Tests/Misc/test_utils.h --- timeit-1.2.1/src/Tests/Misc/test_utils.h 1970-01-01 00:00:00.000000000 +0000 +++ timeit-1.2.5/src/Tests/Misc/test_utils.h 2013-09-25 14:19:47.000000000 +0000 @@ -0,0 +1,12 @@ +#ifndef TEST_UTILS_H_ +#define TEST_UTILS_H_ + +#include "cute_suite.h" + +namespace Test +{ + +extern cute::suite make_suite_UtilsTest(); + +} /* namespace Test */ +#endif /* TEST_UTILS_H_ */ diff -Nru timeit-1.2.1/src/Tests/TestRunner.cpp timeit-1.2.5/src/Tests/TestRunner.cpp --- timeit-1.2.1/src/Tests/TestRunner.cpp 2013-07-04 10:42:20.000000000 +0000 +++ timeit-1.2.5/src/Tests/TestRunner.cpp 2013-09-25 14:19:47.000000000 +0000 @@ -17,6 +17,7 @@ #include "DB/test_TaskAccessor.h" #include "DB/test_SettingsAccessor.h" #include "DB/test_AutotrackAccessor.h" +#include "Misc/test_utils.h" namespace Test { @@ -30,6 +31,7 @@ s += make_suite_test_TaskAccessor(); s += make_suite_test_SettingsAccessor(); s += make_suite_test_AutotrackAccessor(); + s += make_suite_UtilsTest(); } void TestRunner::run() diff -Nru timeit-1.2.1/src/version.h timeit-1.2.5/src/version.h --- timeit-1.2.1/src/version.h 2013-07-04 10:48:04.000000000 +0000 +++ timeit-1.2.5/src/version.h 2013-09-25 14:19:48.000000000 +0000 @@ -1 +1 @@ -#define VERSION "1.2.1" +#define VERSION "1.2.5" diff -Nru timeit-1.2.1/version timeit-1.2.5/version --- timeit-1.2.1/version 2013-07-04 10:48:04.000000000 +0000 +++ timeit-1.2.5/version 2013-09-25 14:19:48.000000000 +0000 @@ -1 +1 @@ -1.2.1 +1.2.5