mirror of https://github.com/PatrickLipka/tt.git
Moved tracking function and signal handler to own files
This commit is contained in:
parent
d511c984e5
commit
d7137f710c
|
@ -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 );
|
||||||
|
}
|
|
@ -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
|
27
src/tt.cpp
27
src/tt.cpp
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue