Commit 8ca31313 authored by Julius Künzel's avatar Julius Künzel
Browse files

Add option to save temporary data in same folder as the project file

Fixes #1106
parent 375e01f6
Pipeline #68500 passed with stage
in 8 minutes and 49 seconds
......@@ -153,6 +153,13 @@ KdenliveSettingsDialog::KdenliveSettingsDialog(QMap<QString, QString> mappable_a
m_page8->setIcon(QIcon::fromTheme(QStringLiteral("project-defaults")));
m_configProject.projecturl->setMode(KFile::Directory);
m_configProject.projecturl->setUrl(QUrl::fromLocalFile(KdenliveSettings::defaultprojectfolder()));
connect(m_configProject.kcfg_customprojectfolder, &QCheckBox::stateChanged, this, [this](int state){
m_configProject.kcfg_sameprojectfolder->setEnabled(state == Qt::Unchecked);
});
connect(m_configProject.kcfg_sameprojectfolder, &QCheckBox::stateChanged, this, [this](int state){
m_configProject.kcfg_customprojectfolder->setEnabled(state == Qt::Unchecked);
m_configProject.projecturl->setEnabled(state == Qt::Unchecked);
});
connect(m_configProject.kcfg_videotracks, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), this, [this]() {
if (m_configProject.kcfg_videotracks->value() + m_configProject.kcfg_audiotracks->value() <= 0) {
m_configProject.kcfg_videotracks->setValue(1);
......@@ -852,7 +859,7 @@ void KdenliveSettingsDialog::slotEditImageApplication()
void KdenliveSettingsDialog::slotCheckShuttle(int state)
{
#ifdef USE_JOGSHUTTLE
m_configShuttle.config_group->setEnabled(state != 0);
m_configShuttle.config_group->setEnabled(state != Qt::Unchecked);
m_configShuttle.shuttledevicelist->clear();
QStringList devNames = KdenliveSettings::shuttledevicenames();
......@@ -864,7 +871,7 @@ void KdenliveSettingsDialog::slotCheckShuttle(int state)
for (int i = 0; i < devNames.count(); ++i) {
m_configShuttle.shuttledevicelist->addItem(devNames.at(i), devPaths.at(i));
}
if (state != 0) {
if (state != Qt::Unchecked) {
setupJogshuttleBtns(m_configShuttle.shuttledevicelist->itemData(m_configShuttle.shuttledevicelist->currentIndex()).toString());
}
#else
......
......@@ -534,6 +534,11 @@
<default>false</default>
</entry>
<entry name="sameprojectfolder" type="Bool">
<label>Use the parent folder of the *.kdenlive file to store project files.</label>
<default>false</default>
</entry>
<entry name="capturetoprojectfolder" type="Bool">
<label>Save captured files to project folder by default.</label>
<default>true</default>
......
......@@ -2055,6 +2055,10 @@ void MainWindow::slotEditProjectSettings()
project->setMetadata(w->metadata());
}
QString newProjectFolder = w->storageFolder();
if(w->docFolderAsStorageFolder()) {
newProjectFolder = QFileInfo(project->url().toLocalFile()).absolutePath() + QStringLiteral("/cachefiles");
}
if (newProjectFolder.isEmpty()) {
newProjectFolder = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
}
......
......@@ -81,6 +81,14 @@ ProjectSettings::ProjectSettings(KdenliveDoc *doc, QMap<QString, QString> metada
list_search->setTreeWidget(files_list);
project_folder->setMode(KFile::Directory);
connect(custom_folder, &QCheckBox::toggled, this, [this](bool checked) {
same_folder->setEnabled(!checked);
});
connect(same_folder, &QCheckBox::toggled, this, [this](bool checked) {
custom_folder->setEnabled(!checked);
project_folder->setEnabled(!checked && custom_folder->isChecked());
});
m_buttonOk = buttonBox->button(QDialogButtonBox::Ok);
// buttonOk->setEnabled(false);
audio_thumbs->setChecked(KdenliveSettings::audiothumbnails());
......@@ -125,7 +133,9 @@ ProjectSettings::ProjectSettings(KdenliveDoc *doc, QMap<QString, QString> metada
m_previewparams = doc->getDocumentProperty(QStringLiteral("previewparameters"));
m_previewextension = doc->getDocumentProperty(QStringLiteral("previewextension"));
QString storageFolder = doc->getDocumentProperty(QStringLiteral("storagefolder"));
if (!storageFolder.isEmpty()) {
if(doc->projectTempFolder() == (QFileInfo(doc->url().toLocalFile()).absolutePath() + QStringLiteral("/cachefiles"))) {
same_folder->setChecked(true);
} else if (!storageFolder.isEmpty()) {
custom_folder->setChecked(true);
}
project_folder->setUrl(QUrl::fromLocalFile(doc->projectTempFolder()));
......@@ -150,7 +160,15 @@ ProjectSettings::ProjectSettings(KdenliveDoc *doc, QMap<QString, QString> metada
m_previewextension = KdenliveSettings::previewextension();
custom_folder->setChecked(KdenliveSettings::customprojectfolder());
project_folder->setUrl(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::CacheLocation)));
same_folder->setChecked(KdenliveSettings::sameprojectfolder());
/* creating a new project we can't use the same folder option as we don't know the path of the project yet.
* If the the option is enabled in the default projec settings, we have disable the custom folder option
* and move the files to the new location as soon as the project is saved for the first time
*/
same_folder->setEnabled(false);
custom_folder->setEnabled(!KdenliveSettings::sameprojectfolder());
}
// Select profile
m_pw->loadProfile(currentProf);
......@@ -529,6 +547,11 @@ bool ProjectSettings::generateImageProxy() const
return generate_imageproxy->isChecked();
}
bool ProjectSettings::docFolderAsStorageFolder() const
{
return same_folder->isChecked();
}
int ProjectSettings::proxyMinSize() const
{
return proxy_minsize->value();
......
......@@ -44,6 +44,7 @@ public:
bool useProxy() const;
bool useExternalProxy() const;
bool generateProxy() const;
bool docFolderAsStorageFolder() const;
int proxyMinSize() const;
bool generateImageProxy() const;
int proxyImageMinSize() const;
......
......@@ -297,6 +297,11 @@ bool ProjectManager::closeCurrentDocument(bool saveChanges, bool quit)
bool ProjectManager::saveFileAs(const QString &outputFileName, bool saveACopy)
{
pCore->monitorManager()->pauseActiveMonitor();
QString oldProjectFolder = m_project->url().isEmpty()
? QString()
: QFileInfo(m_project->url().toLocalFile()).absolutePath() + QStringLiteral("/cachefiles");
// this was the old project folder in case the "save in project file location" setting was active
// Sync document properties
if (!saveACopy && outputFileName != m_project->url().toLocalFile()) {
// Project filename changed
......@@ -346,6 +351,32 @@ bool ProjectManager::saveFileAs(const QString &outputFileName, bool saveACopy)
if (!saveACopy) {
m_fileRevert->setEnabled(true);
pCore->window()->m_undoView->stack()->setClean();
QString newProjectFolder(saveFolder + QStringLiteral("/cachefiles"));
if(((oldProjectFolder.isEmpty() && KdenliveSettings::sameprojectfolder()) || m_project->projectTempFolder() == oldProjectFolder) && newProjectFolder != m_project->projectTempFolder()) {
KMessageBox::ButtonCode answer = KMessageBox::warningContinueCancel(
pCore->window(), i18n("The location of the project file changed. You selected to use the location of the project file to save temporary files. "
"This will move all temporary files from <b>%1</b> to <b>%2</b>, the project file will then be reloaded",
m_project->projectTempFolder(), newProjectFolder));
if (answer == KMessageBox::Continue) {
// Proceed with move
QString documentId = QDir::cleanPath(m_project->getDocumentProperty(QStringLiteral("documentid")));
bool ok;
documentId.toLongLong(&ok, 10);
if (!ok || documentId.isEmpty()) {
KMessageBox::sorry(pCore->window(), i18n("Cannot perform operation, invalid document id: %1", documentId));
} else {
QDir newDir(newProjectFolder);
QDir oldDir(m_project->projectTempFolder());
if (newDir.exists(documentId)) {
KMessageBox::sorry(pCore->window(), i18n("Cannot perform operation, target directory already exists: %1", newDir.absoluteFilePath(documentId)));
} else {
// Proceed with the move
pCore->projectManager()->moveProjectData(oldDir.absoluteFilePath(documentId), newDir.absolutePath());
}
}
}
}
}
return true;
......
......@@ -24,13 +24,7 @@
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QSpinBox" name="kcfg_audiotracks"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="kcfg_videotracks"/>
</item>
<item row="5" column="0" colspan="7">
<item row="7" column="0" colspan="7">
<widget class="QPlainTextEdit" name="previewparams">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
......@@ -43,32 +37,45 @@
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_7">
<item row="1" column="3">
<widget class="QSpinBox" name="kcfg_audiotracks"/>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label">
<property name="text">
<string>Audio tracks</string>
<string>Audio channels</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="7">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item row="1" column="5">
<widget class="QComboBox" name="kcfg_audio_channels">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<widget class="QCheckBox" name="kcfg_customprojectfolder">
<property name="text">
<string>Custom project folder</string>
</property>
</widget>
<property name="text">
<string>2 channels (stereo)</string>
</property>
</item>
<item>
<widget class="KUrlRequester" name="projecturl" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
<property name="text">
<string>4 channels</string>
</property>
</item>
</layout>
<item>
<property name="text">
<string>6 channels</string>
</property>
</item>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="kcfg_videotracks"/>
</item>
<item row="4" column="0" colspan="7">
<item row="6" column="0" colspan="7">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_25">
......@@ -112,6 +119,13 @@
</item>
</layout>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Audio tracks</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
......@@ -119,7 +133,7 @@
</property>
</widget>
</item>
<item row="6" column="0">
<item row="8" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -132,36 +146,29 @@
</property>
</spacer>
</item>
<item row="1" column="4">
<widget class="QLabel" name="label">
<property name="text">
<string>Audio channels</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QComboBox" name="kcfg_audio_channels">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item>
<property name="text">
<string>2 channels (stereo)</string>
</property>
</item>
<item row="2" column="0" colspan="6">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<property name="text">
<string>4 channels</string>
</property>
<widget class="QCheckBox" name="kcfg_customprojectfolder">
<property name="text">
<string>Custom project folder</string>
</property>
</widget>
</item>
<item>
<property name="text">
<string>6 channels</string>
</property>
<widget class="KUrlRequester" name="projecturl" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0" colspan="6">
<widget class="QCheckBox" name="kcfg_sameprojectfolder">
<property name="text">
<string>Use parent folder of the project file as project folder</string>
</property>
</widget>
</item>
</layout>
......
......@@ -27,52 +27,34 @@
<string>Settings</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="4" column="0">
<item row="7" column="0" colspan="4">
<widget class="QPlainTextEdit" name="previewparams">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Thumbnails:</string>
</property>
</widget>
</item>
<item row="4" column="2">
<item row="5" column="2">
<widget class="QCheckBox" name="audio_thumbs">
<property name="text">
<string>Audio</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="custom_folder">
<property name="text">
<string>Custom project folder</string>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="project_folder">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="4">
<widget class="QGroupBox" name="profile_box">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<item row="4" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_7">
......@@ -128,15 +110,28 @@
</item>
</layout>
</item>
<item row="6" column="0" colspan="4">
<widget class="QPlainTextEdit" name="previewparams">
<item row="5" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>229</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0" colspan="4">
<widget class="QGroupBox" name="profile_box">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Maximum">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="readOnly">
<property name="flat">
<bool>true</bool>
</property>
</widget>
......@@ -148,27 +143,14 @@
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="QCheckBox" name="video_thumbs">
<property name="text">
<string>Video</string>
</property>
</widget>
</item>
<item row="4" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>229</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="0" colspan="4">
<item row="6" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_25">
......@@ -212,6 +194,31 @@
</item>
</layout>
</item>
<item row="1" column="0" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QCheckBox" name="custom_folder">
<property name="text">
<string>Custom project folder</string>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="project_folder" native="true">
<property name="enabled">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item row="2" column="0" colspan="4">
<widget class="QCheckBox" name="same_folder">
<property name="text">
<string>Use parent folder of the project file as project folder</string>
</property>
</widget>
</item>
</layout>
<zorder>label_4</zorder>
<zorder>profile_box</zorder>
......@@ -219,6 +226,7 @@
<zorder>video_thumbs</zorder>
<zorder>audio_thumbs</zorder>
<zorder>previewparams</zorder>
<zorder>same_folder</zorder>
</widget>
<widget class="QWidget" name="tab_4">
<attribute name="title">
......@@ -642,17 +650,17 @@
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KUrlRequester</class>
<extends>QWidget</extends>
<header>kurlrequester.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KComboBox</class>
<extends>QComboBox</extends>
<header>kcombobox.h</header>
</customwidget>
<customwidget>
<class>KTreeWidgetSearchLine</class>
<extends>QLineEdit</extends>
......
  • Awesome! Has a small bug, should I reopen the ticket?

    Thank you!

    And if this checkbox could remember it's state would also be helpful. As if I select it on a new project, it would stay active in new projects until I toggle it. I would leave it always on, since I like to keep project files all in their folders.

    Edited by Bruno Santos
  • @bsantos Thanks for the hint, will fix it. In general the option can not be changed for a new project individually because it is code-wise difficult to implement (so it is wrong that the option get enabled after toggling the other checkbox).

    However your workflow is still possible because you can set a default option that will than be used for each new project: go to Settings > Configure Kdenlive… > Project Defaults and enable the option there and the data will be moved as soon as you save the project for the first time.

    Edited by Julius Künzel
  • Okay, I think I found a solution to implement it for new projects too. Forget what I said in the first paragraph of my previous comment…

    But to remember the state Settings > Configure Kdenlive… > Project Defaults is still the way to go. This is how it works for the other parameters too.

  • Perfect, hadn't seen it in the kdenlive settings yet. Thank you very much @jlskuz !

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