[gnome-color-manager] trivial: Use the content type to detect ICC profiles
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] trivial: Use the content type to detect ICC profiles
- Date: Wed, 30 Dec 2009 16:05:10 +0000 (UTC)
commit 9b3d998191cd89ac7ce4c6ddb65f06202ddaf07e
Author: Richard Hughes <richard hughsie com>
Date: Wed Dec 30 12:51:25 2009 +0000
trivial: Use the content type to detect ICC profiles
src/gcm-self-test.c | 2 +-
src/gcm-utils.c | 59 ++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 50 insertions(+), 11 deletions(-)
---
diff --git a/src/gcm-self-test.c b/src/gcm-self-test.c
index abb51bc..e919fe0 100644
--- a/src/gcm-self-test.c
+++ b/src/gcm-self-test.c
@@ -50,7 +50,6 @@ main (int argc, char **argv)
egg_debug_init (&argc, &argv);
/* components */
- gcm_image_test (test);
gcm_edid_test (test);
gcm_tables_test (test);
gcm_utils_test (test);
@@ -63,6 +62,7 @@ main (int argc, char **argv)
gcm_trc_widget_test (test);
gcm_cie_widget_test (test);
gcm_gamma_widget_test (test);
+ gcm_image_test (test);
gcm_calibrate_manual_test (test);
return (egg_test_finish (test));
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index d8fe8bd..1e578d1 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -42,16 +42,48 @@
gboolean
gcm_utils_is_icc_profile (const gchar *filename)
{
- /* TODO: use the mime data if we have a new enought s-m-i */
- if (g_str_has_suffix (filename, ".icc"))
- return TRUE;
- if (g_str_has_suffix (filename, ".icm"))
- return TRUE;
- if (g_str_has_suffix (filename, ".ICC"))
- return TRUE;
- if (g_str_has_suffix (filename, ".ICM"))
- return TRUE;
- return FALSE;
+ GFile *file;
+ GFileInfo *info;
+ const gchar *type;
+ GError *error = NULL;
+ gboolean ret = FALSE;
+
+ /* get content type for file */
+ file = g_file_new_for_path (filename);
+ info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error);
+ if (info != NULL) {
+ type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE);
+ if (g_strcmp0 (type, "application/vnd.iccprofile") == 0) {
+ ret = TRUE;
+ goto out;
+ }
+ } else {
+ egg_warning ("failed to get content type of %s: %s", filename, error->message);
+ g_error_free (error);
+ }
+
+ /* fall back if we have not got a new enought s-m-i */
+ if (g_str_has_suffix (filename, ".icc")) {
+ ret = TRUE;
+ goto out;
+ }
+ if (g_str_has_suffix (filename, ".icm")) {
+ ret = TRUE;
+ goto out;
+ }
+ if (g_str_has_suffix (filename, ".ICC")) {
+ ret = TRUE;
+ goto out;
+ }
+ if (g_str_has_suffix (filename, ".ICM")) {
+ ret = TRUE;
+ goto out;
+ }
+out:
+ if (info != NULL)
+ g_object_unref (info);
+ g_object_unref (file);
+ return ret;
}
/**
@@ -842,6 +874,13 @@ gcm_utils_test (EggTest *test)
g_free (filename);
/************************************************************/
+ egg_test_title (test, "check is icc profile");
+ filename = egg_test_get_data_file ("bluish.icc");
+ ret = gcm_utils_is_icc_profile (filename);
+ egg_test_assert (test, ret);
+ g_free (filename);
+
+ /************************************************************/
egg_test_title (test, "detect LVDS panels");
ret = gcm_utils_output_is_lcd_internal ("LVDS1");
egg_test_assert (test, ret);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]