Commit 0c5e4ea1 authored by Julius Künzel's avatar Julius Künzel Committed by Simon Eugster

Add a "Save Copy…" action to save a project copy

Closes #560
MR: !109
parent c2da5e08
Pipeline #20765 passed with stage
in 9 minutes and 16 seconds
......@@ -2,6 +2,11 @@
<kpartgui name="kdenlive" version="181" translationDomain="kdenlive">
Please register or sign in to reply
<MenuBar>
<Menu name="file" >
<Action name="file_save"/>
<Action name="file_save_as"/>
<Action name="file_save_copy"/>
<Action name="file_revert"/>
<Separator />
<Action name="dvd_wizard" />
<Action name="transcode_clip" />
<Action name="export_project" />
......
......@@ -78,6 +78,10 @@ ProjectManager::ProjectManager(QObject *parent)
a->setIcon(QIcon::fromTheme(QStringLiteral("document-new")));
m_recentFilesAction = KStandardAction::openRecent(this, SLOT(openFile(QUrl)), pCore->window()->actionCollection());
QAction *saveCopyAction = new QAction(QIcon::fromTheme(QStringLiteral("document-save-as")), i18n("Save Copy…"), this);
pCore->window()->addAction(QStringLiteral("file_save_copy"), saveCopyAction);
connect(saveCopyAction, &QAction::triggered, this, [this]{ saveFileAs(true); });
QAction *backupAction = new QAction(QIcon::fromTheme(QStringLiteral("edit-undo")), i18n("Open Backup File"), this);
pCore->window()->addAction(QStringLiteral("open_backup"), backupAction);
connect(backupAction, SIGNAL(triggered(bool)), SLOT(slotOpenBackup()));
......@@ -298,7 +302,7 @@ bool ProjectManager::closeCurrentDocument(bool saveChanges, bool quit)
return true;
}
bool ProjectManager::saveFileAs(const QString &outputFileName)
bool ProjectManager::saveFileAs(const QString &outputFileName, bool saveACopy)
{
pCore->monitorManager()->pauseActiveMonitor();
// Sync document properties
......@@ -319,29 +323,33 @@ bool ProjectManager::saveFileAs(const QString &outputFileName)
// Save timeline thumbnails
QStringList thumbKeys = pCore->window()->getMainTimeline()->controller()->getThumbKeys();
ThumbnailCache::get()->saveCachedThumbs(thumbKeys);
m_project->setUrl(url);
// setting up autosave file in ~/.kde/data/stalefiles/kdenlive/
// saved under file name
// actual saving by KdenliveDoc::slotAutoSave() called by a timer 3 seconds after the document has been edited
// This timer is set by KdenliveDoc::setModified()
const QString projectId = QCryptographicHash::hash(url.fileName().toUtf8(), QCryptographicHash::Md5).toHex();
QUrl autosaveUrl = QUrl::fromLocalFile(QFileInfo(outputFileName).absoluteDir().absoluteFilePath(projectId + QStringLiteral(".kdenlive")));
if (m_project->m_autosave == nullptr) {
// The temporary file is not opened or created until actually needed.
// The file filename does not have to exist for KAutoSaveFile to be constructed (if it exists, it will not be touched).
m_project->m_autosave = new KAutoSaveFile(autosaveUrl, m_project);
} else {
m_project->m_autosave->setManagedFile(autosaveUrl);
}
if (!saveACopy) {
m_project->setUrl(url);
// setting up autosave file in ~/.kde/data/stalefiles/kdenlive/
// saved under file name
// actual saving by KdenliveDoc::slotAutoSave() called by a timer 3 seconds after the document has been edited
// This timer is set by KdenliveDoc::setModified()
const QString projectId = QCryptographicHash::hash(url.fileName().toUtf8(), QCryptographicHash::Md5).toHex();
QUrl autosaveUrl = QUrl::fromLocalFile(QFileInfo(outputFileName).absoluteDir().absoluteFilePath(projectId + QStringLiteral(".kdenlive")));
if (m_project->m_autosave == nullptr) {
// The temporary file is not opened or created until actually needed.
// The file filename does not have to exist for KAutoSaveFile to be constructed (if it exists, it will not be touched).
m_project->m_autosave = new KAutoSaveFile(autosaveUrl, m_project);
} else {
m_project->m_autosave->setManagedFile(autosaveUrl);
}
pCore->window()->setWindowTitle(m_project->description());
m_project->setModified(false);
pCore->window()->setWindowTitle(m_project->description());
m_project->setModified(false);
}
m_recentFilesAction->addUrl(url);
// remember folder for next project opening
KRecentDirs::add(QStringLiteral(":KdenliveProjectsFolder"), saveFolder);
saveRecentFiles();
m_fileRevert->setEnabled(true);
pCore->window()->m_undoView->stack()->setClean();
if (!saveACopy) {
m_fileRevert->setEnabled(true);
pCore->window()->m_undoView->stack()->setClean();
}
return true;
}
......@@ -353,9 +361,12 @@ void ProjectManager::saveRecentFiles()
config->sync();
}
bool ProjectManager::saveFileAs()
bool ProjectManager::saveFileAs(bool saveACopy)
{
QFileDialog fd(pCore->window());
if (saveACopy) {
fd.setWindowTitle(i18n("Save Copy"));
}
fd.setDirectory(m_project->url().isValid() ? m_project->url().adjusted(QUrl::RemoveFilename).toLocalFile() : KdenliveSettings::defaultprojectfolder());
fd.setNameFilter(getProjectNameFilters(false));
fd.setAcceptMode(QFileDialog::AcceptSave);
......@@ -374,7 +385,7 @@ bool ProjectManager::saveFileAs()
file.open(QIODevice::ReadWrite | QIODevice::Text);
file.close();
}
return saveFileAs(outputFile);
return saveFileAs(outputFile, saveACopy);
}
bool ProjectManager::saveFile()
......
......@@ -111,16 +111,19 @@ public slots:
bool saveFile();
/** @brief Shows a save file dialog for saving the project.
* @param saveACopy Default is false. If true, the file title of the dialog is set to "Save Copy…"
* @return Whether the file was saved. */
bool saveFileAs();
bool saveFileAs(bool saveACopy = false);
/** @brief Set properties to match outputFileName and save the document.
* Creates an autosave version of the output file too, at
* Creates an autosave version of the output file too (only if not in copymode), at
* ~/.kde/data/stalefiles/kdenlive/ \n
* that will be actually written in KdenliveDoc::slotAutoSave()
* @param outputFileName The URL to save to / The document's URL.
* @param saveACopy Default is false. If true, the file will be saved but isn’t opened afterwards. Besides no autosave version will be created
* @return Whether we had success. */
bool saveFileAs(const QString &outputFileName);
bool saveFileAs(const QString &outputFileName, bool saveACopy = false);
/** @brief Close currently opened document. Returns false if something went wrong (cannot save modifications, ...). */
bool closeCurrentDocument(bool saveChanges = true, bool quit = false);
......
  • "Save copy" doesn't appear under file.

  • Really? Windows issue maybe? It works on Linux!

  • It is likely, that the version number in kdenliveui.rc is wrong (caused by another commit: dc6568b9). See comment on the file…

    Edited by Julius Künzel
  • I think it is the easiest way if someone with write access changes this or should i open a MR?

  • Fixed, sorry, I missed that when merging!

  • Fixed. Save copy appears and works and is included in the shortcut list.

    Question:
    Could we put the actual file name into the file name field as proposal?
    Even with a counter like Blender #560 (comment 30218)?

  • I am looking on this contribution as a first step on the save copy function. Counter like blender would be nice. By time i could try to do this, if no one else did until then.

    Edited by Julius Künzel
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment