]> git.notmuchmail.org Git - notmuch/blobdiff - lib/config.cc
lib: add stub for notmuch_database_open_with_config
[notmuch] / lib / config.cc
index c079d752eef07e5ad8c9588756f95ecc050bc794..8bce7ba8f480fe1f70794c8d987569feca9d6834 100644 (file)
@@ -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;
+}