[gnome-color-manager] Make gcm-dump-edid more useful by showing parsed data if available



commit 1aec3aec564720cf125835ec8e749ce09bd26769
Author: Richard Hughes <richard hughsie com>
Date:   Sat Dec 19 19:46:00 2009 +0000

    Make gcm-dump-edid more useful by showing parsed data if available

 src/gcm-dump-edid.c |  118 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 116 insertions(+), 2 deletions(-)
---
diff --git a/src/gcm-dump-edid.c b/src/gcm-dump-edid.c
index d1c26d1..5dc5d6f 100644
--- a/src/gcm-dump-edid.c
+++ b/src/gcm-dump-edid.c
@@ -29,6 +29,95 @@
 #include "egg-debug.h"
 
 #include "gcm-utils.h"
+#include "gcm-edid.h"
+
+/**
+ * gcm_dump_edid_filename:
+ **/
+static gboolean
+gcm_dump_edid_filename (const gchar *filename)
+{
+	gchar *monitor_name = NULL;
+	gchar *vendor_name = NULL;
+	gchar *serial_number = NULL;
+	gchar *ascii_string = NULL;
+	gchar *pnp_id = NULL;
+	gchar *data = NULL;
+	guint width;
+	guint height;
+	gfloat gamma;
+	gboolean ret;
+	GError *error = NULL;
+	GcmEdid *edid = NULL;
+
+	/* load */
+	ret = g_file_get_contents (filename, &data, NULL, &error);
+	if (!ret) {
+		/* TRANSLATORS: this is when the EDID file cannot be read */
+		g_print ("%s: %s\n", _("Cannot load file contents"), error->message);
+		goto out;
+	}
+
+	/* parse */
+	edid = gcm_edid_new ();
+	ret = gcm_edid_parse (edid, (const guint8 *) data, &error);
+	if (!ret) {
+		/* TRANSLATORS: this is when the EDID cannot be parsed */
+		g_print ("%s: %s\n", _("Cannot parse EDID contents"), error->message);
+		goto out;
+	}
+
+	g_object_get (edid,
+		      "monitor-name", &monitor_name,
+		      "vendor-name", &vendor_name,
+		      "serial-number", &serial_number,
+		      "ascii-string", &ascii_string,
+		      "pnp-id", &pnp_id,
+		      "width", &width,
+		      "height", &height,
+		      "gamma", &gamma,
+		      NULL);
+
+	/* print data */
+	if (monitor_name != NULL) {
+		/* TRANSLATORS: this is debugging output for the supplied EDID file */
+		g_print ("  %s: %s\n", _("Monitor name"), monitor_name);
+	}
+	if (vendor_name != NULL) {
+		/* TRANSLATORS: this is debugging output for the supplied EDID file */
+		g_print ("  %s: %s\n", _("Vendor name"), vendor_name);
+	}
+	if (serial_number != NULL) {
+		/* TRANSLATORS: this is debugging output for the supplied EDID file */
+		g_print ("  %s: %s\n", _("Serial number"), serial_number);
+	}
+	if (ascii_string != NULL) {
+		/* TRANSLATORS: this is debugging output for the supplied EDID file */
+		g_print ("  %s: %s\n", _("Text string"), ascii_string);
+	}
+	if (pnp_id != NULL) {
+		/* TRANSLATORS: this is debugging output for the supplied EDID file */
+		g_print ("  %s: %s\n", _("PNP identifier"), pnp_id);
+	}
+	if (width != 0) {
+		/* TRANSLATORS: this is debugging output for the supplied EDID file */
+		g_print ("  %s: %ix%i\n", _("Size"), width, height);
+	}
+	if (gamma > 0.0f) {
+		/* TRANSLATORS: this is debugging output for the supplied EDID file */
+		g_print ("  %s: %f\n", _("Gamma"), gamma);
+	}
+out:
+	if (edid != NULL)
+		g_object_unref (edid);
+	g_free (monitor_name);
+	g_free (vendor_name);
+	g_free (serial_number);
+	g_free (ascii_string);
+	g_free (pnp_id);
+	g_free (data);
+	return ret;
+}
 
 /**
  * main:
@@ -40,6 +129,7 @@ main (int argc, char **argv)
 	gboolean ret;
 	gchar *output_name;
 	gchar *filename;
+	gchar **files = NULL;
 	guint i;
 	guint retval = 0;
 	GError *error = NULL;
@@ -47,6 +137,13 @@ main (int argc, char **argv)
 	GnomeRRScreen *rr_screen = NULL;
 	GOptionContext *context;
 
+	const GOptionEntry options[] = {
+		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
+		  /* TRANSLATORS: command line option: a list of files to parse */
+		  _("EDID dumps to parse"), NULL },
+		{ NULL}
+	};
+
 	setlocale (LC_ALL, "");
 
 	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
@@ -56,11 +153,22 @@ main (int argc, char **argv)
 	gtk_init (&argc, &argv);
 
 	context = g_option_context_new ("gnome-color-manager dump edid program");
+	g_option_context_add_main_entries (context, options, NULL);
 	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_parse (context, &argc, &argv, NULL);
 	g_option_context_free (context);
 
+	/* we've specified files, just parse them */
+	if (files != NULL) {
+		for (i=0; files[i] != NULL; i++) {
+			/* TRANSLATORS: this is the filename we are displaying */
+			g_print ("%s: %s\n", _("EDID dump"), files[i]);
+			gcm_dump_edid_filename (files[i]);
+		}
+		goto out;
+	}
+
 	/* get screen */
 	rr_screen = gnome_rr_screen_new (gdk_screen_get_default (), NULL, NULL, &error);
 	if (rr_screen == NULL) {
@@ -93,15 +201,21 @@ main (int argc, char **argv)
 		/* save to disk */
 		ret = g_file_set_contents (filename, (const gchar *) data, 0x80, &error);
 		if (ret) {
-			g_print ("Saved %i bytes to %s\n", 128, filename);
+			/* TRANSLATORS: we saved the EDID to a file - second parameter is a filename */
+			g_print (_("Saved %i bytes to %s"), 128, filename);
+			g_print ("\n");
+			gcm_dump_edid_filename (filename);
 		} else {
-			g_print ("Failed to save EDID to %s: %s\n", filename, error->message);
+			/* TRANSLATORS: we saved the EDID to a file - parameter is a filename */
+			g_print (_("Failed to save EDID to %s"), filename);
+			g_print (": %s\n", error->message);
 			/* non-fatal */
 			g_clear_error (&error);
 		}
 		g_free (filename);
 	}
 out:
+	g_strfreev (files);
 	if (rr_screen != NULL)
 		gnome_rr_screen_destroy (rr_screen);
 	return retval;



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