]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Fix Coverity #980680
[kdenlive] / src / projectlist.cpp
index 5f53232025e458c633242042589b56214a7274e2..181cb96d82d8a1bb3c5f2d53b55e02ee3b4991d3 100644 (file)
@@ -219,22 +219,24 @@ QStringList InvalidDialog::getIds() const
 
 
 ProjectList::ProjectList(QWidget *parent) :
-    QWidget(parent),
-    m_render(NULL),
-    m_fps(-1),
-    m_commandStack(NULL),
-    m_openAction(NULL),
-    m_reloadAction(NULL),
-    m_extractAudioAction(NULL),
-    m_transcodeAction(NULL),
-    m_stabilizeAction(NULL),
-    m_doc(NULL),
-    m_refreshed(false),
-    m_allClipsProcessed(false),
-    m_thumbnailQueue(),
-    m_abortAllJobs(false),
-    m_closing(false),
-    m_invalidClipDialog(NULL)
+    QWidget(parent)
+    , m_render(NULL)
+    , m_fps(-1)
+    , m_menu(NULL)
+    , m_commandStack(NULL)
+    , m_openAction(NULL)
+    , m_reloadAction(NULL)
+    , m_extractAudioAction(NULL)
+    , m_transcodeAction(NULL)
+    , m_clipsActionsMenu(NULL)
+    , m_doc(NULL)
+    , m_refreshed(false)
+    , m_allClipsProcessed(false)
+    , m_thumbnailQueue()
+    , m_proxyAction(NULL)
+    , m_abortAllJobs(false)
+    , m_closing(false)
+    , m_invalidClipDialog(NULL)
 {
     qRegisterMetaType<stringMap> ("stringMap");
     QVBoxLayout *layout = new QVBoxLayout;
@@ -353,7 +355,7 @@ ProjectList::~ProjectList()
     m_jobThreads.clearFutures();
     if (!m_jobList.isEmpty()) qDeleteAll(m_jobList);
     m_jobList.clear();
-    delete m_menu;
+    if (m_menu) delete m_menu;
     m_listView->blockSignals(true);
     m_listView->clear();
     delete m_listViewDelegate;
@@ -404,6 +406,10 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
 
 void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
 {
+    if (!m_menu) {
+       kDebug()<<"Warning, menu was not created, something is wrong";
+       return;
+    }
     if (!menus.contains("addMenu") && ! menus.value("addMenu") )
         return;
     QMenu *menu = m_addButton->menu();
@@ -431,11 +437,11 @@ void ProjectList::setupGeneratorMenu(const QHash<QString,QMenu*>& menus)
                m_menu->addMenu(stabilizeMenu);
                if (stabilizeMenu->isEmpty())
                        stabilizeMenu->setEnabled(false);
-               m_stabilizeAction=stabilizeMenu;
+               m_clipsActionsMenu = stabilizeMenu;
 
        }
-    m_menu->addAction(m_reloadAction);
-    m_menu->addAction(m_proxyAction);
+    if (m_reloadAction) m_menu->addAction(m_reloadAction);
+    if (m_proxyAction) m_menu->addAction(m_proxyAction);
        if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){
                QMenu* inTimelineMenu=menus.value("inTimelineMenu");
                m_menu->addMenu(inTimelineMenu);
@@ -715,10 +721,11 @@ void ProjectList::slotReloadClip(const QString &id)
             QDomElement e = item->toXml();
             // Make sure we get the correct producer length if it was adjusted in timeline
             if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
-                int length = QString(clip->producerProperty("length")).toInt();
-                if (length > 0 && !e.hasAttribute("length")) {
-                    e.setAttribute("length", length);
-                }
+               int length = QString(clip->producerProperty("length")).toInt();
+               if (length > 0 && !e.hasAttribute("length")) {
+                   e.setAttribute("length", length);
+               }
+               e.setAttribute("duration", clip->getProperty("duration"));
             }
             resetThumbsProducer(clip);
             m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true);
@@ -834,18 +841,22 @@ void ProjectList::slotClipSelected()
             m_reloadAction->setEnabled(false);
             m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
-            m_stabilizeAction->setEnabled(false);
+            m_clipsActionsMenu->setEnabled(false);
         } else {
             if (item->type() == PROJECTSUBCLIPTYPE) {
                 // this is a sub item, use base clip
                 m_deleteButton->defaultAction()->setEnabled(true);
                 clip = static_cast <ProjectItem*>(item->parent());
-                if (clip == NULL) kDebug() << "-----------ERROR";
+                if (clip == NULL) {
+                   kDebug() << "-----------ERROR";
+                   return;
+               }
                 SubProjectItem *sub = static_cast <SubProjectItem*>(item);
+               if (clip->referencedClip()->getProducer() == NULL) m_render->getFileProperties(clip->referencedClip()->toXML(), clip->clipId(), m_listView->iconSize().height(), true);
                 emit clipSelected(clip->referencedClip(), sub->zone());
                 m_extractAudioAction->setEnabled(false);
                 m_transcodeAction->setEnabled(false);
-                m_stabilizeAction->setEnabled(false);
+                m_clipsActionsMenu->setEnabled(false);
                 m_reloadAction->setEnabled(false);
                 adjustProxyActions(clip);
                 return;
@@ -853,12 +864,13 @@ void ProjectList::slotClipSelected()
             clip = static_cast <ProjectItem*>(item);
             if (clip && clip->referencedClip())
                 emit clipSelected(clip->referencedClip());
+           if (clip->referencedClip()->getProducer() == NULL) m_render->getFileProperties(clip->referencedClip()->toXML(), clip->clipId(), m_listView->iconSize().height(), true);
             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);
+            m_clipsActionsMenu->setEnabled(true);
             if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
                 m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
                 m_openAction->setEnabled(true);
@@ -882,13 +894,14 @@ void ProjectList::slotClipSelected()
         m_reloadAction->setEnabled(false);
         m_extractAudioAction->setEnabled(true);
         m_transcodeAction->setEnabled(false);
-        m_stabilizeAction->setEnabled(false);
+        m_clipsActionsMenu->setEnabled(false);
     }
     adjustProxyActions(clip);
 }
 
 void ProjectList::adjustProxyActions(ProjectItem *clip) const
 {
+    if (!m_proxyAction) return;
     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) {
         m_proxyAction->setEnabled(false);
         return;
@@ -905,10 +918,10 @@ void ProjectList::adjustStabilizeActions(ProjectItem *clip) const
 {
 
     if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW) {
-        m_stabilizeAction->setEnabled(false);
+        m_clipsActionsMenu->setEnabled(false);
         return;
     }
-       m_stabilizeAction->setEnabled(true);
+       m_clipsActionsMenu->setEnabled(true);
 
 }
 
@@ -948,17 +961,16 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap <QString, QSt
     ProjectItem *item = getItemById(id);
     if (item) {
         slotUpdateClipProperties(item, properties);
-        if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index")) {
+        if (properties.contains("out") || properties.contains("force_fps") || properties.contains("resource") || properties.contains("video_index") || properties.contains("audio_index") || properties.contains("full_luma") || properties.contains("force_progressive") || properties.contains("force_tff") || properties.contains("force_colorspace")) {
             slotReloadClip(id);
         } else if (properties.contains("colour") ||
                    properties.contains("xmldata") ||
                    properties.contains("force_aspect_num") ||
                    properties.contains("force_aspect_den") ||
-                   properties.contains("full_luma") ||
                    properties.contains("templatetext")) {
             slotRefreshClipThumbnail(item);
             emit refreshClip(id, true);
-        } else if (properties.contains("force_colorspace") || properties.contains("loop")) {
+        } else if (properties.contains("loop")) {
             emit refreshClip(id, false);
         }
     }
@@ -1013,6 +1025,7 @@ void ProjectList::slotItemEdited(QTreeWidgetItem *item, int column)
     if (item->type() == PROJECTFOLDERTYPE) {
         if (column == 0) {
             FolderProjectItem *folder = static_cast <FolderProjectItem*>(item);
+           if (item->text(0) == folder->groupName()) return;
             editFolder(item->text(0), folder->groupName(), folder->clipId());
             folder->setGroupName(item->text(0));
             m_doc->clipManager()->addFolder(folder->clipId(), item->text(0));
@@ -1068,20 +1081,24 @@ void ProjectList::slotCheckScrolling()
 
 void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
 {
+    if (!m_menu) {
+       kDebug()<<"Warning, menu was not created, something is wrong";
+       return;
+    }
     bool enable = item ? true : false;
     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);
+    m_clipsActionsMenu->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);
+            m_clipsActionsMenu->setEnabled(false);
             adjustProxyActions(clip);
         } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) {
             clip = static_cast <ProjectItem*>(item);
@@ -1094,7 +1111,7 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
         } else {
             m_extractAudioAction->setEnabled(false);
             m_transcodeAction->setEnabled(false);
-            m_stabilizeAction->setEnabled(false);
+            m_clipsActionsMenu->setEnabled(false);
         }
         if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
@@ -1172,7 +1189,7 @@ void ProjectList::updateButtons() const
             m_openAction->setEnabled(true);
             m_reloadAction->setEnabled(true);
             m_transcodeAction->setEnabled(true);
-            m_stabilizeAction->setEnabled(true);
+            m_clipsActionsMenu->setEnabled(true);
             return;
         }
         else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) {
@@ -1181,10 +1198,10 @@ void ProjectList::updateButtons() const
         else m_editButton->defaultAction()->setEnabled(false);
     }
     m_openAction->setEnabled(false);
-    m_reloadAction->setEnabled(false);
+    if (m_reloadAction) m_reloadAction->setEnabled(false);
     m_transcodeAction->setEnabled(false);
-    m_stabilizeAction->setEnabled(false);
-    m_proxyAction->setEnabled(false);
+    m_clipsActionsMenu->setEnabled(false);
+    if (m_proxyAction) m_proxyAction->setEnabled(false);
 }
 
 void ProjectList::selectItemById(const QString &clipId)
@@ -1458,7 +1475,9 @@ void ProjectList::getCachedThumbnail(ProjectItem *item)
 {
     if (!item) return;
     DocClipBase *clip = item->referencedClip();
-    if (!clip) return;
+    if (!clip) {
+       return;
+    }
     QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
     if (QFile::exists(cachedPixmap)) {
         QPixmap pix(cachedPixmap);
@@ -1578,6 +1597,7 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr
                 }
                 if (clip->isPlaceHolder() == false && !hasPendingJob(item, PROXYJOB)) {
                     QDomElement xml = clip->toXML();
+                   getCachedThumbnail(item);
                     if (fpsChanged) {
                         xml.removeAttribute("out");
                         xml.removeAttribute("file_hash");
@@ -1587,8 +1607,12 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStr
                     xml.removeAttribute("_replaceproxy");
                     if (replace) {
                         resetThumbsProducer(clip);
+                       m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
                     }
-                    m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
+                    else if (item->numReferences() > 0) {
+                       // In some cases, like slowmotion clips, the producer is not loaded automatically be MLT
+                       m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace);
+                   }
                 }
                 else if (clip->isPlaceHolder()) {
                     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
@@ -2186,12 +2210,87 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
     }
 }
 
+void ProjectList::extractMetadata(DocClipBase *clip)
+{
+    CLIPTYPE t = clip->clipType();
+    if (t != AV && t != VIDEO) {
+       // Currently, we only use exiftool on video files
+       return;
+    }
+    QMap <QString, QString> props = clip->properties();
+    if (KdenliveSettings::use_exiftool() && !props.contains("exiftool")) {
+       QMap <QString, QString> meta;
+       QString url = clip->fileURL().path();
+       //Check for Canon THM file
+       url = url.section('.', 0, -2) + ".THM";
+       if (QFile::exists(url)) {
+           // Read the exif metadata embeded in the THM file
+           QProcess p;
+           QStringList args;
+           args << "-g" << "-args" << url;
+           p.start("exiftool", args);
+           p.waitForFinished();
+           QString res = p.readAllStandardOutput();
+           QStringList list = res.split("\n");
+           foreach(QString tagline, list) {
+               if (tagline.startsWith("-File") || tagline.startsWith("-ExifTool")) continue;
+               QString tag = tagline.section(':', 1).simplified();
+               if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
+               if (!tag.section('=', 0, 0).isEmpty() && !tag.section('=', 1).simplified().isEmpty())
+                   meta.insert(tag.section('=', 0, 0), tag.section('=', 1).simplified());
+           }
+       } else {
+           QString codecid = props.value("videocodecid").simplified();
+           if (codecid == "h264") {
+               QProcess p;
+               QStringList args;
+               args << "-g" << "-args" << clip->fileURL().encodedPathAndQuery();
+               p.start("exiftool", args);
+               p.waitForFinished();
+               QString res = p.readAllStandardOutput();
+               QStringList list = res.split("\n");
+               foreach(QString tagline, list) {
+                   if (!tagline.startsWith("-H264")) continue;
+                   QString tag = tagline.section(':', 1);
+                   if (tag.startsWith("ImageWidth") || tag.startsWith("ImageHeight")) continue;
+                   meta.insert(tag.section('=', 0, 0), tag.section('=', 1));
+               }
+           }
+       }
+       clip->setProperty("exiftool", "1");
+       if (!meta.isEmpty()) {
+           clip->setMetadata(meta, "ExifTool");
+           //checkCamcorderFilters(clip, meta);
+       }
+    }
+    if (KdenliveSettings::use_magicLantern() && !props.contains("magiclantern")) {
+       QMap <QString, QString> meta;
+       QString url = clip->fileURL().path();
+       url = url.section('.', 0, -2) + ".LOG";
+       if (QFile::exists(url)) {
+           QFile file(url);
+           if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
+               while (!file.atEnd()) {
+                   QString line = file.readLine().simplified();
+                   if (line.startsWith('#') || line.isEmpty() || !line.contains(':')) continue;
+                   if (line.startsWith("CSV data")) break;
+                   meta.insert(line.section(':', 0, 0).simplified(), line.section(':', 1).simplified());
+               }
+           }
+       }
+       
+       if (!meta.isEmpty())
+           clip->setMetadata(meta, "Magic Lantern");
+       clip->setProperty("magiclantern", "1");
+    }
+}
+
 
 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace)
 {
+    QMutexLocker lock(&m_processMutex);
     QString toReload;
     ProjectItem *item = getItemById(clipId);
-    int queue = m_render->processingItems();
     if (item && producer) {
         monitorItemEditing(false);
         DocClipBase *clip = item->referencedClip();
@@ -2204,6 +2303,8 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
         }
         item->setProperties(properties, metadata);
         clip->setProducer(producer, replace);
+       extractMetadata(clip);
+       m_render->processingDone(clipId);
 
         // Proxy stuff
         QString size = properties.value("frame_size");
@@ -2243,7 +2344,11 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
         }
         if (!toReload.isEmpty())
             item->slotSetToolTip();
-    } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
+    } else {
+       kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
+       m_render->processingDone(clipId);
+    }
+    int queue = m_render->processingItems();
     if (queue == 0) {
         monitorItemEditing(true);
         if (item && m_thumbnailQueue.isEmpty()) {
@@ -2256,6 +2361,9 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
             } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) {
                 // this is the first clip loaded in project, check if we want to adjust project settings to the clip
                 updatedProfile = adjustProjectProfileToItem(item);
+               if (updatedProfile == false) {
+                   emit clipSelected(item->referencedClip());
+               }
             }
             if (updatedProfile == false) {
                 //emit clipSelected(item->referencedClip());
@@ -2475,7 +2583,7 @@ void ProjectList::slotSelectClip(const QString &ix)
         m_reloadAction->setEnabled(true);
         m_extractAudioAction->setEnabled(true);
         m_transcodeAction->setEnabled(true);
-        m_stabilizeAction->setEnabled(true);
+        m_clipsActionsMenu->setEnabled(true);
         if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) {
             m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp()));
             m_openAction->setEnabled(true);
@@ -2619,7 +2727,7 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d
             m_listView->scrollToItem(sub);
             m_listView->editItem(sub, 1);
         }
-       m_doc->clipManager()->requestThumbs(QString('#' + id), QList <int>() << in);
+       m_doc->clipManager()->slotRequestThumbs(QString('#' + id), QList <int>() << in);
         monitorItemEditing(true);
     }
     emit projectModified();
@@ -2944,22 +3052,21 @@ void ProjectList::slotCheckJobProcess()
             }
     }
     if (m_jobList.isEmpty()) return;
-    int count = 0;
+
     m_jobMutex.lock();
+    int count = 0;
     for (int i = 0; i < m_jobList.count(); i++) {
-        if (m_jobList.at(i)->jobStatus == JOBWORKING || m_jobList.at(i)->jobStatus == JOBWAITING)
+        if (m_jobList.at(i)->status() == JOBWORKING || m_jobList.at(i)->status() == JOBWAITING)
             count ++;
         else {
             // remove finished jobs
             AbstractClipJob *job = m_jobList.takeAt(i);
-            delete job;
+            job->deleteLater();
             i--;
         }
     }
-
-    emit jobCount(count);
+    emit jobCount(count);    
     m_jobMutex.unlock();
-    
     if (m_jobThreads.futures().isEmpty() || m_jobThreads.futures().count() < KdenliveSettings::proxythreads()) m_jobThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotProcessJobs));
 }
 
@@ -2982,14 +3089,14 @@ void ProjectList::slotProcessJobs()
         int count = 0;
         m_jobMutex.lock();
         for (int i = 0; i < m_jobList.count(); i++) {
-            if (m_jobList.at(i)->jobStatus == JOBWAITING) {
+            if (m_jobList.at(i)->status() == JOBWAITING) {
                 if (job == NULL) {
-                    m_jobList.at(i)->jobStatus = JOBWORKING;
+                    m_jobList.at(i)->setStatus(JOBWORKING);
                     job = m_jobList.at(i);
                 }
                 count++;
             }
-            else if (m_jobList.at(i)->jobStatus == JOBWORKING)
+            else if (m_jobList.at(i)->status() == JOBWORKING)
                 count ++;
         }
         // Set jobs count
@@ -3028,20 +3135,20 @@ void ProjectList::slotProcessJobs()
             MeltJob *jb = static_cast<MeltJob *> (job);
             jb->setProducer(currentClip->getProducer(), currentClip->fileURL());
            if (jb->isProjectFilter())
-             connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SLOT(slotGotFilterJobResults(QString,int, int,stringMap,stringMap)));
+               connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SLOT(slotGotFilterJobResults(QString,int, int,stringMap,stringMap)));
            else
                connect(job, SIGNAL(gotFilterJobResults(QString,int, int, stringMap,stringMap)), this, SIGNAL(gotFilterJobResults(QString,int, int,stringMap,stringMap)));
         }
         job->startJob();
-        if (job->jobStatus == JOBDONE) {
+        if (job->status() == 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());
             }
-        } else if (job->jobStatus == JOBCRASHED || job->jobStatus == JOBABORTED) {
-            emit updateJobStatus(job->clipId(), job->jobType, job->jobStatus, job->errorMessage(), QString(), job->logDetails());
+        } else if (job->status() == JOBCRASHED || job->status() == JOBABORTED) {
+            emit updateJobStatus(job->clipId(), job->jobType, job->status(), job->errorMessage(), QString(), job->logDetails());
         }
     }
     // Thread finished, cleanup & update count
@@ -3345,7 +3452,7 @@ bool ProjectList::hasPendingJob(ProjectItem *item, JOBTYPE type)
     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;
+        if (job->clipId() == item->clipId() && job->jobType == type && (job->status() == JOBWAITING || job->status() == JOBWORKING)) return true;
     }
     
     return false;
@@ -3437,7 +3544,7 @@ 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)) {
+        if (m_jobList.at(i)->clipId() == id && (m_jobList.at(i)->status() == JOBWAITING || m_jobList.at(i)->status() == JOBWORKING)) {
             // discard this job
             result << m_jobList.at(i)->description;
         }
@@ -3508,14 +3615,24 @@ void ProjectList::startClipFilterJob(const QString &filterName, const QString &c
        // Producer params
        jobParams << QString();
        // Filter params, use a smaller region of the image to speed up operation
-       jobParams << filterName << "bounding=\"25%x25%:15%x15\" shot_change_list=0 denoise=0";
+       // In fact, it's faster to rescale whole image than using part of it (bounding=\"25%x25%:15%x15\")
+       jobParams << filterName << "shot_change_list=0 denoise=0";
        // Consumer
-       jobParams << "null" << "all=1 terminate_on_pause=1 real_time=-1";
+       jobParams << "null" << "all=1 terminate_on_pause=1 real_time=-1 rescale=nearest deinterlace_method=onefield top_field_first=-1";
        QMap <QString, QString> extraParams;
        extraParams.insert("key", "shot_change_list");
        extraParams.insert("projecttreefilter", "1");
        QString keyword("%count");
        extraParams.insert("resultmessage", i18n("Found %1 scenes.", keyword));
+       extraParams.insert("resize_profile", "160");
+       if (ui.store_data->isChecked()) {
+           // We want to save result as clip metadata
+           extraParams.insert("storedata", "1");
+       }
+       if (ui.zone_only->isChecked()) {
+           // We want to analyze only clip zone
+           extraParams.insert("zoneonly", "1");
+       }
        if (ui.add_markers->isChecked()) {
            // We want to create markers
            extraParams.insert("addmarkers", QString::number(ui.marker_type->currentIndex()));
@@ -3556,6 +3673,13 @@ void ProjectList::processClipJob(QStringList ids, const QString&destination, boo
         ProjectItem *item = getItemById(id);
         if (!item) continue;
        QStringList jobArgs;
+       if (extraParams.contains("zoneonly")) {
+           // Analyse clip zone only, remove in / out and replace with zone
+           preParams.takeFirst();
+           preParams.takeFirst();
+           QPoint zone = item->referencedClip()->zone();
+           jobArgs << QString::number(zone.x()) << QString::number(zone.y());
+       }
        jobArgs << preParams;
         if (ids.count() == 1) {
             jobArgs << consumer + ':' + destination;
@@ -3579,9 +3703,10 @@ void ProjectList::processClipJob(QStringList ids, const QString&destination, boo
         job->description = description;
         m_jobList.append(job);
         setJobStatus(item, job->jobType, JOBWAITING, 0, job->statusMessage());
+       slotCheckJobProcess();
     }
-    slotCheckJobProcess();
 }
+   
 
 void ProjectList::slotPrepareJobsMenu()
 {
@@ -3635,9 +3760,10 @@ void ProjectList::slotClosePopup()
 void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap results, stringMap filterInfo)
 {
     // Currently, only the first value of results is used
-    kDebug()<<"// FILTER RES:\n"<<filterInfo<<"\n--------------\n"<<results;
+    //kDebug()<<"// FILTER RES:\n"<<filterInfo<<"\n--------------\n"<<results;
     ProjectItem *clip = getItemById(id);
     if (!clip) return;
+
     // Check for return value
     int markersType = -1;
     if (filterInfo.contains("addmarkers")) markersType = filterInfo.value("addmarkers").toInt();
@@ -3647,6 +3773,7 @@ void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap resu
     }
     bool dataProcessed = false;
     QString key = filterInfo.value("key");
+    int offset = filterInfo.value("offset").toInt();
     QStringList value = results.value(key).split(';', QString::SkipEmptyParts);
     kDebug()<<"// RESULT; "<<key<<" = "<<value;
     if (filterInfo.contains("resultmessage")) {
@@ -3666,7 +3793,7 @@ void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap resu
            int newPos = pos.section("=", 0, 0).toInt();
            // Don't use scenes shorter than 1 second
            if (newPos - cutPos < 24) continue;
-           (void) new AddClipCutCommand(this, id, cutPos, newPos, QString(), true, false, command);
+           (void) new AddClipCutCommand(this, id, cutPos + offset, newPos + offset, QString(), true, false, command);
            cutPos = newPos;
        }
        if (command->childCount() == 0)
@@ -3686,7 +3813,7 @@ void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap resu
            int newPos = pos.section("=", 0, 0).toInt();
            // Don't use scenes shorter than 1 second
            if (newPos - cutPos < 24) continue;
-           CommentedTime m(GenTime(newPos, m_fps), QString::number(index), markersType);
+           CommentedTime m(GenTime(newPos + offset, m_fps), QString::number(index), markersType);
            markersList << m;
            index++;
            cutPos = newPos;
@@ -3695,10 +3822,26 @@ void ProjectList::slotGotFilterJobResults(QString id, int , int , stringMap resu
     }
     if (!dataProcessed || filterInfo.contains("storedata")) {
        // Store returned data as clip extra data
-       clip->referencedClip()->setAnalysisData(filterInfo.contains("displaydataname") ? filterInfo.value("displaydataname") : key, results.value(key));
+       clip->referencedClip()->setAnalysisData(filterInfo.contains("displaydataname") ? filterInfo.value("displaydataname") : key, results.value(key), filterInfo.value("offset").toInt());
        emit updateAnalysisData(clip->referencedClip());
     }
 }
 
 
+/*
+// Work in progress: apply filter based on clip's camcorder
+void ProjectList::checkCamcorderFilters(DocClipBase *clip, QMap <QString, QString> meta)
+{
+    KConfig conf("camcorderfilters.rc", KConfig::CascadeConfig, "appdata");
+    QStringList groups = conf.groupList();
+    foreach(QString grp, groups) {
+       if (!meta.contains(grp)) continue;
+       KConfigGroup group(&conf, grp);
+       QString value = group.readEntry(meta.value(grp));
+       if (value.isEmpty()) continue;
+       clip->setProperty(value.section(' ', 0, 0), value.section(' ', 1));
+       break;
+    }
+}*/
+
 #include "projectlist.moc"