Ejemplo n.º 1
0
/**
 * cd_util_get_standard_space_filename:
 **/
static gchar *
cd_util_get_standard_space_filename (CdUtilPrivate *priv,
				     CdStandardSpace standard_space,
				     GError **error)
{
	gchar *filename = NULL;
	g_autoptr(CdProfile) profile_tmp = NULL;

	/* try to find */
	if (!cd_client_connect_sync (priv->client, NULL, error))
		return NULL;
	profile_tmp = cd_client_get_standard_space_sync (priv->client,
							 standard_space,
							 NULL,
							 error);
	if (profile_tmp == NULL)
		return NULL;

	/* get filename */
	if (!cd_profile_connect_sync (profile_tmp, NULL, error))
		return NULL;
	filename = g_strdup (cd_profile_get_filename (profile_tmp));
	return filename;
}
Ejemplo n.º 2
0
/**
 * cd_edid_install_profile:
 * @scope: where to install the profile, e.g. %CD_EDID_SCOPE_USER
 * @edid: the EDID data, typically just 128 bytes in size
 * @edid_len: the size in bytes of @edid_len
 * @profile_fn: the profile filename to install
 *
 * Install a profile for a given monitor.
 *
 * Return value: a %CdEdidError, e.g. %CD_EDID_ERROR_OK
 *
 * Since: 0.1.34
 **/
CdEdidError
cd_edid_install_profile (unsigned char *edid,
			 int edid_len,
			 CdEdidScope scope,
			 char *profile_fn)
{
	CdClient *client = NULL;
	CdDevice *device = NULL;
	CdEdidError rc = CD_EDID_ERROR_OK;
	CdProfile *profile = NULL;
	gboolean ret;
	gchar *md5 = NULL;
	GError *error = NULL;
	GFile *file;

	g_return_val_if_fail (profile_fn != NULL, CD_EDID_ERROR_RESOURCE);

	/* bad input */
	if (edid == NULL || edid_len == 0) {
		rc = CD_EDID_ERROR_NO_DATA;
		goto out;
	}

	/* conect to daemon */
	client = cd_client_new ();
	ret = cd_client_connect_sync (client, NULL, &error);
	if (!ret) {
		rc = CD_EDID_ERROR_ACCESS_CONFIG;
		g_warning ("Failed to connect to colord: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* find device that matches the output EDID */
	md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5,
					     (const gchar *)edid,
					     (gssize) edid_len);
	device = cd_client_find_device_by_property_sync (client,
							 CD_DEVICE_METADATA_OUTPUT_EDID_MD5,
							 md5,
							 NULL,
							 &error);
	if (device == NULL) {
		rc = CD_EDID_ERROR_MONITOR_NOT_FOUND;
		g_warning ("Failed to find device that matches %s: %s",
			   md5, error->message);
		g_error_free (error);
		goto out;
	}

	/* read device properties */
	ret = cd_device_connect_sync (device, NULL, &error);
	if (!ret) {
		rc = CD_EDID_ERROR_ACCESS_CONFIG;
		g_warning ("device disappeared: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* import profile */
	file = g_file_new_for_path (profile_fn);
	profile = cd_client_import_profile_sync (client, file, NULL, &error);
	if (profile == NULL) {
		rc = CD_EDID_ERROR_NO_PROFILE;
		g_warning ("Could not import profile %s: %s",
			   profile_fn,
			   error->message);
		g_error_free (error);
		goto out;
	}

	/* add profile to device */
	ret = cd_device_add_profile_sync (device,
					  CD_DEVICE_RELATION_HARD,
					  profile,
					  NULL,
					  &error);
	if (!ret) {
		rc = CD_EDID_ERROR_SET_CONFIG;
		g_warning ("could not add profile %s to device %s: %s",
			   cd_profile_get_id (profile),
			   cd_device_get_id (device),
			   error->message);
		g_error_free (error);
		goto out;
	}

	/* install system-wide */
	if (scope == CD_EDID_SCOPE_SYSTEM) {
		ret = cd_profile_install_system_wide_sync (profile, NULL, &error);
		if (!ret) {
			rc = CD_EDID_ERROR_PROFILE_COPY;
			g_warning ("could not set profile %s systemwide: %s",
				   cd_profile_get_id (profile),
				   error->message);
			g_error_free (error);
			goto out;
		}
	}
out:
	if (client != NULL)
		g_object_unref (client);
	if (device != NULL)
		g_object_unref (device);
	if (profile != NULL)
		g_object_unref (profile);
	g_free (md5);
	return rc;
}
Ejemplo n.º 3
0
/**
 * cd_edid_get_profile:
 * @edid: the EDID data, typically just 128 bytes in size
 * @edid_len: the size in bytes of @edid_len
 * @profile_fn: the returned profile filename, use free() when done
 *
 * Get an associated monitor profile.
 *
 * Return value: a %CdEdidError, e.g. %CD_EDID_ERROR_OK
 *
 * Since: 0.1.34
 **/
CdEdidError
cd_edid_get_profile (unsigned char *edid,
		     int edid_len,
		     char **profile_fn)
{
	CdClient *client = NULL;
	CdDevice *device = NULL;
	CdProfile *profile = NULL;
	const gchar *filename;
	gboolean ret;
	gchar *md5 = NULL;
	GError *error = NULL;
	CdEdidError rc = CD_EDID_ERROR_OK;

	/* bad input */
	if (edid == NULL || edid_len == 0) {
		rc = CD_EDID_ERROR_NO_DATA;
		goto out;
	}

	/* conect to daemon */
	client = cd_client_new ();
	ret = cd_client_connect_sync (client, NULL, &error);
	if (!ret) {
		rc = CD_EDID_ERROR_ACCESS_CONFIG;
		g_warning ("Failed to connect to colord: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* find device that matches the output EDID */
	md5 = g_compute_checksum_for_string (G_CHECKSUM_MD5,
					     (const gchar *)edid,
					     (gssize) edid_len);
	device = cd_client_find_device_by_property_sync (client,
							 CD_DEVICE_METADATA_OUTPUT_EDID_MD5,
							 md5,
							 NULL,
							 &error);
	if (device == NULL) {
		rc = CD_EDID_ERROR_MONITOR_NOT_FOUND;
		g_warning ("Failed to find device that matches %s: %s",
			   md5, error->message);
		g_error_free (error);
		goto out;
	}

	/* read device properties */
	ret = cd_device_connect_sync (device, NULL, &error);
	if (!ret) {
		rc = CD_EDID_ERROR_ACCESS_CONFIG;
		g_warning ("device disappeared: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* get the default profile for the device */
	profile = cd_device_get_default_profile (device);
	if (profile == NULL) {
		rc = CD_EDID_ERROR_NO_PROFILE;
		g_warning ("No profile for %s: %s",
			   cd_device_get_id (device),
			   error->message);
		g_error_free (error);
		goto out;
	}

	/* read profile properties */
	ret = cd_profile_connect_sync (profile, NULL, &error);
	if (!ret) {
		rc = CD_EDID_ERROR_ACCESS_CONFIG;
		g_warning ("profile disappeared: %s", error->message);
		g_error_free (error);
		goto out;
	}

	/* get filename */
	filename = cd_profile_get_filename (profile);
	if (filename == NULL) {
		rc = CD_EDID_ERROR_INVALID_PROFILE;
		goto out;
	}

	/* return filename of profile */
	if (profile_fn != NULL)
		*profile_fn = strdup (filename);
out:
	if (client != NULL)
		g_object_unref (client);
	if (device != NULL)
		g_object_unref (device);
	if (profile != NULL)
		g_object_unref (profile);
	g_free (md5);
	return rc;
}
Ejemplo n.º 4
0
/**
 * main:
 **/
int
main (int argc, char **argv)
{
	CdClient *client = NULL;
	CdProfile *profile_tmp = NULL;
	const gchar *copyright;
	const gchar *description;
	const gchar *title;
	const gchar *lang;
	gboolean ret;
	gchar **files = NULL;
	CdIcc *icc = NULL;
	GError *error = NULL;
	GFile *destination = NULL;
	GFile *file = NULL;
	GOptionContext *context;
	GString *string = NULL;
	GtkResponseType response;
	GtkWidget *image = NULL;
	GtkWidget *dialog;
	guint retval = 1;

	const GOptionEntry options[] = {
		{ G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files,
		  /* TRANSLATORS: command line option: a list of catalogs to install */
		  _("ICC profile to install"), NULL },
		{ NULL}
	};

	setlocale (LC_ALL, "");

	bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	gtk_init (&argc, &argv);

	context = g_option_context_new ("gnome-color-manager import program");
	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);
	g_option_context_free (context);

	/* nothing sent */
	if (files == NULL) {
		/* TRANSLATORS: nothing was specified on the command line */
		dialog = gtk_message_dialog_new (NULL,
						 0,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_CLOSE,
						 _("No filename specified"));
		gtk_window_set_icon_name (GTK_WINDOW (dialog),
					  GCM_STOCK_ICON);
		gtk_dialog_run (GTK_DIALOG (dialog));
		gtk_widget_destroy (dialog);
		goto out;
	}

	/* load profile */
	icc = cd_icc_new ();
	file = g_file_new_for_path (files[0]);
	ret = cd_icc_load_file (icc, file,
				CD_ICC_LOAD_FLAGS_FALLBACK_MD5,
				NULL, &error);
	if (!ret) {
		/* TRANSLATORS: could not read file */
		dialog = gtk_message_dialog_new (NULL,
						 0,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_CLOSE,
						 _("Failed to open ICC profile"));
		gtk_window_set_icon_name (GTK_WINDOW (dialog),
					  GCM_STOCK_ICON);
		/* TRANSLATORS: parsing error */
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
							  _("Failed to parse file: %s"),
							  error->message);
		gtk_dialog_run (GTK_DIALOG (dialog));
		g_error_free (error);
		gtk_widget_destroy (dialog);
		goto out;
	}

	/* get data */
	lang = g_getenv ("LANG");
	description = cd_icc_get_description (icc, lang, NULL);
	copyright = cd_icc_get_copyright (icc, lang, NULL);

	/* use the same icon as the color control panel */
	image = gtk_image_new_from_icon_name ("preferences-color",
					      GTK_ICON_SIZE_DIALOG);
	gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
	gtk_widget_show (image);

	/* create message */
	string = g_string_new ("");
	/* TRANSLATORS: message text */
	g_string_append_printf (string, _("Profile description: %s"),
				description != NULL ? description : files[0]);

	/* add copyright */
	if (copyright != NULL) {
		if (g_str_has_prefix (copyright, "Copyright "))
			copyright += 10;
		if (g_str_has_prefix (copyright, "Copyright, "))
			copyright += 11;
		/* TRANSLATORS: message text */
		g_string_append_printf (string, "\n%s %s", _("Profile copyright:"), copyright);
	}

	/* check file does't already exist as system-wide */
	client = cd_client_new ();
	ret = cd_client_connect_sync (client,
				      NULL,
				      &error);
	if (!ret) {
		g_warning ("failed to connect to colord: %s",
			   error->message);
		g_error_free (error);
		goto out;
	}

	profile_tmp = cd_client_find_profile_by_property_sync (client,
							      CD_PROFILE_METADATA_FILE_CHECKSUM,
							      cd_icc_get_checksum (icc),
							      NULL,
							      NULL);
	if (profile_tmp != NULL) {
		ret = cd_profile_connect_sync (profile_tmp,
					       NULL,
					       &error);
		if (!ret) {
			g_warning ("failed to connect to profile %s: %s",
				   cd_profile_get_object_path (profile_tmp),
				   error->message);
			g_error_free (error);
			goto out;
		}
		/* TRANSLATORS: color profile already been installed */
		dialog = gtk_message_dialog_new (NULL,
						 0,
						 GTK_MESSAGE_INFO,
						 GTK_BUTTONS_CLOSE,
						 _("Color profile is already imported"));
		gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
		gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", string->str);
		gtk_dialog_add_button (GTK_DIALOG (dialog), _("Show Details"), GTK_RESPONSE_HELP);
		response = gtk_dialog_run (GTK_DIALOG (dialog));
		if (response == GTK_RESPONSE_HELP) {
			gcm_import_show_details (GTK_WINDOW (dialog),
						 TRUE,
						 cd_profile_get_id (profile_tmp));
			goto try_harder;
		}
		gtk_widget_destroy (dialog);
		goto out;
	}

	/* get correct title */
	switch (cd_icc_get_kind (icc)) {
	case CD_PROFILE_KIND_DISPLAY_DEVICE:
		/* TRANSLATORS: the profile type */
		title = _("Import display color profile?");
		break;
	case CD_PROFILE_KIND_OUTPUT_DEVICE:
		/* TRANSLATORS: the profile type */
		title = _("Import device color profile?");
		break;
	case CD_PROFILE_KIND_NAMED_COLOR:
		/* TRANSLATORS: the profile type */
		title = _("Import named color profile?");
		break;
	default:
		/* TRANSLATORS: the profile type */
		title = _("Import color profile?");
		break;
	}

	/* ask confirmation */
	dialog = gtk_message_dialog_new (NULL,
					 0,
					 GTK_MESSAGE_INFO,
					 GTK_BUTTONS_CANCEL,
					 "%s",
					 title);
	gtk_message_dialog_set_image (GTK_MESSAGE_DIALOG (dialog), image);
	gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
	gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", string->str);
	/* TRANSLATORS: button text */
	gtk_dialog_add_button (GTK_DIALOG (dialog), _("Import"), GTK_RESPONSE_OK);
	gtk_dialog_add_button (GTK_DIALOG (dialog), _("Show Details"), GTK_RESPONSE_HELP);
try_harder:
	response = gtk_dialog_run (GTK_DIALOG (dialog));
	if (response == GTK_RESPONSE_HELP) {
		gcm_import_show_details (GTK_WINDOW (dialog), FALSE, files[0]);
		goto try_harder;
	}
	gtk_widget_destroy (dialog);

	/* not the correct response */
	if (response != GTK_RESPONSE_OK)
		goto out;

	/* copy icc file to users profile path */
	profile_tmp = cd_client_import_profile_sync (client,
						     file,
						     NULL,
						     &error);
	if (profile_tmp == NULL) {
		/* TRANSLATORS: could not read file */
		dialog = gtk_message_dialog_new (NULL,
						 0,
						 GTK_MESSAGE_ERROR,
						 GTK_BUTTONS_CLOSE,
						 _("Failed to import file"));
		gtk_window_set_icon_name (GTK_WINDOW (dialog), GCM_STOCK_ICON);
		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", error->message);
		gtk_dialog_run (GTK_DIALOG (dialog));
		g_error_free (error);
		gtk_widget_destroy (dialog);
		goto out;
	}
out:
	if (file != NULL)
		g_object_unref (file);
	if (string != NULL)
		g_string_free (string, TRUE);
	if (icc != NULL)
		g_object_unref (icc);
	if (client != NULL)
		g_object_unref (client);
	if (profile_tmp != NULL)
		g_object_unref (profile_tmp);
	if (destination != NULL)
		g_object_unref (destination);
	g_strfreev (files);
	return retval;
}
Ejemplo n.º 5
0
static void
gcm_picker_startup_cb (GApplication *application, GcmPickerPrivate *priv)
{
	gboolean ret;
	GtkWidget *main_window;
	GtkWidget *widget;
	guint retval = 0;
	g_autoptr(GError) error = NULL;

	/* get UI */
	priv->builder = gtk_builder_new ();
	retval = gtk_builder_add_from_resource (priv->builder,
						"/org/gnome/color-manager/gcm-picker.ui",
						&error);
	if (retval == 0) {
		g_warning ("failed to load ui: %s", error->message);
		return;
	}

	main_window = GTK_WIDGET (gtk_builder_get_object (priv->builder, "dialog_picker"));
	gtk_application_add_window (GTK_APPLICATION (application), GTK_WINDOW (main_window));
	gtk_window_set_icon_name (GTK_WINDOW (main_window), GCM_STOCK_ICON);

	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "button_measure"));
	g_signal_connect (widget, "clicked",
			  G_CALLBACK (gcm_picker_measure_cb), priv);

	widget = GTK_WIDGET (gtk_builder_get_object (priv->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 (),
	                                   PKGDATADIR G_DIR_SEPARATOR_S "icons");

	/* create a last sample */
	//cd_color_xyz_clear (&last_sample);

	/* set the parent window if it is specified */
	if (priv->xid != 0) {
		g_debug ("Setting xid %u", priv->xid);
		gcm_window_set_parent_xid (GTK_WINDOW (main_window), priv->xid);
	}

	/* use an info bar if there is no device, or the wrong device */
	priv->info_bar_hardware = gtk_info_bar_new ();
	priv->info_bar_hardware_label = gtk_label_new (NULL);
	gtk_info_bar_set_message_type (GTK_INFO_BAR(priv->info_bar_hardware), GTK_MESSAGE_INFO);
	widget = gtk_info_bar_get_content_area (GTK_INFO_BAR(priv->info_bar_hardware));
	gtk_container_add (GTK_CONTAINER(widget), priv->info_bar_hardware_label);
	gtk_widget_show (priv->info_bar_hardware_label);

	/* add infobar to devices pane */
	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "box1"));
	gtk_box_pack_start (GTK_BOX(widget), priv->info_bar_hardware, FALSE, FALSE, 0);

	/* maintain a list of profiles */
	priv->client = cd_client_new ();
	ret = cd_client_connect_sync (priv->client, NULL, &error);
	if (!ret) {
		g_warning ("failed to connect to colord: %s",
			   error->message);
		return;
	}
	g_signal_connect (priv->client, "sensor-added",
			  G_CALLBACK (gcm_picker_sensor_client_changed_cb), priv);
	g_signal_connect (priv->client, "sensor-removed",
			  G_CALLBACK (gcm_picker_sensor_client_changed_cb), priv);

	/* disable some ui if no hardware */
	gcm_picker_sensor_client_setup_ui (priv);

	/* setup RGB combobox */
	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "combobox_colorspace"));
	gcm_prefs_set_combo_simple_text (widget);
	gcm_prefs_setup_space_combobox (priv, widget);
	g_signal_connect (G_OBJECT (widget), "changed",
			  G_CALLBACK (gcm_prefs_space_combo_changed_cb), priv);

	/* setup initial preview window */
	widget = GTK_WIDGET (gtk_builder_get_object (priv->builder, "image_preview"));
	gtk_image_set_from_file (GTK_IMAGE (widget), DATADIR "/icons/hicolor/64x64/apps/gnome-color-manager.png");

	/* wait */
	gtk_widget_show (main_window);
}