]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
* Fix missing proxy not re-created on project opening
[kdenlive] / src / projectlist.cpp
index 2e4bfac0db01a90537f1ea98d5a10672f6894b06..95c06db00bdfa9f19e952a25550eec39f141e046 100644 (file)
@@ -21,6 +21,8 @@
 #include "projectitem.h"
 #include "commands/addfoldercommand.h"
 #include "projecttree/proxyclipjob.h"
+#include "projecttree/cutclipjob.h"
+#include "projecttree/meltjob.h"
 #include "kdenlivesettings.h"
 #include "slideshowclip.h"
 #include "ui_colorclip_ui.h"
@@ -40,6 +42,7 @@
 #include "commands/addclipcutcommand.h"
 
 #include "ui_templateclip_ui.h"
+#include "ui_cutjobdialog_ui.h"
 
 #include <KDebug>
 #include <KAction>
 #include <KApplication>
 #include <KStandardDirs>
 #include <KColorScheme>
+#include <KActionCollection>
+#include <KUrlRequester>
 
-#ifdef NEPOMUK
+#ifdef USE_NEPOMUK
 #include <nepomuk/global.h>
 #include <nepomuk/resourcemanager.h>
+#include <Nepomuk/Resource>
 //#include <nepomuk/tag.h>
 #endif
 
@@ -119,6 +125,7 @@ void SmallInfoLabel::slotSetJobCount(int jobCount)
         setToolTip(i18np("%1 pending job", "%1 pending jobs", jobCount));
         
         if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
+            setFixedWidth(sizeHint().width());
             show();
             return;
         }
@@ -140,6 +147,7 @@ void SmallInfoLabel::slotSetJobCount(int jobCount)
     }
     else {
         if (!(KGlobalSettings::graphicEffectsLevel() & KGlobalSettings::SimpleAnimationEffects)) {
+            setFixedWidth(0);
             hide();
             return;
         }
@@ -197,8 +205,9 @@ ProjectList::ProjectList(QWidget *parent) :
     m_commandStack(NULL),
     m_openAction(NULL),
     m_reloadAction(NULL),
-    m_stabilizeAction(NULL),
+    m_extractAudioAction(NULL),
     m_transcodeAction(NULL),
+    m_stabilizeAction(NULL),
     m_doc(NULL),
     m_refreshed(false),
     m_allClipsProcessed(false),
@@ -225,13 +234,19 @@ ProjectList::ProjectList(QWidget *parent) :
     m_infoLabel = new SmallInfoLabel(this);
     connect(this, SIGNAL(jobCount(int)), m_infoLabel, SLOT(slotSetJobCount(int)));
     m_jobsMenu = new QMenu(this);
+    connect(m_jobsMenu, SIGNAL(aboutToShow()), this, SLOT(slotPrepareJobsMenu()));
     QAction *cancelJobs = new QAction(i18n("Cancel All Jobs"), this);
     cancelJobs->setCheckable(false);
     connect(cancelJobs, SIGNAL(triggered()), this, SLOT(slotCancelJobs()));
+    connect(this, SIGNAL(checkJobProcess()), this, SLOT(slotCheckJobProcess()));
+    m_discardCurrentClipJobs = new QAction(i18n("Cancel Current Clip Jobs"), this);
+    m_discardCurrentClipJobs->setCheckable(false);
+    connect(m_discardCurrentClipJobs, SIGNAL(triggered()), this, SLOT(slotDiscardClipJobs()));
     m_jobsMenu->addAction(cancelJobs);
+    m_jobsMenu->addAction(m_discardCurrentClipJobs);
     m_infoLabel->setMenu(m_jobsMenu);
     box->addWidget(m_infoLabel);
-    
+       
     int size = style()->pixelMetric(QStyle::PM_SmallIconSize);
     QSize iconSize(size, size);
 
@@ -255,6 +270,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);
 
@@ -266,15 +293,21 @@ ProjectList::ProjectList(QWidget *parent) :
     connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *)));
     connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip()));
     connect(m_listView, SIGNAL(addClip(const QList <QUrl>, const QString &, const QString &)), this, SLOT(slotAddClip(const QList <QUrl>, const QString &, const QString &)));
+    connect(this, SIGNAL(addClip(const QString, const QString &, const QString &)), this, SLOT(slotAddClip(const QString, const QString &, const QString &)));
     connect(m_listView, SIGNAL(addClipCut(const QString &, int, int)), this, SLOT(slotAddClipCut(const QString &, int, int)));
     connect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int)));
     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, const QString)), this, SLOT(slotProcessLog(const QString, int , int, const QString)));
+    
+    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(gotProxy(const QString)), this, SLOT(slotGotProxyForId(const QString)));
+    
     m_listViewDelegate = new ItemDelegate(m_listView);
     m_listView->setItemDelegate(m_listViewDelegate);
-#ifdef NEPOMUK
+#ifdef USE_NEPOMUK
     if (KdenliveSettings::activate_nepomuk()) {
         Nepomuk::ResourceManager::instance()->init();
         if (!Nepomuk::ResourceManager::instance()->initialized()) {
@@ -288,14 +321,22 @@ ProjectList::ProjectList(QWidget *parent) :
 ProjectList::~ProjectList()
 {
     m_abortAllJobs = true;
+    for (int i = 0; i < m_jobList.count(); i++) {
+        m_jobList.at(i)->setStatus(JOBABORTED);
+    }
     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
@@ -347,18 +388,21 @@ void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
                QMenu* addMenu=menus.value("addMenu");
                menu->addMenu(addMenu);
                m_addButton->setMenu(menu);
-
-               m_menu->addMenu(addMenu);
                if (addMenu->isEmpty())
                        addMenu->setEnabled(false);
        }
-       if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
-               QMenu* transcodeMenu=menus.value("transcodeMenu");
-               m_menu->addMenu(transcodeMenu);
-               if (transcodeMenu->isEmpty())
-                       transcodeMenu->setEnabled(false);
-               m_transcodeAction = transcodeMenu;
+       if (menus.contains("extractAudioMenu") && menus.value("extractAudioMenu") ){
+               QMenu* extractAudioMenu = menus.value("extractAudioMenu");
+               m_menu->addMenu(extractAudioMenu);
+                m_extractAudioAction = extractAudioMenu;
        }
+       if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){
+                QMenu* transcodeMenu = menus.value("transcodeMenu");
+                m_menu->addMenu(transcodeMenu);
+                if (transcodeMenu->isEmpty())
+                        transcodeMenu->setEnabled(false);
+                m_transcodeAction = transcodeMenu;
+        }
        if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){
                QMenu* stabilizeMenu=menus.value("stabilizeMenu");
                m_menu->addMenu(stabilizeMenu);
@@ -625,7 +669,7 @@ void ProjectList::slotReloadClip(const QString &id)
             continue;
         }
         item = static_cast <ProjectItem *>(selected.at(i));
-        if (item && !item->isProxyRunning()) {
+        if (item && !hasPendingJob(item, PROXYJOB)) {
             DocClipBase *clip = item->referencedClip();
             if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) {
                 kDebug()<<"//// TRYING TO RELOAD: "<<item->clipId()<<", but it is busy";
@@ -748,6 +792,7 @@ void ProjectList::setRenderer(Render *projectRender)
 {
     m_render = projectRender;
     m_listView->setIconSize(QSize((ProjectItem::itemDefaultHeight() - 2) * m_render->dar(), ProjectItem::itemDefaultHeight() - 2));
+    connect(m_render, SIGNAL(requestProxy(QString)), this, SLOT(slotCreateProxy(QString)));
 }
 
 void ProjectList::slotClipSelected()
@@ -761,6 +806,7 @@ void ProjectList::slotClipSelected()
             m_deleteButton->defaultAction()->setEnabled(true);
             m_openAction->setEnabled(false);
             m_reloadAction->setEnabled(false);
+            m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
             m_stabilizeAction->setEnabled(false);
         } else {
@@ -771,6 +817,7 @@ void ProjectList::slotClipSelected()
                 if (clip == NULL) kDebug() << "-----------ERROR";
                 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
                 emit clipSelected(clip->referencedClip(), sub->zone());
+                m_extractAudioAction->setEnabled(false);
                 m_transcodeAction->setEnabled(false);
                 m_stabilizeAction->setEnabled(false);
                 m_reloadAction->setEnabled(false);
@@ -783,6 +830,7 @@ void ProjectList::slotClipSelected()
             m_editButton->defaultAction()->setEnabled(true);
             m_deleteButton->defaultAction()->setEnabled(true);
             m_reloadAction->setEnabled(true);
+            m_extractAudioAction->setEnabled(true);
             m_transcodeAction->setEnabled(true);
             m_stabilizeAction->setEnabled(true);
             if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
@@ -806,6 +854,7 @@ void ProjectList::slotClipSelected()
         m_deleteButton->defaultAction()->setEnabled(false);
         m_openAction->setEnabled(false);
         m_reloadAction->setEnabled(false);
+        m_extractAudioAction->setEnabled(true);
         m_transcodeAction->setEnabled(false);
         m_stabilizeAction->setEnabled(false);
     }
@@ -839,9 +888,11 @@ void ProjectList::adjustTranscodeActions(ProjectItem *clip) const
 {
     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) {
         m_transcodeAction->setEnabled(false);
+        m_extractAudioAction->setEnabled(false);
         return;
     }
     m_transcodeAction->setEnabled(true);
+    m_extractAudioAction->setEnabled(true);
     QList<QAction *> transcodeActions = m_transcodeAction->actions();
     QStringList data;
     QString condition;
@@ -891,7 +942,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->setProxyStatus(NOJOB);
+            // this should only apply to proxy jobs
+            clip->setConditionalJobStatus(NOJOB, PROXYJOB);
     }
     if (properties.contains("name")) {
         monitorItemEditing(false);
@@ -904,7 +956,7 @@ void ProjectList::slotUpdateClipProperties(ProjectItem *clip, QMap <QString, QSt
         monitorItemEditing(false);
         clip->setText(1, properties.value("description"));
         monitorItemEditing(true);
-#ifdef NEPOMUK
+#ifdef USE_NEPOMUK
         if (KdenliveSettings::activate_nepomuk() && (type == AUDIO || type == VIDEO || type == AV || type == IMAGE || type == PLAYLIST)) {
             // Use Nepomuk system to store clip description
             Nepomuk::Resource f(clip->clipUrl().path());
@@ -985,12 +1037,14 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
     m_editButton->defaultAction()->setEnabled(enable);
     m_deleteButton->defaultAction()->setEnabled(enable);
     m_reloadAction->setEnabled(enable);
+    m_extractAudioAction->setEnabled(enable);
     m_transcodeAction->setEnabled(enable);
     m_stabilizeAction->setEnabled(enable);
     if (enable) {
         ProjectItem *clip = NULL;
         if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) {
             clip = static_cast <ProjectItem*>(item->parent());
+            m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
             m_stabilizeAction->setEnabled(false);
             adjustProxyActions(clip);
@@ -1003,6 +1057,7 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
             // Display uses in timeline
             emit findInTimeline(clip->clipId());
         } else {
+            m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
             m_stabilizeAction->setEnabled(false);
         }
@@ -1112,7 +1167,7 @@ void ProjectList::slotDeleteClip(const QString &clipId)
         kDebug() << "/// Cannot find clip to delete";
         return;
     }
-    if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
+    deleteJobsForClip(clipId);
     m_listView->blockSignals(true);
     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
     if (!newSelectedItem)
@@ -1239,17 +1294,20 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
         m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true);
     }
     // WARNING: code below triggers unnecessary reload of all proxy clips on document loading... is it useful in some cases?
-    /*else if (item->hasProxy() && !item->isProxyRunning()) {
+    /*else if (item->hasProxy() && !item->isJobRunning()) {
         slotCreateProxy(clip->getId());
     }*/
     
     KUrl url = clip->fileURL();
-#ifdef NEPOMUK
-    if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) {
+#ifdef USE_NEPOMUK
+    if (!url.isEmpty() && KdenliveSettings::activate_nepomuk() && clip->getProperty("description").isEmpty()) {
         // if file has Nepomuk comment, use it
         Nepomuk::Resource f(url.path());
         QString annotation = f.description();
-        if (!annotation.isEmpty()) item->setText(1, annotation);
+        if (!annotation.isEmpty()) {
+            item->setText(1, annotation);
+            clip->setProperty("description", annotation);
+        }
         item->setText(2, QString::number(f.rating()));
     }
 #endif
@@ -1286,7 +1344,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)
@@ -1296,6 +1354,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;
@@ -1325,9 +1390,12 @@ void ProjectList::slotResetProjectList()
 {
     m_listView->blockSignals(true);
     m_abortAllJobs = true;
+    for (int i = 0; i < m_jobList.count(); i++) {
+        m_jobList.at(i)->setStatus(JOBABORTED);
+    }
     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();
@@ -1433,22 +1501,24 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr
         } else {
             item = static_cast <ProjectItem *>(*it);
             clip = item->referencedClip();
-            if (item->referencedClip()->getProducer() == NULL) {
+            if (clip->getProducer() == NULL) {
                 bool replace = false;
                 if (brokenClips.contains(item->clipId())) {
                     // if this is a proxy clip, disable proxy
-                    item->setProxyStatus(NOJOB);
+                    item->setConditionalJobStatus(NOJOB, PROXYJOB);
+                    discardJobs(item->clipId(), PROXYJOB);
                     clip->setProperty("proxy", "-");
                     replace = true;
                 }
-                if (clip->isPlaceHolder() == false && !item->isProxyRunning()) {
+                if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
                     QDomElement xml = clip->toXML();
                     if (fpsChanged) {
                         xml.removeAttribute("out");
                         xml.removeAttribute("file_hash");
                         xml.removeAttribute("proxy_out");
                     }
-                    if (!replace) replace = xml.attribute("replace") == "1";
+                    if (!replace) replace = xml.attribute("_replaceproxy") == "1";
+                    xml.removeAttribute("_replaceproxy");
                     if (replace) {
                         resetThumbsProducer(clip);
                     }
@@ -1475,7 +1545,7 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr
                     getCachedThumbnail(item);
                 }
                 if (item->data(0, DurationRole).toString().isEmpty()) {
-                    item->changeDuration(item->referencedClip()->getProducer()->get_playtime());
+                    item->changeDuration(clip->getProducer()->get_playtime());
                 }
                 if (clip->isPlaceHolder()) {
                     QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
@@ -1488,6 +1558,10 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr
                     p.end();
                     item->setData(0, Qt::DecorationRole, pixmap);
                 }
+                else if (clip->getProperty("_replaceproxy") == "1") {
+                    clip->setProperty("_replaceproxy", QString());
+                    slotCreateProxy(clip->getId());
+                }
             }
             item->setData(0, UsageRole, QString::number(item->numReferences()));
         }
@@ -1522,6 +1596,14 @@ QString ProjectList::getExtensions()
     return allExtensions.simplified();
 }
 
+void ProjectList::slotAddClip(const QString url, const QString &groupName, const QString &groupId)
+{
+    kDebug()<<"// Adding clip: "<<url;
+    QList <QUrl> list;
+    list.append(url);
+    slotAddClip(list, groupName, groupId);
+}
+
 void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &groupName, const QString &groupId)
 {
     if (!m_commandStack)
@@ -1607,7 +1689,6 @@ void ProjectList::slotAddClip(const QList <QUrl> givenList, const QString &group
 void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
 {
     ProjectItem *item = getItemById(id);
-    m_processingClips.removeAll(id);
     m_thumbnailQueue.removeAll(id);
     if (item) {
         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
@@ -1649,7 +1730,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->setProxyStatus(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/");
 
@@ -1666,7 +1747,6 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
             item->referencedClip()->reloadThumbProducer();
         }
     }
-    m_processingClips.removeAll(id);
     m_thumbnailQueue.removeAll(id);
 }
 
@@ -1776,12 +1856,14 @@ void ProjectList::setDocument(KdenliveDoc *doc)
 {
     m_listView->blockSignals(true);
     m_abortAllJobs = true;
+    for (int i = 0; i < m_jobList.count(); i++) {
+        m_jobList.at(i)->setStatus(JOBABORTED);
+    }
     m_closing = true;
-    m_proxyThreads.waitForFinished();
-    m_proxyThreads.clearFutures();
+    m_jobThreads.waitForFinished();
+    m_jobThreads.clearFutures();
     m_thumbnailQueue.clear();
     m_listView->clear();
-    m_processingClips.clear();
     
     m_listView->setSortingEnabled(false);
     emit clipSelected(NULL);
@@ -1964,7 +2046,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);
@@ -1981,9 +2062,15 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
 
         // Proxy stuff
         QString size = properties.value("frame_size");
-        if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOJOB);
-        if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOJOB);
-        else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) {
+        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() && !hasPendingJob(item, PROXYJOB)) {
             // proxy video and image clips
             int maxSize;
             CLIPTYPE t = item->clipType();
@@ -2058,6 +2145,8 @@ bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
     QString size = item->referencedClip()->getProperty("frame_size");
     int width = size.section('x', 0, 0).toInt();
     int height = size.section('x', -1).toInt();
+    // Fix some avchd clips tht report a wrong size (1920x1088)
+    if (height == 1088) height = 1080;
     double fps = item->referencedClip()->getProperty("fps").toDouble();
     double par = item->referencedClip()->getProperty("aspect_ratio").toDouble();
     if (item->clipType() == IMAGE || item->clipType() == AV || item->clipType() == VIDEO) {
@@ -2226,6 +2315,7 @@ void ProjectList::slotSelectClip(const QString &ix)
         m_editButton->defaultAction()->setEnabled(true);
         m_deleteButton->defaultAction()->setEnabled(true);
         m_reloadAction->setEnabled(true);
+        m_extractAudioAction->setEnabled(true);
         m_transcodeAction->setEnabled(true);
         m_stabilizeAction->setEnabled(true);
         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
@@ -2283,6 +2373,34 @@ KUrl::List ProjectList::getConditionalUrls(const QString &condition) const
     return result;
 }
 
+QStringList ProjectList::getConditionalIds(const QString &condition) const
+{
+    QStringList result;
+    ProjectItem *item;
+    QList<QTreeWidgetItem *> list = m_listView->selectedItems();
+    for (int i = 0; i < list.count(); i++) {
+        if (list.at(i)->type() == PROJECTFOLDERTYPE)
+            continue;
+        if (list.at(i)->type() == PROJECTSUBCLIPTYPE) {
+            // subitem
+            item = static_cast <ProjectItem*>(list.at(i)->parent());
+        } else {
+            item = static_cast <ProjectItem*>(list.at(i));
+        }
+        if (item == NULL || item->type() == COLOR || item->type() == SLIDESHOW || item->type() == TEXT)
+            continue;
+        DocClipBase *clip = item->referencedClip();
+        if (!condition.isEmpty()) {
+            if (condition.startsWith("vcodec") && !clip->hasVideoCodec(condition.section('=', 1, 1)))
+                continue;
+            else if (condition.startsWith("acodec") && !clip->hasAudioCodec(condition.section('=', 1, 1)))
+                continue;
+        }
+        result.append(item->clipId());
+    }
+    return result;
+}
+
 void ProjectList::regenerateTemplate(const QString &id)
 {
     ProjectItem *clip = getItemById(id);
@@ -2472,200 +2590,283 @@ QMap <QString, QString> ProjectList::getProxies()
 void ProjectList::slotCreateProxy(const QString id)
 {
     ProjectItem *item = getItemById(id);
-    if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
+    if (!item || hasPendingJob(item, PROXYJOB) || item->referencedClip()->isPlaceHolder()) return;
     QString path = item->referencedClip()->getProperty("proxy");
     if (path.isEmpty()) {
-        setProxyStatus(item, JOBCRASHED);
-        return;
-    }
-    setProxyStatus(item, JOBWAITING);
-    if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
-    if (m_processingProxy.contains(path)) {
-        // Proxy is already being generated
+        slotUpdateJobStatus(item, PROXYJOB, JOBCRASHED, i18n("Failed to create proxy, empty path."));
         return;
     }
+    
     if (QFileInfo(path).size() > 0) {
         // Proxy already created
-        setProxyStatus(item, JOBDONE);
+        setJobStatus(item, PROXYJOB, JOBDONE);
         slotGotProxy(path);
         return;
     }
-    m_processingProxy.append(path);
 
-    /*PROXYINFO info;
-    info.dest = path;
-    info.src = item->clipUrl().path();
-    info.type = item->clipType();
-    info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();*/
-    ProxyJob *job = new ProxyJob(PROXYJOB, item->clipType(), item->clipId(), 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()));
+    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()));
+    if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
+        delete job;
+        return;
+    }
+
     m_jobList.append(job);
-    int ct = 0;
-    if (!m_proxyThreads.futures().isEmpty()) {
+    setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+    slotCheckJobProcess();
+}
+
+void ProjectList::slotCutClipJob(const QString &id, QPoint zone)
+{
+    ProjectItem *item = getItemById(id);
+    if (!item|| item->referencedClip()->isPlaceHolder()) return;
+    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;
+    // if clip and project have different frame rate, adjust in and out
+    int in = zone.x();
+    int out = zone.y();
+    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 + 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.extra_params->setVisible(false);
+    ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
+    ui.file_url->fileDialog()->setOperationMode(KFileDialog::Saving);
+    ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
+    ui.file_url->setUrl(KUrl(dest));
+    ui.button_more->setIcon(KIcon("configure"));
+    ui.extra_params->setPlainText("-acodec copy -vcodec copy");
+    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;
+
+    QStringList jobParams;
+    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);
+    if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
+        delete job;
+        return;
+    }
+    m_jobList.append(job);
+    setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+
+    slotCheckJobProcess();
+}
+
+void ProjectList::slotTranscodeClipJob(QStringList ids, QString params, QString desc)
+{
+    QStringList existingFiles;
+    foreach(const QString &id, ids) {
+        ProjectItem *item = getItemById(id);
+        if (!item) continue;
+        QString newFile = params.section(' ', -1).replace("%1", item->clipUrl().path());
+        if (QFile::exists(newFile)) existingFiles << newFile;
+    }
+    if (!existingFiles.isEmpty()) {
+        if (KMessageBox::warningContinueCancelList(this, i18n("The transcoding job will overwrite the following files:"), existingFiles) ==  KMessageBox::Cancel) return;
+    }
+    
+    QDialog *d = new QDialog(this);
+    Ui::CutJobDialog_UI ui;
+    ui.setupUi(d);
+    d->setWindowTitle(i18n("Transcoding"));
+    ui.destination_label->setVisible(false);
+    ui.extra_params->setMaximumHeight(QFontMetrics(font()).lineSpacing() * 5);
+    ui.file_url->setVisible(false);
+    ui.extra_params->setVisible(false);
+    ui.button_more->setIcon(KIcon("configure"));
+    ui.add_clip->setChecked(KdenliveSettings::add_clip_cut());
+    ui.extra_params->setPlainText(params.simplified());
+    QString mess = desc;
+    mess.append(" " + i18np("(%1 clip)", "(%1 clips)", ids.count()));
+    ui.info_label->setText(mess);
+    d->adjustSize();
+    if (d->exec() != QDialog::Accepted) {
+        delete d;
+        return;
+    }
+    params = ui.extra_params->toPlainText().simplified();
+    KdenliveSettings::setAdd_clip_cut(ui.add_clip->isChecked());
+    delete d;
+    
+    foreach(const QString &id, ids) {
+        ProjectItem *item = getItemById(id);
+        if (!item || !item->referencedClip()) continue;
+        QString src = item->clipUrl().path();
+        QString dest = params.section(' ', -1).replace("%1", src);
+        QStringList jobParams;
+        jobParams << dest << src << QString() << QString();
+        double clipFps = item->referencedClip()->getProperty("fps").toDouble();
+        if (clipFps == 0) clipFps = m_fps;
+        int max = item->clipMaxDuration();
+        QString duration = QString::number(max);
+        jobParams << duration;
+        jobParams << QString::number(KdenliveSettings::add_clip_cut());
+        jobParams << params.section(' ', 0, -2);
+        CutClipJob *job = new CutClipJob(item->clipType(), id, jobParams);
+        if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
+            delete job;
+            continue;
+        }
+        m_jobList.append(job);
+        setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+    }
+    slotCheckJobProcess();
+    
+}
+
+
+
+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::slotGenerateProxy));
+    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);
+    Q_UNUSED(path)
+
     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::slotGenerateProxy()
+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;
-            }
-        }
-        
-        // 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);
+        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++;
             }
-            ++it;
-        }*/
-
-        // Make sure proxy path is writable
-        QFile file(job->destination());
-        if (!file.open(QIODevice::WriteOnly)) {
-            for (int i = 0; i < processingItems.count(); i++)
-                setProxyStatus(processingItems.at(i), JOBCRASHED);
-            m_processingProxy.removeAll(job->destination());
-            delete job;
-            continue;
+            else if (m_jobList.at(i)->jobStatus == JOBWORKING)
+                count ++;
         }
-        file.close();
-        QFile::remove(job->destination());
-    
-        for (int i = 0; i < processingItems.count(); i++)
-            setProxyStatus(processingItems.at(i), CREATINGJOB, 0); //, job->description);
-        bool success;
-        QProcess *jobProcess = job->startJob(&success);
-            
-        int result = -1;
-        if (jobProcess == NULL) {
-            // job is finished
-            for (int i = 0; i < processingItems.count(); i++)
-                setProxyStatus(processingItems.at(i), success ? JOBDONE : JOBCRASHED);
-            if (success) {
-                slotGotProxy(job->destination());
-            }
-            else {
-                QFile::remove(job->destination());
-            }
-            m_abortProxy.removeAll(job->destination());
-            m_processingProxy.removeAll(job->destination());
-            delete job;
+        // Set jobs count
+        emit jobCount(count);
+        m_jobMutex.unlock();
+
+        if (job == NULL) {
+            break;
+        }
+        QString destination = job->destination();
+        // Check if the clip is still here
+        DocClipBase *currentClip = m_doc->clipManager()->getClipById(job->clipId());
+        //ProjectItem *processingItem = getItemById(job->clipId());
+        if (currentClip == NULL) {
+            job->setStatus(JOBDONE);
             continue;
         }
-        else while (jobProcess->state() != QProcess::NotRunning) {
-            // building proxy file
-            if (m_abortProxy.contains(job->destination()) || m_abortAllJobs) {
-                jobProcess->close();
-                jobProcess->waitForFinished();
-                QFile::remove(job->destination());
-                m_abortProxy.removeAll(job->destination());
-                m_processingProxy.removeAll(job->destination());
-                if (!m_closing) {
-                    emit cancelRunningJob(job->clipId(), job->cancelProperties());
-                    /*for (int i = 0; i < processingItems.count(); i++)
-                        setProxyStatus(processingItems.at(i), NOJOB);*/
-                }
-                else continue;
-                result = -2;
+        // Set clip status to started
+        emit processLog(job->clipId(), 0, job->jobType, job->statusMessage()); 
+
+        // Make sure destination path is writable
+        if (!destination.isEmpty()) {
+            QFile file(destination);
+            if (!file.open(QIODevice::WriteOnly)) {
+                emit updateJobStatus(job->clipId(), job->jobType, JOBCRASHED, i18n("Cannot write to path: %1", destination));
+                job->setStatus(JOBCRASHED);
+                continue;
             }
-            else {
-                int progress = job->processLogInfo();
-                if (progress > -1) processLogInfo(processingItems, progress);
+            file.close();
+            QFile::remove(destination);
+        }
+        connect(job, SIGNAL(jobProgress(QString, int, int)), this, SIGNAL(processLog(QString, int, int)));
+        connect(job, SIGNAL(cancelRunningJob(const QString, stringMap)), this, SIGNAL(cancelRunningJob(const QString, stringMap)));
+        connect(job, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int, QString,stringMap)));
+
+        if (job->jobType == MLTJOB) {
+            MeltJob *jb = static_cast<MeltJob *> (job);
+            jb->setProducer(currentClip->getProducer());
+        }
+        job->startJob();
+        if (job->jobStatus == JOBDONE) {
+            emit updateJobStatus(job->clipId(), job->jobType, JOBDONE);
+            //TODO: replace with more generic clip replacement framework
+            if (job->jobType == PROXYJOB) emit gotProxy(job->clipId());
+            if (job->addClipToProject) {
+                emit addClip(destination, QString(), QString());
             }
-            jobProcess->waitForFinished(500);
+        } else if (job->jobStatus == JOBCRASHED || job->jobStatus == JOBABORTED) {
+            emit updateJobStatus(job->clipId(), job->jobType, job->jobStatus, job->errorMessage(), QString(), job->logDetails());
         }
-        jobProcess->waitForFinished();
-        m_processingProxy.removeAll(job->destination());
-        if (result == -1) result = jobProcess->exitStatus();
-        
-        if (result != -2 && QFileInfo(job->destination()).size() == 0) {
-            result = QProcess::CrashExit;
-        }
-        
-        if (result == QProcess::NormalExit) {
-            // proxy successfully created
-            for (int i = 0; i < processingItems.count(); i++)
-                setProxyStatus(processingItems.at(i), JOBDONE);
-            slotGotProxy(job->destination());
-        }
-        else if (result == QProcess::CrashExit) {
-            // Proxy process crashed
-            QFile::remove(job->destination());
-            for (int i = 0; i < processingItems.count(); i++)
-                setProxyStatus(processingItems.at(i), 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)
-{
-    for (int i = 0; i < items.count(); i++)
-        setProxyStatus(items.at(i), CREATINGJOB, progress);
-}
-
 void ProjectList::updateProxyConfig()
 {
     ProjectItem *item;
@@ -2685,7 +2886,7 @@ void ProjectList::updateProxyConfig()
         }
         CLIPTYPE t = item->clipType();
         if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) {
-            if  (generateProxy() && useProxy() && !item->isProxyRunning()) {
+            if  (generateProxy() && useProxy() && !hasPendingJob(item, PROXYJOB)) {
                 DocClipBase *clip = item->referencedClip();
                 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
                     if (clip->getProperty("proxy").isEmpty()) {
@@ -2702,7 +2903,6 @@ void ProjectList::updateProxyConfig()
                 // remove proxy
                 QMap <QString, QString> newProps;
                 newProps.insert("proxy", QString());
-                newProps.insert("replace", "1");
                 // insert required duration for proxy
                 newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
                 new EditClipCommand(this, item->clipId(), item->referencedClip()->currentProperties(newProps), newProps, true, command);
@@ -2727,7 +2927,6 @@ void ProjectList::updateProxyConfig()
                 // remove proxy
                 QMap <QString, QString> newProps;
                 newProps.insert("proxy", QString());
-                newProps.insert("replace", "1");
                 new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command);
             }
         }
@@ -2737,6 +2936,12 @@ void ProjectList::updateProxyConfig()
     else delete command;
 }
 
+void ProjectList::slotProcessLog(const QString id, int progress, int type, const QString message)
+{
+    ProjectItem *item = getItemById(id);
+    setJobStatus(item, (JOBTYPE) type, JOBWORKING, progress, message);
+}
+
 void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy)
 {
     QList<QTreeWidgetItem *> list;
@@ -2844,11 +3049,11 @@ void ProjectList::slotDeleteProxy(const QString proxyPath)
     QFile::remove(proxyPath);
 }
 
-void ProjectList::setProxyStatus(ProjectItem *item, CLIPJOBSTATUS status, int progress)
+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->setProxyStatus(status, progress);
+    item->setJobStatus(jobType, status, progress, statusMessage);
     if (status == JOBCRASHED) {
         DocClipBase *clip = item->referencedClip();
         if (!clip) {
@@ -2897,14 +3102,13 @@ void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
 {
     if (item->hasProxy()) {
         QPainter p(&pix);
-        QColor c = QPalette().base().color();
-        c.setAlpha(160);
-        QBrush br(c);
-        p.setBrush(br);
-        p.setPen(Qt::NoPen);
-        QRect r(1, 1, 10, 10);
-        p.drawRect(r);
-        p.setPen(QPalette().text().color());
+        QColor c(220, 220, 10, 200);
+        QRect r(0, 0, 12, 12);
+        p.fillRect(r, c);
+        QFont font = p.font();
+        font.setBold(true);
+        p.setFont(font);
+        p.setPen(Qt::black);
         p.drawText(r, Qt::AlignCenter, i18nc("The first letter of Proxy, used as abbreviation", "P"));
     }
 }
@@ -2912,24 +3116,28 @@ void ProjectList::processThumbOverlays(ProjectItem *item, QPixmap &pix)
 void ProjectList::slotCancelJobs()
 {
     m_abortAllJobs = true;
-    m_proxyThreads.waitForFinished();
-    m_proxyThreads.clearFutures();
+    for (int i = 0; i < m_jobList.count(); i++) {
+        m_jobList.at(i)->setStatus(JOBABORTED);
+    }
+    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;
+        DocClipBase *currentClip = m_doc->clipManager()->getClipById(m_jobList.at(i)->clipId());
+        if (!currentClip) continue;
         QMap <QString, QString> newProps = m_jobList.at(i)->cancelProperties();
         if (newProps.isEmpty()) continue;
-        QMap <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
+        QMap <QString, QString> oldProps = currentClip->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);
     }
     else delete command;
     if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
-    m_processingProxy.clear();
     m_jobList.clear();
     m_abortAllJobs = false;
     m_infoLabel->slotSetJobCount(0);    
@@ -2937,14 +3145,159 @@ void ProjectList::slotCancelJobs()
 
 void ProjectList::slotCancelRunningJob(const QString id, stringMap newProps)
 {
-    if (newProps.isEmpty()) return;
-    ProjectItem *item = getItemById(id);
-    if (!item || !item->referencedClip()) return;
-    QMap <QString, QString> oldProps = item->referencedClip()->currentProperties(newProps);
+    if (newProps.isEmpty() || m_closing) return;
+    DocClipBase *currentClip = m_doc->clipManager()->getClipById(id);
+    if (!currentClip) return;
+    QMap <QString, QString> oldProps = currentClip->currentProperties(newProps);
     if (newProps == oldProps) return;
     QMapIterator<QString, QString> i(oldProps);
     EditClipCommand *command = new EditClipCommand(this, id, oldProps, newProps, true);
     m_commandStack->push(command);    
 }
 
+bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
+{
+    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;
+        job = m_jobList.at(i);
+        if (job->clipId() == item->clipId() && job->jobType == type && (job->jobStatus == JOBWAITING || job->jobStatus == JOBWORKING)) return true;
+    }
+    
+    return false;
+}
+
+void ProjectList::deleteJobsForClip(const QString &clipId)
+{
+    QMutexLocker lock(&m_jobMutex);
+    for (int i = 0; i < m_jobList.count(); i++) {
+        if (m_jobList.at(i)->clipId() == clipId) {
+            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
+}
+
+QStringList ProjectList::getPendingJobs(const QString &id)
+{
+    QStringList result;
+    QMutexLocker lock(&m_jobMutex);
+    for (int i = 0; i < m_jobList.count(); i++) {
+        if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->jobStatus == JOBWAITING || m_jobList.at(i)->jobStatus == JOBWORKING)) {
+            // discard this job
+            result << m_jobList.at(i)->description;
+        }
+    }   
+    return result;
+}
+
+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 || type == NOJOBTYPE)) {
+            // discard this job
+            m_jobList.at(i)->setStatus(JOBABORTED);
+        }
+    }
+}
+
+void ProjectList::slotStartFilterJob(ItemInfo info, const QString&id, const QString&filterName, const QString&filterParams, const QString&finalFilterName, const QString&consumer, const QString&consumerParams, const QString&properties)
+{
+    ProjectItem *item = getItemById(id);
+    if (!item) return;
+    QStringList jobParams;
+    jobParams << QString::number(info.cropStart.frames(m_fps)) << QString::number((info.cropStart + info.cropDuration).frames(m_fps));
+    jobParams << filterName << filterParams << consumer << consumerParams << properties << QString::number(info.startPos.frames(m_fps)) << QString::number(info.track) << finalFilterName;
+    MeltJob *job = new MeltJob(item->clipType(), id, jobParams);
+    if (job->isExclusive() && hasPendingJob(item, job->jobType)) {
+        delete job;
+        return;
+    }
+    m_jobList.append(job);
+    setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+    slotCheckJobProcess();
+}
+
+void ProjectList::slotPrepareJobsMenu()
+{
+    ProjectItem *item;
+    if (!m_listView->currentItem() || m_listView->currentItem()->type() == PROJECTFOLDERTYPE)
+        return;
+    if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE)
+        item = static_cast <ProjectItem*>(m_listView->currentItem()->parent());
+    else
+        item = static_cast <ProjectItem*>(m_listView->currentItem());
+    if (item && (item->flags() & Qt::ItemIsDragEnabled)) {
+        QString id = item->clipId();
+        m_discardCurrentClipJobs->setData(id);
+        QStringList jobs = getPendingJobs(id);
+        m_discardCurrentClipJobs->setEnabled(!jobs.isEmpty());
+    } else {
+        m_discardCurrentClipJobs->setData(QString());
+        m_discardCurrentClipJobs->setEnabled(false);
+    }
+}
+
+void ProjectList::slotDiscardClipJobs()
+{
+    QString id = m_discardCurrentClipJobs->data().toString();
+    if (id.isEmpty()) return;
+    discardJobs(id);
+}
+
 #include "projectlist.moc"