Пример #1
0
AppInstancePtr
Gui::openProjectInternal(const std::string & absoluteFileName,
                         bool attemptToLoadAutosave)
{
    QFileInfo file( QString::fromUtf8( absoluteFileName.c_str() ) );

    if ( !file.exists() ) {
        return AppInstancePtr();
    }
    QString fileUnPathed = file.fileName();
    QString path = file.path() + QLatin1Char('/');


    int openedProject = appPTR->isProjectAlreadyOpened(absoluteFileName);

    if (openedProject != -1) {
        AppInstancePtr instance = appPTR->getAppInstance(openedProject);
        if (instance) {
            GuiAppInstancePtr guiApp = toGuiAppInstance(instance);
            if (guiApp) {
                guiApp->getGui()->activateWindow();

                return instance;
            }
        }
    }

    AppInstancePtr ret;
    ProjectPtr project = getApp()->getProject();
    ///if the current graph has no value, just load the project in the same window
    if ( project->isGraphWorthLess() ) {
        bool ok = project->loadProject( path, fileUnPathed, false, attemptToLoadAutosave);
        if (ok) {
            ret = _imp->_appInstance.lock();
        }
    } else {
        CLArgs cl;
        AppInstancePtr newApp = appPTR->newAppInstance(cl, false);
        bool ok  = newApp->getProject()->loadProject( path, fileUnPathed, false, attemptToLoadAutosave);
        if (ok) {
            ret = newApp;
        }
    }

    QSettings settings;
    QStringList recentFiles = settings.value( QString::fromUtf8("recentFileList") ).toStringList();
    recentFiles.removeAll( QString::fromUtf8( absoluteFileName.c_str() ) );
    recentFiles.prepend( QString::fromUtf8( absoluteFileName.c_str() ) );
    while (recentFiles.size() > NATRON_MAX_RECENT_FILES) {
        recentFiles.removeLast();
    }

    settings.setValue(QString::fromUtf8("recentFileList"), recentFiles);
    appPTR->updateAllRecentFileMenus();

    return ret;
} // Gui::openProjectInternal