diff options
| author | houz <houz@gmx.de> | 2016-06-02 13:12:07 +0000 |
|---|---|---|
| committer | Marc Jeanmougin <marcjeanmougin@free.fr> | 2016-06-02 13:12:07 +0000 |
| commit | 86a74b4a93ab62c8ef7819dc549fe7b3ace24916 (patch) | |
| tree | 26e362218ea55b81ca775b05b7acd0d8587ea16f /src/color-profile.cpp | |
| parent | Translations. Updating all translation files. (diff) | |
| download | inkscape-86a74b4a93ab62c8ef7819dc549fe7b3ace24916.tar.gz inkscape-86a74b4a93ab62c8ef7819dc549fe7b3ace24916.zip | |
Sort color profile lists
Fixed bugs:
- https://launchpad.net/bugs/1457126
(bzr r14946)
Diffstat (limited to 'src/color-profile.cpp')
| -rw-r--r-- | src/color-profile.cpp | 83 |
1 files changed, 55 insertions, 28 deletions
diff --git a/src/color-profile.cpp b/src/color-profile.cpp index 523026aa5..9e545df03 100644 --- a/src/color-profile.cpp +++ b/src/color-profile.cpp @@ -705,7 +705,16 @@ gint Inkscape::CMSSystem::getChannelCount(ColorProfile const *profile) #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) -std::vector<Glib::ustring> ColorProfile::getBaseProfileDirs() { +// sort home dir before the rest, and alphabetically oterhwise +bool compareProfileBoolPair(const std::pair<Glib::ustring, bool> & a, const std::pair<Glib::ustring, bool> & b) +{ + if (a.second != b.second) return a.second; // a comes first iff it's home, i.e., second == true + return a.first < b.first; +} + +// the bool return value tells if it's a user's directory or a system location +// note that this will treat places under $HOME as system directories when they are found via $XDG_DATA_DIRS +std::vector<std::pair<Glib::ustring, bool> > ColorProfile::getBaseProfileDirs() { #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) static bool warnSet = false; if (!warnSet) { @@ -715,17 +724,17 @@ std::vector<Glib::ustring> ColorProfile::getBaseProfileDirs() { warnSet = true; } #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - std::vector<Glib::ustring> sources; + std::vector<std::pair<Glib::ustring, bool> > sources; // first try user's local dir gchar* path = g_build_filename(g_get_user_data_dir(), "color", "icc", NULL); - sources.push_back(path); + sources.push_back(std::make_pair(path, true)); g_free(path); const gchar* const * dataDirs = g_get_system_data_dirs(); for ( int i = 0; dataDirs[i]; i++ ) { gchar* path = g_build_filename(dataDirs[i], "color", "icc", NULL); - sources.push_back(path); + sources.push_back(std::make_pair(path, false)); g_free(path); } @@ -737,14 +746,14 @@ std::vector<Glib::ustring> ColorProfile::getBaseProfileDirs() { possible.push_back("/Library/ColorSync/Profiles"); for ( std::vector<Glib::ustring>::const_iterator it = possible.begin(); it != possible.end(); ++it ) { if ( g_file_test(it->c_str(), G_FILE_TEST_EXISTS) && g_file_test(it->c_str(), G_FILE_TEST_IS_DIR) ) { - sources.push_back(it->c_str()); + sources.push_back(std::make_pair(it->c_str(), false)); onOSX = true; } } if ( onOSX ) { gchar* path = g_build_filename(g_get_home_dir(), "Library", "ColorSync", "Profiles", NULL); if ( g_file_test(path, G_FILE_TEST_EXISTS) && g_file_test(path, G_FILE_TEST_IS_DIR) ) { - sources.push_back(path); + sources.push_back(std::make_pair(path, true)); } g_free(path); } @@ -760,12 +769,17 @@ std::vector<Glib::ustring> ColorProfile::getBaseProfileDirs() { if ( !g_utf8_validate(utf8Path, -1, NULL) ) { g_warning( "GetColorDirectoryW() resulted in invalid UTF-8" ); } else { - sources.push_back(utf8Path); + sources.push_back(std::make_pair(utf8Path, false)); } g_free( utf8Path ); } #endif // WIN32 + std::sort(sources.begin(), sources.end(), compareProfileBoolPair); + std::vector<std::pair<Glib::ustring, bool> >::iterator last = std::unique(sources.begin(), sources.end()); + sources.erase(last, sources.end()); + + return sources; } @@ -808,28 +822,28 @@ static bool isIccFile( gchar const *filepath ) return isIccFile; } -std::vector<Glib::ustring> ColorProfile::getProfileFiles() +std::vector<std::pair<Glib::ustring, bool> > ColorProfile::getProfileFiles() { - std::vector<Glib::ustring> files; + std::vector<std::pair<Glib::ustring, bool> > files; - std::list<Glib::ustring> sources; + std::list<std::pair<Glib::ustring, bool> > sources; { - std::vector<Glib::ustring> tmp = ColorProfile::getBaseProfileDirs(); + std::vector<std::pair<Glib::ustring, bool> > tmp = ColorProfile::getBaseProfileDirs(); sources.insert(sources.begin(), tmp.begin(), tmp.end()); } - for ( std::list<Glib::ustring>::const_iterator it = sources.begin(); it != sources.end(); ++it ) { - if ( g_file_test( it->c_str(), G_FILE_TEST_EXISTS ) && g_file_test( it->c_str(), G_FILE_TEST_IS_DIR ) ) { + for ( std::list<std::pair<Glib::ustring, bool> >::const_iterator it = sources.begin(); it != sources.end(); ++it ) { + if ( g_file_test( it->first.c_str(), G_FILE_TEST_EXISTS ) && g_file_test( it->first.c_str(), G_FILE_TEST_IS_DIR ) ) { GError *err = 0; - GDir *dir = g_dir_open(it->c_str(), 0, &err); + GDir *dir = g_dir_open(it->first.c_str(), 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(it->c_str(), file, NULL); + gchar *filepath = g_build_filename(it->first.c_str(), file, NULL); if ( g_file_test( filepath, G_FILE_TEST_IS_DIR ) ) { - sources.push_back( filepath ); + sources.push_back( std::make_pair(filepath, it->second) ); } else { if ( isIccFile( filepath ) ) { - files.push_back( filepath ); + files.push_back( std::make_pair(filepath, it->second) ); } } @@ -838,31 +852,44 @@ std::vector<Glib::ustring> ColorProfile::getProfileFiles() g_dir_close(dir); dir = 0; } else { - gchar *safeDir = Inkscape::IO::sanitizeString(it->c_str()); + gchar *safeDir = Inkscape::IO::sanitizeString(it->first.c_str()); g_warning(_("Color profiles directory (%s) is unavailable."), safeDir); g_free(safeDir); } } } + std::sort(files.begin(), files.end(), compareProfileBoolPair); + std::vector<std::pair<Glib::ustring, bool> >::iterator last = std::unique(files.begin(), files.end()); + files.erase(last, files.end()); + return files; } -std::vector<std::pair<Glib::ustring, Glib::ustring> > ColorProfile::getProfileFilesWithNames() +bool compareProfilePairByName(const std::pair<std::pair<Glib::ustring, bool>, Glib::ustring> & a, + const std::pair<std::pair<Glib::ustring, bool>, Glib::ustring> & b) { - std::vector<std::pair<Glib::ustring, Glib::ustring> > result; + if (a.first.second != b.first.second) return a.first.second; + return a.second < b.second; +} + +std::vector<std::pair<std::pair<Glib::ustring, bool>, Glib::ustring> > ColorProfile::getProfileFilesWithNames() +{ + std::vector<std::pair<std::pair<Glib::ustring, bool>, Glib::ustring> > result; #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) - std::vector<Glib::ustring> files = getProfileFiles(); - for ( std::vector<Glib::ustring>::const_iterator it = files.begin(); it != files.end(); ++it ) { - cmsHPROFILE hProfile = cmsOpenProfileFromFile(it->c_str(), "r"); + std::vector<std::pair<Glib::ustring, bool> > files = getProfileFiles(); + for ( std::vector<std::pair<Glib::ustring, bool> >::const_iterator it = files.begin(); it != files.end(); ++it ) { + cmsHPROFILE hProfile = cmsOpenProfileFromFile(it->first.c_str(), "r"); if ( hProfile ) { Glib::ustring name = getNameFromProfile(hProfile); result.push_back( std::make_pair(*it, name) ); cmsCloseProfile(hProfile); } } - std::sort(result.begin(), result.end()); + + std::sort(result.begin(), result.end(), compareProfilePairByName); + #endif // defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) return result; @@ -942,12 +969,12 @@ void loadProfiles() static bool profiles_searched = false; if ( !profiles_searched ) { knownProfiles.clear(); - std::vector<Glib::ustring> files = ColorProfile::getProfileFiles(); + std::vector<std::pair<Glib::ustring, bool> > files = ColorProfile::getProfileFiles(); - for ( std::vector<Glib::ustring>::const_iterator it = files.begin(); it != files.end(); ++it ) { - cmsHPROFILE prof = cmsOpenProfileFromFile( it->c_str(), "r" ); + for ( std::vector<std::pair<Glib::ustring, bool> >::const_iterator it = files.begin(); it != files.end(); ++it ) { + cmsHPROFILE prof = cmsOpenProfileFromFile( it->first.c_str(), "r" ); if ( prof ) { - ProfileInfo info( prof, Glib::filename_to_utf8( it->c_str() ) ); + ProfileInfo info( prof, Glib::filename_to_utf8( it->first.c_str() ) ); cmsCloseProfile( prof ); prof = 0; |
