[gnome-color-manager] Add a convenience function gcm_utils_device_type_to_profile_type()



commit 18fd6269c2e6a731a99300e9cbb86bfe6ce05f33
Author: Richard Hughes <richard hughsie com>
Date:   Fri Dec 4 12:29:17 2009 +0000

    Add a convenience function gcm_utils_device_type_to_profile_type()

 src/gcm-prefs.c |   17 +----------------
 src/gcm-utils.c |   37 +++++++++++++++++++++++++++++++++++++
 src/gcm-utils.h |    2 ++
 3 files changed, 40 insertions(+), 16 deletions(-)
---
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index cb14e57..4a1551d 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -1094,21 +1094,7 @@ gcm_prefs_add_profiles_suitable_for_devices (GcmDeviceType type)
 	GcmProfileType profile_type_tmp;
 
 	/* get the correct profile type for the device type */
-	switch (type) {
-	case GCM_DEVICE_TYPE_DISPLAY:
-		profile_type = GCM_PROFILE_TYPE_DISPLAY_DEVICE;
-		break;
-	case GCM_DEVICE_TYPE_CAMERA:
-	case GCM_DEVICE_TYPE_SCANNER:
-		profile_type = GCM_PROFILE_TYPE_INPUT_DEVICE;
-		break;
-	case GCM_DEVICE_TYPE_PRINTER:
-		profile_type = GCM_PROFILE_TYPE_OUTPUT_DEVICE;
-		break;
-	default:
-		egg_warning ("unknown type: %i", type);
-		profile_type = GCM_PROFILE_TYPE_UNKNOWN;
-	}
+	profile_type = gcm_utils_device_type_to_profile_type (type);
 
 	/* clear existing entries */
 	widget = GTK_WIDGET (gtk_builder_get_object (builder, "combobox_profile"));
@@ -1295,7 +1281,6 @@ gcm_prefs_devices_treeview_clicked_cb (GtkTreeSelection *selection, gpointer use
 	g_free (profile_filename);
 }
 
-
 /**
  * gcm_prefs_profile_type_to_text:
  **/
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 63d3d12..1c89cdb 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -621,6 +621,31 @@ gcm_utils_get_default_config_location (void)
 	return filename;
 }
 
+/**
+ * gcm_utils_device_type_to_profile_type:
+ **/
+GcmProfileType
+gcm_utils_device_type_to_profile_type (GcmDeviceType type)
+{
+	GcmProfileType profile_type;
+	switch (type) {
+	case GCM_DEVICE_TYPE_DISPLAY:
+		profile_type = GCM_PROFILE_TYPE_DISPLAY_DEVICE;
+		break;
+	case GCM_DEVICE_TYPE_CAMERA:
+	case GCM_DEVICE_TYPE_SCANNER:
+		profile_type = GCM_PROFILE_TYPE_INPUT_DEVICE;
+		break;
+	case GCM_DEVICE_TYPE_PRINTER:
+		profile_type = GCM_PROFILE_TYPE_OUTPUT_DEVICE;
+		break;
+	default:
+		egg_warning ("unknown type: %i", type);
+		profile_type = GCM_PROFILE_TYPE_UNKNOWN;
+	}
+	return profile_type;
+}
+
 /***************************************************************************
  ***                          MAKE CHECK TESTS                           ***
  ***************************************************************************/
@@ -634,6 +659,8 @@ gcm_utils_test (EggTest *test)
 	GError *error = NULL;
 	GPtrArray *array;
 	gchar *filename;
+	GcmProfileType profile_type;
+	GcmDeviceType device_type;
 
 	if (!egg_test_start (test, "GcmUtils"))
 		return;
@@ -702,6 +729,16 @@ gcm_utils_test (EggTest *test)
 		egg_test_failed (test, "failed to get correct config location: %s", filename);
 	g_free (filename);
 
+	/************************************************************/
+	egg_test_title (test, "convert valid device type to profile type");
+	profile_type = gcm_utils_device_type_to_profile_type (GCM_DEVICE_TYPE_SCANNER);
+	egg_test_assert (test, (profile_type == GCM_PROFILE_TYPE_INPUT_DEVICE));
+
+	/************************************************************/
+	egg_test_title (test, "convert invalid device type to profile type");
+	profile_type = gcm_utils_device_type_to_profile_type (GCM_DEVICE_TYPE_UNKNOWN);
+	egg_test_assert (test, (profile_type == GCM_PROFILE_TYPE_UNKNOWN));
+
 	egg_test_end (test);
 }
 #endif
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index 2447675..8e1a8b1 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -25,6 +25,7 @@
 #include <glib-object.h>
 
 #include "gcm-device.h"
+#include "gcm-profile.h"
 
 #define GCM_STOCK_ICON				"gnome-color-manager"
 #define GCM_PROFILE_PATH			"/.color/icc"
@@ -49,6 +50,7 @@ gboolean	 gcm_utils_output_is_lcd		(const gchar		*output_name);
 void		 gcm_utils_alphanum_lcase		(gchar			*string);
 void		 gcm_utils_ensure_sensible_filename	(gchar			*string);
 gchar		*gcm_utils_get_default_config_location	(void);
+GcmProfileType	 gcm_utils_device_type_to_profile_type	(GcmDeviceType		 type);
 
 #endif /* __GCM_UTILS_H */
 



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