From f4f363e00f5db7462fde1b988be156d80d02f502 Mon Sep 17 00:00:00 2001 From: joncruz Date: Mon, 1 Oct 2007 03:55:20 +0000 Subject: [PATCH] Added searching for icc profiles in standard locations, and preference to combo box. --- src/color-profile-fns.h | 6 ++ src/color-profile.cpp | 120 +++++++++++++++++++++++++ src/ui/dialog/inkscape-preferences.cpp | 35 +++++++- src/ui/dialog/inkscape-preferences.h | 4 +- 4 files changed, 159 insertions(+), 6 deletions(-) diff --git a/src/color-profile-fns.h b/src/color-profile-fns.h index 21e6002ee..93d327f42 100644 --- a/src/color-profile-fns.h +++ b/src/color-profile-fns.h @@ -8,6 +8,8 @@ #include #include #if ENABLE_LCMS +#include +#include #include #endif // ENABLE_LCMS @@ -29,6 +31,10 @@ cmsHPROFILE colorprofile_get_handle( SPDocument* document, guint* intent, gchar cmsHPROFILE colorprofile_get_system_profile_handle(); +std::vector colorprofile_get_display_names(); + +Glib::ustring get_path_for_profile(Glib::ustring const& name); + #endif } // namespace Inkscape diff --git a/src/color-profile.cpp b/src/color-profile.cpp index dbd212bd6..03a975a0c 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -369,12 +369,132 @@ cmsHPROFILE Inkscape::colorprofile_get_handle( SPDocument* document, guint* inte } +#include + +class ProfileInfo +{ +public: + ProfileInfo( cmsHPROFILE, Glib::ustring const & path ); + + Glib::ustring const& getName() {return _name;} + Glib::ustring const& getPath() {return _path;} + icColorSpaceSignature getSpace() {return _profileSpace;} + icProfileClassSignature getClass() {return _profileClass;} + +private: + Glib::ustring _path; + Glib::ustring _name; + icColorSpaceSignature _profileSpace; + icProfileClassSignature _profileClass; +}; + + +ProfileInfo::ProfileInfo( cmsHPROFILE prof, Glib::ustring const & path ) +{ + _path = path; + _name = cmsTakeProductName(prof); + _profileSpace = cmsGetColorSpace( prof ); + _profileClass = cmsGetDeviceClass( prof ); +} + + + +static std::vector knownProfiles; + +std::vector Inkscape::colorprofile_get_display_names() +{ + std::vector result; + + for ( std::vector::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) { + if ( it->getClass() == icSigDisplayClass && it->getSpace() == icSigRgbData ) { + result.push_back( it->getName() ); + } + } + + return result; +} + +Glib::ustring Inkscape::get_path_for_profile(Glib::ustring const& name) +{ + Glib::ustring result; + + for ( std::vector::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) { + if ( name == it->getName() ) { + result = it->getPath(); + break; + } + } + + return result; +} + +static void findThings() { + std::list sources; + + gchar* base = profile_path("XXX"); + { + gchar* base2 = g_path_get_dirname(base); + g_free(base); + base = base2; + base2 = g_path_get_dirname(base); + g_free(base); + base = base2; + } + + sources.push_back(g_build_filename( base, ".color", "icc", NULL )); // first try user's local dir + sources.push_back(g_strdup("/usr/local/share/color/icc")); + sources.push_back(g_strdup("/usr/share/color/icc")); + + while (!sources.empty()) { + gchar *dirname = sources.front(); + if ( Inkscape::IO::file_test( dirname, (GFileTest)(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) ) ) { + GError *err = 0; + GDir *dir = g_dir_open(dirname, 0, &err); + + if (dir) { + for (gchar const *file = g_dir_read_name(dir); file != NULL; file = g_dir_read_name(dir)) { + gchar *filepath = g_build_filename(dirname, file, NULL); + cmsHPROFILE prof = cmsOpenProfileFromFile( filepath, "r" ); + if ( prof ) { + ProfileInfo info( prof, Glib::filename_to_utf8( filepath ) ); + cmsCloseProfile( prof ); + + bool sameName = false; + for ( std::vector::iterator it = knownProfiles.begin(); it != knownProfiles.end(); ++it ) { + if ( it->getName() == info.getName() ) { + sameName = true; + break; + } + } + + if ( !sameName ) { + knownProfiles.push_back(info); + } + } + + g_free(filepath); + } + } + } + + // toss the dirname + g_free(dirname); + sources.pop_front(); + } +} + cmsHPROFILE Inkscape::colorprofile_get_system_profile_handle() { static cmsHPROFILE theOne = 0; static std::string lastURI; + static bool init = false; + if ( !init ) { + findThings(); + init = true; + } + long long int which = prefs_get_int_attribute_limited( "options.displayprofile", "enable", 0, 0, 1 ); gchar const * uri = prefs_get_string_attribute("options.displayprofile", "uri"); diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp index 436d5cce6..59132349f 100644 --- a/src/ui/dialog/inkscape-preferences.cpp +++ b/src/ui/dialog/inkscape-preferences.cpp @@ -37,6 +37,7 @@ #include "xml/repr.h" #include "ui/widget/style-swatch.h" #include "display/nr-filter-gaussian.h" +#include "color-profile-fns.h" namespace Inkscape { namespace UI { @@ -632,8 +633,20 @@ static void forceUpdates() { (*it)->requestRedraw(); } } + +static void profileComboChanged( Gtk::ComboBoxText* combo ) +{ + Glib::ustring active = combo->get_active_text(); + + Glib::ustring path = get_path_for_profile(active); + if ( !path.empty() ) { + prefs_set_string_attribute( "options.displayprofile", "uri", path.c_str() ); + forceUpdates(); + } +} #endif // ENABLE_LCMS + void InkscapePreferences::initPageMisc() { _misc_comment.init( _("Add label comments to printing output"), "printing.debug", "show-label-comments", false); @@ -647,14 +660,28 @@ void InkscapePreferences::initPageMisc() _misc_cms_display.init( _("Enable display calibration"), "options.displayprofile", "enable", false); _page_misc.add_line( false, "", _misc_cms_display, "", _("Enables application of the display using an ICC profile."), true); - _misc_cms_display_profile.init("options.displayprofile", "uri"); + _page_misc.add_line( false, _("Display profile:"), _misc_cms_display_profile, "", - _("The ICC profile to use to calibrate display output."), true); + _("The ICC profile to use to calibrate display output."), true); #if ENABLE_LCMS - _misc_cms_display.signal_toggled().connect( sigc::ptr_fun(forceUpdates) ); + { + std::vector names = ::Inkscape::colorprofile_get_display_names(); + Glib::ustring current = prefs_get_string_attribute( "options.displayprofile", "uri" ); + + gint index = 0; + for ( std::vector::iterator it = names.begin(); it != names.end(); ++it ) { + _misc_cms_display_profile.append_text( *it ); + Glib::ustring path = get_path_for_profile(*it); + if ( !path.empty() && path == current ) { + _misc_cms_display_profile.set_active(index); + } + index++; + } + } - _misc_cms_display_profile.signal_selection_changed().connect( sigc::ptr_fun(forceUpdates) ); + _misc_cms_display.signal_toggled().connect( sigc::ptr_fun(forceUpdates) ); + _misc_cms_display_profile.signal_changed().connect( sigc::bind( sigc::ptr_fun(profileComboChanged), &_misc_cms_display_profile) ); #else // disable it, but leave it visible _misc_cms_display.set_sensitive( false ); diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h index eff068569..5dafd4051 100644 --- a/src/ui/dialog/inkscape-preferences.h +++ b/src/ui/dialog/inkscape-preferences.h @@ -162,8 +162,8 @@ protected: PrefCheckButton _misc_small_toolbar; PrefCombo _misc_overs_bitmap; - PrefCheckButton _misc_cms_display; - PrefFileButton _misc_cms_display_profile; + PrefCheckButton _misc_cms_display; + Gtk::ComboBoxText _misc_cms_display_profile; PrefEntryButtonHBox _importexport_ocal_url; PrefEntry _importexport_ocal_username; -- 2.30.2