X-Git-Url: https://wpitchoune.net/gitweb/?a=blobdiff_plain;f=src%2Fnote.c;h=0097d33647f5ec641c4029019b4d620a249602c1;hb=HEAD;hp=2fcb51f617cc98b7991fec84da101e428ef1b13f;hpb=4d1a39be05a99a8fbd2b4839f37c7a21d4214c59;p=ptask.git diff --git a/src/note.c b/src/note.c index 2fcb51f..0097d33 100644 --- a/src/note.c +++ b/src/note.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013 jeanfi@gmail.com + * Copyright (C) 2012-2016 jeanfi@gmail.com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -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); @@ -100,7 +123,7 @@ char *note_get(const char *uuid) } fclose(f); } else { - log_err("Failed to open %s", path); + log_debug("%s does not exist or cannot be opened", path); } return str;