]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Some proxy / job fixes
[kdenlive] / src / projectlist.cpp
index 174e5ff2065889fab7df3d5e47304db650cef043..683500185314d9ebe8dd338421412fc38919c88e 100644 (file)
@@ -54,6 +54,7 @@
 #include <KApplication>
 #include <KStandardDirs>
 #include <KColorScheme>
+#include <KActionCollection>
 #include <KUrlRequester>
 
 #ifdef NEPOMUK
@@ -236,7 +237,7 @@ ProjectList::ProjectList(QWidget *parent) :
     m_jobsMenu->addAction(cancelJobs);
     m_infoLabel->setMenu(m_jobsMenu);
     box->addWidget(m_infoLabel);
-    
+       
     int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
     QSize iconSize(size, size);
 
@@ -260,6 +261,18 @@ ProjectList::ProjectList(QWidget *parent) :
 
     m_listView = new ProjectListView;
     layout->addWidget(m_listView);
+    
+#if KDE_IS_VERSION(4,7,0)    
+    m_infoMessage = new KMessageWidget;
+    layout->addWidget(m_infoMessage);
+    m_infoMessage->setCloseButtonVisible(true);
+    //m_infoMessage->setWordWrap(true);
+    m_infoMessage->hide();
+    m_logAction = new QAction(i18n("Show Log"), this);
+    m_logAction->setCheckable(false);
+    connect(m_logAction, SIGNAL(triggered()), this, SLOT(slotShowJobLog()));
+#endif
+
     setLayout(layout);
     searchView->setTreeWidget(m_listView);
 
@@ -277,7 +290,13 @@ ProjectList::ProjectList(QWidget *parent) :
     connect(m_listView, SIGNAL(showProperties(DocClipBase *)), this, SIGNAL(showClipProperties(DocClipBase *)));
     
     connect(this, SIGNAL(cancelRunningJob(const QString, stringMap )), this, SLOT(slotCancelRunningJob(const QString, stringMap)));
-
+    connect(this, SIGNAL(processLog(const QString, int , int)), this, SLOT(slotProcessLog(const QString, int , int)));
+    
+    connect(this, SIGNAL(updateJobStatus(const QString &, int, int, const QString &, const QString &, const QString)), this, SLOT(slotUpdateJobStatus(const QString &, int, int, const QString &, const QString &, const QString)));
+    
+    connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
+    connect(this, SIGNAL(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
+    
     m_listViewDelegate = new ItemDelegate(m_listView);
     m_listView->setItemDelegate(m_listViewDelegate);
 #ifdef NEPOMUK
@@ -296,12 +315,17 @@ ProjectList::~ProjectList()
     m_abortAllJobs = true;
     m_closing = true;
     m_thumbnailQueue.clear();
+    m_jobThreads.waitForFinished();
+    m_jobThreads.clearFutures();
     if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
     m_jobList.clear();
     delete m_menu;
     m_listView->blockSignals(true);
     m_listView->clear();
     delete m_listViewDelegate;
+#if KDE_IS_VERSION(4,7,0)
+    delete m_infoMessage;
+#endif
 }
 
 void ProjectList::focusTree() const
@@ -897,7 +921,8 @@ void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QSt
     clip->setProperties(properties);
     if (properties.contains("proxy")) {
         if (properties.value("proxy") == "-" || properties.value("proxy").isEmpty())
-            clip->setJobStatus(NOJOB);
+            // this should only apply to proxy jobs
+            clip->setConditionalJobStatus(NOJOB, PROXYJOB);
     }
     if (properties.contains("name")) {
         monitorItemEditing(false);
@@ -1119,7 +1144,6 @@ void ProjectList::slotDeleteClip(const QString &clipId)
         return;
     }
     deleteJobsForClip(clipId);
-    if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
     m_listView->blockSignals(true);
     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
     if (!newSelectedItem)
@@ -1293,7 +1317,7 @@ void ProjectList::slotGotProxy(const QString &proxyPath)
     QTreeWidgetItemIterator it(m_listView);
     ProjectItem *item;
 
-    while (*it && !m_abortAllJobs) {
+    while (*it && !m_closing) {
         if ((*it)->type() == PROJECTCLIPTYPE) {
             item = static_cast <ProjectItem *>(*it);
             if (item->referencedClip()->getProperty("proxy") == proxyPath)
@@ -1303,6 +1327,13 @@ void ProjectList::slotGotProxy(const QString &proxyPath)
     }
 }
 
+void ProjectList::slotGotProxyForId(const QString id)
+{
+    if (m_closing) return;
+    ProjectItem *item = getItemById(id);
+    slotGotProxy(item);
+}
+
 void ProjectList::slotGotProxy(ProjectItem *item)
 {
     if (item == NULL) return;
@@ -1333,8 +1364,8 @@ void ProjectList::slotResetProjectList()
     m_listView->blockSignals(true);
     m_abortAllJobs = true;
     m_closing = true;
-    m_proxyThreads.waitForFinished();
-    m_proxyThreads.clearFutures();
+    m_jobThreads.waitForFinished();
+    m_jobThreads.clearFutures();
     m_thumbnailQueue.clear();
     if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
     m_jobList.clear();
@@ -1444,7 +1475,8 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr
                 bool replace = false;
                 if (brokenClips.contains(item->clipId())) {
                     // if this is a proxy clip, disable proxy
-                    item->setJobStatus(NOJOB);
+                    item->setConditionalJobStatus(NOJOB, PROXYJOB);
+                    discardJobs(item->clipId(), PROXYJOB);
                     clip->setProperty("proxy", "-");
                     replace = true;
                 }
@@ -1664,7 +1696,7 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
             kDebug() << "Proxy duration is wrong, try changing transcoding parameters.";
             emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2);
         }
-        item->setJobStatus(JOBCRASHED);
+        slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy for %1. check parameters", item->text(0)), "project_settings");
         QString path = item->referencedClip()->getProperty("proxy");
         KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/");
 
@@ -1792,8 +1824,8 @@ void ProjectList::setDocument(KdenliveDoc *doc)
     m_listView->blockSignals(true);
     m_abortAllJobs = true;
     m_closing = true;
-    m_proxyThreads.waitForFinished();
-    m_proxyThreads.clearFutures();
+    m_jobThreads.waitForFinished();
+    m_jobThreads.clearFutures();
     m_thumbnailQueue.clear();
     m_listView->clear();
     m_processingClips.clear();
@@ -1979,7 +2011,6 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
 {
     QString toReload;
     ProjectItem *item = getItemById(clipId);
-
     int queue = m_render->processingItems();
     if (item && producer) {
         monitorItemEditing(false);
@@ -1996,8 +2027,14 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
 
         // Proxy stuff
         QString size = properties.value("frame_size");
-        if (!useProxy() && clip->getProperty("proxy").isEmpty()) setJobStatus(item, NOJOB);
-        if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setJobStatus(item, NOJOB);
+        if (!useProxy() && clip->getProperty("proxy").isEmpty()) {
+            item->setConditionalJobStatus(NOJOB, PROXYJOB);
+            discardJobs(clipId, PROXYJOB);
+        }
+        if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") {
+            item->setConditionalJobStatus(NOJOB, PROXYJOB);
+            discardJobs(clipId, PROXYJOB);
+        }
         else if (useProxy() && !item->hasProxy() && !hasPendingProxy(item)) {
             // proxy video and image clips
             int maxSize;
@@ -2490,37 +2527,35 @@ void ProjectList::slotCreateProxy(const QString id)
     if (!item || hasPendingProxy(item) || item->referencedClip()->isPlaceHolder()) return;
     QString path = item->referencedClip()->getProperty("proxy");
     if (path.isEmpty()) {
-        setJobStatus(item, JOBCRASHED);
+        slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
         return;
     }
 
-    if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
     if (m_processingProxy.contains(path)) {
         // Proxy is already being generated
         return;
     }
     if (QFileInfo(path).size() > 0) {
         // Proxy already created
-        setJobStatus(item, JOBDONE);
+        setJobStatus(item, PROXYJOB, JOBDONE);
         slotGotProxy(path);
         return;
     }
-    if (!item->isJobRunning()) setJobStatus(item, JOBWAITING);
     m_processingProxy.append(path);
 
     ProxyJob *job = new ProxyJob(item->clipType(), id, QStringList() << path << item->clipUrl().path() << item->referencedClip()->producerProperty("_exif_orientation") << m_doc->getDocumentProperty("proxyparams").simplified() << QString::number(m_render->frameRenderWidth()) << QString::number(m_render->renderHeight()));
     m_jobList.append(job);
-    
-    startJobProcess();
+    setJobStatus(item, job->jobType, JOBWAITING);
+    slotCheckJobProcess();
 }
 
 void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
 {
     ProjectItem *item = getItemById(id);
     if (!item|| item->referencedClip()->isPlaceHolder()) return;
-    QString dest = item->clipUrl().path();
-    QString ext = dest.section('.', -1);
-    dest = dest.section('.', 0, -2) + "_" + QString::number(zone.x()) + "." + ext;
+    QString source = item->clipUrl().path();
+    QString ext = source.section('.', -1);
+    QString dest = source.section('.', 0, -2) + "_" + QString::number(zone.x()) + "." + ext;
     
     double clipFps = item->referencedClip()->getProperty("fps").toDouble();
     if (clipFps == 0) clipFps = m_fps;
@@ -2530,213 +2565,219 @@ void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
     in = GenTime(in, m_timecode.fps()).frames(clipFps);
     out = GenTime(out, m_timecode.fps()).frames(clipFps);
     int max = GenTime(item->clipMaxDuration(), m_timecode.fps()).frames(clipFps);
-    int duration = out - in;
+    int duration = out - in + 1;
     QString timeIn = Timecode::getStringTimecode(in, clipFps, true);
     QString timeOut = Timecode::getStringTimecode(duration, clipFps, true);
     
     QDialog *d = new QDialog(this);
     Ui::CutJobDialog_UI ui;
     ui.setupUi(d);
+    ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
     ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
     ui.file_url->setUrl(KUrl(dest));
-    ui.info_label->setText(i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true)));
-    if (d->exec() != QDialog::Accepted) return;
+    QString mess = i18n("Extracting %1 out of %2", timeOut, Timecode::getStringTimecode(max, clipFps, true));
+    ui.info_label->setText(mess);
+    if (d->exec() != QDialog::Accepted) {
+        delete d;
+        return;
+    }
     dest = ui.file_url->url().path();
+    bool acceptPath = dest != source;
+    if (acceptPath && QFileInfo(dest).size() > 0) {
+        // destination file olready exists, overwrite?
+        acceptPath = false;
+    }
+    while (!acceptPath) {
+        // Do not allow to save over original clip
+        if (dest == source) ui.info_label->setText("<b>" + i18n("You cannot overwrite original clip.") + "</b><br>" + mess);
+        else if (KMessageBox::questionYesNo(this, i18n("Overwrite file %1", dest)) == KMessageBox::Yes) break;
+        if (d->exec() != QDialog::Accepted) {
+            delete d;
+            return;
+        }
+        dest = ui.file_url->url().path();
+        acceptPath = dest != source;
+        if (acceptPath && QFileInfo(dest).size() > 0) {
+            acceptPath = false;
+        }
+    }
     QString extraParams = ui.extra_params->toPlainText().simplified();
+    KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
     delete d;
-    
-    if (QFileInfo(dest).size() > 0) {
-        // Clip already created
-        setJobStatus(item, JOBDONE);
-        emit addClip(dest, QString(), QString());
-        return;
-    }
-    if (!item->isJobRunning()) setJobStatus(item, JOBWAITING);
+
     m_processingProxy.append(dest);
     QStringList jobParams;
-    jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration);
+    jobParams << dest << item->clipUrl().path() << timeIn << timeOut << QString::number(duration) << QString::number(KdenliveSettings::add_clip_cut());
     if (!extraParams.isEmpty()) jobParams << extraParams;
     CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
     m_jobList.append(job);
-    
-    startJobProcess();
+    setJobStatus(item, job->jobType, JOBWAITING);
+
+    slotCheckJobProcess();
 }
 
 
-void ProjectList::startJobProcess()
-{
-    int ct = 0;
-    if (!m_proxyThreads.futures().isEmpty()) {
+void ProjectList::slotCheckJobProcess()
+{        
+    if (!m_jobThreads.futures().isEmpty()) {
         // Remove inactive threads
-        QList <QFuture<void> > futures = m_proxyThreads.futures();
-        m_proxyThreads.clearFutures();
+        QList <QFuture<void> > futures = m_jobThreads.futures();
+        m_jobThreads.clearFutures();
         for (int i = 0; i < futures.count(); i++)
             if (!futures.at(i).isFinished()) {
-                m_proxyThreads.addFuture(futures.at(i));
-                ct++;
+                m_jobThreads.addFuture(futures.at(i));
             }
     }
-    emit jobCount(ct + m_jobList.count());
+    if (m_jobList.isEmpty()) return;
+    int count = 0;
+    m_jobMutex.lock();
+    for (int i = 0; i < m_jobList.count(); i++) {
+        if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
+            count ++;
+        else {
+            // remove finished jobs
+            AbstractClipJob *job = m_jobList.takeAt(i);
+            delete job;
+            i--;
+        }
+    }
+
+    emit jobCount(count);
+    m_jobMutex.unlock();
     
-    if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
+    if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
 }
 
 void ProjectList::slotAbortProxy(const QString id, const QString path)
 {
-    QTreeWidgetItemIterator it(m_listView);
     ProjectItem *item = getItemById(id);
     if (!item) return;
-    if (!path.isEmpty() && m_processingProxy.contains(path)) {
-        m_abortProxy << path;
-    }
-    else {
-        // Should only be done if we were already using a proxy producer
-        if (!item->isProxyRunning()) slotGotProxy(item);
-    }
+    if (!item->isProxyRunning()) slotGotProxy(item);
+    item->setConditionalJobStatus(NOJOB, PROXYJOB);
+    discardJobs(id, PROXYJOB);
 }
 
 void ProjectList::slotProcessJobs()
 {
     while (!m_jobList.isEmpty() && !m_abortAllJobs) {
         emit projectModified();
-        AbstractClipJob *job = m_jobList.takeFirst();
-        // Get jobs count
-        int ct = 0;
-        QList <QFuture<void> > futures = m_proxyThreads.futures();
-        for (int i = 0; i < futures.count(); i++)
-            if (futures.at(i).isRunning()) {
-                ct++;
-            }
-        emit jobCount(ct + m_jobList.count());
-
-        if (job->jobType == PROXYJOB) {
-            //ProxyJob *pjob = static_cast<ProxyJob *> (job);
-            kDebug()<<"// STARTING JOB: "<<job->destination();
-            if (m_abortProxy.contains(job->destination())) {
-                m_abortProxy.removeAll(job->destination());
-                m_processingProxy.removeAll(job->destination());
-                emit cancelRunningJob(job->clipId(), job->cancelProperties());
-                delete job;
-                continue;
+        AbstractClipJob *job = NULL;
+        int count = 0;
+        m_jobMutex.lock();
+        for (int i = 0; i < m_jobList.count(); i++) {
+            if (m_jobList.at(i)->jobStatus == JOBWAITING) {
+                if (job == NULL) {
+                    m_jobList.at(i)->jobStatus = JOBWORKING;
+                    job = m_jobList.at(i);
+                }
+                count++;
             }
+            else if (m_jobList.at(i)->jobStatus == JOBWORKING)
+                count ++;
         }
-        
+        // Set jobs count
+        emit jobCount(count);
+        m_jobMutex.unlock();
+
+        if (job == NULL) {
+            break;
+        }
+        QString destination = job->destination();
+       
         // Get the list of clips that will need to get progress info
-        QTreeWidgetItemIterator it(m_listView);
-        QList <ProjectItem *> processingItems;
-        ProjectItem *item = getItemById(job->clipId());
-        processingItems.append(item);
-        
-        /*while (*it && !m_abortAllJobs) {
-            if ((*it)->type() == PROJECTCLIPTYPE) {
-                ProjectItem *item = static_cast <ProjectItem *>(*it);
-                if (item->referencedClip()->getProperty("proxy") == job->destination()) {
-                    processingItems.append(item);
-                }
-            }
-            ++it;
-        }*/
+        ProjectItem *processingItem = getItemById(job->clipId());
+        if (processingItem == NULL) {
+            job->setStatus(JOBDONE);
+            continue;
+        }
 
-        // Make sure proxy path is writable
-        QFile file(job->destination());
+        // Make sure destination path is writable
+        QFile file(destination);
         if (!file.open(QIODevice::WriteOnly)) {
-            for (int i = 0; i < processingItems.count(); i++)
-                setJobStatus(processingItems.at(i), JOBCRASHED);
-            m_processingProxy.removeAll(job->destination());
-            delete job;
+            emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
+            m_processingProxy.removeAll(destination);
+            job->setStatus(JOBCRASHED);
             continue;
         }
         file.close();
-        QFile::remove(job->destination());
+        QFile::remove(destination);
     
-        for (int i = 0; i < processingItems.count(); i++)
-            setJobStatus(processingItems.at(i), CREATINGJOB, 0, job->jobType);
+        //setJobStatus(processingItem, JOBWORKING, 0, job->jobType, job->statusMessage());
 
         bool success;
         QProcess *jobProcess = job->startJob(&success);
-            
         int result = -1;
         if (jobProcess == NULL) {
             // job is finished
-            for (int i = 0; i < processingItems.count(); i++)
-                setJobStatus(processingItems.at(i), success ? JOBDONE : JOBCRASHED);
             if (success) {
-                if (job->jobType == PROXYJOB) slotGotProxy(job->destination());
+                emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
+                if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
                 //TODO: set folder for transcoded clips
-                else if (job->jobType == CUTJOB) emit addClip(job->destination(), QString(), QString());
+                else if (job->jobType == CUTJOB) emit addClip(destination, QString(), QString());
+                job->setStatus(JOBDONE);
             }
             else {
-                QFile::remove(job->destination());
+                QFile::remove(destination);
+                emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, job->errorMessage());
+                job->setStatus(JOBCRASHED);
             }
-            m_abortProxy.removeAll(job->destination());
-            m_processingProxy.removeAll(job->destination());
-            delete job;
+            m_processingProxy.removeAll(destination);
             continue;
         }
         else while (jobProcess->state() != QProcess::NotRunning) {
             // building proxy file
-            if (m_abortProxy.contains(job->destination()) || m_abortAllJobs) {
+            if (m_abortAllJobs || job->jobStatus == JOBABORTED) {
+                job->jobStatus = JOBABORTED;
                 jobProcess->close();
                 jobProcess->waitForFinished();
-                QFile::remove(job->destination());
-                m_abortProxy.removeAll(job->destination());
-                m_processingProxy.removeAll(job->destination());
+                QFile::remove(destination);
+                m_processingProxy.removeAll(destination);
                 if (!m_closing) {
                     emit cancelRunningJob(job->clipId(), job->cancelProperties());
-                    /*for (int i = 0; i < processingItems.count(); i++)
-                        setJobStatus(processingItems.at(i), NOJOB);*/
                 }
-                else continue;
                 result = -2;
+                continue;
             }
             else {
                 int progress = job->processLogInfo();
-                if (progress > -1) processLogInfo(processingItems, progress, job->jobType);
+                if (progress > 0) emit processLog(job->clipId(), progress, job->jobType); 
             }
             jobProcess->waitForFinished(500);
         }
         jobProcess->waitForFinished();
-        m_processingProxy.removeAll(job->destination());
+        m_processingProxy.removeAll(destination);
         if (result == -1) result = jobProcess->exitStatus();
         
-        if (result != -2 && QFileInfo(job->destination()).size() == 0) {
-            result = QProcess::CrashExit;
+        if (result != -2 && QFileInfo(destination).size() == 0) {
+            job->processLogInfo();
+            emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Failed to create file"), QString(), job->errorMessage());
+            job->setStatus(JOBCRASHED);
+            result = -2;
         }
-        
         if (result == QProcess::NormalExit) {
             // proxy successfully created
-            for (int i = 0; i < processingItems.count(); i++)
-                setJobStatus(processingItems.at(i), JOBDONE);
-            if (job->jobType == PROXYJOB) slotGotProxy(job->destination());
+            emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
+            if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
             //TODO: set folder for transcoded clips
-            else if (job->jobType == CUTJOB) emit addClip(job->destination(), QString(), QString());
+            else if (job->jobType == CUTJOB) {
+                CutClipJob *cutJob = static_cast<CutClipJob *>(job);
+                if (cutJob->addClipToProject) emit addClip(destination, QString(), QString());
+            }
+            job->setStatus(JOBDONE);
         }
         else if (result == QProcess::CrashExit) {
             // Proxy process crashed
-            QFile::remove(job->destination());
-            for (int i = 0; i < processingItems.count(); i++)
-                setJobStatus(processingItems.at(i), JOBCRASHED);
+            QFile::remove(destination);
+            emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Job crashed"), QString(), job->errorMessage());
+            job->setStatus(JOBCRASHED);
         }
-        delete job;
         continue;
     }
-    // Thread finished, update count
-    int ct = -1; // -1 because we don't want to count this terminating thread
-    QList <QFuture<void> > futures = m_proxyThreads.futures();
-    for (int i = 0; i < futures.count(); i++)
-        if (futures.at(i).isRunning()) {
-            ct++;
-        }
-    emit jobCount(ct + m_jobList.count());
+    // Thread finished, cleanup & update count
+    QTimer::singleShot(200, this, SIGNAL(checkJobProcess()));
 }
 
 
-void ProjectList::processLogInfo(QList <ProjectItem *>items, int progress, JOBTYPE jobType)
-{
-    for (int i = 0; i < items.count(); i++)
-        setJobStatus(items.at(i), CREATINGJOB, progress, jobType);
-}
-
 void ProjectList::updateProxyConfig()
 {
     ProjectItem *item;
@@ -2808,6 +2849,12 @@ void ProjectList::updateProxyConfig()
     else delete command;
 }
 
+void ProjectList::slotProcessLog(const QString id, int progress, int type)
+{
+    ProjectItem *item = getItemById(id);
+    setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress);
+}
+
 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
 {
     QList<QTreeWidgetItem *> list;
@@ -2915,11 +2962,11 @@ void ProjectList::slotDeleteProxy(const QString proxyPath)
     QFile::remove(proxyPath);
 }
 
-void ProjectList::setJobStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress, JOBTYPE jobType)
+void ProjectList::setJobStatus(ProjectItem *item, JOBTYPE jobType, CLIPJOBSTATUS status, int progress, const QString &statusMessage)
 {
-    if (item == NULL || m_abortAllJobs) return;
+    if (item == NULL || (m_abortAllJobs && m_closing)) return;
     monitorItemEditing(false);
-    item->setJobStatus(status, progress, jobType);
+    item->setJobStatus(jobType, status, progress);
     if (status == JOBCRASHED) {
         DocClipBase *clip = item->referencedClip();
         if (!clip) {
@@ -2983,10 +3030,11 @@ void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
 void ProjectList::slotCancelJobs()
 {
     m_abortAllJobs = true;
-    m_proxyThreads.waitForFinished();
-    m_proxyThreads.clearFutures();
+    m_jobThreads.waitForFinished();
+    m_jobThreads.clearFutures();
     QUndoCommand *command = new QUndoCommand();
     command->setText(i18np("Cancel job", "Cancel jobs", m_jobList.count()));
+    m_jobMutex.lock();
     for (int i = 0; i < m_jobList.count(); i++) {
         ProjectItem *item = getItemById(m_jobList.at(i)->clipId());
         if (!item || !item->referencedClip()) continue;
@@ -2995,6 +3043,7 @@ void ProjectList::slotCancelJobs()
         QMap <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
         new EditClipCommand(this, m_jobList.at(i)->clipId(), oldProps, newProps, true, command);
     }
+    m_jobMutex.unlock();
     if (command->childCount() > 0) {
         m_doc->commandStack()->push(command);
     }
@@ -3021,27 +3070,91 @@ void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
 bool ProjectList::hasPendingProxy(ProjectItem *item)
 {
     if (!item || !item->referencedClip() || m_abortAllJobs) return false;
+    AbstractClipJob *job;
+    QMutexLocker lock(&m_jobMutex);
     for (int i = 0; i < m_jobList.count(); i++) {
         if (m_abortAllJobs) break;
-        if (m_jobList.at(i)->clipId() == item->clipId() && m_jobList.at(i)->jobType == PROXYJOB) return true;
+        job = m_jobList.at(i);
+        if (job->clipId() == item->clipId() && job->jobType == PROXYJOB && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
     }
-    if (item->isProxyRunning()) return true;
+    
     return false;
 }
 
 void ProjectList::deleteJobsForClip(const QString &clipId)
 {
-    QList <AbstractClipJob *> jobsToDelete;
+    QMutexLocker lock(&m_jobMutex);
     for (int i = 0; i < m_jobList.count(); i++) {
         if (m_abortAllJobs) break;
         if (m_jobList.at(i)->clipId() == clipId) {
-            AbstractClipJob *job = m_jobList.takeAt(i);
-            delete job;
-            i--;
+            m_jobList.at(i)->setStatus(JOBABORTED);
         }
     }
 }
 
+void ProjectList::slotUpdateJobStatus(const QString &id, int type, int status, const QString &label, const QString &actionName, const QString details)
+{
+    ProjectItem *item = getItemById(id);
+    if (!item) return;
+    slotUpdateJobStatus(item, type, status, label, actionName, details);
+    
+}
+
+void ProjectList::slotUpdateJobStatus(ProjectItem *item, int type, int status, const QString &label, const QString &actionName, const QString details)
+{
+    item->setJobStatus((JOBTYPE) type, (CLIPJOBSTATUS) status);
+    if (status != JOBCRASHED) return;
+#if KDE_IS_VERSION(4,7,0)
+    m_infoMessage->animatedHide();
+    m_errorLog.clear();
+    m_infoMessage->setText(label);
+    m_infoMessage->setWordWrap(label.length() > 35);
+    m_infoMessage->setMessageType(KMessageWidget::Warning);
+    QList<QAction *> actions = m_infoMessage->actions();
+    for (int i = 0; i < actions.count(); i++) {
+        m_infoMessage->removeAction(actions.at(i));
+    }
+    
+    if (!actionName.isEmpty()) {
+        QAction *action = NULL;
+        QList< KActionCollection * > collections = KActionCollection::allCollections();
+        for (int i = 0; i < collections.count(); i++) {
+            KActionCollection *coll = collections.at(i);
+            action = coll->action(actionName);
+            if (action) break;
+        }
+        if (action) m_infoMessage->addAction(action);
+    }
+    if (!details.isEmpty()) {
+        m_errorLog = details;
+        m_infoMessage->addAction(m_logAction);
+    }
+    m_infoMessage->animatedShow();
+#endif
+}
+
+void ProjectList::slotShowJobLog()
+{
+#if KDE_IS_VERSION(4,7,0)
+    KDialog d(this);
+    d.setButtons(KDialog::Close);
+    QTextEdit t(&d);
+    t.setPlainText(m_errorLog);
+    t.setReadOnly(true);
+    d.setMainWidget(&t);
+    d.exec();
+#endif
+}
+
+void ProjectList::discardJobs(const QString &id, JOBTYPE type) {
+    QMutexLocker lock(&m_jobMutex);
+    for (int i = 0; i < m_jobList.count(); i++) {
+        if (m_jobList.at(i)->clipId() == id && m_jobList.at(i)->jobType == type) {
+            // discard this job
+            m_jobList.at(i)->setStatus(JOBABORTED);
+        }
+    }
+}
 
 
 #include "projectlist.moc"