]> git.sesse.net Git - kdenlive/blob - src/databackup/backupwidget.cpp
Move the backup dialog in separate folder, open it automatically when Kdenlive cannot...
[kdenlive] / src / databackup / backupwidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org)        *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program; if not, write to the                         *
16  *   Free Software Foundation, Inc.,                                       *
17  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
18  ***************************************************************************/
19
20
21 #include "backupwidget.h"
22 #include "kdenlivesettings.h"
23
24 #include <KUrl>
25
26
27 BackupWidget::BackupWidget(KUrl projectUrl, KUrl projectFolder, QWidget * parent) :
28         QDialog(parent),
29         m_url(projectUrl)
30 {
31     setupUi(this);
32     setWindowTitle(i18n("Restore Backup File"));
33
34     KUrl backupFile;
35     m_projectWildcard = projectUrl.fileName().section('.', 0, -2);
36     project_url->setUrl(projectFolder);
37     
38     m_projectWildcard.append("-??");
39     m_projectWildcard.append("??");
40     m_projectWildcard.append("-??");
41     m_projectWildcard.append("-??");
42     m_projectWildcard.append("-??");
43     m_projectWildcard.append("-??.kdenlive");
44
45     slotParseBackupFiles();
46     connect(backup_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotDisplayBackupPreview()));
47     connect(project_url, SIGNAL(textChanged(const QString &)), this, SLOT(slotParseBackupFiles()));
48     backup_list->setCurrentRow(0);
49     backup_list->setMinimumHeight(QFontMetrics(font()).lineSpacing() * 12);
50     
51 }
52
53
54
55 BackupWidget::~BackupWidget()
56 {
57
58 }
59
60 void BackupWidget::slotParseBackupFiles()
61 {
62     QStringList filter;
63     KUrl backupFile = project_url->url();
64     backupFile.addPath(".backup/");
65     QDir dir(backupFile.path());
66
67     filter << m_projectWildcard;
68     dir.setNameFilters(filter);
69     QFileInfoList resultList = dir.entryInfoList(QDir::Files, QDir::Time);
70     QStringList results;
71     QListWidgetItem *item;
72     for (int i = 0; i < resultList.count(); i++) {
73         item = new QListWidgetItem(resultList.at(i).lastModified().toString(Qt::DefaultLocaleLongDate), backup_list);
74         item->setData(Qt::UserRole, resultList.at(i).absoluteFilePath());
75     }
76 }
77
78 void BackupWidget::slotDisplayBackupPreview()
79 {
80     QString path = backup_list->currentItem()->data(Qt::UserRole).toString();
81     QPixmap pix(path + ".png");
82     backup_preview->setPixmap(pix);
83 }
84
85 QString BackupWidget::selectedFile()
86 {
87     if (!backup_list->currentItem()) return QString();
88     return backup_list->currentItem()->data(Qt::UserRole).toString();
89 }