| 2166 | } // restoreSettings |
| 2167 | |
| 2168 | bool |
| 2169 | Settings::tryLoadOpenColorIOConfig() |
| 2170 | { |
| 2171 | // the default value is the environment variable "OCIO" |
| 2172 | QString configFile = QFile::decodeName( qgetenv(NATRON_OCIO_ENV_VAR_NAME) ); |
| 2173 | |
| 2174 | // OCIO environment variable overrides everything, then try the custom config... |
| 2175 | if ( configFile.isEmpty() && _customOcioConfigFile->isEnabled(0) ) { |
| 2176 | ///try to load from the file |
| 2177 | std::string file; |
| 2178 | try { |
| 2179 | file = _customOcioConfigFile->getValue(); |
| 2180 | } catch (...) { |
| 2181 | // ignore exceptions |
| 2182 | } |
| 2183 | if ( file.empty() ) { |
| 2184 | return false; |
| 2185 | } |
| 2186 | configFile = QString::fromUtf8( file.c_str() ); |
| 2187 | } |
| 2188 | if ( !configFile.isEmpty() ) { |
| 2189 | if ( !QFile::exists(configFile) ) { |
| 2190 | Dialogs::errorDialog( "OpenColorIO", tr("%1: No such file.").arg(configFile).toStdString() ); |
| 2191 | |
| 2192 | return false; |
| 2193 | } |
| 2194 | } else { |
| 2195 | // ... and finally try the setting from the choice menu. |
| 2196 | try { |
| 2197 | ///try to load from the combobox |
| 2198 | QString activeEntryText = QString::fromUtf8( _ocioConfigKnob->getActiveEntry().id.c_str() ); |
| 2199 | QString configFileName = QString( activeEntryText + QString::fromUtf8(".ocio") ); |
| 2200 | QStringList defaultConfigsPaths = getDefaultOcioConfigPaths(); |
| 2201 | Q_FOREACH(const QString &defaultConfigsDirStr, defaultConfigsPaths) { |
| 2202 | QDir defaultConfigsDir(defaultConfigsDirStr); |
| 2203 | |
| 2204 | if ( !defaultConfigsDir.exists() ) { |
| 2205 | qDebug() << "Attempt to read an OpenColorIO configuration but the configuration directory" |
| 2206 | << defaultConfigsDirStr << "does not exist."; |
| 2207 | continue; |
| 2208 | } |
| 2209 | ///try to open the .ocio config file first in the defaultConfigsDir |
| 2210 | ///if we can't find it, try to look in a subdirectory with the name of the config for the file config.ocio |
| 2211 | if ( !defaultConfigsDir.exists(configFileName) ) { |
| 2212 | QDir subDir(defaultConfigsDirStr + QDir::separator() + activeEntryText); |
| 2213 | if ( !subDir.exists() ) { |
| 2214 | Dialogs::errorDialog( "OpenColorIO", tr("%1: No such file or directory.").arg( subDir.absoluteFilePath( QString::fromUtf8("config.ocio") ) ).toStdString() ); |
| 2215 | |
| 2216 | return false; |
| 2217 | } |
| 2218 | if ( !subDir.exists( QString::fromUtf8("config.ocio") ) ) { |
| 2219 | Dialogs::errorDialog( "OpenColorIO", tr("%1: No such file or directory.").arg( subDir.absoluteFilePath( QString::fromUtf8("config.ocio") ) ).toStdString() ); |
| 2220 | |
| 2221 | return false; |
| 2222 | } |
| 2223 | configFile = subDir.absoluteFilePath( QString::fromUtf8("config.ocio") ); |
| 2224 | } else { |
| 2225 | configFile = defaultConfigsDir.absoluteFilePath(configFileName); |
nothing calls this directly
no test coverage detected