]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Fix crash when closing doc / app while proxy are generated
[kdenlive] / src / projectlist.cpp
index a9087e4e32d4b7ff696843e8c675f75da2bbe403..08935c338cba790877d26614577efb92d1b7b682 100644 (file)
@@ -78,7 +78,8 @@ ProjectList::ProjectList(QWidget *parent) :
     m_doc(NULL),
     m_refreshed(false),
     m_infoQueue(),
-    m_thumbnailQueue()
+    m_thumbnailQueue(),
+    m_abortAllProxies(false)
 {
     QVBoxLayout *layout = new QVBoxLayout;
     layout->setContentsMargins(0, 0, 0, 0);
@@ -114,10 +115,6 @@ ProjectList::ProjectList(QWidget *parent) :
     setLayout(layout);
     searchView->setTreeWidget(m_listView);
 
-    m_proxyAction = new QAction(i18n("Proxy clip"), this);
-    m_proxyAction->setCheckable(true);
-    m_proxyAction->setChecked(false);
-    connect(m_proxyAction, SIGNAL(toggled(bool)), this, SLOT(slotProxyCurrentItem(bool)));
     connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail()));
     connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified()));
     connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected()));
@@ -145,6 +142,7 @@ ProjectList::ProjectList(QWidget *parent) :
 
 ProjectList::~ProjectList()
 {
+    m_abortAllProxies = true;
     delete m_menu;
     m_listView->blockSignals(true);
     m_listView->clear();
@@ -176,6 +174,10 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction)
             m_reloadAction = actions.at(i);
             actions.removeAt(i);
             i--;
+        } else if (actions.at(i)->data().toString() == "proxy_clip") {
+            m_proxyAction = actions.at(i);
+            actions.removeAt(i);
+            i--;
         }
     }
 
@@ -502,8 +504,11 @@ void ProjectList::slotMissingClip(const QString &id)
         item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
         int height = m_listView->iconSize().height();
         int width = (int)(height  * m_render->dar());
-        QPixmap pixmap = QPixmap(width, height);
-        pixmap.fill(Qt::transparent);
+        QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+        if (pixmap.isNull()) {
+            pixmap = QPixmap(width, height);
+            pixmap.fill(Qt::transparent);
+        }
         KIcon icon("dialog-close");
         QPainter p(&pixmap);
         p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
@@ -511,8 +516,17 @@ void ProjectList::slotMissingClip(const QString &id)
         item->setData(0, Qt::DecorationRole, pixmap);
         if (item->referencedClip()) {
             item->referencedClip()->setPlaceHolder(true);
-            if (m_render == NULL) kDebug() << "*********  ERROR, NULL RENDR";
-            item->referencedClip()->setProducer(m_render->invalidProducer(id), true);
+            if (m_render == NULL) {
+                kDebug() << "*********  ERROR, NULL RENDR";
+                return;
+            }
+            Mlt::Producer *newProd = m_render->invalidProducer(id);
+            if (item->referencedClip()->producer()) {
+                Mlt::Properties props(newProd->get_properties());
+                Mlt::Properties src_props(item->referencedClip()->producer()->get_properties());
+                props.inherit(src_props);
+            }
+            item->referencedClip()->setProducer(newProd, true);
             item->slotSetToolTip();
             emit clipNeedsReload(id, true);
         }
@@ -894,11 +908,14 @@ void ProjectList::slotDeleteClip(const QString &clipId)
         kDebug() << "/// Cannot find clip to delete";
         return;
     }
+    if (item->isProxyRunning()) m_abortProxy.append(item->referencedClip()->getProperty("proxy"));
     m_listView->blockSignals(true);
     QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
     if (!newSelectedItem)
         newSelectedItem = m_listView->itemBelow(item);
     delete item;
+    // Pause playing to prevent crash while deleting clip
+    slotPauseMonitor();
     m_doc->clipManager()->deleteClip(clipId);
     m_listView->blockSignals(false);
     if (newSelectedItem) {
@@ -1003,16 +1020,18 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
         item = new ProjectItem(m_listView, clip);
     }
     if (item->data(0, DurationRole).isNull()) item->setData(0, DurationRole, i18n("Loading"));
-    connect(clip, SIGNAL(createProxy(const QString)), this, SLOT(slotCreateProxy(const QString)));
-    connect(clip, SIGNAL(abortProxy(const QString)), this, SLOT(slotAbortProxy(const QString)));
+    connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &)));
+    connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString)));
     if (getProperties) {
         m_listView->processLayout();
         QDomElement e = clip->toXML().cloneNode().toElement();
         e.removeAttribute("file_hash");
+        m_mutex.lock();
         m_infoQueue.insert(clip->getId(), e);
+        m_mutex.unlock();
     }
     else if (item->hasProxy() && !item->isProxyRunning()) {
-        slotCreateProxy(clip->getId(), false);
+        slotCreateProxy(clip->getId());
     }
     clip->askForAudioThumbs();
     
@@ -1056,45 +1075,62 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
         updateButtons();
     }
     
-    if (getProperties && m_processingClips.isEmpty())
-        m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    //if (getProperties && m_processingClips.isEmpty())
+        //m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    if (getProperties)
+        QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
 }
 
-void ProjectList::slotGotProxy(const QString &id)
+void ProjectList::slotGotProxy(const QString &proxyPath)
 {
-    ProjectItem *item = getItemById(id);
-    if (item) {
-        // Proxy clip successfully created
-        QDomElement e = item->referencedClip()->toXML().cloneNode().toElement();  
-        //e.removeAttribute("file_hash");
+    if (proxyPath.isEmpty() || !m_refreshed || m_abortAllProxies) return;
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
 
-        // Make sure we get the correct producer length if it was adjusted in timeline
-        CLIPTYPE t = item->clipType();
-        if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) {
-            int length = QString(item->referencedClip()->producerProperty("length")).toInt();
-            if (length > 0 && !e.hasAttribute("length")) {
-                e.setAttribute("length", length);
-            }
+    while (*it) {
+        if ((*it)->type() == PROJECTCLIPTYPE) {
+            item = static_cast <ProjectItem *>(*it);
+            if (item->referencedClip()->getProperty("proxy") == proxyPath)
+                slotGotProxy(item);
+        }
+        ++it;
+    }
+}
+
+void ProjectList::slotGotProxy(ProjectItem *item)
+{
+    if (item == NULL || !m_refreshed) return;
+    DocClipBase *clip = item->referencedClip();
+    // Proxy clip successfully created
+    QDomElement e = clip->toXML().cloneNode().toElement();
+
+    // Make sure we get the correct producer length if it was adjusted in timeline
+    CLIPTYPE t = item->clipType();
+    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);
         }
-        e.setAttribute("replace", 1);
-        m_infoQueue.insert(id, e);
-        if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
     }
+    e.setAttribute("replace", 1);
+    m_mutex.lock();
+    m_infoQueue.insert(clip->getId(), e);
+    m_mutex.unlock();
+    //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
 }
 
 void ProjectList::slotResetProjectList()
 {
+    m_abortAllProxies = true;
+    m_proxyThreads.waitForFinished();
+    m_proxyThreads.clearFutures();
     m_listView->clear();
     emit clipSelected(NULL);
     m_thumbnailQueue.clear();
     m_infoQueue.clear();
     m_refreshed = false;
-}
-
-void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
-{
-    m_infoQueue.insert(id, xml);
-    //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
+    m_abortAllProxies = false;
 }
 
 void ProjectList::slotProcessNextClipInQueue()
@@ -1103,13 +1139,14 @@ void ProjectList::slotProcessNextClipInQueue()
         emit processNextThumbnail();
         return;
     }
-
+    QMutexLocker locker(&m_mutex);
     QMap<QString, QDomElement>::const_iterator j = m_infoQueue.constBegin();
     if (j != m_infoQueue.constEnd()) {
-        QDomElement dom = j.value();
+        QDomElement dom = j.value().cloneNode().toElement();
         const QString id = j.key();
         m_infoQueue.remove(id);
         m_processingClips.append(id);
+        locker.unlock();
         bool replace;
         if (dom.hasAttribute("replace")) {
             // Proxy action was enabled / disabled and we want to replace current producer
@@ -1131,7 +1168,7 @@ void ProjectList::slotUpdateClip(const QString &id)
     monitorItemEditing(true);
 }
 
-void ProjectList::updateAllClips(bool displayRatioChanged)
+void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged)
 {
     m_listView->setSortingEnabled(false);
 
@@ -1147,7 +1184,7 @@ void ProjectList::updateAllClips(bool displayRatioChanged)
     QPainter p(&missingPixmap);
     p.drawPixmap(3, 3, icon.pixmap(width - 6, height - 6));
     p.end();
-                        
+    kDebug()<<"//////////////7  UPDATE ALL CLPS";
     while (*it) {
         if ((*it)->type() == PROJECTSUBCLIPTYPE) {
             // subitem
@@ -1166,13 +1203,30 @@ void ProjectList::updateAllClips(bool displayRatioChanged)
             item = static_cast <ProjectItem *>(*it);
             clip = item->referencedClip();
             if (item->referencedClip()->producer() == NULL) {
-                if (clip->isPlaceHolder() == false)
-                    requestClipInfo(clip->toXML(), clip->getId());
+                if (clip->isPlaceHolder() == false) {
+                    QDomElement xml = clip->toXML();
+                    if (fpsChanged) {
+                        xml.removeAttribute("out");
+                        xml.removeAttribute("file_hash");
+                        xml.removeAttribute("proxy_out");
+                    }
+                    m_mutex.lock();
+                    m_infoQueue.insert(clip->getId(), xml);
+                    m_mutex.unlock();
+                    QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+                }
                 else {
                     item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled);
                     if (item->data(0, Qt::DecorationRole).isNull()) {
                         item->setData(0, Qt::DecorationRole, missingPixmap);
                     }
+                    else {
+                        QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+                        QPainter p(&pixmap);
+                        p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
+                        p.end();
+                        item->setData(0, Qt::DecorationRole, pixmap);
+                    }
                 }
             } else {
                 if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull())
@@ -1180,14 +1234,29 @@ void ProjectList::updateAllClips(bool displayRatioChanged)
                 if (item->data(0, DurationRole).toString().isEmpty()) {
                     item->changeDuration(item->referencedClip()->producer()->get_playtime());
                 }
+                if (clip->isPlaceHolder()) {
+                    QPixmap pixmap = qVariantValue<QPixmap>(item->data(0, Qt::DecorationRole));
+                    if (pixmap.isNull()) {
+                        pixmap = QPixmap(width, height);
+                        pixmap.fill(Qt::transparent);
+                    }
+                    QPainter p(&pixmap);
+                    p.drawPixmap(3, 3, KIcon("dialog-close").pixmap(pixmap.width() - 6, pixmap.height() - 6));
+                    p.end();
+                    item->setData(0, Qt::DecorationRole, pixmap);
+                }
             }
             item->setData(0, UsageRole, QString::number(item->numReferences()));
         }
-        //qApp->processEvents();
         ++it;
     }
 
-    if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    //QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    /*while (!m_infoQueue.isEmpty()) {
+        QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    }*/
+    
     if (m_listView->isEnabled())
         monitorItemEditing(true);
     m_listView->setSortingEnabled(true);
@@ -1302,7 +1371,9 @@ void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
 {
     ProjectItem *item = getItemById(id);
     m_processingClips.removeAll(id);
-    if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    m_thumbnailQueue.removeAll(id);
+    //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);   
     if (item) {
         const QString path = item->referencedClip()->fileURL().path();
         if (item->referencedClip()->isPlaceHolder()) replace = false;
@@ -1335,7 +1406,9 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError)
         }
     }
     m_processingClips.removeAll(id);
-    if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    m_thumbnailQueue.removeAll(id);
+    //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
 }
 
 void ProjectList::slotAddColorClip()
@@ -1444,6 +1517,9 @@ QStringList ProjectList::getGroup() const
 void ProjectList::setDocument(KdenliveDoc *doc)
 {
     m_listView->blockSignals(true);
+    m_abortAllProxies = true;
+    m_proxyThreads.waitForFinished();
+    m_proxyThreads.clearFutures();
     m_listView->clear();
     m_processingClips.clear();
     m_listView->setSortingEnabled(false);
@@ -1455,7 +1531,7 @@ void ProjectList::setDocument(KdenliveDoc *doc)
     m_timecode = doc->timecode();
     m_commandStack = doc->commandStack();
     m_doc = doc;
-    m_proxyList.clear();
+    m_abortAllProxies = false;
 
     QMap <QString, QString> flist = doc->clipManager()->documentFolderList();
     QStringList openedFolders = doc->getExpandedFolders();
@@ -1467,6 +1543,7 @@ void ProjectList::setDocument(KdenliveDoc *doc)
     }
 
     QList <DocClipBase*> list = doc->clipManager()->documentClipList();
+    if (list.isEmpty()) m_refreshed = true;
     for (int i = 0; i < list.count(); i++)
         slotAddClip(list.at(i), false);
 
@@ -1475,7 +1552,7 @@ void ProjectList::setDocument(KdenliveDoc *doc)
     connect(m_doc->clipManager(), SIGNAL(modifiedClip(const QString &)), this, SLOT(slotModifiedClip(const QString &)));
     connect(m_doc->clipManager(), SIGNAL(missingClip(const QString &)), this, SLOT(slotMissingClip(const QString &)));
     connect(m_doc->clipManager(), SIGNAL(availableClip(const QString &)), this, SLOT(slotAvailableClip(const QString &)));
-    connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool)), this, SLOT(updateAllClips(bool)));
+    connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool)), this, SLOT(updateAllClips(bool, bool)));
 }
 
 QList <DocClipBase*> ProjectList::documentClipList() const
@@ -1507,10 +1584,12 @@ QDomElement ProjectList::producersList()
 
 void ProjectList::slotCheckForEmptyQueue()
 {
-    if (!m_refreshed && m_processingClips.isEmpty() && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
-        m_refreshed = true;
-        emit loadingIsOver();
-        emit displayMessage(QString(), -1);
+    if (m_processingClips.isEmpty() && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
+        if (!m_refreshed) {
+            emit loadingIsOver();
+            emit displayMessage(QString(), -1);
+            m_refreshed = true;
+        }
         m_listView->blockSignals(false);
         m_listView->setEnabled(true);
         updateButtons();
@@ -1576,13 +1655,14 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
         }
         QPixmap pix;
         int height = m_listView->iconSize().height();
-        int width = (int)(height  * m_render->dar());
+        int swidth = (int)(height  * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5);
+        int dwidth = (int)(height  * m_render->dar() + 0.5);
         if (clip->clipType() == AUDIO)
-            pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
+            pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height));
         else if (clip->clipType() == IMAGE)
-            pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
+            pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, swidth, dwidth, height));
         else
-            pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height);
+            pix = item->referencedClip()->extractImage(frame, dwidth, height);
 
         if (!pix.isNull()) {
             monitorItemEditing(false);
@@ -1620,7 +1700,8 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
             item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled);
             toReload = clipId;
         }
-
+        clip->setProducer(producer, replace);
+        clip->askForAudioThumbs();
         // Proxy stuff
         QString size = properties.value("frame_size");
         if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY);
@@ -1631,15 +1712,15 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
             CLIPTYPE t = item->clipType();
             if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt();
             else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt();
-            if ((size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize) && (((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy()))) {
+            if ((((t == AV || t == VIDEO || t == PLAYLIST) && generateProxy()) || (t == IMAGE && generateImageProxy())) && (size.section('x', 0, 0).toInt() > maxSize || size.section('x', 1, 1).toInt() > maxSize)) {
                 if (clip->getProperty("proxy").isEmpty()) {
                     KUrl proxyPath = m_doc->projectFolder();
                     proxyPath.addPath("proxy/");
                     proxyPath.addPath(clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")));
                     QMap <QString, QString> newProps;
-                    newProps.insert("proxy", proxyPath.path());
                     // insert required duration for proxy
                     if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out"));
+                    newProps.insert("proxy", proxyPath.path());
                     QMap <QString, QString> oldProps = clip->properties();
                     oldProps.insert("proxy", QString());
                     EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true);
@@ -1647,53 +1728,46 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
                 }
             }
         }
-        
-        clip->setProducer(producer, replace);
-        clip->askForAudioThumbs();
+
         if (!replace && item->data(0, Qt::DecorationRole).isNull())
             requestClipThumbnail(clipId);
         if (!toReload.isEmpty())
             item->slotSetToolTip();
 
-        if (m_listView->isEnabled() && replace) {
-            // update clip in clip monitor
-            emit clipSelected(NULL);
-            emit clipSelected(clip);
-            //TODO: Make sure the line below has no side effect
-            toReload = clipId;
-        }
-        /*else {
-            // Check if duration changed.
-            emit receivedClipDuration(clipId);
-            delete producer;
-        }*/
         if (m_listView->isEnabled())
             monitorItemEditing(true);
-        /*if (item->icon(0).isNull()) {
-            requestClipThumbnail(clipId);
-        }*/
     } else kDebug() << "////////  COULD NOT FIND CLIP TO UPDATE PRPS...";
     if (selectClip && m_infoQueue.isEmpty()) {
-    if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) {
-        m_listView->setCurrentItem(item);
-        bool updatedProfile = false;
-        if (item->parent()) {
-            if (item->parent()->type() == PROJECTFOLDERTYPE)
-                static_cast <FolderProjectItem *>(item->parent())->switchIcon();
-        } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1) {
-            // 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());
-    } else {
-        int max = m_doc->clipManager()->clipsCount();
-        emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
-    }
+        if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty() && m_processingClips.isEmpty()) {
+            m_listView->setCurrentItem(item);
+            bool updatedProfile = false;
+            if (item->parent()) {
+                if (item->parent()->type() == PROJECTFOLDERTYPE)
+                    static_cast <FolderProjectItem *>(item->parent())->switchIcon();
+            } else if (KdenliveSettings::checkfirstprojectclip() &&  m_listView->topLevelItemCount() == 1) {
+                // 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());
+            }
+        } else {
+            int max = m_doc->clipManager()->clipsCount();
+            emit displayMessage(i18n("Loading clips"), (int)(100 *(max - m_infoQueue.count()) / max));
+        }
     }
+    if (item && m_listView->isEnabled() && replace) {
+            // update clip in clip monitor
+            if (item->isSelected() && m_listView->selectedItems().count() == 1)
+                emit clipSelected(item->referencedClip());
+            //TODO: Make sure the line below has no side effect
+            toReload = clipId;
+        }
     if (!toReload.isEmpty())
         emit clipNeedsReload(toReload, true);
 
-    if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    //if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
 }
 
 bool ProjectList::adjustProjectProfileToItem(ProjectItem *item)
@@ -1982,7 +2056,7 @@ void ProjectList::addClipCut(const QString &id, int in, int out, const QString d
             m_listView->scrollToItem(sub);
             m_listView->editItem(sub, 1);
         }
-        QPixmap p = clip->referencedClip()->thumbProducer()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
+        QPixmap p = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height()  * m_render->dar()), sub->sizeHint(0).height() - 2);
         sub->setData(0, Qt::DecorationRole, p);
         m_doc->cachePixmap(clip->getClipHash() + '#' + QString::number(in), p);
         monitorItemEditing(true);
@@ -2109,69 +2183,78 @@ QMap <QString, QString> ProjectList::getProxies()
     return list;
 }
 
-void ProjectList::slotCreateProxy(const QString id, bool createProducer)
+void ProjectList::slotCreateProxy(const QString id)
 {
     ProjectItem *item = getItemById(id);
-    if (!item || item->isProxyRunning()) return;
-    
-    // If proxy producer already exists, skip creation
-    if (!createProducer) {
-        setProxyStatus(id, PROXYDONE);
+    if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return;
+    QString path = item->referencedClip()->getProperty("proxy");
+    if (path.isEmpty()) {
+        setProxyStatus(path, PROXYCRASHED);
         return;
     }
-    setProxyStatus(id, PROXYWAITING);
-    if (m_abortProxyId.contains(id)) m_abortProxyId.removeAll(id);
-    emit projectModified();
-    QtConcurrent::run(this, &ProjectList::slotGenerateProxy, id);
+    setProxyStatus(path, PROXYWAITING);
+    if (m_abortProxy.contains(path)) m_abortProxy.removeAll(path);
+    if (m_processingProxy.contains(path)) {
+        // Proxy is already being generated
+        return;
+    }
+    if (QFile::exists(path)) {
+        // Proxy already created
+        setProxyStatus(path, PROXYDONE);
+        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();
+    m_proxyList.append(info);
+    m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy));
 }
 
-void ProjectList::slotAbortProxy(const QString id)
+void ProjectList::slotAbortProxy(const QString id, const QString path)
 {
-    if (m_proxyList.contains(id)) m_proxyList.removeAll(id);
+    QTreeWidgetItemIterator it(m_listView);
     ProjectItem *item = getItemById(id);
-    if (item) {
-      emit projectModified();
-      if (item->isProxyReady()) slotGotProxy(id);
-      else if (item->isProxyRunning()) m_abortProxyId << id;
-      setProxyStatus(id, NOPROXY);
+    setProxyStatus(item, NOPROXY);
+    slotGotProxy(item);
+    if (!path.isEmpty() && m_processingProxy.contains(path)) {
+        m_abortProxy << path;
+        setProxyStatus(path, NOPROXY);
     }
 }
 
-void ProjectList::slotGenerateProxy(const QString id)
+void ProjectList::slotGenerateProxy()
 {
-    setProxyStatus(id, CREATINGPROXY);
-    ProjectItem *item = getItemById(id);
-    if (item == NULL) return;
-    QString path = item->referencedClip()->getProperty("proxy");
-    if (path.isEmpty()) {
-        setProxyStatus(id, PROXYCRASHED);
+    if (m_proxyList.isEmpty() || m_abortAllProxies) return;
+    emit projectModified();
+    PROXYINFO info = m_proxyList.takeFirst();
+    if (m_abortProxy.contains(info.dest)) {
+        m_abortProxy.removeAll(info.dest);
         return;
     }
 
-    if (QFile::exists(path)) {
-        setProxyStatus(id, PROXYDONE);
-        slotGotProxy(id);
+    // Make sure proxy path is writable
+    QFile file(info.dest);
+    if (!file.open(QIODevice::WriteOnly)) {
+        setProxyStatus(info.dest, PROXYCRASHED);
+        m_processingProxy.removeAll(info.dest);
         return;
     }
-    else {
-        // Make sure proxy path is writable
-        QFile file(path);
-        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
-            setProxyStatus(id, PROXYCRASHED);
-            return;
-        }
-        file.close();
-        QFile::remove(path);
-    }
-
-    QString url = item->clipUrl().path();
+    file.close();
+    QFile::remove(info.dest);
+    
+    setProxyStatus(info.dest, CREATINGPROXY);
 
     // Special case: playlist clips (.mlt or .kdenlive project files)
-    if (item->clipType() == PLAYLIST) {
+    if (info.type == PLAYLIST) {
         // change FFmpeg params to MLT format
         QStringList parameters;
-        parameters << url;
-        parameters << "-consumer" << "avformat:" + path;
+        parameters << info.src;
+        parameters << "-consumer" << "avformat:" + info.dest;
         QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts);
         
         foreach(QString s, params) {
@@ -2185,8 +2268,8 @@ void ProjectList::slotGenerateProxy(const QString id)
         
         parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads()));
 
-        // currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
-        double display_ratio = KdenliveDoc::getDisplayRatio(url);
+        //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy
+        double display_ratio = KdenliveDoc::getDisplayRatio(info.src);
         parameters << "aspect=" + QString::number(display_ratio);
 
         //kDebug()<<"TRANSCOD: "<<parameters;
@@ -2196,38 +2279,40 @@ void ProjectList::slotGenerateProxy(const QString id)
         int result = -1;
         while (myProcess.state() != QProcess::NotRunning) {
             // building proxy file
-            if (m_abortProxyId.contains(id)) {
+            if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
                 myProcess.close();
                 myProcess.waitForFinished();
-                m_abortProxyId.removeAll(id);
-                QFile::remove(path);
-                setProxyStatus(id, NOPROXY);
+                QFile::remove(info.dest);
+                m_abortProxy.removeAll(info.dest);
+                m_processingProxy.removeAll(info.dest);
+                setProxyStatus(info.dest, NOPROXY);
                 result = -2;
 
             }
             myProcess.waitForFinished(500);
         }
         myProcess.waitForFinished();
+        m_processingProxy.removeAll(info.dest);
         if (result == -1) result = myProcess.exitStatus();
         if (result == 0) {
             // proxy successfully created
-            setProxyStatus(id, PROXYDONE);
-            slotGotProxy(id);
+            setProxyStatus(info.dest, PROXYDONE);
+            slotGotProxy(info.dest);
         }
         else if (result == 1) {
             // Proxy process crashed
-            QFile::remove(path);
-            setProxyStatus(id, PROXYCRASHED);
+            QFile::remove(info.dest);
+            setProxyStatus(info.dest, PROXYCRASHED);
         }   
 
     }
     
-    if (item->clipType() == IMAGE) {
+    if (info.type == IMAGE) {
         // Image proxy
-        QImage i(url);
+        QImage i(info.src);
         if (i.isNull()) {
             // Cannot load image
-            setProxyStatus(id, PROXYCRASHED);
+            setProxyStatus(info.dest, PROXYCRASHED);
             return;
         }
         QImage proxy;
@@ -2235,13 +2320,12 @@ void ProjectList::slotGenerateProxy(const QString id)
         //TODO: Make it be configurable?
         if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth());
         else proxy = i.scaledToHeight(m_render->renderHeight());
-        int exif_orientation = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt();
-        if (exif_orientation > 1) {
+        if (info.exif > 1) {
             // Rotate image according to exif data
             QImage processed;
             QMatrix matrix;
 
-            switch ( exif_orientation ) {
+            switch ( info.exif ) {
                 case 2:
                   matrix.scale( -1, 1 );
                   break;
@@ -2267,35 +2351,39 @@ void ProjectList::slotGenerateProxy(const QString id)
                   break;
               }
               processed = proxy.transformed( matrix );
-              processed.save(path);
+              processed.save(info.dest);
         }
-        else proxy.save(path);
-        setProxyStatus(id, PROXYDONE);
-        slotGotProxy(id);
+        else proxy.save(info.dest);
+        setProxyStatus(info.dest, PROXYDONE);
+        slotGotProxy(info.dest);
+        m_abortProxy.removeAll(info.dest);
+        m_processingProxy.removeAll(info.dest);
         return;
     }
 
     QStringList parameters;
-    parameters << "-i" << url;
+    parameters << "-i" << info.src;
     QString params = m_doc->getDocumentProperty("proxyparams").simplified();
     foreach(QString s, params.split(' '))
     parameters << s;
 
     // Make sure we don't block when proxy file already exists
     parameters << "-y";
-    parameters << path;
+    parameters << info.dest;
+    kDebug()<<"// STARTING PROXY GEN: "<<parameters;
     QProcess myProcess;
     myProcess.start("ffmpeg", parameters);
     myProcess.waitForStarted();
     int result = -1;
     while (myProcess.state() != QProcess::NotRunning) {
         // building proxy file
-        if (m_abortProxyId.contains(id)) {
+        if (m_abortProxy.contains(info.dest) || m_abortAllProxies) {
             myProcess.close();
             myProcess.waitForFinished();
-            m_abortProxyId.removeAll(id);
-            QFile::remove(path);
-            setProxyStatus(id, NOPROXY);
+            m_abortProxy.removeAll(info.dest);
+            m_processingProxy.removeAll(info.dest);
+            QFile::remove(info.dest);
+            setProxyStatus(info.dest, NOPROXY);
             result = -2;
             
         }
@@ -2305,14 +2393,16 @@ void ProjectList::slotGenerateProxy(const QString id)
     if (result == -1) result = myProcess.exitStatus();
     if (result == 0) {
         // proxy successfully created
-        setProxyStatus(id, PROXYDONE);
-        slotGotProxy(id);
+        setProxyStatus(info.dest, PROXYDONE);
+        slotGotProxy(info.dest);
     }
     else if (result == 1) {
         // Proxy process crashed
-        QFile::remove(path);
-        setProxyStatus(id, PROXYCRASHED);
+        QFile::remove(info.dest);
+        setProxyStatus(info.dest, PROXYCRASHED);
     }
+    m_abortProxy.removeAll(info.dest);
+    m_processingProxy.removeAll(info.dest);
 }
 
 void ProjectList::updateProxyConfig()
@@ -2339,7 +2429,7 @@ void ProjectList::updateProxyConfig()
                 if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > m_doc->getDocumentProperty("proxyminsize").toInt()) {
                     if (clip->getProperty("proxy").isEmpty()) {
                         // We need to insert empty proxy in old properties so that undo will work
-                        QMap <QString, QString> oldProps = clip->properties();
+                        QMap <QString, QString> oldProps;// = clip->properties();
                         oldProps.insert("proxy", QString());
                         QMap <QString, QString> newProps;
                         newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension"));
@@ -2384,7 +2474,8 @@ void ProjectList::updateProxyConfig()
     }
     if (command->childCount() > 0) m_doc->commandStack()->push(command);
     else delete command;
-    if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    //if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
 }
 
 void ProjectList::slotProxyCurrentItem(bool doProxy)
@@ -2418,9 +2509,9 @@ void ProjectList::slotProxyCurrentItem(bool doProxy)
                 if (doProxy) {
                     newProps.clear();
                     QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension"));
-                    newProps.insert("proxy", path);
                     // insert required duration for proxy
                     newProps.insert("proxy_out", item->referencedClip()->producerProperty("out"));
+                    newProps.insert("proxy", path);
                     // We need to insert empty proxy so that undo will work
                     oldProps.insert("proxy", QString());
                 }
@@ -2433,12 +2524,50 @@ void ProjectList::slotProxyCurrentItem(bool doProxy)
     }
     else delete command;
     //if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
+    if (!m_infoQueue.isEmpty()) QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue);
 }
 
-void ProjectList::setProxyStatus(const QString id, PROXYSTATUS status)
+
+void ProjectList::slotDeleteProxy(const QString proxyPath)
 {
-    ProjectItem *item = getItemById(id);
-    setProxyStatus(item, status);
+    if (proxyPath.isEmpty()) return;
+    QUndoCommand *proxyCommand = new QUndoCommand();
+    proxyCommand->setText(i18n("Remove Proxy"));
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
+    while (*it) {
+        if ((*it)->type() == PROJECTCLIPTYPE) {
+            item = static_cast <ProjectItem *>(*it);
+            if (item->referencedClip()->getProperty("proxy") == proxyPath) {
+                QMap <QString, QString> props;
+                props.insert("proxy", QString());
+                new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), props, true, proxyCommand);
+            
+            }
+        }
+        ++it;
+    }
+    if (proxyCommand->childCount() == 0)
+        delete proxyCommand;
+    else
+        m_commandStack->push(proxyCommand);
+    QFile::remove(proxyPath);
+}
+
+void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status)
+{
+    if (proxyPath.isEmpty() || m_abortAllProxies) return;
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
+    while (*it) {
+        if ((*it)->type() == PROJECTCLIPTYPE) {
+            item = static_cast <ProjectItem *>(*it);
+            if (item->referencedClip()->getProperty("proxy") == proxyPath) {
+                setProxyStatus(item, status);
+            }
+        }
+        ++it;
+    }
 }
 
 void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status)