diff options
author | Richard Hughes <richard@hughsie.com> | 2011-03-09 15:12:54 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2011-03-09 15:12:54 +0000 |
commit | 5475eb8f7b5ade8ec30108d1c62d1b02db9bdbae (patch) | |
tree | 31c76887138a47feaeff518bd563a9ba04767dbc | |
parent | e9603eec5a577373c1148c4f7061f6cec0eba4e2 (diff) | |
download | colord-5475eb8f7b5ade8ec30108d1c62d1b02db9bdbae.tar.gz |
Add Device.GetProfileRelation() so we can get the profile to device relationship type
This will allow us to prevent 'soft' profiles being removed from the GUI.
-rw-r--r-- | libcolord/cd-device.c | 56 | ||||
-rw-r--r-- | libcolord/cd-device.h | 4 | ||||
-rw-r--r-- | libcolord/cd-self-test.c | 18 | ||||
-rw-r--r-- | src/cd-device.c | 60 | ||||
-rw-r--r-- | src/org.freedesktop.ColorManager.Device.xml | 31 |
5 files changed, 169 insertions, 0 deletions
diff --git a/libcolord/cd-device.c b/libcolord/cd-device.c index e179223..30905f4 100644 --- a/libcolord/cd-device.c +++ b/libcolord/cd-device.c @@ -1116,6 +1116,62 @@ out: } /** + * cd_device_get_profile_relation: + * @device: a #CdDevice instance. + * @profile: a #CdProfile instance. + * @cancellable: a #GCancellable or %NULL + * @error: a #GError, or %NULL. + * + * Gets the property relationship to the device. + * + * Return value: a #CdDeviceRelation + * + * Since: 0.1.4 + **/ +CdDeviceRelation +cd_device_get_profile_relation (CdDevice *device, + CdProfile *profile, + GCancellable *cancellable, + GError **error) +{ + CdDeviceRelation relation = CD_DEVICE_RELATION_UNKNOWN; + gchar *relation_string = NULL; + GError *error_local = NULL; + GVariant *response = NULL; + + g_return_val_if_fail (CD_IS_DEVICE (device), CD_DEVICE_RELATION_UNKNOWN); + g_return_val_if_fail (CD_IS_PROFILE (profile), CD_DEVICE_RELATION_UNKNOWN); + g_return_val_if_fail (device->priv->proxy != NULL, CD_DEVICE_RELATION_UNKNOWN); + + /* execute sync method */ + response = g_dbus_proxy_call_sync (device->priv->proxy, + "GetProfileRelation", + g_variant_new ("(o)", + cd_profile_get_object_path (profile)), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error_local); + if (response == NULL) { + g_set_error (error, + CD_DEVICE_ERROR, + CD_DEVICE_ERROR_FAILED, + "Failed to get relationship: %s", + error_local->message); + g_error_free (error_local); + goto out; + } + + /* get the relationship */ + g_variant_get (response, "(s)", + &relation_string); + relation = cd_device_relation_from_string (relation_string); +out: + g_free (relation_string); + if (response != NULL) + g_variant_unref (response); + return relation; +} + +/** * cd_device_get_object_path: * @device: a #CdDevice instance. * diff --git a/libcolord/cd-device.h b/libcolord/cd-device.h index 0f746c8..a9dbc87 100644 --- a/libcolord/cd-device.h +++ b/libcolord/cd-device.h @@ -134,6 +134,10 @@ gboolean cd_device_profiling_inhibit_sync (CdDevice *device, gboolean cd_device_profiling_uninhibit_sync (CdDevice *device, GCancellable *cancellable, GError **error); +CdDeviceRelation cd_device_get_profile_relation (CdDevice *device, + CdProfile *profile, + GCancellable *cancellable, + GError **error); const gchar *cd_device_get_id (CdDevice *device); const gchar *cd_device_get_model (CdDevice *device); const gchar *cd_device_get_vendor (CdDevice *device); diff --git a/libcolord/cd-self-test.c b/libcolord/cd-self-test.c index d6d808f..f8b5048 100644 --- a/libcolord/cd-self-test.c +++ b/libcolord/cd-self-test.c @@ -108,6 +108,7 @@ colord_client_func (void) { CdClient *client; CdDevice *device; + CdDeviceRelation relation; CdProfile *profile; CdProfile *profile2; CdProfile *profile_tmp; @@ -356,11 +357,28 @@ colord_client_func (void) g_assert (profile_tmp == NULL); g_clear_error (&error); + /* check there is no relation */ + relation = cd_device_get_profile_relation (device, + profile, + NULL, + &error); + g_assert_error (error, CD_DEVICE_ERROR, CD_DEVICE_ERROR_FAILED); + g_assert (relation == CD_DEVICE_RELATION_UNKNOWN); + g_clear_error (&error); + /* assign profile to device */ ret = cd_device_add_profile_sync (device, CD_DEVICE_RELATION_SOFT, profile, NULL, &error); g_assert_no_error (error); g_assert (ret); + /* check there is now a relation */ + relation = cd_device_get_profile_relation (device, + profile, + NULL, + &error); + g_assert_no_error (error); + g_assert (relation == CD_DEVICE_RELATION_SOFT); + /* assign extra profile to device */ ret = cd_device_add_profile_sync (device, CD_DEVICE_RELATION_HARD, profile2, NULL, &error); g_assert_no_error (error); diff --git a/src/cd-device.c b/src/cd-device.c index 57d72b6..fa5254e 100644 --- a/src/cd-device.c +++ b/src/cd-device.c @@ -484,6 +484,41 @@ out: } /** + * cd_device_find_profile_relation: + **/ +static CdDeviceRelation +cd_device_find_profile_relation (CdDevice *device, + const gchar *profile_object_path) +{ + CdDevicePrivate *priv = device->priv; + CdDeviceRelation relation = CD_DEVICE_RELATION_UNKNOWN; + CdProfile *profile_tmp; + guint i; + + /* search hard */ + for (i=0; i<priv->profiles_hard->len; i++) { + profile_tmp = g_ptr_array_index (priv->profiles_hard, i); + if (g_strcmp0 (profile_object_path, + cd_profile_get_object_path (profile_tmp)) == 0) { + relation = CD_DEVICE_RELATION_HARD; + goto out; + } + } + + /* search soft */ + for (i=0; i<priv->profiles_soft->len; i++) { + profile_tmp = g_ptr_array_index (priv->profiles_soft, i); + if (g_strcmp0 (profile_object_path, + cd_profile_get_object_path (profile_tmp)) == 0) { + relation = CD_DEVICE_RELATION_SOFT; + goto out; + } + } +out: + return relation; +} + +/** * _cd_device_relation_to_string: **/ static const gchar * @@ -776,6 +811,31 @@ cd_device_dbus_method_call (GDBusConnection *connection_, const gchar *sender, goto out; } + /* return 's' */ + if (g_strcmp0 (method_name, "GetProfileRelation") == 0) { + + /* find the profile relation */ + g_variant_get (parameters, "(o)", &property_value); + g_debug ("CdDevice %s:GetProfileRelation(%s)", + sender, property_name); + + relation = cd_device_find_profile_relation (device, + property_value); + if (relation == CD_DEVICE_RELATION_UNKNOWN) { + g_dbus_method_invocation_return_error (invocation, + CD_MAIN_ERROR, + CD_MAIN_ERROR_FAILED, + "no profile '%s' found", + property_name); + goto out; + } + + tuple = g_variant_new ("(s)", + cd_device_relation_to_string (relation)); + g_dbus_method_invocation_return_value (invocation, tuple); + goto out; + } + /* return 'o' */ if (g_strcmp0 (method_name, "GetProfileForQualifiers") == 0) { diff --git a/src/org.freedesktop.ColorManager.Device.xml b/src/org.freedesktop.ColorManager.Device.xml index 03f2842..b702e61 100644 --- a/src/org.freedesktop.ColorManager.Device.xml +++ b/src/org.freedesktop.ColorManager.Device.xml @@ -310,6 +310,37 @@ </method> <!--***********************************************************--> + <method name='GetProfileRelation'> + <annotation name='org.freedesktop.DBus.GLib.Async' value=''/> + <doc:doc> + <doc:description> + <doc:para> + Gets a profile relation for a given profile that has been + added to this device. + </doc:para> + </doc:description> + </doc:doc> + <arg type='o' name='object_path' direction='in'> + <doc:doc> + <doc:summary> + <doc:para> + A profile object path. + </doc:para> + </doc:summary> + </doc:doc> + </arg> + <arg type='s' name='relation' direction='out'> + <doc:doc> + <doc:summary> + <doc:para> + The profile to device relation, e.g. <doc:tt>hard</doc:tt>. + </doc:para> + </doc:summary> + </doc:doc> + </arg> + </method> + + <!--***********************************************************--> <method name='ProfilingInhibit'> <annotation name='org.freedesktop.DBus.GLib.Async' value=''/> <doc:doc> |