#include "projectsettings.h"
-ArchiveWidget::ArchiveWidget(QString projectName, QDomDocument doc, QList <DocClipBase*> list, QStringList luma_list, QWidget * parent) :
- QDialog(parent),
- m_requestedSize(0),
- m_copyJob(NULL),
- m_name(projectName.section('.', 0, -2)),
- m_doc(doc),
- m_abortArchive(false),
- m_extractMode(false),
- m_extractArchive(NULL),
- m_missingClips(0)
+ArchiveWidget::ArchiveWidget(const QString &projectName, const QDomDocument &doc, const QList <DocClipBase*> &list, const QStringList &luma_list, QWidget * parent) :
+ QDialog(parent)
+ , m_requestedSize(0)
+ , m_copyJob(NULL)
+ , m_name(projectName.section('.', 0, -2))
+ , m_doc(doc)
+ , m_temp(NULL)
+ , m_abortArchive(false)
+ , m_extractMode(false)
+ , m_progressTimer(NULL)
+ , m_extractArchive(NULL)
+ , m_missingClips(0)
{
setAttribute(Qt::WA_DeleteOnClose);
setupUi(this);
setWindowTitle(i18n("Archive Project"));
archive_url->setUrl(KUrl(QDir::homePath()));
- connect(archive_url, SIGNAL(textChanged (const QString &)), this, SLOT(slotCheckSpace()));
+ connect(archive_url, SIGNAL(textChanged(QString)), this, SLOT(slotCheckSpace()));
connect(this, SIGNAL(archivingFinished(bool)), this, SLOT(slotArchivingFinished(bool)));
connect(this, SIGNAL(archiveProgress(int)), this, SLOT(slotArchivingProgress(int)));
connect(proxy_only, SIGNAL(stateChanged(int)), this, SLOT(slotProxyOnly(int)));
QMap <QString, QString>playlistUrls;
QMap <QString, QString>proxyUrls;
- for (int i = 0; i < list.count(); i++) {
+ for (int i = 0; i < list.count(); ++i) {
DocClipBase *clip = list.at(i);
CLIPTYPE t = clip->clipType();
QString id = clip->getId();
// Hide unused categories, add item count
int total = 0;
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
QTreeWidgetItem *parentItem = files_list->topLevelItem(i);
int items = parentItem->childCount();
if (items == 0) {
}
}
else total += items;
- parentItem->setText(0, files_list->topLevelItem(i)->text(0) + " " + i18np("(%1 item)", "(%1 items)", items));
+ parentItem->setText(0, files_list->topLevelItem(i)->text(0) + ' ' + i18np("(%1 item)", "(%1 items)", items));
}
}
if (m_name.isEmpty()) m_name = i18n("Untitled");
buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Archive"));
connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotStartArchiving()));
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
-
+
slotCheckSpace();
}
//setAttribute(Qt::WA_DeleteOnClose);
setupUi(this);
+ m_progressTimer = new QTimer;
+ m_progressTimer->setInterval(800);
+ m_progressTimer->setSingleShot(false);
+ connect(m_progressTimer, SIGNAL(timeout()), this, SLOT(slotExtractProgress()));
connect(this, SIGNAL(extractingFinished()), this, SLOT(slotExtractingFinished()));
- connect(this, SIGNAL(showMessage(const QString &, const QString &)), this, SLOT(slotDisplayMessage(const QString &, const QString &)));
+ connect(this, SIGNAL(showMessage(QString,QString)), this, SLOT(slotDisplayMessage(QString,QString)));
compressed_archive->setHidden(true);
+ proxy_only->setHidden(true);
project_files->setHidden(true);
files_list->setHidden(true);
label->setText(i18n("Extract to"));
ArchiveWidget::~ArchiveWidget()
{
- if (m_extractArchive) delete m_extractArchive;
+ delete m_extractArchive;
+ delete m_progressTimer;
}
void ArchiveWidget::slotDisplayMessage(const QString &icon, const QString &text)
// Check that it is a kdenlive project archive
bool isProjectArchive = false;
QStringList files = m_extractArchive->directory()->entries();
- for (int i = 0; i < files.count(); i++) {
+ for (int i = 0; i < files.count(); ++i) {
if (files.at(i).endsWith(".kdenlive")) {
m_projectName = files.at(i);
isProjectArchive = true;
if (!isProjectArchive) {
emit showMessage("dialog-close", i18n("File %1\n is not an archived Kdenlive project", m_extractUrl.path()));
groupBox->setEnabled(false);
+ buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
return;
}
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(true);
}
-void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, QStringList items)
+void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QStringList& items)
{
QStringList filesList;
QString fileName;
if (slideUrl.fileName().startsWith(".all.")) {
// mimetype slideshow (for example *.png)
QStringList filters;
- QString extension;
// TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
filters << "*." + slideUrl.fileName().section('.', -1);
dir.setNameFilters(filters);
QFileInfoList resultList = dir.entryInfoList(QDir::Files);
QStringList slideImages;
qint64 totalSize = 0;
- for (int i = 0; i < resultList.count(); i++) {
+ for (int i = 0; i < resultList.count(); ++i) {
totalSize += resultList.at(i).size();
slideImages << resultList.at(i).absoluteFilePath();
}
QString filter = slideUrl.fileName();
QString ext = filter.section('.', -1);
filter = filter.section('%', 0, -2);
- QString regexp = "^" + filter + "\\d+\\." + ext + "$";
+ QString regexp = '^' + filter + "\\d+\\." + ext + '$';
QRegExp rx(regexp);
QStringList slideImages;
QString directory = dir.absolutePath();
else if (filesList.contains(fileName)) {
// we have 2 files with same name
int ix = 0;
- QString newFileName = fileName.section('.', 0, -2) + "_" + QString::number(ix) + "." + fileName.section('.', -1);
+ QString newFileName = fileName.section('.', 0, -2) + '_' + QString::number(ix) + '.' + fileName.section('.', -1);
while (filesList.contains(newFileName)) {
ix ++;
- newFileName = fileName.section('.', 0, -2) + "_" + QString::number(ix) + "." + fileName.section('.', -1);
+ newFileName = fileName.section('.', 0, -2) + '_' + QString::number(ix) + '.' + fileName.section('.', -1);
}
fileName = newFileName;
item->setData(0, Qt::UserRole, fileName);
}
}
-void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, QMap <QString, QString> items)
+void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, const QMap <QString, QString>& items)
{
QStringList filesList;
QString fileName;
if (slideUrl.fileName().startsWith(".all.")) {
// mimetype slideshow (for example *.png)
QStringList filters;
- QString extension;
// TODO: improve jpeg image detection with extension like jpeg, requires change in MLT image producers
filters << "*." + slideUrl.fileName().section('.', -1);
dir.setNameFilters(filters);
QFileInfoList resultList = dir.entryInfoList(QDir::Files);
QStringList slideImages;
qint64 totalSize = 0;
- for (int i = 0; i < resultList.count(); i++) {
+ for (int i = 0; i < resultList.count(); ++i) {
totalSize += resultList.at(i).size();
slideImages << resultList.at(i).absoluteFilePath();
}
QString filter = slideUrl.fileName();
QString ext = filter.section('.', -1);
filter = filter.section('%', 0, -2);
- QString regexp = "^" + filter + "\\d+\\." + ext + "$";
+ QString regexp = '^' + filter + "\\d+\\." + ext + '$';
QRegExp rx(regexp);
QStringList slideImages;
qint64 totalSize = 0;
else if (filesList.contains(fileName)) {
// we have 2 files with same name
int ix = 0;
- QString newFileName = fileName.section('.', 0, -2) + "_" + QString::number(ix) + "." + fileName.section('.', -1);
+ QString newFileName = fileName.section('.', 0, -2) + '_' + QString::number(ix) + '.' + fileName.section('.', -1);
while (filesList.contains(newFileName)) {
ix ++;
newFileName = fileName.section('.', 0, -2) + "_" + QString::number(ix) + "." + fileName.section('.', -1);
QString destPath;
QTreeWidgetItem *parentItem;
bool isSlideshow = false;
+ int items = 0;
// We parse all files going into one folder, then start the copy job
-
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
parentItem = files_list->topLevelItem(i);
if (parentItem->isDisabled()) {
parentItem->setExpanded(false);
else isSlideshow = false;
files_list->setCurrentItem(parentItem);
parentItem->setExpanded(true);
- destPath = parentItem->data(0, Qt::UserRole).toString() + "/";
+ destPath = parentItem->data(0, Qt::UserRole).toString() + '/';
destUrl = KUrl(archive_url->url().path(KUrl::AddTrailingSlash) + destPath);
QTreeWidgetItem *item;
for (int j = 0; j < parentItem->childCount(); j++) {
item = parentItem->child(j);
if (item->isDisabled()) continue;
// Special case: slideshows
+ items++;
if (isSlideshow) {
- destPath += item->data(0, Qt::UserRole).toString() + "/";
+ destPath += item->data(0, Qt::UserRole).toString() + '/';
destUrl = KUrl(archive_url->url().path(KUrl::AddTrailingSlash) + destPath);
QStringList srcFiles = item->data(0, Qt::UserRole + 1).toStringList();
for (int k = 0; k < srcFiles.count(); k++) {
}
}
+ if (items == 0) {
+ // No clips to archive
+ slotArchivingFinished(NULL, true);
+ return true;
+ }
+
if (destPath.isEmpty()) {
if (m_duplicateFiles.isEmpty()) return false;
QMapIterator<KUrl, KUrl> i(m_duplicateFiles);
KUrl startJobDst = i.value();
m_duplicateFiles.remove(startJobSrc);
KIO::CopyJob *job = KIO::copyAs(startJobSrc, startJobDst, KIO::HideProgressInfo);
- connect(job, SIGNAL(result(KJob *)), this, SLOT(slotArchivingFinished(KJob *)));
- connect(job, SIGNAL(processedSize(KJob *, qulonglong)), this, SLOT(slotArchivingProgress(KJob *, qulonglong)));
+ connect(job, SIGNAL(result(KJob*)), this, SLOT(slotArchivingFinished(KJob*)));
+ connect(job, SIGNAL(processedSize(KJob*,qulonglong)), this, SLOT(slotArchivingProgress(KJob*,qulonglong)));
}
return true;
}
if (isArchive) {
m_foldersList.append(destPath);
- for (int i = 0; i < files.count(); i++) {
+ for (int i = 0; i < files.count(); ++i) {
m_filesList.insert(files.at(i).path(), destPath + files.at(i).fileName());
}
slotArchivingFinished();
else {
KIO::NetAccess::mkdir(destUrl, this);
m_copyJob = KIO::copy (files, destUrl, KIO::HideProgressInfo);
- connect(m_copyJob, SIGNAL(result(KJob *)), this, SLOT(slotArchivingFinished(KJob *)));
- connect(m_copyJob, SIGNAL(processedSize(KJob *, qulonglong)), this, SLOT(slotArchivingProgress(KJob *, qulonglong)));
+ connect(m_copyJob, SIGNAL(result(KJob*)), this, SLOT(slotArchivingFinished(KJob*)));
+ connect(m_copyJob, SIGNAL(processedSize(KJob*,qulonglong)), this, SLOT(slotArchivingProgress(KJob*,qulonglong)));
}
if (firstPass) {
progressBar->setValue(0);
return true;
}
-void ArchiveWidget::slotArchivingFinished(KJob *job)
+void ArchiveWidget::slotArchivingFinished(KJob *job, bool finished)
{
if (job == NULL || job->error() == 0) {
- if (slotStartArchiving(false)) {
+ if (!finished && slotStartArchiving(false)) {
// We still have files to archive
return;
}
archive_url->setEnabled(true);
proxy_only->setEnabled(true);
compressed_archive->setEnabled(true);
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
files_list->topLevelItem(i)->setDisabled(false);
for (int j = 0; j < files_list->topLevelItem(i)->childCount(); j++)
files_list->topLevelItem(i)->child(j)->setDisabled(false);
QTreeWidgetItem *item;
bool isArchive = compressed_archive->isChecked();
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
QTreeWidgetItem *parentItem = files_list->topLevelItem(i);
if (parentItem->childCount() > 0) {
destUrl = KUrl(archive_url->url().path(KUrl::AddTrailingSlash) + parentItem->data(0, Qt::UserRole).toString());
KUrl src(item->text(0));
KUrl dest = destUrl;
if (isSlideshow) {
- dest = KUrl(destUrl.path(KUrl::AddTrailingSlash) + item->data(0, Qt::UserRole).toString() + "/" + src.fileName());
+ dest = KUrl(destUrl.path(KUrl::AddTrailingSlash) + item->data(0, Qt::UserRole).toString() + '/' + src.fileName());
}
else if (item->data(0, Qt::UserRole).isNull()) {
dest.addPath(src.fileName());
}
QDomElement mlt = m_doc.documentElement();
- QString root = mlt.attribute("root") + "/";
+ QString root = mlt.attribute("root") + '/';
// Adjust global settings
QString basePath;
// process kdenlive producers
QDomNodeList prods = mlt.elementsByTagName("kdenlive_producer");
- for (int i = 0; i < prods.count(); i++) {
+ for (int i = 0; i < prods.count(); ++i) {
QDomElement e = prods.item(i).toElement();
if (e.isNull()) continue;
if (e.hasAttribute("resource")) {
// process mlt producers
prods = mlt.elementsByTagName("producer");
- for (int i = 0; i < prods.count(); i++) {
+ for (int i = 0; i < prods.count(); ++i) {
QDomElement e = prods.item(i).toElement();
if (e.isNull()) continue;
QString src = EffectsList::property(e, "resource");
// process mlt transitions (for luma files)
prods = mlt.elementsByTagName("transition");
QString attribute;
- for (int i = 0; i < prods.count(); i++) {
+ for (int i = 0; i < prods.count(); ++i) {
QDomElement e = prods.item(i).toElement();
if (e.isNull()) continue;
attribute = "resource";
QString endString("\"");
endString.append(basePath);
playList.replace(startString, endString);
- startString = ">" + archive_url->url().path(KUrl::RemoveTrailingSlash);
- endString = ">" + basePath;
+ startString = '>' + archive_url->url().path(KUrl::RemoveTrailingSlash);
+ endString = '>' + basePath;
playList.replace(startString, endString);
}
}
// Add project file
- archive.addLocalFile(m_temp->fileName(), m_name + ".kdenlive");
- bool result = archive.close();
- delete m_temp;
+ bool result = false;
+ if (m_temp) {
+ archive.addLocalFile(m_temp->fileName(), m_name + ".kdenlive");
+ result = archive.close();
+ delete m_temp;
+ m_temp = 0;
+ }
emit archivingFinished(result);
}
archive_url->setEnabled(true);
proxy_only->setEnabled(true);
compressed_archive->setEnabled(true);
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
files_list->topLevelItem(i)->setDisabled(false);
for (int j = 0; j < files_list->topLevelItem(i)->childCount(); j++)
files_list->topLevelItem(i)->child(j)->setDisabled(false);
KIO::NetAccess::mkdir(archive_url->url().path(KUrl::RemoveTrailingSlash), this);
slotDisplayMessage("system-run", i18n("Extracting..."));
buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Abort"));
- m_progressTimer = new QTimer;
- m_progressTimer->setInterval(800);
- m_progressTimer->setSingleShot(false);
- connect(m_progressTimer, SIGNAL(timeout()), this, SLOT(slotExtractProgress()));
m_archiveThread = QtConcurrent::run(this, &ArchiveWidget::doExtracting);
m_progressTimer->start();
}
emit extractingFinished();
}
-QString ArchiveWidget::extractedProjectFile()
+QString ArchiveWidget::extractedProjectFile() const
{
return archive_url->url().path(KUrl::AddTrailingSlash) + m_projectName;
}
void ArchiveWidget::slotExtractingFinished()
{
m_progressTimer->stop();
- delete m_progressTimer;
// Process project file
QFile file(extractedProjectFile());
bool error = false;
error = true;
}
else {
- QString playList = file.readAll();
+ QString playList = QString::fromUtf8(file.readAll());
file.close();
if (playList.isEmpty()) {
error = true;
QTreeWidgetItem *parentItem = NULL;
// Build list of existing proxy ids
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
parentItem = files_list->topLevelItem(i);
if (parentItem->data(0, Qt::UserRole).toString() == "proxy") break;
}
}
// Parse all items to disable original clips for existing proxies
- for (int i = 0; i < proxyIdList.count(); i++) {
+ for (int i = 0; i < proxyIdList.count(); ++i) {
QString id = proxyIdList.at(i);
if (id.isEmpty()) continue;
for (int j = 0; j < files_list->topLevelItemCount(); j++) {
}
else {
// Archive all clips
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
QTreeWidgetItem *parentItem = files_list->topLevelItem(i);
int items = parentItem->childCount();
for (int j = 0; j < items; j++) {
// Calculate requested size
int total = 0;
- for (int i = 0; i < files_list->topLevelItemCount(); i++) {
+ for (int i = 0; i < files_list->topLevelItemCount(); ++i) {
QTreeWidgetItem *parentItem = files_list->topLevelItem(i);
int items = parentItem->childCount();
int itemsCount = 0;
itemsCount ++;
}
}
- parentItem->setText(0, parentItem->text(0).section("(", 0, 0) + i18np("(%1 item)", "(%1 items)", itemsCount));
+ parentItem->setText(0, parentItem->text(0).section('(', 0, 0) + i18np("(%1 item)", "(%1 items)", itemsCount));
}
project_files->setText(i18np("%1 file to archive, requires %2", "%1 files to archive, requires %2", total, KIO::convertSize(m_requestedSize)));
slotCheckSpace();
}
+
+#include "archivewidget.moc"