]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch-config.c
moved _config_(get|set)_list () functions earlier in the file
[notmuch] / notmuch-config.c
index 3d4d5b9fd1d2f02dedb4bcd8067c8bc0a65021a6..a124e34cf2d8a1beff94704c7a6179026ff85743 100644 (file)
@@ -89,9 +89,10 @@ static const char search_config_comment[] =
     "\n"
     " The following option is supported here:\n"
     "\n"
-    "\tauto_exclude_tags      A ;-separated list of tags that will be\n"
-    "\t excluded from search results by default.  Using an excluded tag\n"
-    "\t in a query will override that exclusion.\n";
+    "\texclude_tags\n"
+    "\t\tA ;-separated list of tags that will be excluded from\n"
+    "\t\tsearch results by default.  Using an excluded tag in a\n"
+    "\t\tquery will override that exclusion.\n";
 
 struct _notmuch_config {
     char *filename;
@@ -105,8 +106,8 @@ struct _notmuch_config {
     const char **new_tags;
     size_t new_tags_length;
     notmuch_bool_t maildir_synchronize_flags;
-    const char **auto_exclude_tags;
-    size_t auto_exclude_tags_length;
+    const char **search_exclude_tags;
+    size_t search_exclude_tags_length;
 };
 
 static int
@@ -264,8 +265,8 @@ notmuch_config_open (void *ctx,
     config->new_tags = NULL;
     config->new_tags_length = 0;
     config->maildir_synchronize_flags = TRUE;
-    config->auto_exclude_tags = NULL;
-    config->auto_exclude_tags_length = 0;
+    config->search_exclude_tags = NULL;
+    config->search_exclude_tags_length = 0;
 
     if (! g_key_file_load_from_file (config->key_file,
                                     config->filename,
@@ -360,9 +361,13 @@ notmuch_config_open (void *ctx,
        notmuch_config_set_new_tags (config, tags, 2);
     }
 
-    if (notmuch_config_get_auto_exclude_tags (config, &tmp) == NULL) {
-       const char *tags[] = { "deleted", "spam" };
-       notmuch_config_set_auto_exclude_tags (config, tags, 2);
+    if (notmuch_config_get_search_exclude_tags (config, &tmp) == NULL) {
+       if (is_new) {
+           const char *tags[] = { "deleted", "spam" };
+           notmuch_config_set_search_exclude_tags (config, tags, 2);
+       } else {
+           notmuch_config_set_search_exclude_tags (config, NULL, 0);
+       }
     }
 
     error = NULL;
@@ -462,6 +467,48 @@ notmuch_config_save (notmuch_config_t *config)
     return 0;
 }
 
+static const char **
+_config_get_list (notmuch_config_t *config,
+                 const char *section, const char *key,
+                 const char ***outlist, size_t *list_length, size_t *ret_length)
+{
+    assert(outlist);
+
+    if (*outlist == NULL) {
+
+       char **inlist = g_key_file_get_string_list (config->key_file,
+                                            section, key, list_length, NULL);
+       if (inlist) {
+           unsigned int i;
+
+           *outlist = talloc_size (config, sizeof (char *) * (*list_length + 1));
+
+           for (i = 0; i < *list_length; i++)
+               (*outlist)[i] = talloc_strdup (*outlist, inlist[i]);
+
+           (*outlist)[i] = NULL;
+
+           g_strfreev (inlist);
+       }
+    }
+
+    if (ret_length)
+       *ret_length = *list_length;
+
+    return *outlist;
+}
+
+static void
+_config_set_list (notmuch_config_t *config,
+                 const char *group, const char *name,
+                 const char *list[],
+                 size_t length, const char ***config_var )
+{
+    g_key_file_set_string_list (config->key_file, group, name, list, length);
+    talloc_free (*config_var);
+    *config_var = NULL;
+}
+
 const char *
 notmuch_config_get_database_path (notmuch_config_t *config)
 {
@@ -546,37 +593,6 @@ notmuch_config_set_user_primary_email (notmuch_config_t *config,
     config->user_primary_email = NULL;
 }
 
-static const char **
-_config_get_list (notmuch_config_t *config,
-                 const char *section, const char *key,
-                 const char ***outlist, size_t *list_length, size_t *ret_length)
-{
-    assert(outlist);
-
-    if (*outlist == NULL) {
-
-       char **inlist = g_key_file_get_string_list (config->key_file,
-                                            section, key, list_length, NULL);
-       if (inlist) {
-           unsigned int i;
-
-           *outlist = talloc_size (config, sizeof (char *) * (*list_length + 1));
-
-           for (i = 0; i < *list_length; i++)
-               (*outlist)[i] = talloc_strdup (*outlist, inlist[i]);
-
-           (*outlist)[i] = NULL;
-
-           g_strfreev (inlist);
-       }
-    }
-
-    if (ret_length)
-       *ret_length = *list_length;
-
-    return *outlist;
-}
-
 const char **
 notmuch_config_get_user_other_email (notmuch_config_t *config,   size_t *length)
 {
@@ -593,17 +609,6 @@ notmuch_config_get_new_tags (notmuch_config_t *config,   size_t *length)
                             &(config->new_tags_length), length);
 }
 
-static void
-_config_set_list (notmuch_config_t *config,
-                 const char *group, const char *name,
-                 const char *list[],
-                 size_t length, const char ***config_var )
-{
-    g_key_file_set_string_list (config->key_file, group, name, list, length);
-    talloc_free (*config_var);
-    *config_var = NULL;
-}
-
 void
 notmuch_config_set_user_other_email (notmuch_config_t *config,
                                     const char *list[],
@@ -623,20 +628,20 @@ notmuch_config_set_new_tags (notmuch_config_t *config,
 }
 
 const char **
-notmuch_config_get_auto_exclude_tags (notmuch_config_t *config, size_t *length)
+notmuch_config_get_search_exclude_tags (notmuch_config_t *config, size_t *length)
 {
-    return _config_get_list (config, "search", "auto_exclude_tags",
-                            &(config->auto_exclude_tags),
-                            &(config->auto_exclude_tags_length), length);
+    return _config_get_list (config, "search", "exclude_tags",
+                            &(config->search_exclude_tags),
+                            &(config->search_exclude_tags_length), length);
 }
 
 void
-notmuch_config_set_auto_exclude_tags (notmuch_config_t *config,
+notmuch_config_set_search_exclude_tags (notmuch_config_t *config,
                                      const char *list[],
                                      size_t length)
 {
-    _config_set_list (config, "search", "auto_exclude_tags", list, length,
-                     &(config->auto_exclude_tags));
+    _config_set_list (config, "search", "exclude_tags", list, length,
+                     &(config->search_exclude_tags));
 }
 
 /* Given a configuration item of the form <group>.<key> return the