summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2011-03-08 22:03:55 +0000
committerRichard Hughes <richard@hughsie.com>2011-03-08 22:03:55 +0000
commitd4122d2e6da2df0d33e9bcd3e0499146b90fd00a (patch)
tree1d2dc40044964be6bbf95bc725ec0d60305806a5
parent0a75394a2c2c6f0e39206c79951ea0cceb2bc067 (diff)
downloadcolord-d4122d2e6da2df0d33e9bcd3e0499146b90fd00a.tar.gz
Do not search external volumes unless SearchVolumes is set in colord.conf
-rw-r--r--src/Makefile.am2
-rw-r--r--src/cd-config.c114
-rw-r--r--src/cd-config.h59
-rw-r--r--src/cd-main.c20
4 files changed, 191 insertions, 4 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 4b343f5..23d3e9b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -28,6 +28,8 @@ libexec_PROGRAMS = \
colord_SOURCES = \
cd-common.c \
cd-common.h \
+ cd-config.c \
+ cd-config.h \
cd-device-array.c \
cd-device-array.h \
cd-device.c \
diff --git a/src/cd-config.c b/src/cd-config.c
new file mode 100644
index 0000000..905f87a
--- /dev/null
+++ b/src/cd-config.c
@@ -0,0 +1,114 @@
+/* -*- 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 "cd-config.h"
+
+static void cd_config_finalize (GObject *object);
+
+#define CD_CONFIG_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CD_TYPE_CONFIG, CdConfigPrivate))
+
+/**
+ * CdConfigPrivate:
+ *
+ * Private #CdConfig data
+ **/
+struct _CdConfigPrivate
+{
+ GKeyFile *keyfile;
+};
+
+G_DEFINE_TYPE (CdConfig, cd_config, G_TYPE_OBJECT)
+
+/**
+ * cd_config_get_boolean:
+ **/
+gboolean
+cd_config_get_boolean (CdConfig *config, const gchar *key)
+{
+ return g_key_file_get_boolean (config->priv->keyfile,
+ "colord", key, NULL);
+}
+
+/**
+ * cd_config_class_init:
+ **/
+static void
+cd_config_class_init (CdConfigClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = cd_config_finalize;
+ g_type_class_add_private (klass, sizeof (CdConfigPrivate));
+}
+
+/**
+ * cd_config_init:
+ **/
+static void
+cd_config_init (CdConfig *config)
+{
+ gboolean ret;
+ GError *error = NULL;
+
+ config->priv = CD_CONFIG_GET_PRIVATE (config);
+ config->priv->keyfile = g_key_file_new ();
+
+ /* load */
+ ret = g_key_file_load_from_file (config->priv->keyfile,
+ SYSCONFDIR "/colord.conf",
+ G_KEY_FILE_NONE,
+ &error);
+ if (!ret) {
+ g_warning ("failed to load config file: %s",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+/**
+ * cd_config_finalize:
+ **/
+static void
+cd_config_finalize (GObject *object)
+{
+ CdConfig *config = CD_CONFIG (object);
+ CdConfigPrivate *priv = config->priv;
+
+ g_key_file_free (priv->keyfile);
+
+ G_OBJECT_CLASS (cd_config_parent_class)->finalize (object);
+}
+
+/**
+ * cd_config_new:
+ **/
+CdConfig *
+cd_config_new (void)
+{
+ CdConfig *config;
+ config = g_object_new (CD_TYPE_CONFIG, NULL);
+ return CD_CONFIG (config);
+}
+
diff --git a/src/cd-config.h b/src/cd-config.h
new file mode 100644
index 0000000..0e9dd29
--- /dev/null
+++ b/src/cd-config.h
@@ -0,0 +1,59 @@
+/* -*- 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 __CD_CONFIG_H
+#define __CD_CONFIG_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define CD_TYPE_CONFIG (cd_config_get_type ())
+#define CD_CONFIG(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), CD_TYPE_CONFIG, CdConfig))
+#define CD_CONFIG_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), CD_TYPE_CONFIG, CdConfigClass))
+#define CD_IS_CONFIG(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), CD_TYPE_CONFIG))
+//#define CD_IS_CONFIG_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), CD_TYPE_CONFIG))
+//#define CD_CONFIG_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CD_TYPE_CONFIG, CdConfigClass))
+
+typedef struct _CdConfigPrivate CdConfigPrivate;
+typedef struct _CdConfig CdConfig;
+typedef struct _CdConfigClass CdConfigClass;
+
+struct _CdConfig
+{
+ GObject parent;
+ CdConfigPrivate *priv;
+};
+
+struct _CdConfigClass
+{
+ GObjectClass parent_class;
+};
+
+GType cd_config_get_type (void);
+CdConfig *cd_config_new (void);
+gboolean cd_config_get_boolean (CdConfig *config,
+ const gchar *key);
+
+G_END_DECLS
+
+#endif /* __CD_CONFIG_H */
+
diff --git a/src/cd-main.c b/src/cd-main.c
index bb35ed5..7a805fb 100644
--- a/src/cd-main.c
+++ b/src/cd-main.c
@@ -26,6 +26,7 @@
#include <locale.h>
#include "cd-common.h"
+#include "cd-config.h"
#include "cd-device-array.h"
#include "cd-device-db.h"
#include "cd-device.h"
@@ -48,6 +49,7 @@ static CdMappingDb *mapping_db = NULL;
static CdDeviceDb *device_db = NULL;
static CdUdevClient *udev_client = NULL;
static CdSaneClient *sane_client = NULL;
+static CdConfig *config = NULL;
/**
* cd_main_profile_removed:
@@ -1112,6 +1114,7 @@ cd_main_on_name_acquired_cb (GDBusConnection *connection_,
GError *error = NULL;
GPtrArray *array_devices = NULL;
guint i;
+ CdProfileSearchFlags flags;
g_debug ("CdMain: acquired name: %s", name);
connection = g_object_ref (connection_);
@@ -1124,10 +1127,14 @@ cd_main_on_name_acquired_cb (GDBusConnection *connection_,
g_signal_connect (profile_store, "removed",
G_CALLBACK (cd_main_profile_store_removed_cb),
user_data);
- cd_profile_store_search (profile_store,
- CD_PROFILE_STORE_SEARCH_SYSTEM |
- CD_PROFILE_STORE_SEARCH_VOLUMES |
- CD_PROFILE_STORE_SEARCH_MACHINE);
+
+ /* search locations specified in the config file */
+ flags = CD_PROFILE_STORE_SEARCH_SYSTEM |
+ CD_PROFILE_STORE_SEARCH_MACHINE;
+ ret = cd_config_get_boolean (config, "SearchVolumes");
+ if (ret)
+ flags |= CD_PROFILE_STORE_SEARCH_VOLUMES;
+ cd_profile_store_search (profile_store, flags);
/* add disk devices */
array_devices = cd_device_db_get_devices (device_db, &error);
@@ -1246,6 +1253,9 @@ main (int argc, char *argv[])
g_option_context_parse (context, &argc, &argv, NULL);
g_option_context_free (context);
+ /* get from config */
+ config = cd_config_new ();
+
/* create new objects */
loop = g_main_loop_new (NULL, FALSE);
devices_array = cd_device_array_new ();
@@ -1368,6 +1378,8 @@ out:
g_free (introspection_profile_data);
if (udev_client != NULL)
g_object_unref (udev_client);
+ if (config != NULL)
+ g_object_unref (config);
if (sane_client != NULL)
g_object_unref (sane_client);
if (profile_store != NULL)