X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlist.cpp;h=001395d820b0f6badf3231ef232a0ad29b7e483a;hb=d1e6242c20436bfa1ac8d1c3a5dc9f55bd8f10ca;hp=cce8bb3d4bd7824ba8fc37dd44cc60c286b824c4;hpb=c975f482a411d7cdb71ba841b35e8a595dca0fde;p=kdenlive diff --git a/src/projectlist.cpp b/src/projectlist.cpp index cce8bb3d..001395d8 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -114,10 +114,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())); @@ -176,6 +172,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--; } } @@ -500,10 +500,31 @@ void ProjectList::slotMissingClip(const QString &id) ProjectItem *item = getItemById(id); if (item) { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); + int height = m_listView->iconSize().height(); + int width = (int)(height * m_render->dar()); + QPixmap pixmap = qVariantValue(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)); + p.end(); + 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); } @@ -608,7 +629,7 @@ void ProjectList::slotClipSelected() void ProjectList::adjustProxyActions(ProjectItem *clip) const { - if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) { + if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == SLIDESHOW || clip->clipType() == AUDIO) { m_proxyAction->setEnabled(false); return; } @@ -885,11 +906,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) { @@ -966,7 +990,8 @@ void ProjectList::deleteProjectFolder(QMap map) i.next(); new AddFolderCommand(this, i.key(), i.value(), false, delCommand); } - m_commandStack->push(delCommand); + if (delCommand->childCount() > 0) m_commandStack->push(delCommand); + else delete delCommand; } void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) @@ -994,13 +1019,14 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) } 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(abortProxy(const QString, const QString)), this, SLOT(slotAbortProxy(const QString, const QString))); if (getProperties) { m_listView->processLayout(); - m_refreshed = false; 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()); @@ -1047,21 +1073,49 @@ 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"); - e.setAttribute("replace", 1); - m_infoQueue.insert(id, e); - if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); + if (proxyPath.isEmpty() || !m_refreshed) return; + QTreeWidgetItemIterator it(m_listView); + ProjectItem *item; + + while (*it) { + if ((*it)->type() == PROJECTCLIPTYPE) { + item = static_cast (*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_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() @@ -1073,26 +1127,20 @@ void ProjectList::slotResetProjectList() m_refreshed = false; } -void ProjectList::requestClipInfo(const QDomElement xml, const QString id) -{ - m_refreshed = false; - m_infoQueue.insert(id, xml); - //if (m_infoQueue.count() == 1 || ) QTimer::singleShot(300, this, SLOT(slotProcessNextClipInQueue())); -} - void ProjectList::slotProcessNextClipInQueue() { if (m_infoQueue.isEmpty()) { emit processNextThumbnail(); return; } - + QMutexLocker locker(&m_mutex); QMap::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 @@ -1114,20 +1162,28 @@ void ProjectList::slotUpdateClip(const QString &id) monitorItemEditing(true); } -void ProjectList::updateAllClips() +void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) { m_listView->setSortingEnabled(false); - kDebug() << "// UPDATE ALL CLPY"; QTreeWidgetItemIterator it(m_listView); DocClipBase *clip; ProjectItem *item; monitorItemEditing(false); + int height = m_listView->iconSize().height(); + int width = (int)(height * m_render->dar()); + QPixmap missingPixmap = QPixmap(width, height); + missingPixmap.fill(Qt::transparent); + KIcon icon("dialog-close"); + 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 SubProjectItem *sub = static_cast (*it); - if (sub->data(0, Qt::DecorationRole).isNull()) { + if (displayRatioChanged || sub->data(0, Qt::DecorationRole).isNull()) { item = static_cast ((*it)->parent()); requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x())); } @@ -1141,28 +1197,66 @@ void ProjectList::updateAllClips() item = static_cast (*it); clip = item->referencedClip(); if (item->referencedClip()->producer() == NULL) { - if (clip->isPlaceHolder() == false) - requestClipInfo(clip->toXML(), clip->getId()); - else if (!clip->isPlaceHolder()) + 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(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 (item->data(0, Qt::DecorationRole).isNull()) + if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull()) requestClipThumbnail(clip->getId()); - if (item->data(0, DurationRole).toString().isEmpty()) + if (item->data(0, DurationRole).toString().isEmpty()) { item->changeDuration(item->referencedClip()->producer()->get_playtime()); + } + if (clip->isPlaceHolder()) { + QPixmap pixmap = qVariantValue(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); - if (m_infoQueue.isEmpty()) - slotProcessNextThumbnail(); + if (m_infoQueue.isEmpty()) { + slotProcessNextThumbnail(); + } } // static @@ -1271,7 +1365,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; @@ -1286,10 +1382,14 @@ void ProjectList::slotRemoveInvalidClip(const QString &id, bool replace) } } -void ProjectList::slotRemoveInvalidProxy(const QString &id) +void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError) { ProjectItem *item = getItemById(id); if (item) { + if (durationError) { + kDebug() << "Proxy duration is wrong, try changing transcoding parameters."; + emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2); + } item->setProxyStatus(PROXYCRASHED); QString path = item->referencedClip()->getProperty("proxy"); KUrl proxyFolder(m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"); @@ -1300,7 +1400,9 @@ void ProjectList::slotRemoveInvalidProxy(const QString &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); } void ProjectList::slotAddColorClip() @@ -1420,16 +1522,18 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_timecode = doc->timecode(); m_commandStack = doc->commandStack(); m_doc = doc; - m_proxyList.clear(); QMap flist = doc->clipManager()->documentFolderList(); + QStringList openedFolders = doc->getExpandedFolders(); QMapIterator f(flist); while (f.hasNext()) { f.next(); - (void) new FolderProjectItem(m_listView, QStringList() << f.value(), f.key()); + FolderProjectItem *folder = new FolderProjectItem(m_listView, QStringList() << f.value(), f.key()); + folder->setExpanded(openedFolders.contains(f.key())); } QList list = doc->clipManager()->documentClipList(); + if (list.isEmpty()) m_refreshed = true; for (int i = 0; i < list.count(); i++) slotAddClip(list.at(i), false); @@ -1438,7 +1542,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()), this, SLOT(updateAllClips())); + connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool)), this, SLOT(updateAllClips(bool, bool))); } QList ProjectList::documentClipList() const @@ -1470,10 +1574,12 @@ QDomElement ProjectList::producersList() void ProjectList::slotCheckForEmptyQueue() { - if (!m_refreshed && 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(); @@ -1482,21 +1588,6 @@ void ProjectList::slotCheckForEmptyQueue() } } -void ProjectList::reloadClipThumbnails() -{ - m_thumbnailQueue.clear(); - QTreeWidgetItemIterator it(m_listView); - while (*it) { - if ((*it)->type() != PROJECTCLIPTYPE) { - // subitem - ++it; - continue; - } - m_thumbnailQueue << ((ProjectItem *)(*it))->clipId(); - ++it; - } - QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail())); -} void ProjectList::requestClipThumbnail(const QString id) { @@ -1525,8 +1616,9 @@ void ProjectList::slotRefreshClipThumbnail(const QString &clipId, bool update) QTreeWidgetItem *item = getAnyItemById(clipId); if (item) slotRefreshClipThumbnail(item, update); - else + else { slotProcessNextThumbnail(); + } } void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) @@ -1559,7 +1651,7 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) else if (clip->clipType() == IMAGE) pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height)); else - pix = item->referencedClip()->thumbProducer()->extractImage(frame, width, height); + pix = item->referencedClip()->extractImage(frame, width, height); if (!pix.isNull()) { monitorItemEditing(false); @@ -1573,7 +1665,6 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) } if (update) emit projectModified(); - slotProcessNextThumbnail(); } } @@ -1582,76 +1673,88 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce { QString toReload; ProjectItem *item = getItemById(clipId); + if (!m_refreshed) { + // we are still finishing to load the document + selectClip = false; + } m_processingClips.removeAll(clipId); if (m_infoQueue.isEmpty() && m_processingClips.isEmpty()) m_listView->setEnabled(true); if (item && producer) { //m_listView->blockSignals(true); monitorItemEditing(false); + DocClipBase *clip = item->referencedClip(); item->setProperties(properties, metadata); - if (item->referencedClip()->isPlaceHolder() && producer->is_valid()) { - item->referencedClip()->setValid(); + if (clip->isPlaceHolder() && producer->is_valid()) { + clip->setValid(); 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"); - DocClipBase *clip = item->referencedClip(); - if (!useProxy() && item->referencedClip()->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY); - if (useProxy() && generateProxy() && item->referencedClip()->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY); - else if (useProxy() && !item->isProxyRunning() && (item->clipType() == AV || item->clipType() == VIDEO) && generateProxy() && size.section('x', 0, 0).toInt() > proxyMinSize()) { - if (clip->getProperty("proxy").isEmpty()) { - QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; - clip->setProperty("proxy", proxydir + item->referencedClip()->getClipHash() + ".avi"); + if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY); + if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY); + else if (useProxy() && !item->isProxyRunning()) { + // proxy video and image clips + int maxSize; + CLIPTYPE t = item->clipType(); + if (t == IMAGE) maxSize = m_doc->getDocumentProperty("proxyimageminsize").toInt(); + else maxSize = m_doc->getDocumentProperty("proxyminsize").toInt(); + 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 newProps; + // insert required duration for proxy + if (t != IMAGE) newProps.insert("proxy_out", clip->producerProperty("out")); + newProps.insert("proxy", proxyPath.path()); + QMap oldProps = clip->properties(); + oldProps.insert("proxy", QString()); + EditClipCommand *command = new EditClipCommand(this, clipId, oldProps, newProps, true); + m_doc->commandStack()->push(command); + } } } - - 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 (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_listView->setCurrentItem(item); + bool updatedProfile = false; + if (item->parent()) { + if (item->parent()->type() == PROJECTFOLDERTYPE) + static_cast (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) @@ -1713,6 +1816,11 @@ bool ProjectList::adjustProjectProfileToItem(ProjectItem *item) return profileUpdated; } +QString ProjectList::getDocumentProperty(const QString &key) const +{ + return m_doc->getDocumentProperty(key); +} + bool ProjectList::useProxy() const { return m_doc->getDocumentProperty("enableproxy").toInt(); @@ -1723,14 +1831,9 @@ bool ProjectList::generateProxy() const return m_doc->getDocumentProperty("generateproxy").toInt(); } -int ProjectList::proxyMinSize() const -{ - return m_doc->getDocumentProperty("proxyminsize").toInt(); -} - -QString ProjectList::proxyParams() const +bool ProjectList::generateImageProxy() const { - return m_doc->getDocumentProperty("proxyparams").simplified(); + return m_doc->getDocumentProperty("generateimageproxy").toInt(); } void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) @@ -1940,7 +2043,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); @@ -2070,73 +2173,190 @@ QMap ProjectList::getProxies() void ProjectList::slotCreateProxy(const QString id) { ProjectItem *item = getItemById(id); - if (!item || item->isProxyRunning()) return; - setProxyStatus(id, PROXYWAITING); - if (m_abortProxyId.contains(id)) m_abortProxyId.removeAll(id); - QtConcurrent::run(this, &ProjectList::slotGenerateProxy, id); + if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return; + QString path = item->referencedClip()->getProperty("proxy"); + if (path.isEmpty()) { + setProxyStatus(path, PROXYCRASHED); + return; + } + 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); + QtConcurrent::run(this, &ProjectList::slotGenerateProxy, path, item->clipUrl().path(), item->clipType(), QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt()); } -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) { - 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(const QString destPath, const QString sourcePath, int clipType, int exif_orientation) { - setProxyStatus(id, CREATINGPROXY); - ProjectItem *item = getItemById(id); - if (item == NULL) return; - QString path = item->referencedClip()->getProperty("proxy"); - if (path.isEmpty()) { - setProxyStatus(id, PROXYCRASHED); + emit projectModified(); + // Make sure proxy path is writable + QFile file(destPath); + if (!file.open(QIODevice::WriteOnly)) { + setProxyStatus(destPath, PROXYCRASHED); + m_processingProxy.removeAll(destPath); return; } - - QString url = item->clipUrl().path(); + file.close(); + QFile::remove(destPath); - if (QFile::exists(path)) { - setProxyStatus(id, PROXYDONE); - slotGotProxy(id); - return; + setProxyStatus(destPath, CREATINGPROXY); + + // Special case: playlist clips (.mlt or .kdenlive project files) + if (clipType == PLAYLIST) { + // change FFmpeg params to MLT format + QStringList parameters; + parameters << sourcePath; + parameters << "-consumer" << "avformat:" + destPath; + QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts); + + foreach(QString s, params) { + s = s.simplified(); + if (s.count(' ') == 0) { + s.append("=1"); + } + else s.replace(' ', '='); + parameters << s; + } + + parameters.append(QString("real_time=-%1").arg(KdenliveSettings::mltthreads())); + + //TODO: currently, when rendering an xml file through melt, the display ration is lost, so we enforce it manualy + double display_ratio = KdenliveDoc::getDisplayRatio(sourcePath); + parameters << "aspect=" + QString::number(display_ratio); + + //kDebug()<<"TRANSCOD: "< i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth()); + else proxy = i.scaledToHeight(m_render->renderHeight()); + if (exif_orientation > 1) { + // Rotate image according to exif data + QImage processed; + QMatrix matrix; + + switch ( exif_orientation ) { + case 2: + matrix.scale( -1, 1 ); + break; + case 3: + matrix.rotate( 180 ); + break; + case 4: + matrix.scale( 1, -1 ); + break; + case 5: + matrix.rotate( 270 ); + matrix.scale( -1, 1 ); + break; + case 6: + matrix.rotate( 90 ); + break; + case 7: + matrix.rotate( 90 ); + matrix.scale( -1, 1 ); + break; + case 8: + matrix.rotate( 270 ); + break; + } + processed = proxy.transformed( matrix ); + processed.save(destPath); + } + else proxy.save(destPath); + setProxyStatus(destPath, PROXYDONE); + slotGotProxy(destPath); + m_abortProxy.removeAll(destPath); + m_processingProxy.removeAll(destPath); + return; } QStringList parameters; - parameters << "-i" << url; - QString params = proxyParams(); + parameters << "-i" << sourcePath; + 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 << destPath; + kDebug()<<"// STARTING PROXY GEN: "<setText(i18n("Update proxy settings")); + QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; while (*it) { if ((*it)->type() != PROJECTCLIPTYPE) { ++it; @@ -2174,25 +2399,56 @@ void ProjectList::updateProxyConfig() if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip() != NULL) { if (generateProxy() && useProxy() && !item->isProxyRunning()) { DocClipBase *clip = item->referencedClip(); - if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > proxyMinSize()) { + 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 oldProps;// = clip->properties(); + oldProps.insert("proxy", QString()); + QMap newProps; + newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension")); + new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command); + } + } + } + else if (item->hasProxy()) { + // remove proxy + QMap newProps; + newProps.insert("proxy", QString()); + newProps.insert("replace", "1"); + // insert required duration for proxy + newProps.insert("proxy_out", item->referencedClip()->producerProperty("out")); + new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command); + } + } + else if (t == IMAGE && item->referencedClip() != NULL) { + if (generateImageProxy() && useProxy()) { + DocClipBase *clip = item->referencedClip(); + int maxImageSize = m_doc->getDocumentProperty("proxyimageminsize").toInt(); + if (clip->getProperty("frame_size").section('x', 0, 0).toInt() > maxImageSize || clip->getProperty("frame_size").section('x', 1, 1).toInt() > maxImageSize) { if (clip->getProperty("proxy").isEmpty()) { - QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; - clip->setProperty("proxy", proxydir + item->referencedClip()->getClipHash() + ".avi"); + // We need to insert empty proxy in old properties so that undo will work + QMap oldProps = clip->properties(); + oldProps.insert("proxy", QString()); + QMap newProps; + newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + ".png"); + new EditClipCommand(this, clip->getId(), oldProps, newProps, true, command); } } } else if (item->hasProxy()) { // remove proxy - item->referencedClip()->clearProperty("proxy"); - QDomElement e = item->toXml().cloneNode().toElement(); - e.removeAttribute("file_hash"); - e.setAttribute("replace", 1); - m_infoQueue.insert(item->clipId(), e); + QMap newProps; + newProps.insert("proxy", QString()); + newProps.insert("replace", "1"); + new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command); } } ++it; } - if (!m_infoQueue.isEmpty() && !m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); + 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); + QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); } void ProjectList::slotProxyCurrentItem(bool doProxy) @@ -2200,13 +2456,15 @@ void ProjectList::slotProxyCurrentItem(bool doProxy) QList list = m_listView->selectedItems(); QTreeWidgetItem *listItem; QUndoCommand *command = new QUndoCommand(); - command->setText(i18np("Edit clip", "Edit clips", list.count())); + if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", list.count())); + else command->setText(i18np("Remove proxy clip", "Remove proxy clips", list.count())); // Make sure the proxy folder exists QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; KStandardDirs::makeDir(proxydir); QMap newProps; + QMap oldProps; if (!doProxy) newProps.insert("proxy", "-"); for (int i = 0; i < list.count(); i++) { listItem = list.at(i); @@ -2219,24 +2477,70 @@ void ProjectList::slotProxyCurrentItem(bool doProxy) if (listItem->type() == PROJECTCLIPTYPE) { ProjectItem *item = static_cast (listItem); CLIPTYPE t = item->clipType(); - if ((t == VIDEO || t == AV || t == UNKNOWN) && item->referencedClip()) { + if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) { + oldProps = item->referencedClip()->properties(); if (doProxy) { newProps.clear(); - QString path = proxydir + item->referencedClip()->getClipHash() + ".avi"; + QString path = proxydir + item->referencedClip()->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")); + // 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()); } - new EditClipCommand(this, item->clipId(), item->referencedClip()->properties(), newProps, true, command); + new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command); } } } - m_doc->commandStack()->push(command); + 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()) 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 (*it); + if (item->referencedClip()->getProperty("proxy") == proxyPath) { + QMap 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()) return; + QTreeWidgetItemIterator it(m_listView); + ProjectItem *item; + while (*it) { + if ((*it)->type() == PROJECTCLIPTYPE) { + item = static_cast (*it); + if (item->referencedClip()->getProperty("proxy") == proxyPath) { + setProxyStatus(item, status); + } + } + ++it; + } } void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status) @@ -2253,4 +2557,23 @@ void ProjectList::monitorItemEditing(bool enable) else disconnect(m_listView, SIGNAL(itemChanged(QTreeWidgetItem *, int)), this, SLOT(slotItemEdited(QTreeWidgetItem *, int))); } +QStringList ProjectList::expandedFolders() const +{ + QStringList result; + FolderProjectItem *item; + QTreeWidgetItemIterator it(m_listView); + while (*it) { + if ((*it)->type() != PROJECTFOLDERTYPE) { + ++it; + continue; + } + if ((*it)->isExpanded()) { + item = static_cast(*it); + result.append(item->clipId()); + } + ++it; + } + return result; +} + #include "projectlist.moc"