diff options
author | Richard Hughes <richard@hughsie.com> | 2013-07-16 12:43:36 +0100 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2013-07-16 12:43:36 +0100 |
commit | 47d1cf8681a42455aec09a23413738cd5d139548 (patch) | |
tree | 6c69f3f9d7cd93824350942ec1903daa1b3019c1 /lib | |
parent | 414421dce535f0cd762d2ec41e012c59bab78620 (diff) | |
download | colord-47d1cf8681a42455aec09a23413738cd5d139548.tar.gz |
Add methods to create a profile using CdClient with a CdIcc object
Diffstat (limited to 'lib')
-rw-r--r-- | lib/colord/cd-client-sync.c | 58 | ||||
-rw-r--r-- | lib/colord/cd-client-sync.h | 6 | ||||
-rw-r--r-- | lib/colord/cd-client.c | 75 | ||||
-rw-r--r-- | lib/colord/cd-client.h | 10 |
4 files changed, 149 insertions, 0 deletions
diff --git a/lib/colord/cd-client-sync.c b/lib/colord/cd-client-sync.c index fc76c6b..9342b8b 100644 --- a/lib/colord/cd-client-sync.c +++ b/lib/colord/cd-client-sync.c @@ -374,6 +374,64 @@ cd_client_create_profile_sync (CdClient *client, /**********************************************************************/ static void +cd_client_create_profile_for_icc_finish_sync (CdClient *client, + GAsyncResult *res, + CdClientHelper *helper) +{ + helper->profile = cd_client_create_profile_for_icc_finish (client, + res, + helper->error); + g_main_loop_quit (helper->loop); +} + +/** + * cd_client_create_profile_for_icc_sync: + * @client: a #CdClient instance. + * @icc: A #CdIcc + * @scope: the scope of the profile + * @cancellable: a #GCancellable, or %NULL + * @error: a #GError, or %NULL + * + * Creates a color profile from a #CdIcc object. + * + * WARNING: This function is synchronous, and may block. + * Do not use it in GUI applications. + * + * Return value: (transfer full): A #CdProfile object, or %NULL for error + * + * Since: 1.1.1 + **/ +CdProfile * +cd_client_create_profile_for_icc_sync (CdClient *client, + CdIcc *icc, + CdObjectScope scope, + GCancellable *cancellable, + GError **error) +{ + CdClientHelper helper; + + /* create temp object */ + memset (&helper, 0, sizeof (CdClientHelper)); + helper.loop = g_main_loop_new (NULL, FALSE); + helper.error = error; + helper.profile = NULL; + + /* run async method */ + cd_client_create_profile_for_icc (client, icc, scope, + cancellable, + (GAsyncReadyCallback) cd_client_create_profile_for_icc_finish_sync, + &helper); + g_main_loop_run (helper.loop); + + /* free temp object */ + g_main_loop_unref (helper.loop); + + return helper.profile; +} + +/**********************************************************************/ + +static void cd_client_import_profile_finish_sync (CdClient *client, GAsyncResult *res, CdClientHelper *helper) diff --git a/lib/colord/cd-client-sync.h b/lib/colord/cd-client-sync.h index 9b212c9..4d35929 100644 --- a/lib/colord/cd-client-sync.h +++ b/lib/colord/cd-client-sync.h @@ -65,6 +65,12 @@ CdProfile *cd_client_create_profile_sync (CdClient *client, GCancellable *cancellable, GError **error) G_GNUC_WARN_UNUSED_RESULT; +CdProfile *cd_client_create_profile_for_icc_sync (CdClient *client, + CdIcc *icc, + CdObjectScope scope, + GCancellable *cancellable, + GError **error) + G_GNUC_WARN_UNUSED_RESULT; CdProfile *cd_client_import_profile_sync (CdClient *client, GFile *file, GCancellable *cancellable, diff --git a/lib/colord/cd-client.c b/lib/colord/cd-client.c index 61b6109..737a27f 100644 --- a/lib/colord/cd-client.c +++ b/lib/colord/cd-client.c @@ -843,6 +843,81 @@ out: } /**********************************************************************/ +/** + * cd_client_create_profile_for_icc: + * @client: a #CdClient instance. + * @icc: #CdIcc object + * @scope: the scope of the profile + * @cancellable: a #GCancellable, or %NULL + * @callback: the function to run on completion + * @user_data: the data to pass to @callback + * + * Creates a color profile for an #CdIcc Object. + * + * Since: 1.1.1 + **/ +void +cd_client_create_profile_for_icc (CdClient *client, + CdIcc *icc, + CdObjectScope scope, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + const gchar *checksum; + const gchar *filename; + gchar *profile_id = NULL; + GHashTable *profile_props = NULL; + + g_return_if_fail (CD_IS_CLIENT (client)); + g_return_if_fail (CD_IS_ICC (icc)); + g_return_if_fail (cancellable == NULL || G_IS_CANCELLABLE (cancellable)); + + /* generate ID */ + checksum = cd_icc_get_checksum (icc); + filename = cd_icc_get_filename (icc); + profile_id = g_strdup_printf ("icc-%s", checksum); + profile_props = g_hash_table_new_full (g_str_hash, g_str_equal, + NULL, NULL); + g_hash_table_insert (profile_props, + (gpointer) CD_PROFILE_PROPERTY_FILENAME, + (gpointer) filename); + g_hash_table_insert (profile_props, + (gpointer) CD_PROFILE_METADATA_FILE_CHECKSUM, + (gpointer) checksum); + cd_client_create_profile (client, + profile_id, + scope, + profile_props, + NULL, + callback, + user_data); + g_free (profile_id); + g_hash_table_unref (profile_props); +} + + +/** + * cd_client_create_profile_for_icc_finish: + * @client: a #CdClient instance. + * @res: the #GAsyncResult + * @error: A #GError or %NULL + * + * Gets the result from the asynchronous function. + * + * Return value: (transfer full): a #CdProfile or %NULL + * + * Since: 1.1.1 + **/ +CdProfile * +cd_client_create_profile_for_icc_finish (CdClient *client, + GAsyncResult *res, + GError **error) +{ + return cd_client_create_profile_finish (client, res, error); +} + +/**********************************************************************/ /** * cd_client_import_get_profile_destination: diff --git a/lib/colord/cd-client.h b/lib/colord/cd-client.h index 0dc0428..7728f86 100644 --- a/lib/colord/cd-client.h +++ b/lib/colord/cd-client.h @@ -121,6 +121,16 @@ CdProfile *cd_client_create_profile_finish (CdClient *client, GAsyncResult *res, GError **error) G_GNUC_WARN_UNUSED_RESULT; +void cd_client_create_profile_for_icc (CdClient *client, + CdIcc *icc, + CdObjectScope scope, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +CdProfile *cd_client_create_profile_for_icc_finish (CdClient *client, + GAsyncResult *res, + GError **error) + G_GNUC_WARN_UNUSED_RESULT; void cd_client_import_profile (CdClient *client, GFile *file, GCancellable *cancellable, |