aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordam <dam@gudinoff>2022-09-28 07:03:31 +0000
committerdam <dam@gudinoff>2022-09-28 07:03:31 +0000
commit127e4e3fe6377ef5857b790e3f843f8449f1e9d9 (patch)
treecce63c142f029f333968e67d809dbf321968c85a
parent9f5963fc2fdbf4af36d8471fb183699b7281a9c1 (diff)
downloadtask-time-tracker-127e4e3fe6377ef5857b790e3f843f8449f1e9d9.tar.zst
task-time-tracker-127e4e3fe6377ef5857b790e3f843f8449f1e9d9.zip
Fixed bug in delete_task. Improved user input control for creating new task. Implemented prototype version of task-archive/unarchive feature.
-rw-r--r--main.c65
-rw-r--r--readme.md2
2 files changed, 42 insertions, 25 deletions
diff --git a/main.c b/main.c
index f704ccc..6275e90 100644
--- a/main.c
+++ b/main.c
@@ -298,7 +298,7 @@ bool delete_task(database_t *db, task_t *task) {
if (db->count <= (current_capacity >> 2)) {
size_t new_capacity = current_capacity >> 1;
task_t *new_tasks = realloc(db->tasks, new_capacity * SIZEOF_TASK_T);
- if (new_tasks == NULL) {
+ if (new_tasks == NULL && new_capacity > 0) {
fprintf(stderr, "Failed to shrink database.\n");
return false;
}
@@ -996,16 +996,15 @@ int main(int argc, char *argv[]) {
store_database(&database, DB_BIN_PATH_NAME);
}
- int ch;
ungetch(KEY_RESIZE);
- while((ch = getch()) != 'q') {
-
+ for (int key; (key = getch()) != 'q'; ) {
+
timeout(INPUT_AWAIT_INF);
task_t *active_task = get_active_task(db);
task_t *selected_task = get_selected_task(db);
update_timers(&database);
- switch(ch) {
+ switch(key) {
// When getch() times out.
case ERR:
@@ -1020,34 +1019,25 @@ int main(int argc, char *argv[]) {
case KEY_F(1):
{
-
+ // Create new task.
task_t *new_task;
if (create_task(db, &new_task) == false) {
- // ERROR
+ // TODO ERROR
break;
}
- // TODO THIS SUCKS
- db->selected_task = db->count-1;
- draw_tui(db, &layouts[size_x > 100 ? L_NORMAL : L_COMPACT]);
- int row = (db->selected_task % (size_y - 2)) + 1;
-
- attron(A_BOLD);
- mvaddch(row, 0, ACS_DIAMOND);
- clrtoeol();
- mvaddch(row, size_x-1, ACS_VLINE);
- curs_set(1);
+ // Set new task name.
+ time_t now_utc = time(NULL);
+ struct tm *now_local = localtime(&now_utc);
+ strftime(new_task->name, MAX_TASK_NAME, "%Y-%m-%d %H:%M:%S", now_local);
- mvgetnstr(row, 1, new_task->name, MAX_TASK_NAME-1);
- new_task->name[MAX_TASK_NAME-1] = '\0';
- truncate_string_utf8(new_task->name, MAX_TASK_NAME-1);
+ // Select new task.
+ selected_task = new_task;
+ db->selected_task = selected_task - db->tasks;
- if (is_empty_string(new_task->name) == true) {
- strcpy(new_task->name, "-- new task --");
- }
+ // Force rename action.
+ ungetch(KEY_F(2));
- curs_set(0);
- attrset(A_NORMAL);
break;
}
@@ -1087,6 +1077,7 @@ int main(int argc, char *argv[]) {
}
case 'c':
+ case 'C':
if (active_task != NULL) {
db->selected_task = db->active_task;
}
@@ -1126,6 +1117,30 @@ int main(int argc, char *argv[]) {
}
break;
+ case 'a':
+ case 'A':
+ if (selected_task == NULL || selected_task == active_task) {
+ break;
+ }
+
+ // TODO
+ // Would be nice to mark several tasks to be archived then really do it,
+ // instead of loading adding and storing every single time.
+ // If the archive was in CSV, we could simply append to it. Let's do this!
+ if (db == &database) {
+ if (load_database(&archive, AR_BIN_PATH_NAME) == false) {
+ store_database(&archive, AR_BIN_PATH_NAME);
+ }
+ }
+ database_t *target = (db == &database ? &archive : &database);
+ add_task(target, selected_task);
+ delete_task(db, selected_task);
+ if (db == &database) {
+ store_database(&archive, AR_BIN_PATH_NAME);
+ reset_database(&archive);
+ }
+ break;
+
case KEY_LEFT:
break;
diff --git a/readme.md b/readme.md
index d79ddff..0695d1b 100644
--- a/readme.md
+++ b/readme.md
@@ -33,6 +33,8 @@ Task Time Tracker
- [x] rename layout members: title_header, archive_header, total_header, days_headers, column_widths, column_alignments, headers_paddings.
- [x] using the archive header, we can remove the top-left-corner diamond on the archive.
- [x] Allow to cancel a rename_task operation: you can do it by leaving it blank.
+- [ ] Make archive be stored in CSV format: takes less space and allows to quickly archive by appending to end of file;
+- [ ] Implement `append_to_csv(task_t *task, char *path_name)` and use it in archive function;
- [ ] MAYBE... IS THIS REALLY NEEDED? add helper func: get_selected_screen_row(db*, out int selected_row); It seems to be used in KEY_F(1) and KEY_F(2) cases of input management.
- [ ] Improve total_times:
- Create function to recalculate them. Shouldn't take so long, right?