]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Fix dropframe timecode, patch from John T. Mertz
[kdenlive] / src / projectlist.cpp
index 7a4121c02481192634367321041856f1bed17fba..2c33398a9aaec6ef929a3705d25b86589a0c31bd 100644 (file)
@@ -202,6 +202,11 @@ void ProjectList::setHeaderInfo(const QByteArray &state)
     m_listView->header()->restoreState(state);
 }
 
+void ProjectList::updateProjectFormat(Timecode t)
+{
+    m_timecode = t;
+}
+
 void ProjectList::slotEditClip()
 {
     QList<QTreeWidgetItem *> list = m_listView->selectedItems();
@@ -350,7 +355,7 @@ void ProjectList::trashUnusedClips()
         it2++;
     }
 
-    m_doc->deleteProjectClip(ids);
+    emit deleteProjectClips(ids, QMap <QString, QString>());
     for (int i = 0; i < urls.count(); i++) {
         KIO::NetAccess::del(KUrl(urls.at(i)), this);
     }
@@ -613,7 +618,7 @@ void ProjectList::slotRemoveClip()
             folderids[folder->groupName()] = folder->clipId();
             int children = folder->childCount();
 
-            if (children > 0 && 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, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
+            if (children > 0 && 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, folder->text(1)), i18n("Delete Folder")) != KMessageBox::Yes) return;
             for (int i = 0; i < children; ++i) {
                 ProjectItem *child = static_cast <ProjectItem *>(folder->child(i));
                 ids << child->clipId();
@@ -622,22 +627,37 @@ void ProjectList::slotRemoveClip()
             ProjectItem *item = static_cast <ProjectItem *>(selected.at(i));
             ids << item->clipId();
             if (item->numReferences() > 0) {
-                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;
+                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;
             }
         }
     }
 
     if (delCommand->childCount() == 0) delete delCommand;
     else m_commandStack->push(delCommand);
-    if (!ids.isEmpty()) m_doc->deleteProjectClip(ids);
-    if (!folderids.isEmpty()) deleteProjectFolder(folderids);
+    emit deleteProjectClips(ids, folderids);
+}
+
+void ProjectList::updateButtons() const
+{
     if (m_listView->topLevelItemCount() == 0) {
-        m_editAction->setEnabled(false);
         m_deleteAction->setEnabled(false);
-        m_openAction->setEnabled(false);
-        m_reloadAction->setEnabled(false);
-        m_transcodeAction->setEnabled(false);
+    } else {
+        m_deleteAction->setEnabled(true);
+        if (!m_listView->currentItem()) m_listView->setCurrentItem(m_listView->topLevelItem(0));
+        QTreeWidgetItem *item = m_listView->currentItem();
+        if (item && item->type() == PROJECTCLIPTYPE) {
+            m_editAction->setEnabled(true);
+            m_openAction->setEnabled(true);
+            m_reloadAction->setEnabled(true);
+            m_transcodeAction->setEnabled(true);
+            return;
+        }
     }
+
+    m_editAction->setEnabled(false);
+    m_openAction->setEnabled(false);
+    m_reloadAction->setEnabled(false);
+    m_transcodeAction->setEnabled(false);
 }
 
 void ProjectList::selectItemById(const QString &clipId)
@@ -655,10 +675,13 @@ void ProjectList::slotDeleteClip(const QString &clipId)
         return;
     }
     m_listView->blockSignals(true);
+    QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
+    if (!newSelectedItem) newSelectedItem = m_listView->itemBelow(item);
     delete item;
     m_doc->clipManager()->deleteClip(clipId);
     m_listView->blockSignals(false);
-    slotClipSelected();
+    if (newSelectedItem) m_listView->setCurrentItem(newSelectedItem);
+    else updateButtons();
 }
 
 
@@ -681,7 +704,11 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
         FolderProjectItem *item = getFolderItemById(clipId);
         if (item) {
             m_doc->clipManager()->deleteFolder(clipId);
+            QTreeWidgetItem *newSelectedItem = m_listView->itemAbove(item);
+            if (!newSelectedItem) newSelectedItem = m_listView->itemBelow(item);
             delete item;
+            if (newSelectedItem) m_listView->setCurrentItem(newSelectedItem);
+            else updateButtons();
         }
     } else {
         if (edit) {
@@ -705,6 +732,7 @@ void ProjectList::slotAddFolder(const QString foldername, const QString &clipId,
             m_doc->clipManager()->addFolder(clipId, foldername);
             m_listView->blockSignals(false);
         }
+        updateButtons();
     }
     m_doc->setModified(true);
 }
@@ -733,6 +761,7 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
         QDomElement e = clip->toXML().cloneNode().toElement();
         e.removeAttribute("file_hash");
         m_infoQueue.insert(clip->getId(), e);
+        clip->askForAudioThumbs();
         //m_render->getFileProperties(clip->toXML(), clip->getId(), true);
     }
     const QString parent = clip->getProperty("groupid");
@@ -757,7 +786,9 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
     if (getProperties == false && !clip->getClipHash().isEmpty()) {
         QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png";
         if (QFile::exists(cachedPixmap)) {
-            item->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap));
+            QPixmap pix(cachedPixmap);
+            if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this);
+            item->setData(0, Qt::DecorationRole, pix);
         }
     }
 #ifdef NEPOMUK
@@ -777,13 +808,17 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
             if (!clip->getClipHash().isEmpty()) {
                 QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + '#' + QString::number(cuts.at(i).zone.x()) + ".png";
                 if (QFile::exists(cachedPixmap)) {
-                    sub->setData(0, Qt::DecorationRole, QPixmap(cachedPixmap));
+                    QPixmap pix(cachedPixmap);
+                    if (pix.isNull()) KIO::NetAccess::del(KUrl(cachedPixmap), this);
+                    sub->setData(0, Qt::DecorationRole, pix);
                 }
             }
         }
     }
-
-    if (getProperties && m_listView->isEnabled()) m_listView->blockSignals(false);
+    if (m_listView->isEnabled()) {
+        updateButtons();
+        if (getProperties) m_listView->blockSignals(false);
+    }
     if (getProperties && !m_queueTimer.isActive()) m_queueTimer.start();
 }
 
@@ -823,7 +858,7 @@ void ProjectList::slotUpdateClip(const QString &id)
 {
     ProjectItem *item = getItemById(id);
     m_listView->blockSignals(true);
-    if (item) item->setData(1, UsageRole, QString::number(item->numReferences()));
+    if (item) item->setData(0, UsageRole, QString::number(item->numReferences()));
     m_listView->blockSignals(false);
 }
 
@@ -856,7 +891,7 @@ void ProjectList::updateAllClips()
             if (item->referencedClip()->producer() == NULL) {
                 if (clip->isPlaceHolder() == false) {
                     requestClipInfo(clip->toXML(), clip->getId());
-                } else item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
+                } else if (!clip->isPlaceHolder()) item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
             } else {
                 if (item->data(0, Qt::DecorationRole).isNull()) {
                     requestClipThumbnail(clip->getId());
@@ -865,7 +900,7 @@ void ProjectList::updateAllClips()
                     item->changeDuration(item->referencedClip()->producer()->get_playtime());
                 }
             }
-            item->setData(1, UsageRole, QString::number(item->numReferences()));
+            item->setData(0, UsageRole, QString::number(item->numReferences()));
         }
         //qApp->processEvents();
         ++it;
@@ -925,15 +960,16 @@ void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
     QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue()));
     if (item) {
         const QString path = item->referencedClip()->fileURL().path();
+        if (item->referencedClip()->isPlaceHolder()) replace = false;
         if (!path.isEmpty()) {
-            if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br>is invalid, will be removed from project.", path));
+            if (replace) KMessageBox::sorry(this, i18n("Clip <b>%1</b><br />is invalid, will be removed from project.", path));
             else {
-                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;
+                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;
             }
         }
         QStringList ids;
         ids << id;
-        if (replace) m_doc->deleteProjectClip(ids);
+        if (replace) emit deleteProjectClips(ids, QMap <QString, QString>());
     }
 }
 
@@ -945,8 +981,10 @@ void ProjectList::slotAddColorClip()
     QDialog *dia = new QDialog(this);
     Ui::ColorClip_UI dia_ui;
     dia_ui.setupUi(dia);
+    dia->setWindowTitle(i18n("Color Clip"));
     dia_ui.clip_name->setText(i18n("Color Clip"));
-    dia_ui.clip_duration->setText(KdenliveSettings::color_duration());
+    dia_ui.clip_duration->setInputMask(m_timecode.inputMask());
+    dia_ui.clip_duration->setText(m_timecode.reformatSeparators(KdenliveSettings::color_duration()));
     if (dia->exec() == QDialog::Accepted) {
         QString color = dia_ui.clip_color->color().name();
         color = color.replace(0, 1, "0x") + "ff";
@@ -1091,6 +1129,7 @@ void ProjectList::slotCheckForEmptyQueue()
         emit displayMessage(QString(), -1);
         m_listView->blockSignals(false);
         m_listView->setEnabled(true);
+        updateButtons();
     } else if (!m_refreshed) QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue()));
 }
 
@@ -1183,12 +1222,19 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update)
 
 void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const QMap < QString, QString > &properties, const QMap < QString, QString > &metadata, bool replace)
 {
+    QString toReload;
     ProjectItem *item = getItemById(clipId);
     if (item && producer) {
         m_listView->blockSignals(true);
         item->setProperties(properties, metadata);
+        if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) {
+            item->referencedClip()->setValid();
+            item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable);
+            toReload = clipId;
+        }
         //Q_ASSERT_X(item->referencedClip(), "void ProjectList::slotReplyGetFileProperties", QString("Item with groupName %1 does not have a clip associated").arg(item->groupName()).toLatin1());
         item->referencedClip()->setProducer(producer, replace);
+        item->referencedClip()->askForAudioThumbs();
         if (!replace && item->data(0, Qt::DecorationRole).isNull()) {
             requestClipThumbnail(clipId);
         }
@@ -1215,6 +1261,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
         m_listView->setCurrentItem(item);
         emit clipSelected(item->referencedClip());
     }
+    if (!toReload.isEmpty()) emit clipNeedsReload(toReload, true);
     QTimer::singleShot(30, this, SLOT(slotProcessNextClipInQueue()));
 }