[gnome-color-manager] Parse the description and vendor outside of GcmCalibrate
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Parse the description and vendor outside of GcmCalibrate
- Date: Sat, 14 Nov 2009 15:29:18 +0000 (UTC)
commit 7f4ac02226432282b4c0b2de83b3f67afefc1f5a
Author: Richard Hughes <richard hughsie com>
Date: Sat Nov 14 14:22:54 2009 +0000
Parse the description and vendor outside of GcmCalibrate
src/gcm-calibrate.c | 194 ++++++++++++++++++++++++++++----------------------
src/gcm-prefs.c | 106 +++++++++++++++++++++++++++-
2 files changed, 214 insertions(+), 86 deletions(-)
---
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index 28898fa..d9788e4 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -39,7 +39,6 @@
#include <libgnomeui/gnome-rr.h>
#include "gcm-calibrate.h"
-#include "gcm-edid.h"
#include "gcm-utils.h"
#include "egg-debug.h"
@@ -62,17 +61,23 @@ struct _GcmCalibratePrivate
gchar *filename_source;
gchar *filename_reference;
gchar *basename;
+ gchar *manufacturer;
+ gchar *model;
+ gchar *description;
GMainLoop *loop;
GtkWidget *terminal;
GtkBuilder *builder;
pid_t child_pid;
GtkResponseType response;
GnomeRRScreen *rr_screen;
- GcmEdid *edid;
};
enum {
PROP_0,
+ PROP_BASENAME,
+ PROP_MODEL,
+ PROP_DESCRIPTION,
+ PROP_MANUFACTURER,
PROP_IS_LCD,
PROP_IS_CRT,
PROP_OUTPUT_NAME,
@@ -318,10 +323,12 @@ gcm_calibrate_display_neutralise (GcmCalibrate *calibrate, GError **error)
gchar **argv = NULL;
GtkWidget *widget;
GnomeRROutput *output;
- const guint8 *data;
GPtrArray *array = NULL;
gint x, y;
+ g_return_val_if_fail (priv->basename != NULL, FALSE);
+ g_return_val_if_fail (priv->output_name != NULL, FALSE);
+
/* match up the output name with the device number defined by dispcal */
priv->display = gcm_calibrate_get_display (priv->output_name, error);
if (priv->display == G_MAXUINT)
@@ -335,33 +342,9 @@ gcm_calibrate_display_neutralise (GcmCalibrate *calibrate, GError **error)
goto out;
}
- /* get edid */
- data = gnome_rr_output_get_edid_data (output);
- if (data == NULL) {
- if (error != NULL)
- *error = g_error_new (1, 0, "failed to get EDID for %s", priv->output_name);
- goto out;
- }
-
- /* parse edid */
- ret = gcm_edid_parse (priv->edid, data, error);
- if (!ret)
- goto out;
-
/* get l-cd or c-rt */
type = gcm_calibrate_get_display_type (calibrate);
- /* get a filename based on the serial number */
- g_object_get (priv->edid, "serial-number", &priv->basename, NULL);
- if (priv->basename == NULL)
- g_object_get (priv->edid, "monitor-name", &priv->basename, NULL);
- if (priv->basename == NULL)
- g_object_get (priv->edid, "ascii-string", &priv->basename, NULL);
- if (priv->basename == NULL)
- g_object_get (priv->edid, "vendor-name", &priv->basename, NULL);
- if (priv->basename == NULL)
- priv->basename = g_strdup ("custom");
-
/* make a suitable filename */
gcm_utils_alphanum_lcase (priv->basename);
egg_debug ("using filename basename of %s", priv->basename);
@@ -462,6 +445,8 @@ gcm_calibrate_display_generate_patches (GcmCalibrate *calibrate, GError **error)
gchar **argv = NULL;
GPtrArray *array = NULL;
+ g_return_val_if_fail (priv->basename != NULL, FALSE);
+
/* argument array */
array = g_ptr_array_new_with_free_func (g_free);
@@ -518,6 +503,8 @@ gcm_calibrate_display_draw_and_measure (GcmCalibrate *calibrate, GError **error)
gchar **argv = NULL;
GPtrArray *array = NULL;
+ g_return_val_if_fail (priv->basename != NULL, FALSE);
+
/* get l-cd or c-rt */
type = gcm_calibrate_get_display_type (calibrate);
@@ -577,40 +564,22 @@ gcm_calibrate_display_generate_profile (GcmCalibrate *calibrate, GError **error)
GcmCalibratePrivate *priv = calibrate->priv;
gchar **argv = NULL;
GDate *date;
- gchar *manufacturer = NULL;
- gchar *model = NULL;
- gchar *description_tmp = NULL;
- gchar *description = NULL;
gchar *copyright = NULL;
+ gchar *description = NULL;
GPtrArray *array = NULL;
+ GtkWidget *widget;
+
+ g_return_val_if_fail (priv->basename != NULL, FALSE);
+ g_return_val_if_fail (priv->description != NULL, FALSE);
+ g_return_val_if_fail (priv->manufacturer != NULL, FALSE);
+ g_return_val_if_fail (priv->model != NULL, FALSE);
/* create date and set it to now */
date = g_date_new ();
g_date_set_time_t (date, time (NULL));
- /* get model */
- g_object_get (priv->edid, "monitor-name", &model, NULL);
- if (model == NULL)
- g_object_get (priv->edid, "ascii-string", &model, NULL);
- if (model == NULL)
- model = g_strdup ("unknown model");
-
- /* get description */
- g_object_get (priv->edid, "ascii-string", &description_tmp, NULL);
- if (description_tmp == NULL)
- g_object_get (priv->edid, "monitor-name", &description_tmp, NULL);
- if (description_tmp == NULL)
- description_tmp = g_strdup ("calibrated monitor");
-
/* TRANSLATORS: this is the formattted custom profile description. "Custom" refers to the fact that it's user generated" */
- description = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", _("Custom"), description_tmp, date->year, date->month, date->day);
-
- /* get manufacturer */
- g_object_get (priv->edid, "vendor-name", &manufacturer, NULL);
- if (manufacturer == NULL)
- g_object_get (priv->edid, "ascii-string", &manufacturer, NULL);
- if (manufacturer == NULL)
- manufacturer = g_strdup ("unknown manufacturer");
+ description = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", _("Custom"), priv->description, date->year, date->month, date->day);
/* TRANSLATORS: this is the copyright string, where it might be "Copyright (c) 2009 Edward Scissorhands" */
copyright = g_strdup_printf ("%s %04i %s", _("Copyright (c)"), date->year, g_get_real_name ());
@@ -620,8 +589,8 @@ gcm_calibrate_display_generate_profile (GcmCalibrate *calibrate, GError **error)
/* setup the command */
g_ptr_array_add (array, g_strdup ("-v"));
- g_ptr_array_add (array, g_strdup_printf ("-A%s", manufacturer));
- g_ptr_array_add (array, g_strdup_printf ("-M%s", model));
+ g_ptr_array_add (array, g_strdup_printf ("-A%s", priv->manufacturer));
+ g_ptr_array_add (array, g_strdup_printf ("-M%s", priv->model));
g_ptr_array_add (array, g_strdup_printf ("-D%s", description));
g_ptr_array_add (array, g_strdup_printf ("-C%s", copyright));
g_ptr_array_add (array, g_strdup ("-qm"));
@@ -663,9 +632,6 @@ out:
if (array != NULL)
g_ptr_array_unref (array);
g_date_free (date);
- g_free (manufacturer);
- g_free (model);
- g_free (description_tmp);
g_free (description);
g_free (copyright);
g_strfreev (argv);
@@ -682,18 +648,19 @@ gcm_calibrate_scanner_copy (GcmCalibrate *calibrate, GError **error)
gchar *scanner = NULL;
gchar *it8cht = NULL;
gchar *it8ref = NULL;
+ gchar *filename = NULL;
GcmCalibratePrivate *priv = calibrate->priv;
+ g_return_val_if_fail (priv->basename != NULL, FALSE);
+
/* TRANSLATORS: title, a profile is a ICC file */
gcm_calibrate_set_title (calibrate, _("Copying files"));
/* TRANSLATORS: dialog message */
gcm_calibrate_set_message (calibrate, _("Copying source image, chart data and CIE reference values."));
- /* setup generic basename */
- calibrate->priv->basename = g_strdup ("scanner");
-
/* build filenames */
- scanner = g_build_filename (GCM_CALIBRATE_TEMP_DIR, "scanner.tif", NULL);
+ filename = g_strdup_printf ("%s.tif", priv->basename);
+ scanner = g_build_filename (GCM_CALIBRATE_TEMP_DIR, filename, NULL);
it8cht = g_build_filename (GCM_CALIBRATE_TEMP_DIR, "it8.cht", NULL);
it8ref = g_build_filename (GCM_CALIBRATE_TEMP_DIR, "it8ref.txt", NULL);
@@ -708,6 +675,7 @@ gcm_calibrate_scanner_copy (GcmCalibrate *calibrate, GError **error)
if (!ret)
goto out;
out:
+ g_free (filename);
g_free (scanner);
g_free (it8cht);
g_free (it8ref);
@@ -724,13 +692,15 @@ gcm_calibrate_scanner_measure (GcmCalibrate *calibrate, GError **error)
GcmCalibratePrivate *priv = calibrate->priv;
gchar **argv = NULL;
GPtrArray *array = NULL;
+ gchar *filename = NULL;
/* argument array */
array = g_ptr_array_new_with_free_func (g_free);
+ filename = g_strdup_printf ("%s.tif", priv->basename);
/* setup the command */
g_ptr_array_add (array, g_strdup ("-v"));
- g_ptr_array_add (array, g_strdup ("scanner.tif"));
+ g_ptr_array_add (array, g_strdup (filename));
g_ptr_array_add (array, g_strdup ("it8.cht"));
g_ptr_array_add (array, g_strdup ("it8ref.txt"));
argv = gcm_utils_ptr_array_to_strv (array);
@@ -762,6 +732,7 @@ gcm_calibrate_scanner_measure (GcmCalibrate *calibrate, GError **error)
goto out;
}
out:
+ g_free (filename);
if (array != NULL)
g_ptr_array_unref (array);
g_strfreev (argv);
@@ -778,28 +749,22 @@ gcm_calibrate_scanner_generate_profile (GcmCalibrate *calibrate, GError **error)
GcmCalibratePrivate *priv = calibrate->priv;
gchar **argv = NULL;
GDate *date;
- gchar *manufacturer = NULL;
- gchar *model = NULL;
gchar *description_tmp = NULL;
gchar *description = NULL;
gchar *copyright = NULL;
GPtrArray *array = NULL;
+ g_return_val_if_fail (priv->basename != NULL, FALSE);
+ g_return_val_if_fail (priv->description != NULL, FALSE);
+ g_return_val_if_fail (priv->manufacturer != NULL, FALSE);
+ g_return_val_if_fail (priv->model != NULL, FALSE);
+
/* create date and set it to now */
date = g_date_new ();
g_date_set_time_t (date, time (NULL));
- /* get model */
- model = g_strdup ("Generic profile model");
-
- /* get description */
- description_tmp = g_strdup ("Generic profile description");
-
/* TRANSLATORS: this is the formattted custom profile description. "Custom" refers to the fact that it's user generated" */
- description = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", _("Custom"), description_tmp, date->year, date->month, date->day);
-
- /* get manufacturer */
- manufacturer = g_strdup ("Generic profile manufacturer");
+ description = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", _("Custom"), priv->description, date->year, date->month, date->day);
/* TRANSLATORS: this is the copyright string, where it might be "Copyright (c) 2009 Edward Scissorhands" */
copyright = g_strdup_printf ("%s %04i %s", _("Copyright (c)"), date->year, g_get_real_name ());
@@ -809,13 +774,13 @@ gcm_calibrate_scanner_generate_profile (GcmCalibrate *calibrate, GError **error)
/* setup the command */
g_ptr_array_add (array, g_strdup ("-v"));
- g_ptr_array_add (array, g_strdup_printf ("-A%s", manufacturer));
- g_ptr_array_add (array, g_strdup_printf ("-M%s", model));
+ g_ptr_array_add (array, g_strdup_printf ("-A%s", priv->manufacturer));
+ g_ptr_array_add (array, g_strdup_printf ("-M%s", priv->model));
g_ptr_array_add (array, g_strdup_printf ("-D%s", description));
g_ptr_array_add (array, g_strdup_printf ("-C%s", copyright));
g_ptr_array_add (array, g_strdup ("-qm"));
// g_ptr_array_add (array, g_strdup ("-as"));
- g_ptr_array_add (array, g_strdup ("scanner"));
+ g_ptr_array_add (array, g_strdup (priv->basename));
argv = gcm_utils_ptr_array_to_strv (array);
gcm_calibrate_debug_argv ("colprof", argv);
@@ -848,10 +813,7 @@ out:
if (array != NULL)
g_ptr_array_unref (array);
g_date_free (date);
- g_free (manufacturer);
- g_free (model);
g_free (description_tmp);
- g_free (description);
g_free (copyright);
g_strfreev (argv);
return ret;
@@ -991,6 +953,18 @@ gcm_calibrate_get_property (GObject *object, guint prop_id, GValue *value, GPara
case PROP_FILENAME_REFERENCE:
g_value_set_string (value, priv->filename_reference);
break;
+ case PROP_BASENAME:
+ g_value_set_string (value, priv->basename);
+ break;
+ case PROP_MODEL:
+ g_value_set_string (value, priv->model);
+ break;
+ case PROP_DESCRIPTION:
+ g_value_set_string (value, priv->description);
+ break;
+ case PROP_MANUFACTURER:
+ g_value_set_string (value, priv->manufacturer);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1080,6 +1054,22 @@ gcm_calibrate_set_property (GObject *object, guint prop_id, const GValue *value,
g_free (priv->filename_reference);
priv->filename_reference = g_strdup (g_value_get_string (value));
break;
+ case PROP_BASENAME:
+ g_free (priv->basename);
+ priv->basename = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_MODEL:
+ g_free (priv->model);
+ priv->model = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_DESCRIPTION:
+ g_free (priv->description);
+ priv->description = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_MANUFACTURER:
+ g_free (priv->manufacturer);
+ priv->manufacturer = g_strdup (g_value_get_string (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -1138,6 +1128,38 @@ gcm_calibrate_class_init (GcmCalibrateClass *klass)
G_PARAM_READWRITE);
g_object_class_install_property (object_class, PROP_FILENAME_REFERENCE, pspec);
+ /**
+ * GcmCalibrate:basename:
+ */
+ pspec = g_param_spec_string ("basename", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_BASENAME, pspec);
+
+ /**
+ * GcmCalibrate:model:
+ */
+ pspec = g_param_spec_string ("model", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_MODEL, pspec);
+
+ /**
+ * GcmCalibrate:description:
+ */
+ pspec = g_param_spec_string ("description", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_DESCRIPTION, pspec);
+
+ /**
+ * GcmCalibrate:manufacturer:
+ */
+ pspec = g_param_spec_string ("manufacturer", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_MANUFACTURER, pspec);
+
g_type_class_add_private (klass, sizeof (GcmCalibratePrivate));
}
@@ -1157,6 +1179,9 @@ gcm_calibrate_init (GcmCalibrate *calibrate)
calibrate->priv->filename_source = NULL;
calibrate->priv->filename_reference = NULL;
calibrate->priv->basename = NULL;
+ calibrate->priv->manufacturer = NULL;
+ calibrate->priv->model = NULL;
+ calibrate->priv->description = NULL;
calibrate->priv->child_pid = -1;
calibrate->priv->loop = g_main_loop_new (NULL, FALSE);
@@ -1177,9 +1202,6 @@ gcm_calibrate_init (GcmCalibrate *calibrate)
return;
}
- /* get edid parser */
- calibrate->priv->edid = gcm_edid_new ();
-
/* set icon */
main_window = GTK_WIDGET (gtk_builder_get_object (calibrate->priv->builder, "dialog_calibrate"));
gtk_window_set_icon_name (GTK_WINDOW (main_window), GCM_STOCK_ICON);
@@ -1229,9 +1251,11 @@ gcm_calibrate_finalize (GObject *object)
g_free (priv->filename_reference);
g_free (priv->output_name);
g_free (priv->basename);
+ g_free (priv->manufacturer);
+ g_free (priv->model);
+ g_free (priv->description);
g_main_loop_unref (priv->loop);
g_object_unref (priv->builder);
- g_object_unref (priv->edid);
gnome_rr_screen_destroy (priv->rr_screen);
G_OBJECT_CLASS (gcm_calibrate_parent_class)->finalize (object);
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index 8252740..f921d6c 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -85,6 +85,8 @@ gcm_prefs_help_cb (GtkWidget *widget, gpointer data)
gcm_gnome_help ("preferences");
}
+#include "gcm-edid.h"
+
/**
* gcm_prefs_calibrate_display:
**/
@@ -96,6 +98,13 @@ gcm_prefs_calibrate_display (GcmCalibrate *calib)
GError *error = NULL;
gchar *output_name = NULL;
guint percentage = G_MAXUINT;
+ GnomeRROutput *output;
+ const guint8 *data;
+ GcmEdid *edid = NULL;
+ gchar *basename = NULL;
+ gchar *manufacturer = NULL;
+ gchar *model = NULL;
+ gchar *description = NULL;
/* get the device */
g_object_get (current_device,
@@ -106,12 +115,67 @@ gcm_prefs_calibrate_display (GcmCalibrate *calib)
goto out;
}
- /* create new calibration and brightness objects */
+ /* create new helper objects */
brightness = gcm_brightness_new ();
+ edid = gcm_edid_new ();
+
+ /* get the device */
+ output = gnome_rr_screen_get_output_by_name (rr_screen, output_name);
+ if (output == NULL)
+ goto out;
+
+ /* get edid */
+ data = gnome_rr_output_get_edid_data (output);
+ if (data == NULL)
+ goto out;
+
+ /* parse edid */
+ ret = gcm_edid_parse (edid, data, &error);
+ if (!ret) {
+ egg_warning ("failed to get brightness: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* get a filename based on the serial number */
+ g_object_get (edid, "serial-number", &basename, NULL);
+ if (basename == NULL)
+ g_object_get (edid, "monitor-name", &basename, NULL);
+ if (basename == NULL)
+ g_object_get (edid, "ascii-string", &basename, NULL);
+ if (basename == NULL)
+ g_object_get (edid, "vendor-name", &basename, NULL);
+ if (basename == NULL)
+ basename = g_strdup ("custom");
+
+ /* get model */
+ g_object_get (edid, "monitor-name", &model, NULL);
+ if (model == NULL)
+ g_object_get (edid, "ascii-string", &model, NULL);
+ if (model == NULL)
+ model = g_strdup ("unknown model");
+
+ /* get description */
+ g_object_get (edid, "ascii-string", &description, NULL);
+ if (description == NULL)
+ g_object_get (edid, "monitor-name", &description, NULL);
+ if (description == NULL)
+ description = g_strdup ("calibrated monitor");
+
+ /* get manufacturer */
+ g_object_get (edid, "vendor-name", &manufacturer, NULL);
+ if (manufacturer == NULL)
+ g_object_get (edid, "ascii-string", &manufacturer, NULL);
+ if (manufacturer == NULL)
+ manufacturer = g_strdup ("unknown manufacturer");
/* set the proper output name */
g_object_set (calib,
"output-name", output_name,
+ "basename", basename,
+ "model", model,
+ "description", description,
+ "manufacturer", manufacturer,
NULL);
/* if we are an internal LCD, we need to set the brightness to maximum */
@@ -189,9 +253,15 @@ finish_calibrate:
}
}
out:
+ if (edid != NULL)
+ g_object_unref (edid);
if (brightness != NULL)
g_object_unref (brightness);
g_free (output_name);
+ g_free (basename);
+ g_free (manufacturer);
+ g_free (model);
+ g_free (description);
return ret;
}
@@ -291,6 +361,22 @@ gcm_prefs_calibrate_scanner (GcmCalibrate *calib)
GError *error = NULL;
gchar *scanned_image = NULL;
gchar *reference_data = NULL;
+ gchar *basename = NULL;
+ gchar *manufacturer = NULL;
+ gchar *model = NULL;
+ gchar *description = NULL;
+
+ /* get the device */
+ g_object_get (current_device,
+ "id", &basename,
+ "vendor", &manufacturer,
+ "description", &model,
+ "vendor", &manufacturer,
+ NULL);
+ if (basename == NULL) {
+ egg_warning ("failed to get device id");
+ goto out;
+ }
/* get scanned image */
scanned_image = gcm_prefs_calibrate_scanner_get_scanned_profile ();
@@ -302,8 +388,22 @@ gcm_prefs_calibrate_scanner (GcmCalibrate *calib)
if (reference_data == NULL)
goto out;
+ /* ensure we have data */
+ if (basename == NULL)
+ basename = g_strdup ("scanner");
+ if (manufacturer == NULL)
+ manufacturer = g_strdup ("Generic vendor");
+ if (model == NULL)
+ model = g_strdup ("Generic model");
+ if (description == NULL)
+ description = g_strdup ("Generic scanner");
+
/* set the calibration parameters */
g_object_set (calib,
+ "basename", basename,
+ "model", model,
+ "description", description,
+ "manufacturer", manufacturer,
"filename-source", scanned_image,
"filename-reference", reference_data,
NULL);
@@ -332,6 +432,10 @@ gcm_prefs_calibrate_scanner (GcmCalibrate *calib)
goto out;
}
out:
+ g_free (basename);
+ g_free (manufacturer);
+ g_free (model);
+ g_free (description);
g_free (scanned_image);
g_free (reference_data);
return ret;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]