From: Jean-Baptiste Mardelle Date: Mon, 6 Jun 2011 11:09:50 +0000 (+0000) Subject: Move the backup dialog in separate folder, open it automatically when Kdenlive cannot... X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=8094288cefb96c161d2bdbfc6ace594530ec16bc;p=kdenlive Move the backup dialog in separate folder, open it automatically when Kdenlive cannot read a project file svn path=/trunk/kdenlive/; revision=5667 --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a17eec70..4f2e4964 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(mimetypes) add_subdirectory(onmonitoritems) add_subdirectory(rotoscoping) add_subdirectory(widgets) +add_subdirectory(databackup) macro_optional_find_package(Nepomuk) macro_optional_find_package(QJSON) diff --git a/src/databackup/CMakeLists.txt b/src/databackup/CMakeLists.txt new file mode 100644 index 00000000..4089576c --- /dev/null +++ b/src/databackup/CMakeLists.txt @@ -0,0 +1,5 @@ +set(kdenlive_SRCS + ${kdenlive_SRCS} + databackup/backupwidget.cpp + PARENT_SCOPE +) diff --git a/src/databackup/backupwidget.cpp b/src/databackup/backupwidget.cpp new file mode 100644 index 00000000..b38152b6 --- /dev/null +++ b/src/databackup/backupwidget.cpp @@ -0,0 +1,89 @@ +/*************************************************************************** + * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#include "backupwidget.h" +#include "kdenlivesettings.h" + +#include + + +BackupWidget::BackupWidget(KUrl projectUrl, KUrl projectFolder, QWidget * parent) : + QDialog(parent), + m_url(projectUrl) +{ + setupUi(this); + setWindowTitle(i18n("Restore Backup File")); + + KUrl backupFile; + m_projectWildcard = projectUrl.fileName().section('.', 0, -2); + project_url->setUrl(projectFolder); + + m_projectWildcard.append("-??"); + m_projectWildcard.append("??"); + m_projectWildcard.append("-??"); + m_projectWildcard.append("-??"); + m_projectWildcard.append("-??"); + m_projectWildcard.append("-??.kdenlive"); + + slotParseBackupFiles(); + connect(backup_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotDisplayBackupPreview())); + connect(project_url, SIGNAL(textChanged(const QString &)), this, SLOT(slotParseBackupFiles())); + backup_list->setCurrentRow(0); + backup_list->setMinimumHeight(QFontMetrics(font()).lineSpacing() * 12); + +} + + + +BackupWidget::~BackupWidget() +{ + +} + +void BackupWidget::slotParseBackupFiles() +{ + QStringList filter; + KUrl backupFile = project_url->url(); + backupFile.addPath(".backup/"); + QDir dir(backupFile.path()); + + filter << m_projectWildcard; + dir.setNameFilters(filter); + QFileInfoList resultList = dir.entryInfoList(QDir::Files, QDir::Time); + QStringList results; + QListWidgetItem *item; + for (int i = 0; i < resultList.count(); i++) { + item = new QListWidgetItem(resultList.at(i).lastModified().toString(Qt::DefaultLocaleLongDate), backup_list); + item->setData(Qt::UserRole, resultList.at(i).absoluteFilePath()); + } +} + +void BackupWidget::slotDisplayBackupPreview() +{ + QString path = backup_list->currentItem()->data(Qt::UserRole).toString(); + QPixmap pix(path + ".png"); + backup_preview->setPixmap(pix); +} + +QString BackupWidget::selectedFile() +{ + if (!backup_list->currentItem()) return QString(); + return backup_list->currentItem()->data(Qt::UserRole).toString(); +} \ No newline at end of file diff --git a/src/databackup/backupwidget.h b/src/databackup/backupwidget.h new file mode 100644 index 00000000..566dbd53 --- /dev/null +++ b/src/databackup/backupwidget.h @@ -0,0 +1,61 @@ +/*************************************************************************** + * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * + ***************************************************************************/ + + +#ifndef BACKUPWIDGET_H +#define BACKUPWIDGET_H + + +#include "ui_backupdialog_ui.h" + + + +/** + * @class BackupWidget + * @brief A widget allowing to parse backup project files + * @author Jean-Baptiste Mardelle + */ + +class BackupWidget : public QDialog, public Ui::BackupDialog_UI +{ + Q_OBJECT + +public: + BackupWidget(KUrl projectUrl, KUrl projectFolder, QWidget * parent = 0); + // Constructor for extracting widget + ~BackupWidget(); + /** @brief Return the path for selected backup file. */ + QString selectedFile(); + +private slots: + /** @brief Parse the backup files in project folder. */ + void slotParseBackupFiles(); + /** @brief Display a thumbnail preview of selected backup. */ + void slotDisplayBackupPreview(); + +private: + KUrl m_url; + QString m_projectWildcard; + +signals: +}; + + +#endif + diff --git a/src/kdenlivedoc.cpp b/src/kdenlivedoc.cpp index 7a4b9482..35355db0 100644 --- a/src/kdenlivedoc.cpp +++ b/src/kdenlivedoc.cpp @@ -54,7 +54,7 @@ const double DOCUMENTVERSION = 0.86; -KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap properties, const QPoint tracks, Render *render, KTextEdit *notes, MainWindow *parent, KProgressDialog *progressDialog) : +KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap properties, const QPoint tracks, Render *render, KTextEdit *notes, bool *openBackup, MainWindow *parent, KProgressDialog *progressDialog) : QObject(parent), m_autosave(NULL), m_url(url), @@ -88,12 +88,19 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup i.next(); m_documentProperties[i.key()] = i.value(); } + + *openBackup = false; if (!url.isEmpty()) { QString tmpFile; success = KIO::NetAccess::download(url.path(), tmpFile, parent); - if (!success) // The file cannot be opened - KMessageBox::error(parent, KIO::NetAccess::lastErrorString()); + if (!success) { + // The file cannot be opened + if (KMessageBox::warningContinueCancel(parent, i18n("Cannot open the project file, error is:\n%1\nDo you want to open a backup file?", KIO::NetAccess::lastErrorString()), i18n("Error opening file"), KGuiItem(i18n("Open Backup"))) == KMessageBox::Continue) { + *openBackup = true; + } + //KMessageBox::error(parent, KIO::NetAccess::lastErrorString()); + } else { QFile file(tmpFile); QString errorMsg; @@ -103,8 +110,13 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup file.close(); KIO::NetAccess::removeTempFile(tmpFile); - if (!success) // It is corrupted - KMessageBox::error(parent, errorMsg); + if (!success) { + // It is corrupted + if (KMessageBox::warningContinueCancel(parent, i18n("Cannot open the project file, error is:\n%1\nDo you want to open a backup file?", errorMsg), i18n("Error opening file"), KGuiItem(i18n("Open Backup"))) == KMessageBox::Continue) { + *openBackup = true; + } + //KMessageBox::error(parent, errorMsg); + } else { parent->slotGotProgressInfo(i18n("Validating"), 0); qApp->processEvents(); @@ -113,6 +125,9 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup if (!success) { // It is not a project file parent->slotGotProgressInfo(i18n("File %1 is not a Kdenlive project file", m_url.path()), 100); + if (KMessageBox::warningContinueCancel(parent, i18n("File %1 is not a valid project file.\nDo you want to open a backup file?", m_url.path()), i18n("Error opening file"), KGuiItem(i18n("Open Backup"))) == KMessageBox::Continue) { + *openBackup = true; + } } else { /* * Validate the file against the current version (upgrade @@ -249,7 +264,7 @@ KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup // Something went wrong, or a new file was requested: create a new project if (!success) { - m_url = KUrl(); + m_url.clear(); setProfilePath(profileName); m_document = createEmptyDocument(tracks.x(), tracks.y()); } diff --git a/src/kdenlivedoc.h b/src/kdenlivedoc.h index e3b914a7..5c427239 100644 --- a/src/kdenlivedoc.h +++ b/src/kdenlivedoc.h @@ -52,7 +52,7 @@ class KdenliveDoc: public QObject { Q_OBJECT public: - KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap properties, const QPoint tracks, Render *render, KTextEdit *notes, MainWindow *parent = 0, KProgressDialog *progressDialog = 0); + KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap properties, const QPoint tracks, Render *render, KTextEdit *notes, bool *openBackup, MainWindow *parent = 0, KProgressDialog *progressDialog = 0); ~KdenliveDoc(); QDomNodeList producersList(); double fps() const; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index f9918685..54ed5506 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -62,6 +62,7 @@ #include "audiospectrum.h" #include "spectrogram.h" #include "archivewidget.h" +#include "databackup/backupwidget.h" #include #include @@ -146,8 +147,7 @@ MainWindow::MainWindow(const QString &MltPath, const KUrl & Url, const QString & m_jogShuttle(NULL), #endif /* NO_JOGSHUTTLE */ m_findActivated(false), - m_stopmotion(NULL), - m_backup_ui(NULL) + m_stopmotion(NULL) { qRegisterMetaType > (); // Create DBus interface @@ -1795,8 +1795,8 @@ void MainWindow::newFile(bool showProjectSettings, bool force) } m_timelineArea->setEnabled(true); m_projectList->setEnabled(true); - - KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, documentProperties, projectTracks, m_projectMonitor->render, m_notesWidget, this); + bool openBackup; + KdenliveDoc *doc = new KdenliveDoc(KUrl(), projectFolder, m_commandStack, profileName, documentProperties, projectTracks, m_projectMonitor->render, m_notesWidget, &openBackup, this); doc->m_autosave = new KAutoSaveFile(KUrl(), doc); bool ok; TrackView *trackView = new TrackView(doc, &ok, this); @@ -2020,7 +2020,8 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) progressDialog.progressBar()->setValue(0); qApp->processEvents(); - KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QMap (), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, this, &progressDialog); + bool openBackup; + KdenliveDoc *doc = new KdenliveDoc(url, KdenliveSettings::defaultprojectfolder(), m_commandStack, KdenliveSettings::default_profile(), QMap (), QPoint(KdenliveSettings::videotracks(), KdenliveSettings::audiotracks()), m_projectMonitor->render, m_notesWidget, &openBackup, this, &progressDialog); progressDialog.progressBar()->setValue(1); progressDialog.progressBar()->setMaximum(4); @@ -2067,6 +2068,7 @@ void MainWindow::doOpenFile(const KUrl &url, KAutoSaveFile *stale) m_clipMonitor->refreshMonitor(true); progressDialog.progressBar()->setValue(4); + if (openBackup) slotOpenBackupDialog(url); } void MainWindow::recoverFiles(QList staleFiles) @@ -2463,6 +2465,7 @@ void MainWindow::connectDocument(TrackView *trackView, KdenliveDoc *doc) //cha connect(doc, SIGNAL(docModified(bool)), this, SLOT(slotUpdateDocumentState(bool))); connect(doc, SIGNAL(guidesUpdated()), this, SLOT(slotGuidesUpdated())); connect(doc, SIGNAL(saveTimelinePreview(const QString)), trackView->projectView(), SLOT(saveTimelinePreview(const QString))); + connect(m_notesWidget, SIGNAL(textChanged()), doc, SLOT(setModified())); connect(trackView->projectView(), SIGNAL(clipItemSelected(ClipItem*, int, bool)), m_effectStack, SLOT(slotClipItemSelected(ClipItem*, int))); @@ -4265,57 +4268,35 @@ void MainWindow::slotArchiveProject() } -void MainWindow::slotOpenBackupDialog() -{ - QDialog *dia = new QDialog(this); - m_backup_ui = new Ui::BackupDialog_UI; - m_backup_ui->setupUi(dia); - dia->setWindowTitle(i18n("Backup Files")); - KUrl backupFile = m_activeDocument->projectFolder(); - backupFile.addPath(".backup/"); - QDir dir(backupFile.path()); - QString projectFile = m_activeDocument->url().fileName().section('.', 0, -2); - projectFile.append("-??"); - projectFile.append("??"); - projectFile.append("-??"); - projectFile.append("-??"); - projectFile.append("-??"); - projectFile.append("-??.kdenlive"); - - QStringList filter; - backupFile.addPath(projectFile); - filter << projectFile; - dir.setNameFilters(filter); - QFileInfoList resultList = dir.entryInfoList(QDir::Files, QDir::Time); - QStringList results; - QListWidgetItem *item; - for (int i = 0; i < resultList.count(); i++) { - item = new QListWidgetItem(resultList.at(i).lastModified().toString(Qt::DefaultLocaleLongDate), m_backup_ui->backup_list); - item->setData(Qt::UserRole, resultList.at(i).absoluteFilePath()); +void MainWindow::slotOpenBackupDialog(const KUrl url) +{ + KUrl projectFile; + KUrl projectFolder; + kDebug()<<"// BACKUP URL: "<backup_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotDisplayBackupPreview())); - m_backup_ui->backup_list->setCurrentRow(0); - m_backup_ui->backup_list->setMinimumHeight(QFontMetrics(font()).lineSpacing() * 12); + else { + projectFolder = m_activeDocument->projectFolder(); + projectFile = m_activeDocument->url(); + } + + BackupWidget *dia = new BackupWidget(projectFile, projectFolder, this); if (dia->exec() == QDialog::Accepted) { - QString requestedBackup = m_backup_ui->backup_list->currentItem()->data(Qt::UserRole).toString(); - KUrl currentUrl = m_activeDocument->url(); - m_activeDocument->backupLastSavedVersion(currentUrl.path()); + QString requestedBackup = dia->selectedFile(); + m_activeDocument->backupLastSavedVersion(projectFile.path()); closeCurrentDocument(false); doOpenFile(KUrl(requestedBackup), NULL); - m_activeDocument->setUrl(currentUrl); + m_activeDocument->setUrl(projectFile); setCaption(m_activeDocument->description()); } delete dia; - delete m_backup_ui; - m_backup_ui = NULL; } -void MainWindow::slotDisplayBackupPreview() -{ - QString path = m_backup_ui->backup_list->currentItem()->data(Qt::UserRole).toString(); - QPixmap pix(path + ".png"); - m_backup_ui->backup_preview->setPixmap(pix); -} + + #include "mainwindow.moc" diff --git a/src/mainwindow.h b/src/mainwindow.h index 6bc6f7df..c8d0ff24 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -306,9 +306,6 @@ private: StopmotionWidget *m_stopmotion; - /** @brief UI for backup dialog. */ - Ui::BackupDialog_UI *m_backup_ui; - public slots: /** @brief Prepares opening @param url. * @@ -545,9 +542,8 @@ private slots: /** @brief Insert current project's timecode into the notes widget. */ void slotInsertNotesTimecode(); /** @brief Open the project's backupdialog. */ - void slotOpenBackupDialog(); - /** @brief Display chosen backup thumbnail. */ - void slotDisplayBackupPreview(); + void slotOpenBackupDialog(const KUrl url = KUrl()); + signals: Q_SCRIPTABLE void abortRenderJob(const QString &url); }; diff --git a/src/widgets/backupdialog_ui.ui b/src/widgets/backupdialog_ui.ui index 0467ba73..a12b72b9 100644 --- a/src/widgets/backupdialog_ui.ui +++ b/src/widgets/backupdialog_ui.ui @@ -14,7 +14,7 @@ Dialog - + Qt::Horizontal @@ -24,14 +24,14 @@ - + true - + QFrame::Box @@ -41,9 +41,28 @@ + + + + KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly + + + + + + + Project Folder + + + + + KUrlRequester + QFrame +
kurlrequester.h
+
KListWidget QListWidget