Moved tracking function and signal handler to own files

This commit is contained in:
Patrick Lipka 2021-12-09 17:08:22 +01:00
parent d511c984e5
commit d7137f710c
3 changed files with 37 additions and 26 deletions

29
src/track.cpp Normal file
View File

@ -0,0 +1,29 @@
#include <iostream>
#include <unistd.h>
#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 );
}

7
src/track.h Normal file
View File

@ -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

View File

@ -5,32 +5,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "task.h" #include "task.h"
#include "project.h" #include "project.h"
#include "track.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 );
}
int main(){ int main(){
signal(SIGINT, handler); signal(SIGINT, handler);