[gnome-color-manager] Show the ambient level of light in gcm-picker for native sensors



commit 1a2b5d35863364cc4393c47c69d094f9d21ae1d3
Author: Richard Hughes <richard hughsie com>
Date:   Mon Jul 19 13:54:28 2010 +0100

    Show the ambient level of light in gcm-picker for native sensors

 data/gcm-picker.ui                               |   49 ++++++++++++++++++++--
 src/.gitignore                                   |    2 +-
 src/Makefile.am                                  |    4 +-
 src/gcm-picker.c                                 |   25 +++++++++++
 src/{gcm-huey-example.c => gcm-sensor-example.c} |   10 ++++
 5 files changed, 83 insertions(+), 7 deletions(-)
---
diff --git a/data/gcm-picker.ui b/data/gcm-picker.ui
index 6849fed..2f511af 100644
--- a/data/gcm-picker.ui
+++ b/data/gcm-picker.ui
@@ -1,4 +1,4 @@
-<?xml version="1.0"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="2.16"/>
   <!-- interface-naming-policy project-wide -->
@@ -11,13 +11,11 @@
     <child internal-child="vbox">
       <object class="GtkVBox" id="dialog-vbox1">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
         <property name="spacing">2</property>
         <child>
           <object class="GtkVBox" id="vbox1">
             <property name="visible">True</property>
             <property name="border_width">12</property>
-            <property name="orientation">vertical</property>
             <property name="spacing">12</property>
             <child>
               <object class="GtkHBox" id="hbox1">
@@ -61,7 +59,6 @@
                   <object class="GtkVBox" id="vbox2">
                     <property name="visible">True</property>
                     <property name="border_width">9</property>
-                    <property name="orientation">vertical</property>
                     <property name="spacing">6</property>
                     <child>
                       <object class="GtkHBox" id="hbox_xyz">
@@ -275,6 +272,49 @@
                         <property name="position">4</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkHBox" id="hbox_ambient">
+                        <property name="visible">True</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox_ambient_align">
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkLabel" id="label_ambient_title">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes" comments="This shows the error in the conversion to RGB.">Ambient:</property>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">False</property>
+                                <property name="position">0</property>
+                              </packing>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">0</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkLabel" id="label_ambient">
+                            <property name="visible">True</property>
+                            <property name="selectable">True</property>
+                          </object>
+                          <packing>
+                            <property name="expand">False</property>
+                            <property name="fill">False</property>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">5</property>
+                      </packing>
+                    </child>
                   </object>
                 </child>
                 <child type="label">
@@ -351,6 +391,7 @@
       <widget name="hbox_colorspace_align"/>
       <widget name="hbox_rgb_align"/>
       <widget name="hbox_error_align"/>
+      <widget name="hbox_ambient_align"/>
     </widgets>
   </object>
 </interface>
diff --git a/src/.gitignore b/src/.gitignore
index 87580a1..71aeb6f 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -19,4 +19,4 @@ gcm-install-system-wide
 gcm-helper-exiv
 gcm-glsl-demo
 gcm-ddc-util
-gcm-huey-example
+gcm-sensor-example
diff --git a/src/Makefile.am b/src/Makefile.am
index 3483737..3332c0f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -99,7 +99,7 @@ bin_PROGRAMS =						\
 	gcm-picker					\
 	gcm-ddc-util					\
 	gcm-import					\
-	gcm-huey-example
+	gcm-sensor-example
 
 if HAVE_EXIV
 libexec_PROGRAMS = gcm-helper-exiv
@@ -372,7 +372,7 @@ install-data-hook:
 	fi
 
 gcm_huey_example_SOURCES =				\
-	gcm-huey-example.c
+	gcm-sensor-example.c
 
 gcm_huey_example_LDADD =				\
 	$(GLIB_LIBS)					\
diff --git a/src/gcm-picker.c b/src/gcm-picker.c
index 793a4c6..e5e9e15 100644
--- a/src/gcm-picker.c
+++ b/src/gcm-picker.c
@@ -47,6 +47,7 @@ static const gchar *profile_filename = NULL;
 static gboolean done_measure = FALSE;
 static GcmSensor *sensor = NULL;
 static GcmColorXYZ last_sample;
+static gdouble last_ambient = -1.0f;
 
 enum {
 	GCM_PREFS_COMBO_COLUMN_TEXT,
@@ -98,6 +99,7 @@ gcm_picker_refresh_results (void)
 	gchar *text_lab = NULL;
 	gchar *text_rgb = NULL;
 	gchar *text_error = NULL;
+	gchar *text_ambient = NULL;
 	cmsHPROFILE profile_xyz;
 	cmsHPROFILE profile_rgb;
 	cmsHPROFILE profile_lab;
@@ -164,6 +166,16 @@ gcm_picker_refresh_results (void)
 				      ABS ((color_error.Z - color_xyz.Z) / color_xyz.Z * 100));
 	gtk_label_set_label (label, text_error);
 
+	/* set ambient */
+	label = GTK_LABEL (gtk_builder_get_object (builder, "label_ambient"));
+	if (last_ambient < 0) {
+		/* TRANSLATORS: this is when the ambient light level is unknown */
+		gtk_label_set_label (label, _("Unknown"));
+	} else {
+		text_ambient = g_strdup_printf ("%.1f Lux", last_ambient);
+		gtk_label_set_label (label, text_ambient);
+	}
+
 	/* set image */
 	image = GTK_IMAGE (gtk_builder_get_object (builder, "image_preview"));
 	gtk_image_set_from_pixbuf (image, pixbuf);
@@ -172,6 +184,7 @@ gcm_picker_refresh_results (void)
 	g_free (text_lab);
 	g_free (text_rgb);
 	g_free (text_error);
+	g_free (text_ambient);
 	if (pixbuf != NULL)
 		g_object_unref (pixbuf);
 }
@@ -208,6 +221,18 @@ gcm_picker_measure_cb (GtkWidget *widget, gpointer data)
 	gtk_image_set_from_file (GTK_IMAGE (widget), DATADIR "/icons/hicolor/64x64/apps/gnome-color-manager.png");
 
 	if (gcm_sensor_get_is_native (sensor)) {
+
+		/* set mode */
+		gcm_sensor_set_output_type (sensor, GCM_SENSOR_OUTPUT_TYPE_LCD);
+
+		/* get ambient */
+		ret = gcm_sensor_get_ambient (sensor, &last_ambient, &error);
+		if (!ret) {
+			g_warning ("failed to get ambient: %s", error->message);
+			g_error_free (error);
+			goto out;
+		}
+
 		/* sample color */
 		ret = gcm_sensor_sample (sensor, &last_sample, &error);
 		if (!ret) {
diff --git a/src/gcm-huey-example.c b/src/gcm-sensor-example.c
similarity index 93%
rename from src/gcm-huey-example.c
rename to src/gcm-sensor-example.c
index 6f9c859..937932d 100644
--- a/src/gcm-huey-example.c
+++ b/src/gcm-sensor-example.c
@@ -27,6 +27,7 @@
 
 #include <glib.h>
 #include <libcolor-glib.h>
+#include <libusb-1.0/libusb.h>
 
 /**
  * main:
@@ -34,6 +35,7 @@
 int
 main (void)
 {
+#if 0
 	gboolean ret;
 	GError *error = NULL;
 	GcmSensor *sensor;
@@ -68,5 +70,13 @@ main (void)
 out:
 	g_object_unref (sensor);
 	return 0;
+#endif
+
+	/* get device */
+	/* set configuration */
+	/* get ambient */
+	/* close device */
+
+	return 0;
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]