]> git.sesse.net Git - kdenlive/blobdiff - src/archivewidget.cpp
Fix crash when opening invalid file from command line: http://kdenlive.org/mantis...
[kdenlive] / src / archivewidget.cpp
index 6dc3cda02f286d6f9bc7c546f261c027cee9711a..569d336ac7dd6a02dc33d1e93ef89c45db291252 100644 (file)
@@ -197,7 +197,7 @@ ArchiveWidget::ArchiveWidget(QString projectName, QDomDocument doc, QList <DocCl
                 }
             }
             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");
@@ -223,6 +223,7 @@ ArchiveWidget::ArchiveWidget(const KUrl &url, QWidget * parent):
     connect(this, SIGNAL(showMessage(const QString &, const QString &)), this, SLOT(slotDisplayMessage(const QString &, const QString &)));
     
     compressed_archive->setHidden(true);
+    proxy_only->setHidden(true);
     project_files->setHidden(true);
     files_list->setHidden(true);
     label->setText(i18n("Extract to"));
@@ -284,6 +285,7 @@ void ArchiveWidget::openArchiveForExtraction()
     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);
@@ -355,7 +357,7 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, QStringList items
                 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();
@@ -375,10 +377,10 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, QStringList items
         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);
@@ -441,7 +443,7 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, QMap <QString, QS
                 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;
@@ -461,7 +463,7 @@ void ArchiveWidget::generateItems(QTreeWidgetItem *parentItem, QMap <QString, QS
         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);
@@ -528,9 +530,9 @@ bool ArchiveWidget::slotStartArchiving(bool firstPass)
     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++) {
         parentItem = files_list->topLevelItem(i);
         if (parentItem->isDisabled()) {
@@ -547,15 +549,16 @@ bool ArchiveWidget::slotStartArchiving(bool firstPass)
             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++) {
@@ -585,6 +588,12 @@ bool ArchiveWidget::slotStartArchiving(bool firstPass)
         }
     }
 
+    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);
@@ -623,10 +632,10 @@ bool ArchiveWidget::slotStartArchiving(bool firstPass)
     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;
         }
@@ -680,7 +689,7 @@ bool ArchiveWidget::processProjectFile()
                 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());
@@ -694,7 +703,7 @@ bool ArchiveWidget::processProjectFile()
     }
     
     QDomElement mlt = m_doc.documentElement();
-    QString root = mlt.attribute("root") + "/";
+    QString root = mlt.attribute("root") + '/';
 
     // Adjust global settings
     QString basePath;
@@ -760,8 +769,8 @@ bool ArchiveWidget::processProjectFile()
         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);
     }
 
@@ -905,7 +914,7 @@ void ArchiveWidget::slotExtractingFinished()
         error = true;
     }
     else {
-        QString playList = file.readAll();
+        QString playList = QString::fromUtf8(file.readAll());
         file.close();
         if (playList.isEmpty()) {
             error = true;
@@ -996,7 +1005,7 @@ void ArchiveWidget::slotProxyOnly(int onlyProxy)
                 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();