]> git.sesse.net Git - kdenlive/blobdiff - src/projectlist.cpp
Fix dropframe timecode, patch from John T. Mertz
[kdenlive] / src / projectlist.cpp
index 020bb439aaafc3514ee8d93c93dfa5c743ccabda..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");
@@ -786,8 +815,10 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties)
             }
         }
     }
-
-    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();
 }
 
@@ -827,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);
 }
 
@@ -869,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;
@@ -931,14 +962,14 @@ void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace)
         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>());
     }
 }
 
@@ -950,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";
@@ -1096,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()));
 }
 
@@ -1200,6 +1234,7 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce
         }
         //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);
         }