]> git.sesse.net Git - kdenlive/blobdiff - src/archivewidget.cpp
Initialize variable
[kdenlive] / src / archivewidget.cpp
index bee3707f224e1f7b0e7d0bff0cfce5658e219e0b..d93c87470badd3619e5df614d78343a9732d8e50 100644 (file)
 
 
 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)
+        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);
@@ -197,7 +199,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");
@@ -206,7 +208,7 @@ ArchiveWidget::ArchiveWidget(QString projectName, QDomDocument doc, QList <DocCl
     buttonBox->button(QDialogButtonBox::Apply)->setText(i18n("Archive"));
     connect(buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotStartArchiving()));
     buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
-
+    
     slotCheckSpace();
 }
 
@@ -219,6 +221,10 @@ ArchiveWidget::ArchiveWidget(const KUrl &url, QWidget * parent):
     //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 &)));
     
@@ -240,6 +246,7 @@ ArchiveWidget::ArchiveWidget(const KUrl &url, QWidget * parent):
 ArchiveWidget::~ArchiveWidget()
 {
     if (m_extractArchive) delete m_extractArchive;
+    if (m_progressTimer) delete m_progressTimer;
 }
 
 void ArchiveWidget::slotDisplayMessage(const QString &icon, const QString &text)
@@ -285,6 +292,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);
@@ -356,7 +364,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();
@@ -376,10 +384,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);
@@ -442,7 +450,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;
@@ -462,7 +470,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);
@@ -529,9 +537,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()) {
@@ -548,15 +556,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++) {
@@ -586,6 +595,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);
@@ -624,10 +639,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;
         }
@@ -681,7 +696,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());
@@ -695,7 +710,7 @@ bool ArchiveWidget::processProjectFile()
     }
     
     QDomElement mlt = m_doc.documentElement();
-    QString root = mlt.attribute("root") + "/";
+    QString root = mlt.attribute("root") + '/';
 
     // Adjust global settings
     QString basePath;
@@ -761,8 +776,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);
     }
 
@@ -817,9 +832,12 @@ void ArchiveWidget::createArchive()
     }
 
     // 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;
+    }
     emit archivingFinished(result);
 }
 
@@ -860,10 +878,6 @@ void ArchiveWidget::slotStartExtracting()
     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();
 }
@@ -898,7 +912,6 @@ QString ArchiveWidget::extractedProjectFile()
 void ArchiveWidget::slotExtractingFinished()
 {
     m_progressTimer->stop();
-    delete m_progressTimer;
     // Process project file
     QFile file(extractedProjectFile());
     bool error = false;
@@ -906,7 +919,7 @@ void ArchiveWidget::slotExtractingFinished()
         error = true;
     }
     else {
-        QString playList = file.readAll();
+        QString playList = QString::fromUtf8(file.readAll());
         file.close();
         if (playList.isEmpty()) {
             error = true;
@@ -997,7 +1010,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();