bool Gui::saveProject() { ProjectPtr project = getApp()->getProject(); if ( project->hasProjectBeenSavedByUser() ) { QString projectFilename = project->getProjectFilename(); QString projectPath = project->getProjectPath(); if ( !_imp->checkProjectLockAndWarn(projectPath, projectFilename) ) { return false; } bool ret = project->saveProject(projectPath, projectFilename, 0); ///update the open recents if ( !projectPath.endsWith( QLatin1Char('/') ) ) { projectPath.append( QLatin1Char('/') ); } if (ret) { QString file = projectPath + projectFilename; updateRecentFiles(file); } return ret; } else { return saveProjectAs(); } }
void Gui::saveAndIncrVersion() { ProjectPtr project = getApp()->getProject(); QString path = project->getProjectPath(); QString name = project->getProjectFilename(); int currentVersion = 0; int positionToInsertVersion; bool mustAppendFileExtension = false; // extension is everything after the last '.' int lastDotPos = name.lastIndexOf( QLatin1Char('.') ); if (lastDotPos == -1) { positionToInsertVersion = name.size(); mustAppendFileExtension = true; } else { //Extract the current version number if any QString versionStr; int i = lastDotPos - 1; while ( i >= 0 && name.at(i).isDigit() ) { versionStr.prepend( name.at(i) ); --i; } ++i; //move back the head to the first digit if ( !versionStr.isEmpty() ) { name.remove( i, versionStr.size() ); --i; //move 1 char backward, if the char is a '_' remove it if ( (i >= 0) && ( name.at(i) == QLatin1Char('_') ) ) { name.remove(i, 1); } currentVersion = versionStr.toInt(); } positionToInsertVersion = i; } //Incr version ++currentVersion; QString newVersionStr = QString::number(currentVersion); //Add enough 0s in the beginning of the version number to have at least 3 digits int nb0s = 3 - newVersionStr.size(); nb0s = std::max(0, nb0s); QString toInsert( QLatin1Char('_') ); for (int c = 0; c < nb0s; ++c) { toInsert.append( QLatin1Char('0') ); } toInsert.append(newVersionStr); if (mustAppendFileExtension) { toInsert.append( QString::fromUtf8("." NATRON_PROJECT_FILE_EXT) ); } if ( positionToInsertVersion >= name.size() ) { name.append(toInsert); } else { name.insert(positionToInsertVersion, toInsert); } project->saveProject(path, name, 0); QString filename = path + QLatin1Char('/') + name; updateRecentFiles(filename); } // Gui::saveAndIncrVersion