diff options
Diffstat (limited to 'clients/ui.c')
| -rw-r--r-- | clients/ui.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/clients/ui.c b/clients/ui.c index a95ce44..ca6906f 100644 --- a/clients/ui.c +++ b/clients/ui.c @@ -217,17 +217,12 @@ void app_refresh_context(struct app *a) free(resp); snprintf(a->default_series, sizeof a->default_series, "%s", "A"); - a->attachment_dir[0] = '\0'; resp = client_rpc(&a->conn, "settings.get", a->session, a->org, "{}"); if (resp && client_ok(resp)) { char *ser = jstr_dup(resp, "result.default_series"); if (ser && *ser) snprintf(a->default_series, sizeof a->default_series, "%s", ser); free(ser); - char *dir = jstr_dup(resp, "result.attachment_dir"); - if (dir && *dir) - snprintf(a->attachment_dir, sizeof a->attachment_dir, "%s", dir); - free(dir); } free(resp); @@ -332,14 +327,18 @@ static void expand_path(const char *in, char *out, size_t n) Returns a malloc'd path, or NULL on cancel. */ char *file_browser(struct app *a, const char *start_dir) { - (void)a; if (g_quit) return NULL; char dir[1024]; - const char *start = (start_dir && *start_dir) ? start_dir : getenv("HOME"); + const char *home = getenv("HOME"); + const char *start = (start_dir && *start_dir) ? start_dir : home; expand_path(start, dir, sizeof dir); - if (!dir[0]) - snprintf(dir, sizeof dir, "."); + struct stat sb; + if (!dir[0] || stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode)) { + expand_path(home && *home ? home : ".", dir, sizeof dir); + if (!dir[0]) + snprintf(dir, sizeof dir, "."); + } for (;;) { DIR *d = opendir(dir); if (!d) { @@ -408,6 +407,8 @@ char *file_browser(struct app *a, const char *start_dir) continue; } free(ents); + snprintf(a->attachment_dir, sizeof a->attachment_dir, "%.255s", dir); + config_save(a); return xstrdup(full); } } |
