[evolution-data-server] I#343 - Slow down automatic background downloads when in power saver mode



commit 23014d17f9584dd0f793d0385757db086684836c
Author: Milan Crha <mcrha redhat com>
Date:   Mon Aug 30 17:13:54 2021 +0200

    I#343 - Slow down automatic background downloads when in power saver mode
    
    Closes https://gitlab.gnome.org/GNOME/evolution-data-server/-/issues/343

 CMakeLists.txt                                      | 13 +++++++++++++
 config.h.in                                         |  3 +++
 src/addressbook/libedata-book/e-book-meta-backend.c | 15 +++++++++++++++
 src/calendar/libedata-cal/e-cal-meta-backend.c      | 15 +++++++++++++++
 src/camel/providers/imapx/camel-imapx-server.c      |  9 +++++++++
 5 files changed, 55 insertions(+)
---
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f7bac53d0..6029a18ea 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -909,6 +909,19 @@ else(ENABLE_LARGEFILE)
        set(HAVE_O_LARGEFILE OFF)
 endif(ENABLE_LARGEFILE)
 
+# ******************************
+# Miscellaneous checks
+# ******************************
+
+set(CMAKE_REQUIRED_FLAGS ${GNOME_PLATFORM_CFLAGS})
+set(CMAKE_REQUIRED_INCLUDES ${GNOME_PLATFORM_INCLUDE_DIRS})
+set(CMAKE_REQUIRED_LIBRARIES ${GNOME_PLATFORM_LDFLAGS})
+CHECK_C_SOURCE_COMPILES("#include <gio/gio.h>
+                       int main(void) { GPowerProfileMonitor *monitor = g_power_profile_monitor_dup_default 
(); g_clear_object (&monitor); return 0; }" HAVE_GPOWERPROFILEMONITOR)
+unset(CMAKE_REQUIRED_FLAGS)
+unset(CMAKE_REQUIRED_INCLUDES)
+unset(CMAKE_REQUIRED_LIBRARIES)
+
 # ******************************
 # subparts flags
 # ******************************
diff --git a/config.h.in b/config.h.in
index bd2978acf..dfe787d19 100644
--- a/config.h.in
+++ b/config.h.in
@@ -199,3 +199,6 @@
 
 /* evolution-alarm-notify - Define if using Canberra-GTK for sound */
 #cmakedefine HAVE_CANBERRA 1
+
+/* Whether glib provides GPowerProfileMonitor */
+#cmakedefine HAVE_GPOWERPROFILEMONITOR 1
diff --git a/src/addressbook/libedata-book/e-book-meta-backend.c 
b/src/addressbook/libedata-book/e-book-meta-backend.c
index 9d50cc6b7..f2382726f 100644
--- a/src/addressbook/libedata-book/e-book-meta-backend.c
+++ b/src/addressbook/libedata-book/e-book-meta-backend.c
@@ -779,6 +779,9 @@ ebmb_refresh_internal_sync (EBookMetaBackend *meta_backend,
                            GCancellable *cancellable,
                            GError **error)
 {
+#ifdef HAVE_GPOWERPROFILEMONITOR
+       GPowerProfileMonitor *power_monitor;
+#endif
        EBookCache *book_cache;
        gboolean success = FALSE, repeat = TRUE, is_repeat = FALSE;
 
@@ -787,6 +790,18 @@ ebmb_refresh_internal_sync (EBookMetaBackend *meta_backend,
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
                goto done;
 
+#ifdef HAVE_GPOWERPROFILEMONITOR
+       /* Silently ignore the refresh request when in the power-saver mode */
+       power_monitor = g_power_profile_monitor_dup_default ();
+       if (power_monitor && g_power_profile_monitor_get_power_saver_enabled (power_monitor)) {
+               g_clear_object (&power_monitor);
+               success = TRUE;
+               goto done;
+       }
+
+       g_clear_object (&power_monitor);
+#endif
+
        e_book_backend_foreach_view_notify_progress (E_BOOK_BACKEND (meta_backend), TRUE, 0, 
_("Refreshing…"));
 
        if (!e_book_meta_backend_ensure_connected_sync (meta_backend, cancellable, with_connection_error ? 
error : NULL) ||
diff --git a/src/calendar/libedata-cal/e-cal-meta-backend.c b/src/calendar/libedata-cal/e-cal-meta-backend.c
index a97e9cdcd..9270929df 100644
--- a/src/calendar/libedata-cal/e-cal-meta-backend.c
+++ b/src/calendar/libedata-cal/e-cal-meta-backend.c
@@ -680,6 +680,9 @@ ecmb_refresh_internal_sync (ECalMetaBackend *meta_backend,
                            GCancellable *cancellable,
                            GError **error)
 {
+#ifdef HAVE_GPOWERPROFILEMONITOR
+       GPowerProfileMonitor *power_monitor;
+#endif
        ECalCache *cal_cache;
        gboolean success = FALSE, repeat = TRUE, is_repeat = FALSE;
 
@@ -688,6 +691,18 @@ ecmb_refresh_internal_sync (ECalMetaBackend *meta_backend,
        if (g_cancellable_set_error_if_cancelled (cancellable, error))
                goto done;
 
+#ifdef HAVE_GPOWERPROFILEMONITOR
+       /* Silently ignore the refresh request when in the power-saver mode */
+       power_monitor = g_power_profile_monitor_dup_default ();
+       if (power_monitor && g_power_profile_monitor_get_power_saver_enabled (power_monitor)) {
+               g_clear_object (&power_monitor);
+               success = TRUE;
+               goto done;
+       }
+
+       g_clear_object (&power_monitor);
+#endif
+
        e_cal_backend_foreach_view_notify_progress (E_CAL_BACKEND (meta_backend), TRUE, 0, _("Refreshing…"));
 
        if (!e_cal_meta_backend_ensure_connected_sync (meta_backend, cancellable, with_connection_error ? 
error : NULL) ||
diff --git a/src/camel/providers/imapx/camel-imapx-server.c b/src/camel/providers/imapx/camel-imapx-server.c
index b8905d072..eeeaaf67a 100644
--- a/src/camel/providers/imapx/camel-imapx-server.c
+++ b/src/camel/providers/imapx/camel-imapx-server.c
@@ -5558,6 +5558,15 @@ camel_imapx_server_skip_old_flags_update (CamelStore *store)
 
        skip_old_flags_update = network_monitor && g_network_monitor_get_network_metered (network_monitor);
 
+#ifdef HAVE_GPOWERPROFILEMONITOR
+       if (!skip_old_flags_update) {
+               GPowerProfileMonitor *power_monitor;
+
+               power_monitor = g_power_profile_monitor_dup_default ();
+               skip_old_flags_update = power_monitor && g_power_profile_monitor_get_power_saver_enabled 
(power_monitor);
+               g_clear_object (&power_monitor);
+       }
+#endif
        g_clear_object (&network_monitor);
        g_clear_object (&session);
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]