]> git.sesse.net Git - kdenlive/commitdiff
Move the backup dialog in separate folder, open it automatically when Kdenlive cannot...
authorJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 6 Jun 2011 11:09:50 +0000 (11:09 +0000)
committerJean-Baptiste Mardelle <jb@kdenlive.org>
Mon, 6 Jun 2011 11:09:50 +0000 (11:09 +0000)
svn path=/trunk/kdenlive/; revision=5667

src/CMakeLists.txt
src/databackup/CMakeLists.txt [new file with mode: 0644]
src/databackup/backupwidget.cpp [new file with mode: 0644]
src/databackup/backupwidget.h [new file with mode: 0644]
src/kdenlivedoc.cpp
src/kdenlivedoc.h
src/mainwindow.cpp
src/mainwindow.h
src/widgets/backupdialog_ui.ui

index a17eec703ce42d715eff4075068b597c57da32b9..4f2e4964154baee699b996eee4a2964e4418e3d9 100644 (file)
@@ -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 (file)
index 0000000..4089576
--- /dev/null
@@ -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 (file)
index 0000000..b38152b
--- /dev/null
@@ -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 <KUrl>
+
+
+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 (file)
index 0000000..566dbd5
--- /dev/null
@@ -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
+
index 7a4b9482698dc0d23adadadaf291e3848e554dc9..35355db0e74b989442973f1d21e2085d218b3198 100644 (file)
@@ -54,7 +54,7 @@
 
 const double DOCUMENTVERSION = 0.86;
 
-KdenliveDoc::KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap <QString, QString> 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 <QString, QString> 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());
     }
index e3b914a72fe576b29297b1ec3f9fd4519110e955..5c4272399f10995e9a60dc59d519ebc3ec83c0ee 100644 (file)
@@ -52,7 +52,7 @@ class KdenliveDoc: public QObject
 {
 Q_OBJECT public:
 
-    KdenliveDoc(const KUrl &url, const KUrl &projectFolder, QUndoGroup *undoGroup, QString profileName, QMap <QString, QString> 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 <QString, QString> properties, const QPoint tracks, Render *render, KTextEdit *notes, bool *openBackup, MainWindow *parent = 0, KProgressDialog *progressDialog = 0);
     ~KdenliveDoc();
     QDomNodeList producersList();
     double fps() const;
index f9918685ba363fb2a5a613aa7b1150dad40bc16b..54ed5506ede8a1c314a74fde015101250268dd28 100644 (file)
@@ -62,6 +62,7 @@
 #include "audiospectrum.h"
 #include "spectrogram.h"
 #include "archivewidget.h"
+#include "databackup/backupwidget.h"
 
 #include <KApplication>
 #include <KAction>
@@ -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<QVector<int16_t> > ();
     // 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 <QString, QString> (), 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 <QString, QString> (), 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<KAutoSaveFile *> 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: "<<url.path();
+    if (!url.isEmpty()) {
+        // we could not open the project file, guess where the backups are
+        projectFolder = KUrl(KdenliveSettings::defaultprojectfolder());
+        projectFile = url;
     }
-    connect(m_backup_ui->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"
index 6bc6f7df520caa80c8d0e602acde6907e322670c..c8d0ff241947d545f866917040cf500a271e53d0 100644 (file)
@@ -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);
 };
index 0467ba7378c4ebac5ac9c76f009a3fe048d9425f..a12b72b97cb2aef6f732b80e6508976548fa249e 100644 (file)
@@ -14,7 +14,7 @@
    <string>Dialog</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="2" column="0">
+   <item row="3" column="1">
     <widget class="QDialogButtonBox" name="buttonBox">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
     </widget>
    </item>
-   <item row="0" column="0">
+   <item row="1" column="0" colspan="2">
     <widget class="KListWidget" name="backup_list">
      <property name="alternatingRowColors">
       <bool>true</bool>
      </property>
     </widget>
    </item>
-   <item row="1" column="0">
+   <item row="2" column="0" colspan="2">
     <widget class="QLabel" name="backup_preview">
      <property name="frameShape">
       <enum>QFrame::Box</enum>
      </property>
     </widget>
    </item>
+   <item row="0" column="1">
+    <widget class="KUrlRequester" name="project_url">
+     <property name="mode">
+      <set>KFile::Directory|KFile::ExistingOnly|KFile::LocalOnly</set>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="0">
+    <widget class="QLabel" name="label">
+     <property name="text">
+      <string>Project Folder</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <customwidgets>
+  <customwidget>
+   <class>KUrlRequester</class>
+   <extends>QFrame</extends>
+   <header>kurlrequester.h</header>
+  </customwidget>
   <customwidget>
    <class>KListWidget</class>
    <extends>QListWidget</extends>