/** * mcm_dump_profile_filename: **/ static gboolean mcm_dump_profile_filename (const gchar *filename) { gboolean ret; GError *error = NULL; McmProfile *profile; guint profile_kind; guint colorspace; guint size; gboolean has_vcgt; const gchar *description; const gchar *copyright; const gchar *manufacturer; const gchar *model; const gchar *datetime; GFile *file = NULL; /* parse profile */ profile = mcm_profile_default_new (); file = g_file_new_for_path (filename); ret = mcm_profile_parse (profile, file, &error); if (!ret) { egg_warning ("failed to parse: %s", error->message); g_error_free (error); goto out; } /* print what we know */ profile_kind = mcm_profile_get_kind (profile); g_print ("Kind:\t%s\n", mcm_profile_kind_to_string (profile_kind)); colorspace = mcm_profile_get_colorspace (profile); g_print ("Colorspace:\t%s\n", mcm_colorspace_to_string (colorspace)); size = mcm_profile_get_size (profile); g_print ("Size:\t%i bytes\n", size); has_vcgt = mcm_profile_get_has_vcgt (profile); g_print ("Has VCGT:\t%s\n", has_vcgt ? "Yes" : "No"); description = mcm_profile_get_description (profile); if (description != NULL) g_print ("Description:\t%s\n", description); copyright = mcm_profile_get_copyright (profile); if (copyright != NULL) g_print ("Copyright:\t%s\n", copyright); manufacturer = mcm_profile_get_manufacturer (profile); if (manufacturer != NULL) g_print ("Manufacturer:\t%s\n", manufacturer); model = mcm_profile_get_model (profile); if (model != NULL) g_print ("Model:\t%s\n", model); datetime = mcm_profile_get_datetime (profile); if (datetime != NULL) g_print ("Created:\t%s\n", datetime); out: if (file != NULL) g_object_unref (file); g_object_unref (profile); return ret; }
/** * mcm_prefs_setup_space_combobox: **/ static void mcm_prefs_setup_space_combobox (GtkWidget *widget) { McmProfile *profile; guint i; const gchar *filename; McmColorspace colorspace; gboolean has_profile = FALSE; gboolean has_vcgt; gboolean has_colorspace_description; gchar *text = NULL; GPtrArray *profile_array = NULL; GtkTreeIter iter; /* get new list */ profile_array = mcm_profile_store_get_array (profile_store); /* update each list */ for (i=0; i<profile_array->len; i++) { profile = g_ptr_array_index (profile_array, i); /* only for correct kind */ has_vcgt = mcm_profile_get_has_vcgt (profile); has_colorspace_description = mcm_profile_has_colorspace_description (profile); colorspace = mcm_profile_get_colorspace (profile); if (!has_vcgt && has_colorspace_description && colorspace == MCM_COLORSPACE_RGB) { mcm_prefs_combobox_add_profile (widget, profile, &iter); /* set active option */ filename = mcm_profile_get_filename (profile); if (g_strcmp0 (filename, profile_filename) == 0) gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter); has_profile = TRUE; } } if (!has_profile) { /* TRANSLATORS: this is when there are no profiles that can be used; the search term is either "RGB" or "CMYK" */ text = g_strdup_printf (_("No %s color spaces available"), mcm_colorspace_to_localised_string (MCM_COLORSPACE_RGB)); gtk_combo_box_append_text (GTK_COMBO_BOX(widget), text); gtk_combo_box_set_active (GTK_COMBO_BOX (widget), 0); gtk_widget_set_sensitive (widget, FALSE); } if (profile_array != NULL) g_ptr_array_unref (profile_array); g_free (text); }
/** * main: **/ int main (int argc, char **argv) { gboolean ret; const gchar *copyright; const gchar *description; GFile *destination = NULL; GFile *file = NULL; gchar **files = NULL; guint retval = 1; McmProfile *profile = NULL; McmColorspace colorspace; GError *error = NULL; GOptionContext *context; GString *string = NULL; GtkWidget *dialog; GtkResponseType response; GtkWidget *cie_widget = NULL; McmXyz *white = NULL; McmXyz *red = NULL; McmXyz *green = NULL; McmXyz *blue = NULL; 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 ("mate-color-manager import 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); /* nothing sent */ if (files == NULL) { /* TRANSLATORS: nothing was specified on the command line */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("No filename specified")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_STOCK_ICON); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); goto out; } /* load profile */ profile = mcm_profile_default_new (); file = g_file_new_for_path (files[0]); ret = mcm_profile_parse (profile, file, &error); if (!ret) { /* TRANSLATORS: could not read file */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to open ICC profile")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_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 */ description = mcm_profile_get_description (profile); copyright = mcm_profile_get_copyright (profile); colorspace = mcm_profile_get_colorspace (profile); g_object_get (profile, "white", &white, "red", &red, "green", &green, "blue", &blue, NULL); /* use CIE widget */ cie_widget = mcm_cie_widget_new (); gtk_widget_set_size_request (cie_widget, 200, 200); g_object_set (cie_widget, "use-grid", FALSE, "use-whitepoint", FALSE, "white", white, "red", red, "green", green, "blue", blue, NULL); /* check file does't already exist */ destination = mcm_utils_get_profile_destination (file); ret = g_file_query_exists (destination, NULL); if (ret) { /* TRANSLATORS: color profile already been installed */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_CLOSE, _("ICC profile already installed")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_STOCK_ICON); gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s\n%s", description, copyright); /* add cie widget */ mcm_import_add_cie_widget (GTK_DIALOG(dialog), cie_widget); gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); goto out; } /* create message */ string = g_string_new (""); if (description != NULL) { /* TRANSLATORS: message text */ g_string_append_printf (string, _("Import ICC color profile %s?"), description); } else { /* TRANSLATORS: message text */ g_string_append (string, _("Import ICC color profile?")); } /* add copyright */ if (copyright != NULL) g_string_append_printf (string, "\n%s", copyright); /* ask confirmation */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_CLOSE, "%s", _("Import ICC profile")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_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), _("Install"), GTK_RESPONSE_OK); /* add cie widget */ mcm_import_add_cie_widget (GTK_DIALOG(dialog), cie_widget); /* only show the cie widget if we have RGB data */ if (colorspace != MCM_COLORSPACE_RGB) gtk_widget_hide (cie_widget); gtk_window_set_resizable (GTK_WINDOW (dialog), TRUE); response = gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); /* not the correct response */ if (response != GTK_RESPONSE_OK) goto out; /* copy icc file to users profile path */ ret = mcm_utils_mkdir_and_copy (file, destination, &error); if (!ret) { /* TRANSLATORS: could not read file */ dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, _("Failed to copy file")); gtk_window_set_icon_name (GTK_WINDOW (dialog), MCM_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; } /* open up the preferences */ ret = g_spawn_command_line_async (BINDIR "/mcm-prefs", &error); if (!ret) { egg_warning ("failed to spawn preferences: %s", error->message); g_error_free (error); goto out; } out: if (file != NULL) g_object_unref (file); if (white != NULL) g_object_unref (white); if (red != NULL) g_object_unref (red); if (green != NULL) g_object_unref (green); if (blue != NULL) g_object_unref (blue); if (string != NULL) g_string_free (string, TRUE); if (profile != NULL) g_object_unref (profile); if (destination != NULL) g_object_unref (destination); g_strfreev (files); return retval; }