| 2226 | } |
| 2227 | |
| 2228 | Plugin* |
| 2229 | AppManager::getPluginBinary(const QString & pluginId, |
| 2230 | int majorVersion, |
| 2231 | int minorVersion, |
| 2232 | bool convertToLowerCase) const |
| 2233 | { |
| 2234 | Q_UNUSED(minorVersion); |
| 2235 | |
| 2236 | PluginsMap::const_iterator foundID = _imp->_plugins.find( pluginId.toStdString() ); |
| 2237 | if ( convertToLowerCase && foundID == _imp->_plugins.end() ) { |
| 2238 | foundID = _imp->_plugins.end(); |
| 2239 | for (PluginsMap::const_iterator it = _imp->_plugins.begin(); it != _imp->_plugins.end(); ++it) { |
| 2240 | QString pID = QString::fromUtf8( it->first.c_str() ); |
| 2241 | if ( !pluginId.startsWith( QString::fromUtf8(NATRON_ORGANIZATION_DOMAIN_TOPLEVEL "." NATRON_ORGANIZATION_DOMAIN_SUB ".built-in.") ) ) { |
| 2242 | QString lowerCase = pID.toLower(); |
| 2243 | if (lowerCase == pluginId) { |
| 2244 | foundID = it; |
| 2245 | break; |
| 2246 | } |
| 2247 | } |
| 2248 | } |
| 2249 | } |
| 2250 | |
| 2251 | if ( foundID != _imp->_plugins.end() ) { |
| 2252 | assert( !foundID->second.empty() ); |
| 2253 | |
| 2254 | // see also OFX::Host::PluginCache::getPluginById() |
| 2255 | // see also AppManager::getPluginBinaryFromOldID() |
| 2256 | |
| 2257 | if (majorVersion == -1) { |
| 2258 | // -1 means we want to load the highest version existing |
| 2259 | return *foundID->second.rbegin(); |
| 2260 | } |
| 2261 | |
| 2262 | // Let's be a bit smarter than HostSupport. |
| 2263 | // The best compatible plugin is, by order of preference |
| 2264 | // - the plugin with the same major version and the highest minor |
| 2265 | // - the plugin with the closest major above and the highest minor |
| 2266 | // - the plugin with the highest major and the highest minor |
| 2267 | // |
| 2268 | // For example, if versions (1,0) (1,2) (3,1) (3,4) (4,2) are available, |
| 2269 | // - asking for (1,0) returns (1,2) |
| 2270 | // - asking for (2,7) returns (3,4) |
| 2271 | // - asking for (3,1) returns (3,4) |
| 2272 | // - asking for (6,0) returns (4,2) |
| 2273 | |
| 2274 | // Try to find the exact major version, with the highest minor |
| 2275 | // (thus the reverse iterator) |
| 2276 | Plugin* nextPlugin = *(foundID->second.rbegin()); |
| 2277 | int nextVersion = nextPlugin->getMajorVersion(); |
| 2278 | for (PluginVersionsOrdered::const_reverse_iterator itver = foundID->second.rbegin(); itver != foundID->second.rend(); ++itver) { |
| 2279 | int thisMajorVersion = (*itver)->getMajorVersion(); |
| 2280 | if (thisMajorVersion == majorVersion) { |
| 2281 | return *itver; |
| 2282 | } else if (thisMajorVersion > majorVersion && |
| 2283 | thisMajorVersion < nextVersion) { |
| 2284 | nextPlugin = *itver; |
| 2285 | nextVersion = thisMajorVersion; |