X-Git-Url: https://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fnote.c;h=be9d87a0e25db084b40348ee5dd98c742b0d5c45;hb=909b5e1edc01d95ebfaf39982b69831d8503c74c;hp=77f98cfa48b9debec6e8fb74cec0b4a4c2f19297;hpb=2cf9ca6ed6eca3a02209f58ab86d663d7cfbf710;p=ptask.git diff --git a/src/note.c b/src/note.c index 77f98cf..be9d87a 100644 --- a/src/note.c +++ b/src/note.c @@ -25,10 +25,14 @@ #include #include +#include +#include -static char *get_default_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,17 +45,31 @@ static char *get_default_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); - - free(dir); - - return path; + return dir; } static char *get_path(const char *uuid) { - return get_default_path(uuid); + const char *sdir; + char *path, *dir; + + sdir = settings_get_str(SETTINGS_KEY_NOTES_DIR); + + if (sdir == NULL || *sdir == '\0') { + dir = get_default_path(); + settings_set_str(SETTINGS_KEY_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); + + return path; } void note_put(const char *uuid, const char *note)