From d7137f710cc23bf5e44bd347730f1774c18537ec Mon Sep 17 00:00:00 2001 From: Patrick Lipka Date: Thu, 9 Dec 2021 17:08:22 +0100 Subject: [PATCH] Moved tracking function and signal handler to own files --- src/track.cpp | 29 +++++++++++++++++++++++++++++ src/track.h | 7 +++++++ src/tt.cpp | 27 +-------------------------- 3 files changed, 37 insertions(+), 26 deletions(-) create mode 100644 src/track.cpp create mode 100644 src/track.h diff --git a/src/track.cpp b/src/track.cpp new file mode 100644 index 0000000..631f11b --- /dev/null +++ b/src/track.cpp @@ -0,0 +1,29 @@ +#include +#include +#include "track.h" +#include "project.h" + +void handler(int signum){ + sigint = 1; + std::cout << std::endl; +} + +void track(Project *proj){ + int worktime = 0; + int work_h, work_m, work_s; + time_t start; + system("clear"); + time(&start); + std::cout << "Started tracking of task " << proj->name << "/" << proj->active_task->name << " at " << ctime(&start) << std::endl; + sigint = 0; + while (!sigint){ + sleep(1); + worktime += 1; + } + proj->active_task->add_time(worktime); + work_h = (worktime % 86400) / 3600; + work_m = (worktime % 3600) / 60; + work_s = worktime % 60; + // TODO: replace with proper cout call + printf("Time worked on project: %02d:%02d:%02d\n", work_h,work_m,work_s ); +} diff --git a/src/track.h b/src/track.h new file mode 100644 index 0000000..d38d4be --- /dev/null +++ b/src/track.h @@ -0,0 +1,7 @@ +#ifndef TRACK_H +#define TRACK_H +#include "project.h" +extern int sigint; +void handler(int signum); +void track (Project *proj); +#endif diff --git a/src/tt.cpp b/src/tt.cpp index ad4d5b3..0070dfa 100644 --- a/src/tt.cpp +++ b/src/tt.cpp @@ -5,32 +5,7 @@ #include #include "task.h" #include "project.h" - -int sigint; - -void handler(int signum){ - sigint = 1; - std::cout << std::endl; -} - -void track(Project *proj){ - int worktime = 0; - int work_h, work_m, work_s; - time_t start; - system("clear"); - time(&start); - std::cout << "Started tracking of task " << proj->name << "/" << proj->active_task->name << " at " << ctime(&start) << std::endl; - while (!sigint){ - sleep(1); - worktime += 1; - } - proj->active_task->add_time(worktime); - work_h = (worktime % 86400) / 3600; - work_m = (worktime % 3600) / 60; - work_s = worktime % 60; - // TODO: replace with proper cout call - printf("Time worked on project: %02d:%02d:%02d\n", work_h,work_m,work_s ); -} +#include "track.h" int main(){ signal(SIGINT, handler);