X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fprojectlist.cpp;h=cddd5d5bec1f1097c70aed23bcddd80f554ec215;hb=f68bd080a6d251d0d9ffaf03450d5142dfe5515d;hp=5d8d0d9a712c6649e33df7a903e4cdfda8863a21;hpb=f1c0cd6a5390c3cc4ffe6f08974bfed9513e6045;p=kdenlive diff --git a/src/projectlist.cpp b/src/projectlist.cpp index 5d8d0d9a..cddd5d5b 100644 --- a/src/projectlist.cpp +++ b/src/projectlist.cpp @@ -19,7 +19,7 @@ #include "projectlist.h" #include "projectitem.h" -#include "addfoldercommand.h" +#include "commands/addfoldercommand.h" #include "kdenlivesettings.h" #include "slideshowclip.h" #include "ui_colorclip_ui.h" @@ -33,10 +33,10 @@ #include "projectlistview.h" #include "timecodedisplay.h" #include "profilesdialog.h" -#include "editclipcommand.h" -#include "editclipcutcommand.h" -#include "editfoldercommand.h" -#include "addclipcutcommand.h" +#include "commands/editclipcommand.h" +#include "commands/editclipcutcommand.h" +#include "commands/editfoldercommand.h" +#include "commands/addclipcutcommand.h" #include "ui_templateclip_ui.h" @@ -66,6 +66,44 @@ #include #include #include +#include + +InvalidDialog::InvalidDialog(const QString &caption, const QString &message, bool infoOnly, QWidget *parent) : KDialog(parent) +{ + setCaption(caption); + if (infoOnly) setButtons(KDialog::Ok); + else setButtons(KDialog::Yes | KDialog::No); + QWidget *w = new QWidget(this); + QVBoxLayout *l = new QVBoxLayout; + l->addWidget(new QLabel(message)); + m_clipList = new QListWidget; + l->addWidget(m_clipList); + w->setLayout(l); + setMainWidget(w); +} + +InvalidDialog::~InvalidDialog() +{ + delete m_clipList; +} + + +void InvalidDialog::addClip(const QString &id, const QString &path) +{ + QListWidgetItem *item = new QListWidgetItem(path); + item->setData(Qt::UserRole, id); + m_clipList->addItem(item); +} + +QStringList InvalidDialog::getIds() const +{ + QStringList ids; + for (int i = 0; i < m_clipList->count(); i++) { + ids << m_clipList->item(i)->data(Qt::UserRole).toString(); + } + return ids; +} + ProjectList::ProjectList(QWidget *parent) : QWidget(parent), @@ -74,11 +112,14 @@ ProjectList::ProjectList(QWidget *parent) : m_commandStack(NULL), m_openAction(NULL), m_reloadAction(NULL), + m_stabilizeAction(NULL), m_transcodeAction(NULL), m_doc(NULL), m_refreshed(false), + m_allClipsProcessed(false), m_thumbnailQueue(), - m_abortAllProxies(false) + m_abortAllProxies(false), + m_invalidClipDialog(NULL) { QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); @@ -117,7 +158,7 @@ ProjectList::ProjectList(QWidget *parent) : connect(this, SIGNAL(processNextThumbnail()), this, SLOT(slotProcessNextThumbnail())); connect(m_listView, SIGNAL(projectModified()), this, SIGNAL(projectModified())); connect(m_listView, SIGNAL(itemSelectionChanged()), this, SLOT(slotClipSelected())); - connect(m_listView, SIGNAL(focusMonitor()), this, SLOT(slotClipSelected())); + connect(m_listView, SIGNAL(focusMonitor()), this, SIGNAL(raiseClipMonitor())); connect(m_listView, SIGNAL(pauseMonitor()), this, SLOT(slotPauseMonitor())); connect(m_listView, SIGNAL(requestMenu(const QPoint &, QTreeWidgetItem *)), this, SLOT(slotContextMenu(const QPoint &, QTreeWidgetItem *))); connect(m_listView, SIGNAL(addClip()), this, SLOT(slotAddClip())); @@ -189,31 +230,52 @@ void ProjectList::setupMenu(QMenu *addMenu, QAction *defaultAction) m_menu->addActions(addMenu->actions()); } -void ProjectList::setupGeneratorMenu(QMenu *addMenu, QMenu *transcodeMenu, QMenu *inTimelineMenu) +void ProjectList::setupGeneratorMenu(const QHash& menus) { - if (!addMenu) + if (!menus.contains("addMenu") && ! menus.value("addMenu") ) return; QMenu *menu = m_addButton->menu(); - menu->addMenu(addMenu); - m_addButton->setMenu(menu); - - m_menu->addMenu(addMenu); - if (addMenu->isEmpty()) - addMenu->setEnabled(false); - m_menu->addMenu(transcodeMenu); - if (transcodeMenu->isEmpty()) - transcodeMenu->setEnabled(false); - m_transcodeAction = transcodeMenu; + if (menus.contains("addMenu") && menus.value("addMenu")){ + QMenu* addMenu=menus.value("addMenu"); + menu->addMenu(addMenu); + m_addButton->setMenu(menu); + + m_menu->addMenu(addMenu); + if (addMenu->isEmpty()) + addMenu->setEnabled(false); + } + if (menus.contains("transcodeMenu") && menus.value("transcodeMenu") ){ + QMenu* transcodeMenu=menus.value("transcodeMenu"); + m_menu->addMenu(transcodeMenu); + if (transcodeMenu->isEmpty()) + transcodeMenu->setEnabled(false); + m_transcodeAction = transcodeMenu; + } + if (menus.contains("stabilizeMenu") && menus.value("stabilizeMenu") ){ + QMenu* stabilizeMenu=menus.value("stabilizeMenu"); + m_menu->addMenu(stabilizeMenu); + if (stabilizeMenu->isEmpty()) + stabilizeMenu->setEnabled(false); + m_stabilizeAction=stabilizeMenu; + + } m_menu->addAction(m_reloadAction); m_menu->addAction(m_proxyAction); - m_menu->addMenu(inTimelineMenu); - inTimelineMenu->setEnabled(false); + if (menus.contains("inTimelineMenu") && menus.value("inTimelineMenu")){ + QMenu* inTimelineMenu=menus.value("inTimelineMenu"); + m_menu->addMenu(inTimelineMenu); + inTimelineMenu->setEnabled(false); + } m_menu->addAction(m_editButton->defaultAction()); m_menu->addAction(m_openAction); m_menu->addAction(m_deleteButton->defaultAction()); m_menu->insertSeparator(m_deleteButton->defaultAction()); } +void ProjectList::clearSelection() +{ + m_listView->clearSelection(); +} QByteArray ProjectList::headerInfo() const { @@ -455,27 +517,33 @@ void ProjectList::slotReloadClip(const QString &id) continue; } item = static_cast (selected.at(i)); - if (item) { + if (item && !item->isProxyRunning()) { + DocClipBase *clip = item->referencedClip(); + if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) { + kDebug()<<"//// TRYING TO RELOAD: "<clipId()<<", but it is busy"; + continue; + } CLIPTYPE t = item->clipType(); if (t == TEXT) { - if (!item->referencedClip()->getProperty("xmltemplate").isEmpty()) + if (clip && !clip->getProperty("xmltemplate").isEmpty()) regenerateTemplate(item); - } else if (t != COLOR && t != SLIDESHOW && item->referencedClip() && item->referencedClip()->checkHash() == false) { + } else if (t != COLOR && t != SLIDESHOW && clip && clip->checkHash() == false) { item->referencedClip()->setPlaceHolder(true); item->setProperty("file_hash", QString()); } else if (t == IMAGE) { - item->referencedClip()->producer()->set("force_reload", 1); + clip->getProducer()->set("force_reload", 1); } QDomElement e = item->toXml(); // Make sure we get the correct producer length if it was adjusted in timeline if (t == COLOR || t == IMAGE || t == SLIDESHOW || t == TEXT) { - int length = QString(item->referencedClip()->producerProperty("length")).toInt(); + int length = QString(clip->producerProperty("length")).toInt(); if (length > 0 && !e.hasAttribute("length")) { e.setAttribute("length", length); } - } - emit getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true); + } + resetThumbsProducer(clip); + m_render->getFileProperties(e, item->clipId(), m_listView->iconSize().height(), true); } } } @@ -521,14 +589,14 @@ void ProjectList::slotMissingClip(const QString &id) return; } Mlt::Producer *newProd = m_render->invalidProducer(id); - if (item->referencedClip()->producer()) { + if (item->referencedClip()->getProducer()) { Mlt::Properties props(newProd->get_properties()); - Mlt::Properties src_props(item->referencedClip()->producer()->get_properties()); + Mlt::Properties src_props(item->referencedClip()->getProducer()->get_properties()); props.inherit(src_props); } item->referencedClip()->setProducer(newProd, true); item->slotSetToolTip(); - emit clipNeedsReload(id, true); + emit clipNeedsReload(id); } } update(); @@ -576,35 +644,39 @@ void ProjectList::setRenderer(Render *projectRender) void ProjectList::slotClipSelected() { - if (!m_listView->isEnabled()) return; - if (m_listView->currentItem()) { - if (m_listView->currentItem()->type() == PROJECTFOLDERTYPE) { + QTreeWidgetItem *item = m_listView->currentItem(); + ProjectItem *clip = NULL; + if (item) { + if (item->type() == PROJECTFOLDERTYPE) { emit clipSelected(NULL); - m_editButton->defaultAction()->setEnabled(m_listView->currentItem()->childCount() > 0); + m_editButton->defaultAction()->setEnabled(item->childCount() > 0); m_deleteButton->defaultAction()->setEnabled(true); m_openAction->setEnabled(false); m_reloadAction->setEnabled(false); m_transcodeAction->setEnabled(false); - m_proxyAction->setEnabled(false); + m_stabilizeAction->setEnabled(false); } else { - ProjectItem *clip; - if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { + if (item->type() == PROJECTSUBCLIPTYPE) { // this is a sub item, use base clip m_deleteButton->defaultAction()->setEnabled(true); - clip = static_cast (m_listView->currentItem()->parent()); + clip = static_cast (item->parent()); if (clip == NULL) kDebug() << "-----------ERROR"; - SubProjectItem *sub = static_cast (m_listView->currentItem()); + SubProjectItem *sub = static_cast (item); emit clipSelected(clip->referencedClip(), sub->zone()); m_transcodeAction->setEnabled(false); + m_stabilizeAction->setEnabled(false); + m_reloadAction->setEnabled(false); + adjustProxyActions(clip); return; } - clip = static_cast (m_listView->currentItem()); + clip = static_cast (item); if (clip && clip->referencedClip()) emit clipSelected(clip->referencedClip()); m_editButton->defaultAction()->setEnabled(true); m_deleteButton->defaultAction()->setEnabled(true); m_reloadAction->setEnabled(true); m_transcodeAction->setEnabled(true); + m_stabilizeAction->setEnabled(true); if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); @@ -616,6 +688,7 @@ void ProjectList::slotClipSelected() } // Display relevant transcoding actions only adjustTranscodeActions(clip); + adjustStabilizeActions(clip); // Display uses in timeline emit findInTimeline(clip->clipId()); } @@ -626,7 +699,9 @@ void ProjectList::slotClipSelected() m_openAction->setEnabled(false); m_reloadAction->setEnabled(false); m_transcodeAction->setEnabled(false); + m_stabilizeAction->setEnabled(false); } + adjustProxyActions(clip); } void ProjectList::adjustProxyActions(ProjectItem *clip) const @@ -641,6 +716,17 @@ void ProjectList::adjustProxyActions(ProjectItem *clip) const m_proxyAction->blockSignals(false); } +void ProjectList::adjustStabilizeActions(ProjectItem *clip) const +{ + + if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) { + m_stabilizeAction->setEnabled(false); + return; + } + m_stabilizeAction->setEnabled(true); + +} + void ProjectList::adjustTranscodeActions(ProjectItem *clip) const { if (clip == NULL || clip->type() != PROJECTCLIPTYPE || clip->clipType() == COLOR || clip->clipType() == TEXT || clip->clipType() == PLAYLIST || clip->clipType() == SLIDESHOW) { @@ -684,6 +770,7 @@ void ProjectList::slotUpdateClipProperties(const QString &id, QMap referencedClip(), item->referencedClip()->zone(), true); } else if (properties.contains("full_luma") || properties.contains("force_colorspace") || properties.contains("loop")) { emit refreshClip(id, false); } @@ -788,20 +875,25 @@ void ProjectList::slotContextMenu(const QPoint &pos, QTreeWidgetItem *item) m_deleteButton->defaultAction()->setEnabled(enable); m_reloadAction->setEnabled(enable); m_transcodeAction->setEnabled(enable); + m_stabilizeAction->setEnabled(enable); if (enable) { ProjectItem *clip = NULL; if (m_listView->currentItem()->type() == PROJECTSUBCLIPTYPE) { clip = static_cast (item->parent()); m_transcodeAction->setEnabled(false); + m_stabilizeAction->setEnabled(false); + adjustProxyActions(clip); } else if (m_listView->currentItem()->type() == PROJECTCLIPTYPE) { clip = static_cast (item); // Display relevant transcoding actions only adjustTranscodeActions(clip); + adjustStabilizeActions(clip); adjustProxyActions(clip); // Display uses in timeline emit findInTimeline(clip->clipId()); } else { m_transcodeAction->setEnabled(false); + m_stabilizeAction->setEnabled(false); } if (clip && clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); @@ -879,7 +971,7 @@ void ProjectList::updateButtons() const m_openAction->setEnabled(true); m_reloadAction->setEnabled(true); m_transcodeAction->setEnabled(true); - m_proxyAction->setEnabled(useProxy()); + m_stabilizeAction->setEnabled(true); return; } else if (item && item->type() == PROJECTFOLDERTYPE && item->childCount() > 0) { @@ -890,6 +982,7 @@ void ProjectList::updateButtons() const m_openAction->setEnabled(false); m_reloadAction->setEnabled(false); m_transcodeAction->setEnabled(false); + m_stabilizeAction->setEnabled(false); m_proxyAction->setEnabled(false); } @@ -998,7 +1091,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); @@ -1033,23 +1126,14 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) m_listView->processLayout(); QDomElement e = clip->toXML().cloneNode().toElement(); e.removeAttribute("file_hash"); - emit getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); + resetThumbsProducer(clip); + m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); } else if (item->hasProxy() && !item->isProxyRunning()) { slotCreateProxy(clip->getId()); } - 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 @@ -1059,6 +1143,13 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) item->setText(2, QString::number(f.rating())); } #endif + + // Add info to date column + QFileInfo fileInfo(url.path()); + if (fileInfo.exists()) { + item->setText(3, fileInfo.lastModified().toString(QString("yyyy/MM/dd hh:mm:ss"))); + } + // Add cut zones QList cuts = clip->cutZones(); if (!cuts.isEmpty()) { @@ -1076,18 +1167,16 @@ void ProjectList::slotAddClip(DocClipBase *clip, bool getProperties) } } monitorItemEditing(true); - if (m_listView->isEnabled()) { - updateButtons(); - } + updateButtons(); } void ProjectList::slotGotProxy(const QString &proxyPath) { - if (proxyPath.isEmpty() || !m_refreshed || m_abortAllProxies) return; + if (proxyPath.isEmpty() || m_abortAllProxies) return; QTreeWidgetItemIterator it(m_listView); ProjectItem *item; - while (*it) { + while (*it && !m_abortAllProxies) { if ((*it)->type() == PROJECTCLIPTYPE) { item = static_cast (*it); if (item->referencedClip()->getProperty("proxy") == proxyPath) @@ -1099,8 +1188,14 @@ void ProjectList::slotGotProxy(const QString &proxyPath) void ProjectList::slotGotProxy(ProjectItem *item) { - if (item == NULL || !m_refreshed) return; + if (item == NULL) return; DocClipBase *clip = item->referencedClip(); + if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) { + // Clip is being reprocessed, abort + kDebug()<<"//// TRYING TO PROXY: "<clipId()<<", but it is busy"; + return; + } + // Proxy clip successfully created QDomElement e = clip->toXML().cloneNode().toElement(); @@ -1112,19 +1207,24 @@ void ProjectList::slotGotProxy(ProjectItem *item) e.setAttribute("length", length); } } - emit getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); + resetThumbsProducer(clip); + m_render->getFileProperties(e, clip->getId(), m_listView->iconSize().height(), true); } void ProjectList::slotResetProjectList() { + m_listView->blockSignals(true); m_abortAllProxies = true; m_proxyThreads.waitForFinished(); m_proxyThreads.clearFutures(); m_thumbnailQueue.clear(); m_listView->clear(); + m_listView->setEnabled(true); emit clipSelected(NULL); m_refreshed = false; + m_allClipsProcessed = false; m_abortAllProxies = false; + m_listView->blockSignals(false); } void ProjectList::slotUpdateClip(const QString &id) @@ -1135,10 +1235,49 @@ void ProjectList::slotUpdateClip(const QString &id) monitorItemEditing(true); } -void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) +void ProjectList::getCachedThumbnail(ProjectItem *item) { - m_listView->setSortingEnabled(false); + 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::getCachedThumbnail(SubProjectItem *item) +{ + if (!item) return; + ProjectItem *parentItem = static_cast (item->parent()); + if (!parentItem) return; + DocClipBase *clip = parentItem->referencedClip(); + if (!clip) return; + int pos = item->zone().x(); + QString cachedPixmap = m_doc->projectFolder().path(KUrl::AddTrailingSlash) + "thumbs/" + clip->getClipHash() + "#" + QString::number(pos) + ".png"; + if (QFile::exists(cachedPixmap)) { + QPixmap pix(cachedPixmap); + if (pix.isNull()) { + KIO::NetAccess::del(KUrl(cachedPixmap), this); + requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos)); + } + else item->setData(0, Qt::DecorationRole, pix); + } + else requestClipThumbnail(parentItem->clipId() + '#' + QString::number(pos)); +} +void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged, QStringList brokenClips) +{ + if (!m_allClipsProcessed) m_listView->setEnabled(false); + m_listView->setSortingEnabled(false); QTreeWidgetItemIterator it(m_listView); DocClipBase *clip; ProjectItem *item; @@ -1151,15 +1290,23 @@ 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"; + + int max = m_doc->clipManager()->clipsCount(); + max = qMax(1, max); + int ct = 0; + while (*it) { + emit displayMessage(i18n("Loading thumbnails"), (int)(100 *(max - ct++) / max)); if ((*it)->type() == PROJECTSUBCLIPTYPE) { // subitem SubProjectItem *sub = static_cast (*it); - if (displayRatioChanged || sub->data(0, Qt::DecorationRole).isNull()) { + if (displayRatioChanged) { item = static_cast ((*it)->parent()); requestClipThumbnail(item->clipId() + '#' + QString::number(sub->zone().x())); } + else if (sub->data(0, Qt::DecorationRole).isNull()) { + getCachedThumbnail(sub); + } ++it; continue; } else if ((*it)->type() == PROJECTFOLDERTYPE) { @@ -1169,17 +1316,26 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) } else { item = static_cast (*it); clip = item->referencedClip(); - if (item->referencedClip()->producer() == NULL) { - if (clip->isPlaceHolder() == false) { + if (item->referencedClip()->getProducer() == NULL) { + bool replace = false; + if (brokenClips.contains(item->clipId())) { + // if this is a proxy clip, disable proxy + item->setProxyStatus(NOPROXY); + clip->setProperty("proxy", "-"); + replace = true; + } + if (clip->isPlaceHolder() == false && !item->isProxyRunning()) { QDomElement xml = clip->toXML(); if (fpsChanged) { xml.removeAttribute("out"); xml.removeAttribute("file_hash"); xml.removeAttribute("proxy_out"); } - emit getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), xml.attribute("replace") == "1"); + if (!replace) replace = xml.attribute("replace") == "1"; + if (replace) resetThumbsProducer(clip); + m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), replace); } - else { + else if (clip->isPlaceHolder()) { item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDropEnabled); if (item->data(0, Qt::DecorationRole).isNull()) { item->setData(0, Qt::DecorationRole, missingPixmap); @@ -1193,10 +1349,13 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) } } } else { - if (displayRatioChanged || item->data(0, Qt::DecorationRole).isNull()) + 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()); + item->changeDuration(item->referencedClip()->getProducer()->get_playtime()); } if (clip->isPlaceHolder()) { QPixmap pixmap = qVariantValue(item->data(0, Qt::DecorationRole)); @@ -1214,11 +1373,11 @@ void ProjectList::updateAllClips(bool displayRatioChanged, bool fpsChanged) } ++it; } - - if (m_listView->isEnabled()) - monitorItemEditing(true); + m_listView->setSortingEnabled(true); + m_allClipsProcessed = true; if (m_render->processingItems() == 0) { + monitorItemEditing(true); slotProcessNextThumbnail(); } } @@ -1335,13 +1494,28 @@ 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 (m_invalidClipDialog) { + m_invalidClipDialog->addClip(id, path); + return; + } + else { + if (replace) + m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip %1
is invalid, will be removed from project.", QString()), replace, kapp->activeWindow()); + else { + m_invalidClipDialog = new InvalidDialog(i18n("Invalid clip"), i18n("Clip %1
is missing or invalid. Remove it from project?", QString()), replace, kapp->activeWindow()); + } + m_invalidClipDialog->addClip(id, path); + int result = m_invalidClipDialog->exec(); + if (result == KDialog::Yes) replace = true; + } + } + if (m_invalidClipDialog) { if (replace) - KMessageBox::sorry(kapp->activeWindow(), i18n("Clip %1
is invalid, will be removed from project.", path)); - else if (KMessageBox::questionYesNo(kapp->activeWindow(), i18n("Clip %1
is missing or invalid. Remove it from project?", path), i18n("Invalid clip")) == KMessageBox::Yes) - replace = true; + emit deleteProjectClips(m_invalidClipDialog->getIds(), QMap ()); + delete m_invalidClipDialog; + m_invalidClipDialog = NULL; } - if (replace) - emit deleteProjectClips(QStringList() << id, QMap ()); + } } @@ -1349,6 +1523,7 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError) { ProjectItem *item = getItemById(id); if (item) { + kDebug()<<"// Proxy for clip "<setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); if (durationError) { kDebug() << "Proxy duration is wrong, try changing transcoding parameters."; @@ -1362,6 +1537,14 @@ void ProjectList::slotRemoveInvalidProxy(const QString &id, bool durationError) if (proxyFolder.isParentOf(KUrl(path))) { QFile::remove(path); } + if (item->referencedClip()->getProducer() == NULL) { + // Clip has no valid producer, request it + slotProxyCurrentItem(false, item); + } + else { + // refresh thumbs producer + item->referencedClip()->reloadThumbProducer(); + } } m_processingClips.removeAll(id); m_thumbnailQueue.removeAll(id); @@ -1380,7 +1563,6 @@ void ProjectList::slotAddColorClip() TimecodeDisplay *t = new TimecodeDisplay(m_timecode); t->setValue(KdenliveSettings::color_duration()); - t->setTimeCodeFormat(false); dia_ui.clip_durationBox->addWidget(t); dia_ui.clip_color->setColor(KdenliveSettings::colorclipcolor()); @@ -1483,6 +1665,7 @@ void ProjectList::setDocument(KdenliveDoc *doc) m_listView->setSortingEnabled(false); emit clipSelected(NULL); m_refreshed = false; + m_allClipsProcessed = false; m_fps = doc->fps(); m_timecode = doc->timecode(); m_commandStack = doc->commandStack(); @@ -1499,7 +1682,11 @@ void ProjectList::setDocument(KdenliveDoc *doc) } QList list = doc->clipManager()->documentClipList(); - if (list.isEmpty()) m_refreshed = true; + if (list.isEmpty()) { + // blank document + m_refreshed = true; + m_allClipsProcessed = true; + } for (int i = 0; i < list.count(); i++) slotAddClip(list.at(i), false); @@ -1508,7 +1695,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(bool, bool)), this, SLOT(updateAllClips(bool, bool))); + connect(m_doc->clipManager(), SIGNAL(checkAllClips(bool, bool, QStringList)), this, SLOT(updateAllClips(bool, bool, QStringList))); } QList ProjectList::documentClipList() const @@ -1524,7 +1711,6 @@ QDomElement ProjectList::producersList() QDomDocument doc; QDomElement prods = doc.createElement("producerlist"); doc.appendChild(prods); - kDebug() << "//////////// PRO LIST BUILD PRDSLIST "; QTreeWidgetItemIterator it(m_listView); while (*it) { if ((*it)->type() != PROJECTCLIPTYPE) { @@ -1541,13 +1727,13 @@ QDomElement ProjectList::producersList() void ProjectList::slotCheckForEmptyQueue() { if (m_render->processingItems() == 0 && m_thumbnailQueue.isEmpty()) { - if (!m_refreshed) { - emit loadingIsOver(); - emit displayMessage(QString(), -1); + if (!m_refreshed && m_allClipsProcessed) { m_refreshed = true; + m_listView->setEnabled(true); + slotClipSelected(); + QTimer::singleShot(500, this, SIGNAL(loadingIsOver())); + emit displayMessage(QString(), -1); } - m_listView->blockSignals(false); - m_listView->setEnabled(true); updateButtons(); } else if (!m_refreshed) { QTimer::singleShot(300, this, SLOT(slotCheckForEmptyQueue())); @@ -1561,6 +1747,14 @@ void ProjectList::requestClipThumbnail(const QString id) slotProcessNextThumbnail(); } +void ProjectList::resetThumbsProducer(DocClipBase *clip) +{ + if (!clip) return; + clip->clearThumbProducer(); + QString id = clip->getId(); + m_thumbnailQueue.removeAll(id); +} + void ProjectList::slotProcessNextThumbnail() { if (m_render->processingItems() > 0) { @@ -1608,25 +1802,31 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) return; } QPixmap pix; + QImage img; int height = m_listView->iconSize().height(); 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(dwidth, height)); else if (clip->clipType() == IMAGE) - pix = QPixmap::fromImage(KThumb::getFrame(item->referencedClip()->producer(), 0, swidth, dwidth, height)); - else - pix = item->referencedClip()->extractImage(frame, dwidth, height); + img = KThumb::getFrame(item->referencedClip()->getProducer(), 0, swidth, dwidth, height); + else { + img = item->referencedClip()->extractImage(frame, dwidth, height); + } - if (!pix.isNull()) { + if (!pix.isNull() || !img.isNull()) { monitorItemEditing(false); + if (!img.isNull()) pix = QPixmap::fromImage(img); it->setData(0, Qt::DecorationRole, pix); monitorItemEditing(true); - - if (!isSubItem) - m_doc->cachePixmap(item->getClipHash(), pix); - else - m_doc->cachePixmap(item->getClipHash() + '#' + QString::number(frame), pix); + + QString hash = item->getClipHash(); + if (!hash.isEmpty() && !img.isNull()) { + if (!isSubItem) + m_doc->cacheImage(hash, img); + else + m_doc->cacheImage(hash + '#' + QString::number(frame), img); + } } if (update) emit projectModified(); @@ -1634,20 +1834,16 @@ void ProjectList::slotRefreshClipThumbnail(QTreeWidgetItem *it, bool update) } } -void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace, bool refreshThumbnail) + +void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Producer *producer, const stringMap &properties, const stringMap &metadata, bool replace) { QString toReload; ProjectItem *item = getItemById(clipId); 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 (producer->is_valid()) { if (clip->isPlaceHolder()) { clip->setValid(); @@ -1655,14 +1851,15 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce } item->setFlags(Qt::ItemIsSelectable | Qt::ItemIsDragEnabled | Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsDropEnabled); } + item->setProperties(properties, metadata); clip->setProducer(producer, replace); - clip->askForAudioThumbs(); - if (refreshThumbnail) requestClipThumbnail(clipId); + clip->getAudioThumbs(); + // Proxy stuff QString size = properties.value("frame_size"); if (!useProxy() && clip->getProperty("proxy").isEmpty()) setProxyStatus(item, NOPROXY); if (useProxy() && generateProxy() && clip->getProperty("proxy") == "-") setProxyStatus(item, NOPROXY); - else if (useProxy() && !item->isProxyRunning()) { + else if (useProxy() && !item->hasProxy() && !item->isProxyRunning()) { // proxy video and image clips int maxSize; CLIPTYPE t = item->clipType(); @@ -1685,43 +1882,42 @@ void ProjectList::slotReplyGetFileProperties(const QString &clipId, Mlt::Produce } } - if (!replace && item->data(0, Qt::DecorationRole).isNull()) - requestClipThumbnail(clipId); + if (!replace && m_allClipsProcessed && item->data(0, Qt::DecorationRole).isNull()) { + getCachedThumbnail(item); + } if (!toReload.isEmpty()) item->slotSetToolTip(); - - if (m_listView->isEnabled()) - monitorItemEditing(true); } else kDebug() << "//////// COULD NOT FIND CLIP TO UPDATE PRPS..."; if (queue == 0) { + monitorItemEditing(true); if (item && m_thumbnailQueue.isEmpty()) { - m_listView->setCurrentItem(item); + if (!item->hasProxy() || m_render->activeClipId() == item->clipId()) + 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) { + } else if (KdenliveSettings::checkfirstprojectclip() && m_listView->topLevelItemCount() == 1 && m_refreshed && m_allClipsProcessed) { // 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()); + //emit clipSelected(item->referencedClip()); } } else { int max = m_doc->clipManager()->clipsCount(); - emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max)); + if (max > 0) emit displayMessage(i18n("Loading clips"), (int)(100 *(max - queue) / max)); } - processNextThumbnail(); + if (m_allClipsProcessed) emit processNextThumbnail(); } - 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 (!item) { + // no item for producer, delete it + delete producer; + return; + } + if (replace) toReload = clipId; if (!toReload.isEmpty()) - emit clipNeedsReload(toReload, true); + emit clipNeedsReload(toReload); } bool ProjectList::adjustProjectProfileToItem(ProjectItem *item) @@ -1805,27 +2001,26 @@ bool ProjectList::generateImageProxy() const void ProjectList::slotReplyGetImage(const QString &clipId, const QImage &img) { - QPixmap pix = QPixmap::fromImage(img); - setThumbnail(clipId, pix); + ProjectItem *item = getItemById(clipId); + if (item && !img.isNull()) { + QPixmap pix = QPixmap::fromImage(img); + monitorItemEditing(false); + item->setData(0, Qt::DecorationRole, pix); + monitorItemEditing(true); + QString hash = item->getClipHash(); + if (!hash.isEmpty()) m_doc->cacheImage(hash, img); + } } 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) -{ + // For clips that have a generic icon (like audio clips...) ProjectItem *item = getItemById(clipId); + QPixmap pix = KIcon(name).pixmap(QSize(width, height)); 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); } } @@ -1907,7 +2102,7 @@ void ProjectList::slotSelectClip(const QString &ix) m_deleteButton->defaultAction()->setEnabled(true); m_reloadAction->setEnabled(true); m_transcodeAction->setEnabled(true); - m_proxyAction->setEnabled(useProxy()); + m_stabilizeAction->setEnabled(true); if (clip->clipType() == IMAGE && !KdenliveSettings::defaultimageapp().isEmpty()) { m_openAction->setIcon(KIcon(KdenliveSettings::defaultimageapp())); m_openAction->setEnabled(true); @@ -1973,7 +2168,7 @@ void ProjectList::regenerateTemplate(const QString &id) void ProjectList::regenerateTemplate(ProjectItem *clip) { //TODO: remove this unused method, only force_reload is necessary - clip->referencedClip()->producer()->set("force_reload", 1); + clip->referencedClip()->getProducer()->set("force_reload", 1); } QDomDocument ProjectList::generateTemplateXml(QString path, const QString &replaceString) @@ -2023,9 +2218,10 @@ 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()->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); + QImage img = clip->referencedClip()->extractImage(in, (int)(sub->sizeHint(0).height() * m_render->dar()), sub->sizeHint(0).height() - 2); + sub->setData(0, Qt::DecorationRole, QPixmap::fromImage(img)); + QString hash = clip->getClipHash(); + if (!hash.isEmpty()) m_doc->cacheImage(hash + '#' + QString::number(in), img); monitorItemEditing(true); } emit projectModified(); @@ -2154,18 +2350,18 @@ void ProjectList::slotCreateProxy(const QString id) if (!item || item->isProxyRunning() || item->referencedClip()->isPlaceHolder()) return; QString path = item->referencedClip()->getProperty("proxy"); if (path.isEmpty()) { - setProxyStatus(path, PROXYCRASHED); + setProxyStatus(item, PROXYCRASHED); return; } - setProxyStatus(path, PROXYWAITING); + setProxyStatus(item, 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)) { + if (QFileInfo(path).size() > 0) { // Proxy already created - setProxyStatus(path, PROXYDONE); + setProxyStatus(item, PROXYDONE); slotGotProxy(path); return; } @@ -2177,212 +2373,256 @@ void ProjectList::slotCreateProxy(const QString id) 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)); + if (!m_proxyThreads.futures().isEmpty()) { + // Remove inactive threads + QList > futures = m_proxyThreads.futures(); + m_proxyThreads.clearFutures(); + for (int i = 0; i < futures.count(); i++) + if (!futures.at(i).isFinished()) { + m_proxyThreads.addFuture(futures.at(i)); + } + } + if (m_proxyThreads.futures().isEmpty() || m_proxyThreads.futures().count() < KdenliveSettings::proxythreads()) m_proxyThreads.addFuture(QtConcurrent::run(this, &ProjectList::slotGenerateProxy)); } void ProjectList::slotAbortProxy(const QString id, const QString path) { QTreeWidgetItemIterator it(m_listView); ProjectItem *item = getItemById(id); - setProxyStatus(item, NOPROXY); - slotGotProxy(item); if (!path.isEmpty() && m_processingProxy.contains(path)) { m_abortProxy << path; - setProxyStatus(path, NOPROXY); + setProxyStatus(item, NOPROXY); + } + else { + setProxyStatus(item, NOPROXY); + slotGotProxy(item); } } 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; - } + while (!m_proxyList.isEmpty() && !m_abortAllProxies) { + emit projectModified(); + PROXYINFO info = m_proxyList.takeFirst(); + if (m_abortProxy.contains(info.dest)) { + m_abortProxy.removeAll(info.dest); + continue; + } + // Get the list of clips that will need to get progress info + QTreeWidgetItemIterator it(m_listView); + QList processingItems; + while (*it && !m_abortAllProxies) { + if ((*it)->type() == PROJECTCLIPTYPE) { + ProjectItem *item = static_cast (*it); + if (item->referencedClip()->getProperty("proxy") == info.dest) { + processingItems.append(item); + } + } + ++it; + } - // Make sure proxy path is writable - QFile file(info.dest); - if (!file.open(QIODevice::WriteOnly)) { - setProxyStatus(info.dest, PROXYCRASHED); - m_processingProxy.removeAll(info.dest); - return; - } - file.close(); - QFile::remove(info.dest); + // Make sure proxy path is writable + QFile file(info.dest); + if (!file.open(QIODevice::WriteOnly)) { + for (int i = 0; i < processingItems.count(); i++) + setProxyStatus(processingItems.at(i), PROXYCRASHED); + m_processingProxy.removeAll(info.dest); + continue; + } + file.close(); + QFile::remove(info.dest); - setProxyStatus(info.dest, CREATINGPROXY); - - // Special case: playlist clips (.mlt or .kdenlive project files) - if (info.type == PLAYLIST) { - // change FFmpeg params to MLT format - QStringList parameters; - parameters << info.src; - parameters << "-consumer" << "avformat:" + info.dest; - QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts); + for (int i = 0; i < processingItems.count(); i++) + setProxyStatus(processingItems.at(i), CREATINGPROXY); + + // Special case: playlist clips (.mlt or .kdenlive project files) + if (info.type == PLAYLIST) { + // change FFmpeg params to MLT format + QStringList parameters; + parameters << info.src; + parameters << "-consumer" << "avformat:" + info.dest; + QStringList params = m_doc->getDocumentProperty("proxyparams").simplified().split('-', QString::SkipEmptyParts); - foreach(QString s, params) { - s = s.simplified(); - if (s.count(' ') == 0) { - s.append("=1"); + foreach(QString s, params) { + s = s.simplified(); + if (s.count(' ') == 0) { + s.append("=1"); + } + else s.replace(' ', '='); + parameters << s; } - 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(info.src); - parameters << "aspect=" + QString::number(display_ratio); + 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(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 (info.exif > 1) { + // Rotate image according to exif data + QImage processed; + QMatrix matrix; + + switch ( info.exif ) { + 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(info.dest); + } + else proxy.save(info.dest); + for (int i = 0; i < processingItems.count(); i++) + setProxyStatus(processingItems.at(i), PROXYDONE); + slotGotProxy(info.dest); + m_abortProxy.removeAll(info.dest); + m_processingProxy.removeAll(info.dest); + continue; + } - //kDebug()<<"TRANSCOD: "<getDocumentProperty("proxyparams").simplified(); + foreach(QString s, params.split(' ')) + parameters << s; + + // Make sure we don't block when proxy file already exists + parameters << "-y"; + parameters << info.dest; QProcess myProcess; myProcess.setProcessChannelMode(QProcess::MergedChannels); - myProcess.start(KdenliveSettings::rendererpath(), parameters); + myProcess.start("ffmpeg", parameters); myProcess.waitForStarted(); int result = -1; int duration = 0; + while (myProcess.state() != QProcess::NotRunning) { // building proxy file if (m_abortProxy.contains(info.dest) || m_abortAllProxies) { myProcess.close(); myProcess.waitForFinished(); - QFile::remove(info.dest); m_abortProxy.removeAll(info.dest); m_processingProxy.removeAll(info.dest); - setProxyStatus(info.dest, NOPROXY); + QFile::remove(info.dest); + if (!m_abortAllProxies) { + for (int i = 0; i < processingItems.count(); i++) + setProxyStatus(processingItems.at(i), NOPROXY); + } + else continue; result = -2; } else { QString log = QString(myProcess.readAll()); - processLogInfo(info.dest, &duration, log); + processLogInfo(processingItems, &duration, log); } myProcess.waitForFinished(500); } myProcess.waitForFinished(); + m_abortProxy.removeAll(info.dest); m_processingProxy.removeAll(info.dest); - if (result == -1) result = myProcess.exitStatus(); - if (result == 0) { + if (result == -1) { + result = myProcess.exitStatus(); + } + + // FFmpeg process terminated normally, but make sure proxy clip exists + if (result != -2 && QFileInfo(info.dest).size() == 0) { + result = QProcess::CrashExit; + } + + if (result == QProcess::NormalExit) { // proxy successfully created - setProxyStatus(info.dest, PROXYDONE); + for (int i = 0; i < processingItems.count(); i++) + setProxyStatus(processingItems.at(i), PROXYDONE); slotGotProxy(info.dest); } - else if (result == 1) { + else if (result == QProcess::CrashExit) { // Proxy process crashed QFile::remove(info.dest); - setProxyStatus(info.dest, PROXYCRASHED); - } - - } - - if (info.type == IMAGE) { - // Image proxy - QImage i(info.src); - if (i.isNull()) { - // Cannot load image - setProxyStatus(info.dest, PROXYCRASHED); - return; - } - QImage proxy; - // Images are scaled to profile size. - //TODO: Make it be configurable? - if (i.width() > i.height()) proxy = i.scaledToWidth(m_render->frameRenderWidth()); - else proxy = i.scaledToHeight(m_render->renderHeight()); - if (info.exif > 1) { - // Rotate image according to exif data - QImage processed; - QMatrix matrix; - - switch ( info.exif ) { - 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(info.dest); - } - 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" << 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 << info.dest; - kDebug()<<"// STARTING PROXY GEN: "<items, int *duration, const QString &log) { int progress; if (*duration == 0) { @@ -2399,7 +2639,8 @@ void ProjectList::processLogInfo(const QString &path, int *duration, const QStri progress = numbers.at(0).toInt() * 3600 + numbers.at(1).toInt() * 60 + numbers.at(2).toDouble(); } else progress = (int) time.toDouble(); - setProxyStatus(path, CREATINGPROXY, (int) (100.0 * progress / (*duration))); + for (int i = 0; i < items.count(); i++) + setProxyStatus(items.at(i), CREATINGPROXY, (int) (100.0 * progress / (*duration))); } } @@ -2474,13 +2715,40 @@ void ProjectList::updateProxyConfig() else delete command; } -void ProjectList::slotProxyCurrentItem(bool doProxy) +void ProjectList::slotProxyCurrentItem(bool doProxy, ProjectItem *itemToProxy) { - QList list = m_listView->selectedItems(); + QList list; + if (itemToProxy == NULL) list = m_listView->selectedItems(); + else list << itemToProxy; + + // expand list (folders, subclips) to get real clips QTreeWidgetItem *listItem; + QList clipList; + for (int i = 0; i < list.count(); i++) { + listItem = list.at(i); + if (listItem->type() == PROJECTFOLDERTYPE) { + for (int j = 0; j < listItem->childCount(); j++) { + QTreeWidgetItem *sub = listItem->child(j); + if (sub->type() == PROJECTCLIPTYPE) { + ProjectItem *item = static_cast (sub); + if (!clipList.contains(item)) clipList.append(item); + } + } + } + else if (listItem->type() == PROJECTSUBCLIPTYPE) { + QTreeWidgetItem *sub = listItem->parent(); + ProjectItem *item = static_cast (sub); + if (!clipList.contains(item)) clipList.append(item); + } + else if (listItem->type() == PROJECTCLIPTYPE) { + ProjectItem *item = static_cast (listItem); + if (!clipList.contains(item)) clipList.append(item); + } + } + QUndoCommand *command = new QUndoCommand(); - 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())); + if (doProxy) command->setText(i18np("Add proxy clip", "Add proxy clips", clipList.count())); + else command->setText(i18np("Remove proxy clip", "Remove proxy clips", clipList.count())); // Make sure the proxy folder exists QString proxydir = m_doc->projectFolder().path( KUrl::AddTrailingSlash) + "proxy/"; @@ -2489,30 +2757,33 @@ void ProjectList::slotProxyCurrentItem(bool doProxy) QMap newProps; QMap oldProps; if (!doProxy) newProps.insert("proxy", "-"); - for (int i = 0; i < list.count(); i++) { - listItem = list.at(i); - if (listItem->type() == PROJECTFOLDERTYPE) { - for (int j = 0; j < listItem->childCount(); j++) { - QTreeWidgetItem *sub = listItem->child(j); - if (!list.contains(sub)) list.append(sub); + for (int i = 0; i < clipList.count(); i++) { + ProjectItem *item = clipList.at(i); + CLIPTYPE t = item->clipType(); + if ((t == VIDEO || t == AV || t == UNKNOWN || t == IMAGE || t == PLAYLIST) && item->referencedClip()) { + if ((doProxy && item->hasProxy()) || (!doProxy && !item->hasProxy() && item->referencedClip()->getProducer() != NULL)) continue; + DocClipBase *clip = item->referencedClip(); + if (!clip || !clip->isClean() || m_render->isProcessing(item->clipId())) { + kDebug()<<"//// TRYING TO PROXY: "<clipId()<<", but it is busy"; + continue; } - } - if (listItem->type() == PROJECTCLIPTYPE) { - ProjectItem *item = static_cast (listItem); - CLIPTYPE t = item->clipType(); - 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() + "." + (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(), oldProps, newProps, true, command); + + oldProps = clip->properties(); + if (doProxy) { + newProps.clear(); + QString path = proxydir + clip->getClipHash() + "." + (t == IMAGE ? "png" : m_doc->getDocumentProperty("proxyextension")); + // insert required duration for proxy + newProps.insert("proxy_out", clip->producerProperty("out")); + newProps.insert("proxy", path); + // We need to insert empty proxy so that undo will work + oldProps.insert("proxy", QString()); + } + else if (item->referencedClip()->getProducer() == NULL) { + // Force clip reload + kDebug()<<"// CLIP HAD NULL PROD------------"; + newProps.insert("resource", item->referencedClip()->getProperty("resource")); } + new EditClipCommand(this, item->clipId(), oldProps, newProps, true, command); } } if (command->childCount() > 0) { @@ -2548,27 +2819,27 @@ void ProjectList::slotDeleteProxy(const QString proxyPath) QFile::remove(proxyPath); } -void ProjectList::setProxyStatus(const QString proxyPath, PROXYSTATUS status, int progress) -{ - 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, progress); - } - } - ++it; - } -} - void ProjectList::setProxyStatus(ProjectItem *item, PROXYSTATUS status, int progress) { - if (item == NULL) return; + if (item == NULL || m_abortAllProxies) return; monitorItemEditing(false); item->setProxyStatus(status, progress); + if (status == PROXYCRASHED) { + DocClipBase *clip = item->referencedClip(); + if (!clip) { + kDebug()<<"// PROXY CRASHED"; + } + else if (clip->getProducer() == NULL && !clip->isPlaceHolder()) { + // disable proxy and fetch real clip + clip->setProperty("proxy", "-"); + QDomElement xml = clip->toXML(); + m_render->getFileProperties(xml, clip->getId(), m_listView->iconSize().height(), true); + } + else { + // Disable proxy for this clip + clip->setProperty("proxy", "-"); + } + } monitorItemEditing(true); }