X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=lib%2Fconfig.cc;h=8bce7ba8f480fe1f70794c8d987569feca9d6834;hp=c079d752eef07e5ad8c9588756f95ecc050bc794;hb=e5f3c3ed50247323ecbd2a50e3b24a8352d17f8d;hpb=4743e87c2c79c37208bb60d6617ef203796fc5c2 diff --git a/lib/config.cc b/lib/config.cc index c079d752..8bce7ba8 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -245,3 +245,37 @@ _notmuch_config_load_from_database (notmuch_database_t *notmuch) return status; } + +notmuch_status_t +_notmuch_config_load_from_file (notmuch_database_t *notmuch, + GKeyFile *file) +{ + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + gchar **groups,**keys, *val; + + if (notmuch->config == NULL) + notmuch->config = _notmuch_string_map_create (notmuch); + + if (unlikely(notmuch->config == NULL)) { + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + + for (groups = g_key_file_get_groups (file, NULL); *groups; groups++) { + for (keys = g_key_file_get_keys (file, *groups, NULL, NULL); *keys; keys++) { + char *absolute_key = talloc_asprintf(notmuch, "%s.%s", *groups, *keys); + val = g_key_file_get_value (file, *groups, *keys, NULL); + if (! val) { + status = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + _notmuch_string_map_set (notmuch->config, absolute_key, val); + talloc_free (absolute_key); + if (status) + goto DONE; + } + } + + DONE: + return status; +}