X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fnote.c;h=247d8d9a4e7eec80aaf2ba1888032f0ab848f0c2;hb=d90d80c49709335e9101657d1a82cdd964e14c40;hp=f5e3a91d2b3bc81ef8f715fa1e66f5d0dc4bc273;hpb=ce7497e25edfc10304e38edbf206566ad4548dee;p=ptask.git diff --git a/src/note.c b/src/note.c index f5e3a91..247d8d9 100644 --- a/src/note.c +++ b/src/note.c @@ -25,10 +25,14 @@ #include #include +#include +#include -static char *get_path(const char *uuid) +static const char *NOTE_SUF = ".note"; + +static char *get_default_path() { - char *home, *dir, *path; + char *home, *dir; home = getenv("HOME"); @@ -41,8 +45,27 @@ static char *get_path(const char *uuid) sprintf(dir, "%s/%s", home, ".task"); mkdir(dir, 0777); - path = malloc(strlen(dir) + 1 + strlen(uuid) + strlen(".note") + 1); - sprintf(path, "%s/%s.note", dir, uuid); + return dir; +} + +static char *get_path(const char *uuid) +{ + const char *sdir; + char *path, *dir; + + sdir = settings_get_notes_dir(); + + if (sdir == NULL || *sdir == '\0') { + dir = get_default_path(); + settings_set_notes_dir(dir); + } else { + dir = strdup(sdir); + } + + mkdirs(dir, 0777); + + path = malloc(strlen(dir) + 1 + strlen(uuid) + strlen(NOTE_SUF) + 1); + sprintf(path, "%s/%s%s", dir, uuid, NOTE_SUF); free(dir);