diff options
-rw-r--r-- | e-util/gconf-bridge.c | 40 | ||||
-rw-r--r-- | e-util/gconf-bridge.h | 18 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-content.h | 3 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-view-actions.c | 39 | ||||
-rw-r--r-- | modules/mail/e-mail-shell-view-private.c | 70 |
5 files changed, 169 insertions, 1 deletions
diff --git a/e-util/gconf-bridge.c b/e-util/gconf-bridge.c index be2a0cabd7..03f82f43ca 100644 --- a/e-util/gconf-bridge.c +++ b/e-util/gconf-bridge.c @@ -550,6 +550,46 @@ gconf_bridge_bind_property_full (GConfBridge *bridge, return binding->id; } +static void +prop_binding_block_cb (gpointer hkey, PropBinding *binding, const gchar *key) +{ + g_return_if_fail (binding != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (binding->key != NULL); + + if (binding->type == BINDING_PROP && g_ascii_strcasecmp (binding->key, key) == 0) + g_signal_handler_block (binding->object, binding->prop_notify_id); +} + +static void +prop_binding_unblock_cb (gpointer hkey, PropBinding *binding, const gchar *key) +{ + g_return_if_fail (binding != NULL); + g_return_if_fail (key != NULL); + g_return_if_fail (binding->key != NULL); + + if (binding->type == BINDING_PROP && g_ascii_strcasecmp (binding->key, key) == 0) + g_signal_handler_unblock (binding->object, binding->prop_notify_id); +} + +void +gconf_bridge_block_property_bindings (GConfBridge *bridge, const gchar *key) +{ + g_return_if_fail (bridge != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_foreach (bridge->bindings, (GHFunc) prop_binding_block_cb, (gpointer)key); +} + +void +gconf_bridge_unblock_property_bindings (GConfBridge *bridge, const gchar *key) +{ + g_return_if_fail (bridge != NULL); + g_return_if_fail (key != NULL); + + g_hash_table_foreach (bridge->bindings, (GHFunc) prop_binding_unblock_cb, (gpointer)key); +} + /* Unbinds a property binding */ static void prop_binding_unbind (PropBinding *binding) diff --git a/e-util/gconf-bridge.h b/e-util/gconf-bridge.h index 7c7f53b0ce..371f1173e5 100644 --- a/e-util/gconf-bridge.h +++ b/e-util/gconf-bridge.h @@ -70,6 +70,24 @@ guint gconf_bridge_bind_property_full (GConfBridge *bridge, gconf_bridge_bind_property_full ((bridge), (key), \ (object), (prop), TRUE) +/** + * gconf_bridge_block_property_bindings + * @bridge: A #GConfBridge + * @key: A GConf key to be blocked + * + * Blocks property bindings for @key. To unblock it call #gconf_bridge_unblock_property_bindings. + **/ +void gconf_bridge_block_property_bindings (GConfBridge *bridge, const gchar *key); + +/** + * gconf_bridge_unblock_property_bindings + * @bridge: A #GConfBridge + * @key: A GConf key to be unblocked + * + * Unblocks property bindings for @key, these should be previously blocked with #gconf_bridge_unblock_property_bindings. + **/ +void gconf_bridge_unblock_property_bindings (GConfBridge *bridge, const gchar *key); + guint gconf_bridge_bind_window (GConfBridge *bridge, const gchar *key_prefix, GtkWindow *window, diff --git a/modules/mail/e-mail-shell-content.h b/modules/mail/e-mail-shell-content.h index 88714f8f95..c11323b5f1 100644 --- a/modules/mail/e-mail-shell-content.h +++ b/modules/mail/e-mail-shell-content.h @@ -46,6 +46,9 @@ (G_TYPE_INSTANCE_GET_CLASS \ ((obj), E_TYPE_MAIL_SHELL_CONTENT, EMailShellContentClass)) +#define STATE_KEY_PREVIEW "Preview" +#define STATE_KEY_THREAD_LIST "ThreadList" + G_BEGIN_DECLS typedef struct _EMailShellContent EMailShellContent; diff --git a/modules/mail/e-mail-shell-view-actions.c b/modules/mail/e-mail-shell-view-actions.c index 93a3bf63a1..f300ec0c92 100644 --- a/modules/mail/e-mail-shell-view-actions.c +++ b/modules/mail/e-mail-shell-view-actions.c @@ -483,6 +483,28 @@ action_mail_hide_selected_cb (GtkAction *action, } static void +action_mail_preview_cb (GtkToggleAction *action, EMailShellView *mail_shell_view) +{ + const gchar *folder_uri; + EMailReader *reader; + + reader = E_MAIL_READER (mail_shell_view->priv->mail_shell_content); + folder_uri = e_mail_reader_get_folder_uri (reader); + + if (folder_uri) { + GKeyFile *key_file; + const gchar *key; + gchar *group_name; + + key_file = e_shell_view_get_state_key_file (E_SHELL_VIEW (mail_shell_view)); + key = STATE_KEY_PREVIEW; + group_name = g_strdup_printf ("Folder %s", folder_uri); + g_key_file_set_boolean (key_file, group_name, key, gtk_toggle_action_get_active (action)); + g_free (group_name); + } +} + +static void action_mail_label_cb (GtkToggleAction *action, EMailShellView *mail_shell_view) { @@ -821,6 +843,7 @@ action_mail_threads_group_by_cb (GtkToggleAction *action, EMailShellContent *mail_shell_content; GtkWidget *message_list; EMailReader *reader; + const gchar *folder_uri; gboolean active; mail_shell_content = mail_shell_view->priv->mail_shell_content; @@ -830,6 +853,20 @@ action_mail_threads_group_by_cb (GtkToggleAction *action, message_list = e_mail_reader_get_message_list (reader); message_list_set_threaded (MESSAGE_LIST (message_list), active); + + folder_uri = e_mail_reader_get_folder_uri (reader); + + if (folder_uri) { + GKeyFile *key_file; + const gchar *key; + gchar *group_name; + + key_file = e_shell_view_get_state_key_file (E_SHELL_VIEW (mail_shell_view)); + key = STATE_KEY_THREAD_LIST; + group_name = g_strdup_printf ("Folder %s", folder_uri); + g_key_file_set_boolean (key_file, group_name, key, active); + g_free (group_name); + } } static void @@ -1281,7 +1318,7 @@ static GtkToggleActionEntry mail_toggle_entries[] = { N_("Show Message _Preview"), "<Control>m", N_("Show message preview pane"), - NULL, /* Handled by property bindings */ + G_CALLBACK (action_mail_preview_cb), /* Also handled by property bindings */ TRUE }, { "mail-threads-group-by", diff --git a/modules/mail/e-mail-shell-view-private.c b/modules/mail/e-mail-shell-view-private.c index 0a38886a6d..c152b84817 100644 --- a/modules/mail/e-mail-shell-view-private.c +++ b/modules/mail/e-mail-shell-view-private.c @@ -23,6 +23,49 @@ #include "widgets/menus/gal-view-factory-etable.h" +static gboolean +restore_action_bool_state (gpointer view, GtkToggleAction *action, GKeyFile *key_file, const gchar *group_name, const gchar *key, const gchar *gconf_key) +{ + gboolean value; + GConfBridge *bridge; + + g_return_val_if_fail (action != NULL, FALSE); + g_return_val_if_fail (GTK_IS_TOGGLE_ACTION (action), FALSE); + g_return_val_if_fail (key_file != NULL, FALSE); + g_return_val_if_fail (group_name != NULL, FALSE); + g_return_val_if_fail (key != NULL, FALSE); + g_return_val_if_fail (gconf_key != NULL, FALSE); + + bridge = gconf_bridge_get (); + + if (g_key_file_has_key (key_file, group_name, key, NULL)) { + value = g_key_file_get_boolean (key_file, group_name, key, NULL); + } else { + GError *error = NULL; + + value = gconf_client_get_bool (gconf_bridge_get_client (bridge), gconf_key, &error); + + if (error) { + g_error_free (error); + value = gtk_toggle_action_get_active (action); + } + } + + if (value != gtk_toggle_action_get_active (action)) { + /* block bindings to not store this change to gconf */ + gconf_bridge_block_property_bindings (bridge, gconf_key); + /* block action to not store to key file for the previous folder */ + g_signal_handlers_block_matched (action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, view); + + gtk_toggle_action_set_active (action, value); + + g_signal_handlers_unblock_matched (action, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, view); + gconf_bridge_unblock_property_bindings (bridge, gconf_key); + } + + return value; +} + static void mail_shell_view_folder_tree_selected_cb (EMailShellView *mail_shell_view, const gchar *full_name, @@ -47,6 +90,33 @@ mail_shell_view_folder_tree_selected_cb (EMailShellView *mail_shell_view, e_mail_reader_set_folder (reader, NULL, NULL); e_shell_view_update_actions (shell_view); + + if (folder_selected && uri) { + EShellWindow *shell_window; + GtkToggleAction *action; + GKeyFile *key_file; + gchar *group_name; + gboolean value; + + shell_window = e_shell_view_get_shell_window (shell_view); + key_file = e_shell_view_get_state_key_file (shell_view); + group_name = g_strdup_printf ("Folder %s", uri); + + action = GTK_TOGGLE_ACTION (ACTION (MAIL_PREVIEW)); + restore_action_bool_state (mail_shell_view, action, + key_file, group_name, STATE_KEY_PREVIEW, + "/apps/evolution/mail/display/show_preview"); + + action = GTK_TOGGLE_ACTION (ACTION (MAIL_THREADS_GROUP_BY)); + value = restore_action_bool_state (mail_shell_view, action, + key_file, group_name, STATE_KEY_THREAD_LIST, + "/apps/evolution/mail/display/thread_list"); + + /* because the change is not propagated due to blocking the action signal */ + message_list_set_threaded (MESSAGE_LIST (e_mail_reader_get_message_list (reader)), value); + + g_free (group_name); + } } static gboolean |