[gnome-color-manager] Add an experimental gcm-picker program to read spot colors



commit b8e9cddb722d1fdfe7dcebc9b8a384abee9751f3
Author: Richard Hughes <richard hughsie com>
Date:   Wed Mar 31 14:48:50 2010 +0100

    Add an experimental gcm-picker program to read spot colors

 data/Makefile.am   |    1 +
 data/gcm-picker.ui |  312 ++++++++++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in     |    2 +
 src/.gitignore     |    1 +
 src/Makefile.am    |   50 ++++++--
 src/gcm-picker.c   |  336 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 691 insertions(+), 11 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 7042d29..1300c8a 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -31,6 +31,7 @@ $(service_DATA): $(service_in_files) Makefile
 pkgdata_DATA =						\
 	gcm-calibrate.ui				\
 	gcm-spawn.ui					\
+	gcm-picker.ui					\
 	gcm-prefs.ui
 
 EXTRA_DIST =						\
diff --git a/data/gcm-picker.ui b/data/gcm-picker.ui
new file mode 100644
index 0000000..eacebfe
--- /dev/null
+++ b/data/gcm-picker.ui
@@ -0,0 +1,312 @@
+<?xml version="1.0"?>
+<interface>
+  <requires lib="gtk+" version="2.16"/>
+  <!-- interface-naming-policy project-wide -->
+  <object class="GtkDialog" id="dialog_picker">
+    <property name="border_width">5</property>
+    <property name="title" translatable="yes">Color Picker</property>
+    <property name="icon_name">gnome-color-manager</property>
+    <property name="type_hint">dialog</property>
+    <property name="has_separator">False</property>
+    <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">
+                <property name="visible">True</property>
+                <property name="spacing">6</property>
+                <child>
+                  <object class="GtkImage" id="image_preview">
+                    <property name="visible">True</property>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkButton" id="button_measure">
+                    <property name="label" translatable="yes">_Measure</property>
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="use_underline">True</property>
+                    <property name="image_position">top</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">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkExpander" id="expander_results">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <child>
+                  <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_lab">
+                        <property name="visible">True</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox_lab_align">
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkLabel" id="label_lab_title">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">LAB:</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_lab">
+                            <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">0</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" id="hbox_xyz">
+                        <property name="visible">True</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox_xyz_align">
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkLabel" id="label_xyz_title">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">XYZ:</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_xyz">
+                            <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">1</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" id="hbox2">
+                        <property name="visible">True</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox_colorspace_align">
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkLabel" id="label_colorspace">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">Colorspace:</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="GtkComboBox" id="combobox_colorspace">
+                            <property name="visible">True</property>
+                          </object>
+                          <packing>
+                            <property name="position">1</property>
+                          </packing>
+                        </child>
+                      </object>
+                      <packing>
+                        <property name="expand">False</property>
+                        <property name="fill">False</property>
+                        <property name="position">2</property>
+                      </packing>
+                    </child>
+                    <child>
+                      <object class="GtkHBox" id="hbox_rgb">
+                        <property name="visible">True</property>
+                        <property name="spacing">12</property>
+                        <child>
+                          <object class="GtkHBox" id="hbox_rgb_align">
+                            <property name="visible">True</property>
+                            <child>
+                              <object class="GtkLabel" id="label_rgb_title">
+                                <property name="visible">True</property>
+                                <property name="label" translatable="yes">RGB:</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_rgb">
+                            <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">3</property>
+                      </packing>
+                    </child>
+                  </object>
+                </child>
+                <child type="label">
+                  <object class="GtkLabel" id="label1">
+                    <property name="visible">True</property>
+                    <property name="label" translatable="yes">Results</property>
+                    <attributes>
+                      <attribute name="weight" value="bold"/>
+                    </attributes>
+                  </object>
+                </child>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child internal-child="action_area">
+          <object class="GtkHButtonBox" id="dialog-action_area1">
+            <property name="visible">True</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button_help">
+                <property name="label">gtk-help</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+                <property name="secondary">True</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button_close">
+                <property name="label">gtk-close</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">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="pack_type">end</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+    <action-widgets>
+      <action-widget response="0">button_help</action-widget>
+      <action-widget response="0">button_close</action-widget>
+    </action-widgets>
+  </object>
+  <object class="GtkSizeGroup" id="sizegroup_titles">
+    <widgets>
+      <widget name="hbox_lab_align"/>
+      <widget name="hbox_xyz_align"/>
+      <widget name="hbox_colorspace_align"/>
+      <widget name="hbox_rgb_align"/>
+    </widgets>
+  </object>
+</interface>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 53f596d..5f40e5c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -17,11 +17,13 @@ src/gcm-fix-profile.c
 src/gcm-import.c
 src/gcm-inspect.c
 src/gcm-install-system-wide.c
+src/gcm-picker.c
 src/gcm-prefs.c
 src/gcm-profile.c
 src/gcm-session.c
 src/gcm-utils.c
 [type: gettext/glade]data/gcm-calibrate.ui
+[type: gettext/glade]data/gcm-picker.ui
 [type: gettext/glade]data/gcm-prefs.ui
 [type: gettext/glade]data/gcm-spawn.ui
 
diff --git a/src/.gitignore b/src/.gitignore
index c431a4c..55d7092 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -5,6 +5,7 @@
 gcm-apply
 gcm-import
 gcm-prefs
+gcm-picker
 gcm-inspect
 gcm-session
 gcm-dump-edid
diff --git a/src/Makefile.am b/src/Makefile.am
index 45ccc62..cc4541e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -78,7 +78,17 @@ libgcmshared_a_SOURCES =				\
 	gcm-profile-lcms1.c				\
 	gcm-profile-lcms1.h				\
 	gcm-profile.c					\
-	gcm-profile.h
+	gcm-profile.h					\
+	gcm-calibrate.c					\
+	gcm-calibrate.h					\
+	gcm-calibrate-argyll.c				\
+	gcm-calibrate-argyll.h				\
+	gcm-calibrate-manual.c				\
+	gcm-calibrate-manual.h				\
+	gcm-calibrate-dialog.c				\
+	gcm-calibrate-dialog.h				\
+	gcm-brightness.c				\
+	gcm-brightness.h
 
 libgcmshared_a_CFLAGS =					\
 	$(WARNINGFLAGS_C)
@@ -96,6 +106,9 @@ bin_PROGRAMS =						\
 	gcm-session					\
 	gcm-import
 
+noinst_PROGRAMS = 					\
+	gcm-picker
+
 gcm_install_system_wide_SOURCES =			\
 	gcm-install-system-wide.c
 
@@ -226,16 +239,6 @@ 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				\
-	gcm-calibrate-manual.h				\
-	gcm-calibrate-dialog.c				\
-	gcm-calibrate-dialog.h				\
-	gcm-brightness.c				\
-	gcm-brightness.h				\
 	gcm-prefs.c
 
 gcm_prefs_LDADD =					\
@@ -260,6 +263,31 @@ gcm_prefs_LDADD =					\
 gcm_prefs_CFLAGS =					\
 	$(WARNINGFLAGS_C)
 
+gcm_picker_SOURCES =					\
+	gcm-picker.c
+
+gcm_picker_LDADD =					\
+	libgcmshared.a					\
+	$(GLIB_LIBS)					\
+	$(X11_LIBS)					\
+	$(GNOMEDESKTOP_LIBS)				\
+	$(UNIQUE_LIBS)					\
+	$(GCONF_LIBS)					\
+	$(VTE_LIBS)					\
+	$(GUDEV_LIBS)					\
+	$(LCMS_LIBS)					\
+	$(DBUS_GLIB_LIBS)				\
+	$(XORG_LIBS)					\
+	$(GTK_LIBS)					\
+	$(SANE_LIBS)					\
+	$(CUPS_LIBS)					\
+	$(TIFF_LIBS)					\
+	$(CANBERRA_LIBS)				\
+	-lm
+
+gcm_picker_CFLAGS =					\
+	$(WARNINGFLAGS_C)
+
 gcm_session_SOURCES =					\
 	gcm-dbus.c					\
 	gcm-dbus.h					\
diff --git a/src/gcm-picker.c b/src/gcm-picker.c
new file mode 100644
index 0000000..4d5771f
--- /dev/null
+++ b/src/gcm-picker.c
@@ -0,0 +1,336 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2010 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <glib-object.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+#include <locale.h>
+#include <gtk/gtk.h>
+#include <unique/unique.h>
+
+#include "egg-debug.h"
+
+#include "gcm-colorimeter.h"
+#include "gcm-utils.h"
+
+static GtkBuilder *builder = NULL;
+static GtkWidget *info_bar_hardware = NULL;
+static GtkWidget *info_bar_hardware_label = NULL;
+
+/**
+ * gcm_picker_set_pixbuf_color:
+ **/
+static void
+gcm_picker_set_pixbuf_color (GdkPixbuf *pixbuf, gchar red, gchar green, gchar blue)
+{
+	gint x, y;
+	gint width, height, rowstride, n_channels;
+	guchar *pixels, *p;
+
+	n_channels = gdk_pixbuf_get_n_channels (pixbuf);
+	width = gdk_pixbuf_get_width (pixbuf);
+	height = gdk_pixbuf_get_height (pixbuf);
+	rowstride = gdk_pixbuf_get_rowstride (pixbuf);
+	pixels = gdk_pixbuf_get_pixels (pixbuf);
+
+	/* set to all the correct colors */
+	for (y=0; y<height; y++) {
+		for (x=0; x<width; x++) {
+			p = pixels + y * rowstride + x * n_channels;
+			p[0] = red;
+			p[1] = green;
+			p[2] = blue;
+//			p[3] = alpha;
+		}
+	}
+}
+
+/**
+ * gcm_picker_measure_cb:
+ **/
+static void
+gcm_picker_measure_cb (GtkWidget *widget, gpointer data)
+{
+	GtkImage *image;
+	GtkLabel *label;
+	GdkPixbuf *pixbuf;
+	image = GTK_IMAGE (gtk_builder_get_object (builder, "image_preview"));
+	pixbuf = gtk_image_get_pixbuf (image);
+	if (pixbuf == NULL) {
+		pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, FALSE, 8, 200, 200);
+		gtk_image_set_from_pixbuf (image, pixbuf);
+	}
+
+	gcm_picker_set_pixbuf_color (pixbuf, 254, 128, 0);
+
+	/* set LAB */
+	label = GTK_LABEL (gtk_builder_get_object (builder, "label_lab"));
+	gtk_label_set_label (label, "1, 2, 3");
+
+	/* set XYZ */
+	label = GTK_LABEL (gtk_builder_get_object (builder, "label_xyz"));
+	gtk_label_set_label (label, "1, 2, 3");
+
+	/* set RGB */
+	label = GTK_LABEL (gtk_builder_get_object (builder, "label_rgb"));
+	gtk_label_set_label (label, "1, 2, 3");
+
+	/* set XYZ */
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "expander_results"));
+	gtk_expander_set_expanded (GTK_EXPANDER (widget), TRUE);
+
+}
+
+/**
+ * gcm_picker_close_cb:
+ **/
+static void
+gcm_picker_close_cb (GtkWidget *widget, gpointer data)
+{
+	GMainLoop *loop = (GMainLoop *) data;
+	g_main_loop_quit (loop);
+}
+
+/**
+ * gcm_picker_help_cb:
+ **/
+static void
+gcm_picker_help_cb (GtkWidget *widget, gpointer data)
+{
+	gcm_gnome_help ("picker");
+}
+
+/**
+ * gcm_picker_delete_event_cb:
+ **/
+static gboolean
+gcm_picker_delete_event_cb (GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+	gcm_picker_close_cb (widget, data);
+	return FALSE;
+}
+
+/**
+ * gcm_picker_colorimeter_setup_ui:
+ **/
+static void
+gcm_picker_colorimeter_setup_ui (GcmColorimeter *colorimeter)
+{
+	gboolean present;
+	gboolean supports_spot;
+	gboolean ret;
+	GtkWidget *widget;
+
+	present = gcm_colorimeter_get_present (colorimeter);
+	supports_spot = gcm_colorimeter_supports_spot (colorimeter);
+	ret = (present && supports_spot);
+
+	/* change the label */
+	if (present && !supports_spot) {
+		/* TRANSLATORS: this is displayed the user has not got suitable hardware */
+		gtk_label_set_label (GTK_LABEL (info_bar_hardware_label), _("The attached colorimeter is not capable of reading a spot color."));
+	} else if (!present) {
+		/* TRANSLATORS: this is displayed the user has not got suitable hardware */
+		gtk_label_set_label (GTK_LABEL (info_bar_hardware_label), _("No colorimeter is attached."));
+	}
+
+	/* hide some stuff */
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_measure"));
+	gtk_widget_set_sensitive (widget, ret);
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "expander_results"));
+	gtk_widget_set_sensitive (widget, ret);
+	gtk_widget_set_visible (info_bar_hardware, !ret);
+}
+
+/**
+ * gcm_picker_colorimeter_changed_cb:
+ **/
+static void
+gcm_picker_colorimeter_changed_cb (GcmColorimeter *colorimeter, gpointer user_data)
+{
+	gcm_picker_colorimeter_setup_ui (colorimeter);
+}
+
+/**
+ * gcm_picker_message_received_cb
+ **/
+static UniqueResponse
+gcm_picker_message_received_cb (UniqueApp *app, UniqueCommand command, UniqueMessageData *message_data, guint time_ms, gpointer data)
+{
+	GtkWindow *window;
+	if (command == UNIQUE_ACTIVATE) {
+		window = GTK_WINDOW (gtk_builder_get_object (builder, "dialog_picker"));
+		gtk_window_present (window);
+	}
+	return UNIQUE_RESPONSE_OK;
+}
+
+/**
+ * gcm_window_set_parent_xid:
+ **/
+static void
+gcm_window_set_parent_xid (GtkWindow *window, guint32 xid)
+{
+	GdkDisplay *display;
+	GdkWindow *parent_window;
+	GdkWindow *our_window;
+
+	display = gdk_display_get_default ();
+	parent_window = gdk_window_foreign_new_for_display (display, xid);
+	our_window = gtk_widget_get_window (GTK_WIDGET (window));
+
+	/* set this above our parent */
+	gtk_window_set_modal (window, TRUE);
+	gdk_window_set_transient_for (our_window, parent_window);
+}
+
+/**
+ * main:
+ **/
+int
+main (int argc, char *argv[])
+{
+	GOptionContext *context;
+	guint retval = 0;
+	GError *error = NULL;
+//	gboolean ret = FALSE;
+	GMainLoop *loop;
+	GtkWidget *main_window;
+	GtkWidget *widget;
+	UniqueApp *unique_app;
+	guint xid = 0;
+	GcmColorimeter *colorimeter = NULL;
+
+	const GOptionEntry options[] = {
+		{ "parent-window", 'p', 0, G_OPTION_ARG_INT, &xid,
+		  /* TRANSLATORS: we can make this modal (stay on top of) another window */
+		  _("Set the parent window to make this modal"), NULL },
+		{ NULL}
+	};
+
+	/* setup translations */
+	setlocale (LC_ALL, "");
+	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
+	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+	textdomain (GETTEXT_PACKAGE);
+
+	/* setup type system */
+	g_type_init ();
+
+	context = g_option_context_new (NULL);
+	/* TRANSLATORS: tool that is used to pick colors */
+	g_option_context_set_summary (context, _("GNOME Color Manager Color Picker"));
+	g_option_context_add_group (context, egg_debug_get_option_group ());
+	g_option_context_add_group (context, gtk_get_option_group (TRUE));
+	g_option_context_add_main_entries (context, options, NULL);
+	g_option_context_parse (context, &argc, &argv, NULL);
+	g_option_context_free (context);
+
+	/* block in a loop */
+	loop = g_main_loop_new (NULL, FALSE);
+
+
+	/* are we already activated? */
+	unique_app = unique_app_new ("org.gnome.ColorManager.Picker", NULL);
+	if (unique_app_is_running (unique_app)) {
+		egg_debug ("You have another instance running. This program will now close");
+		unique_app_send_message (unique_app, UNIQUE_ACTIVATE, NULL);
+		goto out;
+	}
+	g_signal_connect (unique_app, "message-received",
+			  G_CALLBACK (gcm_picker_message_received_cb), NULL);
+
+	/* get UI */
+	builder = gtk_builder_new ();
+	retval = gtk_builder_add_from_file (builder, GCM_DATA "/gcm-picker.ui", &error);
+	if (retval == 0) {
+		egg_warning ("failed to load ui: %s", error->message);
+		g_error_free (error);
+		goto out;
+	}
+
+	main_window = GTK_WIDGET (gtk_builder_get_object (builder, "dialog_picker"));
+	gtk_window_set_icon_name (GTK_WINDOW (main_window), GCM_STOCK_ICON);
+	g_signal_connect (main_window, "delete_event",
+			  G_CALLBACK (gcm_picker_delete_event_cb), loop);
+
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_close"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_picker_close_cb), loop);
+
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_help"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_picker_help_cb), NULL);
+
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "button_measure"));
+	g_signal_connect (widget, "clicked",
+			  G_CALLBACK (gcm_picker_measure_cb), NULL);
+
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "image_preview"));
+	gtk_widget_set_size_request (widget, 200, 200);
+
+	/* add application specific icons to search path */
+	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
+	                                   GCM_DATA G_DIR_SEPARATOR_S "icons");
+
+	/* use the color device */
+	colorimeter = gcm_colorimeter_new ();
+	g_signal_connect (colorimeter, "changed", G_CALLBACK (gcm_picker_colorimeter_changed_cb), NULL);
+
+	/* set the parent window if it is specified */
+	if (xid != 0) {
+		egg_debug ("Setting xid %i", xid);
+		gcm_window_set_parent_xid (GTK_WINDOW (main_window), xid);
+	}
+
+	/* use an info bar if there is no device, or the wrong device */
+	info_bar_hardware = gtk_info_bar_new ();
+	info_bar_hardware_label = gtk_label_new (NULL);
+	gtk_info_bar_set_message_type (GTK_INFO_BAR(info_bar_hardware), GTK_MESSAGE_INFO);
+	widget = gtk_info_bar_get_content_area (GTK_INFO_BAR(info_bar_hardware));
+	gtk_container_add (GTK_CONTAINER(widget), info_bar_hardware_label);
+	gtk_widget_show (info_bar_hardware_label);
+
+	/* add infobar to devices pane */
+	widget = GTK_WIDGET (gtk_builder_get_object (builder, "vbox1"));
+	gtk_box_pack_start (GTK_BOX(widget), info_bar_hardware, FALSE, FALSE, 0);
+
+	/* disable some ui if no hardware */
+	gcm_picker_colorimeter_setup_ui (colorimeter);
+
+	/* wait */
+	gtk_widget_show (main_window);
+	g_main_loop_run (loop);
+
+out:
+	g_object_unref (unique_app);
+	if (colorimeter != NULL)
+		g_object_unref (colorimeter);
+	if (builder != NULL)
+		g_object_unref (builder);
+	g_main_loop_unref (loop);
+	return retval;
+}
+



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