diff options
author | Louie S <louie@example.com> | 2023-07-04 13:43:10 -0700 |
---|---|---|
committer | Louie S <louie@example.com> | 2023-07-04 13:43:10 -0700 |
commit | ed11c16d6687b0b51d41a598b93d7923331a3853 (patch) | |
tree | d53621501b365e5dcb48bf6849f78b3ee79f5606 /src | |
parent | 27f266e072ad40cdb9c46190b1d8ccc212af001e (diff) |
Groups printing, need to debug entries
Diffstat (limited to 'src')
-rw-r--r-- | src/db/sqlite3/db.c | 17 | ||||
-rw-r--r-- | src/draw.c | 26 | ||||
-rw-r--r-- | src/draw.h | 2 | ||||
-rw-r--r-- | src/entry.c | 8 | ||||
-rw-r--r-- | src/entry.h | 3 | ||||
-rw-r--r-- | src/main.c | 12 |
6 files changed, 57 insertions, 11 deletions
diff --git a/src/db/sqlite3/db.c b/src/db/sqlite3/db.c index f863028..4f3b136 100644 --- a/src/db/sqlite3/db.c +++ b/src/db/sqlite3/db.c @@ -205,20 +205,21 @@ int load_entries_callback(void *first_arg, int argc, char **argv, char **azColNa Entry **entries = (Entry **) first_arg; // check that enough arguments were passed - if(argc < 7) { + if(argc < 8) { fprintf(stderr, "Error: not enough rows returned in 'Entry' table\n"); return 1; } entry_set_id(&((*entries)[callback_index]), (argv[0] ? atoi(argv[0]) : 0)); - fprintf(stderr, "time format: %s\n", (argv[1] ? argv[1] : "")); + entry_set_id(&((*entries)[callback_index]), (argv[1] ? atoi(argv[1]) : 0)); + fprintf(stderr, "time format: %s\n", (argv[2] ? argv[2] : "")); //entry_set_due_date(&((*entries)[callback_index]), (argv[1] ? argv[1] : "")); // TODO - entry_set_alt_due_date(&((*entries)[callback_index]), (argv[2] ? argv[2] : "")); - entry_set_title(&((*entries)[callback_index]), (argv[3] ? argv[3] : "")); - entry_set_color(&((*entries)[callback_index]), (argv[4] ? argv[4] : "")); - entry_set_highlight(&((*entries)[callback_index]), (argv[5] ? argv[5] : "")); - entry_set_done(&((*entries)[callback_index]), (argv[6] ? argv[6] : false)); - entry_set_url(&((*entries)[callback_index]), (argv[7] ? argv[7] : "")); + entry_set_alt_due_date(&((*entries)[callback_index]), (argv[3] ? argv[3] : "")); + entry_set_title(&((*entries)[callback_index]), (argv[4] ? argv[4] : "")); + entry_set_color(&((*entries)[callback_index]), (argv[5] ? argv[5] : "")); + entry_set_highlight(&((*entries)[callback_index]), (argv[6] ? argv[6] : "")); + entry_set_done(&((*entries)[callback_index]), (argv[7] ? argv[7] : false)); + entry_set_url(&((*entries)[callback_index]), (argv[8] ? argv[8] : "")); ++callback_index; return 0; @@ -3,8 +3,12 @@ #include <stdlib.h> #include "draw.h" +#include "entry.h" +#include "group.h" -void tui_init(Group **groups, Entry **entries) { +void draw_data(Group **groups, int g_count, Entry **entries, int e_count, int start_x, int start_y); + +void tui_init(Group **groups, int g_count, Entry **entries, int e_count) { int input; // capture user input WINDOW *w_main; @@ -24,6 +28,7 @@ void tui_init(Group **groups, Entry **entries) { wrefresh(w_main); // draw groups and entries + draw_data(groups, g_count, entries, e_count, 1, 1); input = getch(); tui_end(); @@ -34,3 +39,22 @@ void tui_init(Group **groups, Entry **entries) { void tui_end() { endwin(); } + + + +void draw_data(Group **groups, int g_count, Entry **entries, int e_count, int start_x, int start_y) { + int i; + int j; + + for(i = 0; i < g_count; ++i) { + mvprintw(start_y, start_x, "%s", group_get_name(&((*groups)[i]))); + ++start_y; + for(j = 0; j < e_count; ++j) { + if(entry_get_group_id(&((*entries)[j])) == group_get_id(&((*groups)[i]))) { + mvprintw(start_y, start_x, "\t%s", entry_get_title(&((*entries)[i]))); + ++start_y; + } + } + ++start_y; + } +} @@ -5,7 +5,7 @@ #include "group.h" // initialize the tui -void tui_init(Group **groups, Entry **entries); +void tui_init(Group **groups, int g_count, Entry **entries, int e_count); // destroy the tui void tui_end(); diff --git a/src/entry.c b/src/entry.c index af4b8f4..c2958ed 100644 --- a/src/entry.c +++ b/src/entry.c @@ -7,6 +7,10 @@ int entry_get_id(Entry *e) { return e->id; } +int entry_get_group_id(Entry *e) { + return e->group_id; +} + struct tm entry_get_due_date(Entry *e) { return e->due_date; } @@ -41,6 +45,10 @@ void entry_set_id(Entry *e, int id) { e->id = id; } +void entry_set_group_id(Entry *e, int id) { + e->group_id = id; +} + void entry_set_due_date(Entry *e, struct tm due_date) { e->due_date = due_date; } diff --git a/src/entry.h b/src/entry.h index e22a737..819c1cc 100644 --- a/src/entry.h +++ b/src/entry.h @@ -9,6 +9,7 @@ // a group/category for entries to be put in typedef struct { int id; // id from database + int group_id; // id of corresponding group struct tm due_date; char alt_due_date[BUF_LEN]; char title[BUF_LEN]; @@ -20,6 +21,7 @@ typedef struct { // getters int entry_get_id(Entry *e); +int entry_get_group_id(Entry *e); struct tm entry_get_due_date(Entry *e); char *entry_get_alt_due_date(Entry *e); char *entry_get_title(Entry *e); @@ -30,6 +32,7 @@ char *entry_get_url(Entry *e); // setters void entry_set_id(Entry *e, int id); +void entry_set_group_id(Entry *e, int id); void entry_set_due_date(Entry *e, struct tm due_date); void entry_set_alt_due_date(Entry *e, char *alt_due_date); void entry_set_title(Entry *e, char *title); @@ -22,12 +22,22 @@ int main() { fprintf(stderr, "\t Url: %s\n", group_get_url(&(groups[i]))); } + /* + for(int i = 0; i < entry_count; ++i) { + fprintf(stderr, "entry %d:\n", i+1); + fprintf(stderr, "\t ID: %d\n", group_get_id(&(groups[i]))); + fprintf(stderr, "\tName: %s\n", group_get_name(&(groups[i]))); + fprintf(stderr, "\tDesc: %s\n", group_get_desc(&(groups[i]))); + fprintf(stderr, "\t Url: %s\n", group_get_url(&(groups[i]))); + } + */ + entries = db_load_entries(&entry_count); if(groups == NULL) perror("could not get groups"); if(entries == NULL) perror("could not get entries"); - tui_init(&groups, &entries); + tui_init(&groups, group_count, &entries, entry_count); return 0; } |