1 /***************************************************************************
2 * Copyright (C) 2011 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
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. *
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. *
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 ***************************************************************************/
21 #include "backupwidget.h"
22 #include "kdenlivesettings.h"
27 BackupWidget::BackupWidget(KUrl projectUrl, KUrl projectFolder, const QString projectId, QWidget * parent) :
32 setWindowTitle(i18n("Restore Backup File"));
35 m_projectWildcard = projectUrl.fileName().section('.', 0, -2);
36 project_url->setUrl(projectFolder);
37 if (!projectId.isEmpty()) m_projectWildcard.append("-" + projectId);
39 // No project id, it was lost, add wildcard
40 m_projectWildcard.append("*");
42 m_projectWildcard.append("-??");
43 m_projectWildcard.append("??");
44 m_projectWildcard.append("-??");
45 m_projectWildcard.append("-??");
46 m_projectWildcard.append("-??");
47 m_projectWildcard.append("-??.kdenlive");
49 slotParseBackupFiles();
50 connect(backup_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotDisplayBackupPreview()));
51 connect(project_url, SIGNAL(textChanged(const QString &)), this, SLOT(slotParseBackupFiles()));
52 backup_list->setCurrentRow(0);
53 backup_list->setMinimumHeight(QFontMetrics(font()).lineSpacing() * 12);
59 BackupWidget::~BackupWidget()
64 void BackupWidget::slotParseBackupFiles()
67 KUrl backupFile = project_url->url();
68 backupFile.addPath(".backup/");
69 QDir dir(backupFile.path());
71 filter << m_projectWildcard;
72 dir.setNameFilters(filter);
73 QFileInfoList resultList = dir.entryInfoList(QDir::Files, QDir::Time);
76 QListWidgetItem *item;
77 for (int i = 0; i < resultList.count(); i++) {
78 item = new QListWidgetItem(resultList.at(i).lastModified().toString(Qt::DefaultLocaleLongDate), backup_list);
79 item->setData(Qt::UserRole, resultList.at(i).absoluteFilePath());
83 void BackupWidget::slotDisplayBackupPreview()
85 if (!backup_list->currentItem()) {
86 backup_preview->setPixmap(QPixmap());
89 QString path = backup_list->currentItem()->data(Qt::UserRole).toString();
90 QPixmap pix(path + ".png");
91 backup_preview->setPixmap(pix);
94 QString BackupWidget::selectedFile()
96 if (!backup_list->currentItem()) return QString();
97 return backup_list->currentItem()->data(Qt::UserRole).toString();