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 "archivewidget.h"
22 #include "titlewidget.h"
25 #include <KDiskFreeSpaceInfo>
26 #include <KUrlRequester>
27 #include <KFileDialog>
30 #include <QListWidget>
31 #include "projectsettings.h"
34 ArchiveWidget::ArchiveWidget(QList <DocClipBase*> list, QStringList lumas, QWidget * parent) :
40 setWindowTitle(i18n("Archive Project"));
41 archive_url->setUrl(KUrl(QDir::homePath()));
42 connect(archive_url, SIGNAL(textChanged (const QString &)), this, SLOT(slotCheckSpace()));
46 foreach(const QString & file, lumas) {
47 kDebug()<<"LUMA: "<<file;
48 files_list->addItem(file);
49 m_requestedSize += QFileInfo(file).size();
52 for (int i = 0; i < list.count(); i++) {
53 DocClipBase *clip = list.at(i);
54 if (clip->clipType() == SLIDESHOW) {
55 QStringList subfiles = ProjectSettings::extractSlideshowUrls(clip->fileURL());
56 foreach(const QString & file, subfiles) {
57 kDebug()<<"SLIDE: "<<file;
58 files_list->addItem(file);
59 m_requestedSize += QFileInfo(file).size();
61 } else if (!clip->fileURL().isEmpty()) {
62 files_list->addItem(clip->fileURL().path());
63 m_requestedSize += QFileInfo(clip->fileURL().path()).size();
65 if (clip->clipType() == TEXT) {
66 QStringList imagefiles = TitleWidget::extractImageList(clip->getProperty("xmldata"));
67 QStringList fonts = TitleWidget::extractFontList(clip->getProperty("xmldata"));
68 foreach(const QString & file, imagefiles) {
69 kDebug()<<"TXT IMAGE: "<<file;
70 files_list->addItem(file);
71 m_requestedSize += QFileInfo(file).size();
74 } else if (clip->clipType() == PLAYLIST) {
75 QStringList files = ProjectSettings::extractPlaylistUrls(clip->fileURL().path());
76 foreach(const QString & file, files) {
77 kDebug()<<"PLAYLIST: "<<file;
78 files_list->addItem(file);
79 m_requestedSize += QFileInfo(file).size();
83 #if QT_VERSION >= 0x040500
84 allFonts.removeDuplicates();
86 project_files->setText(i18n("%1 files to archive, requires %2", files_list->count(), KIO::convertSize(m_requestedSize)));
87 buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Archive"));
88 connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotStartArchiving()));
89 buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
94 ArchiveWidget::~ArchiveWidget()
98 void ArchiveWidget::slotCheckSpace()
100 KDiskFreeSpaceInfo inf = KDiskFreeSpaceInfo::freeSpaceInfo( archive_url->url().path());
101 KIO::filesize_t freeSize = inf.available();;
102 if (freeSize > m_requestedSize) {
104 buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
105 icon_info->setPixmap(KIcon("dialog-ok").pixmap(16, 16));
106 text_info->setText(i18n("Available space on drive: %1", KIO::convertSize(freeSize)));
109 buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
110 icon_info->setPixmap(KIcon("dialog-close").pixmap(16, 16));
111 text_info->setText(i18n("Not enough space on drive, free space: %1", KIO::convertSize(freeSize)));
115 void ArchiveWidget::slotStartArchiving()
118 // archiving in progress, abort
119 m_copyJob->kill(KJob::EmitResult);
123 for (int i = 0; i < files_list->count(); i++) {
124 if (files_list->item(i))
125 files << KUrl(files_list->item(i)->text());
128 progressBar->setValue(0);
129 buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Abort"));
130 m_copyJob = KIO::copy (files, archive_url->url(), KIO::HideProgressInfo);
131 connect(m_copyJob, SIGNAL(result(KJob *)), this, SLOT(slotArchivingFinished(KJob *)));
132 connect(m_copyJob, SIGNAL(processedSize(KJob *, qulonglong)), this, SLOT(slotArchivingProgress(KJob *, qulonglong)));
135 void ArchiveWidget::slotArchivingFinished(KJob *job)
137 progressBar->setValue(100);
138 buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Archive"));
139 if (job->error() == 0) text_info->setText(i18n("Project was successfully archived."));
141 icon_info->setPixmap(KIcon("dialog-close").pixmap(16, 16));
142 text_info->setText(i18n("There was an error while copying the files: %1", job->errorString()));
147 void ArchiveWidget::slotArchivingProgress(KJob *, qulonglong size)
149 progressBar->setValue((int) 100 * size / m_requestedSize);