]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Add option to remove unused clips from project tree:
[kdenlive] / src / projectlist.cpp
index 1f173bef57a7f4986aa7db0261fb3eb3bf748557..a8f76657421fdd781cef7ed2b89e7ebc7eda29f9 100644 (file)
@@ -212,6 +212,19 @@ void ProjectList::slotOpenClip()
     }
 }
 
+void ProjectList::cleanup()
+{
+    m_listView->clearSelection();
+    QTreeWidgetItemIterator it(m_listView);
+    ProjectItem *item;
+    while (*it) {
+        item = static_cast <ProjectItem *>(*it);
+        if (item->numReferences() == 0) item->setSelected(true);
+        it++;
+    }
+    slotRemoveClip();
+}
+
 void ProjectList::slotReloadClip(const QString &id)
 {
     QList<QTreeWidgetItem *> selected;
@@ -383,7 +396,7 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item)
 void ProjectList::slotRemoveClip()
 {
     if (!m_listView->currentItem()) return;
-    QList <QString> ids;
+    QStringList ids;
     QMap <QString, QString> folderids;
     QList<QTreeWidgetItem *> selected = m_listView->selectedItems();
     ProjectItem *item;
@@ -395,7 +408,7 @@ void ProjectList::slotRemoveClip()
             if (KMessageBox::questionYesNo(this, i18np("Delete clip <b>%2</b>?<br>This will also remove the clip in timeline", "Delete clip <b>%2</b>?<br>This will also remove its %1 clips in timeline", item->numReferences(), item->names().at(1)), i18n("Delete Clip")) != KMessageBox::Yes) return;
         } else if (item->isGroup() && item->childCount() > 0) {
             int children = item->childCount();
-            if (KMessageBox::questionYesNo(this, i18n("Delete folder <b>%2</b>?<br>This will also remove the %1 clips in that folder", children, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
+            if (KMessageBox::questionYesNo(this, i18np("Delete folder <b>%2</b>?<br>This will also remove the clip in that folder", "Delete folder <b>%2</b>?<br>This will also remove the %1 clips in that folder",  children, item->names().at(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
             for (int i = 0; i < children; ++i) {
                 ProjectItem *child = static_cast <ProjectItem *>(item->child(i));
                 ids << child->clipId();
@@ -498,9 +511,15 @@ void ProjectList::deleteProjectFolder(QMap <QString, QString> map)
 
 void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
 {
+    m_listView->setEnabled(false);
     if (getProperties) {
-        m_listView->setEnabled(false);
         m_listView->blockSignals(true);
+        m_refreshed = false;
+        // remove file_hash so that we load all properties for the clip
+        QDomElement e = clip->toXML().cloneNode().toElement();
+        e.removeAttribute("file_hash");
+        m_infoQueue.insert(clip->getId(), e);
+        //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
     }
     const QString parent = clip->getProperty("groupid");
     kDebug() << "Adding clip with groupid: " << parent;
@@ -536,7 +555,8 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
         if (!annotation.isEmpty()) item->setText(2, annotation);
         item->setText(3, QString::number(f.rating()));
     }
-    if (getProperties) m_listView->blockSignals(false);
+    if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
+    if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
 }
 
 void ProjectList::slotResetProjectList()
@@ -550,9 +570,8 @@ void ProjectList::slotResetProjectList()
 
 void ProjectList::requestClipInfo(const QDomElement xml, const QString id)
 {
+    m_refreshed = false;
     m_infoQueue.insert(id, xml);
-    m_listView->setEnabled(false);
-    if (!m_queueTimer.isActive()) m_queueTimer.start();
     //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
 }
 
@@ -570,7 +589,8 @@ void ProjectList::slotProcessNextClipInQueue()
         m_infoQueue.remove(j.key());
         emit getFileProperties(dom, id, false);
     }
-    if (!m_infoQueue.isEmpty()) m_queueTimer.start();
+
+    if (!m_infoQueue.isEmpty() && !m_queueTimer.isActive()) m_queueTimer.start();
 }
 
 void ProjectList::slotUpdateClip(const QString &id)
@@ -606,12 +626,14 @@ void ProjectList::updateAllClips()
                 }
             }
             item->setData(1, UsageRole, QString::number(item->numReferences()));
-            qApp->processEvents();
+            //qApp->processEvents();
         }
         ++it;
     }
+    qApp->processEvents();
+    if (!m_queueTimer.isActive()) m_queueTimer.start();
 
-    m_listView->blockSignals(false);
+    if (m_listView->isEnabled()) m_listView->blockSignals(false);
     m_listView->setSortingEnabled(true);
     if (m_infoQueue.isEmpty()) slotProcessNextThumbnail();
 }
@@ -661,7 +683,7 @@ void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
                 if (KMessageBox::questionYesNo(this, i18n("Clip <b>%1</b><br>is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) replace = true;
             }
         }
-        QList <QString> ids;
+        QStringList ids;
         ids << id;
         if (replace) m_doc->deleteProjectClip(ids);
     }
@@ -809,7 +831,10 @@ void ProjectList::slotCheckForEmptyQueue()
     if (!m_refreshed && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
         m_refreshed = true;
         emit loadingIsOver();
-    } else QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
+        emit displayMessage(QString(), DefaultMessage);
+        m_listView->blockSignals(false);
+        m_listView->setEnabled(true);
+    } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
 }
 
 void ProjectList::reloadClipThumbnails()
@@ -832,7 +857,6 @@ void ProjectList::requestClipThumbnail(const QString id)
 void ProjectList::slotProcessNextThumbnail()
 {
     if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) {
-        m_listView->setEnabled(true);
         slotCheckForEmptyQueue();
         return;
     }
@@ -841,6 +865,10 @@ void ProjectList::slotProcessNextThumbnail()
         return;
     }
     slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false);
+    if (m_thumbnailQueue.count() > 1) {
+        emit displayMessage(i18n("Loading clips (%1)", m_thumbnailQueue.count()), InformationMessage);
+        qApp->processEvents();
+    }
 }
 
 void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update)
@@ -862,12 +890,12 @@ void ProjectList::slotRefreshClipThumbnail(ProjectItem *item, bool update)
         int height = 50;
         int width = (int)(height  * m_render->dar());
         if (clip->clipType() == AUDIO) pix = KIcon("audio-x-generic").pixmap(QSize(width, height));
-        else if (clip->clipType() == IMAGE) pix = KThumb::getFrame(item->referencedClip()->producer(), 0, width, height);
+        else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height));
         else pix = item->referencedClip()->thumbProducer()->extractImage(item->referencedClip()->getClipThumbFrame(), width, height);
         if (!pix.isNull()) {
             m_listView->blockSignals(true);
             item->setIcon(0, pix);
-            m_listView->blockSignals(false);
+            if (m_listView->isEnabled()) m_listView->blockSignals(false);
             m_doc->cachePixmap(item->getClipHash(), pix);
         }
         if (update) emit projectModified();
@@ -894,7 +922,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
             emit receivedClipDuration(clipId);
             delete producer;
         }*/
-        m_listView->blockSignals(false);
+        if (m_listView->isEnabled()) m_listView->blockSignals(false);
         if (item->icon(0).isNull()) {
             requestClipThumbnail(clipId);
         }
@@ -910,7 +938,7 @@ void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix)
         m_listView->blockSignals(true);
         item->setIcon(0, pix);
         m_doc->cachePixmap(item->getClipHash(), pix);
-        m_listView->blockSignals(false);
+        if (m_listView->isEnabled()) m_listView->blockSignals(false);
     }
 }