[gnome-color-manager] Allow passing profile and device types to GetProfilesForType()



commit 54f8cfc5fcf90bb04b0a2d87101ba57d7bbccba5
Author: Richard Hughes <richard hughsie com>
Date:   Fri Jun 25 12:11:23 2010 +0100

    Allow passing profile and device types to GetProfilesForType()
    
    This allows us to get 'abstract' profiles and do some funky things in the future

 src/gcm-inspect.c |   12 ++++++++----
 src/gcm-session.c |   32 ++++++++++++++++++++++----------
 src/gcm-utils.c   |    1 -
 3 files changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/src/gcm-inspect.c b/src/gcm-inspect.c
index 8b101a1..78f72a2 100644
--- a/src/gcm-inspect.c
+++ b/src/gcm-inspect.c
@@ -556,13 +556,13 @@ out:
 int
 main (int argc, char **argv)
 {
+	guint i;
 	gboolean x11 = FALSE;
 	gboolean dump = FALSE;
 	guint xid = 0;
 	gchar *device_id = NULL;
 	gchar *type = NULL;
 	gchar *filename = NULL;
-	GcmDeviceKind kind_enum;
 	guint retval = 0;
 	GOptionContext *context;
 
@@ -613,10 +613,14 @@ main (int argc, char **argv)
 	if (xid != 0)
 		gcm_inspect_show_profile_for_window (xid);
 	if (type != NULL) {
-		kind_enum = gcm_device_kind_from_string (type);
-		if (kind_enum == GCM_DEVICE_KIND_UNKNOWN) {
+		if (gcm_device_kind_from_string (type) == GCM_DEVICE_KIND_UNKNOWN &&
+		    gcm_profile_kind_from_string (type) == GCM_PROFILE_KIND_UNKNOWN) {
 			/* TRANSLATORS: this is when the user does --type=mickeymouse */
-			g_print ("%s\n", _("Device type not recognized"));
+			g_print ("%s\n", _("Device or profile type not recognized, recognised types are:"));
+			for (i=1; i<GCM_DEVICE_KIND_LAST; i++)
+				g_print (" - %s\n", gcm_device_kind_to_string (i));
+			for (i=1; i<GCM_PROFILE_KIND_LAST; i++)
+				g_print (" - %s\n", gcm_profile_kind_to_string (i));
 		} else {
 			/* show device profiles */
 			gcm_inspect_show_profiles_for_type (type);
diff --git a/src/gcm-session.c b/src/gcm-session.c
index 78bd0ca..c64d3e8 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -246,32 +246,26 @@ out:
 }
 
 /**
- * gcm_session_get_profiles_for_kind:
+ * gcm_session_get_profiles_for_profile_kind:
  **/
 static GPtrArray *
-gcm_session_get_profiles_for_kind (GcmDeviceKind kind, GError **error)
+gcm_session_get_profiles_for_profile_kind (GcmProfileKind kind, GError **error)
 {
 	guint i;
 	GcmProfile *profile;
-	GcmProfileKind profile_kind;
-	GcmProfileKind kind_tmp;
 	GPtrArray *array;
 	GPtrArray *profile_array;
 
 	/* create a temp array */
 	array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
 
-	/* get the correct profile kind for the device kind */
-	profile_kind = gcm_utils_device_kind_to_profile_kind (kind);
-
 	/* get list */
 	profile_array = gcm_profile_store_get_array (profile_store);
 	for (i=0; i<profile_array->len; i++) {
 		profile = g_ptr_array_index (profile_array, i);
 
 		/* compare what we have against what we were given */
-		kind_tmp = gcm_profile_get_kind (profile);
-		if (kind_tmp == profile_kind)
+		if (kind == gcm_profile_get_kind (profile))
 			g_ptr_array_add (array, g_object_ref (profile));
 	}
 
@@ -437,6 +431,8 @@ gcm_session_handle_method_call (GDBusConnection *connection_, const gchar *sende
 	GcmDevice *device;
 	GError *error = NULL;
 	const gchar *profile_filename;
+	GcmProfileKind profile_kind;
+	GcmDeviceKind device_kind;
 	guint i;
 
 	/* return 'as' */
@@ -503,8 +499,24 @@ gcm_session_handle_method_call (GDBusConnection *connection_, const gchar *sende
 	if (g_strcmp0 (method_name, "GetProfilesForType") == 0) {
 		g_variant_get (parameters, "(ss)", &type, &hints);
 
+		/* try to parse string */
+		profile_kind = gcm_profile_kind_from_string (type);
+		if (profile_kind == GCM_PROFILE_KIND_UNKNOWN) {
+			/* get the correct profile kind for the device kind */
+			device_kind = gcm_device_kind_from_string (type);
+			profile_kind = gcm_utils_device_kind_to_profile_kind (device_kind);
+		}
+
+		/* still nothing */
+		if (profile_kind == GCM_PROFILE_KIND_UNKNOWN) {
+			g_dbus_method_invocation_return_dbus_error (invocation,
+								    "org.gnome.ColorManager.Failed",
+								    "did not get a profile or device type");
+			goto out;
+		}
+
 		/* get array of profiles */
-		array = gcm_session_get_profiles_for_kind (gcm_device_kind_from_string (type), &error);
+		array = gcm_session_get_profiles_for_profile_kind (profile_kind, &error);
 		if (array == NULL) {
 			g_dbus_method_invocation_return_dbus_error (invocation,
 								    "org.gnome.ColorManager.Failed",
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index e159369..2189e50 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -576,7 +576,6 @@ gcm_utils_device_kind_to_profile_kind (GcmDeviceKind kind)
 		profile_kind = GCM_PROFILE_KIND_OUTPUT_DEVICE;
 		break;
 	default:
-		egg_warning ("unknown kind: %i", kind);
 		profile_kind = GCM_PROFILE_KIND_UNKNOWN;
 	}
 	return profile_kind;



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