*(char *) var = !value;
- cs_notify_observers(cs, he, he->key.strkey, CE_SET);
+ cs_notify_observers(cs, he, he->key.strkey, NT_CONFIG_SET);
return CSR_SUCCESS;
}
*(char *) var = quad_toggle(value);
- cs_notify_observers(cs, he, he->key.strkey, CE_SET);
+ cs_notify_observers(cs, he, he->key.strkey, NT_CONFIG_SET);
return CSR_SUCCESS;
}
memset(cs, 0, sizeof(*cs));
cs->hash = mutt_hash_new(size, MUTT_HASH_NO_FLAGS);
mutt_hash_set_destructor(cs->hash, destroy, (intptr_t) cs);
+ cs->notify = notify_new(cs, NT_CONFIG);
}
/**
return he;
}
-/**
- * cs_add_observer - Add a observer (callback function)
- * @param cs Config items
- * @param fn Observer callback function
- */
-void cs_add_observer(struct ConfigSet *cs, cs_observer fn)
-{
- if (!cs || !fn)
- return;
-
- for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
- {
- if (cs->observers[i] == fn)
- {
- mutt_debug(LL_DEBUG1, "Observer was already registered\n");
- return;
- }
- }
-
- for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
- {
- if (!cs->observers[i])
- {
- cs->observers[i] = fn;
- return;
- }
- }
-}
-
-/**
- * cs_remove_observer - Remove a observer (callback function)
- * @param cs Config items
- * @param fn Observer callback function
- */
-void cs_remove_observer(struct ConfigSet *cs, cs_observer fn)
-{
- if (!cs || !fn)
- return;
-
- for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
- {
- if (cs->observers[i] == fn)
- {
- cs->observers[i] = NULL;
- return;
- }
- }
- mutt_debug(LL_DEBUG1, "Observer wasn't registered\n");
-}
-
/**
* cs_notify_observers - Notify all observers of an event
* @param cs Config items
* @param ev Type of event
*/
void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he,
- const char *name, enum ConfigEvent ev)
+ const char *name, enum NotifyConfig ev)
{
if (!cs || !he || !name)
return;
- for (size_t i = 0; i < mutt_array_size(cs->observers); i++)
- {
- if (!cs->observers[i])
- return;
-
- cs->observers[i](cs, he, name, ev);
- }
+ struct EventConfig ec = { cs, he, name };
+ notify_send(cs->notify, NT_CONFIG, ev, IP & ec);
}
/**
}
if ((CSR_RESULT(rc) == CSR_SUCCESS) && !(rc & CSR_SUC_NO_CHANGE))
- cs_notify_observers(cs, he, he->key.strkey, CE_RESET);
+ cs_notify_observers(cs, he, he->key.strkey, NT_CONFIG_RESET);
return rc;
}
if (CSR_RESULT(rc) != CSR_SUCCESS)
return rc;
- cs_notify_observers(cs, he, he->key.strkey, CE_INITIAL_SET);
+ cs_notify_observers(cs, he, he->key.strkey, NT_CONFIG_INITIAL_SET);
return CSR_SUCCESS;
}
he->type = i->parent->type | DT_INHERITED;
}
if (!(rc & CSR_SUC_NO_CHANGE))
- cs_notify_observers(cs, he, he->key.strkey, CE_SET);
+ cs_notify_observers(cs, he, he->key.strkey, NT_CONFIG_SET);
return rc;
}
if (he->type & DT_INHERITED)
he->type = cdef->type | DT_INHERITED;
if (!(rc & CSR_SUC_NO_CHANGE))
- cs_notify_observers(cs, he, cdef->name, CE_SET);
+ cs_notify_observers(cs, he, cdef->name, NT_CONFIG_SET);
}
return rc;
if (he->type & DT_INHERITED)
he->type = cdef->type | DT_INHERITED;
if (!(rc & CSR_SUC_NO_CHANGE))
- cs_notify_observers(cs, he, cdef->name, CE_SET);
+ cs_notify_observers(cs, he, cdef->name, NT_CONFIG_SET);
}
return rc;
struct ConfigDef;
/**
- * enum ConfigEvent - Config notification types
+ * enum NotifyConfig - Config notification types
*/
-enum ConfigEvent
+enum NotifyConfig
{
- CE_SET = 1, ///< Config item has been set
- CE_RESET, ///< Config item has been reset to initial, or parent, value
- CE_INITIAL_SET, ///< Config item's initial value has been set
+ NT_CONFIG_SET = 1, ///< Config item has been set
+ NT_CONFIG_RESET, ///< Config item has been reset to initial, or parent, value
+ NT_CONFIG_INITIAL_SET, ///< Config item's initial value has been set
};
/* Config Set Results */
CSOA_STOP, ///< Stop notifying observers
};
-/**
- * typedef cs_observer - Listen for config changes
- * @param cs Config items
- * @param he HashElem representing config item
- * @param name Name of the config item
- * @param ev Event type, e.g. #CE_SET
- * @retval true Continue notifying
- */
-typedef bool (*cs_observer) (const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
/**
* typedef cs_validator - Validate the "charset" config variable
* @param cs Config items
*/
struct ConfigSet
{
- struct Hash *hash; /**< HashTable storing the config itesm */
- struct ConfigSetType types[18]; /**< All the defined config types */
- cs_observer observers[8]; /**< Observers for notifications of changes to config items */
+ struct Hash *hash; ///< HashTable storing the config items
+ struct ConfigSetType types[18]; ///< All the defined config types
+ struct Notify *notify; ///< Notifications system
+};
+
+/**
+ * struct EventConfig - A config-change event
+ *
+ * Events such as #NT_CONFIG_SET
+ */
+struct EventConfig
+{
+ const struct ConfigSet *cs; ///< Config set
+ struct HashElem *he; ///< Config item that changed
+ const char *name; ///< Name of config item that changed
};
struct ConfigSet *cs_new(size_t size);
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], int flags);
struct HashElem *cs_inherit_variable(const struct ConfigSet *cs, struct HashElem *parent, const char *name);
-void cs_add_observer(struct ConfigSet *cs, cs_observer fn);
-void cs_remove_observer(struct ConfigSet *cs, cs_observer fn);
-void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+void cs_notify_observers(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum NotifyConfig ev);
int cs_he_initial_get (const struct ConfigSet *cs, struct HashElem *he, struct Buffer *result);
int cs_he_initial_set (const struct ConfigSet *cs, struct HashElem *he, const char *value, struct Buffer *err);
}
/**
- * mutt_reply_observer - Listen for config changes to "reply_regex" - Implements ::cs_observer()
+ * mutt_reply_observer - Listen for config changes to "reply_regex" - Implements ::observer_t()
*/
-bool mutt_reply_observer(const struct ConfigSet *cs, struct HashElem *he,
- const char *name, enum ConfigEvent ev)
+int mutt_reply_observer(struct NotifyCallback *nc)
{
- if (mutt_str_strcmp(name, "reply_regex") != 0)
- return true;
+ if (!nc)
+ return -1;
+
+ struct EventConfig *ec = (struct EventConfig *) nc->event;
+
+ if (mutt_str_strcmp(ec->name, "reply_regex") != 0)
+ return 0;
if (!Context)
- return true;
+ return 0;
regmatch_t pmatch[1];
}
OptResortInit = true; /* trigger a redraw of the index */
- return true;
+ return 0;
}
Config = init_config(500);
if (!Config)
goto main_curses;
+ notify_set_parent(Config->notify, NeoMutt->notify);
if (!get_user_info(Config))
goto main_exit;
goto main_ok; // TEST22: neomutt -B
}
- cs_add_observer(Config, mutt_hist_observer);
- cs_add_observer(Config, mutt_log_observer);
- cs_add_observer(Config, mutt_menu_observer);
- cs_add_observer(Config, mutt_reply_observer);
+ notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_hist_observer, 0);
+ notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_log_observer, 0);
+ notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_menu_observer, 0);
+ notify_observer_add(Config->notify, NT_CONFIG, 0, mutt_reply_observer, 0);
if (sendflags & SEND_POSTPONED)
{
}
/**
- * mutt_menu_observer - Listen for config changes affecting the menu - Implements ::cs_observer()
+ * mutt_menu_observer - Listen for config changes affecting the menu - Implements ::observer_t()
*/
-bool mutt_menu_observer(const struct ConfigSet *cs, struct HashElem *he,
- const char *name, enum ConfigEvent ev)
+int mutt_menu_observer(struct NotifyCallback *nc)
{
- const struct ConfigDef *cdef = he->data;
+ if (!nc)
+ return -1;
+
+ struct EventConfig *ec = (struct EventConfig *) nc->event;
+
+ const struct ConfigDef *cdef = ec->he->data;
ConfigRedrawFlags flags = cdef->flags;
if (flags == 0)
- return true;
+ return 0;
if (flags & R_INDEX)
mutt_menu_set_redraw_full(MENU_MAIN);
if (flags & R_MENU)
mutt_menu_set_current_redraw_full();
- return true;
+ return 0;
}
}
/**
- * mutt_hist_observer - Listen for config changes affecting the history - Implements ::cs_observer()
+ * mutt_hist_observer - Listen for config changes affecting the history - Implements ::observer_t()
*/
-bool mutt_hist_observer(const struct ConfigSet *cs, struct HashElem *he,
- const char *name, enum ConfigEvent ev)
+int mutt_hist_observer(struct NotifyCallback *nc)
{
- if (mutt_str_strcmp(name, "history") != 0)
- return true;
+ if (!nc)
+ return -1;
+
+ struct EventConfig *ec = (struct EventConfig *) nc->event;
+
+ if (mutt_str_strcmp(ec->name, "history") != 0)
+ return 0;
mutt_hist_init();
- return true;
+ return 0;
}
#include "mutt/mutt.h"
void mutt_hist_complete(char *buf, size_t buflen, enum HistoryClass hclass);
-bool mutt_hist_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+int mutt_hist_observer(struct NotifyCallback *nc);
#endif /* MUTT_MUTT_HISTORY_H */
}
/**
- * mutt_log_observer - Listen for config changes affecting the log file - Implements ::cs_observer()
+ * mutt_log_observer - Listen for config changes affecting the log file - Implements ::observer_t()
*/
-bool mutt_log_observer(const struct ConfigSet *cs, struct HashElem *he,
- const char *name, enum ConfigEvent ev)
+int mutt_log_observer(struct NotifyCallback *nc)
{
- if (mutt_str_strcmp(name, "debug_file") == 0)
+ if (!nc)
+ return -1;
+
+ struct EventConfig *ec = (struct EventConfig *) nc->event;
+
+ if (mutt_str_strcmp(ec->name, "debug_file") == 0)
mutt_log_set_file(C_DebugFile, true);
- else if (mutt_str_strcmp(name, "debug_level") == 0)
+ else if (mutt_str_strcmp(ec->name, "debug_level") == 0)
mutt_log_set_level(C_DebugLevel, true);
- return true;
+ return 0;
}
void mutt_log_stop(void);
int mutt_log_set_level(int level, bool verbose);
int mutt_log_set_file(const char *file, bool verbose);
-bool mutt_log_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+int mutt_log_observer(struct NotifyCallback *nc);
int level_validator(const struct ConfigSet *cs, const struct ConfigDef *cdef, intptr_t value, struct Buffer *err);
void mutt_clear_error(void);
void mutt_menu_set_redraw_full(int menu_type);
void mutt_menu_set_redraw(int menu_type, MuttRedrawFlags redraw);
-bool mutt_menu_observer(const struct ConfigSet *cs, struct HashElem *he, const char *name, enum ConfigEvent ev);
+int mutt_menu_observer(struct NotifyCallback *nc);
#endif /* MUTT_MENU_H */
int wcscasecmp(const wchar_t *a, const wchar_t *b);
#endif
-bool mutt_reply_observer(const struct ConfigSet *cs, struct HashElem *he,
- const char *name, enum ConfigEvent ev);
+int mutt_reply_observer(struct NotifyCallback *nc);
#endif /* MUTT_PROTOS_H */