Fix several crashes / issues with bin subclips

Fixes #16
parent 3e9dd5a6
...@@ -995,7 +995,12 @@ void Bin::slotReloadClip() ...@@ -995,7 +995,12 @@ void Bin::slotReloadClip()
continue; continue;
} }
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix)); std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
auto currentItem = std::static_pointer_cast<ProjectClip>(item); std::shared_ptr<ProjectClip> currentItem = nullptr;
if (item->itemType() == AbstractProjectItem::ClipItem) {
currentItem = std::static_pointer_cast<ProjectClip>(item);
} else if (item->itemType() == AbstractProjectItem::SubClipItem) {
currentItem = std::static_pointer_cast<ProjectSubClip>(item)->getMasterClip();
}
if (currentItem) { if (currentItem) {
emit openClip(std::shared_ptr<ProjectClip>()); emit openClip(std::shared_ptr<ProjectClip>());
if (currentItem->clipType() == ClipType::Playlist) { if (currentItem->clipType() == ClipType::Playlist) {
...@@ -1037,7 +1042,12 @@ void Bin::slotLocateClip() ...@@ -1037,7 +1042,12 @@ void Bin::slotLocateClip()
continue; continue;
} }
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix)); std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
auto currentItem = std::static_pointer_cast<ProjectClip>(item); std::shared_ptr<ProjectClip> currentItem = nullptr;
if (item->itemType() == AbstractProjectItem::ClipItem) {
currentItem = std::static_pointer_cast<ProjectClip>(item);
} else if (item->itemType() == AbstractProjectItem::SubClipItem) {
currentItem = std::static_pointer_cast<ProjectSubClip>(item)->getMasterClip();
}
if (currentItem) { if (currentItem) {
QUrl url = QUrl::fromLocalFile(currentItem->url()).adjusted(QUrl::RemoveFilename); QUrl url = QUrl::fromLocalFile(currentItem->url()).adjusted(QUrl::RemoveFilename);
bool exists = QFile(url.toLocalFile()).exists(); bool exists = QFile(url.toLocalFile()).exists();
...@@ -1062,26 +1072,34 @@ void Bin::slotDuplicateClip() ...@@ -1062,26 +1072,34 @@ void Bin::slotDuplicateClip()
continue; continue;
} }
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix)); std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(ix));
auto currentItem = std::static_pointer_cast<ProjectClip>(item); if (item->itemType() == AbstractProjectItem::ClipItem) {
if (currentItem) { auto currentItem = std::static_pointer_cast<ProjectClip>(item);
QDomDocument doc; if (currentItem) {
QDomElement xml = currentItem->toXml(doc); QDomDocument doc;
if (!xml.isNull()) { QDomElement xml = currentItem->toXml(doc);
QString currentName = Xml::getXmlProperty(xml, QStringLiteral("kdenlive:clipname")); if (!xml.isNull()) {
if (currentName.isEmpty()) { QString currentName = Xml::getXmlProperty(xml, QStringLiteral("kdenlive:clipname"));
QUrl url = QUrl::fromLocalFile(Xml::getXmlProperty(xml, QStringLiteral("resource"))); if (currentName.isEmpty()) {
if (url.isValid()) { QUrl url = QUrl::fromLocalFile(Xml::getXmlProperty(xml, QStringLiteral("resource")));
currentName = url.fileName(); if (url.isValid()) {
currentName = url.fileName();
}
} }
if (!currentName.isEmpty()) {
currentName.append(i18nc("append to clip name to indicate a copied idem", " (copy)"));
Xml::setXmlProperty(xml, QStringLiteral("kdenlive:clipname"), currentName);
}
QString id;
m_itemModel->requestAddBinClip(id, xml, item->parent()->clipId(), i18n("Duplicate clip"));
selectClipById(id);
} }
if (!currentName.isEmpty()) {
currentName.append(i18nc("append to clip name to indicate a copied idem", " (copy)"));
Xml::setXmlProperty(xml, QStringLiteral("kdenlive:clipname"), currentName);
}
QString id;
m_itemModel->requestAddBinClip(id, xml, item->parent()->clipId(), i18n("Duplicate clip"));
selectClipById(id);
} }
} else if (item->itemType() == AbstractProjectItem::SubClipItem) {
auto currentItem = std::static_pointer_cast<ProjectSubClip>(item);
QString id;
QPoint clipZone = currentItem->zone();
m_itemModel->requestAddBinSubClip(id, clipZone.x(), clipZone.y(), QString(), currentItem->getMasterClip()->clipId());
selectClipById(id);
} }
} }
} }
...@@ -1452,6 +1470,7 @@ void Bin::contextMenuEvent(QContextMenuEvent *event) ...@@ -1452,6 +1470,7 @@ void Bin::contextMenuEvent(QContextMenuEvent *event)
ClipType::ProducerType type = ClipType::Unknown; ClipType::ProducerType type = ClipType::Unknown;
bool isFolder = false; bool isFolder = false;
bool isImported = false; bool isImported = false;
AbstractProjectItem::PROJECTITEMTYPE itemType;
QString clipService; QString clipService;
QString audioCodec; QString audioCodec;
if (m_itemView) { if (m_itemView) {
...@@ -1459,11 +1478,10 @@ void Bin::contextMenuEvent(QContextMenuEvent *event) ...@@ -1459,11 +1478,10 @@ void Bin::contextMenuEvent(QContextMenuEvent *event)
if (idx.isValid()) { if (idx.isValid()) {
// User right clicked on a clip // User right clicked on a clip
std::shared_ptr<AbstractProjectItem> currentItem = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(idx)); std::shared_ptr<AbstractProjectItem> currentItem = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(idx));
itemType = currentItem->itemType();
if (currentItem) { if (currentItem) {
enableClipActions = true; enableClipActions = true;
if (currentItem->itemType() == AbstractProjectItem::FolderItem) { if (itemType == AbstractProjectItem::ClipItem) {
isFolder = true;
} else {
auto clip = std::static_pointer_cast<ProjectClip>(currentItem); auto clip = std::static_pointer_cast<ProjectClip>(currentItem);
if (clip) { if (clip) {
m_proxyAction->blockSignals(true); m_proxyAction->blockSignals(true);
...@@ -1508,6 +1526,7 @@ void Bin::contextMenuEvent(QContextMenuEvent *event) ...@@ -1508,6 +1526,7 @@ void Bin::contextMenuEvent(QContextMenuEvent *event)
} }
} }
m_proxyAction->blockSignals(false); m_proxyAction->blockSignals(false);
} else if (itemType == AbstractProjectItem::SubClipItem) {
} }
} }
} }
...@@ -1521,19 +1540,19 @@ void Bin::contextMenuEvent(QContextMenuEvent *event) ...@@ -1521,19 +1540,19 @@ void Bin::contextMenuEvent(QContextMenuEvent *event)
m_editAction->setVisible(!isFolder); m_editAction->setVisible(!isFolder);
m_clipsActionsMenu->setEnabled(enableClipActions); m_clipsActionsMenu->setEnabled(enableClipActions);
m_extractAudioAction->setEnabled(enableClipActions); m_extractAudioAction->setEnabled(enableClipActions);
m_openAction->setVisible(!isFolder); m_openAction->setVisible(itemType != AbstractProjectItem::FolderItem);
m_reloadAction->setVisible(!isFolder); m_reloadAction->setVisible(itemType != AbstractProjectItem::FolderItem);
m_duplicateAction->setVisible(!isFolder); m_duplicateAction->setVisible(itemType != AbstractProjectItem::FolderItem);
m_inTimelineAction->setVisible(!isFolder); m_inTimelineAction->setVisible(itemType != AbstractProjectItem::FolderItem);
if (m_transcodeAction) { if (m_transcodeAction) {
m_transcodeAction->setEnabled(enableClipActions); m_transcodeAction->setEnabled(enableClipActions);
m_transcodeAction->menuAction()->setVisible(!isFolder && clipService.contains(QStringLiteral("avformat"))); m_transcodeAction->menuAction()->setVisible(itemType != AbstractProjectItem::FolderItem && clipService.contains(QStringLiteral("avformat")));
} }
m_clipsActionsMenu->menuAction()->setVisible( m_clipsActionsMenu->menuAction()->setVisible(
!isFolder && itemType != AbstractProjectItem::FolderItem &&
(clipService.contains(QStringLiteral("avformat")) || clipService.contains(QStringLiteral("xml")) || clipService.contains(QStringLiteral("consumer")))); (clipService.contains(QStringLiteral("avformat")) || clipService.contains(QStringLiteral("xml")) || clipService.contains(QStringLiteral("consumer"))));
m_extractAudioAction->menuAction()->setVisible(!isFolder && !audioCodec.isEmpty()); m_extractAudioAction->menuAction()->setVisible(!isFolder && !audioCodec.isEmpty());
m_locateAction->setVisible(!isFolder && (isImported)); m_locateAction->setVisible(itemType != AbstractProjectItem::FolderItem && (isImported));
// Show menu // Show menu
event->setAccepted(true); event->setAccepted(true);
...@@ -1632,9 +1651,14 @@ void Bin::slotSwitchClipProperties() ...@@ -1632,9 +1651,14 @@ void Bin::slotSwitchClipProperties()
if (current.isValid()) { if (current.isValid()) {
// User clicked in the icon, open clip properties // User clicked in the icon, open clip properties
std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(current)); std::shared_ptr<AbstractProjectItem> item = m_itemModel->getBinItemByIndex(m_proxyModel->mapToSource(current));
auto clip = std::static_pointer_cast<ProjectClip>(item); std::shared_ptr<ProjectClip> currentItem = nullptr;
if (clip) { if (item->itemType() == AbstractProjectItem::ClipItem) {
slotSwitchClipProperties(clip); currentItem = std::static_pointer_cast<ProjectClip>(item);
} else if (item->itemType() == AbstractProjectItem::SubClipItem) {
currentItem = std::static_pointer_cast<ProjectSubClip>(item)->getMasterClip();
}
if (currentItem) {
slotSwitchClipProperties(currentItem);
return; return;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment