X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlist.cpp;h=2109bfa921b2ed6befda0046b4df37a1c9f22e5c;hb=c45bc0a73244411dbc8c6fc486f66e88f152462c;hp=8bb2d2bf658b469e221574cd84a0f63ca9cc22dd;hpb=8d37be5eb4693a75a8354fa91613f3fcd9adab4b;p=kdenlive diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 8bb2d2bf..2109bfa9 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -77,8 +77,8 @@ ProjectList::ProjectList(QWidget *parent) : m_transcodeAction(NULL), m_doc(NULL), m_refreshed(false), - m_infoQueue(), - m_thumbnailQueue() + m_thumbnailQueue(), + m_abortAllProxies(false) { QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); @@ -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())); @@ -145,6 +141,8 @@ ProjectList::ProjectList(QWidget *parent) : ProjectList::~ProjectList() { + m_abortAllProxies = true; + m_thumbnailQueue.clear(); delete m_menu; m_listView->blockSignals(true); m_listView->clear(); @@ -176,6 +174,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--; } } @@ -473,7 +475,7 @@ void ProjectList::slotReloadClip(const QString &id) e.setAttribute("length", length); } } - emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true, false); + emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true); } } } @@ -574,7 +576,6 @@ void ProjectList::setRenderer(Render *projectRender) void ProjectList::slotClipSelected() { - if (!m_listView->isEnabled()) return; if (m_listView->currentItem()) { if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) { emit clipSelected(NULL); @@ -906,11 +907,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) { @@ -993,7 +997,7 @@ void ProjectList::deleteProjectFolder(QMap map) void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) { - m_listView->setEnabled(false); + //m_listView->setEnabled(false); const QString parent = clip->getProperty("groupid"); ProjectItem *item = NULL; monitorItemEditing(false); @@ -1015,13 +1019,20 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) item = new ProjectItem(m_listView, clip); } 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, const QString)), this, SLOT(slotAbortProxy(const QString, const QString))); + QString proxy = clip->getProperty("proxy"); + if (!proxy.isEmpty() && proxy != "-") slotCreateProxy(clip->getId()); + connect(clip, SIGNAL(createProxy(const QString &)), this, SLOT(slotCreateProxy(const QString &))); + connect(clip, SIGNAL(abortProxy(const QString &, const QString &)), this, SLOT(slotAbortProxy(const QString, const QString))); if (getProperties) { + int height = m_listView->iconSize().height(); + int width = (int)(height * m_render->dar()); + QPixmap pix = KIcon("video-x-generic").pixmap(QSize(width, height)); + item->setData(0, Qt::DecorationRole, pix); + //item->setFlags(Qt::ItemIsSelectable); m_listView->processLayout(); QDomElement e = clip->toXML().cloneNode().toElement(); e.removeAttribute("file_hash"); - m_infoQueue.insert(clip->getId(), e); + emit getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); } else if (item->hasProxy() && !item->isProxyRunning()) { slotCreateProxy(clip->getId()); @@ -1029,15 +1040,6 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) clip->askForAudioThumbs(); KUrl url = clip->fileURL(); - if (getProperties == false && !clip->getClipHash().isEmpty()) { - QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png"; - if (QFile::exists(cachedPixmap)) { - QPixmap pix(cachedPixmap); - if (pix.isNull()) - KIO::NetAccess::del(KUrl(cachedPixmap), this); - item->setData(0, Qt::DecorationRole, pix); - } - } #ifdef NEPOMUK if (!url.isEmpty() && KdenliveSettings::activate_nepomuk()) { // if file has Nepomuk comment, use it @@ -1064,17 +1066,12 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) } } monitorItemEditing(true); - if (m_listView->isEnabled()) { - updateButtons(); - } - - if (getProperties && m_processingClips.isEmpty()) - m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); + updateButtons(); } void ProjectList::slotGotProxy(const QString &proxyPath) { - if (proxyPath.isEmpty()) return; + if (proxyPath.isEmpty() || !m_refreshed || m_abortAllProxies) return; QTreeWidgetItemIterator it(m_listView); ProjectItem *item; @@ -1090,7 +1087,7 @@ void ProjectList::slotGotProxy(const QString &proxyPath) void ProjectList::slotGotProxy(ProjectItem *item) { - if (item == NULL) return; + if (item == NULL || !m_refreshed) return; DocClipBase *clip = item->referencedClip(); // Proxy clip successfully created QDomElement e = clip->toXML().cloneNode().toElement(); @@ -1103,50 +1100,19 @@ void ProjectList::slotGotProxy(ProjectItem *item) e.setAttribute("length", length); } } - e.setAttribute("replace", 1); - m_infoQueue.insert(clip->getId(), e); - if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); + emit getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); } void ProjectList::slotResetProjectList() { + m_abortAllProxies = true; + m_proxyThreads.waitForFinished(); + m_proxyThreads.clearFutures(); + m_thumbnailQueue.clear(); m_listView->clear(); emit clipSelected(NULL); - m_thumbnailQueue.clear(); - m_infoQueue.clear(); m_refreshed = false; -} - -void ProjectList::requestClipInfo(const QDomElement xml, const QString id) -{ - 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; - } - - QMap::const_iterator j = m_infoQueue.constBegin(); - if (j != m_infoQueue.constEnd()) { - QDomElement dom = j.value(); - const QString id = j.key(); - m_infoQueue.remove(id); - m_processingClips.append(id); - bool replace; - if (dom.hasAttribute("replace")) { - // Proxy action was enabled / disabled and we want to replace current producer - dom.removeAttribute("replace"); - replace = true; - } - else replace = false; - bool selectClip = !replace; - if (m_infoQueue.count() > 1) selectClip = false; - emit getFileProperties(dom, id, m_listView->iconSize().height(), replace, selectClip); - } + m_abortAllProxies = false; } void ProjectList::slotUpdateClip(const QString &id) @@ -1157,6 +1123,23 @@ void ProjectList::slotUpdateClip(const QString &id) monitorItemEditing(true); } +void ProjectList::getCachedThumbnail(ProjectItem *item) +{ + if (!item) return; + DocClipBase *clip = item->referencedClip(); + if (!clip) return; + QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + ".png"; + if (QFile::exists(cachedPixmap)) { + QPixmap pix(cachedPixmap); + if (pix.isNull()) { + KIO::NetAccess::del(KUrl(cachedPixmap), this); + requestClipThumbnail(item->clipId()); + } + else item->setData(0, Qt::DecorationRole, pix); + } + else requestClipThumbnail(item->clipId()); +} + void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) { m_listView->setSortingEnabled(false); @@ -1173,7 +1156,7 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) 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 @@ -1199,7 +1182,7 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) xml.removeAttribute("file_hash"); xml.removeAttribute("proxy_out"); } - requestClipInfo(xml, clip->getId()); + emit getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), xml.attribute("replace") == "1"); } else { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); @@ -1214,9 +1197,12 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) item->setData(0, Qt::DecorationRole, pixmap); } } - } else { - if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull()) + } else { + if (displayRatioChanged) requestClipThumbnail(clip->getId()); + else if (item->data(0, Qt::DecorationRole).isNull()) { + getCachedThumbnail(item); + } if (item->data(0, DurationRole).toString().isEmpty()) { item->changeDuration(item->referencedClip()->producer()->get_playtime()); } @@ -1237,11 +1223,9 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) ++it; } - if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); - if (m_listView->isEnabled()) - monitorItemEditing(true); m_listView->setSortingEnabled(true); - if (m_infoQueue.isEmpty()) { + if (m_render->processingItems() == 0) { + monitorItemEditing(true); slotProcessNextThumbnail(); } } @@ -1352,8 +1336,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 (item) { + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); const QString path = item->referencedClip()->fileURL().path(); if (item->referencedClip()->isPlaceHolder()) replace = false; if (!path.isEmpty()) { @@ -1371,6 +1356,7 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError) { ProjectItem *item = getItemById(id); if (item) { + item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); if (durationError) { kDebug() << "Proxy duration is wrong, try changing transcoding parameters."; emit displayMessage(i18n("Proxy clip unusable (duration is different from original)."), -2); @@ -1385,7 +1371,7 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError) } } m_processingClips.removeAll(id); - if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); + m_thumbnailQueue.removeAll(id); } void ProjectList::slotAddColorClip() @@ -1494,17 +1480,21 @@ QStringList ProjectList::getGroup() const void ProjectList::setDocument(KdenliveDoc *doc) { m_listView->blockSignals(true); + m_abortAllProxies = true; + m_proxyThreads.waitForFinished(); + m_proxyThreads.clearFutures(); + m_thumbnailQueue.clear(); m_listView->clear(); m_processingClips.clear(); + m_listView->setSortingEnabled(false); emit clipSelected(NULL); - m_thumbnailQueue.clear(); - m_infoQueue.clear(); m_refreshed = false; m_fps = doc->fps(); m_timecode = doc->timecode(); m_commandStack = doc->commandStack(); m_doc = doc; + m_abortAllProxies = false; QMap flist = doc->clipManager()->documentFolderList(); QStringList openedFolders = doc->getExpandedFolders(); @@ -1516,6 +1506,7 @@ void ProjectList::setDocument(KdenliveDoc *doc) } QList list = doc->clipManager()->documentClipList(); + if (list.isEmpty()) m_refreshed = true; for (int i = 0; i < list.count(); i++) slotAddClip(list.at(i), false); @@ -1556,12 +1547,12 @@ QDomElement ProjectList::producersList() void ProjectList::slotCheckForEmptyQueue() { - if (!m_refreshed && m_processingClips.isEmpty() && m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) { - m_refreshed = true; - emit loadingIsOver(); - emit displayMessage(QString(), -1); - m_listView->blockSignals(false); - m_listView->setEnabled(true); + if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) { + if (!m_refreshed) { + emit loadingIsOver(); + emit displayMessage(QString(), -1); + m_refreshed = true; + } updateButtons(); } else if (!m_refreshed) { QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue())); @@ -1572,22 +1563,20 @@ void ProjectList::slotCheckForEmptyQueue() void ProjectList::requestClipThumbnail(const QString id) { if (!m_thumbnailQueue.contains(id)) m_thumbnailQueue.append(id); + slotProcessNextThumbnail(); } void ProjectList::slotProcessNextThumbnail() { - if (m_thumbnailQueue.isEmpty() && m_infoQueue.isEmpty()) { - slotCheckForEmptyQueue(); + if (m_render->processingItems() > 0) { return; } - if (!m_infoQueue.isEmpty()) { - //QTimer::singleShot(300, this, SLOT(slotProcessNextThumbnail())); + if (m_thumbnailQueue.isEmpty()) { + slotCheckForEmptyQueue(); return; } - if (m_thumbnailQueue.count() > 1) { - int max = m_doc->clipManager()->clipsCount(); - emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max)); - } + int max = m_doc->clipManager()->clipsCount(); + emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - m_thumbnailQueue.count()) / max)); slotRefreshClipThumbnail(m_thumbnailQueue.takeFirst(), false); } @@ -1625,13 +1614,14 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) } QPixmap pix; int height = m_listView->iconSize().height(); - int width = (int)(height * m_render->dar()); + int swidth = (int)(height * m_render->frameRenderWidth() / m_render->renderHeight()+ 0.5); + int dwidth = (int)(height * m_render->dar() + 0.5); if (clip->clipType() == AUDIO) - pix = KIcon("audio-x-generic").pixmap(QSize(width, height)); + pix = KIcon("audio-x-generic").pixmap(QSize(dwidth, height)); else if (clip->clipType() == IMAGE) - pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, width, height)); + pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, swidth, dwidth, height)); else - pix = item->referencedClip()->extractImage(frame, width, height); + pix = item->referencedClip()->extractImage(frame, dwidth, height); if (!pix.isNull()) { monitorItemEditing(false); @@ -1649,27 +1639,29 @@ 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, bool selectClip) +void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail) { 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); + int queue = m_render->processingItems(); + if (queue == 0) { + m_listView->setEnabled(true); + } if (item && producer) { - //m_listView->blockSignals(true); monitorItemEditing(false); DocClipBase *clip = item->referencedClip(); item->setProperties(properties, metadata); - if (clip->isPlaceHolder() && producer->is_valid()) { - clip->setValid(); + if (producer->is_valid()) { + if (clip->isPlaceHolder()) { + clip->setValid(); + toReload = clipId; + } item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); - toReload = clipId; } + clip->setProducer(producer, replace); + clip->askForAudioThumbs(); + if (refreshThumbnail) getCachedThumbnail(item); // Proxy stuff QString size = properties.value("frame_size"); if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY); @@ -1696,19 +1688,16 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce } } } - clip->setProducer(producer, replace); - clip->askForAudioThumbs(); - if (!replace && item->data(0, Qt::DecorationRole).isNull()) + if (!replace && item->data(0, Qt::DecorationRole).isNull() && !refreshThumbnail) { requestClipThumbnail(clipId); + } if (!toReload.isEmpty()) item->slotSetToolTip(); - - if (m_listView->isEnabled()) - monitorItemEditing(true); } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS..."; - if (selectClip && m_infoQueue.isEmpty()) { - if (item && m_infoQueue.isEmpty() && m_thumbnailQueue.isEmpty()) { + if (queue == 0) { + monitorItemEditing(true); + if (item && m_thumbnailQueue.isEmpty()) { m_listView->setCurrentItem(item); bool updatedProfile = false; if (item->parent()) { @@ -1718,22 +1707,28 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce // 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()); + 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)); + emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max)); } + processNextThumbnail(); } - if (item && m_listView->isEnabled() && replace) { - // update clip in clip monitor + if (item && queue == 0 && 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; - } + //TODO: Make sure the line below has no side effect + toReload = clipId; + } + if (!item) { + // no item for producer, delete it + delete producer; + } if (!toReload.isEmpty()) emit clipNeedsReload(toReload, true); - - if (!m_queueRunner.isRunning() && m_processingClips.isEmpty()) m_queueRunner = QtConcurrent::run(this, &ProjectList::slotProcessNextClipInQueue); } bool ProjectList::adjustProjectProfileToItem(ProjectItem *item) @@ -1815,16 +1810,27 @@ bool ProjectList::generateImageProxy() const return m_doc->getDocumentProperty("generateimageproxy").toInt(); } -void ProjectList::slotReplyGetImage(const QString &clipId, const QPixmap &pix) +void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img) +{ + QPixmap pix = QPixmap::fromImage(img); + setThumbnail(clipId, pix); +} + +void ProjectList::slotReplyGetImage(const QString &clipId, const QString &name, int width, int height) +{ + QPixmap pix = KIcon(name).pixmap(QSize(width, height)); + setThumbnail(clipId, pix); +} + +void ProjectList::setThumbnail(const QString &clipId, const QPixmap &pix) { ProjectItem *item = getItemById(clipId); if (item && !pix.isNull()) { monitorItemEditing(false); item->setData(0, Qt::DecorationRole, pix); monitorItemEditing(true); + //update(); m_doc->cachePixmap(item->getClipHash(), pix); - if (m_listView->isEnabled()) - m_listView->blockSignals(false); } } @@ -2091,9 +2097,7 @@ void ProjectList::doUpdateClipCut(const QString &id, const QPoint oldzone, const void ProjectList::slotForceProcessing(const QString &id) { - while (m_infoQueue.contains(id)) { - slotProcessNextClipInQueue(); - } + m_render->forceProcessing(id); } void ProjectList::slotAddOrUpdateSequence(const QString frameName) @@ -2171,7 +2175,14 @@ void ProjectList::slotCreateProxy(const QString id) return; } m_processingProxy.append(path); - QtConcurrent::run(this, &ProjectList::slotGenerateProxy, path, item->clipUrl().path(), item->clipType(), QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt()); + + PROXYINFO info; + info.dest = path; + info.src = item->clipUrl().path(); + info.type = item->clipType(); + info.exif = QString(item->referencedClip()->producerProperty("_exif_orientation")).toInt(); + m_proxyList.append(info); + m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy)); } void ProjectList::slotAbortProxy(const QString id, const QString path) @@ -2186,26 +2197,34 @@ void ProjectList::slotAbortProxy(const QString id, const QString path) } } -void ProjectList::slotGenerateProxy(const QString destPath, const QString sourcePath, int clipType, int exif_orientation) +void ProjectList::slotGenerateProxy() { + if (m_proxyList.isEmpty() || m_abortAllProxies) return; emit projectModified(); + PROXYINFO info = m_proxyList.takeFirst(); + if (m_abortProxy.contains(info.dest)) { + m_abortProxy.removeAll(info.dest); + return; + } + // Make sure proxy path is writable - QFile file(destPath); - if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { - setProxyStatus(destPath, PROXYCRASHED); + QFile file(info.dest); + if (!file.open(QIODevice::WriteOnly)) { + setProxyStatus(info.dest, PROXYCRASHED); + m_processingProxy.removeAll(info.dest); return; } file.close(); - QFile::remove(destPath); + QFile::remove(info.dest); - setProxyStatus(destPath, CREATINGPROXY); + setProxyStatus(info.dest, CREATINGPROXY); // Special case: playlist clips (.mlt or .kdenlive project files) - if (clipType == PLAYLIST) { + if (info.type == PLAYLIST) { // change FFmpeg params to MLT format QStringList parameters; - parameters << sourcePath; - parameters << "-consumer" << "avformat:" + destPath; + parameters << info.src; + parameters << "-consumer" << "avformat:" + info.dest; QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts); foreach(QString s, params) { @@ -2220,50 +2239,55 @@ void ProjectList::slotGenerateProxy(const QString destPath, const QString source 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); + double display_ratio = KdenliveDoc::getDisplayRatio(info.src); 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) { + if (info.exif > 1) { // Rotate image according to exif data QImage processed; QMatrix matrix; - switch ( exif_orientation ) { + switch ( info.exif ) { case 2: matrix.scale( -1, 1 ); break; @@ -2302,58 +2326,86 @@ void ProjectList::slotGenerateProxy(const QString destPath, const QString source break; } processed = proxy.transformed( matrix ); - processed.save(destPath); + processed.save(info.dest); } - else proxy.save(destPath); - setProxyStatus(destPath, PROXYDONE); - slotGotProxy(destPath); - m_abortProxy.removeAll(destPath); - m_processingProxy.removeAll(destPath); + else proxy.save(info.dest); + setProxyStatus(info.dest, PROXYDONE); + slotGotProxy(info.dest); + m_abortProxy.removeAll(info.dest); + m_processingProxy.removeAll(info.dest); return; } QStringList parameters; - parameters << "-i" << sourcePath; + parameters << "-i" << info.src; 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 << destPath; + parameters << info.dest; kDebug()<<"// STARTING PROXY GEN: "< 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(); + QMap oldProps;// = clip->properties(); oldProps.insert("proxy", QString()); QMap newProps; newProps.insert("proxy", proxydir + item->referencedClip()->getClipHash() + "." + m_doc->getDocumentProperty("proxyextension")); @@ -2425,7 +2477,6 @@ void ProjectList::updateProxyConfig() } 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); } void ProjectList::slotProxyCurrentItem(bool doProxy) @@ -2473,7 +2524,6 @@ void ProjectList::slotProxyCurrentItem(bool doProxy) 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); } @@ -2503,27 +2553,27 @@ void ProjectList::slotDeleteProxy(const QString proxyPath) QFile::remove(proxyPath); } -void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status) +void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress) { - if (proxyPath.isEmpty()) return; + if (proxyPath.isEmpty() || m_abortAllProxies) 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); + setProxyStatus(item, status, progress); } } ++it; } } -void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status) +void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress) { if (item == NULL) return; monitorItemEditing(false); - item->setProxyStatus(status); + item->setProxyStatus(status, progress); monitorItemEditing(true); }