diff options
-rw-r--r-- | etc/UPower.conf | 14 | ||||
-rw-r--r-- | src/Makefile.am | 2 | ||||
-rw-r--r-- | src/linux/up-backend.c | 53 | ||||
-rw-r--r-- | src/up-config.c | 120 | ||||
-rw-r--r-- | src/up-config.h | 56 |
5 files changed, 207 insertions, 38 deletions
diff --git a/etc/UPower.conf b/etc/UPower.conf index c82827a..ca120dc 100644 --- a/etc/UPower.conf +++ b/etc/UPower.conf @@ -20,6 +20,20 @@ SleepTimeout=1000 # default=true AllowHibernateEncryptedSwap=true +# Enable the Watts Up Pro device. +# +# The Watts Up Pro contains a generic FTDI USB device without a specific +# vendor and product ID. When we probe for WUP devices, we can cause +# the user to get a perplexing "Device or resource busy" error when +# attempting to use their non-WUP device. +# +# The generic FTDI device is known to also be used on: +# +# - Sparkfun FT232 breakout board +# - Parallax Propeller +# +# default=true +EnableWattsUpPro=true # Poll the kernel for dock state changes. # diff --git a/src/Makefile.am b/src/Makefile.am index 1cb9050..51c6948 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -76,6 +76,8 @@ upowerd_SOURCES = \ up-device-list.c \ up-qos.h \ up-qos.c \ + up-config.h \ + up-config.c \ up-kbd-backlight.h \ up-kbd-backlight.c \ up-wakeups.h \ diff --git a/src/linux/up-backend.c b/src/linux/up-backend.c index 069ca9b..14435be 100644 --- a/src/linux/up-backend.c +++ b/src/linux/up-backend.c @@ -40,6 +40,7 @@ #include "up-device-hid.h" #include "up-input.h" #include "up-dock.h" +#include "up-config.h" #ifdef HAVE_IDEVICE #include "up-device-idevice.h" #endif /* HAVE_IDEVICE */ @@ -57,6 +58,7 @@ struct UpBackendPrivate GUdevClient *gudev_client; UpDeviceList *managed_devices; UpDock *dock; + UpConfig *config; }; enum { @@ -105,11 +107,15 @@ up_backend_device_new (UpBackend *backend, GUdevDevice *native) } else if (g_strcmp0 (subsys, "tty") == 0) { /* try to detect a Watts Up? Pro monitor */ - device = UP_DEVICE (up_device_wup_new ()); - ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native)); - if (ret) - goto out; - g_object_unref (device); + ret = up_config_get_boolean (backend->priv->config, + "EnableWattsUpPro"); + if (ret) { + device = UP_DEVICE (up_device_wup_new ()); + ret = up_device_coldplug (device, backend->priv->daemon, G_OBJECT (native)); + if (ret) + goto out; + g_object_unref (device); + } /* no valid TTY object */ device = NULL; @@ -284,38 +290,6 @@ up_backend_uevent_signal_handler_cb (GUdevClient *client, const gchar *action, } /** - * up_backend_should_poll_docks: - **/ -static gboolean -up_backend_should_poll_docks (void) -{ - gboolean ret; - GKeyFile *keyfile; - GError *error = NULL; - - /* get the settings from the config file */ - keyfile = g_key_file_new (); - ret = g_key_file_load_from_file (keyfile, - PACKAGE_SYSCONF_DIR "/UPower/UPower.conf", - G_KEY_FILE_NONE, - &error); - if (!ret) { - g_error ("Failed to get poll setting, assuming FALSE: %s", - error->message); - g_error_free (error); - goto out; - } - ret = g_key_file_get_boolean (keyfile, - "UPower", - "PollDockDevices", - NULL); - g_debug ("Polling docks: %s", ret ? "YES" : "NO"); -out: - g_key_file_free (keyfile); - return ret; -} - -/** * up_backend_coldplug: * @backend: The %UpBackend class instance * @daemon: The %UpDaemon controlling instance @@ -355,7 +329,8 @@ up_backend_coldplug (UpBackend *backend, UpDaemon *daemon) /* add dock update object */ backend->priv->dock = up_dock_new (); - ret = up_backend_should_poll_docks (); + ret = up_config_get_boolean (backend->priv->config, "PollDockDevices"); + g_debug ("Polling docks: %s", ret ? "YES" : "NO"); up_dock_set_should_poll (backend->priv->dock, ret); ret = up_dock_coldplug (backend->priv->dock, daemon); if (!ret) @@ -643,6 +618,7 @@ static void up_backend_init (UpBackend *backend) { backend->priv = UP_BACKEND_GET_PRIVATE (backend); + backend->priv->config = up_config_new (); backend->priv->daemon = NULL; backend->priv->device_list = NULL; backend->priv->managed_devices = up_device_list_new (); @@ -660,6 +636,7 @@ up_backend_finalize (GObject *object) backend = UP_BACKEND (object); + g_object_unref (backend->priv->config); if (backend->priv->daemon != NULL) g_object_unref (backend->priv->daemon); if (backend->priv->device_list != NULL) diff --git a/src/up-config.c b/src/up-config.c new file mode 100644 index 0000000..1d92f07 --- /dev/null +++ b/src/up-config.c @@ -0,0 +1,120 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2011 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" + +#include <glib-object.h> +#include <gio/gio.h> + +#include "up-config.h" + +static void up_config_finalize (GObject *object); + +#define UP_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), UP_TYPE_CONFIG, UpConfigPrivate)) + +/** + * UpConfigPrivate: + * + * Private #UpConfig data + **/ +struct _UpConfigPrivate +{ + GKeyFile *keyfile; +}; + +G_DEFINE_TYPE (UpConfig, up_config, G_TYPE_OBJECT) + +static gpointer up_config_object = NULL; + +/** + * up_config_get_boolean: + **/ +gboolean +up_config_get_boolean (UpConfig *config, const gchar *key) +{ + return g_key_file_get_boolean (config->priv->keyfile, + "UPower", key, NULL); +} + +/** + * up_config_class_init: + **/ +static void +up_config_class_init (UpConfigClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + object_class->finalize = up_config_finalize; + g_type_class_add_private (klass, sizeof (UpConfigPrivate)); +} + +/** + * up_config_init: + **/ +static void +up_config_init (UpConfig *config) +{ + gboolean ret; + GError *error = NULL; + + config->priv = UP_CONFIG_GET_PRIVATE (config); + config->priv->keyfile = g_key_file_new (); + + /* load */ + ret = g_key_file_load_from_file (config->priv->keyfile, + PACKAGE_SYSCONF_DIR "/UPower/UPower.conf", + G_KEY_FILE_NONE, + &error); + if (!ret) { + g_warning ("failed to load config file: %s", + error->message); + g_error_free (error); + } +} + +/** + * up_config_finalize: + **/ +static void +up_config_finalize (GObject *object) +{ + UpConfig *config = UP_CONFIG (object); + UpConfigPrivate *priv = config->priv; + + g_key_file_free (priv->keyfile); + + G_OBJECT_CLASS (up_config_parent_class)->finalize (object); +} + +/** + * up_config_new: + **/ +UpConfig * +up_config_new (void) +{ + if (up_config_object != NULL) { + g_object_ref (up_config_object); + } else { + up_config_object = g_object_new (UP_TYPE_CONFIG, NULL); + g_object_add_weak_pointer (up_config_object, &up_config_object); + } + return UP_CONFIG (up_config_object); +} + diff --git a/src/up-config.h b/src/up-config.h new file mode 100644 index 0000000..2622509 --- /dev/null +++ b/src/up-config.h @@ -0,0 +1,56 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2011 Richard Hughes <richard@hughsie.com> + * + * Licensed under the GNU General Public License Version 2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __UP_CONFIG_H +#define __UP_CONFIG_H + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define UP_TYPE_CONFIG (up_config_get_type ()) +#define UP_CONFIG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), UP_TYPE_CONFIG, UpConfig)) +#define UP_CONFIG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), UP_TYPE_CONFIG, UpConfigClass)) +#define UP_IS_CONFIG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), UP_TYPE_CONFIG)) + +typedef struct _UpConfigPrivate UpConfigPrivate; +typedef struct _UpConfig UpConfig; +typedef struct _UpConfigClass UpConfigClass; + +struct _UpConfig +{ + GObject parent; + UpConfigPrivate *priv; +}; + +struct _UpConfigClass +{ + GObjectClass parent_class; +}; + +GType up_config_get_type (void); +UpConfig *up_config_new (void); +gboolean up_config_get_boolean (UpConfig *config, + const gchar *key); + +G_END_DECLS + +#endif /* __UP_CONFIG_H */ |