]> git.sesse.net Git - kdenlive/blob - src/databackup/backupwidget.cpp
normalize signal/slots
[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, const QString &projectId, QWidget * parent) :
28         QDialog(parent)
29 {
30     setupUi(this);
31     setWindowTitle(i18n("Restore Backup File"));
32
33     KUrl backupFile;
34
35     if (projectUrl.isEmpty()) {
36         // No url, means we opened the backup dialog from an empty project
37         info_label->setText(i18n("Showing all backup files in folder"));
38         m_projectWildcard = '*';
39     }
40     else {
41         info_label->setText(i18n("Showing backup files for %1", projectUrl.fileName()));
42         m_projectWildcard = projectUrl.fileName().section('.', 0, -2);
43         if (!projectId.isEmpty()) m_projectWildcard.append('-' + projectId);
44         else {
45             // No project id, it was lost, add wildcard
46             m_projectWildcard.append('*');
47         }
48     }
49     project_url->setUrl(projectFolder);
50     m_projectWildcard.append("-??");
51     m_projectWildcard.append("??");
52     m_projectWildcard.append("-??");
53     m_projectWildcard.append("-??");
54     m_projectWildcard.append("-??");
55     m_projectWildcard.append("-??.kdenlive");
56
57     slotParseBackupFiles();
58     connect(backup_list, SIGNAL(currentRowChanged(int)), this, SLOT(slotDisplayBackupPreview()));
59     connect(project_url, SIGNAL(textChanged(QString)), this, SLOT(slotParseBackupFiles()));
60     backup_list->setCurrentRow(0);
61     backup_list->setMinimumHeight(QFontMetrics(font()).lineSpacing() * 12);
62     
63 }
64
65
66
67 BackupWidget::~BackupWidget()
68 {
69
70 }
71
72 void BackupWidget::slotParseBackupFiles()
73 {
74     QStringList filter;
75     KUrl backupFile = project_url->url();
76     backupFile.addPath(".backup/");
77     QDir dir(backupFile.path());
78
79     filter << m_projectWildcard;
80     dir.setNameFilters(filter);
81     QFileInfoList resultList = dir.entryInfoList(QDir::Files, QDir::Time);
82     QStringList results;
83     backup_list->clear();
84     QListWidgetItem *item;
85     QString label;
86     for (int i = 0; i < resultList.count(); i++) {
87         label = resultList.at(i).lastModified().toString(Qt::SystemLocaleLongDate);
88         if (m_projectWildcard.startsWith('*')) {
89             // Displaying all backup files, so add project name in the entries
90             label.prepend(resultList.at(i).fileName().section('-', 0, -7) + ".kdenlive - ");
91         }
92         item = new QListWidgetItem(label, backup_list);
93         item->setData(Qt::UserRole, resultList.at(i).absoluteFilePath());
94     }
95     buttonBox->button(QDialogButtonBox::Open)->setEnabled(backup_list->count() > 0);
96 }
97
98 void BackupWidget::slotDisplayBackupPreview()
99 {
100     if (!backup_list->currentItem()) {
101         backup_preview->setPixmap(QPixmap());
102         return;
103     }
104     QString path = backup_list->currentItem()->data(Qt::UserRole).toString();
105     QPixmap pix(path + ".png");
106     backup_preview->setPixmap(pix);
107 }
108
109 QString BackupWidget::selectedFile()
110 {
111     if (!backup_list->currentItem()) return QString();
112     return backup_list->currentItem()->data(Qt::UserRole).toString();
113 }
114