[gnome-color-manager] Move the brightness and inhibit functionality to the calibration module
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Move the brightness and inhibit functionality to the calibration module
- Date: Mon, 28 Nov 2011 21:34:48 +0000 (UTC)
commit 40291d7a8a311ec6f4b3d23c5fca586d3ee600ce
Author: Richard Hughes <richard hughsie com>
Date: Mon Nov 28 15:51:17 2011 +0000
Move the brightness and inhibit functionality to the calibration module
src/Makefile.am | 2 +
src/gcm-calibrate-main.c | 95 +-----------------------------------------
src/gcm-calibrate.c | 104 +++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 106 insertions(+), 95 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index c657204..31d48e6 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -134,6 +134,8 @@ gcm_calibrate_helper_SOURCES = \
gcm-utils.h \
gcm-exif.c \
gcm-exif.h \
+ gcm-brightness.c \
+ gcm-brightness.h \
gcm-calibrate.c \
gcm-calibrate.h \
gcm-sample-window.c \
diff --git a/src/gcm-calibrate-main.c b/src/gcm-calibrate-main.c
index 513fe04..0df92d5 100644
--- a/src/gcm-calibrate-main.c
+++ b/src/gcm-calibrate-main.c
@@ -33,7 +33,6 @@
#include "gcm-utils.h"
#include "gcm-debug.h"
-#include "gcm-brightness.h"
#include "gcm-calibrate.h"
#include "gcm-calibrate-argyll.h"
@@ -66,8 +65,6 @@ typedef struct {
guint xid;
GtkWindow *main_window;
GPtrArray *pages;
- GcmBrightness *brightness;
- guint old_brightness;
gboolean internal_lcd;
GtkWidget *reference_preview;
GtkWidget *action_title;
@@ -194,89 +191,6 @@ gcm_calib_assistant_close_cb (GtkAssistant *assistant, GcmCalibratePriv *calib)
}
/**
- * gcm_calib_device_inihibit:
- **/
-static void
-gcm_calib_device_inihibit (GcmCalibratePriv *calib)
-{
- gboolean ret;
- GError *error = NULL;
-
- /* invalid */
- if (calib->device == NULL)
- return;
-
- /* mark device to be profiled in colord */
- ret = cd_device_profiling_inhibit_sync (calib->device,
- calib->cancellable,
- &error);
- if (!ret) {
- g_warning ("failed to inhibit device: %s",
- error->message);
- g_clear_error (&error);
- }
-
- /* set the brightness to max */
- if (calib->device_kind == CD_DEVICE_KIND_DISPLAY &&
- calib->internal_lcd) {
- ret = gcm_brightness_get_percentage (calib->brightness,
- &calib->old_brightness,
- &error);
- if (!ret) {
- g_warning ("failed to get brightness: %s",
- error->message);
- g_clear_error (&error);
- }
- ret = gcm_brightness_set_percentage (calib->brightness,
- 100,
- &error);
- if (!ret) {
- g_warning ("failed to set brightness: %s",
- error->message);
- g_error_free (error);
- }
- }
-}
-
-/**
- * gcm_calib_device_uninihibit:
- **/
-static void
-gcm_calib_device_uninihibit (GcmCalibratePriv *calib)
-{
- gboolean ret;
- GError *error = NULL;
-
- /* invalid */
- if (calib->device == NULL)
- return;
-
- /* mark device to be profiled in colord */
- ret = cd_device_profiling_uninhibit_sync (calib->device,
- calib->cancellable,
- &error);
- if (!ret) {
- g_warning ("failed to uninhibit device: %s",
- error->message);
- g_clear_error (&error);
- }
-
- /* reset the brightness to what it was before */
- if (calib->device_kind == CD_DEVICE_KIND_DISPLAY &&
- calib->old_brightness != G_MAXUINT &&
- calib->internal_lcd) {
- ret = gcm_brightness_set_percentage (calib->brightness,
- calib->old_brightness,
- &error);
- if (!ret) {
- g_warning ("failed to set brightness: %s",
- error->message);
- g_error_free (error);
- }
- }
-}
-
-/**
* gcm_calib_play_sound:
**/
static void
@@ -551,15 +465,12 @@ gcm_calib_assistant_prepare_cb (GtkAssistant *assistant,
"GcmCalibrateMain::Index"));
switch (calib->current_page) {
case GCM_CALIBRATE_PAGE_LAST:
- gcm_calib_device_uninihibit (calib);
gcm_calib_play_sound (calib);
break;
case GCM_CALIBRATE_PAGE_ACTION:
g_debug ("lights! camera! action!");
- if (!calib->started_calibration) {
- gcm_calib_device_inihibit (calib);
+ if (!calib->started_calibration)
g_idle_add (gcm_calib_start_idle_cb, calib);
- }
break;
default:
break;
@@ -570,7 +481,6 @@ gcm_calib_assistant_prepare_cb (GtkAssistant *assistant,
calib->started_calibration) {
gcm_calibrate_interaction (calib->calibrate,
GTK_RESPONSE_CANCEL);
- gcm_calib_device_uninihibit (calib);
calib->started_calibration = FALSE;
}
@@ -2159,8 +2069,6 @@ main (int argc, char **argv)
calib->pages = g_ptr_array_new ();
calib->xid = xid;
calib->device_id = device_id;
- calib->old_brightness = G_MAXUINT;
- calib->brightness = gcm_brightness_new ();
calib->calibrate = gcm_calibrate_argyll_new ();
g_object_set (calib->calibrate,
"precision", GCM_CALIBRATE_PRECISION_LONG,
@@ -2195,7 +2103,6 @@ main (int argc, char **argv)
g_ptr_array_unref (calib->pages);
g_object_unref (calib->application);
- g_object_unref (calib->brightness);
g_object_unref (calib->calibrate);
if (calib->client != NULL)
g_object_unref (calib->client);
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index b5ce1cc..337e0ac 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -46,6 +46,7 @@ static void gcm_calibrate_finalize (GObject *object);
**/
struct _GcmCalibratePrivate
{
+ GcmBrightness *brightness;
GcmCalibrateDisplayKind display_kind;
GcmCalibratePrintKind print_kind;
GcmCalibratePrecision precision;
@@ -64,6 +65,7 @@ struct _GcmCalibratePrivate
gchar *serial;
gchar *device;
gchar *working_path;
+ guint old_brightness;
guint target_whitepoint;
GtkWidget *content_widget;
GtkWindow *sample_window;
@@ -434,7 +436,7 @@ gcm_calibrate_display_characterize (GcmCalibrate *calibrate,
GcmCalibratePrivate *priv = calibrate->priv;
/* open ti1 file as input */
- g_debug ("loading %s", ti3_fn);
+ g_debug ("loading %s", ti1_fn);
ret = g_file_get_contents (ti1_fn, &ti1_data, &ti1_size, error);
if (!ret)
goto out;
@@ -594,6 +596,78 @@ out:
}
/**
+ * gcm_calibrate_set_brightness:
+ **/
+static void
+gcm_calibrate_set_brightness (GcmCalibrate *calibrate, CdDevice *device)
+{
+ const gchar *xrandr_name;
+ gboolean ret;
+ GError *error = NULL;
+
+ /* is this a laptop */
+ xrandr_name = cd_device_get_metadata_item (device,
+ CD_DEVICE_METADATA_XRANDR_NAME);
+ if (xrandr_name == NULL)
+ return;
+ ret = gcm_utils_output_is_lcd_internal (xrandr_name);
+ if (!ret)
+ return;
+
+ /* set the brightness to max */
+ ret = gcm_brightness_get_percentage (calibrate->priv->brightness,
+ &calibrate->priv->old_brightness,
+ &error);
+ if (!ret) {
+ g_warning ("failed to get brightness: %s",
+ error->message);
+ g_clear_error (&error);
+ }
+ ret = gcm_brightness_set_percentage (calibrate->priv->brightness,
+ 100,
+ &error);
+ if (!ret) {
+ g_warning ("failed to set brightness: %s",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+/**
+ * gcm_calibrate_unset_brightness:
+ **/
+static void
+gcm_calibrate_unset_brightness (GcmCalibrate *calibrate, CdDevice *device)
+{
+ const gchar *xrandr_name;
+ gboolean ret;
+ GError *error = NULL;
+
+ /* is this a laptop */
+ xrandr_name = cd_device_get_metadata_item (device,
+ CD_DEVICE_METADATA_XRANDR_NAME);
+ if (xrandr_name == NULL)
+ return;
+ ret = gcm_utils_output_is_lcd_internal (xrandr_name);
+ if (!ret)
+ return;
+
+ /* never set */
+ if (calibrate->priv->old_brightness == G_MAXUINT)
+ return;
+
+ /* reset the brightness to what it was before */
+ ret = gcm_brightness_set_percentage (calibrate->priv->brightness,
+ calibrate->priv->old_brightness,
+ &error);
+ if (!ret) {
+ g_warning ("failed to set brightness: %s",
+ error->message);
+ g_error_free (error);
+ }
+}
+
+/**
* gcm_calibrate_display:
**/
static gboolean
@@ -610,6 +684,9 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
GcmCalibrateClass *klass = GCM_CALIBRATE_GET_CLASS (calibrate);
GcmCalibratePrivate *priv = calibrate->priv;
+ /* set brightness */
+ gcm_calibrate_set_brightness (calibrate, device);
+
/* get a ti1 file suitable for the calibration */
ti1_dest_fn = g_strdup_printf ("%s/%s.ti1",
calibrate->priv->working_path,
@@ -661,6 +738,8 @@ gcm_calibrate_display (GcmCalibrate *calibrate,
/* proxy */
ret = klass->calibrate_display (calibrate, device, priv->sensor, window, error);
out:
+ /* unset brightness */
+ gcm_calibrate_unset_brightness (calibrate, device);
g_free (ti1_src_fn);
g_free (ti1_dest_fn);
g_free (ti3_fn);
@@ -1027,6 +1106,13 @@ gcm_calibrate_device (GcmCalibrate *calibrate,
if (!ret)
goto out;
+ /* mark device to be profiled in colord */
+ ret = cd_device_profiling_inhibit_sync (device,
+ NULL,
+ error);
+ if (!ret)
+ goto out;
+
/* set progress */
gcm_calibrate_set_progress (calibrate, 0);
@@ -1036,21 +1122,34 @@ gcm_calibrate_device (GcmCalibrate *calibrate,
device,
window,
error);
+ if (!ret)
+ goto out;
break;
case CD_DEVICE_KIND_PRINTER:
ret = gcm_calibrate_printer (calibrate,
device,
window,
error);
+ if (!ret)
+ goto out;
break;
default:
ret = gcm_calibrate_camera (calibrate,
device,
window,
error);
+ if (!ret)
+ goto out;
break;
}
+ /* device back to normal */
+ ret = cd_device_profiling_uninhibit_sync (device,
+ NULL,
+ error);
+ if (!ret)
+ goto out;
+
/* set progress */
gcm_calibrate_set_progress (calibrate, 100);
out:
@@ -1403,6 +1502,8 @@ gcm_calibrate_init (GcmCalibrate *calibrate)
calibrate->priv->reference_kind = GCM_CALIBRATE_REFERENCE_KIND_UNKNOWN;
calibrate->priv->precision = GCM_CALIBRATE_PRECISION_UNKNOWN;
calibrate->priv->sample_window = gcm_sample_window_new ();
+ calibrate->priv->old_brightness = G_MAXUINT;
+ calibrate->priv->brightness = gcm_brightness_new ();
// FIXME: this has to be per-run specific
calibrate->priv->working_path = g_strdup ("/tmp");
@@ -1433,6 +1534,7 @@ gcm_calibrate_finalize (GObject *object)
g_ptr_array_unref (calibrate->priv->old_title);
g_ptr_array_unref (calibrate->priv->old_message);
gtk_widget_destroy (GTK_WIDGET (calibrate->priv->sample_window));
+ g_object_unref (priv->brightness);
G_OBJECT_CLASS (gcm_calibrate_parent_class)->finalize (object);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]