[gnome-color-manager] Add some utility functions to GcmDevice
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add some utility functions to GcmDevice
- Date: Wed, 18 Nov 2009 13:15:18 +0000 (UTC)
commit eaef0ec5179ec0c8aa3792768cec38002e0cf98d
Author: Richard Hughes <richard hughsie com>
Date: Wed Nov 18 12:25:59 2009 +0000
Add some utility functions to GcmDevice
src/gcm-device.c | 41 +++++++++++++++++++++++++++++++----------
src/gcm-device.h | 3 +++
src/gcm-utils.c | 13 +++++++++++++
src/gcm-utils.h | 1 +
4 files changed, 48 insertions(+), 10 deletions(-)
---
diff --git a/src/gcm-device.c b/src/gcm-device.c
index 61e5973..0963d90 100644
--- a/src/gcm-device.c
+++ b/src/gcm-device.c
@@ -36,6 +36,7 @@
#include "gcm-device.h"
#include "gcm-profile.h"
+#include "gcm-utils.h"
#include "egg-debug.h"
@@ -91,17 +92,37 @@ enum {
G_DEFINE_TYPE (GcmDevice, gcm_device, G_TYPE_OBJECT)
/**
- * gcm_device_get_default_config_location:
+ * gcm_device_type_from_text:
**/
-static gchar *
-gcm_device_get_default_config_location (void)
+GcmDeviceType
+gcm_device_type_from_text (const gchar *type)
{
- gchar *filename;
-
- /* create default path */
- filename = g_build_filename (g_get_user_config_dir (), "gnome-color-manager", "config.dat", NULL);
+ if (g_strcmp0 (type, "display") == 0)
+ return GCM_DEVICE_TYPE_DISPLAY;
+ if (g_strcmp0 (type, "scanner") == 0)
+ return GCM_DEVICE_TYPE_SCANNER;
+ if (g_strcmp0 (type, "printer") == 0)
+ return GCM_DEVICE_TYPE_PRINTER;
+ if (g_strcmp0 (type, "camera") == 0)
+ return GCM_DEVICE_TYPE_CAMERA;
+ return GCM_DEVICE_TYPE_UNKNOWN;
+}
- return filename;
+/**
+ * gcm_device_type_to_text:
+ **/
+const gchar *
+gcm_device_type_to_text (GcmDeviceType type)
+{
+ if (type == GCM_DEVICE_TYPE_DISPLAY)
+ return "display";
+ if (type == GCM_DEVICE_TYPE_SCANNER)
+ return "scanner";
+ if (type == GCM_DEVICE_TYPE_PRINTER)
+ return "printer";
+ if (type == GCM_DEVICE_TYPE_CAMERA)
+ return "camera";
+ return "unknown";
}
/**
@@ -190,7 +211,7 @@ gcm_device_load (GcmDevice *device, GError **error)
g_return_val_if_fail (device->priv->id != NULL, FALSE);
/* get default config */
- filename = gcm_device_get_default_config_location ();
+ filename = gcm_utils_get_default_config_location ();
/* check we have a config, or is this first start */
ret = g_file_test (filename, G_FILE_TEST_EXISTS);
@@ -269,7 +290,7 @@ gcm_device_save (GcmDevice *device, GError **error)
g_return_val_if_fail (device->priv->id != NULL, FALSE);
/* get default config */
- filename = gcm_device_get_default_config_location ();
+ filename = gcm_utils_get_default_config_location ();
/* directory exists? */
dirname = g_path_get_dirname (filename);
diff --git a/src/gcm-device.h b/src/gcm-device.h
index 438ea48..22ce30a 100644
--- a/src/gcm-device.h
+++ b/src/gcm-device.h
@@ -55,6 +55,7 @@ struct _GcmDeviceClass
};
typedef enum {
+ GCM_DEVICE_TYPE_UNKNOWN,
GCM_DEVICE_TYPE_DISPLAY,
GCM_DEVICE_TYPE_SCANNER,
GCM_DEVICE_TYPE_PRINTER,
@@ -69,6 +70,8 @@ gboolean gcm_device_load (GcmDevice *device,
GError **error);
gboolean gcm_device_save (GcmDevice *device,
GError **error);
+GcmDeviceType gcm_device_type_from_text (const gchar *type);
+const gchar *gcm_device_type_to_text (GcmDeviceType type);
G_END_DECLS
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 003f58b..80576f8 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -572,4 +572,17 @@ gcm_utils_alphanum_lcase (gchar *data)
}
}
+/**
+ * gcm_utils_get_default_config_location:
+ **/
+gchar *
+gcm_utils_get_default_config_location (void)
+{
+ gchar *filename;
+
+ /* create default path */
+ filename = g_build_filename (g_get_user_config_dir (), "gnome-color-manager", "config.dat", NULL);
+
+ return filename;
+}
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 2f39bee..991182e 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -45,6 +45,7 @@ gboolean gcm_gnome_help (const gchar *link_id);
gboolean gcm_utils_output_is_lcd_internal (const gchar *output_name);
gboolean gcm_utils_output_is_lcd (const gchar *output_name);
void gcm_utils_alphanum_lcase (gchar *string);
+gchar *gcm_utils_get_default_config_location (void);
#endif /* __GCM_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]