From dbaa80fb67f675251a0b5b2dbd74f6c00a0b39e6 Mon Sep 17 00:00:00 2001 From: Bastien Nocera Date: Mon, 25 Aug 2014 17:04:55 +0200 Subject: [PATCH] linux: Respect the CriticalPowerAction config option It was documented, but the configuration was never actually read. https://bugs.freedesktop.org/show_bug.cgi?id=82925 --- src/linux/up-backend.c | 16 ++++++++++++++-- src/up-config.c | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c index 9f4d033..f588e74 100644 --- a/src/linux/up-backend.c +++ b/src/linux/up-backend.c @@ -371,11 +371,23 @@ up_backend_get_critical_action (UpBackend *backend) { "Hibernate", "CanHibernate" }, { "PowerOff", NULL }, }; - guint i; + guint i = 0; + char *action; g_return_val_if_fail (backend->priv->logind_proxy != NULL, NULL); - for (i = 0; i < G_N_ELEMENTS (actions); i++) { + /* Find the configured action first */ + action = up_config_get_string (backend->priv->config, "CriticalPowerAction"); + if (action != NULL) { + for (i = 0; i < G_N_ELEMENTS (actions); i++) + if (g_str_equal (actions[i].method, action)) + break; + if (i >= G_N_ELEMENTS (actions)) + i = 0; + g_free (action); + } + + for (; i < G_N_ELEMENTS (actions); i++) { GVariant *result; if (actions[i].can_method) { diff --git a/src/up-config.c b/src/up-config.c index c3a4ced..703774a 100644 --- a/src/up-config.c +++ b/src/up-config.c @@ -76,8 +76,8 @@ up_config_get_uint (UpConfig *config, const gchar *key) gchar * up_config_get_string (UpConfig *config, const gchar *key) { - return g_key_file_get_integer (config->priv->keyfile, - "UPower", key, NULL); + return g_key_file_get_string (config->priv->keyfile, + "UPower", key, NULL); } /** -- 2.1.0