Commit 62029de8 authored by Jean-Baptiste Mardelle's avatar Jean-Baptiste Mardelle
Browse files

Move project backup files to an XDG compliant path (but still check old path for previous backups)

Ref: T2582
parent 37f0d444
......@@ -285,7 +285,6 @@ KdenliveDoc::KdenliveDoc(const QUrl &url, const QUrl &projectFolder, QUndoGroup
// Make sure that the necessary folders exist
QDir dir(m_projectFolder.path());
dir.mkdir(QStringLiteral("titles"));
dir.mkdir(QStringLiteral(".backup"));
updateProjectFolderPlacesEntry();
}
......@@ -713,7 +712,7 @@ bool KdenliveDoc::saveSceneList(const QString &path, const QString &scene)
fileName.append('-' + m_documentProperties.value(QStringLiteral("documentid")));
fileName.append(info.lastModified().toString(QStringLiteral("-yyyy-MM-dd-hh-mm")));
fileName.append(".kdenlive.png");
QDir backupFolder(m_projectFolder.path() + "/.backup");
QDir backupFolder(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/.backup"));
emit saveTimelinePreview(backupFolder.absoluteFilePath(fileName));
return true;
}
......@@ -743,7 +742,6 @@ void KdenliveDoc::setProjectFolder(QUrl url)
dir.mkpath(dir.absolutePath());
}
dir.mkdir(QStringLiteral("titles"));
dir.mkdir(QStringLiteral(".backup"));
if (KMessageBox::questionYesNo(QApplication::activeWindow(), i18n("You have changed the project folder. Do you want to copy the cached data from %1 to the new folder %2?", m_projectFolder.path(), url.path())) == KMessageBox::Yes) moveProjectData(url);
m_projectFolder = url;
......@@ -1277,8 +1275,7 @@ void KdenliveDoc::backupLastSavedVersion(const QString &path)
// Ensure backup folder exists
if (path.isEmpty()) return;
QFile file(path);
QDir backupFolder(m_projectFolder.path() + "/.backup");
QDir backupFolder(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/.backup"));
QString fileName = QUrl::fromLocalFile(path).fileName().section('.', 0, -2);
QFileInfo info(file);
fileName.append('-' + m_documentProperties.value(QStringLiteral("documentid")));
......@@ -1296,7 +1293,7 @@ void KdenliveDoc::backupLastSavedVersion(const QString &path)
void KdenliveDoc::cleanupBackupFiles()
{
QDir backupFolder(m_projectFolder.path() + "/.backup");
QDir backupFolder(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/.backup"));
QString projectFile = url().fileName().section('.', 0, -2);
projectFile.append('-' + m_documentProperties.value(QStringLiteral("documentid")));
projectFile.append("-??");
......
......@@ -22,9 +22,12 @@
#include "kdenlivesettings.h"
#include <klocalizedstring.h>
#include <QDir>
#include <QPushButton>
BackupWidget::BackupWidget(const QUrl &projectUrl, const QUrl &projectFolder, const QString &projectId, QWidget * parent) :
QDialog(parent)
, m_projectFolder(projectFolder)
{
setupUi(this);
setWindowTitle(i18n("Restore Backup File"));
......@@ -42,7 +45,6 @@ BackupWidget::BackupWidget(const QUrl &projectUrl, const QUrl &projectFolder, co
m_projectWildcard.append('*');
}
}
project_url->setUrl(projectFolder);
m_projectWildcard.append("-??");
m_projectWildcard.append("??");
m_projectWildcard.append("-??");
......@@ -52,9 +54,9 @@ BackupWidget::BackupWidget(const QUrl &projectUrl, const QUrl &projectFolder, co
slotParseBackupFiles();
connect(backup_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotDisplayBackupPreview()));
connect(project_url, SIGNAL(textChanged(QString)), this, SLOT(slotParseBackupFiles()));
backup_list->setCurrentRow(0);
backup_list->setMinimumHeight(QFontMetrics(font()).lineSpacing() * 12);
slotParseBackupFiles();
}
BackupWidget::~BackupWidget()
......@@ -64,14 +66,13 @@ BackupWidget::~BackupWidget()
void BackupWidget::slotParseBackupFiles()
{
QStringList filter;
QDir dir(project_url->url().path());
dir.cd(QStringLiteral(".backup"));
filter << m_projectWildcard;
dir.setNameFilters(filter);
QFileInfoList resultList = dir.entryInfoList(QDir::Files, QDir::Time);
QStringList results;
backup_list->clear();
// Parse new XDG backup folder $HOME/.local/share/kdenlive/.backup
QDir backupFolder(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QStringLiteral("/.backup"));
backupFolder.setNameFilters(filter);
QFileInfoList resultList = backupFolder.entryInfoList(QDir::Files, QDir::Time);
for (int i = 0; i < resultList.count(); ++i) {
QString label = resultList.at(i).lastModified().toString(Qt::SystemLocaleLongDate);
if (m_projectWildcard.startsWith(QLatin1Char('*'))) {
......@@ -80,7 +81,26 @@ void BackupWidget::slotParseBackupFiles()
}
QListWidgetItem *item = new QListWidgetItem(label, backup_list);
item->setData(Qt::UserRole, resultList.at(i).absoluteFilePath());
item->setToolTip(resultList.at(i).absoluteFilePath());
}
// Parse old $HOME/kdenlive/.backup folder
QDir dir(m_projectFolder.toLocalFile() + QStringLiteral("/.backup"));
if (dir.exists()) {
dir.setNameFilters(filter);
QFileInfoList resultList = dir.entryInfoList(QDir::Files, QDir::Time);
for (int i = 0; i < resultList.count(); ++i) {
QString label = resultList.at(i).lastModified().toString(Qt::SystemLocaleLongDate);
if (m_projectWildcard.startsWith(QLatin1Char('*'))) {
// Displaying all backup files, so add project name in the entries
label.prepend(resultList.at(i).fileName().section('-', 0, -7) + ".kdenlive - ");
}
QListWidgetItem *item = new QListWidgetItem(label, backup_list);
item->setData(Qt::UserRole, resultList.at(i).absoluteFilePath());
item->setToolTip(resultList.at(i).absoluteFilePath());
}
}
buttonBox->button(QDialogButtonBox::Open)->setEnabled(backup_list->count() > 0);
}
......
......@@ -24,7 +24,7 @@
#include "ui_backupdialog_ui.h"
#include <QUrl>
/**
* @class BackupWidget
......@@ -51,6 +51,7 @@ private slots:
private:
QString m_projectWildcard;
QUrl m_projectFolder;
};
......
......@@ -66,6 +66,11 @@ ProjectManager::ProjectManager(QObject* parent) :
m_autoSaveTimer.setSingleShot(true);
connect(&m_autoSaveTimer, SIGNAL(timeout()), this, SLOT(slotAutoSave()));
// Ensure the default data folder exist
QDir dir(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
dir.mkdir(QStringLiteral(".backup"));
dir.mkdir(QStringLiteral("titles"));
}
ProjectManager::~ProjectManager()
......
......@@ -6,40 +6,15 @@
<rect>
<x>0</x>
<y>0</y>
<width>284</width>
<height>150</height>
<width>301</width>
<height>249</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Project Folder</string>
</property>
</widget>
</item>
<item>
<widget class="KUrlRequester" name="project_url">
<property name="mode">
<set>KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly</set>
</property>
</widget>
</item>
</layout>
</item>
<item row="1" column="0" colspan="2">
<widget class="QListWidget" name="backup_list">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="backup_preview">
<property name="frameShape">
<enum>QFrame::Box</enum>
......@@ -49,7 +24,7 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="2" column="0">
<widget class="QLabel" name="info_label">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
......@@ -62,7 +37,14 @@
</property>
</widget>
</item>
<item row="3" column="1">
<item row="0" column="0" colspan="2">
<widget class="QListWidget" name="backup_list">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -74,13 +56,6 @@
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KUrlRequester</class>
<extends>QFrame</extends>
<header>kurlrequester.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
......
Supports Markdown
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