diff options
| author | David Bremner <david@tethera.net> | 2020-08-25 22:36:43 -0300 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-02-06 19:02:00 -0400 |
| commit | d6bd87a712c6df3126589ec223f4c599fa8450b5 (patch) | |
| tree | 6c7192be624503d6c9d87ab006b054a5234f9f50 /lib/config.cc | |
| parent | 867d7352a76e0a8a46e64a035f23edcf7d6f49e4 (diff) | |
lib/config: add notmuch_config_key_{get,set}
By using an enum we can have better error detection than copy pasting
key strings around.
The question of what layer this belongs in is a bit
tricky. Historically most of the keys are defined by the CLI. On the
other hand features like excludes are supported in the
library/bindings, and it makes sense to configure them from the
library as well.
The somewhat long prefix for notmuch_config_t is to avoid collisions
with the existing usage in notmuch-client.h.
Diffstat (limited to 'lib/config.cc')
| -rw-r--r-- | lib/config.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/config.cc b/lib/config.cc index 32e5a9b7..c07b607b 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -279,3 +279,37 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, DONE: return status; } + +const char * +_notmuch_config_key_to_string (notmuch_config_key_t key) { + switch (key) { + case NOTMUCH_CONFIG_DATABASE_PATH: + return "database.path"; + case NOTMUCH_CONFIG_EXCLUDE_TAGS: + return "search.exclude_tags"; + case NOTMUCH_CONFIG_NEW_TAGS: + return "new.tags"; + case NOTMUCH_CONFIG_SYNC_MAILDIR_FLAGS: + return "maildir.synchronize_flags"; + case NOTMUCH_CONFIG_PRIMARY_EMAIL: + return "user.primary_email"; + case NOTMUCH_CONFIG_OTHER_EMAIL: + return "user.other_email"; + case NOTMUCH_CONFIG_USER_NAME: + return "user.name"; + default: + return NULL; + } +} + +const char * +notmuch_config_get (notmuch_database_t *notmuch, notmuch_config_key_t key) { + + return _notmuch_string_map_get (notmuch->config, _notmuch_config_key_to_string (key)); +} + +notmuch_status_t +notmuch_config_set (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val) { + + return notmuch_database_set_config (notmuch, _notmuch_config_key_to_string (key), val); +} |
