diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2012-03-07 22:36:12 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2012-03-08 00:52:25 +0800 |
commit | 932f7cada8400905b5aeb75a3d40979cf4004c22 (patch) | |
tree | 94c3a09fe33806f01520e144ca2bc363ed284d54 /e-util | |
parent | 579417fec3165f844516b5ba3d5d50f0849c39b7 (diff) | |
download | gsoc2013-evolution-932f7cada8400905b5aeb75a3d40979cf4004c22.tar gsoc2013-evolution-932f7cada8400905b5aeb75a3d40979cf4004c22.tar.gz gsoc2013-evolution-932f7cada8400905b5aeb75a3d40979cf4004c22.tar.bz2 gsoc2013-evolution-932f7cada8400905b5aeb75a3d40979cf4004c22.tar.lz gsoc2013-evolution-932f7cada8400905b5aeb75a3d40979cf4004c22.tar.xz gsoc2013-evolution-932f7cada8400905b5aeb75a3d40979cf4004c22.tar.zst gsoc2013-evolution-932f7cada8400905b5aeb75a3d40979cf4004c22.zip |
EConfig: Support custom page skip callbacks.
Add e_config_add_skip_check() to install a callback function to
decide whether to skip a particular page in a GtkAssistant, useful
if a page may be blank in certain conditions.
This feature is not used in Evolution 3.4, but will be used in 3.5.
Diffstat (limited to 'e-util')
-rw-r--r-- | e-util/e-config.c | 62 | ||||
-rw-r--r-- | e-util/e-config.h | 4 |
2 files changed, 65 insertions, 1 deletions
diff --git a/e-util/e-config.c b/e-util/e-config.c index 97711f95be..7bb6038dbd 100644 --- a/e-util/e-config.c +++ b/e-util/e-config.c @@ -91,6 +91,7 @@ struct _EConfigPrivate { GList *widgets; GList *checks; GList *finish_pages; + GHashTable *skip_checks; }; static GtkWidget * @@ -174,6 +175,8 @@ config_finalize (GObject *object) link = g_list_delete_link (link, link); } + g_hash_table_destroy (priv->skip_checks); + /* Chain up to parent's finalize() method. */ G_OBJECT_CLASS (e_config_parent_class)->finalize (object); } @@ -232,6 +235,12 @@ static void e_config_init (EConfig *config) { config->priv = E_CONFIG_GET_PRIVATE (config); + + config->priv->skip_checks = g_hash_table_new_full ( + (GHashFunc) g_str_hash, + (GEqualFunc) g_str_equal, + (GDestroyNotify) NULL, + (GDestroyNotify) check_node_free); } /** @@ -322,6 +331,39 @@ e_config_add_page_check (EConfig *ec, ec->priv->checks = g_list_append (ec->priv->checks, cn); } +/** + * e_config_add_skip_check: + * @config: an #EConfig + * @pageid: the page ID for the skip page callback + * @func: the skip page callback function + * @data: data to pass to the callback function + * + * Adds a callback function to decide whether to skip the page in a + * GtkAssistant, useful if the page is blank in certain conditions. + * + * The callback function should return %TRUE if the page should be + * skipped, or %FALSE if the page should be visited. + **/ +void +e_config_add_skip_check (EConfig *config, + const gchar *pageid, + EConfigCheckFunc func, + gpointer data) +{ + struct _check_node *cn; + + g_return_if_fail (E_IS_CONFIG (config)); + g_return_if_fail (pageid != NULL); + g_return_if_fail (func != NULL); + + cn = g_slice_new0 (struct _check_node); + cn->pageid = g_strdup (pageid); + cn->func = func; + cn->data = data; + + g_hash_table_insert (config->priv->skip_checks, cn->pageid, cn); +} + static struct _finish_page_node * find_page_finish (EConfig *config, const gchar *pageid) @@ -507,6 +549,24 @@ ec_assistant_check_current (EConfig *ec) gtk_assistant_update_buttons_state (assistant); } +static gboolean +ec_assistant_skip_page (EConfig *config, + struct _widget_node *wn) +{ + struct _check_node *cn; + gboolean skip_page = FALSE; + + g_return_val_if_fail (wn->item->path != NULL, FALSE); + cn = g_hash_table_lookup (config->priv->skip_checks, wn->item->path); + + if (cn != NULL) { + g_return_val_if_fail (cn->func != NULL, FALSE); + skip_page = cn->func (config, wn->item->path, cn->data); + } + + return skip_page; +} + static gint ec_assistant_forward (gint current_page, gpointer user_data) @@ -554,7 +614,7 @@ ec_assistant_forward (gint current_page, break; } - if (node_is_page) + if (node_is_page && !ec_assistant_skip_page (ec, node)) break; } diff --git a/e-util/e-config.h b/e-util/e-config.h index 0535895b99..6f009b7f77 100644 --- a/e-util/e-config.h +++ b/e-util/e-config.h @@ -283,6 +283,10 @@ void e_config_add_page_check (EConfig *config, void e_config_set_page_is_finish (EConfig *config, const gchar *pageid, gboolean is_finish); +void e_config_add_skip_check (EConfig *config, + const gchar *pageid, + EConfigCheckFunc func, + gpointer data); void e_config_set_target (EConfig *config, EConfigTarget *target); |