| 389 | } |
| 390 | |
| 391 | bool |
| 392 | GuiApplicationManager::handleImageFileOpenRequest(const std::string& filename) |
| 393 | { |
| 394 | QString fileCopy( QString::fromUtf8( filename.c_str() ) ); |
| 395 | QString ext = QtCompat::removeFileExtension(fileCopy); |
| 396 | std::string readerFileType = appPTR->getReaderPluginIDForFileType( ext.toStdString() ); |
| 397 | AppInstancePtr mainInstance = appPTR->getTopLevelInstance(); |
| 398 | bool instanceCreated = false; |
| 399 | |
| 400 | if ( !mainInstance || !mainInstance->getProject()->isGraphWorthLess() ) { |
| 401 | CLArgs cl; |
| 402 | mainInstance = appPTR->newAppInstance(cl, false); |
| 403 | instanceCreated = true; |
| 404 | } |
| 405 | if (!mainInstance) { |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | CreateNodeArgs args(readerFileType, mainInstance->getProject() ); |
| 410 | args.addParamDefaultValue<std::string>(kOfxImageEffectFileParamName, filename); |
| 411 | args.setProperty<bool>(kCreateNodeArgsPropAddUndoRedoCommand, false); |
| 412 | args.setProperty<bool>(kCreateNodeArgsPropAutoConnect, false); |
| 413 | NodePtr readerNode = mainInstance->createNode(args); |
| 414 | if (!readerNode && instanceCreated) { |
| 415 | mainInstance->quit(); |
| 416 | |
| 417 | return false; |
| 418 | } |
| 419 | |
| 420 | ///Find and connect the viewer |
| 421 | NodesList allNodes = mainInstance->getProject()->getNodes(); |
| 422 | NodePtr viewerFound; |
| 423 | for (NodesList::iterator it = allNodes.begin(); it != allNodes.end(); ++it) { |
| 424 | if ( (*it)->isEffectViewer() ) { |
| 425 | viewerFound = *it; |
| 426 | break; |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | ///If no viewer is found, create it |
| 431 | if (!viewerFound) { |
| 432 | CreateNodeArgs args(PLUGINID_NATRON_VIEWER, mainInstance->getProject() ); |
| 433 | args.setProperty<bool>(kCreateNodeArgsPropAddUndoRedoCommand, false); |
| 434 | args.setProperty<bool>(kCreateNodeArgsPropAutoConnect, false); |
| 435 | viewerFound = mainInstance->createNode(args); |
| 436 | } |
| 437 | if (viewerFound) { |
| 438 | viewerFound->connectInput(readerNode, 0); |
| 439 | } else { |
| 440 | return false; |
| 441 | } |
| 442 | |
| 443 | return true; |
| 444 | } |
| 445 | |
| 446 | void |
| 447 | GuiApplicationManager::handleOpenFileRequest() |
no test coverage detected