[evolution] Ignore false GSettings key change notifications
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Ignore false GSettings key change notifications
- Date: Thu, 5 Jun 2014 15:02:43 +0000 (UTC)
commit 6e9e7b067618a22795db3d9a97f60705b8046353
Author: Milan Crha <mcrha redhat com>
Date: Thu Jun 5 16:59:29 2014 +0200
Ignore false GSettings key change notifications
Similar to GObject::notify, the GSettings::changed can be emitted
even if a key didn't change. It's up to the user (aka evolution)
to test for real changes, thus let's do it. It may have certain
performance positive impact too.
calendar/gui/e-day-view-time-item.c | 9 ++++-
e-util/e-web-view.c | 37 ++++++++++++++++++--
libemail-engine/mail-config.c | 18 +++++++++-
mail/e-mail-display.c | 49 ++++++++++++++++++++++++--
modules/calendar/e-cal-shell-backend.c | 12 ++++++-
modules/calendar/e-task-shell-view-private.c | 24 +++++++++++-
modules/calendar/e-task-shell-view-private.h | 2 +
7 files changed, 139 insertions(+), 12 deletions(-)
---
diff --git a/calendar/gui/e-day-view-time-item.c b/calendar/gui/e-day-view-time-item.c
index f85b09e..b30951b 100644
--- a/calendar/gui/e-day-view-time-item.c
+++ b/calendar/gui/e-day-view-time-item.c
@@ -727,16 +727,21 @@ edvti_second_zone_changed_cb (GSettings *settings,
{
EDayViewTimeItem *time_item = user_data;
EDayView *day_view;
+ icaltimezone *second_zone;
gchar *location;
g_return_if_fail (user_data != NULL);
g_return_if_fail (E_IS_DAY_VIEW_TIME_ITEM (time_item));
location = calendar_config_get_day_second_zone ();
- time_item->priv->second_zone =
- location ? icaltimezone_get_builtin_timezone (location) : NULL;
+ second_zone = location ? icaltimezone_get_builtin_timezone (location) : NULL;
g_free (location);
+ if (second_zone == time_item->priv->second_zone)
+ return;
+
+ time_item->priv->second_zone = second_zone;
+
day_view = e_day_view_time_item_get_day_view (time_item);
gtk_widget_set_size_request (
day_view->time_canvas,
diff --git a/e-util/e-web-view.c b/e-util/e-web-view.c
index 3985401..afb3cc9 100644
--- a/e-util/e-web-view.c
+++ b/e-util/e-web-view.c
@@ -69,6 +69,8 @@ struct _EWebViewPrivate {
GSettings *aliasing_settings;
gulong antialiasing_changed_handler_id;
+
+ GHashTable *old_settings;
};
struct _AsyncContext {
@@ -897,6 +899,11 @@ web_view_finalize (GObject *object)
while (!g_queue_is_empty (&priv->highlights))
g_free (g_queue_pop_head (&priv->highlights));
+ if (priv->old_settings) {
+ g_hash_table_destroy (priv->old_settings);
+ priv->old_settings = NULL;
+ }
+
/* Chain up to parent's finalize() method. */
G_OBJECT_CLASS (e_web_view_parent_class)->finalize (object);
}
@@ -1407,6 +1414,28 @@ web_view_selectable_select_all (ESelectable *selectable)
e_web_view_select_all (E_WEB_VIEW (selectable));
}
+static void
+e_web_view_test_change_and_update_fonts_cb (EWebView *web_view,
+ const gchar *key,
+ GSettings *settings)
+{
+ GVariant *new_value, *old_value;
+
+ new_value = g_settings_get_value (settings, key);
+ old_value = g_hash_table_lookup (web_view->priv->old_settings, key);
+
+ if (!new_value || !old_value || !g_variant_equal (new_value, old_value)) {
+ if (new_value)
+ g_hash_table_insert (web_view->priv->old_settings, g_strdup (key), new_value);
+ else
+ g_hash_table_remove (web_view->priv->old_settings, key);
+
+ e_web_view_update_fonts (web_view);
+ } else if (new_value) {
+ g_variant_unref (new_value);
+ }
+}
+
static gpointer
web_view_disable_webkit_3rd_party_plugins (gpointer unused)
{
@@ -1670,6 +1699,8 @@ e_web_view_init (EWebView *web_view)
web_view->priv = E_WEB_VIEW_GET_PRIVATE (web_view);
+ web_view->priv->old_settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) g_variant_unref);
+
/* XXX No WebKitWebView class method pointers to
* override so we have to use signal handlers. */
@@ -1727,11 +1758,11 @@ e_web_view_init (EWebView *web_view)
web_view->priv->font_settings = g_object_ref (settings);
handler_id = g_signal_connect_swapped (
settings, "changed::font-name",
- G_CALLBACK (e_web_view_update_fonts), web_view);
+ G_CALLBACK (e_web_view_test_change_and_update_fonts_cb), web_view);
web_view->priv->font_name_changed_handler_id = handler_id;
handler_id = g_signal_connect_swapped (
settings, "changed::monospace-font-name",
- G_CALLBACK (e_web_view_update_fonts), web_view);
+ G_CALLBACK (e_web_view_test_change_and_update_fonts_cb), web_view);
web_view->priv->monospace_font_name_changed_handler_id = handler_id;
g_object_unref (settings);
@@ -1744,7 +1775,7 @@ e_web_view_init (EWebView *web_view)
web_view->priv->aliasing_settings = g_object_ref (settings);
handler_id = g_signal_connect_swapped (
settings, "changed::antialiasing",
- G_CALLBACK (e_web_view_update_fonts), web_view);
+ G_CALLBACK (e_web_view_test_change_and_update_fonts_cb), web_view);
web_view->priv->antialiasing_changed_handler_id = handler_id;
g_object_unref (settings);
g_settings_schema_unref (settings_schema);
diff --git a/libemail-engine/mail-config.c b/libemail-engine/mail-config.c
index 17532f2..e9f3e8e 100644
--- a/libemail-engine/mail-config.c
+++ b/libemail-engine/mail-config.c
@@ -73,11 +73,24 @@ settings_jh_headers_changed (GSettings *settings,
gchar **strv;
gint i;
+ strv = g_settings_get_strv (settings, "junk-custom-header");
+ if (key) {
+ for (i = 0, node = config->jh_header; strv[i] && node; i++, node = g_slist_next (node)) {
+ if (g_strcmp0 (node->data, strv[i]) != 0)
+ break;
+ }
+
+ /* both lists are read to the end, thus they are the same */
+ if (!node && !strv[i]) {
+ g_strfreev (strv);
+ return;
+ }
+ }
+
g_slist_foreach (config->jh_header, (GFunc) g_free, NULL);
g_slist_free (config->jh_header);
config->jh_header = NULL;
- strv = g_settings_get_strv (settings, "junk-custom-header");
for (i = 0; strv[i] != NULL; i++)
config->jh_header = g_slist_append (config->jh_header, g_strdup (strv[i]));
g_strfreev (strv);
@@ -108,6 +121,9 @@ settings_jh_check_changed (GSettings *settings,
const gchar *key,
EMailSession *session)
{
+ if (key && config->jh_check == g_settings_get_boolean (settings, "junk-check-custom-header"))
+ return;
+
config->jh_check = g_settings_get_boolean (settings, "junk-check-custom-header");
if (!config->jh_check) {
camel_session_set_junk_headers (
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index 5dc0286..61751df 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -59,6 +59,8 @@ struct _EMailDisplayPrivate {
GHashTable *widgets;
guint scheduled_reload;
+
+ GHashTable *old_settings;
};
enum {
@@ -1135,6 +1137,22 @@ mail_display_dispose (GObject *object)
}
static void
+mail_display_finalize (GObject *object)
+{
+ EMailDisplayPrivate *priv;
+
+ priv = E_MAIL_DISPLAY_GET_PRIVATE (object);
+
+ if (priv->old_settings) {
+ g_hash_table_destroy (priv->old_settings);
+ priv->old_settings = NULL;
+ }
+
+ /* Chain up to parent's finalize() method. */
+ G_OBJECT_CLASS (e_mail_display_parent_class)->finalize (object);
+}
+
+static void
mail_display_constructed (GObject *object)
{
e_extensible_load_extensions (E_EXTENSIBLE (object));
@@ -1406,6 +1424,28 @@ mail_display_set_fonts (EWebView *web_view,
}
static void
+e_mail_display_test_change_and_update_fonts_cb (EMailDisplay *mail_display,
+ const gchar *key,
+ GSettings *settings)
+{
+ GVariant *new_value, *old_value;
+
+ new_value = g_settings_get_value (settings, key);
+ old_value = g_hash_table_lookup (mail_display->priv->old_settings, key);
+
+ if (!new_value || !old_value || !g_variant_equal (new_value, old_value)) {
+ if (new_value)
+ g_hash_table_insert (mail_display->priv->old_settings, g_strdup (key), new_value);
+ else
+ g_hash_table_remove (mail_display->priv->old_settings, key);
+
+ e_web_view_update_fonts (E_WEB_VIEW (mail_display));
+ } else if (new_value) {
+ g_variant_unref (new_value);
+ }
+}
+
+static void
e_mail_display_class_init (EMailDisplayClass *class)
{
GObjectClass *object_class;
@@ -1419,6 +1459,7 @@ e_mail_display_class_init (EMailDisplayClass *class)
object_class->set_property = mail_display_set_property;
object_class->get_property = mail_display_get_property;
object_class->dispose = mail_display_dispose;
+ object_class->finalize = mail_display_finalize;
widget_class = GTK_WIDGET_CLASS (class);
widget_class->realize = mail_display_realize;
@@ -1496,6 +1537,8 @@ e_mail_display_init (EMailDisplay *display)
display->priv = E_MAIL_DISPLAY_GET_PRIVATE (display);
+ display->priv->old_settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) g_variant_unref);
+
/* Set invalid mode so that MODE property initialization is run
* completely (see e_mail_display_set_mode) */
display->priv->mode = E_MAIL_FORMATTER_MODE_INVALID;
@@ -1536,13 +1579,13 @@ e_mail_display_init (EMailDisplay *display)
display->priv->settings = g_settings_new ("org.gnome.evolution.mail");
g_signal_connect_swapped (
display->priv->settings , "changed::monospace-font",
- G_CALLBACK (e_web_view_update_fonts), display);
+ G_CALLBACK (e_mail_display_test_change_and_update_fonts_cb), display);
g_signal_connect_swapped (
display->priv->settings , "changed::variable-width-font",
- G_CALLBACK (e_web_view_update_fonts), display);
+ G_CALLBACK (e_mail_display_test_change_and_update_fonts_cb), display);
g_signal_connect_swapped (
display->priv->settings , "changed::use-custom-font",
- G_CALLBACK (e_web_view_update_fonts), display);
+ G_CALLBACK (e_mail_display_test_change_and_update_fonts_cb), display);
e_web_view_update_fonts (E_WEB_VIEW (display));
diff --git a/modules/calendar/e-cal-shell-backend.c b/modules/calendar/e-cal-shell-backend.c
index 0a9c80f..65f8802 100644
--- a/modules/calendar/e-cal-shell-backend.c
+++ b/modules/calendar/e-cal-shell-backend.c
@@ -666,7 +666,17 @@ static void
cal_shell_backend_use_system_timezone_changed_cb (GSettings *settings,
const gchar *key)
{
- g_signal_emit_by_name (settings, "changed::timezone", timezone);
+ /* the '-1' is a trick to emit the change the first time */
+ static gint old_value = -1;
+ gboolean value;
+
+ value = g_settings_get_boolean (settings, key);
+
+ if ((value ? 1 : 0) != old_value) {
+ old_value = value ? 1 : 0;
+
+ g_signal_emit_by_name (settings, "changed::timezone", timezone);
+ }
}
static void
diff --git a/modules/calendar/e-task-shell-view-private.c b/modules/calendar/e-task-shell-view-private.c
index 863fd01..5a26284 100644
--- a/modules/calendar/e-task-shell-view-private.c
+++ b/modules/calendar/e-task-shell-view-private.c
@@ -88,7 +88,21 @@ task_shell_view_hide_completed_tasks_changed_cb (GSettings *settings,
const gchar *key,
ETaskShellView *task_shell_view)
{
- task_shell_view_process_completed_tasks (task_shell_view);
+ GVariant *new_value, *old_value;
+
+ new_value = g_settings_get_value (settings, key);
+ old_value = g_hash_table_lookup (task_shell_view->priv->old_settings, key);
+
+ if (!new_value || !old_value || !g_variant_equal (new_value, old_value)) {
+ if (new_value)
+ g_hash_table_insert (task_shell_view->priv->old_settings, g_strdup (key), new_value);
+ else
+ g_hash_table_remove (task_shell_view->priv->old_settings, key);
+
+ task_shell_view_process_completed_tasks (task_shell_view);
+ } else if (new_value) {
+ g_variant_unref (new_value);
+ }
}
static void
@@ -210,6 +224,8 @@ task_shell_view_notify_view_id_cb (EShellView *shell_view)
void
e_task_shell_view_private_init (ETaskShellView *task_shell_view)
{
+ task_shell_view->priv->old_settings = g_hash_table_new_full (g_str_hash, g_str_equal, g_free,
(GDestroyNotify) g_variant_unref);
+
e_signal_connect_notify (
task_shell_view, "notify::view-id",
G_CALLBACK (task_shell_view_notify_view_id_cb), NULL);
@@ -553,7 +569,11 @@ e_task_shell_view_private_dispose (ETaskShellView *task_shell_view)
void
e_task_shell_view_private_finalize (ETaskShellView *task_shell_view)
{
- /* XXX Nothing to do? */
+ if (task_shell_view->priv->old_settings) {
+ g_hash_table_destroy (task_shell_view->priv->old_settings);
+ task_shell_view->priv->old_settings = NULL;
+ }
+
}
void
diff --git a/modules/calendar/e-task-shell-view-private.h b/modules/calendar/e-task-shell-view-private.h
index b2a1511..d29bd2e 100644
--- a/modules/calendar/e-task-shell-view-private.h
+++ b/modules/calendar/e-task-shell-view-private.h
@@ -120,6 +120,8 @@ struct _ETaskShellViewPrivate {
guint update_completed_timeout;
guint confirm_purge : 1;
+
+ GHashTable *old_settings;
};
void e_task_shell_view_private_init
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]