From aaab2912338a721bba2d2ac97b7c566dfb5f194b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Mardelle Date: Sun, 8 Jan 2012 18:31:06 +0100 Subject: [PATCH] Fix KAutosave not managing long filenames or non UTF-8 on some systems: http://kdenlive.org/mantis/view.php?id=2441 http://kdenlive.org/mantis/view.php?id=2450 --- src/mainwindow.cpp | 21 ++++++++++++--------- src/mainwindow.h | 2 +- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 76e8ba25..ef8f4d9c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1973,9 +1973,10 @@ bool MainWindow::saveFileAs(const QString &outputFileName) // Save timeline thumbnails m_activeTimeline->projectView()->saveThumbnails(); m_activeDocument->setUrl(KUrl(outputFileName)); + QByteArray hash = QCryptographicHash::hash(KUrl(outputFileName).encodedPath(), QCryptographicHash::Md5).toHex(); if (m_activeDocument->m_autosave == NULL) { - m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(outputFileName), this); - } else m_activeDocument->m_autosave->setManagedFile(KUrl(outputFileName)); + m_activeDocument->m_autosave = new KAutoSaveFile(KUrl(hash), this); + } else m_activeDocument->m_autosave->setManagedFile(KUrl(hash)); setCaption(m_activeDocument->description()); m_timelineArea->setTabText(m_timelineArea->currentIndex(), m_activeDocument->description()); m_timelineArea->setTabToolTip(m_timelineArea->currentIndex(), m_activeDocument->url().path()); @@ -2072,13 +2073,14 @@ void MainWindow::openFile(const KUrl &url) if (!KdenliveSettings::activatetabs()) if (!closeCurrentDocument()) return; // Check for backup file - QList staleFiles = KAutoSaveFile::staleFiles(url); + QByteArray hash = QCryptographicHash::hash(url.encodedPath(), QCryptographicHash::Md5).toHex(); + QList staleFiles = KAutoSaveFile::staleFiles(KUrl(hash)); if (!staleFiles.isEmpty()) { if (KMessageBox::questionYesNo(this, i18n("Auto-saved files exist. Do you want to recover them now?"), i18n("File Recovery"), KGuiItem(i18n("Recover")), KGuiItem(i18n("Don't recover"))) == KMessageBox::Yes) { - recoverFiles(staleFiles); + recoverFiles(staleFiles, url); return; } else { // remove the stale files @@ -2113,7 +2115,7 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) qApp->processEvents(); bool openBackup; - KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QMap (), QMap (), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, &openBackup, this, &progressDialog); + KdenliveDoc *doc = new KdenliveDoc(stale ? KUrl(stale->fileName()) : url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QMap (), QMap (), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, &openBackup, this, &progressDialog); progressDialog.progressBar()->setValue(1); progressDialog.progressBar()->setMaximum(4); @@ -2121,11 +2123,12 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) qApp->processEvents(); if (stale == NULL) { - stale = new KAutoSaveFile(url, doc); + QByteArray hash = QCryptographicHash::hash(url.encodedPath(), QCryptographicHash::Md5).toHex(); + stale = new KAutoSaveFile(KUrl(hash), doc); doc->m_autosave = stale; } else { doc->m_autosave = stale; - doc->setUrl(stale->managedFile()); + doc->setUrl(url);//stale->managedFile()); doc->setModified(true); stale->setParent(doc); } @@ -2161,7 +2164,7 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) if (openBackup) slotOpenBackupDialog(url); } -void MainWindow::recoverFiles(QList staleFiles) +void MainWindow::recoverFiles(QList staleFiles, const KUrl &originUrl) { foreach(KAutoSaveFile * stale, staleFiles) { /*if (!stale->open(QIODevice::QIODevice::ReadOnly)) { @@ -2172,7 +2175,7 @@ void MainWindow::recoverFiles(QList staleFiles) }*/ kDebug() << "// OPENING RECOVERY: " << stale->fileName() << "\nMANAGED: " << stale->managedFile().path(); // the stalefiles also contain ".lock" files so we must ignore them... bug in KAutoSaveFile? - if (!stale->fileName().endsWith(".lock")) doOpenFile(KUrl(stale->fileName()), stale); + if (!stale->fileName().endsWith(".lock")) doOpenFile(originUrl, stale); else KIO::NetAccess::del(KUrl(stale->fileName()), this); } } diff --git a/src/mainwindow.h b/src/mainwindow.h index 4164a60f..bef2e067 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -273,7 +273,7 @@ private: void connectDocumentInfo(KdenliveDoc *doc); void findAhead(); void doOpenFile(const KUrl &url, KAutoSaveFile *stale); - void recoverFiles(QList staleFiles); + void recoverFiles(QList staleFiles, const KUrl &originUrl); /** @brief Loads static and dynamic plugins. * -- 2.39.2