[gnome-color-manager/colord: 10/72] Remove gcm-apply and merge the functionality into gcm-session



commit 3d46bb9f23aacf515d6cd8faee895d1043f11fa1
Author: Richard Hughes <richard hughsie com>
Date:   Sat Jan 15 22:44:55 2011 +0000

    Remove gcm-apply and merge the functionality into gcm-session

 data/Makefile.am                                   |    4 +-
 ...gcm-apply.desktop.in => gcm-session.desktop.in} |    2 +-
 po/POTFILES.in                                     |    4 +-
 src/.gitignore                                     |    1 -
 src/Makefile.am                                    |   19 --
 src/gcm-apply.c                                    |  190 --------------------
 src/gcm-session.c                                  |  127 +++++++++++++-
 7 files changed, 126 insertions(+), 221 deletions(-)
---
diff --git a/data/Makefile.am b/data/Makefile.am
index 9b35163..2ceea63 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -17,7 +17,7 @@ desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
 
 @INTLTOOL_DESKTOP_RULE@
 autostartdir = $(sysconfdir)/xdg/autostart
-autostart_in_files = gcm-apply.desktop.in
+autostart_in_files = gcm-session.desktop.in
 autostart_DATA = $(autostart_in_files:.desktop.in=.desktop)
 
 servicedir       = $(datadir)/dbus-1/services
@@ -51,7 +51,7 @@ clean-local :
 
 DISTCLEANFILES =					\
 	org.gnome.ColorManager.service			\
-	gcm-apply.desktop				\
+	gcm-session.desktop				\
 	gcm-prefs.desktop				\
 	gcm-viewer.desktop				\
 	gcm-import.desktop
diff --git a/data/gcm-apply.desktop.in b/data/gcm-session.desktop.in
similarity index 88%
rename from data/gcm-apply.desktop.in
rename to data/gcm-session.desktop.in
index 3a0bfab..288a82c 100644
--- a/data/gcm-apply.desktop.in
+++ b/data/gcm-session.desktop.in
@@ -2,7 +2,7 @@
 _Name=Load device color profiles
 _Comment=Applies device profile settings at session startup
 Icon=gnome-color-manager
-Exec=gcm-apply --login
+Exec=gcm-session --login
 Terminal=false
 Type=Application
 Categories=
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 3361ede..0940274 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,4 +1,4 @@
-data/gcm-apply.desktop.in
+data/gcm-session.desktop.in
 data/gcm-import.desktop.in
 data/gcm-prefs.desktop.in
 data/gcm-viewer.desktop.in
@@ -8,9 +8,7 @@ data/org.gnome.settings-daemon.plugins.color.gschema.xml
 libcolor-glib/gcm-debug.c
 libcolor-glib/gcm-profile.c
 libcolor-glib/gcm-sensor-client.c
-policy/org.gnome.color.policy.in
 src/cc-color-panel.c
-src/gcm-apply.c
 src/gcm-calibrate-argyll.c
 src/gcm-calibrate.c
 src/gcm-calibrate-dialog.c
diff --git a/src/.gitignore b/src/.gitignore
index c08378a..4e1519e 100644
--- a/src/.gitignore
+++ b/src/.gitignore
@@ -5,7 +5,6 @@
 *.bin
 .libs
 .deps
-gcm-apply
 gcm-import
 gcm-viewer
 gcm-picker
diff --git a/src/Makefile.am b/src/Makefile.am
index 7fd1261..4055357 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -81,7 +81,6 @@ libgcmshared_a_LIBADD =					\
 
 bin_PROGRAMS =						\
 	gcm-inspect					\
-	gcm-apply					\
 	gcm-viewer					\
 	gcm-session					\
 	gcm-picker					\
@@ -112,24 +111,6 @@ gcm_inspect_LDADD =					\
 gcm_inspect_CFLAGS =					\
 	$(WARNINGFLAGS_C)
 
-gcm_apply_SOURCES =					\
-	gcm-apply.c
-
-gcm_apply_LDADD =					\
-	libgcmshared.a					\
-	$(GLIB_LIBS)					\
-	$(X11_LIBS)					\
-	$(GUDEV_LIBS)					\
-	$(XORG_LIBS)					\
-	$(GTK_LIBS)					\
-	$(SANE_LIBS)					\
-	$(CUPS_LIBS)					\
-	$(COLOR_GLIB_LIBS)				\
-	-lm
-
-gcm_apply_CFLAGS =					\
-	$(WARNINGFLAGS_C)
-
 gcm_import_SOURCES =					\
 	gcm-import.c
 
diff --git a/src/gcm-session.c b/src/gcm-session.c
index 052f51d..d9a9c48 100644
--- a/src/gcm-session.c
+++ b/src/gcm-session.c
@@ -576,19 +576,92 @@ gcm_session_client_changed_cb (GcmClient *client_, GcmDevice *device, gpointer u
 }
 
 /**
+ * gcm_apply_create_icc_profile_for_edid:
+ **/
+static gboolean
+gcm_apply_create_icc_profile_for_edid (GcmDevice *device, const gchar *filename, GError **error)
+{
+	gboolean ret = FALSE;
+	GcmProfile *profile;
+
+	/* generate */
+	profile = gcm_device_generate_profile (device, error);
+	if (profile == NULL)
+		goto out;
+
+	/* ensure the per-user directory exists */
+	ret = gcm_utils_mkdir_for_filename (filename, error);
+	if (!ret)
+		goto out;
+
+	/* save this */
+	ret = gcm_profile_save (profile, filename, error);
+	if (!ret)
+		goto out;
+
+	/*
+	 * When we get here there are 4 possible situations:
+	 *
+	 * 1. profiles assigned, use-edid-profile=TRUE		-> add to profiles if not already added, but not as default
+	 * 2. profiles assigned, use-edid-profile=FALSE		-> do nothing
+	 * 3. no profiles, use-edid-profile=TRUE		-> add to profiles as default
+	 * 4. no profiles, use-edid-profile=FALSE		-> do nothing
+	 */
+
+	/* do we set this by default? */
+	if (!gcm_device_get_use_edid_profile (device)) {
+		g_debug ("not using auto-edid profile as device profile");
+		goto out;
+	}
+
+	/* add to the profiles list */
+	ret = gcm_device_profile_add (device, profile, NULL);
+	if (ret) {
+		/* need to save new list */
+		ret = gcm_device_save (device, error);
+		if (!ret)
+			goto out;
+	} else {
+		/* if this failed, it's because it's already associated
+		 * with the device which is okay with us */
+		g_debug ("already added auto-edid profile, not adding %s",
+			 gcm_profile_get_checksum (profile));
+		ret = TRUE;
+	}
+out:
+	if (profile != NULL)
+		g_object_unref (profile);
+	return ret;
+}
+
+/**
  * main:
  **/
 int
 main (int argc, char *argv[])
 {
-	GOptionContext *context;
-	GError *error = NULL;
+	const gchar *edid_md5;
+	gboolean login = FALSE;
 	gboolean ret;
-	guint retval = 1;
+	gchar *filename;
+	gchar *introspection_data = NULL;
+	gchar *path;
+	GcmDevice *device;
+	GError *error = NULL;
+	GFile *file = NULL;
+	GOptionContext *context;
+	GPtrArray *array = NULL;
+	guint i;
 	guint owner_id = 0;
 	guint poll_id = 0;
-	GFile *file = NULL;
-	gchar *introspection_data = NULL;
+	guint retval = 1;
+
+	const GOptionEntry options[] = {
+		{ "login", 'l', 0, G_OPTION_ARG_NONE, &login,
+		  /* TRANSLATORS: we use this mode at login as we're sure there are no previous settings to clear */
+		  _("Do not attempt to clear previously applied settings"), NULL },
+		{ NULL}
+	};
 
 	setlocale (LC_ALL, "");
 
@@ -605,6 +678,7 @@ main (int argc, char *argv[])
 	g_set_application_name (_("Color Management"));
 	context = g_option_context_new (NULL);
 	g_option_context_set_summary (context, _("Color Management D-Bus Service"));
+	g_option_context_add_main_entries (context, options, NULL);
 	g_option_context_add_group (context, gcm_debug_get_option_group ());
 	g_option_context_add_group (context, gtk_get_option_group (TRUE));
 	g_option_context_parse (context, &argc, &argv, NULL);
@@ -624,6 +698,47 @@ main (int argc, char *argv[])
 	g_signal_connect (client, "removed", G_CALLBACK (gcm_session_client_changed_cb), NULL);
 	g_signal_connect (client, "changed", G_CALLBACK (gcm_session_client_changed_cb), NULL);
 
+	/* set for each output */
+	array = gcm_client_get_devices (client);
+	for (i=0; i<array->len; i++) {
+		device = g_ptr_array_index (array, i);
+
+		/* optimize for login to save a few hundred ms */
+		gcm_device_xrandr_set_remove_atom (GCM_DEVICE_XRANDR (device), !login);
+
+		/* do we have to generate a edid profile? */
+		edid_md5 = gcm_device_xrandr_get_edid_md5 (GCM_DEVICE_XRANDR (device));
+		if (edid_md5 == NULL) {
+			g_warning ("no EDID data for device");
+		} else {
+			filename = g_strdup_printf ("edid-%s.icc", edid_md5);
+			path = g_build_filename (g_get_user_data_dir (), "icc", filename, NULL);
+			if (g_file_test (path, G_FILE_TEST_EXISTS)) {
+				g_debug ("auto-profile edid %s exists", path);
+			} else {
+				g_debug ("auto-profile edid does not exist, creating as %s", path);
+				ret = gcm_apply_create_icc_profile_for_edid (device, path, &error);
+				if (!ret) {
+					g_warning ("failed to create profile from EDID data: %s",
+						     error->message);
+					g_clear_error (&error);
+				}
+			}
+			g_free (filename);
+			g_free (path);
+		}
+
+		/* set gamma for device */
+		g_debug ("applying default profile for device: %s", gcm_device_get_id (device));
+		ret = gcm_device_apply (device, &error);
+		if (!ret) {
+			retval = 1;
+			g_warning ("failed to set gamma: %s", error->message);
+			g_error_free (error);
+			break;
+		}
+	}
+
 	/* have access to all profiles */
 	profile_store = gcm_profile_store_new ();
 	gcm_profile_store_search (profile_store);
@@ -672,6 +787,8 @@ main (int argc, char *argv[])
 	retval = 0;
 out:
 	g_free (introspection_data);
+	if (array != NULL)
+		g_ptr_array_unref (array);
 	if (poll_id != 0)
 		g_source_remove (poll_id);
 	if (file != NULL)



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