[gnome-color-manager] trivial: share calibration state in a central place, GcmCalibration
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] trivial: share calibration state in a central place, GcmCalibration
- Date: Mon, 21 Dec 2009 18:24:45 +0000 (UTC)
commit 71a2f3b53fd4f7dd7cfd8c8e8cadda228b00ba00
Author: Richard Hughes <richard hughsie com>
Date: Mon Dec 21 18:16:57 2009 +0000
trivial: share calibration state in a central place, GcmCalibration
src/Makefile.am | 3 +
src/gcm-calibrate-argyll.c | 539 +++++++++++---------------------------------
src/gcm-calibrate-argyll.h | 13 +-
src/gcm-calibrate-manual.c | 24 ++-
src/gcm-calibrate-manual.h | 9 +-
src/gcm-calibrate.c | 523 ++++++++++++++++++++++++++++++++++++++++++
src/gcm-calibrate.h | 76 ++++++
src/gcm-prefs.c | 21 +-
src/gcm-utils.c | 2 +
9 files changed, 770 insertions(+), 440 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 4e32215..b7ea6a7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -146,6 +146,8 @@ gcm_import_CFLAGS = \
$(WARNINGFLAGS_C)
gcm_prefs_SOURCES = \
+ gcm-calibrate.c \
+ gcm-calibrate.h \
gcm-calibrate-argyll.c \
gcm-calibrate-argyll.h \
gcm-calibrate-manual.c \
@@ -209,6 +211,7 @@ gcm_self_test_SOURCES = \
gcm-cie-widget.c \
gcm-trc-widget.c \
gcm-gamma-widget.c \
+ gcm-calibrate.c \
gcm-calibrate-manual.c \
egg-test.h \
egg-test.c \
diff --git a/src/gcm-calibrate-argyll.c b/src/gcm-calibrate-argyll.c
index 2a6b599..b6f33b9 100644
--- a/src/gcm-calibrate-argyll.c
+++ b/src/gcm-calibrate-argyll.c
@@ -40,7 +40,6 @@
#include "gcm-calibrate-argyll.h"
#include "gcm-utils.h"
-#include "gcm-brightness.h"
#include "egg-debug.h"
@@ -55,17 +54,7 @@ static void gcm_calibrate_argyll_finalize (GObject *object);
**/
struct _GcmCalibrateArgyllPrivate
{
- gboolean is_lcd;
- gboolean is_crt;
guint display;
- gchar *output_name;
- gchar *filename_source;
- gchar *filename_reference;
- gchar *filename_result;
- gchar *basename;
- gchar *manufacturer;
- gchar *model;
- gchar *description;
GMainLoop *loop;
GtkWidget *terminal;
GtkBuilder *builder;
@@ -76,20 +65,10 @@ struct _GcmCalibrateArgyllPrivate
enum {
PROP_0,
- PROP_BASENAME,
- PROP_MODEL,
- PROP_DESCRIPTION,
- PROP_MANUFACTURER,
- PROP_IS_LCD,
- PROP_IS_CRT,
- PROP_OUTPUT_NAME,
- PROP_FILENAME_SOURCE,
- PROP_FILENAME_REFERENCE,
- PROP_FILENAME_RESULT,
PROP_LAST
};
-G_DEFINE_TYPE (GcmCalibrateArgyll, gcm_calibrate_argyll, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GcmCalibrateArgyll, gcm_calibrate_argyll, GCM_TYPE_CALIBRATE)
/* assume this is writable by users */
#define GCM_CALIBRATE_ARGYLL_TEMP_DIR "/tmp"
@@ -142,10 +121,18 @@ out:
static gchar
gcm_calibrate_argyll_get_display_type (GcmCalibrateArgyll *calibrate_argyll)
{
- GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
- if (priv->is_lcd)
+ gboolean is_lcd;
+ gboolean is_crt;
+// GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+
+ g_object_get (calibrate_argyll,
+ "is-lcd", &is_lcd,
+ "is-crt", &is_crt,
+ NULL);
+
+ if (is_lcd)
return 'l';
- if (priv->is_crt)
+ if (is_crt)
return 'c';
return '\0';
}
@@ -197,103 +184,6 @@ gcm_calibrate_argyll_debug_argv (const gchar *program, gchar **argv)
}
/**
- * gcm_calibrate_argyll_display_setup:
- **/
-static gboolean
-gcm_calibrate_argyll_display_setup (GcmCalibrateArgyll *calibrate_argyll, GError **error)
-{
- gboolean ret = TRUE;
- GtkWidget *dialog;
- GtkResponseType response;
- GString *string = NULL;
- GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
- GtkWidget *widget;
-
- /* this wasn't previously set */
- if (!priv->is_lcd && !priv->is_crt) {
- widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "dialog_calibrate"));
- dialog = gtk_message_dialog_new (GTK_WINDOW(widget), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
- /* TRANSLATORS: title, usually we can tell based on the EDID data or output name */
- _("Could not auto-detect CRT or LCD"));
- gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
- /* TRANSLATORS: dialog message */
- _("Please indicate if the screen you are trying to profile is a CRT (old type) or a LCD (digital flat panel)."));
- gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
- /* TRANSLATORS: button, Liquid Crystal Display */
- gtk_dialog_add_button (GTK_DIALOG (dialog), _("LCD"), GTK_RESPONSE_YES);
- /* TRANSLATORS: button, Cathode Ray Tube */
- gtk_dialog_add_button (GTK_DIALOG (dialog), _("CRT"), GTK_RESPONSE_NO);
- response = gtk_dialog_run (GTK_DIALOG (dialog));
- gtk_widget_destroy (dialog);
- if (response == GTK_RESPONSE_YES) {
- g_object_set (calibrate_argyll,
- "is-lcd", TRUE,
- NULL);
- } else if (response == GTK_RESPONSE_NO) {
- g_object_set (calibrate_argyll,
- "is-crt", TRUE,
- NULL);
- } else {
- if (error != NULL)
- *error = g_error_new (1, 0, "user did not choose crt or lcd");
- ret = FALSE;
- goto out;
- }
- }
-
- /* show a warning for external monitors */
- ret = gcm_utils_output_is_lcd_internal (priv->output_name);
- if (!ret) {
- string = g_string_new ("");
-
- /* TRANSLATORS: dialog message, preface */
- g_string_append_printf (string, "%s\n", _("Before calibrating the display, it is recommended to configure your display with the following settings to get optimal results."));
-
- /* TRANSLATORS: dialog message, preface */
- g_string_append_printf (string, "%s\n\n", _("You may want to consult the owner's manual for your display on how to achieve these settings."));
-
- /* TRANSLATORS: dialog message, bullet item */
- g_string_append_printf (string, "â?¢ %s\n", _("Reset your display to the factory defaults."));
-
- /* TRANSLATORS: dialog message, bullet item */
- g_string_append_printf (string, "â?¢ %s\n", _("Disable dynamic contrast if your display has this feature."));
-
- /* TRANSLATORS: dialog message, bullet item */
- g_string_append_printf (string, "â?¢ %s", _("Configure your display with custom color settings and ensure the RGB channels are set to the same values."));
-
- /* TRANSLATORS: dialog message, addition to bullet item */
- g_string_append_printf (string, " %s\n", _("If custom color is not available then use a 6500K color temperature."));
-
- /* TRANSLATORS: dialog message, bullet item */
- g_string_append_printf (string, "â?¢ %s\n", _("Adjust the display brightness to a comfortable level for prolonged viewing."));
-
- /* TRANSLATORS: dialog message, suffix */
- g_string_append_printf (string, "\n%s\n", _("For best results, the display should have been powered for at least 15 minutes before starting the calibration."));
-
- /* set the message */
- gcm_calibrate_argyll_set_message (calibrate_argyll, string->str);
-
- /* wait until user selects okay or closes window */
- g_main_loop_run (priv->loop);
-
- /* get result */
- if (priv->response != GTK_RESPONSE_OK) {
- if (error != NULL)
- *error = g_error_new (1, 0, "user follow calibration steps");
- ret = FALSE;
- goto out;
- }
- }
-
- /* success */
- ret = TRUE;
-out:
- if (string != NULL)
- g_string_free (string, TRUE);
- return ret;
-}
-
-/**
* gcm_calibrate_argyll_get_tool_filename:
**/
static gchar *
@@ -339,9 +229,14 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll, G
GnomeRROutput *output;
GPtrArray *array = NULL;
gint x, y;
+ gchar *basename = NULL;
+ gchar *output_name = NULL;
- g_return_val_if_fail (priv->basename != NULL, FALSE);
- g_return_val_if_fail (priv->output_name != NULL, FALSE);
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ "output-name", &output_name,
+ NULL);
/* get correct name of the command */
command = gcm_calibrate_argyll_get_tool_filename ("dispcal", error);
@@ -351,17 +246,17 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll, G
}
/* match up the output name with the device number defined by dispcal */
- priv->display = gcm_calibrate_argyll_get_display (priv->output_name, error);
+ priv->display = gcm_calibrate_argyll_get_display (output_name, error);
if (priv->display == G_MAXUINT) {
ret = FALSE;
goto out;
}
/* get the device */
- output = gnome_rr_screen_get_output_by_name (priv->rr_screen, priv->output_name);
+ output = gnome_rr_screen_get_output_by_name (priv->rr_screen, output_name);
if (output == NULL) {
if (error != NULL)
- *error = g_error_new (1, 0, "failed to get output for %s", priv->output_name);
+ *error = g_error_new (1, 0, "failed to get output for %s", output_name);
ret = FALSE;
goto out;
}
@@ -370,8 +265,8 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll, G
type = gcm_calibrate_argyll_get_display_type (calibrate_argyll);
/* make a suitable filename */
- gcm_utils_ensure_sensible_filename (priv->basename);
- egg_debug ("using filename basename of %s", priv->basename);
+ gcm_utils_ensure_sensible_filename (basename);
+ egg_debug ("using filename basename of %s", basename);
/* argument array */
array = g_ptr_array_new_with_free_func (g_free);
@@ -383,7 +278,7 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll, G
g_ptr_array_add (array, g_strdup_printf ("-d%i", priv->display));
g_ptr_array_add (array, g_strdup_printf ("-y%c", type));
// g_ptr_array_add (array, g_strdup ("-p 0.8,0.5,1.0"));
- g_ptr_array_add (array, g_strdup (priv->basename));
+ g_ptr_array_add (array, g_strdup (basename));
argv = gcm_utils_ptr_array_to_strv (array);
gcm_calibrate_argyll_debug_argv (command, argv);
@@ -444,6 +339,8 @@ gcm_calibrate_argyll_display_neutralise (GcmCalibrateArgyll *calibrate_argyll, G
out:
if (array != NULL)
g_ptr_array_unref (array);
+ g_free (basename);
+ g_free (output_name);
g_free (command);
g_strfreev (argv);
return ret;
@@ -470,8 +367,12 @@ gcm_calibrate_argyll_display_generate_patches (GcmCalibrateArgyll *calibrate_arg
gchar *command = NULL;
gchar **argv = NULL;
GPtrArray *array = NULL;
+ gchar *basename = NULL;
- g_return_val_if_fail (priv->basename != NULL, FALSE);
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ NULL);
/* get correct name of the command */
command = gcm_calibrate_argyll_get_tool_filename ("targen", error);
@@ -487,7 +388,7 @@ gcm_calibrate_argyll_display_generate_patches (GcmCalibrateArgyll *calibrate_arg
g_ptr_array_add (array, g_strdup ("-v"));
g_ptr_array_add (array, g_strdup ("-d3"));
g_ptr_array_add (array, g_strdup ("-f250"));
- g_ptr_array_add (array, g_strdup (priv->basename));
+ g_ptr_array_add (array, g_strdup (basename));
argv = gcm_utils_ptr_array_to_strv (array);
gcm_calibrate_argyll_debug_argv (command, argv);
@@ -520,6 +421,7 @@ gcm_calibrate_argyll_display_generate_patches (GcmCalibrateArgyll *calibrate_arg
out:
if (array != NULL)
g_ptr_array_unref (array);
+ g_free (basename);
g_free (command);
g_strfreev (argv);
return ret;
@@ -537,8 +439,12 @@ gcm_calibrate_argyll_display_draw_and_measure (GcmCalibrateArgyll *calibrate_arg
gchar *command = NULL;
gchar **argv = NULL;
GPtrArray *array = NULL;
+ gchar *basename = NULL;
- g_return_val_if_fail (priv->basename != NULL, FALSE);
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ NULL);
/* get correct name of the command */
command = gcm_calibrate_argyll_get_tool_filename ("dispread", error);
@@ -558,8 +464,8 @@ gcm_calibrate_argyll_display_draw_and_measure (GcmCalibrateArgyll *calibrate_arg
g_ptr_array_add (array, g_strdup_printf ("-d%i", priv->display));
g_ptr_array_add (array, g_strdup_printf ("-y%c", type));
g_ptr_array_add (array, g_strdup ("-k"));
- g_ptr_array_add (array, g_strdup_printf ("%s.cal", priv->basename));
- g_ptr_array_add (array, g_strdup (priv->basename));
+ g_ptr_array_add (array, g_strdup_printf ("%s.cal", basename));
+ g_ptr_array_add (array, g_strdup (basename));
argv = gcm_utils_ptr_array_to_strv (array);
gcm_calibrate_argyll_debug_argv (command, argv);
@@ -592,6 +498,7 @@ gcm_calibrate_argyll_display_draw_and_measure (GcmCalibrateArgyll *calibrate_arg
out:
if (array != NULL)
g_ptr_array_unref (array);
+ g_free (basename);
g_free (command);
g_strfreev (argv);
return ret;
@@ -608,15 +515,22 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
gchar **argv = NULL;
GDate *date = NULL;
gchar *copyright = NULL;
- gchar *description = NULL;
+ gchar *description_new = NULL;
gchar *command = NULL;
+ gchar *basename = NULL;
+ gchar *description = NULL;
+ gchar *manufacturer = NULL;
+ gchar *model = 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);
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ "description", &description,
+ "manufacturer", &manufacturer,
+ "model", &model,
+ NULL);
/* get correct name of the command */
command = gcm_calibrate_argyll_get_tool_filename ("colprof", error);
@@ -630,7 +544,7 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
g_date_set_time_t (date, time (NULL));
/* this is the formattted custom profile description. It can't be translated as we need 7-bit ASCII */
- description = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", "Custom", priv->description, date->year, date->month, date->day);
+ description_new = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", "Custom", 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 ());
@@ -640,13 +554,13 @@ gcm_calibrate_argyll_display_generate_profile (GcmCalibrateArgyll *calibrate_arg
/* setup the command */
g_ptr_array_add (array, g_strdup ("-v"));
- 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 ("-A%s", manufacturer));
+ g_ptr_array_add (array, g_strdup_printf ("-M%s", model));
+ g_ptr_array_add (array, g_strdup_printf ("-D%s", description_new));
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 (priv->basename));
+ g_ptr_array_add (array, g_strdup (basename));
argv = gcm_utils_ptr_array_to_strv (array);
gcm_calibrate_argyll_debug_argv (command, argv);
@@ -684,8 +598,12 @@ out:
g_ptr_array_unref (array);
if (date != NULL)
g_date_free (date);
+ g_free (basename);
g_free (command);
+ g_free (manufacturer);
+ g_free (model);
g_free (description);
+ g_free (description_new);
g_free (copyright);
g_strfreev (argv);
return ret;
@@ -751,9 +669,16 @@ gcm_calibrate_argyll_device_copy (GcmCalibrateArgyll *calibrate_argyll, GError *
gchar *it8cht = NULL;
gchar *it8ref = NULL;
gchar *filename = NULL;
- GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-
- g_return_val_if_fail (priv->basename != NULL, FALSE);
+ gchar *basename = NULL;
+ gchar *filename_source = NULL;
+ gchar *filename_reference = NULL;
+
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ "filename-source", &filename_source,
+ "filename-reference", &filename_reference,
+ NULL);
/* TRANSLATORS: title, a profile is a ICC file */
gcm_calibrate_argyll_set_title (calibrate_argyll, _("Copying files"));
@@ -761,7 +686,7 @@ gcm_calibrate_argyll_device_copy (GcmCalibrateArgyll *calibrate_argyll, GError *
gcm_calibrate_argyll_set_message (calibrate_argyll, _("Copying source image, chart data and CIE reference values."));
/* build filenames */
- filename = g_strdup_printf ("%s.tif", priv->basename);
+ filename = g_strdup_printf ("%s.tif", basename);
device = g_build_filename (GCM_CALIBRATE_ARGYLL_TEMP_DIR, filename, NULL);
it8cht = g_build_filename (GCM_CALIBRATE_ARGYLL_TEMP_DIR, "it8.cht", NULL);
it8ref = g_build_filename (GCM_CALIBRATE_ARGYLL_TEMP_DIR, "it8ref.txt", NULL);
@@ -770,14 +695,17 @@ gcm_calibrate_argyll_device_copy (GcmCalibrateArgyll *calibrate_argyll, GError *
ret = gcm_utils_mkdir_and_copy ("/usr/share/color/argyll/ref/it8.cht", it8cht, error);
if (!ret)
goto out;
- ret = gcm_utils_mkdir_and_copy (priv->filename_source, device, error);
+ ret = gcm_utils_mkdir_and_copy (filename_source, device, error);
if (!ret)
goto out;
- ret = gcm_utils_mkdir_and_copy (priv->filename_reference, it8ref, error);
+ ret = gcm_utils_mkdir_and_copy (filename_reference, it8ref, error);
if (!ret)
goto out;
out:
+ g_free (basename);
g_free (filename);
+ g_free (filename_source);
+ g_free (filename_reference);
g_free (device);
g_free (it8cht);
g_free (it8ref);
@@ -796,6 +724,12 @@ gcm_calibrate_argyll_device_measure (GcmCalibrateArgyll *calibrate_argyll, GErro
GPtrArray *array = NULL;
gchar *filename = NULL;
gchar *command = NULL;
+ gchar *basename = NULL;
+
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ NULL);
/* get correct name of the command */
command = gcm_calibrate_argyll_get_tool_filename ("scanin", error);
@@ -806,7 +740,7 @@ gcm_calibrate_argyll_device_measure (GcmCalibrateArgyll *calibrate_argyll, GErro
/* argument array */
array = g_ptr_array_new_with_free_func (g_free);
- filename = g_strdup_printf ("%s.tif", priv->basename);
+ filename = g_strdup_printf ("%s.tif", basename);
/* setup the command */
g_ptr_array_add (array, g_strdup ("-v"));
@@ -844,6 +778,7 @@ gcm_calibrate_argyll_device_measure (GcmCalibrateArgyll *calibrate_argyll, GErro
out:
g_free (filename);
g_free (command);
+ g_free (basename);
if (array != NULL)
g_ptr_array_unref (array);
g_strfreev (argv);
@@ -865,11 +800,17 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
gchar *copyright = NULL;
GPtrArray *array = NULL;
gchar *command = 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);
+ gchar *basename = NULL;
+ gchar *manufacturer = NULL;
+ gchar *model = NULL;
+
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ "description", &description,
+ "manufacturer", &manufacturer,
+ "model", &model,
+ NULL);
/* get correct name of the command */
command = gcm_calibrate_argyll_get_tool_filename ("colprof", error);
@@ -883,7 +824,7 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
g_date_set_time_t (date, time (NULL));
/* 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"), priv->description, date->year, date->month, date->day);
+ description_tmp = g_strdup_printf ("%s, %s (%04i-%02i-%02i)", _("Custom"), 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 ());
@@ -893,13 +834,13 @@ gcm_calibrate_argyll_device_generate_profile (GcmCalibrateArgyll *calibrate_argy
/* setup the command */
g_ptr_array_add (array, g_strdup ("-v"));
- 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 ("-A%s", manufacturer));
+ g_ptr_array_add (array, g_strdup_printf ("-M%s", model));
+ g_ptr_array_add (array, g_strdup_printf ("-D%s", description_tmp));
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 (priv->basename));
+ g_ptr_array_add (array, g_strdup (basename));
argv = gcm_utils_ptr_array_to_strv (array);
gcm_calibrate_argyll_debug_argv (command, argv);
@@ -935,6 +876,10 @@ out:
g_date_free (date);
g_free (description_tmp);
g_free (copyright);
+ g_free (basename);
+ g_free (manufacturer);
+ g_free (model);
+ g_free (description);
g_free (command);
g_strfreev (argv);
return ret;
@@ -952,12 +897,17 @@ gcm_calibrate_argyll_finish (GcmCalibrateArgyll *calibrate_argyll, GError **erro
gboolean ret;
const gchar *exts[] = {"cal", "ti1", "ti3", "tif", NULL};
const gchar *filenames[] = {"it8.cht", "it8ref.txt", NULL};
- GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
+ gchar *basename = NULL;
+
+ /* get shared data */
+ g_object_get (calibrate_argyll,
+ "basename", &basename,
+ NULL);
/* remove all the temp files */
- if (priv->basename != NULL) {
+ if (basename != NULL) {
for (i=0; exts[i] != NULL; i++) {
- filename_tmp = g_strdup_printf ("%s/%s.%s", GCM_CALIBRATE_ARGYLL_TEMP_DIR, priv->basename, exts[i]);
+ filename_tmp = g_strdup_printf ("%s/%s.%s", GCM_CALIBRATE_ARGYLL_TEMP_DIR, basename, exts[i]);
ret = g_file_test (filename_tmp, G_FILE_TEST_IS_REGULAR);
if (ret) {
egg_debug ("removing %s", filename_tmp);
@@ -979,7 +929,7 @@ gcm_calibrate_argyll_finish (GcmCalibrateArgyll *calibrate_argyll, GError **erro
}
/* we can't have finished with success */
- if (priv->basename == NULL) {
+ if (basename == NULL) {
ret = FALSE;
if (error != NULL)
*error = g_error_new (1, 0, "profile was not generated");
@@ -987,7 +937,7 @@ gcm_calibrate_argyll_finish (GcmCalibrateArgyll *calibrate_argyll, GError **erro
}
/* get the finished icc file */
- filename = g_strdup_printf ("%s/%s.icc", GCM_CALIBRATE_ARGYLL_TEMP_DIR, priv->basename);
+ filename = g_strdup_printf ("%s/%s.icc", GCM_CALIBRATE_ARGYLL_TEMP_DIR, basename);
/* we never finished all the steps */
if (!g_file_test (filename, G_FILE_TEST_EXISTS)) {
@@ -1002,6 +952,7 @@ gcm_calibrate_argyll_finish (GcmCalibrateArgyll *calibrate_argyll, GError **erro
NULL);
ret = TRUE;
out:
+ g_free (basename);
g_free (filename);
return ret;
}
@@ -1009,15 +960,13 @@ out:
/**
* gcm_calibrate_argyll_display:
**/
-gboolean
-gcm_calibrate_argyll_display (GcmCalibrateArgyll *calibrate_argyll, GtkWindow *window, GError **error)
+static gboolean
+gcm_calibrate_argyll_display (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
{
GtkWidget *widget;
+ GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL(calibrate);
GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
gboolean ret;
- GcmBrightness *brightness = NULL;
- guint percentage = G_MAXUINT;
- GError *error_tmp = NULL;
/* show main UI */
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "dialog_calibrate"));
@@ -1031,36 +980,6 @@ gcm_calibrate_argyll_display (GcmCalibrateArgyll *calibrate_argyll, GtkWindow *w
/* TRANSLATORS: dialog message */
gcm_calibrate_argyll_set_message (calibrate_argyll, _("Setting up display device for use..."));
- /* create new helper objects */
- brightness = gcm_brightness_new ();
-
- /* if we are an internal LCD, we need to set the brightness to maximum */
- ret = gcm_utils_output_is_lcd_internal (priv->output_name);
- if (ret) {
- /* get the old brightness so we can restore state */
- ret = gcm_brightness_get_percentage (brightness, &percentage, &error_tmp);
- if (!ret) {
- egg_warning ("failed to get brightness: %s", error_tmp->message);
- g_error_free (error_tmp);
- /* not fatal */
- error_tmp = NULL;
- }
-
- /* set the new brightness */
- ret = gcm_brightness_set_percentage (brightness, 100, &error_tmp);
- if (!ret) {
- egg_warning ("failed to set brightness: %s", error_tmp->message);
- g_error_free (error_tmp);
- /* not fatal */
- error_tmp = NULL;
- }
- }
-
- /* step 1 */
- ret = gcm_calibrate_argyll_display_setup (calibrate_argyll, error);
- if (!ret)
- goto out;
-
/* step 1 */
ret = gcm_calibrate_argyll_display_neutralise (calibrate_argyll, error);
if (!ret)
@@ -1086,31 +1005,17 @@ gcm_calibrate_argyll_display (GcmCalibrateArgyll *calibrate_argyll, GtkWindow *w
if (!ret)
goto out;
out:
- /* restore brightness */
- if (percentage != G_MAXUINT) {
- /* set the new brightness */
- ret = gcm_brightness_set_percentage (brightness, percentage, &error_tmp);
- if (!ret) {
- egg_warning ("failed to restore brightness: %s", error_tmp->message);
- g_error_free (error_tmp);
- /* not fatal */
- error = NULL;
- }
- }
-
- if (brightness != NULL)
- g_object_unref (brightness);
-
return ret;
}
/**
* gcm_calibrate_argyll_device:
**/
-gboolean
-gcm_calibrate_argyll_device (GcmCalibrateArgyll *calibrate_argyll, GtkWindow *window, GError **error)
+static gboolean
+gcm_calibrate_argyll_device (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
{
GtkWidget *widget;
+ GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL(calibrate);
GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
gboolean ret;
@@ -1181,40 +1086,7 @@ gcm_calibrate_argyll_exit_cb (VteTerminal *terminal, GcmCalibrateArgyll *calibra
static void
gcm_calibrate_argyll_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
{
- GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL (object);
- GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-
switch (prop_id) {
- case PROP_IS_LCD:
- g_value_set_boolean (value, priv->is_lcd);
- break;
- case PROP_IS_CRT:
- g_value_set_boolean (value, priv->is_crt);
- break;
- case PROP_OUTPUT_NAME:
- g_value_set_string (value, priv->output_name);
- break;
- case PROP_FILENAME_SOURCE:
- g_value_set_string (value, priv->filename_source);
- break;
- case PROP_FILENAME_REFERENCE:
- g_value_set_string (value, priv->filename_reference);
- break;
- case PROP_FILENAME_RESULT:
- g_value_set_string (value, priv->filename_result);
- 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;
@@ -1222,27 +1094,6 @@ gcm_calibrate_argyll_get_property (GObject *object, guint prop_id, GValue *value
}
/**
- * gcm_calibrate_argyll_guess_type:
- **/
-static void
-gcm_calibrate_argyll_guess_type (GcmCalibrateArgyll *calibrate_argyll)
-{
- gboolean ret;
- GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-
- /* guess based on the output name */
- ret = gcm_utils_output_is_lcd (priv->output_name);
- if (ret) {
- priv->is_lcd = TRUE;
- priv->is_crt = FALSE;
- } else {
- priv->is_lcd = FALSE;
- priv->is_crt = FALSE;
- }
-}
-
-
-/**
* gcm_calibrate_argyll_cancel_cb:
**/
static void
@@ -1281,49 +1132,7 @@ gcm_calibrate_argyll_delete_event_cb (GtkWidget *widget, GdkEvent *event, GcmCal
static void
gcm_calibrate_argyll_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
{
- GcmCalibrateArgyll *calibrate_argyll = GCM_CALIBRATE_ARGYLL (object);
- GcmCalibrateArgyllPrivate *priv = calibrate_argyll->priv;
-
switch (prop_id) {
- case PROP_IS_LCD:
- priv->is_lcd = g_value_get_boolean (value);
- break;
- case PROP_IS_CRT:
- priv->is_crt = g_value_get_boolean (value);
- break;
- case PROP_OUTPUT_NAME:
- g_free (priv->output_name);
- priv->output_name = g_strdup (g_value_get_string (value));
- gcm_calibrate_argyll_guess_type (calibrate_argyll);
- break;
- case PROP_FILENAME_SOURCE:
- g_free (priv->filename_source);
- priv->filename_source = g_strdup (g_value_get_string (value));
- break;
- case PROP_FILENAME_REFERENCE:
- g_free (priv->filename_reference);
- priv->filename_reference = g_strdup (g_value_get_string (value));
- break;
- case PROP_FILENAME_RESULT:
- g_free (priv->filename_result);
- priv->filename_result = 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;
@@ -1336,91 +1145,15 @@ gcm_calibrate_argyll_set_property (GObject *object, guint prop_id, const GValue
static void
gcm_calibrate_argyll_class_init (GcmCalibrateArgyllClass *klass)
{
- GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GcmCalibrateClass *parent_class = GCM_CALIBRATE_CLASS (klass);
object_class->finalize = gcm_calibrate_argyll_finalize;
object_class->get_property = gcm_calibrate_argyll_get_property;
object_class->set_property = gcm_calibrate_argyll_set_property;
- /**
- * GcmCalibrateArgyll:is-lcd:
- */
- pspec = g_param_spec_boolean ("is-lcd", NULL, NULL,
- FALSE,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_IS_LCD, pspec);
-
- /**
- * GcmCalibrateArgyll:is-crt:
- */
- pspec = g_param_spec_boolean ("is-crt", NULL, NULL,
- FALSE,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_IS_CRT, pspec);
-
- /**
- * GcmCalibrateArgyll:output-name:
- */
- pspec = g_param_spec_string ("output-name", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_OUTPUT_NAME, pspec);
-
- /**
- * GcmCalibrateArgyll:filename-source:
- */
- pspec = g_param_spec_string ("filename-source", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_FILENAME_SOURCE, pspec);
-
- /**
- * GcmCalibrateArgyll:filename-reference:
- */
- pspec = g_param_spec_string ("filename-reference", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_FILENAME_REFERENCE, pspec);
-
- /**
- * GcmCalibrateArgyll:filename-result:
- */
- pspec = g_param_spec_string ("filename-result", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_FILENAME_RESULT, pspec);
-
- /**
- * GcmCalibrateArgyll:basename:
- */
- pspec = g_param_spec_string ("basename", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_BASENAME, pspec);
-
- /**
- * GcmCalibrateArgyll:model:
- */
- pspec = g_param_spec_string ("model", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_MODEL, pspec);
-
- /**
- * GcmCalibrateArgyll:description:
- */
- pspec = g_param_spec_string ("description", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_DESCRIPTION, pspec);
-
- /**
- * GcmCalibrateArgyll:manufacturer:
- */
- pspec = g_param_spec_string ("manufacturer", NULL, NULL,
- NULL,
- G_PARAM_READWRITE);
- g_object_class_install_property (object_class, PROP_MANUFACTURER, pspec);
+ /* setup klass links */
+ parent_class->calibrate_display = gcm_calibrate_argyll_display;
+ parent_class->calibrate_device = gcm_calibrate_argyll_device;
g_type_class_add_private (klass, sizeof (GcmCalibrateArgyllPrivate));
}
@@ -1437,14 +1170,6 @@ gcm_calibrate_argyll_init (GcmCalibrateArgyll *calibrate_argyll)
GtkWidget *main_window;
calibrate_argyll->priv = GCM_CALIBRATE_ARGYLL_GET_PRIVATE (calibrate_argyll);
- calibrate_argyll->priv->output_name = NULL;
- calibrate_argyll->priv->filename_source = NULL;
- calibrate_argyll->priv->filename_reference = NULL;
- calibrate_argyll->priv->filename_result = NULL;
- calibrate_argyll->priv->basename = NULL;
- calibrate_argyll->priv->manufacturer = NULL;
- calibrate_argyll->priv->model = NULL;
- calibrate_argyll->priv->description = NULL;
calibrate_argyll->priv->child_pid = -1;
calibrate_argyll->priv->loop = g_main_loop_new (NULL, FALSE);
@@ -1510,14 +1235,6 @@ gcm_calibrate_argyll_finalize (GObject *object)
widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "dialog_calibrate"));
gtk_widget_hide (widget);
- g_free (priv->filename_source);
- g_free (priv->filename_reference);
- g_free (priv->filename_result);
- 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);
gnome_rr_screen_destroy (priv->rr_screen);
diff --git a/src/gcm-calibrate-argyll.h b/src/gcm-calibrate-argyll.h
index 7d22517..42f0015 100644
--- a/src/gcm-calibrate-argyll.h
+++ b/src/gcm-calibrate-argyll.h
@@ -23,6 +23,9 @@
#define __GCM_CALIBRATE_ARGYLL_H
#include <glib-object.h>
+#include <gtk/gtk.h>
+
+#include "gcm-calibrate.h"
G_BEGIN_DECLS
@@ -39,13 +42,13 @@ typedef struct _GcmCalibrateArgyllClass GcmCalibrateArgyllClass;
struct _GcmCalibrateArgyll
{
- GObject parent;
+ GcmCalibrate parent;
GcmCalibrateArgyllPrivate *priv;
};
struct _GcmCalibrateArgyllClass
{
- GObjectClass parent_class;
+ GcmCalibrateClass parent_class;
/* padding for future expansion */
void (*_gcm_reserved1) (void);
void (*_gcm_reserved2) (void);
@@ -56,12 +59,6 @@ struct _GcmCalibrateArgyllClass
GType gcm_calibrate_argyll_get_type (void);
GcmCalibrateArgyll *gcm_calibrate_argyll_new (void);
-gboolean gcm_calibrate_argyll_display (GcmCalibrateArgyll *calibrate_argyll,
- GtkWindow *window,
- GError **error);
-gboolean gcm_calibrate_argyll_device (GcmCalibrateArgyll *calibrate_argyll,
- GtkWindow *window,
- GError **error);
G_END_DECLS
diff --git a/src/gcm-calibrate-manual.c b/src/gcm-calibrate-manual.c
index 635d553..304264c 100644
--- a/src/gcm-calibrate-manual.c
+++ b/src/gcm-calibrate-manual.c
@@ -82,7 +82,7 @@ enum {
GCM_CALIBRATE_MANUAL_PAGE_LAST
};
-G_DEFINE_TYPE (GcmCalibrateManual, gcm_calibrate_manual, G_TYPE_OBJECT)
+G_DEFINE_TYPE (GcmCalibrateManual, gcm_calibrate_manual, GCM_TYPE_CALIBRATE)
/**
@@ -433,12 +433,12 @@ gcm_calibrate_manual_apply_cb (GtkWidget *widget, GcmCalibrateManual *calibrate)
/**
* gcm_calibrate_manual_display:
**/
-gboolean
-gcm_calibrate_manual_display (GcmCalibrateManual *calibrate, GtkWindow *window, GError **error)
+static gboolean
+gcm_calibrate_manual_display (GcmCalibrate *calibrate_, GtkWindow *window, GError **error)
{
GtkWidget *widget;
guint i;
-
+ GcmCalibrateManual *calibrate = GCM_CALIBRATE_MANUAL(calibrate_);
GcmCalibrateManualPrivate *priv = calibrate->priv;
egg_debug ("calibrate_display in %i steps", priv->calibration_steps);
@@ -520,10 +520,14 @@ gcm_calibrate_manual_class_init (GcmCalibrateManualClass *klass)
{
GParamSpec *pspec;
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GcmCalibrateClass *parent_class = GCM_CALIBRATE_CLASS (klass);
object_class->finalize = gcm_calibrate_manual_finalize;
object_class->get_property = gcm_calibrate_manual_get_property;
object_class->set_property = gcm_calibrate_manual_set_property;
+ /* setup klass links */
+ parent_class->calibrate_display = gcm_calibrate_manual_display;
+
/**
* GcmCalibrateManual:calibration-steps:
*/
@@ -678,10 +682,18 @@ gcm_calibrate_manual_test (EggTest *test)
calibrate = gcm_calibrate_manual_new ();
egg_test_assert (test, calibrate != NULL);
+ /* set to avoid a critical warning */
+ g_object_set (calibrate,
+ "output-name", "lvds1",
+ NULL);
+
/************************************************************/
egg_test_title (test, "calibrate display manually");
- ret = gcm_calibrate_manual_display (calibrate, NULL, &error);
- egg_test_assert (test, ret);
+ ret = gcm_calibrate_display (GCM_CALIBRATE(calibrate), NULL, &error);
+ if (ret)
+ egg_test_success (test, NULL);
+ else
+ egg_test_failed (test, "error: %s", error->message);
g_object_unref (calibrate);
diff --git a/src/gcm-calibrate-manual.h b/src/gcm-calibrate-manual.h
index f713bc2..542a3eb 100644
--- a/src/gcm-calibrate-manual.h
+++ b/src/gcm-calibrate-manual.h
@@ -25,6 +25,8 @@
#include <glib-object.h>
#include <gtk/gtk.h>
+#include "gcm-calibrate.h"
+
G_BEGIN_DECLS
#define GCM_TYPE_CALIBRATE_MANUAL (gcm_calibrate_manual_get_type ())
@@ -40,13 +42,13 @@ typedef struct _GcmCalibrateManualClass GcmCalibrateManualClass;
struct _GcmCalibrateManual
{
- GObject parent;
+ GcmCalibrate parent;
GcmCalibrateManualPrivate *priv;
};
struct _GcmCalibrateManualClass
{
- GObjectClass parent_class;
+ GcmCalibrateClass parent_class;
/* padding for future expansion */
void (*_gcm_reserved1) (void);
void (*_gcm_reserved2) (void);
@@ -57,9 +59,6 @@ struct _GcmCalibrateManualClass
GType gcm_calibrate_manual_get_type (void);
GcmCalibrateManual *gcm_calibrate_manual_new (void);
-gboolean gcm_calibrate_manual_display (GcmCalibrateManual *calibrate,
- GtkWindow *window,
- GError **error);
G_END_DECLS
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
new file mode 100644
index 0000000..1c4129f
--- /dev/null
+++ b/src/gcm-calibrate.c
@@ -0,0 +1,523 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:gcm-calibrate
+ * @short_description: Calibration object
+ *
+ * This object allows calibration functionality using CMS.
+ */
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <gtk/gtk.h>
+
+#include "gcm-calibrate.h"
+#include "gcm-utils.h"
+#include "gcm-brightness.h"
+
+#include "egg-debug.h"
+
+static void gcm_calibrate_finalize (GObject *object);
+
+#define GCM_CALIBRATE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GCM_TYPE_CALIBRATE, GcmCalibratePrivate))
+
+/**
+ * GcmCalibratePrivate:
+ *
+ * Private #GcmCalibrate data
+ **/
+struct _GcmCalibratePrivate
+{
+ gboolean is_lcd;
+ gboolean is_crt;
+ gchar *output_name;
+ gchar *filename_source;
+ gchar *filename_reference;
+ gchar *filename_result;
+ gchar *basename;
+ gchar *manufacturer;
+ gchar *model;
+ gchar *description;
+};
+
+enum {
+ PROP_0,
+ PROP_BASENAME,
+ PROP_MODEL,
+ PROP_DESCRIPTION,
+ PROP_MANUFACTURER,
+ PROP_IS_LCD,
+ PROP_IS_CRT,
+ PROP_OUTPUT_NAME,
+ PROP_FILENAME_SOURCE,
+ PROP_FILENAME_REFERENCE,
+ PROP_FILENAME_RESULT,
+ PROP_LAST
+};
+
+G_DEFINE_TYPE (GcmCalibrate, gcm_calibrate, G_TYPE_OBJECT)
+
+/**
+ * gcm_calibrate_display:
+ **/
+gboolean
+gcm_calibrate_display (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
+{
+ GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
+ gboolean ret = TRUE;
+ GtkWidget *dialog;
+ GtkResponseType response;
+ GString *string = NULL;
+ GcmBrightness *brightness = NULL;
+ guint percentage = G_MAXUINT;
+ GError *error_tmp = NULL;
+ GcmCalibratePrivate *priv = calibrate->priv;
+
+ /* coldplug source */
+ if (priv->output_name == NULL) {
+ ret = FALSE;
+ if (error != NULL)
+ *error = g_error_new (1, 0, "no output name set");
+ goto out;
+ }
+
+ /* coldplug source */
+ if (klass->calibrate_display == NULL) {
+ ret = FALSE;
+ if (error != NULL)
+ *error = g_error_new (1, 0, "no support");
+ goto out;
+ }
+
+ /* this wasn't previously set */
+ if (!priv->is_lcd && !priv->is_crt) {
+ dialog = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CANCEL,
+ /* TRANSLATORS: title, usually we can tell based on the EDID data or output name */
+ _("Could not auto-detect CRT or LCD"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+ /* TRANSLATORS: dialog message */
+ _("Please indicate if the screen you are trying to profile is a CRT (old type) or a LCD (digital flat panel)."));
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
+ /* TRANSLATORS: button, Liquid Crystal Display */
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("LCD"), GTK_RESPONSE_YES);
+ /* TRANSLATORS: button, Cathode Ray Tube */
+ gtk_dialog_add_button (GTK_DIALOG (dialog), _("CRT"), GTK_RESPONSE_NO);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ if (response == GTK_RESPONSE_YES) {
+ g_object_set (calibrate,
+ "is-lcd", TRUE,
+ NULL);
+ } else if (response == GTK_RESPONSE_NO) {
+ g_object_set (calibrate,
+ "is-crt", TRUE,
+ NULL);
+ } else {
+ if (error != NULL)
+ *error = g_error_new (1, 0, "user did not choose crt or lcd");
+ ret = FALSE;
+ goto out;
+ }
+ }
+
+ /* show a warning for external monitors */
+ ret = gcm_utils_output_is_lcd_internal (priv->output_name);
+ if (!ret) {
+ string = g_string_new ("");
+
+ /* TRANSLATORS: dialog message, preface */
+ g_string_append_printf (string, "%s\n", _("Before calibrating the display, it is recommended to configure your display with the following settings to get optimal results."));
+
+ /* TRANSLATORS: dialog message, preface */
+ g_string_append_printf (string, "%s\n\n", _("You may want to consult the owner's manual for your display on how to achieve these settings."));
+
+ /* TRANSLATORS: dialog message, bullet item */
+ g_string_append_printf (string, "â?¢ %s\n", _("Reset your display to the factory defaults."));
+
+ /* TRANSLATORS: dialog message, bullet item */
+ g_string_append_printf (string, "â?¢ %s\n", _("Disable dynamic contrast if your display has this feature."));
+
+ /* TRANSLATORS: dialog message, bullet item */
+ g_string_append_printf (string, "â?¢ %s", _("Configure your display with custom color settings and ensure the RGB channels are set to the same values."));
+
+ /* TRANSLATORS: dialog message, addition to bullet item */
+ g_string_append_printf (string, " %s\n", _("If custom color is not available then use a 6500K color temperature."));
+
+ /* TRANSLATORS: dialog message, bullet item */
+ g_string_append_printf (string, "â?¢ %s\n", _("Adjust the display brightness to a comfortable level for prolonged viewing."));
+
+ /* TRANSLATORS: dialog message, suffix */
+ g_string_append_printf (string, "\n%s\n", _("For best results, the display should have been powered for at least 15 minutes before starting the calibration."));
+
+
+ dialog = gtk_message_dialog_new (window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, GTK_BUTTONS_OK_CANCEL,
+ /* TRANSLATORS: window title */
+ _("Display setup"));
+ gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", string->str);
+ gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
+ response = gtk_dialog_run (GTK_DIALOG (dialog));
+ gtk_widget_destroy (dialog);
+ if (response != GTK_RESPONSE_OK) {
+ if (error != NULL)
+ *error = g_error_new (1, 0, "user did not follow calibration steps");
+ ret = FALSE;
+ goto out;
+ }
+ }
+
+ /* create new helper objects */
+ brightness = gcm_brightness_new ();
+
+ /* if we are an internal LCD, we need to set the brightness to maximum */
+ ret = gcm_utils_output_is_lcd_internal (priv->output_name);
+ if (ret) {
+ /* get the old brightness so we can restore state */
+ ret = gcm_brightness_get_percentage (brightness, &percentage, &error_tmp);
+ if (!ret) {
+ egg_warning ("failed to get brightness: %s", error_tmp->message);
+ g_error_free (error_tmp);
+ /* not fatal */
+ error_tmp = NULL;
+ }
+
+ /* set the new brightness */
+ ret = gcm_brightness_set_percentage (brightness, 100, &error_tmp);
+ if (!ret) {
+ egg_warning ("failed to set brightness: %s", error_tmp->message);
+ g_error_free (error_tmp);
+ /* not fatal */
+ error_tmp = NULL;
+ }
+ }
+
+ /* proxy */
+ ret = klass->calibrate_display (calibrate, window, error);
+out:
+ /* restore brightness */
+ if (percentage != G_MAXUINT) {
+ /* set the new brightness */
+ ret = gcm_brightness_set_percentage (brightness, percentage, &error_tmp);
+ if (!ret) {
+ egg_warning ("failed to restore brightness: %s", error_tmp->message);
+ g_error_free (error_tmp);
+ /* not fatal */
+ error = NULL;
+ }
+ }
+
+ if (brightness != NULL)
+ g_object_unref (brightness);
+ if (string != NULL)
+ g_string_free (string, TRUE);
+ return ret;
+}
+
+/**
+ * gcm_calibrate_device:
+ **/
+gboolean
+gcm_calibrate_device (GcmCalibrate *calibrate, GtkWindow *window, GError **error)
+{
+ gboolean ret = FALSE;
+ GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
+
+ /* coldplug source */
+ if (klass->calibrate_device == NULL) {
+ if (error != NULL)
+ *error = g_error_new (1, 0, "no support");
+ goto out;
+ }
+
+ /* proxy */
+ ret = klass->calibrate_device (calibrate, window, error);
+out:
+ return ret;
+}
+
+/**
+ * gcm_calibrate_get_property:
+ **/
+static void
+gcm_calibrate_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
+{
+ GcmCalibrate *calibrate = GCM_CALIBRATE (object);
+ GcmCalibratePrivate *priv = calibrate->priv;
+
+ switch (prop_id) {
+ case PROP_IS_LCD:
+ g_value_set_boolean (value, priv->is_lcd);
+ break;
+ case PROP_IS_CRT:
+ g_value_set_boolean (value, priv->is_crt);
+ break;
+ case PROP_OUTPUT_NAME:
+ g_value_set_string (value, priv->output_name);
+ break;
+ case PROP_FILENAME_SOURCE:
+ g_value_set_string (value, priv->filename_source);
+ break;
+ case PROP_FILENAME_REFERENCE:
+ g_value_set_string (value, priv->filename_reference);
+ break;
+ case PROP_FILENAME_RESULT:
+ g_value_set_string (value, priv->filename_result);
+ 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;
+ }
+}
+
+/**
+ * gcm_calibrate_guess_type:
+ **/
+static void
+gcm_calibrate_guess_type (GcmCalibrate *calibrate)
+{
+ gboolean ret;
+ GcmCalibratePrivate *priv = calibrate->priv;
+
+ /* guess based on the output name */
+ ret = gcm_utils_output_is_lcd (priv->output_name);
+ if (ret) {
+ priv->is_lcd = TRUE;
+ priv->is_crt = FALSE;
+ } else {
+ priv->is_lcd = FALSE;
+ priv->is_crt = FALSE;
+ }
+}
+
+/**
+ * gcm_calibrate_set_property:
+ **/
+static void
+gcm_calibrate_set_property (GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
+{
+ GcmCalibrate *calibrate = GCM_CALIBRATE (object);
+ GcmCalibratePrivate *priv = calibrate->priv;
+
+ switch (prop_id) {
+ case PROP_IS_LCD:
+ priv->is_lcd = g_value_get_boolean (value);
+ break;
+ case PROP_IS_CRT:
+ priv->is_crt = g_value_get_boolean (value);
+ break;
+ case PROP_OUTPUT_NAME:
+ g_free (priv->output_name);
+ priv->output_name = g_strdup (g_value_get_string (value));
+ gcm_calibrate_guess_type (calibrate);
+ break;
+ case PROP_FILENAME_SOURCE:
+ g_free (priv->filename_source);
+ priv->filename_source = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_FILENAME_REFERENCE:
+ g_free (priv->filename_reference);
+ priv->filename_reference = g_strdup (g_value_get_string (value));
+ break;
+ case PROP_FILENAME_RESULT:
+ g_free (priv->filename_result);
+ priv->filename_result = 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;
+ }
+}
+
+/**
+ * gcm_calibrate_class_init:
+ **/
+static void
+gcm_calibrate_class_init (GcmCalibrateClass *klass)
+{
+ GParamSpec *pspec;
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ object_class->finalize = gcm_calibrate_finalize;
+ object_class->get_property = gcm_calibrate_get_property;
+ object_class->set_property = gcm_calibrate_set_property;
+
+ /**
+ * GcmCalibrate:is-lcd:
+ */
+ pspec = g_param_spec_boolean ("is-lcd", NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_IS_LCD, pspec);
+
+ /**
+ * GcmCalibrate:is-crt:
+ */
+ pspec = g_param_spec_boolean ("is-crt", NULL, NULL,
+ FALSE,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_IS_CRT, pspec);
+
+ /**
+ * GcmCalibrate:output-name:
+ */
+ pspec = g_param_spec_string ("output-name", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_OUTPUT_NAME, pspec);
+
+ /**
+ * GcmCalibrate:filename-source:
+ */
+ pspec = g_param_spec_string ("filename-source", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_FILENAME_SOURCE, pspec);
+
+ /**
+ * GcmCalibrate:filename-reference:
+ */
+ pspec = g_param_spec_string ("filename-reference", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_FILENAME_REFERENCE, pspec);
+
+ /**
+ * GcmCalibrate:filename-result:
+ */
+ pspec = g_param_spec_string ("filename-result", NULL, NULL,
+ NULL,
+ G_PARAM_READWRITE);
+ g_object_class_install_property (object_class, PROP_FILENAME_RESULT, 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));
+}
+
+/**
+ * gcm_calibrate_init:
+ **/
+static void
+gcm_calibrate_init (GcmCalibrate *calibrate)
+{
+ calibrate->priv = GCM_CALIBRATE_GET_PRIVATE (calibrate);
+ calibrate->priv->output_name = NULL;
+ calibrate->priv->filename_source = NULL;
+ calibrate->priv->filename_reference = NULL;
+ calibrate->priv->filename_result = NULL;
+ calibrate->priv->basename = NULL;
+ calibrate->priv->manufacturer = NULL;
+ calibrate->priv->model = NULL;
+ calibrate->priv->description = NULL;
+}
+
+/**
+ * gcm_calibrate_finalize:
+ **/
+static void
+gcm_calibrate_finalize (GObject *object)
+{
+ GcmCalibrate *calibrate = GCM_CALIBRATE (object);
+ GcmCalibratePrivate *priv = calibrate->priv;
+
+ g_free (priv->filename_source);
+ g_free (priv->filename_reference);
+ g_free (priv->filename_result);
+ g_free (priv->output_name);
+ g_free (priv->basename);
+ g_free (priv->manufacturer);
+ g_free (priv->model);
+ g_free (priv->description);
+
+ G_OBJECT_CLASS (gcm_calibrate_parent_class)->finalize (object);
+}
+
+/**
+ * gcm_calibrate_new:
+ *
+ * Return value: a new GcmCalibrate object.
+ **/
+GcmCalibrate *
+gcm_calibrate_new (void)
+{
+ GcmCalibrate *calibrate;
+ calibrate = g_object_new (GCM_TYPE_CALIBRATE, NULL);
+ return GCM_CALIBRATE (calibrate);
+}
+
diff --git a/src/gcm-calibrate.h b/src/gcm-calibrate.h
new file mode 100644
index 0000000..fe72f69
--- /dev/null
+++ b/src/gcm-calibrate.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2009 Richard Hughes <richard hughsie com>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more calibrate.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GCM_CALIBRATE_H
+#define __GCM_CALIBRATE_H
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GCM_TYPE_CALIBRATE (gcm_calibrate_get_type ())
+#define GCM_CALIBRATE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GCM_TYPE_CALIBRATE, GcmCalibrate))
+#define GCM_CALIBRATE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), GCM_TYPE_CALIBRATE, GcmCalibrateClass))
+#define GCM_IS_CALIBRATE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GCM_TYPE_CALIBRATE))
+#define GCM_IS_CALIBRATE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GCM_TYPE_CALIBRATE))
+#define GCM_CALIBRATE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GCM_TYPE_CALIBRATE, GcmCalibrateClass))
+
+typedef struct _GcmCalibratePrivate GcmCalibratePrivate;
+typedef struct _GcmCalibrate GcmCalibrate;
+typedef struct _GcmCalibrateClass GcmCalibrateClass;
+
+struct _GcmCalibrate
+{
+ GObject parent;
+ GcmCalibratePrivate *priv;
+};
+
+struct _GcmCalibrateClass
+{
+ GObjectClass parent_class;
+ /* vtable */
+ gboolean (*calibrate_display) (GcmCalibrate *calibrate,
+ GtkWindow *window,
+ GError **error);
+ gboolean (*calibrate_device) (GcmCalibrate *calibrate,
+ GtkWindow *window,
+ GError **error);
+ /* padding for future expansion */
+ void (*_gcm_reserved1) (void);
+ void (*_gcm_reserved2) (void);
+ void (*_gcm_reserved3) (void);
+ void (*_gcm_reserved4) (void);
+ void (*_gcm_reserved5) (void);
+};
+
+GType gcm_calibrate_get_type (void);
+GcmCalibrate *gcm_calibrate_new (void);
+gboolean gcm_calibrate_display (GcmCalibrate *calibrate,
+ GtkWindow *window,
+ GError **error);
+gboolean gcm_calibrate_device (GcmCalibrate *calibrate,
+ GtkWindow *window,
+ GError **error);
+
+G_END_DECLS
+
+#endif /* __GCM_CALIBRATE_H */
+
diff --git a/src/gcm-prefs.c b/src/gcm-prefs.c
index d7a5094..c641a36 100644
--- a/src/gcm-prefs.c
+++ b/src/gcm-prefs.c
@@ -178,9 +178,10 @@ gcm_prefs_calibrate_get_basename (GcmDevice *device)
* gcm_prefs_calibrate_display:
**/
static gboolean
-gcm_prefs_calibrate_display (GcmCalibrateArgyll *calibrate)
+gcm_prefs_calibrate_display (GcmCalibrate *calibrate)
{
gboolean ret = FALSE;
+ gboolean ret_tmp;
GError *error = NULL;
gchar *output_name = NULL;
gchar *basename = NULL;
@@ -229,21 +230,21 @@ gcm_prefs_calibrate_display (GcmCalibrateArgyll *calibrate)
/* run each task in order */
window = GTK_WINDOW(gtk_builder_get_object (builder, "dialog_prefs"));
- ret = gcm_calibrate_argyll_display (calibrate, window, &error);
+ ret = gcm_calibrate_display (calibrate, window, &error);
if (!ret) {
egg_warning ("failed to calibrate: %s", error->message);
g_error_free (error);
+ goto out;
}
-
+out:
/* need to set the gamma back to the default after calibration */
error = NULL;
- ret = gcm_utils_set_gamma_for_device (current_device, &error);
- if (!ret) {
+ ret_tmp = gcm_utils_set_gamma_for_device (current_device, &error);
+ if (!ret_tmp) {
egg_warning ("failed to set output gamma: %s", error->message);
g_error_free (error);
}
-out:
g_free (output_name);
g_free (basename);
g_free (manufacturer);
@@ -342,7 +343,7 @@ gcm_prefs_calibrate_device_get_reference_data (const gchar *directory)
* gcm_prefs_calibrate_device:
**/
static gboolean
-gcm_prefs_calibrate_device (GcmCalibrateArgyll *calibrate)
+gcm_prefs_calibrate_device (GcmCalibrate *calibrate)
{
gboolean ret = FALSE;
gboolean has_shared_targets;
@@ -437,7 +438,7 @@ gcm_prefs_calibrate_device (GcmCalibrateArgyll *calibrate)
NULL);
/* do each step */
- ret = gcm_calibrate_argyll_device (calibrate, window, &error);
+ ret = gcm_calibrate_device (calibrate, window, &error);
if (!ret) {
egg_warning ("failed to calibrate: %s", error->message);
g_error_free (error);
@@ -779,7 +780,7 @@ out:
static void
gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
{
- GcmCalibrateArgyll *calibrate = NULL;
+ GcmCalibrate *calibrate = NULL;
GcmDeviceType type;
gboolean ret;
GError *error = NULL;
@@ -801,7 +802,7 @@ gcm_prefs_calibrate_cb (GtkWidget *widget, gpointer data)
NULL);
/* create new calibration object */
- calibrate = gcm_calibrate_argyll_new ();
+ calibrate = GCM_CALIBRATE(gcm_calibrate_argyll_new ());
/* choose the correct type of calibration */
switch (type) {
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 9ee1e5e..8951ebc 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -96,6 +96,7 @@ out:
gboolean
gcm_utils_output_is_lcd_internal (const gchar *output_name)
{
+ g_return_val_if_fail (output_name != NULL, FALSE);
if (g_strstr_len (output_name, -1, "LVDS") != NULL)
return TRUE;
if (g_strstr_len (output_name, -1, "lvds") != NULL)
@@ -112,6 +113,7 @@ gcm_utils_output_is_lcd_internal (const gchar *output_name)
gboolean
gcm_utils_output_is_lcd (const gchar *output_name)
{
+ g_return_val_if_fail (output_name != NULL, FALSE);
if (gcm_utils_output_is_lcd_internal (output_name))
return TRUE;
if (g_strstr_len (output_name, -1, "DVI") != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]